Rev 688 | Rev 698 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 688 | Rev 697 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Josef Cejka |
2 | * Copyright (C) 2005 Josef Cejka |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include<softfloat.h> |
29 | #include<softfloat.h> |
30 | #include<sftypes.h> |
30 | #include<sftypes.h> |
31 | #include<arithmetic.h> |
31 | #include<arithmetic.h> |
32 | #include<conversion.h> |
32 | #include<conversion.h> |
33 | #include<comparison.h> |
33 | #include<comparison.h> |
34 | #include<other.h> |
34 | #include<other.h> |
35 | 35 | ||
36 | /* Arithmetic functions */ |
36 | /* Arithmetic functions */ |
37 | 37 | ||
38 | float __addsf3(float a, float b) |
38 | float __addsf3(float a, float b) |
39 | { |
39 | { |
40 | float32 fa, fb; |
40 | float32 fa, fb; |
41 | fa.f=a; |
41 | fa.f=a; |
42 | fb.f=b; |
42 | fb.f=b; |
43 | if (fa.parts.sign!=fb.parts.sign) { |
43 | if (fa.parts.sign!=fb.parts.sign) { |
44 | if (fa.parts.sign) { |
44 | if (fa.parts.sign) { |
45 | fa.parts.sign=0; |
45 | fa.parts.sign=0; |
46 | return subFloat32(fb,fa).f; |
46 | return subFloat32(fb,fa).f; |
47 | }; |
47 | }; |
48 | fb.parts.sign=0; |
48 | fb.parts.sign=0; |
49 | return subFloat32(fa,fb).f; |
49 | return subFloat32(fa,fb).f; |
50 | } |
50 | } |
51 | return addFloat32(fa,fb).f; |
51 | return addFloat32(fa,fb).f; |
52 | }; |
52 | }; |
53 | 53 | ||
54 | float __subsf3(float a, float b) |
54 | float __subsf3(float a, float b) |
55 | { |
55 | { |
56 | float32 fa, fb; |
56 | float32 fa, fb; |
57 | fa.f=a; |
57 | fa.f=a; |
58 | fb.f=b; |
58 | fb.f=b; |
59 | if (fa.parts.sign!=fb.parts.sign) { |
59 | if (fa.parts.sign!=fb.parts.sign) { |
60 | fb.parts.sign=!fb.parts.sign; |
60 | fb.parts.sign=!fb.parts.sign; |
61 | return addFloat32(fa,fb).f; |
61 | return addFloat32(fa,fb).f; |
62 | } |
62 | } |
63 | return subFloat32(fa,fb).f; |
63 | return subFloat32(fa,fb).f; |
64 | }; |
64 | }; |
65 | 65 | ||
66 | float __mulsf3(float a, float b) |
66 | float __mulsf3(float a, float b) |
67 | { |
67 | { |
68 | float32 fa, fb; |
68 | float32 fa, fb; |
69 | fa.f=a; |
69 | fa.f=a; |
70 | fb.f=b; |
70 | fb.f=b; |
71 | return mulFloat32(fa, fb).f; |
71 | return mulFloat32(fa, fb).f; |
72 | } |
72 | } |
73 | 73 | ||
- | 74 | float __divsf3(float a, float b) |
|
- | 75 | { |
|
- | 76 | float32 fa, fb; |
|
- | 77 | fa.f=a; |
|
- | 78 | fb.f=b; |
|
- | 79 | // return divFloat32(fa, fb).f; |
|
- | 80 | }; |
|
- | 81 | ||
74 | float __negsf2(float a) |
82 | float __negsf2(float a) |
75 | { |
83 | { |
76 | float32 fa; |
84 | float32 fa; |
77 | fa.f=a; |
85 | fa.f=a; |
78 | fa.parts.sign=!fa.parts.sign; |
86 | fa.parts.sign=!fa.parts.sign; |
79 | return fa.f; |
87 | return fa.f; |
80 | }; |
88 | }; |
81 | 89 | ||
82 | double __negdf2(double a) |
90 | double __negdf2(double a) |
83 | { |
91 | { |
84 | float64 fa; |
92 | float64 fa; |
85 | fa.d=a; |
93 | fa.d=a; |
86 | fa.parts.sign=!fa.parts.sign; |
94 | fa.parts.sign=!fa.parts.sign; |
87 | return fa.d; |
95 | return fa.d; |
88 | }; |
96 | }; |
89 | 97 | ||
90 | /* Conversion functions */ |
98 | /* Conversion functions */ |
91 | 99 | ||
- | 100 | double __extendsfdf2(float a) |
|
- | 101 | { |
|
- | 102 | float32 fa; |
|
- | 103 | fa.f = a; |
|
- | 104 | return convertFloat32ToFloat64(fa).d; |
|
- | 105 | }; |
|
- | 106 | ||
- | 107 | float __truncdfsf2(double a) |
|
- | 108 | { |
|
- | 109 | float64 da; |
|
- | 110 | da.d = a; |
|
- | 111 | return convertFloat64ToFloat32(da).f; |
|
- | 112 | } |
|
92 | /* Comparison functions */ |
113 | /* Comparison functions */ |
93 | 114 | ||
94 | /* a<b .. -1 |
115 | /* a<b .. -1 |
95 | * a=b .. 0 |
116 | * a=b .. 0 |
96 | * a>b .. 1 |
117 | * a>b .. 1 |
97 | * */ |
118 | * */ |
98 | 119 | ||
99 | int __cmpsf2(float a, float b) |
120 | int __cmpsf2(float a, float b) |
100 | { |
121 | { |
101 | float32 fa,fb; |
122 | float32 fa,fb; |
102 | fa.f=a; |
123 | fa.f=a; |
103 | fb.f=b; |
124 | fb.f=b; |
104 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
125 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
105 | return 1; /* no special constant for unordered - maybe signaled? */ |
126 | return 1; /* no special constant for unordered - maybe signaled? */ |
106 | }; |
127 | }; |
107 | 128 | ||
108 | 129 | ||
109 | if (isFloat32eq(fa,fb)) { |
130 | if (isFloat32eq(fa,fb)) { |
110 | return 0; |
131 | return 0; |
111 | }; |
132 | }; |
112 | 133 | ||
113 | if (isFloat32lt(fa,fb)) { |
134 | if (isFloat32lt(fa,fb)) { |
114 | return -1; |
135 | return -1; |
115 | }; |
136 | }; |
116 | return 1; |
137 | return 1; |
117 | } |
138 | } |
118 | 139 | ||
119 | int __unordsf2(float a, float b) |
140 | int __unordsf2(float a, float b) |
120 | { |
141 | { |
121 | float32 fa,fb; |
142 | float32 fa,fb; |
122 | fa.f=a; |
143 | fa.f=a; |
123 | fb.f=b; |
144 | fb.f=b; |
124 | return ((isFloat32NaN(fa))||(isFloat32NaN(fb))); |
145 | return ((isFloat32NaN(fa))||(isFloat32NaN(fb))); |
125 | }; |
146 | }; |
126 | 147 | ||
127 | /** |
148 | /** |
128 | * @return zero, if neither argument is a NaN and are equal |
149 | * @return zero, if neither argument is a NaN and are equal |
129 | * */ |
150 | * */ |
130 | int __eqsf2(float a, float b) |
151 | int __eqsf2(float a, float b) |
131 | { |
152 | { |
132 | float32 fa,fb; |
153 | float32 fa,fb; |
133 | fa.f=a; |
154 | fa.f=a; |
134 | fb.f=b; |
155 | fb.f=b; |
135 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
156 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
136 | /* TODO: sigNaNs*/ |
157 | /* TODO: sigNaNs*/ |
137 | return 1; |
158 | return 1; |
138 | }; |
159 | }; |
139 | return isFloat32eq(fa,fb)-1; |
160 | return isFloat32eq(fa,fb)-1; |
140 | }; |
161 | }; |
141 | 162 | ||
142 | /* strange behavior, but it was in gcc documentation */ |
163 | /* strange behavior, but it was in gcc documentation */ |
143 | int __nesf2(float a, float b) |
164 | int __nesf2(float a, float b) |
144 | { |
165 | { |
145 | return __eqsf2(a,b); |
166 | return __eqsf2(a,b); |
146 | }; |
167 | }; |
147 | 168 | ||
148 | /* return value >= 0 if a>=b and neither is NaN */ |
169 | /* return value >= 0 if a>=b and neither is NaN */ |
149 | int __gesf2(float a, float b) |
170 | int __gesf2(float a, float b) |
150 | { |
171 | { |
151 | float32 fa,fb; |
172 | float32 fa,fb; |
152 | fa.f=a; |
173 | fa.f=a; |
153 | fb.f=b; |
174 | fb.f=b; |
154 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
175 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
155 | /* TODO: sigNaNs*/ |
176 | /* TODO: sigNaNs*/ |
156 | return -1; |
177 | return -1; |
157 | }; |
178 | }; |
158 | 179 | ||
159 | if (isFloat32eq(fa,fb)) { |
180 | if (isFloat32eq(fa,fb)) { |
160 | return 0; |
181 | return 0; |
161 | }; |
182 | }; |
162 | 183 | ||
163 | if (isFloat32gt(fa,fb)) { |
184 | if (isFloat32gt(fa,fb)) { |
164 | return 1; |
185 | return 1; |
165 | }; |
186 | }; |
166 | 187 | ||
167 | return -1; |
188 | return -1; |
168 | } |
189 | } |
169 | 190 | ||
170 | /** Return negative value, if a<b and neither is NaN*/ |
191 | /** Return negative value, if a<b and neither is NaN*/ |
171 | int __ltsf2(float a, float b) |
192 | int __ltsf2(float a, float b) |
172 | { |
193 | { |
173 | float32 fa,fb; |
194 | float32 fa,fb; |
174 | fa.f=a; |
195 | fa.f=a; |
175 | fb.f=b; |
196 | fb.f=b; |
176 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
197 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
177 | /* TODO: sigNaNs*/ |
198 | /* TODO: sigNaNs*/ |
178 | return 1; |
199 | return 1; |
179 | }; |
200 | }; |
180 | if (isFloat32lt(fa, fb)) { |
201 | if (isFloat32lt(fa, fb)) { |
181 | return -1; |
202 | return -1; |
182 | }; |
203 | }; |
183 | return 0; |
204 | return 0; |
184 | } |
205 | } |
185 | 206 | ||
186 | /* return value <= 0 if a<=b and neither is NaN */ |
207 | /* return value <= 0 if a<=b and neither is NaN */ |
187 | int __lesf2(float a, float b) |
208 | int __lesf2(float a, float b) |
188 | { |
209 | { |
189 | float32 fa,fb; |
210 | float32 fa,fb; |
190 | fa.f=a; |
211 | fa.f=a; |
191 | fb.f=b; |
212 | fb.f=b; |
192 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
213 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
193 | /* TODO: sigNaNs*/ |
214 | /* TODO: sigNaNs*/ |
194 | return 1; |
215 | return 1; |
195 | }; |
216 | }; |
196 | 217 | ||
197 | if (isFloat32eq(fa,fb)) { |
218 | if (isFloat32eq(fa,fb)) { |
198 | return 0; |
219 | return 0; |
199 | }; |
220 | }; |
200 | 221 | ||
201 | if (isFloat32lt(fa,fb)) { |
222 | if (isFloat32lt(fa,fb)) { |
202 | return -1; |
223 | return -1; |
203 | }; |
224 | }; |
204 | 225 | ||
205 | return 1; |
226 | return 1; |
206 | } |
227 | } |
207 | 228 | ||
208 | /** Return positive value, if a>b and neither is NaN*/ |
229 | /** Return positive value, if a>b and neither is NaN*/ |
209 | int __gtsf2(float a, float b) |
230 | int __gtsf2(float a, float b) |
210 | { |
231 | { |
211 | float32 fa,fb; |
232 | float32 fa,fb; |
212 | fa.f=a; |
233 | fa.f=a; |
213 | fb.f=b; |
234 | fb.f=b; |
214 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
235 | if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) { |
215 | /* TODO: sigNaNs*/ |
236 | /* TODO: sigNaNs*/ |
216 | return -1; |
237 | return -1; |
217 | }; |
238 | }; |
218 | if (isFloat32gt(fa, fb)) { |
239 | if (isFloat32gt(fa, fb)) { |
219 | return 1; |
240 | return 1; |
220 | }; |
241 | }; |
221 | return 0; |
242 | return 0; |
222 | } |
243 | } |
223 | 244 | ||
224 | /* Other functions */ |
245 | /* Other functions */ |
225 | 246 | ||
226 | 247 |