|
@@ -99,6 +99,134 @@ struct struct31 {
|
|
|
float v2;
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+/* to avoid depending on libc for double->int64 conversions
|
|
|
+
|
|
|
+License/credit:
|
|
|
+
|
|
|
+Written by John R. Hauser. This work was made possible in part by the
|
|
|
+International Computer Science Institute, located at Suite 600, 1947 Center
|
|
|
+Street, Berkeley, California 94704. Funding was partially provided by the
|
|
|
+National Science Foundation under grant MIP-9311980. The original version
|
|
|
+of this code was written as part of a project to build a fixed-point vector
|
|
|
+processor in collaboration with the University of California at Berkeley,
|
|
|
+overseen by Profs. Nelson Morgan and John Wawrzynek. More information
|
|
|
+is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
|
|
|
+arithmetic/SoftFloat.html'.
|
|
|
+
|
|
|
+THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
|
|
|
+been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
|
|
|
+RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
|
|
|
+AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
|
|
|
+COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
|
|
|
+EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
|
|
|
+INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
|
|
|
+OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
|
|
|
+
|
|
|
+Derivative works are acceptable, even for commercial purposes, so long as
|
|
|
+(1) the source code for the derivative work includes prominent notice that
|
|
|
+the work is derivative, and (2) the source code includes prominent notice with
|
|
|
+these four paragraphs for those parts of this code that are retained.
|
|
|
+
|
|
|
+
|
|
|
+*/
|
|
|
+
|
|
|
+#define LIT64( a ) a##LL
|
|
|
+
|
|
|
+#define double2float64( a ) (*(float64*)&(a))
|
|
|
+
|
|
|
+typedef char flag;
|
|
|
+
|
|
|
+typedef int64_t float64;
|
|
|
+typedef uint64_t bits64;
|
|
|
+typedef int64_t sbits64;
|
|
|
+
|
|
|
+bits64 extractFloat64Frac( float64 a )
|
|
|
+{
|
|
|
+ return a & LIT64( 0x000FFFFFFFFFFFFF );
|
|
|
+}
|
|
|
+
|
|
|
+int16_t extractFloat64Exp( float64 a )
|
|
|
+{
|
|
|
+ return ( a>>52 ) & 0x7FF;
|
|
|
+}
|
|
|
+
|
|
|
+flag extractFloat64Sign( float64 a )
|
|
|
+{
|
|
|
+ return a>>63;
|
|
|
+}
|
|
|
+
|
|
|
+int32_t int64_is_zero(bits64 a0)
|
|
|
+{
|
|
|
+ return (((uint32_t)(a0 >> 32)) == 0) && ((((uint32_t)(a0 & LIT64(0xFFFFFFFF)))) == 0);
|
|
|
+}
|
|
|
+
|
|
|
+void shift64ExtraRightJamming(bits64 a0, bits64 a1, int16_t count, bits64 *z0Ptr, bits64 *z1Ptr )
|
|
|
+{
|
|
|
+ bits64 z0, z1;
|
|
|
+ int8_t negCount = ( - count ) & 63;
|
|
|
+
|
|
|
+ if ( count == 0 ) {
|
|
|
+ z1 = a1;
|
|
|
+ z0 = a0;
|
|
|
+ }
|
|
|
+ else if ( count < 64 ) {
|
|
|
+ z1 = ( a0<<negCount ) | ( !int64_is_zero(a1));
|
|
|
+ z0 = a0>>count;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if ( count == 64 ) {
|
|
|
+ z1 = a0 | ( !int64_is_zero(a1) );
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ z1 = ( !int64_is_zero( a0 | a1 ) );
|
|
|
+ }
|
|
|
+ z0 = 0;
|
|
|
+ }
|
|
|
+ *z1Ptr = z1;
|
|
|
+ *z0Ptr = z0;
|
|
|
+}
|
|
|
+
|
|
|
+static int64_t roundAndPackInt64( flag zSign, bits64 absZ0, bits64 absZ1 )
|
|
|
+{
|
|
|
+ int64_t z;
|
|
|
+
|
|
|
+ z = absZ0;
|
|
|
+ if ( zSign ) z = - z;
|
|
|
+ return z;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+int64_t float64_to_int64( float64 a )
|
|
|
+{
|
|
|
+ flag aSign;
|
|
|
+ int16_t aExp, shiftCount;
|
|
|
+ bits64 aSig, aSigExtra;
|
|
|
+
|
|
|
+ aSig = extractFloat64Frac( a );
|
|
|
+ aExp = extractFloat64Exp( a );
|
|
|
+ aSign = extractFloat64Sign( a );
|
|
|
+ if ( aExp ) aSig |= LIT64( 0x0010000000000000 );
|
|
|
+ shiftCount = 0x433 - aExp;
|
|
|
+ if ( shiftCount <= 0 ) {
|
|
|
+ if ( 0x43E < aExp ) {
|
|
|
+ if ( ! aSign
|
|
|
+ || ( ( aExp == 0x7FF )
|
|
|
+ && ( aSig != LIT64( 0x0010000000000000 ) ) )
|
|
|
+ ) {
|
|
|
+ return LIT64( 0x7FFFFFFFFFFFFFFF );
|
|
|
+ }
|
|
|
+ return (sbits64) LIT64( 0x8000000000000000 );
|
|
|
+ }
|
|
|
+ aSigExtra = 0;
|
|
|
+ aSig <<= - shiftCount;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ shift64ExtraRightJamming( aSig, 0, shiftCount, &aSig, &aSigExtra );
|
|
|
+ }
|
|
|
+ return roundAndPackInt64( aSign, aSig, aSigExtra );
|
|
|
+}
|
|
|
+
|
|
|
float pass1(struct struct1 s) {
|
|
|
return s.v;
|
|
|
}
|
|
@@ -132,31 +260,31 @@ double pass8(struct struct8 s) {
|
|
|
}
|
|
|
|
|
|
int64_t pass9(struct struct9 s) {
|
|
|
- return s.v1 + (int64_t)s.v2;
|
|
|
+ return s.v1 + double2float64(s.v2);
|
|
|
}
|
|
|
|
|
|
int64_t pass10(struct struct10 s) {
|
|
|
- return s.v1 + s.v2 + (int64_t)s.v3;
|
|
|
+ return s.v1 + s.v2 + double2float64(s.v3);
|
|
|
}
|
|
|
|
|
|
int64_t pass11(struct struct11 s) {
|
|
|
- return s.v1 + (int64_t)s.v2;
|
|
|
+ return s.v1 + double2float64(s.v2);
|
|
|
}
|
|
|
|
|
|
int64_t pass12(struct struct12 s) {
|
|
|
- return s.v1 + (int64_t)s.v2 + (int64_t)s.v3;
|
|
|
+ return s.v1 + double2float64(s.v2) + double2float64(s.v3);
|
|
|
}
|
|
|
|
|
|
int64_t pass13(struct struct13 s) {
|
|
|
- return (int64_t)s.v1 + s.v2;
|
|
|
+ return double2float64(s.v1) + s.v2;
|
|
|
}
|
|
|
|
|
|
int64_t pass14(struct struct14 s) {
|
|
|
- return (int64_t)s.v1 + s.v2 + s.v3;
|
|
|
+ return double2float64(s.v1) + s.v2 + s.v3;
|
|
|
}
|
|
|
|
|
|
int64_t pass15(struct struct15 s) {
|
|
|
- return (int64_t)s.v1 + s.v2 + (int64_t)s.v3;
|
|
|
+ return double2float64(s.v1) + s.v2 + double2float64(s.v3);
|
|
|
}
|
|
|
|
|
|
float pass16(struct struct16 s) {
|
|
@@ -167,8 +295,9 @@ float pass17(struct struct17 s) {
|
|
|
return s.v1 + s.v2;
|
|
|
}
|
|
|
|
|
|
-long double pass31(struct struct31 s) {
|
|
|
- return s.v1 + s.v2;
|
|
|
+long double pass31(struct struct31 s, float *v2) {
|
|
|
+ *v2 = s.v2;
|
|
|
+ return s.v1;
|
|
|
}
|
|
|
|
|
|
|