From 0de664d0a886bcda45a0cd05551b6896c5c46ed0 Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Sat, 14 Feb 2015 12:00:00 +0100 Subject: Import icculus.org release (2015-02-14) --- src/mathline.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/mathline.h (limited to 'src/mathline.h') 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 + +#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 -- cgit v1.3