Changeset feef1cd in mainline
- Timestamp:
- 2006-01-08T19:39:07Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 56a39dde
- Parents:
- 3af72dc
- Location:
- softfloat
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
softfloat/generic/comparison.c
r3af72dc rfeef1cd 35 35 }; 36 36 37 inline int isFloat64NaN(float64 d) 38 { /* NaN : exp = 0x7ff and nonzero mantisa */ 39 return ((d.parts.exp==0x7FF)&&(d.parts.mantisa)); 40 }; 41 37 42 inline int isFloat32SigNaN(float32 f) 38 43 { /* SigNaN : exp = 0xff mantisa = 1xxxxx..x (binary), where at least one x is nonzero */ 39 44 return ((f.parts.exp==0xFF)&&(f.parts.mantisa>0x400000)); 45 }; 46 47 inline int isFloat64SigNaN(float64 d) 48 { /* SigNaN : exp = 0x7ff mantisa = 1xxxxx..x (binary), where at least one x is nonzero */ 49 return ((d.parts.exp==0x7FF)&&(d.parts.mantisa>0x8000000000000ll)); 40 50 }; 41 51 … … 45 55 }; 46 56 57 inline int isFloat64Infinity(float64 d) 58 { 59 return ((d.parts.exp==0x7FF)&&(d.parts.mantisa==0x0)); 60 }; 61 47 62 inline int isFloat32Zero(float32 f) 48 63 { 49 64 return (((f.binary) & 0x7FFFFFFF) == 0); 65 } 66 67 inline int isFloat64Zero(float64 d) 68 { 69 return (((d.binary) & 0x7FFFFFFFFFFFFFFFll) == 0); 50 70 } 51 71 … … 101 121 102 122 123 -
softfloat/generic/conversion.c
r3af72dc rfeef1cd 27 27 */ 28 28 29 #include "sftypes.h" 30 #include "conversion.h" 31 32 float64 convertFloat32ToFloat64(float32 a) 33 { 34 float64 result; 35 __u64 mant; 36 37 result.parts.sign = a.parts.sign; 38 result.parts.mantisa = a.parts.mantisa; 39 result.parts.mantisa <<= (FLOAT64_MANTISA_SIZE - FLOAT32_MANTISA_SIZE ); 40 41 if ((isFloat32Infinity(a))||(isFloat32NaN(a))) { 42 result.parts.exp = 0x7FF; 43 /* TODO; check if its correct for SigNaNs*/ 44 return result; 45 }; 46 47 result.parts.exp = a.parts.exp + ( (int)FLOAT64_BIAS - FLOAT32_BIAS ); 48 if (a.parts.exp == 0) { 49 /* normalize denormalized numbers */ 50 51 if (result.parts.mantisa == 0ll) { /* fix zero */ 52 result.parts.exp = 0ll; 53 return result; 54 } 55 56 mant = result.parts.mantisa; 57 58 while (!(mant & (0x10000000000000ll))) { 59 mant <<= 1; 60 --result.parts.exp; 61 }; 62 result.parts.mantisa = mant; 63 }; 64 65 return result; 66 67 }; 68 69 float32 convertFloat64ToFloat32(float64 a) 70 { 71 float32 result; 72 __s32 exp; 73 __u64 mant; 74 75 result.parts.sign = a.parts.sign; 76 77 if (isFloat64NaN(a)) { 78 79 result.parts.exp = 0xFF; 80 81 if (isFloat64SigNaN(a)) { 82 result.parts.mantisa = 0x800000; /* set first bit of mantisa nonzero */ 83 return result; 84 } 85 86 result.parts.mantisa = 0x1; /* mantisa nonzero but its first bit is zero */ 87 return result; 88 }; 89 90 if (isFloat64Infinity(a)) { 91 result.parts.mantisa = 0; 92 result.parts.exp = 0xFF; 93 return result; 94 }; 95 96 exp = (int)a.parts.exp - FLOAT64_BIAS + FLOAT32_BIAS; 97 98 if (exp >= 0xFF) { 99 /*FIXME: overflow*/ 100 result.parts.mantisa = 0; 101 result.parts.exp = 0xFF; 102 return result; 103 104 } else if (exp <= 0 ) { 105 106 /* underflow or denormalized */ 107 108 result.parts.exp = 0; 109 110 exp *= -1; 111 112 if (exp > FLOAT32_MANTISA_SIZE ) { 113 /* FIXME: underflow */ 114 result.parts.mantisa = 0; 115 return result; 116 }; 117 118 /* denormalized */ 119 120 mant = result.parts.mantisa >> 1; 121 mant |= 0x10000000000000ll; /* denormalize and set hidden bit */ 122 123 while (exp > 0) { 124 --exp; 125 mant >>= 1; 126 }; 127 result.parts.mantisa = mant; 128 129 return result; 130 }; 131 132 result.parts.exp = exp; 133 result.parts.mantisa = a.parts.mantisa >> (FLOAT64_MANTISA_SIZE - FLOAT32_MANTISA_SIZE); 134 return result; 135 }; 136 -
softfloat/generic/softfloat.c
r3af72dc rfeef1cd 72 72 } 73 73 74 float __divsf3(float a, float b) 75 { 76 float32 fa, fb; 77 fa.f=a; 78 fb.f=b; 79 // return divFloat32(fa, fb).f; 80 }; 81 74 82 float __negsf2(float a) 75 83 { … … 90 98 /* Conversion functions */ 91 99 100 double __extendsfdf2(float a) 101 { 102 float32 fa; 103 fa.f = a; 104 return convertFloat32ToFloat64(fa).d; 105 }; 106 107 float __truncdfsf2(double a) 108 { 109 float64 da; 110 da.d = a; 111 return convertFloat64ToFloat32(da).f; 112 } 92 113 /* Comparison functions */ 93 114 -
softfloat/include/comparison.h
r3af72dc rfeef1cd 36 36 inline int isFloat32Zero(float32 f); 37 37 38 inline int isFloat64NaN(float64 d); 39 inline int isFloat64SigNaN(float64 d); 40 41 inline int isFloat64Infinity(float64 d); 42 inline int isFloat64Zero(float64 d); 43 38 44 inline int isFloat32eq(float32 a, float32 b); 39 45 inline int isFloat32lt(float32 a, float32 b); -
softfloat/include/conversion.h
r3af72dc rfeef1cd 30 30 #define __CONVERSION_H__ 31 31 32 float64 convertFloat32ToFloat64(float32 a); 33 34 float32 convertFloat64ToFloat32(float64 a); 35 32 36 #endif 33 37 -
softfloat/include/sftypes.h
r3af72dc rfeef1cd 29 29 #ifndef __SFTYPES_H__ 30 30 #define __SFTYPES_H__ 31 32 31 33 32 typedef union { … … 80 79 81 80 #define FLOAT32_MANTISA_SIZE 23 81 #define FLOAT64_MANTISA_SIZE 52 82 82 83 83 #define FLOAT32_BIAS 0x7F
Note:
See TracChangeset
for help on using the changeset viewer.