]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmSoftFloatLib/bits32/softfloat-macros
ArmPkg: factor out softfloat support from StdLib/LibC/SoftFloat
[mirror_edk2.git] / ArmPkg / Library / ArmSoftFloatLib / bits32 / softfloat-macros
diff --git a/ArmPkg/Library/ArmSoftFloatLib/bits32/softfloat-macros b/ArmPkg/Library/ArmSoftFloatLib/bits32/softfloat-macros
new file mode 100644 (file)
index 0000000..8e1f2d8
--- /dev/null
@@ -0,0 +1,648 @@
+\r
+/*\r
+===============================================================================\r
+\r
+This C source fragment is part of the SoftFloat IEC/IEEE Floating-point\r
+Arithmetic Package, Release 2a.\r
+\r
+Written by John R. Hauser.  This work was made possible in part by the\r
+International Computer Science Institute, located at Suite 600, 1947 Center\r
+Street, Berkeley, California 94704.  Funding was partially provided by the\r
+National Science Foundation under grant MIP-9311980.  The original version\r
+of this code was written as part of a project to build a fixed-point vector\r
+processor in collaboration with the University of California at Berkeley,\r
+overseen by Profs. Nelson Morgan and John Wawrzynek.  More information\r
+is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/\r
+arithmetic/SoftFloat.html'.\r
+\r
+THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort\r
+has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT\r
+TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO\r
+PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY\r
+AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.\r
+\r
+Derivative works are acceptable, even for commercial purposes, so long as\r
+(1) they include prominent notice that the work is derivative, and (2) they\r
+include prominent notice akin to these four paragraphs for those parts of\r
+this code that are retained.\r
+\r
+===============================================================================\r
+*/\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Shifts `a' right by the number of bits given in `count'.  If any nonzero\r
+bits are shifted off, they are ``jammed'' into the least significant bit of\r
+the result by setting the least significant bit to 1.  The value of `count'\r
+can be arbitrarily large; in particular, if `count' is greater than 32, the\r
+result will be either 0 or 1, depending on whether `a' is zero or nonzero.\r
+The result is stored in the location pointed to by `zPtr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void shift32RightJamming( bits32 a, int16 count, bits32 *zPtr )\r
+{\r
+    bits32 z;\r
+\r
+    if ( count == 0 ) {\r
+        z = a;\r
+    }\r
+    else if ( count < 32 ) {\r
+        z = ( a>>count ) | ( ( a<<( ( - count ) & 31 ) ) != 0 );\r
+    }\r
+    else {\r
+        z = ( a != 0 );\r
+    }\r
+    *zPtr = z;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Shifts the 64-bit value formed by concatenating `a0' and `a1' right by the\r
+number of bits given in `count'.  Any bits shifted off are lost.  The value\r
+of `count' can be arbitrarily large; in particular, if `count' is greater\r
+than 64, the result will be 0.  The result is broken into two 32-bit pieces\r
+which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ shift64Right(\r
+     bits32 a0, bits32 a1, int16 count, bits32 *z0Ptr, bits32 *z1Ptr )\r
+{\r
+    bits32 z0, z1;\r
+    int8 negCount = ( - count ) & 31;\r
+\r
+    if ( count == 0 ) {\r
+        z1 = a1;\r
+        z0 = a0;\r
+    }\r
+    else if ( count < 32 ) {\r
+        z1 = ( a0<<negCount ) | ( a1>>count );\r
+        z0 = a0>>count;\r
+    }\r
+    else {\r
+        z1 = ( count < 64 ) ? ( a0>>( count & 31 ) ) : 0;\r
+        z0 = 0;\r
+    }\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Shifts the 64-bit value formed by concatenating `a0' and `a1' right by the\r
+number of bits given in `count'.  If any nonzero bits are shifted off, they\r
+are ``jammed'' into the least significant bit of the result by setting the\r
+least significant bit to 1.  The value of `count' can be arbitrarily large;\r
+in particular, if `count' is greater than 64, the result will be either 0\r
+or 1, depending on whether the concatenation of `a0' and `a1' is zero or\r
+nonzero.  The result is broken into two 32-bit pieces which are stored at\r
+the locations pointed to by `z0Ptr' and `z1Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ shift64RightJamming(\r
+     bits32 a0, bits32 a1, int16 count, bits32 *z0Ptr, bits32 *z1Ptr )\r
+{\r
+    bits32 z0, z1;\r
+    int8 negCount = ( - count ) & 31;\r
+\r
+    if ( count == 0 ) {\r
+        z1 = a1;\r
+        z0 = a0;\r
+    }\r
+    else if ( count < 32 ) {\r
+        z1 = ( a0<<negCount ) | ( a1>>count ) | ( ( a1<<negCount ) != 0 );\r
+        z0 = a0>>count;\r
+    }\r
+    else {\r
+        if ( count == 32 ) {\r
+            z1 = a0 | ( a1 != 0 );\r
+        }\r
+        else if ( count < 64 ) {\r
+            z1 = ( a0>>( count & 31 ) ) | ( ( ( a0<<negCount ) | a1 ) != 0 );\r
+        }\r
+        else {\r
+            z1 = ( ( a0 | a1 ) != 0 );\r
+        }\r
+        z0 = 0;\r
+    }\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Shifts the 96-bit value formed by concatenating `a0', `a1', and `a2' right\r
+by 32 _plus_ the number of bits given in `count'.  The shifted result is\r
+at most 64 nonzero bits; these are broken into two 32-bit pieces which are\r
+stored at the locations pointed to by `z0Ptr' and `z1Ptr'.  The bits shifted\r
+off form a third 32-bit result as follows:  The _last_ bit shifted off is\r
+the most-significant bit of the extra result, and the other 31 bits of the\r
+extra result are all zero if and only if _all_but_the_last_ bits shifted off\r
+were all zero.  This extra result is stored in the location pointed to by\r
+`z2Ptr'.  The value of `count' can be arbitrarily large.\r
+    (This routine makes more sense if `a0', `a1', and `a2' are considered\r
+to form a fixed-point value with binary point between `a1' and `a2'.  This\r
+fixed-point value is shifted right by the number of bits given in `count',\r
+and the integer part of the result is returned at the locations pointed to\r
+by `z0Ptr' and `z1Ptr'.  The fractional part of the result may be slightly\r
+corrupted as described above, and is returned at the location pointed to by\r
+`z2Ptr'.)\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ shift64ExtraRightJamming(\r
+     bits32 a0,\r
+     bits32 a1,\r
+     bits32 a2,\r
+     int16 count,\r
+     bits32 *z0Ptr,\r
+     bits32 *z1Ptr,\r
+     bits32 *z2Ptr\r
+ )\r
+{\r
+    bits32 z0, z1, z2;\r
+    int8 negCount = ( - count ) & 31;\r
+\r
+    if ( count == 0 ) {\r
+        z2 = a2;\r
+        z1 = a1;\r
+        z0 = a0;\r
+    }\r
+    else {\r
+        if ( count < 32 ) {\r
+            z2 = a1<<negCount;\r
+            z1 = ( a0<<negCount ) | ( a1>>count );\r
+            z0 = a0>>count;\r
+        }\r
+        else {\r
+            if ( count == 32 ) {\r
+                z2 = a1;\r
+                z1 = a0;\r
+            }\r
+            else {\r
+                a2 |= a1;\r
+                if ( count < 64 ) {\r
+                    z2 = a0<<negCount;\r
+                    z1 = a0>>( count & 31 );\r
+                }\r
+                else {\r
+                    z2 = ( count == 64 ) ? a0 : ( a0 != 0 );\r
+                    z1 = 0;\r
+                }\r
+            }\r
+            z0 = 0;\r
+        }\r
+        z2 |= ( a2 != 0 );\r
+    }\r
+    *z2Ptr = z2;\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Shifts the 64-bit value formed by concatenating `a0' and `a1' left by the\r
+number of bits given in `count'.  Any bits shifted off are lost.  The value\r
+of `count' must be less than 32.  The result is broken into two 32-bit\r
+pieces which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ shortShift64Left(\r
+     bits32 a0, bits32 a1, int16 count, bits32 *z0Ptr, bits32 *z1Ptr )\r
+{\r
+\r
+    *z1Ptr = a1<<count;\r
+    *z0Ptr =\r
+        ( count == 0 ) ? a0 : ( a0<<count ) | ( a1>>( ( - count ) & 31 ) );\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Shifts the 96-bit value formed by concatenating `a0', `a1', and `a2' left\r
+by the number of bits given in `count'.  Any bits shifted off are lost.\r
+The value of `count' must be less than 32.  The result is broken into three\r
+32-bit pieces which are stored at the locations pointed to by `z0Ptr',\r
+`z1Ptr', and `z2Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ shortShift96Left(\r
+     bits32 a0,\r
+     bits32 a1,\r
+     bits32 a2,\r
+     int16 count,\r
+     bits32 *z0Ptr,\r
+     bits32 *z1Ptr,\r
+     bits32 *z2Ptr\r
+ )\r
+{\r
+    bits32 z0, z1, z2;\r
+    int8 negCount;\r
+\r
+    z2 = a2<<count;\r
+    z1 = a1<<count;\r
+    z0 = a0<<count;\r
+    if ( 0 < count ) {\r
+        negCount = ( ( - count ) & 31 );\r
+        z1 |= a2>>negCount;\r
+        z0 |= a1>>negCount;\r
+    }\r
+    *z2Ptr = z2;\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Adds the 64-bit value formed by concatenating `a0' and `a1' to the 64-bit\r
+value formed by concatenating `b0' and `b1'.  Addition is modulo 2^64, so\r
+any carry out is lost.  The result is broken into two 32-bit pieces which\r
+are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ add64(\r
+     bits32 a0, bits32 a1, bits32 b0, bits32 b1, bits32 *z0Ptr, bits32 *z1Ptr )\r
+{\r
+    bits32 z1;\r
+\r
+    z1 = a1 + b1;\r
+    *z1Ptr = z1;\r
+    *z0Ptr = a0 + b0 + ( z1 < a1 );\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Adds the 96-bit value formed by concatenating `a0', `a1', and `a2' to the\r
+96-bit value formed by concatenating `b0', `b1', and `b2'.  Addition is\r
+modulo 2^96, so any carry out is lost.  The result is broken into three\r
+32-bit pieces which are stored at the locations pointed to by `z0Ptr',\r
+`z1Ptr', and `z2Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ add96(\r
+     bits32 a0,\r
+     bits32 a1,\r
+     bits32 a2,\r
+     bits32 b0,\r
+     bits32 b1,\r
+     bits32 b2,\r
+     bits32 *z0Ptr,\r
+     bits32 *z1Ptr,\r
+     bits32 *z2Ptr\r
+ )\r
+{\r
+    bits32 z0, z1, z2;\r
+    int8 carry0, carry1;\r
+\r
+    z2 = a2 + b2;\r
+    carry1 = ( z2 < a2 );\r
+    z1 = a1 + b1;\r
+    carry0 = ( z1 < a1 );\r
+    z0 = a0 + b0;\r
+    z1 += carry1;\r
+    z0 += ( z1 < (bits32)carry1 );\r
+    z0 += carry0;\r
+    *z2Ptr = z2;\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Subtracts the 64-bit value formed by concatenating `b0' and `b1' from the\r
+64-bit value formed by concatenating `a0' and `a1'.  Subtraction is modulo\r
+2^64, so any borrow out (carry out) is lost.  The result is broken into two\r
+32-bit pieces which are stored at the locations pointed to by `z0Ptr' and\r
+`z1Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ sub64(\r
+     bits32 a0, bits32 a1, bits32 b0, bits32 b1, bits32 *z0Ptr, bits32 *z1Ptr )\r
+{\r
+\r
+    *z1Ptr = a1 - b1;\r
+    *z0Ptr = a0 - b0 - ( a1 < b1 );\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Subtracts the 96-bit value formed by concatenating `b0', `b1', and `b2' from\r
+the 96-bit value formed by concatenating `a0', `a1', and `a2'.  Subtraction\r
+is modulo 2^96, so any borrow out (carry out) is lost.  The result is broken\r
+into three 32-bit pieces which are stored at the locations pointed to by\r
+`z0Ptr', `z1Ptr', and `z2Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ sub96(\r
+     bits32 a0,\r
+     bits32 a1,\r
+     bits32 a2,\r
+     bits32 b0,\r
+     bits32 b1,\r
+     bits32 b2,\r
+     bits32 *z0Ptr,\r
+     bits32 *z1Ptr,\r
+     bits32 *z2Ptr\r
+ )\r
+{\r
+    bits32 z0, z1, z2;\r
+    int8 borrow0, borrow1;\r
+\r
+    z2 = a2 - b2;\r
+    borrow1 = ( a2 < b2 );\r
+    z1 = a1 - b1;\r
+    borrow0 = ( a1 < b1 );\r
+    z0 = a0 - b0;\r
+    z0 -= ( z1 < (bits32)borrow1 );\r
+    z1 -= borrow1;\r
+    z0 -= borrow0;\r
+    *z2Ptr = z2;\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Multiplies `a' by `b' to obtain a 64-bit product.  The product is broken\r
+into two 32-bit pieces which are stored at the locations pointed to by\r
+`z0Ptr' and `z1Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void mul32To64( bits32 a, bits32 b, bits32 *z0Ptr, bits32 *z1Ptr )\r
+{\r
+    bits16 aHigh, aLow, bHigh, bLow;\r
+    bits32 z0, zMiddleA, zMiddleB, z1;\r
+\r
+    aLow = a;\r
+    aHigh = a>>16;\r
+    bLow = b;\r
+    bHigh = b>>16;\r
+    z1 = ( (bits32) aLow ) * bLow;\r
+    zMiddleA = ( (bits32) aLow ) * bHigh;\r
+    zMiddleB = ( (bits32) aHigh ) * bLow;\r
+    z0 = ( (bits32) aHigh ) * bHigh;\r
+    zMiddleA += zMiddleB;\r
+    z0 += ( ( (bits32) ( zMiddleA < zMiddleB ) )<<16 ) + ( zMiddleA>>16 );\r
+    zMiddleA <<= 16;\r
+    z1 += zMiddleA;\r
+    z0 += ( z1 < zMiddleA );\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Multiplies the 64-bit value formed by concatenating `a0' and `a1' by `b'\r
+to obtain a 96-bit product.  The product is broken into three 32-bit pieces\r
+which are stored at the locations pointed to by `z0Ptr', `z1Ptr', and\r
+`z2Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ mul64By32To96(\r
+     bits32 a0,\r
+     bits32 a1,\r
+     bits32 b,\r
+     bits32 *z0Ptr,\r
+     bits32 *z1Ptr,\r
+     bits32 *z2Ptr\r
+ )\r
+{\r
+    bits32 z0, z1, z2, more1;\r
+\r
+    mul32To64( a1, b, &z1, &z2 );\r
+    mul32To64( a0, b, &z0, &more1 );\r
+    add64( z0, more1, 0, z1, &z0, &z1 );\r
+    *z2Ptr = z2;\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Multiplies the 64-bit value formed by concatenating `a0' and `a1' to the\r
+64-bit value formed by concatenating `b0' and `b1' to obtain a 128-bit\r
+product.  The product is broken into four 32-bit pieces which are stored at\r
+the locations pointed to by `z0Ptr', `z1Ptr', `z2Ptr', and `z3Ptr'.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE void\r
+ mul64To128(\r
+     bits32 a0,\r
+     bits32 a1,\r
+     bits32 b0,\r
+     bits32 b1,\r
+     bits32 *z0Ptr,\r
+     bits32 *z1Ptr,\r
+     bits32 *z2Ptr,\r
+     bits32 *z3Ptr\r
+ )\r
+{\r
+    bits32 z0, z1, z2, z3;\r
+    bits32 more1, more2;\r
+\r
+    mul32To64( a1, b1, &z2, &z3 );\r
+    mul32To64( a1, b0, &z1, &more2 );\r
+    add64( z1, more2, 0, z2, &z1, &z2 );\r
+    mul32To64( a0, b0, &z0, &more1 );\r
+    add64( z0, more1, 0, z1, &z0, &z1 );\r
+    mul32To64( a0, b1, &more1, &more2 );\r
+    add64( more1, more2, 0, z2, &more1, &z2 );\r
+    add64( z0, z1, 0, more1, &z0, &z1 );\r
+    *z3Ptr = z3;\r
+    *z2Ptr = z2;\r
+    *z1Ptr = z1;\r
+    *z0Ptr = z0;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Returns an approximation to the 32-bit integer quotient obtained by dividing\r
+`b' into the 64-bit value formed by concatenating `a0' and `a1'.  The\r
+divisor `b' must be at least 2^31.  If q is the exact quotient truncated\r
+toward zero, the approximation returned lies between q and q + 2 inclusive.\r
+If the exact quotient q is larger than 32 bits, the maximum positive 32-bit\r
+unsigned integer is returned.\r
+-------------------------------------------------------------------------------\r
+*/\r
+static bits32 estimateDiv64To32( bits32 a0, bits32 a1, bits32 b )\r
+{\r
+    bits32 b0, b1;\r
+    bits32 rem0, rem1, term0, term1;\r
+    bits32 z;\r
+\r
+    if ( b <= a0 ) return 0xFFFFFFFF;\r
+    b0 = b>>16;\r
+    z = ( b0<<16 <= a0 ) ? 0xFFFF0000 : ( a0 / b0 )<<16;\r
+    mul32To64( b, z, &term0, &term1 );\r
+    sub64( a0, a1, term0, term1, &rem0, &rem1 );\r
+    while ( ( (sbits32) rem0 ) < 0 ) {\r
+        z -= 0x10000;\r
+        b1 = b<<16;\r
+        add64( rem0, rem1, b0, b1, &rem0, &rem1 );\r
+    }\r
+    rem0 = ( rem0<<16 ) | ( rem1>>16 );\r
+    z |= ( b0<<16 <= rem0 ) ? 0xFFFF : rem0 / b0;\r
+    return z;\r
+\r
+}\r
+\r
+#ifndef SOFTFLOAT_FOR_GCC\r
+/*\r
+-------------------------------------------------------------------------------\r
+Returns an approximation to the square root of the 32-bit significand given\r
+by `a'.  Considered as an integer, `a' must be at least 2^31.  If bit 0 of\r
+`aExp' (the least significant bit) is 1, the integer returned approximates\r
+2^31*sqrt(`a'/2^31), where `a' is considered an integer.  If bit 0 of `aExp'\r
+is 0, the integer returned approximates 2^31*sqrt(`a'/2^30).  In either\r
+case, the approximation returned lies strictly within +/-2 of the exact\r
+value.\r
+-------------------------------------------------------------------------------\r
+*/\r
+static bits32 estimateSqrt32( int16 aExp, bits32 a )\r
+{\r
+    static const bits16 sqrtOddAdjustments[] = {\r
+        0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0,\r
+        0x039C, 0x0468, 0x0545, 0x0631, 0x072B, 0x0832, 0x0946, 0x0A67\r
+    };\r
+    static const bits16 sqrtEvenAdjustments[] = {\r
+        0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E,\r
+        0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002\r
+    };\r
+    int8 index;\r
+    bits32 z;\r
+\r
+    index = ( a>>27 ) & 15;\r
+    if ( aExp & 1 ) {\r
+        z = 0x4000 + ( a>>17 ) - sqrtOddAdjustments[ index ];\r
+        z = ( ( a / z )<<14 ) + ( z<<15 );\r
+        a >>= 1;\r
+    }\r
+    else {\r
+        z = 0x8000 + ( a>>17 ) - sqrtEvenAdjustments[ index ];\r
+        z = a / z + z;\r
+        z = ( 0x20000 <= z ) ? 0xFFFF8000 : ( z<<15 );\r
+        if ( z <= a ) return (bits32) ( ( (sbits32) a )>>1 );\r
+    }\r
+    return ( ( estimateDiv64To32( a, 0, z ) )>>1 ) + ( z>>1 );\r
+\r
+}\r
+#endif\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Returns the number of leading 0 bits before the most-significant 1 bit of\r
+`a'.  If `a' is zero, 32 is returned.\r
+-------------------------------------------------------------------------------\r
+*/\r
+static int8 countLeadingZeros32( bits32 a )\r
+{\r
+    static const int8 countLeadingZerosHigh[] = {\r
+        8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,\r
+        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,\r
+        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
+    };\r
+    int8 shiftCount;\r
+\r
+    shiftCount = 0;\r
+    if ( a < 0x10000 ) {\r
+        shiftCount += 16;\r
+        a <<= 16;\r
+    }\r
+    if ( a < 0x1000000 ) {\r
+        shiftCount += 8;\r
+        a <<= 8;\r
+    }\r
+    shiftCount += countLeadingZerosHigh[ a>>24 ];\r
+    return shiftCount;\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Returns 1 if the 64-bit value formed by concatenating `a0' and `a1' is\r
+equal to the 64-bit value formed by concatenating `b0' and `b1'.  Otherwise,\r
+returns 0.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE flag eq64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 )\r
+{\r
+\r
+    return ( a0 == b0 ) && ( a1 == b1 );\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Returns 1 if the 64-bit value formed by concatenating `a0' and `a1' is less\r
+than or equal to the 64-bit value formed by concatenating `b0' and `b1'.\r
+Otherwise, returns 0.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE flag le64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 )\r
+{\r
+\r
+    return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 <= b1 ) );\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Returns 1 if the 64-bit value formed by concatenating `a0' and `a1' is less\r
+than the 64-bit value formed by concatenating `b0' and `b1'.  Otherwise,\r
+returns 0.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE flag lt64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 )\r
+{\r
+\r
+    return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 < b1 ) );\r
+\r
+}\r
+\r
+/*\r
+-------------------------------------------------------------------------------\r
+Returns 1 if the 64-bit value formed by concatenating `a0' and `a1' is not\r
+equal to the 64-bit value formed by concatenating `b0' and `b1'.  Otherwise,\r
+returns 0.\r
+-------------------------------------------------------------------------------\r
+*/\r
+INLINE flag ne64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 )\r
+{\r
+\r
+    return ( a0 != b0 ) || ( a1 != b1 );\r
+\r
+}\r
+\r