summaryrefslogtreecommitdiff
path: root/src/mathline.h
diff options
context:
space:
mode:
authorSteven Fuller <relnev@icculus.org>2015-02-14 12:00:00 +0100
committerPatryk Obara <dreamer.tan@gmail.com>2019-08-20 03:51:33 +0200
commit0de664d0a886bcda45a0cd05551b6896c5c46ed0 (patch)
tree50127b6ec478d76bc714dbfda69602610334ed0c /src/mathline.h
parent22475d6d94e96056d1550dca00b32d00e3821649 (diff)
Import icculus.org release (2015-02-14)
Diffstat (limited to 'src/mathline.h')
-rw-r--r--src/mathline.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/mathline.h b/src/mathline.h
new file mode 100644
index 0000000..b1620a5
--- /dev/null
+++ b/src/mathline.h
@@ -0,0 +1,66 @@
+#ifndef MATHLINE_H
+#define MATHLINE_H
+
+#include <math.h>
+
+#define f2i(a, b) a = lrintf(b)
+
+/*
+
+ Fixed Point Multiply.
+
+
+ 16.16 * 16.16 -> 16.16
+ or
+ 16.16 * 0.32 -> 0.32
+
+ A proper version of this function ought to read
+ 16.16 * 16.16 -> 32.16
+ but this would require a __int64 result
+
+ Algorithm:
+
+ Take the mid 32 bits of the 64 bit result
+
+*/
+
+/*
+ These functions have been checked for suitability for
+ a Pentium and look as if they would work adequately.
+ Might be worth a more detailed look at optimising
+ them though.
+*/
+
+static inline int MUL_FIXED(int a, int b)
+{
+/*
+ int retval;
+ _asm
+ {
+ mov eax,a
+ imul b
+ shrd eax,edx,16
+ mov retval,eax
+ }
+*/
+
+#if defined(ASM386)
+ int retval;
+__asm__("imull %2 \n\t"
+ "shrdl $16, %%edx, %%eax \n\t"
+ : "=a" (retval)
+ : "0" (a), "m" (b)
+ : "%edx", "cc"
+ );
+ return retval;
+#else
+ __int64 aa = (__int64) a;
+ __int64 bb = (__int64) b;
+
+ __int64 cc = aa * bb;
+
+ return (int) ((cc >> 16) & 0xffffffff);
+#endif
+}
+
+#endif