Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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