Rev 804 | Rev 857 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
535 | cejka | 1 | /* |
2 | * Copyright (C) 2005 Josef Cejka |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | #include<softfloat.h> |
||
647 | cejka | 30 | #include<sftypes.h> |
731 | cejka | 31 | |
32 | #include<add.h> |
||
33 | #include<sub.h> |
||
34 | #include<mul.h> |
||
35 | #include<div.h> |
||
36 | |||
647 | cejka | 37 | #include<conversion.h> |
38 | #include<comparison.h> |
||
39 | #include<other.h> |
||
535 | cejka | 40 | |
647 | cejka | 41 | /* Arithmetic functions */ |
542 | cejka | 42 | |
43 | float __addsf3(float a, float b) |
||
44 | { |
||
45 | float32 fa, fb; |
||
804 | cejka | 46 | fa.f = a; |
47 | fb.f = b; |
||
48 | if (fa.parts.sign != fb.parts.sign) { |
||
647 | cejka | 49 | if (fa.parts.sign) { |
804 | cejka | 50 | fa.parts.sign = 0; |
51 | return subFloat32(fb, fa).f; |
||
647 | cejka | 52 | }; |
804 | cejka | 53 | fb.parts.sign = 0; |
54 | return subFloat32(fa, fb).f; |
||
647 | cejka | 55 | } |
804 | cejka | 56 | return addFloat32(fa, fb).f; |
698 | cejka | 57 | } |
542 | cejka | 58 | |
734 | cejka | 59 | double __adddf3(double a, double b) |
60 | { |
||
61 | float64 da, db; |
||
804 | cejka | 62 | da.d = a; |
63 | db.d = b; |
||
64 | if (da.parts.sign != db.parts.sign) { |
||
734 | cejka | 65 | if (da.parts.sign) { |
804 | cejka | 66 | da.parts.sign = 0; |
67 | return subFloat64(db, da).d; |
||
734 | cejka | 68 | }; |
804 | cejka | 69 | db.parts.sign = 0; |
70 | return subFloat64(da, db).d; |
||
734 | cejka | 71 | } |
804 | cejka | 72 | return addFloat64(da, db).d; |
734 | cejka | 73 | } |
74 | |||
542 | cejka | 75 | float __subsf3(float a, float b) |
76 | { |
||
77 | float32 fa, fb; |
||
804 | cejka | 78 | fa.f = a; |
79 | fb.f = b; |
||
80 | if (fa.parts.sign != fb.parts.sign) { |
||
81 | fb.parts.sign = !fb.parts.sign; |
||
82 | return addFloat32(fa, fb).f; |
||
647 | cejka | 83 | } |
804 | cejka | 84 | return subFloat32(fa, fb).f; |
698 | cejka | 85 | } |
542 | cejka | 86 | |
734 | cejka | 87 | double __subdf3(double a, double b) |
88 | { |
||
89 | float64 da, db; |
||
90 | da.d = a; |
||
91 | db.d = b; |
||
92 | if (da.parts.sign != db.parts.sign) { |
||
93 | db.parts.sign = !db.parts.sign; |
||
94 | return addFloat64(da, db).d; |
||
95 | } |
||
96 | return subFloat64(da, db).d; |
||
97 | } |
||
98 | |||
688 | cejka | 99 | float __mulsf3(float a, float b) |
100 | { |
||
101 | float32 fa, fb; |
||
804 | cejka | 102 | fa.f = a; |
103 | fb.f = b; |
||
688 | cejka | 104 | return mulFloat32(fa, fb).f; |
105 | } |
||
106 | |||
737 | cejka | 107 | double __muldf3(double a, double b) |
108 | { |
||
109 | float64 da, db; |
||
110 | da.d = a; |
||
111 | db.d = b; |
||
112 | return mulFloat64(da, db).d; |
||
113 | } |
||
114 | |||
697 | cejka | 115 | float __divsf3(float a, float b) |
116 | { |
||
117 | float32 fa, fb; |
||
804 | cejka | 118 | fa.f = a; |
119 | fb.f = b; |
||
120 | return divFloat32(fa, fb).f; |
||
698 | cejka | 121 | } |
697 | cejka | 122 | |
828 | cejka | 123 | double __divdf3(double a, double b) |
124 | { |
||
125 | float64 da, db; |
||
126 | da.d = a; |
||
127 | db.d = b; |
||
128 | return divFloat64(da, db).d; |
||
129 | } |
||
130 | |||
542 | cejka | 131 | float __negsf2(float a) |
132 | { |
||
133 | float32 fa; |
||
804 | cejka | 134 | fa.f = a; |
135 | fa.parts.sign = !fa.parts.sign; |
||
542 | cejka | 136 | return fa.f; |
698 | cejka | 137 | } |
542 | cejka | 138 | |
139 | double __negdf2(double a) |
||
140 | { |
||
141 | float64 fa; |
||
804 | cejka | 142 | fa.d = a; |
143 | fa.parts.sign = !fa.parts.sign; |
||
563 | cejka | 144 | return fa.d; |
698 | cejka | 145 | } |
542 | cejka | 146 | |
647 | cejka | 147 | /* Conversion functions */ |
542 | cejka | 148 | |
697 | cejka | 149 | double __extendsfdf2(float a) |
150 | { |
||
151 | float32 fa; |
||
152 | fa.f = a; |
||
153 | return convertFloat32ToFloat64(fa).d; |
||
698 | cejka | 154 | } |
697 | cejka | 155 | |
156 | float __truncdfsf2(double a) |
||
157 | { |
||
158 | float64 da; |
||
159 | da.d = a; |
||
160 | return convertFloat64ToFloat32(da).f; |
||
161 | } |
||
698 | cejka | 162 | |
647 | cejka | 163 | /* Comparison functions */ |
542 | cejka | 164 | |
652 | cejka | 165 | /* a<b .. -1 |
166 | * a=b .. 0 |
||
167 | * a>b .. 1 |
||
168 | * */ |
||
169 | |||
660 | cejka | 170 | int __cmpsf2(float a, float b) |
652 | cejka | 171 | { |
804 | cejka | 172 | float32 fa, fb; |
173 | fa.f = a; |
||
174 | fb.f = b; |
||
175 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
652 | cejka | 176 | return 1; /* no special constant for unordered - maybe signaled? */ |
177 | }; |
||
178 | |||
179 | |||
804 | cejka | 180 | if (isFloat32eq(fa, fb)) { |
652 | cejka | 181 | return 0; |
182 | }; |
||
183 | |||
804 | cejka | 184 | if (isFloat32lt(fa, fb)) { |
652 | cejka | 185 | return -1; |
186 | }; |
||
187 | return 1; |
||
188 | } |
||
189 | |||
190 | int __unordsf2(float a, float b) |
||
191 | { |
||
804 | cejka | 192 | float32 fa, fb; |
193 | fa.f = a; |
||
194 | fb.f = b; |
||
195 | return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ); |
||
698 | cejka | 196 | } |
652 | cejka | 197 | |
198 | /** |
||
199 | * @return zero, if neither argument is a NaN and are equal |
||
200 | * */ |
||
201 | int __eqsf2(float a, float b) |
||
202 | { |
||
804 | cejka | 203 | float32 fa, fb; |
204 | fa.f = a; |
||
205 | fb.f = b; |
||
206 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
652 | cejka | 207 | /* TODO: sigNaNs*/ |
208 | return 1; |
||
209 | }; |
||
804 | cejka | 210 | return isFloat32eq(fa, fb) - 1; |
698 | cejka | 211 | } |
652 | cejka | 212 | |
213 | /* strange behavior, but it was in gcc documentation */ |
||
214 | int __nesf2(float a, float b) |
||
215 | { |
||
804 | cejka | 216 | return __eqsf2(a, b); |
698 | cejka | 217 | } |
653 | cejka | 218 | |
219 | /* return value >= 0 if a>=b and neither is NaN */ |
||
220 | int __gesf2(float a, float b) |
||
221 | { |
||
804 | cejka | 222 | float32 fa, fb; |
223 | fa.f = a; |
||
224 | fb.f = b; |
||
225 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
653 | cejka | 226 | /* TODO: sigNaNs*/ |
660 | cejka | 227 | return -1; |
653 | cejka | 228 | }; |
229 | |||
804 | cejka | 230 | if (isFloat32eq(fa, fb)) { |
653 | cejka | 231 | return 0; |
232 | }; |
||
233 | |||
804 | cejka | 234 | if (isFloat32gt(fa, fb)) { |
653 | cejka | 235 | return 1; |
236 | }; |
||
237 | |||
238 | return -1; |
||
239 | } |
||
240 | |||
241 | /** Return negative value, if a<b and neither is NaN*/ |
||
242 | int __ltsf2(float a, float b) |
||
243 | { |
||
804 | cejka | 244 | float32 fa, fb; |
245 | fa.f = a; |
||
246 | fb.f = b; |
||
247 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
653 | cejka | 248 | /* TODO: sigNaNs*/ |
249 | return 1; |
||
250 | }; |
||
251 | if (isFloat32lt(fa, fb)) { |
||
252 | return -1; |
||
253 | }; |
||
254 | return 0; |
||
255 | } |
||
256 | |||
257 | /* return value <= 0 if a<=b and neither is NaN */ |
||
258 | int __lesf2(float a, float b) |
||
259 | { |
||
804 | cejka | 260 | float32 fa, fb; |
261 | fa.f = a; |
||
262 | fb.f = b; |
||
263 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
653 | cejka | 264 | /* TODO: sigNaNs*/ |
265 | return 1; |
||
266 | }; |
||
267 | |||
804 | cejka | 268 | if (isFloat32eq(fa, fb)) { |
653 | cejka | 269 | return 0; |
270 | }; |
||
271 | |||
804 | cejka | 272 | if (isFloat32lt(fa, fb)) { |
653 | cejka | 273 | return -1; |
274 | }; |
||
275 | |||
276 | return 1; |
||
277 | } |
||
278 | |||
279 | /** Return positive value, if a>b and neither is NaN*/ |
||
660 | cejka | 280 | int __gtsf2(float a, float b) |
653 | cejka | 281 | { |
804 | cejka | 282 | float32 fa, fb; |
283 | fa.f = a; |
||
284 | fb.f = b; |
||
285 | if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) { |
||
653 | cejka | 286 | /* TODO: sigNaNs*/ |
660 | cejka | 287 | return -1; |
653 | cejka | 288 | }; |
289 | if (isFloat32gt(fa, fb)) { |
||
290 | return 1; |
||
291 | }; |
||
292 | return 0; |
||
293 | } |
||
294 | |||
647 | cejka | 295 | /* Other functions */ |
542 | cejka | 296 | |
698 | cejka | 297 | float __powisf2(float a, int b) |
298 | { |
||
804 | cejka | 299 | /* TODO: */ |
698 | cejka | 300 | } |
301 | |||
302 | float __mulsc3(float a, float b, float c, float d) |
||
303 | { |
||
804 | cejka | 304 | /* TODO: */ |
698 | cejka | 305 | } |
306 | |||
307 | float __divsc3(float a, float b, float c, float d) |
||
308 | { |
||
804 | cejka | 309 | /* TODO: */ |
698 | cejka | 310 | } |
311 |