[AD] fixdiv patch

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


Is anyone against including this patch if we test for the prescense
of an FPU (or check against platforms known to have one)? The
original patch is attached for convenience.

Trent :{)>
Index: fmaths.inl
===================================================================
--- fmaths.inl	(revision 10260)
+++ fmaths.inl	(working copy)
@@ -143,7 +143,7 @@
    })
 #endif	    /* fixmul() C implementations */
 
-
+#if (defined ALLEGRO_I386) || (!defined LONG_LONG)
 AL_INLINE(fixed, fixdiv, (fixed x, fixed y),
 {
    if (y == 0) {
@@ -153,8 +153,30 @@
    else
       return ftofix(fixtof(x) / fixtof(y));
 })
+#else
+AL_INLINE(fixed, fixdiv, (fixed x, fixed y),
+{
+   LONG_LONG lres = x;
+   if (y == 0) {
+      *allegro_errno = ERANGE;
+      return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF;
+   }
+   lres <<= 16;
+   lres /= y;
+   if (lres > 0x7FFFFFFF) {
+      *allegro_errno = ERANGE;
+      return 0x7FFFFFFF;
+   }
+   else if (lres < -0x7FFFFFFF) {
+      *allegro_errno = ERANGE;
+      return 0x80000000;
+   }
+   else {
+      return (fixed)(lres);
+   }
+})
+#endif	    /* fixmul() C implementations */
 
-
 AL_INLINE(int, fixfloor, (fixed x),
 {
    /* (x >> 16) is not portable */


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