2009-03-02 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / decimal.c
index 766a688aac7205fa9ee643e3ce58992553edc1dc..6524443eab3d57168325a710d2ac93e05d74671a 100644 (file)
@@ -1,12 +1,12 @@
 /* 
  decimal.c
-
  conversions and numerical operations for the c# type System.Decimal
-
  Author: Martin Weindel (martin.weindel@t-online.de)
-
  (C) 2001 by Martin Weindel
-*/
* decimal.c
+ *
* conversions and numerical operations for the c# type System.Decimal
+ *
* Author: Martin Weindel (martin.weindel@t-online.de)
+ *
* (C) 2001 by Martin Weindel
+ */
 
 /*
  * machine dependent configuration for 
@@ -22,6 +22,9 @@
 #ifdef HAVE_MEMORY_H
 #include <memory.h>
 #endif
+#ifdef _MSC_VER
+#include <intrin.h>
+#endif
 
 #ifndef DISABLE_DECIMAL
 
@@ -565,8 +568,26 @@ my_g_bit_nth_msf (gsize mask)
        __asm__("bsrq %1,%0\n\t"
                        : "=r" (r) : "rm" (mask));
        return r;
+#elif defined(__i386__) && defined(_MSC_VER)
+       unsigned long bIndex = 0;
+       if (_BitScanReverse (&bIndex, mask))
+               return bIndex;
+       return -1;
+#elif defined(__x86_64__) && defined(_MSC_VER)
+       unsigned long bIndex = 0;
+       if (_BitScanReverse64 (&bIndex, mask))
+               return bIndex;
+       return -1;
 #else
-       return g_bit_nth_msf (mask, sizeof (gsize) * 8);
+       int i;
+
+       i = sizeof (gsize) * 8;
+       while (i > 0) {
+               i --;
+               if (mask & (1UL << i))
+                       return i;
+       }
+       return -1;
 #endif
 }