Changeset e799e3a in mainline
- Timestamp:
- 2005-12-06T12:44:50Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ebff5e8
- Parents:
- 211bd8a5
- Location:
- softfloat
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
softfloat/generic/softfloat.c
r211bd8a5 re799e3a 30 30 #include<softfloat.h> 31 31 32 33 float __addsf3(float a, float b) 34 { 35 float32 fa, fb; 36 a.f=a; 37 b.f=b; 38 if (a.parts.sign!=b.parts.sign) return subFloat32(a,b).f; 39 return addFloat32(a,b).f; 40 }; 41 42 float __subsf3(float a, float b) 43 { 44 float32 fa, fb; 45 a.f=a; 46 b.f=b; 47 if (a.parts.sign!=b.parts.sign) return addFloat32(a,b).f; 48 return subFloat32(a,b).f; 49 }; 50 51 float __negsf2(float a) 52 { 53 float32 fa; 54 fa.f=a; 55 fa.parts.sign=!fa.parts.sign; 56 return fa.f; 57 }; 58 59 double __negdf2(double a) 60 { 61 float64 fa; 62 fa.f=a; 63 fa.parts.sign=!fa.parts.sign; 64 return fa.f; 65 }; 66 67 float32 addFloat32(float32 a, float32 b) 68 { 69 __u32 expdiff; 70 __u32 exp1,exp2,mant1,mant2; 71 72 expdiff=a.parts.exp - b.parts.exp; 73 if (expdiff<0) { 74 if (isFloat32NaN(a)) { 75 //TODO: fix it 76 return a; 77 }; 78 79 mant1=b.parts.mantisa; 80 exp1=b.parts.exp; 81 mant2=a.parts.mantisa; 82 exp2=a.parts.exp; 83 expdiff*=-1; 84 } else { 85 if (isFloat32NaN(b)) { 86 //TODO: fix it 87 return b; 88 }; 89 mant1=a.parts.mantisa; 90 exp1=a.parts.exp; 91 mant2=b.parts.mantisa; 92 exp2=b.parts.exp; 93 }; 94 95 // create some space for rounding 96 mant1<<=6; 97 mant2<<=6; 98 99 if (exp1!=0) { 100 mant1|=0x20000000; //add hidden bit 101 }; 102 103 if (exp2==0) { 104 --expdiff; 105 } else { 106 mant2|=0x20000000; //hidden bit 107 }; 108 109 110 if (expdiff>24) { 111 goto done; 112 }; 113 114 mant2>>=expdiff; 115 mant1+=mant2; 116 done: 117 //TODO: round mant1 118 a.parts.exp=exp1; 119 a.parts.mantisa=mant1>>6; 120 return a; 121 }; 122 123 float32 subFloat32(float32 a, float32 b) 124 { 125 126 127 }; 128 129 inline int isFloat32NaN(float32 f) 130 { /* NaN : exp = 0xff and nonzero mantisa */ 131 float32 fa; 132 fa.f=f; 133 return ((fa.parts.exp==0xFF)&&(fa.parts.mantisa)); 134 }; 135 136 inline int isFloat32SigNaN(float32 f) 137 { /* SigNaN : exp = 0xff mantisa = 1xxxxx..x (binary), where at least one x is nonzero */ 138 float32 fa; 139 fa.f=f; 140 return ((fa.parts.exp==0xFF)&&(fa.parts.mantisa>0x400000)); 141 }; 142 -
softfloat/include/softfloat.h
r211bd8a5 re799e3a 42 42 __u32 mantisa:23; 43 43 __u8 exp:8; 44 __u8 44 __u8 sign:1; 45 45 #else 46 46 #endif … … 59 59 __u32 mantisa:52; 60 60 __u8 exp:11; 61 __u8 61 __u8 sign:1; 62 62 #else 63 63 #endif 64 64 } parts __attribute__ ((packed)); 65 65 } float64_t; 66 67 #define FLOAT32_MAX 0x7f800000 68 #define FLOAT32_MIN 0xff800000 69 #define FLOAT64_MAX 70 #define FLOAT64_MIN 71 72 #define FLOAT32_BIAS 0xF7 73 #define FLOAT64_BIAS 0x3FF 74 #define FLOAT80_BIAS 0x3FFF 75 66 76 67 77
Note:
See TracChangeset
for help on using the changeset viewer.