📄 softfloat-macros
字号:
/*===============================================================================This C source fragment is part of the SoftFloat IEC/IEEE Floating-pointArithmetic Package, Release 2.Written by John R. Hauser. This work was made possible in part by theInternational Computer Science Institute, located at Suite 600, 1947 CenterStreet, Berkeley, California 94704. Funding was partially provided by theNational Science Foundation under grant MIP-9311980. The original versionof this code was written as part of a project to build a fixed-point vectorprocessor in collaboration with the University of California at Berkeley,overseen by Profs. Nelson Morgan and John Wawrzynek. More informationis available through the web page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/softfloat.html'.THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable efforthas been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL ATTIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TOPERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANYAND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.Derivative works are acceptable, even for commercial purposes, so long as(1) they include prominent notice that the work is derivative, and (2) theyinclude prominent notice akin to these three paragraphs for those parts ofthis code that are retained.===============================================================================*//*-------------------------------------------------------------------------------Shifts `a' right by the number of bits given in `count'. If any nonzerobits are shifted off, they are ``jammed'' into the least significant bit ofthe result by setting the least significant bit to 1. The value of `count'can be arbitrarily large; in particular, if `count' is greater than 32, theresult will be either 0 or 1, depending on whether `a' is zero or nonzero.The result is stored in the location pointed to by `zPtr'.-------------------------------------------------------------------------------*/INLINE void shift32RightJamming( bits32 a, int16 count, bits32 *zPtr ){ bits32 z; if ( count == 0 ) { z = a; } else if ( count < 32 ) { z = ( a>>count ) | ( ( a<<( ( - count ) & 31 ) ) != 0 ); } else { z = ( a != 0 ); } *zPtr = z;}/*-------------------------------------------------------------------------------Shifts `a' right by the number of bits given in `count'. If any nonzerobits are shifted off, they are ``jammed'' into the least significant bit ofthe result by setting the least significant bit to 1. The value of `count'can be arbitrarily large; in particular, if `count' is greater than 64, theresult will be either 0 or 1, depending on whether `a' is zero or nonzero.The result is stored in the location pointed to by `zPtr'.-------------------------------------------------------------------------------*/INLINE void shift64RightJamming( bits64 a, int16 count, bits64 *zPtr ){ bits64 z; __asm__("@shift64RightJamming -- start"); if ( count == 0 ) { z = a; } else if ( count < 64 ) { z = ( a>>count ) | ( ( a<<( ( - count ) & 63 ) ) != 0 ); } else { z = ( a != 0 ); } __asm__("@shift64RightJamming -- end"); *zPtr = z;}/*-------------------------------------------------------------------------------Shifts the 128-bit value formed by concatenating `a0' and `a1' right by 64_plus_ the number of bits given in `count'. The shifted result is at most64 nonzero bits; this is stored at the location pointed to by `z0Ptr'. Thebits shifted off form a second 64-bit result as follows: The _last_ bitshifted off is the most-significant bit of the extra result, and the other63 bits of the extra result are all zero if and only if _all_but_the_last_bits shifted off were all zero. This extra result is stored in the locationpointed to by `z1Ptr'. The value of `count' can be arbitrarily large. (This routine makes more sense if `a0' and `a1' are considered to form afixed-point value with binary point between `a0' and `a1'. This fixed-pointvalue is shifted right by the number of bits given in `count', and theinteger part of the result is returned at the location pointed to by`z0Ptr'. The fractional part of the result may be slightly corrupted asdescribed above, and is returned at the location pointed to by `z1Ptr'.)-------------------------------------------------------------------------------*/INLINE void shift64ExtraRightJamming( bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr ){ bits64 z0, z1; int8 negCount = ( - count ) & 63; if ( count == 0 ) { z1 = a1; z0 = a0; } else if ( count < 64 ) { z1 = ( a0<<negCount ) | ( a1 != 0 ); z0 = a0>>count; } else { if ( count == 64 ) { z1 = a0 | ( a1 != 0 ); } else { z1 = ( ( a0 | a1 ) != 0 ); } z0 = 0; } *z1Ptr = z1; *z0Ptr = z0;}/*-------------------------------------------------------------------------------Shifts the 128-bit value formed by concatenating `a0' and `a1' right by thenumber of bits given in `count'. Any bits shifted off are lost. The valueof `count' can be arbitrarily large; in particular, if `count' is greaterthan 128, the result will be 0. The result is broken into two 64-bit pieceswhich are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.-------------------------------------------------------------------------------*/INLINE void shift128Right( bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr ){ bits64 z0, z1; int8 negCount = ( - count ) & 63; if ( count == 0 ) { z1 = a1; z0 = a0; } else if ( count < 64 ) { z1 = ( a0<<negCount ) | ( a1>>count ); z0 = a0>>count; } else { z1 = ( count < 64 ) ? ( a0>>( count & 63 ) ) : 0; z0 = 0; } *z1Ptr = z1; *z0Ptr = z0;}/*-------------------------------------------------------------------------------Shifts the 128-bit value formed by concatenating `a0' and `a1' right by thenumber of bits given in `count'. If any nonzero bits are shifted off, theyare ``jammed'' into the least significant bit of the result by setting theleast significant bit to 1. The value of `count' can be arbitrarily large;in particular, if `count' is greater than 128, the result will be either 0or 1, depending on whether the concatenation of `a0' and `a1' is zero ornonzero. The result is broken into two 64-bit pieces which are stored atthe locations pointed to by `z0Ptr' and `z1Ptr'.-------------------------------------------------------------------------------*/INLINE void shift128RightJamming( bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr ){ bits64 z0, z1; int8 negCount = ( - count ) & 63; if ( count == 0 ) { z1 = a1; z0 = a0; } else if ( count < 64 ) { z1 = ( a0<<negCount ) | ( a1>>count ) | ( ( a1<<negCount ) != 0 ); z0 = a0>>count; } else { if ( count == 64 ) { z1 = a0 | ( a1 != 0 ); } else if ( count < 128 ) { z1 = ( a0>>( count & 63 ) ) | ( ( ( a0<<negCount ) | a1 ) != 0 ); } else { z1 = ( ( a0 | a1 ) != 0 ); } z0 = 0; } *z1Ptr = z1; *z0Ptr = z0;}/*-------------------------------------------------------------------------------Shifts the 192-bit value formed by concatenating `a0', `a1', and `a2' rightby 64 _plus_ the number of bits given in `count'. The shifted result isat most 128 nonzero bits; these are broken into two 64-bit pieces which arestored at the locations pointed to by `z0Ptr' and `z1Ptr'. The bits shiftedoff form a third 64-bit result as follows: The _last_ bit shifted off isthe most-significant bit of the extra result, and the other 63 bits of theextra result are all zero if and only if _all_but_the_last_ bits shifted offwere all zero. This extra result is stored in the location pointed to by`z2Ptr'. The value of `count' can be arbitrarily large. (This routine makes more sense if `a0', `a1', and `a2' are consideredto form a fixed-point value with binary point between `a1' and `a2'. Thisfixed-point value is shifted right by the number of bits given in `count',and the integer part of the result is returned at the locations pointed toby `z0Ptr' and `z1Ptr'. The fractional part of the result may be slightlycorrupted as described above, and is returned at the location pointed to by`z2Ptr'.)-------------------------------------------------------------------------------*/INLINE void shift128ExtraRightJamming( bits64 a0, bits64 a1, bits64 a2, int16 count, bits64 *z0Ptr, bits64 *z1Ptr, bits64 *z2Ptr ){ bits64 z0, z1, z2; int8 negCount = ( - count ) & 63; if ( count == 0 ) { z2 = a2; z1 = a1; z0 = a0; } else { if ( count < 64 ) { z2 = a1<<negCount; z1 = ( a0<<negCount ) | ( a1>>count ); z0 = a0>>count; } else { if ( count == 64 ) { z2 = a1; z1 = a0; } else { a2 |= a1; if ( count < 128 ) { z2 = a0<<negCount; z1 = a0>>( count & 63 ); } else { z2 = ( count == 128 ) ? a0 : ( a0 != 0 ); z1 = 0; } } z0 = 0; } z2 |= ( a2 != 0 ); } *z2Ptr = z2; *z1Ptr = z1; *z0Ptr = z0;}/*-------------------------------------------------------------------------------Shifts the 128-bit value formed by concatenating `a0' and `a1' left by thenumber of bits given in `count'. Any bits shifted off are lost. The valueof `count' must be less than 64. The result is broken into two 64-bitpieces which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.-------------------------------------------------------------------------------*/INLINE void shortShift128Left( bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr ){ *z1Ptr = a1<<count; *z0Ptr = ( count == 0 ) ? a0 : ( a0<<count ) | ( a1>>( ( - count ) & 63 ) );}/*-------------------------------------------------------------------------------Shifts the 192-bit value formed by concatenating `a0', `a1', and `a2' leftby the number of bits given in `count'. Any bits shifted off are lost.The value of `count' must be less than 64. The result is broken into three64-bit pieces which are stored at the locations pointed to by `z0Ptr',`z1Ptr', and `z2Ptr'.-------------------------------------------------------------------------------*/INLINE void shortShift192Left( bits64 a0, bits64 a1, bits64 a2, int16 count, bits64 *z0Ptr, bits64 *z1Ptr, bits64 *z2Ptr ){ bits64 z0, z1, z2; int8 negCount; z2 = a2<<count; z1 = a1<<count; z0 = a0<<count; if ( 0 < count ) { negCount = ( ( - count ) & 63 ); z1 |= a2>>negCount; z0 |= a1>>negCount; } *z2Ptr = z2; *z1Ptr = z1; *z0Ptr = z0;}/*-------------------------------------------------------------------------------Adds the 128-bit value formed by concatenating `a0' and `a1' to the 128-bitvalue formed by concatenating `b0' and `b1'. Addition is modulo 2^128, soany carry out is lost. The result is broken into two 64-bit pieces whichare stored at the locations pointed to by `z0Ptr' and `z1Ptr'.-------------------------------------------------------------------------------*/INLINE void add128( bits64 a0, bits64 a1, bits64 b0, bits64 b1, bits64 *z0Ptr, bits64 *z1Ptr ){ bits64 z1; z1 = a1 + b1; *z1Ptr = z1; *z0Ptr = a0 + b0 + ( z1 < a1 );}/*-------------------------------------------------------------------------------Adds the 192-bit value formed by concatenating `a0', `a1', and `a2' to the192-bit value formed by concatenating `b0', `b1', and `b2'. Addition ismodulo 2^192, so any carry out is lost. The result is broken into three64-bit pieces which are stored at the locations pointed to by `z0Ptr',`z1Ptr', and `z2Ptr'.-------------------------------------------------------------------------------*/INLINE void add192( bits64 a0, bits64 a1, bits64 a2, bits64 b0, bits64 b1,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -