softfloat-macros.h

来自「基于组件方式开发操作系统的OSKIT源代码」· C头文件 代码 · 共 751 行 · 第 1/2 页

H
751
字号
/*	$NetBSD: softfloat-macros.h,v 1.4 1998/04/24 18:46:53 cgd Exp $	*//*===============================================================================This C source fragment is part of the SoftFloat IEC/IEEE Floating-pointArithmetic Package, Release 1a.Written by John R. Hauser.  This work was made possible by the InternationalComputer Science Institute, located at Suite 600, 1947 Center Street,Berkeley, California 94704.  Funding was provided in part by the NationalScience Foundation under grant MIP-9311980.  The original version ofthis 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://www.cs.berkeley.edu/~jhauser/softfloat.html'.THIS PACKAGE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort hasbeen made to avoid it, THIS PACKAGE MAY CONTAIN FAULTS THAT WILL AT TIMESRESULT IN INCORRECT BEHAVIOR.  USE OF THIS PACKAGE IS RESTRICTED TO PERSONSAND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY AND ALLLOSSES, 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.===============================================================================*/INLINE void shiftDown32Jamming( bits32 a, uint16 count, bits32 *zPtr );INLINE void shiftDown64ExtraJamming(     bits32 a0,     bits32 a1,     bits32 a2,     uint16 count,     bits32 *z0Ptr,     bits32 *z1Ptr,     bits32 *z2Ptr );INLINE void shiftDown64Jamming(     bits32 a0, bits32 a1, uint16 count, bits32 *z0Ptr, bits32 *z1Ptr );INLINE void shiftDown64(     bits32 a0, bits32 a1, uint16 count, bits32 *z0Ptr, bits32 *z1Ptr );INLINE void shortShiftUp64(     bits32 a0, bits32 a1, uint16 count, bits32 *z0Ptr, bits32 *z1Ptr );INLINE void shortShiftUp96(     bits32 a0,     bits32 a1,     bits32 a2,     uint16 count,     bits32 *z0Ptr,     bits32 *z1Ptr,     bits32 *z2Ptr );INLINE void add64(     bits32 a0, bits32 a1, bits32 b0, bits32 b1, bits32 *z0Ptr, bits32 *z1Ptr );INLINE void add96(     bits32 a0,     bits32 a1,     bits32 a2,     bits32 b0,     bits32 b1,     bits32 b2,     bits32 *z0Ptr,     bits32 *z1Ptr,     bits32 *z2Ptr );INLINE void sub64(     bits32 a0, bits32 a1, bits32 b0, bits32 b1, bits32 *z0Ptr, bits32 *z1Ptr );INLINE void sub96(     bits32 a0,     bits32 a1,     bits32 a2,     bits32 b0,     bits32 b1,     bits32 b2,     bits32 *z0Ptr,     bits32 *z1Ptr,     bits32 *z2Ptr );INLINE void mul32To64( bits32 a, bits32 b, bits32 *z0Ptr, bits32 *z1Ptr );INLINE void mul64By32To96(     bits32 a0,     bits32 a1,     bits32 b,     bits32 *z0Ptr,     bits32 *z1Ptr,     bits32 *z2Ptr );INLINE void mul64To128(     bits32 a0,     bits32 a1,     bits32 b0,     bits32 b1,     bits32 *z0Ptr,     bits32 *z1Ptr,     bits32 *z2Ptr,     bits32 *z3Ptr );static bits32 estimateDiv64To32( bits32 a0, bits32 a1, bits32 b );static bits32 estimateSqrt32( int16 aExp, bits32 a );static int8 countLeadingZeros( bits32 a );INLINE flag eq64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 );INLINE flag le64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 );INLINE flag lt64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 );#if 0 /* XXX not used */INLINE flag ne64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 );#endif/*-------------------------------------------------------------------------------Shifts `a' down by the number of bits given in `count'.  If any nonzero bitsare shifted off, they are ``jammed'' into the least significant bit of theresult by setting the least significant bit to 1.  The value of `count' canbe 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 shiftDown32Jamming( bits32 a, uint16 count, bits32 *zPtr ){    bits32 z;    if ( count == 0 ) {        z = a;    }    else if ( count < 32 ) {        z = ( a>>count ) | ( 0 < ( a<<( ( - count ) & 31 ) ) );    }    else {        z = ( 0 < a );    }    *zPtr = z;}/*-------------------------------------------------------------------------------Shifts the 96-bit value formed by concatenating `a0', `a1', and `a2' down by32 _plus_ the number of bits given in `count'.  The shifted-down result isat most 64 nonzero bits; these are broken into two 32-bit pieces which arestored at the locations pointed to by `z0Ptr' and `z1Ptr'.  The bits shiftedoff form a third 32-bit result as follows:  The _last_ bit shifted off isthe most-significant bit of the extra result, and the other 31 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 down 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 shiftDown64ExtraJamming(     bits32 a0,     bits32 a1,     bits32 a2,     uint16 count,     bits32 *z0Ptr,     bits32 *z1Ptr,     bits32 *z2Ptr ){    bits32 z0, z1, z2;    int8 negCount = ( - count ) & 31;    if ( count == 0 ) {        z2 = a2;        z1 = a1;        z0 = a0;    }    else {        if ( count < 32 ) {            z2 = a1<<negCount;            z1 = ( a0<<negCount ) | ( a1>>count );            z0 = a0>>count;        }        else {            if ( count == 32 ) {                z2 = a1;                z1 = a0;            }            else {                a2 |= a1;                if ( count < 64 ) {                    z2 = a0<<negCount;                    z1 = a0>>( count & 31 );                }                else {                    z2 = ( count == 64 ) ? a0 : ( 0 < a0 );                    z1 = 0;                }            }            z0 = 0;        }        z2 |= ( 0 < a2 );    }    *z2Ptr = z2;    *z1Ptr = z1;    *z0Ptr = z0;}/*-------------------------------------------------------------------------------Shifts the 64-bit value formed by concatenating `a0' and `a1' down 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 64, 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 32-bit pieces which are stored atthe locations pointed to by `z0Ptr' and `z1Ptr'.-------------------------------------------------------------------------------*/INLINE void shiftDown64Jamming(     bits32 a0, bits32 a1, uint16 count, bits32 *z0Ptr, bits32 *z1Ptr ){    bits32 z0, z1;    int8 negCount = ( - count ) & 31;    if ( count == 0 ) {        z1 = a1;        z0 = a0;    }    else if ( count < 32 ) {        z1 = ( a0<<negCount ) | ( a1>>count ) | ( 0 < ( a1<<negCount ) );        z0 = a0>>count;    }    else {        if ( count == 32 ) {            z1 = a0 | ( 0 < a1 );        }        else if ( count < 64 ) {            z1 = ( a0>>( count & 31 ) ) | ( 0 < ( ( a0<<negCount ) | a1 ) );        }        else {            z1 = ( 0 < ( a0 | a1 ) );        }        z0 = 0;    }    *z1Ptr = z1;    *z0Ptr = z0;}/*-------------------------------------------------------------------------------Shifts the 64-bit value formed by concatenating `a0' and `a1' down 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 64, the result will be 0.  The result is broken into two 32-bit pieceswhich are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.-------------------------------------------------------------------------------*/INLINE void shiftDown64(     bits32 a0, bits32 a1, uint16 count, bits32 *z0Ptr, bits32 *z1Ptr ){    bits32 z0, z1;    int8 negCount = ( - count ) & 31;    if ( count == 0 ) {        z1 = a1;        z0 = a0;    }    else if ( count < 32 ) {        z1 = ( a0<<negCount ) | ( a1>>count );        z0 = a0>>count;    }    else {        z1 = ( count < 64 ) ? ( a0>>( count & 31 ) ) : 0;        z0 = 0;    }    *z1Ptr = z1;    *z0Ptr = z0;}/*-------------------------------------------------------------------------------Shifts the 64-bit value formed by concatenating `a0' and `a1' up by thenumber of bits given in `count'.  Any bits shifted off are lost.  The valueof `count' must be less than 32.  The result is broken into two 32-bitpieces which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.-------------------------------------------------------------------------------*/INLINE void shortShiftUp64(     bits32 a0, bits32 a1, uint16 count, bits32 *z0Ptr, bits32 *z1Ptr ){    *z1Ptr = a1<<count;    *z0Ptr =        ( count == 0 ) ? a0 : ( a0<<count ) | ( a1>>( ( - count ) & 31 ) );}/*-------------------------------------------------------------------------------Shifts the 96-bit value formed by concatenating `a0', `a1', and `a2' up bythe number of bits given in `count'.  Any bits shifted off are lost.  Thevalue of `count' must be less than 32.  The result is broken into three32-bit pieces which are stored at the locations pointed to by `z0Ptr',`z1Ptr', and `z2Ptr'.-------------------------------------------------------------------------------*/INLINE void shortShiftUp96(     bits32 a0,     bits32 a1,     bits32 a2,     uint16 count,     bits32 *z0Ptr,     bits32 *z1Ptr,     bits32 *z2Ptr ){    bits32 z0, z1, z2;    int8 negCount;    z2 = a2<<count;    z1 = a1<<count;    z0 = a0<<count;    if ( 0 < count ) {        negCount = ( ( - count ) & 31 );        z1 |= a2>>negCount;        z0 |= a1>>negCount;    }    *z2Ptr = z2;    *z1Ptr = z1;    *z0Ptr = z0;}/*-------------------------------------------------------------------------------Adds the 64-bit value formed by concatenating `a0' and `a1' to the 64-bitvalue formed by concatenating `b0' and `b1'.  Addition is modulo 2^64, soany carry out is lost.  The result is broken into two 32-bit pieces whichare stored at the locations pointed to by `z0Ptr' and `z1Ptr'.-------------------------------------------------------------------------------*/INLINE void add64(     bits32 a0, bits32 a1, bits32 b0, bits32 b1, bits32 *z0Ptr, bits32 *z1Ptr ){    bits32 z1;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?