Changeset b5440cf in mainline
- Timestamp:
- 2005-12-19T09:47:27Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e557805
- Parents:
- 36aee474
- Location:
- softfloat
- Files:
-
- 9 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
softfloat/generic/softfloat.c
r36aee474 rb5440cf 1 2 1 /* 3 2 * Copyright (C) 2005 Josef Cejka … … 29 28 30 29 #include<softfloat.h> 30 #include<sftypes.h> 31 #include<arithmetic.h> 32 #include<conversion.h> 33 #include<comparison.h> 34 #include<other.h> 31 35 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); 36 /* Arithmetic functions */ 36 37 37 38 float __addsf3(float a, float b) … … 40 41 fa.f=a; 41 42 fb.f=b; 42 if (fa.parts.sign!=fb.parts.sign) return subFloat32(fa,fb).f; 43 if (fa.parts.sign!=fb.parts.sign) { 44 if (fa.parts.sign) { 45 fa.parts.sign=0; 46 return subFloat32(fb,fa).f; 47 }; 48 fb.parts.sign=0; 49 return subFloat32(fa,fb).f; 50 } 43 51 return addFloat32(fa,fb).f; 44 52 }; … … 49 57 fa.f=a; 50 58 fb.f=b; 51 if (fa.parts.sign!=fb.parts.sign) return addFloat32(fa,fb).f; 59 if (fa.parts.sign!=fb.parts.sign) { 60 fb.parts.sign!=fb.parts.sign; 61 return addFloat32(fa,fb).f; 62 } 52 63 return subFloat32(fa,fb).f; 53 64 }; … … 69 80 }; 70 81 71 /** Add two Float32 numbers with same signs 72 */ 73 float32 addFloat32(float32 a, float32 b) 74 { 75 int expdiff; 76 __u32 exp1,exp2,mant1,mant2; 77 78 expdiff=a.parts.exp - b.parts.exp; 79 if (expdiff<0) { 80 if (isFloat32NaN(b)) { 81 //TODO: fix SigNaN 82 if (isFloat32SigNaN(b)) { 83 }; 84 return b; 85 }; 86 87 if (b.parts.exp==0xFF) { 88 return b; 89 } 90 91 mant1=b.parts.mantisa; 92 exp1=b.parts.exp; 93 mant2=a.parts.mantisa; 94 exp2=a.parts.exp; 95 expdiff*=-1; 96 } else { 97 if (isFloat32NaN(a)) { 98 //TODO: fix SigNaN 99 if ((isFloat32SigNaN(a))||(isFloat32SigNaN(b))) { 100 }; 101 return a; 102 }; 103 104 if (a.parts.exp==0xFF) { 105 return a; 106 } 107 108 mant1=a.parts.mantisa; 109 exp1=a.parts.exp; 110 mant2=b.parts.mantisa; 111 exp2=b.parts.exp; 112 }; 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 124 // create some space for rounding 125 mant1<<=6; 126 mant2<<=6; 127 128 mant1|=0x20000000; //add hidden bit 129 130 131 if (exp2==0) { 132 --expdiff; 133 } else { 134 mant2|=0x20000000; //hidden bit 135 }; 136 137 if (expdiff>24) { 138 goto done; 139 }; 140 141 mant2>>=expdiff; 142 mant1+=mant2; 143 done: 144 if (mant1&0x40000000) { 145 ++exp1; 146 mant1>>=1; 147 }; 148 149 //rounding - if first bit after mantisa is set then round up 150 mant1+=0x20; 151 152 a.parts.exp=exp1; 153 a.parts.mantisa=mant1>>6; 154 return a; 155 }; 82 /* Conversion functions */ 156 83 157 /** Substract two float32 numbers with same signs 158 */ 159 float32 subFloat32(float32 a, float32 b) 160 { 161 162 163 }; 84 /* Comparison functions */ 164 85 165 inline int isFloat32NaN(float32 f) 166 { /* NaN : exp = 0xff and nonzero mantisa */ 167 return ((f.parts.exp==0xFF)&&(f.parts.mantisa)); 168 }; 86 /* Other functions */ 169 87 170 inline int isFloat32SigNaN(float32 f)171 { /* SigNaN : exp = 0xff mantisa = 1xxxxx..x (binary), where at least one x is nonzero */172 return ((f.parts.exp==0xFF)&&(f.parts.mantisa>0x400000));173 };174 -
softfloat/include/softfloat.h
r36aee474 rb5440cf 29 29 #ifndef __SOFTFLOAT_H__ 30 30 #define __SOFTFLOAT_H__ 31 32 33 typedef union {34 float f;35 struct {36 #ifdef __BIG_ENDIAN__37 __u32 sign:1;38 __u32 exp:8;39 __u32 mantisa:23;40 #elif defined __LITTLE_ENDIAN__41 __u32 mantisa:23;42 __u32 exp:8;43 __u32 sign:1;44 #else45 #error "Unknown endians."46 #endif47 } parts __attribute__ ((packed));48 } float32;49 50 typedef union {51 double d;52 struct {53 #ifdef __BIG_ENDIAN__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;61 #else62 #error "Unknown endians."63 #endif64 } parts __attribute__ ((packed));65 } float64;66 67 #define FLOAT32_MAX 0x7f80000068 #define FLOAT32_MIN 0xff80000069 #define FLOAT64_MAX70 #define FLOAT64_MIN71 72 #define FLOAT32_BIAS 0xF773 #define FLOAT64_BIAS 0x3FF74 #define FLOAT80_BIAS 0x3FFF75 76 77 31 78 32 float __addsf3(float a, float b);
Note:
See TracChangeset
for help on using the changeset viewer.