1*2fe8fb19SBen Gras/* $NetBSD: softfloat-macros,v 1.2 2009/02/16 10:23:35 tron Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras/* 4*2fe8fb19SBen Gras=============================================================================== 5*2fe8fb19SBen Gras 6*2fe8fb19SBen GrasThis C source fragment is part of the SoftFloat IEC/IEEE Floating-point 7*2fe8fb19SBen GrasArithmetic Package, Release 2a. 8*2fe8fb19SBen Gras 9*2fe8fb19SBen GrasWritten by John R. Hauser. This work was made possible in part by the 10*2fe8fb19SBen GrasInternational Computer Science Institute, located at Suite 600, 1947 Center 11*2fe8fb19SBen GrasStreet, Berkeley, California 94704. Funding was partially provided by the 12*2fe8fb19SBen GrasNational Science Foundation under grant MIP-9311980. The original version 13*2fe8fb19SBen Grasof this code was written as part of a project to build a fixed-point vector 14*2fe8fb19SBen Grasprocessor in collaboration with the University of California at Berkeley, 15*2fe8fb19SBen Grasoverseen by Profs. Nelson Morgan and John Wawrzynek. More information 16*2fe8fb19SBen Grasis available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ 17*2fe8fb19SBen Grasarithmetic/SoftFloat.html'. 18*2fe8fb19SBen Gras 19*2fe8fb19SBen GrasTHIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 20*2fe8fb19SBen Grashas been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 21*2fe8fb19SBen GrasTIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 22*2fe8fb19SBen GrasPERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 23*2fe8fb19SBen GrasAND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 24*2fe8fb19SBen Gras 25*2fe8fb19SBen GrasDerivative works are acceptable, even for commercial purposes, so long as 26*2fe8fb19SBen Gras(1) they include prominent notice that the work is derivative, and (2) they 27*2fe8fb19SBen Grasinclude prominent notice akin to these four paragraphs for those parts of 28*2fe8fb19SBen Grasthis code that are retained. 29*2fe8fb19SBen Gras 30*2fe8fb19SBen Gras=============================================================================== 31*2fe8fb19SBen Gras*/ 32*2fe8fb19SBen Gras 33*2fe8fb19SBen Gras/* 34*2fe8fb19SBen Gras------------------------------------------------------------------------------- 35*2fe8fb19SBen GrasShifts `a' right by the number of bits given in `count'. If any nonzero 36*2fe8fb19SBen Grasbits are shifted off, they are ``jammed'' into the least significant bit of 37*2fe8fb19SBen Grasthe result by setting the least significant bit to 1. The value of `count' 38*2fe8fb19SBen Grascan be arbitrarily large; in particular, if `count' is greater than 32, the 39*2fe8fb19SBen Grasresult will be either 0 or 1, depending on whether `a' is zero or nonzero. 40*2fe8fb19SBen GrasThe result is stored in the location pointed to by `zPtr'. 41*2fe8fb19SBen Gras------------------------------------------------------------------------------- 42*2fe8fb19SBen Gras*/ 43*2fe8fb19SBen GrasINLINE void shift32RightJamming( bits32 a, int16 count, bits32 *zPtr ) 44*2fe8fb19SBen Gras{ 45*2fe8fb19SBen Gras bits32 z; 46*2fe8fb19SBen Gras 47*2fe8fb19SBen Gras if ( count == 0 ) { 48*2fe8fb19SBen Gras z = a; 49*2fe8fb19SBen Gras } 50*2fe8fb19SBen Gras else if ( count < 32 ) { 51*2fe8fb19SBen Gras z = ( a>>count ) | ( ( a<<( ( - count ) & 31 ) ) != 0 ); 52*2fe8fb19SBen Gras } 53*2fe8fb19SBen Gras else { 54*2fe8fb19SBen Gras z = ( a != 0 ); 55*2fe8fb19SBen Gras } 56*2fe8fb19SBen Gras *zPtr = z; 57*2fe8fb19SBen Gras 58*2fe8fb19SBen Gras} 59*2fe8fb19SBen Gras 60*2fe8fb19SBen Gras/* 61*2fe8fb19SBen Gras------------------------------------------------------------------------------- 62*2fe8fb19SBen GrasShifts `a' right by the number of bits given in `count'. If any nonzero 63*2fe8fb19SBen Grasbits are shifted off, they are ``jammed'' into the least significant bit of 64*2fe8fb19SBen Grasthe result by setting the least significant bit to 1. The value of `count' 65*2fe8fb19SBen Grascan be arbitrarily large; in particular, if `count' is greater than 64, the 66*2fe8fb19SBen Grasresult will be either 0 or 1, depending on whether `a' is zero or nonzero. 67*2fe8fb19SBen GrasThe result is stored in the location pointed to by `zPtr'. 68*2fe8fb19SBen Gras------------------------------------------------------------------------------- 69*2fe8fb19SBen Gras*/ 70*2fe8fb19SBen GrasINLINE void shift64RightJamming( bits64 a, int16 count, bits64 *zPtr ) 71*2fe8fb19SBen Gras{ 72*2fe8fb19SBen Gras bits64 z; 73*2fe8fb19SBen Gras 74*2fe8fb19SBen Gras if ( count == 0 ) { 75*2fe8fb19SBen Gras z = a; 76*2fe8fb19SBen Gras } 77*2fe8fb19SBen Gras else if ( count < 64 ) { 78*2fe8fb19SBen Gras z = ( a>>count ) | ( ( a<<( ( - count ) & 63 ) ) != 0 ); 79*2fe8fb19SBen Gras } 80*2fe8fb19SBen Gras else { 81*2fe8fb19SBen Gras z = ( a != 0 ); 82*2fe8fb19SBen Gras } 83*2fe8fb19SBen Gras *zPtr = z; 84*2fe8fb19SBen Gras 85*2fe8fb19SBen Gras} 86*2fe8fb19SBen Gras 87*2fe8fb19SBen Gras/* 88*2fe8fb19SBen Gras------------------------------------------------------------------------------- 89*2fe8fb19SBen GrasShifts the 128-bit value formed by concatenating `a0' and `a1' right by 64 90*2fe8fb19SBen Gras_plus_ the number of bits given in `count'. The shifted result is at most 91*2fe8fb19SBen Gras64 nonzero bits; this is stored at the location pointed to by `z0Ptr'. The 92*2fe8fb19SBen Grasbits shifted off form a second 64-bit result as follows: The _last_ bit 93*2fe8fb19SBen Grasshifted off is the most-significant bit of the extra result, and the other 94*2fe8fb19SBen Gras63 bits of the extra result are all zero if and only if _all_but_the_last_ 95*2fe8fb19SBen Grasbits shifted off were all zero. This extra result is stored in the location 96*2fe8fb19SBen Graspointed to by `z1Ptr'. The value of `count' can be arbitrarily large. 97*2fe8fb19SBen Gras (This routine makes more sense if `a0' and `a1' are considered to form a 98*2fe8fb19SBen Grasfixed-point value with binary point between `a0' and `a1'. This fixed-point 99*2fe8fb19SBen Grasvalue is shifted right by the number of bits given in `count', and the 100*2fe8fb19SBen Grasinteger part of the result is returned at the location pointed to by 101*2fe8fb19SBen Gras`z0Ptr'. The fractional part of the result may be slightly corrupted as 102*2fe8fb19SBen Grasdescribed above, and is returned at the location pointed to by `z1Ptr'.) 103*2fe8fb19SBen Gras------------------------------------------------------------------------------- 104*2fe8fb19SBen Gras*/ 105*2fe8fb19SBen GrasINLINE void 106*2fe8fb19SBen Gras shift64ExtraRightJamming( 107*2fe8fb19SBen Gras bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr ) 108*2fe8fb19SBen Gras{ 109*2fe8fb19SBen Gras bits64 z0, z1; 110*2fe8fb19SBen Gras int8 negCount = ( - count ) & 63; 111*2fe8fb19SBen Gras 112*2fe8fb19SBen Gras if ( count == 0 ) { 113*2fe8fb19SBen Gras z1 = a1; 114*2fe8fb19SBen Gras z0 = a0; 115*2fe8fb19SBen Gras } 116*2fe8fb19SBen Gras else if ( count < 64 ) { 117*2fe8fb19SBen Gras z1 = ( a0<<negCount ) | ( a1 != 0 ); 118*2fe8fb19SBen Gras z0 = a0>>count; 119*2fe8fb19SBen Gras } 120*2fe8fb19SBen Gras else { 121*2fe8fb19SBen Gras if ( count == 64 ) { 122*2fe8fb19SBen Gras z1 = a0 | ( a1 != 0 ); 123*2fe8fb19SBen Gras } 124*2fe8fb19SBen Gras else { 125*2fe8fb19SBen Gras z1 = ( ( a0 | a1 ) != 0 ); 126*2fe8fb19SBen Gras } 127*2fe8fb19SBen Gras z0 = 0; 128*2fe8fb19SBen Gras } 129*2fe8fb19SBen Gras *z1Ptr = z1; 130*2fe8fb19SBen Gras *z0Ptr = z0; 131*2fe8fb19SBen Gras 132*2fe8fb19SBen Gras} 133*2fe8fb19SBen Gras 134*2fe8fb19SBen Gras/* 135*2fe8fb19SBen Gras------------------------------------------------------------------------------- 136*2fe8fb19SBen GrasShifts the 128-bit value formed by concatenating `a0' and `a1' right by the 137*2fe8fb19SBen Grasnumber of bits given in `count'. Any bits shifted off are lost. The value 138*2fe8fb19SBen Grasof `count' can be arbitrarily large; in particular, if `count' is greater 139*2fe8fb19SBen Grasthan 128, the result will be 0. The result is broken into two 64-bit pieces 140*2fe8fb19SBen Graswhich are stored at the locations pointed to by `z0Ptr' and `z1Ptr'. 141*2fe8fb19SBen Gras------------------------------------------------------------------------------- 142*2fe8fb19SBen Gras*/ 143*2fe8fb19SBen GrasINLINE void 144*2fe8fb19SBen Gras shift128Right( 145*2fe8fb19SBen Gras bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr ) 146*2fe8fb19SBen Gras{ 147*2fe8fb19SBen Gras bits64 z0, z1; 148*2fe8fb19SBen Gras int8 negCount = ( - count ) & 63; 149*2fe8fb19SBen Gras 150*2fe8fb19SBen Gras if ( count == 0 ) { 151*2fe8fb19SBen Gras z1 = a1; 152*2fe8fb19SBen Gras z0 = a0; 153*2fe8fb19SBen Gras } 154*2fe8fb19SBen Gras else if ( count < 64 ) { 155*2fe8fb19SBen Gras z1 = ( a0<<negCount ) | ( a1>>count ); 156*2fe8fb19SBen Gras z0 = a0>>count; 157*2fe8fb19SBen Gras } 158*2fe8fb19SBen Gras else { 159*2fe8fb19SBen Gras z1 = ( count < 64 ) ? ( a0>>( count & 63 ) ) : 0; 160*2fe8fb19SBen Gras z0 = 0; 161*2fe8fb19SBen Gras } 162*2fe8fb19SBen Gras *z1Ptr = z1; 163*2fe8fb19SBen Gras *z0Ptr = z0; 164*2fe8fb19SBen Gras 165*2fe8fb19SBen Gras} 166*2fe8fb19SBen Gras 167*2fe8fb19SBen Gras/* 168*2fe8fb19SBen Gras------------------------------------------------------------------------------- 169*2fe8fb19SBen GrasShifts the 128-bit value formed by concatenating `a0' and `a1' right by the 170*2fe8fb19SBen Grasnumber of bits given in `count'. If any nonzero bits are shifted off, they 171*2fe8fb19SBen Grasare ``jammed'' into the least significant bit of the result by setting the 172*2fe8fb19SBen Grasleast significant bit to 1. The value of `count' can be arbitrarily large; 173*2fe8fb19SBen Grasin particular, if `count' is greater than 128, the result will be either 174*2fe8fb19SBen Gras0 or 1, depending on whether the concatenation of `a0' and `a1' is zero or 175*2fe8fb19SBen Grasnonzero. The result is broken into two 64-bit pieces which are stored at 176*2fe8fb19SBen Grasthe locations pointed to by `z0Ptr' and `z1Ptr'. 177*2fe8fb19SBen Gras------------------------------------------------------------------------------- 178*2fe8fb19SBen Gras*/ 179*2fe8fb19SBen GrasINLINE void 180*2fe8fb19SBen Gras shift128RightJamming( 181*2fe8fb19SBen Gras bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr ) 182*2fe8fb19SBen Gras{ 183*2fe8fb19SBen Gras bits64 z0, z1; 184*2fe8fb19SBen Gras int8 negCount = ( - count ) & 63; 185*2fe8fb19SBen Gras 186*2fe8fb19SBen Gras if ( count == 0 ) { 187*2fe8fb19SBen Gras z1 = a1; 188*2fe8fb19SBen Gras z0 = a0; 189*2fe8fb19SBen Gras } 190*2fe8fb19SBen Gras else if ( count < 64 ) { 191*2fe8fb19SBen Gras z1 = ( a0<<negCount ) | ( a1>>count ) | ( ( a1<<negCount ) != 0 ); 192*2fe8fb19SBen Gras z0 = a0>>count; 193*2fe8fb19SBen Gras } 194*2fe8fb19SBen Gras else { 195*2fe8fb19SBen Gras if ( count == 64 ) { 196*2fe8fb19SBen Gras z1 = a0 | ( a1 != 0 ); 197*2fe8fb19SBen Gras } 198*2fe8fb19SBen Gras else if ( count < 128 ) { 199*2fe8fb19SBen Gras z1 = ( a0>>( count & 63 ) ) | ( ( ( a0<<negCount ) | a1 ) != 0 ); 200*2fe8fb19SBen Gras } 201*2fe8fb19SBen Gras else { 202*2fe8fb19SBen Gras z1 = ( ( a0 | a1 ) != 0 ); 203*2fe8fb19SBen Gras } 204*2fe8fb19SBen Gras z0 = 0; 205*2fe8fb19SBen Gras } 206*2fe8fb19SBen Gras *z1Ptr = z1; 207*2fe8fb19SBen Gras *z0Ptr = z0; 208*2fe8fb19SBen Gras 209*2fe8fb19SBen Gras} 210*2fe8fb19SBen Gras 211*2fe8fb19SBen Gras/* 212*2fe8fb19SBen Gras------------------------------------------------------------------------------- 213*2fe8fb19SBen GrasShifts the 192-bit value formed by concatenating `a0', `a1', and `a2' right 214*2fe8fb19SBen Grasby 64 _plus_ the number of bits given in `count'. The shifted result is 215*2fe8fb19SBen Grasat most 128 nonzero bits; these are broken into two 64-bit pieces which are 216*2fe8fb19SBen Grasstored at the locations pointed to by `z0Ptr' and `z1Ptr'. The bits shifted 217*2fe8fb19SBen Grasoff form a third 64-bit result as follows: The _last_ bit shifted off is 218*2fe8fb19SBen Grasthe most-significant bit of the extra result, and the other 63 bits of the 219*2fe8fb19SBen Grasextra result are all zero if and only if _all_but_the_last_ bits shifted off 220*2fe8fb19SBen Graswere all zero. This extra result is stored in the location pointed to by 221*2fe8fb19SBen Gras`z2Ptr'. The value of `count' can be arbitrarily large. 222*2fe8fb19SBen Gras (This routine makes more sense if `a0', `a1', and `a2' are considered 223*2fe8fb19SBen Grasto form a fixed-point value with binary point between `a1' and `a2'. This 224*2fe8fb19SBen Grasfixed-point value is shifted right by the number of bits given in `count', 225*2fe8fb19SBen Grasand the integer part of the result is returned at the locations pointed to 226*2fe8fb19SBen Grasby `z0Ptr' and `z1Ptr'. The fractional part of the result may be slightly 227*2fe8fb19SBen Grascorrupted as described above, and is returned at the location pointed to by 228*2fe8fb19SBen Gras`z2Ptr'.) 229*2fe8fb19SBen Gras------------------------------------------------------------------------------- 230*2fe8fb19SBen Gras*/ 231*2fe8fb19SBen GrasINLINE void 232*2fe8fb19SBen Gras shift128ExtraRightJamming( 233*2fe8fb19SBen Gras bits64 a0, 234*2fe8fb19SBen Gras bits64 a1, 235*2fe8fb19SBen Gras bits64 a2, 236*2fe8fb19SBen Gras int16 count, 237*2fe8fb19SBen Gras bits64 *z0Ptr, 238*2fe8fb19SBen Gras bits64 *z1Ptr, 239*2fe8fb19SBen Gras bits64 *z2Ptr 240*2fe8fb19SBen Gras ) 241*2fe8fb19SBen Gras{ 242*2fe8fb19SBen Gras bits64 z0, z1, z2; 243*2fe8fb19SBen Gras int8 negCount = ( - count ) & 63; 244*2fe8fb19SBen Gras 245*2fe8fb19SBen Gras if ( count == 0 ) { 246*2fe8fb19SBen Gras z2 = a2; 247*2fe8fb19SBen Gras z1 = a1; 248*2fe8fb19SBen Gras z0 = a0; 249*2fe8fb19SBen Gras } 250*2fe8fb19SBen Gras else { 251*2fe8fb19SBen Gras if ( count < 64 ) { 252*2fe8fb19SBen Gras z2 = a1<<negCount; 253*2fe8fb19SBen Gras z1 = ( a0<<negCount ) | ( a1>>count ); 254*2fe8fb19SBen Gras z0 = a0>>count; 255*2fe8fb19SBen Gras } 256*2fe8fb19SBen Gras else { 257*2fe8fb19SBen Gras if ( count == 64 ) { 258*2fe8fb19SBen Gras z2 = a1; 259*2fe8fb19SBen Gras z1 = a0; 260*2fe8fb19SBen Gras } 261*2fe8fb19SBen Gras else { 262*2fe8fb19SBen Gras a2 |= a1; 263*2fe8fb19SBen Gras if ( count < 128 ) { 264*2fe8fb19SBen Gras z2 = a0<<negCount; 265*2fe8fb19SBen Gras z1 = a0>>( count & 63 ); 266*2fe8fb19SBen Gras } 267*2fe8fb19SBen Gras else { 268*2fe8fb19SBen Gras z2 = ( count == 128 ) ? a0 : ( a0 != 0 ); 269*2fe8fb19SBen Gras z1 = 0; 270*2fe8fb19SBen Gras } 271*2fe8fb19SBen Gras } 272*2fe8fb19SBen Gras z0 = 0; 273*2fe8fb19SBen Gras } 274*2fe8fb19SBen Gras z2 |= ( a2 != 0 ); 275*2fe8fb19SBen Gras } 276*2fe8fb19SBen Gras *z2Ptr = z2; 277*2fe8fb19SBen Gras *z1Ptr = z1; 278*2fe8fb19SBen Gras *z0Ptr = z0; 279*2fe8fb19SBen Gras 280*2fe8fb19SBen Gras} 281*2fe8fb19SBen Gras 282*2fe8fb19SBen Gras/* 283*2fe8fb19SBen Gras------------------------------------------------------------------------------- 284*2fe8fb19SBen GrasShifts the 128-bit value formed by concatenating `a0' and `a1' left by the 285*2fe8fb19SBen Grasnumber of bits given in `count'. Any bits shifted off are lost. The value 286*2fe8fb19SBen Grasof `count' must be less than 64. The result is broken into two 64-bit 287*2fe8fb19SBen Graspieces which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'. 288*2fe8fb19SBen Gras------------------------------------------------------------------------------- 289*2fe8fb19SBen Gras*/ 290*2fe8fb19SBen GrasINLINE void 291*2fe8fb19SBen Gras shortShift128Left( 292*2fe8fb19SBen Gras bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr ) 293*2fe8fb19SBen Gras{ 294*2fe8fb19SBen Gras 295*2fe8fb19SBen Gras *z1Ptr = a1<<count; 296*2fe8fb19SBen Gras *z0Ptr = 297*2fe8fb19SBen Gras ( count == 0 ) ? a0 : ( a0<<count ) | ( a1>>( ( - count ) & 63 ) ); 298*2fe8fb19SBen Gras 299*2fe8fb19SBen Gras} 300*2fe8fb19SBen Gras 301*2fe8fb19SBen Gras/* 302*2fe8fb19SBen Gras------------------------------------------------------------------------------- 303*2fe8fb19SBen GrasShifts the 192-bit value formed by concatenating `a0', `a1', and `a2' left 304*2fe8fb19SBen Grasby the number of bits given in `count'. Any bits shifted off are lost. 305*2fe8fb19SBen GrasThe value of `count' must be less than 64. The result is broken into three 306*2fe8fb19SBen Gras64-bit pieces which are stored at the locations pointed to by `z0Ptr', 307*2fe8fb19SBen Gras`z1Ptr', and `z2Ptr'. 308*2fe8fb19SBen Gras------------------------------------------------------------------------------- 309*2fe8fb19SBen Gras*/ 310*2fe8fb19SBen GrasINLINE void 311*2fe8fb19SBen Gras shortShift192Left( 312*2fe8fb19SBen Gras bits64 a0, 313*2fe8fb19SBen Gras bits64 a1, 314*2fe8fb19SBen Gras bits64 a2, 315*2fe8fb19SBen Gras int16 count, 316*2fe8fb19SBen Gras bits64 *z0Ptr, 317*2fe8fb19SBen Gras bits64 *z1Ptr, 318*2fe8fb19SBen Gras bits64 *z2Ptr 319*2fe8fb19SBen Gras ) 320*2fe8fb19SBen Gras{ 321*2fe8fb19SBen Gras bits64 z0, z1, z2; 322*2fe8fb19SBen Gras int8 negCount; 323*2fe8fb19SBen Gras 324*2fe8fb19SBen Gras z2 = a2<<count; 325*2fe8fb19SBen Gras z1 = a1<<count; 326*2fe8fb19SBen Gras z0 = a0<<count; 327*2fe8fb19SBen Gras if ( 0 < count ) { 328*2fe8fb19SBen Gras negCount = ( ( - count ) & 63 ); 329*2fe8fb19SBen Gras z1 |= a2>>negCount; 330*2fe8fb19SBen Gras z0 |= a1>>negCount; 331*2fe8fb19SBen Gras } 332*2fe8fb19SBen Gras *z2Ptr = z2; 333*2fe8fb19SBen Gras *z1Ptr = z1; 334*2fe8fb19SBen Gras *z0Ptr = z0; 335*2fe8fb19SBen Gras 336*2fe8fb19SBen Gras} 337*2fe8fb19SBen Gras 338*2fe8fb19SBen Gras/* 339*2fe8fb19SBen Gras------------------------------------------------------------------------------- 340*2fe8fb19SBen GrasAdds the 128-bit value formed by concatenating `a0' and `a1' to the 128-bit 341*2fe8fb19SBen Grasvalue formed by concatenating `b0' and `b1'. Addition is modulo 2^128, so 342*2fe8fb19SBen Grasany carry out is lost. The result is broken into two 64-bit pieces which 343*2fe8fb19SBen Grasare stored at the locations pointed to by `z0Ptr' and `z1Ptr'. 344*2fe8fb19SBen Gras------------------------------------------------------------------------------- 345*2fe8fb19SBen Gras*/ 346*2fe8fb19SBen GrasINLINE void 347*2fe8fb19SBen Gras add128( 348*2fe8fb19SBen Gras bits64 a0, bits64 a1, bits64 b0, bits64 b1, bits64 *z0Ptr, bits64 *z1Ptr ) 349*2fe8fb19SBen Gras{ 350*2fe8fb19SBen Gras bits64 z1; 351*2fe8fb19SBen Gras 352*2fe8fb19SBen Gras z1 = a1 + b1; 353*2fe8fb19SBen Gras *z1Ptr = z1; 354*2fe8fb19SBen Gras *z0Ptr = a0 + b0 + ( z1 < a1 ); 355*2fe8fb19SBen Gras 356*2fe8fb19SBen Gras} 357*2fe8fb19SBen Gras 358*2fe8fb19SBen Gras/* 359*2fe8fb19SBen Gras------------------------------------------------------------------------------- 360*2fe8fb19SBen GrasAdds the 192-bit value formed by concatenating `a0', `a1', and `a2' to the 361*2fe8fb19SBen Gras192-bit value formed by concatenating `b0', `b1', and `b2'. Addition is 362*2fe8fb19SBen Grasmodulo 2^192, so any carry out is lost. The result is broken into three 363*2fe8fb19SBen Gras64-bit pieces which are stored at the locations pointed to by `z0Ptr', 364*2fe8fb19SBen Gras`z1Ptr', and `z2Ptr'. 365*2fe8fb19SBen Gras------------------------------------------------------------------------------- 366*2fe8fb19SBen Gras*/ 367*2fe8fb19SBen GrasINLINE void 368*2fe8fb19SBen Gras add192( 369*2fe8fb19SBen Gras bits64 a0, 370*2fe8fb19SBen Gras bits64 a1, 371*2fe8fb19SBen Gras bits64 a2, 372*2fe8fb19SBen Gras bits64 b0, 373*2fe8fb19SBen Gras bits64 b1, 374*2fe8fb19SBen Gras bits64 b2, 375*2fe8fb19SBen Gras bits64 *z0Ptr, 376*2fe8fb19SBen Gras bits64 *z1Ptr, 377*2fe8fb19SBen Gras bits64 *z2Ptr 378*2fe8fb19SBen Gras ) 379*2fe8fb19SBen Gras{ 380*2fe8fb19SBen Gras bits64 z0, z1, z2; 381*2fe8fb19SBen Gras int8 carry0, carry1; 382*2fe8fb19SBen Gras 383*2fe8fb19SBen Gras z2 = a2 + b2; 384*2fe8fb19SBen Gras carry1 = ( z2 < a2 ); 385*2fe8fb19SBen Gras z1 = a1 + b1; 386*2fe8fb19SBen Gras carry0 = ( z1 < a1 ); 387*2fe8fb19SBen Gras z0 = a0 + b0; 388*2fe8fb19SBen Gras z1 += carry1; 389*2fe8fb19SBen Gras z0 += ( z1 < (bits64)carry1 ); 390*2fe8fb19SBen Gras z0 += carry0; 391*2fe8fb19SBen Gras *z2Ptr = z2; 392*2fe8fb19SBen Gras *z1Ptr = z1; 393*2fe8fb19SBen Gras *z0Ptr = z0; 394*2fe8fb19SBen Gras 395*2fe8fb19SBen Gras} 396*2fe8fb19SBen Gras 397*2fe8fb19SBen Gras/* 398*2fe8fb19SBen Gras------------------------------------------------------------------------------- 399*2fe8fb19SBen GrasSubtracts the 128-bit value formed by concatenating `b0' and `b1' from the 400*2fe8fb19SBen Gras128-bit value formed by concatenating `a0' and `a1'. Subtraction is modulo 401*2fe8fb19SBen Gras2^128, so any borrow out (carry out) is lost. The result is broken into two 402*2fe8fb19SBen Gras64-bit pieces which are stored at the locations pointed to by `z0Ptr' and 403*2fe8fb19SBen Gras`z1Ptr'. 404*2fe8fb19SBen Gras------------------------------------------------------------------------------- 405*2fe8fb19SBen Gras*/ 406*2fe8fb19SBen GrasINLINE void 407*2fe8fb19SBen Gras sub128( 408*2fe8fb19SBen Gras bits64 a0, bits64 a1, bits64 b0, bits64 b1, bits64 *z0Ptr, bits64 *z1Ptr ) 409*2fe8fb19SBen Gras{ 410*2fe8fb19SBen Gras 411*2fe8fb19SBen Gras *z1Ptr = a1 - b1; 412*2fe8fb19SBen Gras *z0Ptr = a0 - b0 - ( a1 < b1 ); 413*2fe8fb19SBen Gras 414*2fe8fb19SBen Gras} 415*2fe8fb19SBen Gras 416*2fe8fb19SBen Gras/* 417*2fe8fb19SBen Gras------------------------------------------------------------------------------- 418*2fe8fb19SBen GrasSubtracts the 192-bit value formed by concatenating `b0', `b1', and `b2' 419*2fe8fb19SBen Grasfrom the 192-bit value formed by concatenating `a0', `a1', and `a2'. 420*2fe8fb19SBen GrasSubtraction is modulo 2^192, so any borrow out (carry out) is lost. The 421*2fe8fb19SBen Grasresult is broken into three 64-bit pieces which are stored at the locations 422*2fe8fb19SBen Graspointed to by `z0Ptr', `z1Ptr', and `z2Ptr'. 423*2fe8fb19SBen Gras------------------------------------------------------------------------------- 424*2fe8fb19SBen Gras*/ 425*2fe8fb19SBen GrasINLINE void 426*2fe8fb19SBen Gras sub192( 427*2fe8fb19SBen Gras bits64 a0, 428*2fe8fb19SBen Gras bits64 a1, 429*2fe8fb19SBen Gras bits64 a2, 430*2fe8fb19SBen Gras bits64 b0, 431*2fe8fb19SBen Gras bits64 b1, 432*2fe8fb19SBen Gras bits64 b2, 433*2fe8fb19SBen Gras bits64 *z0Ptr, 434*2fe8fb19SBen Gras bits64 *z1Ptr, 435*2fe8fb19SBen Gras bits64 *z2Ptr 436*2fe8fb19SBen Gras ) 437*2fe8fb19SBen Gras{ 438*2fe8fb19SBen Gras bits64 z0, z1, z2; 439*2fe8fb19SBen Gras int8 borrow0, borrow1; 440*2fe8fb19SBen Gras 441*2fe8fb19SBen Gras z2 = a2 - b2; 442*2fe8fb19SBen Gras borrow1 = ( a2 < b2 ); 443*2fe8fb19SBen Gras z1 = a1 - b1; 444*2fe8fb19SBen Gras borrow0 = ( a1 < b1 ); 445*2fe8fb19SBen Gras z0 = a0 - b0; 446*2fe8fb19SBen Gras z0 -= ( z1 < (bits64)borrow1 ); 447*2fe8fb19SBen Gras z1 -= borrow1; 448*2fe8fb19SBen Gras z0 -= borrow0; 449*2fe8fb19SBen Gras *z2Ptr = z2; 450*2fe8fb19SBen Gras *z1Ptr = z1; 451*2fe8fb19SBen Gras *z0Ptr = z0; 452*2fe8fb19SBen Gras 453*2fe8fb19SBen Gras} 454*2fe8fb19SBen Gras 455*2fe8fb19SBen Gras/* 456*2fe8fb19SBen Gras------------------------------------------------------------------------------- 457*2fe8fb19SBen GrasMultiplies `a' by `b' to obtain a 128-bit product. The product is broken 458*2fe8fb19SBen Grasinto two 64-bit pieces which are stored at the locations pointed to by 459*2fe8fb19SBen Gras`z0Ptr' and `z1Ptr'. 460*2fe8fb19SBen Gras------------------------------------------------------------------------------- 461*2fe8fb19SBen Gras*/ 462*2fe8fb19SBen GrasINLINE void mul64To128( bits64 a, bits64 b, bits64 *z0Ptr, bits64 *z1Ptr ) 463*2fe8fb19SBen Gras{ 464*2fe8fb19SBen Gras bits32 aHigh, aLow, bHigh, bLow; 465*2fe8fb19SBen Gras bits64 z0, zMiddleA, zMiddleB, z1; 466*2fe8fb19SBen Gras 467*2fe8fb19SBen Gras aLow = a; 468*2fe8fb19SBen Gras aHigh = a>>32; 469*2fe8fb19SBen Gras bLow = b; 470*2fe8fb19SBen Gras bHigh = b>>32; 471*2fe8fb19SBen Gras z1 = ( (bits64) aLow ) * bLow; 472*2fe8fb19SBen Gras zMiddleA = ( (bits64) aLow ) * bHigh; 473*2fe8fb19SBen Gras zMiddleB = ( (bits64) aHigh ) * bLow; 474*2fe8fb19SBen Gras z0 = ( (bits64) aHigh ) * bHigh; 475*2fe8fb19SBen Gras zMiddleA += zMiddleB; 476*2fe8fb19SBen Gras z0 += ( ( (bits64) ( zMiddleA < zMiddleB ) )<<32 ) + ( zMiddleA>>32 ); 477*2fe8fb19SBen Gras zMiddleA <<= 32; 478*2fe8fb19SBen Gras z1 += zMiddleA; 479*2fe8fb19SBen Gras z0 += ( z1 < zMiddleA ); 480*2fe8fb19SBen Gras *z1Ptr = z1; 481*2fe8fb19SBen Gras *z0Ptr = z0; 482*2fe8fb19SBen Gras 483*2fe8fb19SBen Gras} 484*2fe8fb19SBen Gras 485*2fe8fb19SBen Gras/* 486*2fe8fb19SBen Gras------------------------------------------------------------------------------- 487*2fe8fb19SBen GrasMultiplies the 128-bit value formed by concatenating `a0' and `a1' by 488*2fe8fb19SBen Gras`b' to obtain a 192-bit product. The product is broken into three 64-bit 489*2fe8fb19SBen Graspieces which are stored at the locations pointed to by `z0Ptr', `z1Ptr', and 490*2fe8fb19SBen Gras`z2Ptr'. 491*2fe8fb19SBen Gras------------------------------------------------------------------------------- 492*2fe8fb19SBen Gras*/ 493*2fe8fb19SBen GrasINLINE void 494*2fe8fb19SBen Gras mul128By64To192( 495*2fe8fb19SBen Gras bits64 a0, 496*2fe8fb19SBen Gras bits64 a1, 497*2fe8fb19SBen Gras bits64 b, 498*2fe8fb19SBen Gras bits64 *z0Ptr, 499*2fe8fb19SBen Gras bits64 *z1Ptr, 500*2fe8fb19SBen Gras bits64 *z2Ptr 501*2fe8fb19SBen Gras ) 502*2fe8fb19SBen Gras{ 503*2fe8fb19SBen Gras bits64 z0, z1, z2, more1; 504*2fe8fb19SBen Gras 505*2fe8fb19SBen Gras mul64To128( a1, b, &z1, &z2 ); 506*2fe8fb19SBen Gras mul64To128( a0, b, &z0, &more1 ); 507*2fe8fb19SBen Gras add128( z0, more1, 0, z1, &z0, &z1 ); 508*2fe8fb19SBen Gras *z2Ptr = z2; 509*2fe8fb19SBen Gras *z1Ptr = z1; 510*2fe8fb19SBen Gras *z0Ptr = z0; 511*2fe8fb19SBen Gras 512*2fe8fb19SBen Gras} 513*2fe8fb19SBen Gras 514*2fe8fb19SBen Gras/* 515*2fe8fb19SBen Gras------------------------------------------------------------------------------- 516*2fe8fb19SBen GrasMultiplies the 128-bit value formed by concatenating `a0' and `a1' to the 517*2fe8fb19SBen Gras128-bit value formed by concatenating `b0' and `b1' to obtain a 256-bit 518*2fe8fb19SBen Grasproduct. The product is broken into four 64-bit pieces which are stored at 519*2fe8fb19SBen Grasthe locations pointed to by `z0Ptr', `z1Ptr', `z2Ptr', and `z3Ptr'. 520*2fe8fb19SBen Gras------------------------------------------------------------------------------- 521*2fe8fb19SBen Gras*/ 522*2fe8fb19SBen GrasINLINE void 523*2fe8fb19SBen Gras mul128To256( 524*2fe8fb19SBen Gras bits64 a0, 525*2fe8fb19SBen Gras bits64 a1, 526*2fe8fb19SBen Gras bits64 b0, 527*2fe8fb19SBen Gras bits64 b1, 528*2fe8fb19SBen Gras bits64 *z0Ptr, 529*2fe8fb19SBen Gras bits64 *z1Ptr, 530*2fe8fb19SBen Gras bits64 *z2Ptr, 531*2fe8fb19SBen Gras bits64 *z3Ptr 532*2fe8fb19SBen Gras ) 533*2fe8fb19SBen Gras{ 534*2fe8fb19SBen Gras bits64 z0, z1, z2, z3; 535*2fe8fb19SBen Gras bits64 more1, more2; 536*2fe8fb19SBen Gras 537*2fe8fb19SBen Gras mul64To128( a1, b1, &z2, &z3 ); 538*2fe8fb19SBen Gras mul64To128( a1, b0, &z1, &more2 ); 539*2fe8fb19SBen Gras add128( z1, more2, 0, z2, &z1, &z2 ); 540*2fe8fb19SBen Gras mul64To128( a0, b0, &z0, &more1 ); 541*2fe8fb19SBen Gras add128( z0, more1, 0, z1, &z0, &z1 ); 542*2fe8fb19SBen Gras mul64To128( a0, b1, &more1, &more2 ); 543*2fe8fb19SBen Gras add128( more1, more2, 0, z2, &more1, &z2 ); 544*2fe8fb19SBen Gras add128( z0, z1, 0, more1, &z0, &z1 ); 545*2fe8fb19SBen Gras *z3Ptr = z3; 546*2fe8fb19SBen Gras *z2Ptr = z2; 547*2fe8fb19SBen Gras *z1Ptr = z1; 548*2fe8fb19SBen Gras *z0Ptr = z0; 549*2fe8fb19SBen Gras 550*2fe8fb19SBen Gras} 551*2fe8fb19SBen Gras 552*2fe8fb19SBen Gras/* 553*2fe8fb19SBen Gras------------------------------------------------------------------------------- 554*2fe8fb19SBen GrasReturns an approximation to the 64-bit integer quotient obtained by dividing 555*2fe8fb19SBen Gras`b' into the 128-bit value formed by concatenating `a0' and `a1'. The 556*2fe8fb19SBen Grasdivisor `b' must be at least 2^63. If q is the exact quotient truncated 557*2fe8fb19SBen Grastoward zero, the approximation returned lies between q and q + 2 inclusive. 558*2fe8fb19SBen GrasIf the exact quotient q is larger than 64 bits, the maximum positive 64-bit 559*2fe8fb19SBen Grasunsigned integer is returned. 560*2fe8fb19SBen Gras------------------------------------------------------------------------------- 561*2fe8fb19SBen Gras*/ 562*2fe8fb19SBen Grasstatic bits64 estimateDiv128To64( bits64 a0, bits64 a1, bits64 b ) 563*2fe8fb19SBen Gras{ 564*2fe8fb19SBen Gras bits64 b0, b1; 565*2fe8fb19SBen Gras bits64 rem0, rem1, term0, term1; 566*2fe8fb19SBen Gras bits64 z; 567*2fe8fb19SBen Gras 568*2fe8fb19SBen Gras if ( b <= a0 ) return LIT64( 0xFFFFFFFFFFFFFFFF ); 569*2fe8fb19SBen Gras b0 = b>>32; 570*2fe8fb19SBen Gras z = ( b0<<32 <= a0 ) ? LIT64( 0xFFFFFFFF00000000 ) : ( a0 / b0 )<<32; 571*2fe8fb19SBen Gras mul64To128( b, z, &term0, &term1 ); 572*2fe8fb19SBen Gras sub128( a0, a1, term0, term1, &rem0, &rem1 ); 573*2fe8fb19SBen Gras while ( ( (sbits64) rem0 ) < 0 ) { 574*2fe8fb19SBen Gras z -= LIT64( 0x100000000 ); 575*2fe8fb19SBen Gras b1 = b<<32; 576*2fe8fb19SBen Gras add128( rem0, rem1, b0, b1, &rem0, &rem1 ); 577*2fe8fb19SBen Gras } 578*2fe8fb19SBen Gras rem0 = ( rem0<<32 ) | ( rem1>>32 ); 579*2fe8fb19SBen Gras z |= ( b0<<32 <= rem0 ) ? 0xFFFFFFFF : rem0 / b0; 580*2fe8fb19SBen Gras return z; 581*2fe8fb19SBen Gras 582*2fe8fb19SBen Gras} 583*2fe8fb19SBen Gras 584*2fe8fb19SBen Gras#if !defined(SOFTFLOAT_FOR_GCC) || defined(FLOATX80) || defined(FLOAT128) 585*2fe8fb19SBen Gras/* 586*2fe8fb19SBen Gras------------------------------------------------------------------------------- 587*2fe8fb19SBen GrasReturns an approximation to the square root of the 32-bit significand given 588*2fe8fb19SBen Grasby `a'. Considered as an integer, `a' must be at least 2^31. If bit 0 of 589*2fe8fb19SBen Gras`aExp' (the least significant bit) is 1, the integer returned approximates 590*2fe8fb19SBen Gras2^31*sqrt(`a'/2^31), where `a' is considered an integer. If bit 0 of `aExp' 591*2fe8fb19SBen Grasis 0, the integer returned approximates 2^31*sqrt(`a'/2^30). In either 592*2fe8fb19SBen Grascase, the approximation returned lies strictly within +/-2 of the exact 593*2fe8fb19SBen Grasvalue. 594*2fe8fb19SBen Gras------------------------------------------------------------------------------- 595*2fe8fb19SBen Gras*/ 596*2fe8fb19SBen Grasstatic bits32 estimateSqrt32( int16 aExp, bits32 a ) 597*2fe8fb19SBen Gras{ 598*2fe8fb19SBen Gras static const bits16 sqrtOddAdjustments[] = { 599*2fe8fb19SBen Gras 0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0, 600*2fe8fb19SBen Gras 0x039C, 0x0468, 0x0545, 0x0631, 0x072B, 0x0832, 0x0946, 0x0A67 601*2fe8fb19SBen Gras }; 602*2fe8fb19SBen Gras static const bits16 sqrtEvenAdjustments[] = { 603*2fe8fb19SBen Gras 0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E, 604*2fe8fb19SBen Gras 0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002 605*2fe8fb19SBen Gras }; 606*2fe8fb19SBen Gras int8 idx; 607*2fe8fb19SBen Gras bits32 z; 608*2fe8fb19SBen Gras 609*2fe8fb19SBen Gras idx = ( a>>27 ) & 15; 610*2fe8fb19SBen Gras if ( aExp & 1 ) { 611*2fe8fb19SBen Gras z = 0x4000 + ( a>>17 ) - sqrtOddAdjustments[ idx ]; 612*2fe8fb19SBen Gras z = ( ( a / z )<<14 ) + ( z<<15 ); 613*2fe8fb19SBen Gras a >>= 1; 614*2fe8fb19SBen Gras } 615*2fe8fb19SBen Gras else { 616*2fe8fb19SBen Gras z = 0x8000 + ( a>>17 ) - sqrtEvenAdjustments[ idx ]; 617*2fe8fb19SBen Gras z = a / z + z; 618*2fe8fb19SBen Gras z = ( 0x20000 <= z ) ? 0xFFFF8000 : ( z<<15 ); 619*2fe8fb19SBen Gras if ( z <= a ) return (bits32) ( ( (sbits32) a )>>1 ); 620*2fe8fb19SBen Gras } 621*2fe8fb19SBen Gras return ( (bits32) ( ( ( (bits64) a )<<31 ) / z ) ) + ( z>>1 ); 622*2fe8fb19SBen Gras 623*2fe8fb19SBen Gras} 624*2fe8fb19SBen Gras#endif 625*2fe8fb19SBen Gras 626*2fe8fb19SBen Gras/* 627*2fe8fb19SBen Gras------------------------------------------------------------------------------- 628*2fe8fb19SBen GrasReturns the number of leading 0 bits before the most-significant 1 bit of 629*2fe8fb19SBen Gras`a'. If `a' is zero, 32 is returned. 630*2fe8fb19SBen Gras------------------------------------------------------------------------------- 631*2fe8fb19SBen Gras*/ 632*2fe8fb19SBen Grasstatic int8 countLeadingZeros32( bits32 a ) 633*2fe8fb19SBen Gras{ 634*2fe8fb19SBen Gras static const int8 countLeadingZerosHigh[] = { 635*2fe8fb19SBen Gras 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 636*2fe8fb19SBen Gras 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 637*2fe8fb19SBen Gras 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 638*2fe8fb19SBen Gras 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 639*2fe8fb19SBen Gras 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 640*2fe8fb19SBen Gras 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 641*2fe8fb19SBen Gras 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 642*2fe8fb19SBen Gras 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 643*2fe8fb19SBen Gras 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 644*2fe8fb19SBen Gras 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 645*2fe8fb19SBen Gras 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 646*2fe8fb19SBen Gras 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 647*2fe8fb19SBen Gras 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 648*2fe8fb19SBen Gras 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 649*2fe8fb19SBen Gras 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 650*2fe8fb19SBen Gras 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 651*2fe8fb19SBen Gras }; 652*2fe8fb19SBen Gras int8 shiftCount; 653*2fe8fb19SBen Gras 654*2fe8fb19SBen Gras shiftCount = 0; 655*2fe8fb19SBen Gras if ( a < 0x10000 ) { 656*2fe8fb19SBen Gras shiftCount += 16; 657*2fe8fb19SBen Gras a <<= 16; 658*2fe8fb19SBen Gras } 659*2fe8fb19SBen Gras if ( a < 0x1000000 ) { 660*2fe8fb19SBen Gras shiftCount += 8; 661*2fe8fb19SBen Gras a <<= 8; 662*2fe8fb19SBen Gras } 663*2fe8fb19SBen Gras shiftCount += countLeadingZerosHigh[ a>>24 ]; 664*2fe8fb19SBen Gras return shiftCount; 665*2fe8fb19SBen Gras 666*2fe8fb19SBen Gras} 667*2fe8fb19SBen Gras 668*2fe8fb19SBen Gras/* 669*2fe8fb19SBen Gras------------------------------------------------------------------------------- 670*2fe8fb19SBen GrasReturns the number of leading 0 bits before the most-significant 1 bit of 671*2fe8fb19SBen Gras`a'. If `a' is zero, 64 is returned. 672*2fe8fb19SBen Gras------------------------------------------------------------------------------- 673*2fe8fb19SBen Gras*/ 674*2fe8fb19SBen Grasstatic int8 countLeadingZeros64( bits64 a ) 675*2fe8fb19SBen Gras{ 676*2fe8fb19SBen Gras int8 shiftCount; 677*2fe8fb19SBen Gras 678*2fe8fb19SBen Gras shiftCount = 0; 679*2fe8fb19SBen Gras if ( a < ( (bits64) 1 )<<32 ) { 680*2fe8fb19SBen Gras shiftCount += 32; 681*2fe8fb19SBen Gras } 682*2fe8fb19SBen Gras else { 683*2fe8fb19SBen Gras a >>= 32; 684*2fe8fb19SBen Gras } 685*2fe8fb19SBen Gras shiftCount += countLeadingZeros32( a ); 686*2fe8fb19SBen Gras return shiftCount; 687*2fe8fb19SBen Gras 688*2fe8fb19SBen Gras} 689*2fe8fb19SBen Gras 690*2fe8fb19SBen Gras/* 691*2fe8fb19SBen Gras------------------------------------------------------------------------------- 692*2fe8fb19SBen GrasReturns 1 if the 128-bit value formed by concatenating `a0' and `a1' 693*2fe8fb19SBen Grasis equal to the 128-bit value formed by concatenating `b0' and `b1'. 694*2fe8fb19SBen GrasOtherwise, returns 0. 695*2fe8fb19SBen Gras------------------------------------------------------------------------------- 696*2fe8fb19SBen Gras*/ 697*2fe8fb19SBen GrasINLINE flag eq128( bits64 a0, bits64 a1, bits64 b0, bits64 b1 ) 698*2fe8fb19SBen Gras{ 699*2fe8fb19SBen Gras 700*2fe8fb19SBen Gras return ( a0 == b0 ) && ( a1 == b1 ); 701*2fe8fb19SBen Gras 702*2fe8fb19SBen Gras} 703*2fe8fb19SBen Gras 704*2fe8fb19SBen Gras/* 705*2fe8fb19SBen Gras------------------------------------------------------------------------------- 706*2fe8fb19SBen GrasReturns 1 if the 128-bit value formed by concatenating `a0' and `a1' is less 707*2fe8fb19SBen Grasthan or equal to the 128-bit value formed by concatenating `b0' and `b1'. 708*2fe8fb19SBen GrasOtherwise, returns 0. 709*2fe8fb19SBen Gras------------------------------------------------------------------------------- 710*2fe8fb19SBen Gras*/ 711*2fe8fb19SBen GrasINLINE flag le128( bits64 a0, bits64 a1, bits64 b0, bits64 b1 ) 712*2fe8fb19SBen Gras{ 713*2fe8fb19SBen Gras 714*2fe8fb19SBen Gras return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 <= b1 ) ); 715*2fe8fb19SBen Gras 716*2fe8fb19SBen Gras} 717*2fe8fb19SBen Gras 718*2fe8fb19SBen Gras/* 719*2fe8fb19SBen Gras------------------------------------------------------------------------------- 720*2fe8fb19SBen GrasReturns 1 if the 128-bit value formed by concatenating `a0' and `a1' is less 721*2fe8fb19SBen Grasthan the 128-bit value formed by concatenating `b0' and `b1'. Otherwise, 722*2fe8fb19SBen Grasreturns 0. 723*2fe8fb19SBen Gras------------------------------------------------------------------------------- 724*2fe8fb19SBen Gras*/ 725*2fe8fb19SBen GrasINLINE flag lt128( bits64 a0, bits64 a1, bits64 b0, bits64 b1 ) 726*2fe8fb19SBen Gras{ 727*2fe8fb19SBen Gras 728*2fe8fb19SBen Gras return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 < b1 ) ); 729*2fe8fb19SBen Gras 730*2fe8fb19SBen Gras} 731*2fe8fb19SBen Gras 732*2fe8fb19SBen Gras/* 733*2fe8fb19SBen Gras------------------------------------------------------------------------------- 734*2fe8fb19SBen GrasReturns 1 if the 128-bit value formed by concatenating `a0' and `a1' is 735*2fe8fb19SBen Grasnot equal to the 128-bit value formed by concatenating `b0' and `b1'. 736*2fe8fb19SBen GrasOtherwise, returns 0. 737*2fe8fb19SBen Gras------------------------------------------------------------------------------- 738*2fe8fb19SBen Gras*/ 739*2fe8fb19SBen GrasINLINE flag ne128( bits64 a0, bits64 a1, bits64 b0, bits64 b1 ) 740*2fe8fb19SBen Gras{ 741*2fe8fb19SBen Gras 742*2fe8fb19SBen Gras return ( a0 != b0 ) || ( a1 != b1 ); 743*2fe8fb19SBen Gras 744*2fe8fb19SBen Gras} 745*2fe8fb19SBen Gras 746