Changeset 7afd2aca in mainline
- Timestamp:
- 2005-12-07T22:37:49Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 36aee474
- Parents:
- ebff5e8
- Location:
- softfloat
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
softfloat/generic/softfloat.c
rebff5e8 r7afd2aca 30 30 #include<softfloat.h> 31 31 32 float32 addFloat32(float32 a, float32 b); 33 float32 subFloat32(float32 a, float32 b); 34 inline int isFloat32NaN(float32 f); 35 inline int isFloat32SigNaN(float32 f); 32 36 33 37 float __addsf3(float a, float b) 34 38 { 35 39 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 fa.f=a; 41 fb.f=b; 42 if (fa.parts.sign!=fb.parts.sign) return subFloat32(fa,fb).f; 43 return addFloat32(fa,fb).f; 40 44 }; 41 45 … … 43 47 { 44 48 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 fa.f=a; 50 fb.f=b; 51 if (fa.parts.sign!=fb.parts.sign) return addFloat32(fa,fb).f; 52 return subFloat32(fa,fb).f; 49 53 }; 50 54 … … 60 64 { 61 65 float64 fa; 62 fa. f=a;66 fa.d=a; 63 67 fa.parts.sign=!fa.parts.sign; 64 return fa. f;68 return fa.d; 65 69 }; 66 70 71 /** Add two Float32 numbers with same signs 72 */ 67 73 float32 addFloat32(float32 a, float32 b) 68 74 { 69 __u32expdiff;75 int expdiff; 70 76 __u32 exp1,exp2,mant1,mant2; 71 77 72 78 expdiff=a.parts.exp - b.parts.exp; 73 79 if (expdiff<0) { 74 if (isFloat32NaN(a)) { 75 //TODO: fix it 76 return a; 80 if (isFloat32NaN(b)) { 81 //TODO: fix SigNaN 82 if (isFloat32SigNaN(b)) { 83 }; 84 return b; 77 85 }; 78 86 87 if (b.parts.exp==0xFF) { 88 return b; 89 } 90 79 91 mant1=b.parts.mantisa; 80 92 exp1=b.parts.exp; … … 83 95 expdiff*=-1; 84 96 } else { 85 if (isFloat32NaN(b)) { 86 //TODO: fix it 87 return b; 97 if (isFloat32NaN(a)) { 98 //TODO: fix SigNaN 99 if ((isFloat32SigNaN(a))||(isFloat32SigNaN(b))) { 100 }; 101 return a; 88 102 }; 103 104 if (a.parts.exp==0xFF) { 105 return a; 106 } 107 89 108 mant1=a.parts.mantisa; 90 109 exp1=a.parts.exp; … … 92 111 exp2=b.parts.exp; 93 112 }; 94 113 114 if (exp1==0) { 115 //both are denormalized 116 mant1+=mant2; 117 if (mant1&0xF00000) { 118 a.parts.exp=1; 119 }; 120 a.parts.mantisa=mant1; 121 return a; 122 }; 123 95 124 // create some space for rounding 96 125 mant1<<=6; 97 126 mant2<<=6; 98 127 99 if (exp1!=0) { 100 mant1|=0x20000000; //add hidden bit 101 }; 128 mant1|=0x20000000; //add hidden bit 129 102 130 103 131 if (exp2==0) { … … 107 135 }; 108 136 109 110 if (expdiff>24) {111 goto done;112 };113 114 137 mant2>>=expdiff; 115 138 mant1+=mant2; 116 139 done: 117 //TODO: round mant1 140 if (mant1&0x40000000) { 141 ++exp1; 142 mant1>>=1; 143 }; 144 145 //rounding - if first bit after mantisa is set then round up 146 mant1+=0x20; 147 118 148 a.parts.exp=exp1; 119 149 a.parts.mantisa=mant1>>6; … … 121 151 }; 122 152 153 /** Substract two float32 numbers with same signs 154 */ 123 155 float32 subFloat32(float32 a, float32 b) 124 156 { … … 129 161 inline int isFloat32NaN(float32 f) 130 162 { /* NaN : exp = 0xff and nonzero mantisa */ 131 float32 fa; 132 fa.f=f; 133 return ((fa.parts.exp==0xFF)&&(fa.parts.mantisa)); 163 return ((f.parts.exp==0xFF)&&(f.parts.mantisa)); 134 164 }; 135 165 136 166 inline int isFloat32SigNaN(float32 f) 137 167 { /* 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)); 168 return ((f.parts.exp==0xFF)&&(f.parts.mantisa>0x400000)); 141 169 }; 142 170 -
softfloat/include/softfloat.h
rebff5e8 r7afd2aca 35 35 struct { 36 36 #ifdef __BIG_ENDIAN__ 37 __u 8sign:1;38 __u 8exp:8;37 __u32 sign:1; 38 __u32 exp:8; 39 39 __u32 mantisa:23; 40 #else 41 #ifdef __LITTLE_ENDIAN__ 40 #elif defined __LITTLE_ENDIAN__ 42 41 __u32 mantisa:23; 43 __u 8exp:8;44 __u 8sign:1;42 __u32 exp:8; 43 __u32 sign:1; 45 44 #else 45 #error "Unknown endians." 46 46 #endif 47 47 } parts __attribute__ ((packed)); 48 } float32 _t;48 } float32; 49 49 50 50 typedef union { … … 52 52 struct { 53 53 #ifdef __BIG_ENDIAN__ 54 __u8 sign:1; 55 __u8 exp:11; 56 __u32 mantisa:52; 57 #else 58 #ifdef __LITTLE_ENDIAN__ 59 __u32 mantisa:52; 60 __u8 exp:11; 61 __u8 sign:1; 54 __u64 sign:1; 55 __u64 exp:11; 56 __u64 mantisa:52; 57 #elif defined __LITTLE_ENDIAN__ 58 __u64 mantisa:52; 59 __u64 exp:11; 60 __u64 sign:1; 62 61 #else 62 #error "Unknown endians." 63 63 #endif 64 64 } parts __attribute__ ((packed)); 65 } float64 _t;65 } float64; 66 66 67 67 #define FLOAT32_MAX 0x7f800000
Note:
See TracChangeset
for help on using the changeset viewer.