[AD] fixmul

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Attached is a modified version of Peter's fixmul patch posted originally in 
http://www.allegro.cc/forums/view_thread.php?_id=488085. The only 
difference is that I've got rid of the conditionals and used the code on 
Bob's code-snippet page to get the absolute value and flip the signs of 
the input and output.
A minor enhancement would be to just do (x*y)>>32 if we can use 64 bit 
integers. Is there and easy way to do this at compile time? Or should I 
just do something like
#ifdef LONG_LONG
   LONG_LONG lx = x;
   LONG_LONG ly = y;
   LONG_LONG lres = (lx*ly)>>32;
   int res = lres;
   return res;
#endif
?

Evert
Index: include/allegro/inline/fmaths.inl
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/inline/fmaths.inl,v
retrieving revision 1.7
diff -u -r1.7 fmaths.inl
--- include/allegro/inline/fmaths.inl	1 Feb 2005 13:12:04 -0000	1.7
+++ include/allegro/inline/fmaths.inl	16 May 2005 07:55:27 -0000
@@ -103,7 +103,24 @@
 
 AL_INLINE(fixed, fixmul, (fixed x, fixed y),
 {
+#if 0
    return ftofix(fixtof(x) * fixtof(y));
+#else
+   fixed sign = (x^y) & 0x80000000;
+   int mask_x = x >> 31;
+   int mask_y = y >> 31;
+   int mask_result = sign >> 31;
+   fixed result;
+
+   x = (x^mask_x) - mask_x;
+   y = (y^mask_y) - mask_y;
+
+   result = ((y >> 8)*(x >> 8) +
+             (((y >> 8)*(x&0xff)) >> 8) +
+             (((x >> 8)*(y&0xff)) >> 8));
+
+   return (result^mask_result) - mask_result;
+#endif
 })
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/