Rev 535 | Rev 563 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 535 | Rev 542 | ||
---|---|---|---|
Line 27... | Line 27... | ||
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | #include<softfloat.h> |
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 |