source: mainline/softfloat/generic/softfloat.c@ a96c570

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a96c570 was a96c570, checked in by Josef Cejka <malyzelenyhnus@…>, 19 years ago

Added function for 64bit subtraction.
Fixed bug in recognizing signaling and quiet NaNs.
Some 64-bit add and sub testing done.

  • Property mode set to 100644
File size: 5.3 KB
Line 
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>
30#include<sftypes.h>
31
32#include<add.h>
33#include<sub.h>
34#include<mul.h>
35#include<div.h>
36
37#include<conversion.h>
38#include<comparison.h>
39#include<other.h>
40
41/* Arithmetic functions */
42
43float __addsf3(float a, float b)
44{
45 float32 fa, fb;
46 fa.f=a;
47 fb.f=b;
48 if (fa.parts.sign!=fb.parts.sign) {
49 if (fa.parts.sign) {
50 fa.parts.sign=0;
51 return subFloat32(fb,fa).f;
52 };
53 fb.parts.sign=0;
54 return subFloat32(fa,fb).f;
55 }
56 return addFloat32(fa,fb).f;
57}
58
59double __adddf3(double a, double b)
60{
61 float64 da, db;
62 da.d=a;
63 db.d=b;
64 if (da.parts.sign!=db.parts.sign) {
65 if (da.parts.sign) {
66 da.parts.sign=0;
67 return subFloat64(db,da).d;
68 };
69 db.parts.sign=0;
70 return subFloat64(da,db).d;
71 }
72 return addFloat64(da,db).d;
73}
74
75float __subsf3(float a, float b)
76{
77 float32 fa, fb;
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;
83 }
84 return subFloat32(fa,fb).f;
85}
86
87double __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
99float __mulsf3(float a, float b)
100{
101 float32 fa, fb;
102 fa.f=a;
103 fb.f=b;
104 return mulFloat32(fa, fb).f;
105}
106
107float __divsf3(float a, float b)
108{
109 float32 fa, fb;
110 fa.f=a;
111 fb.f=b;
112 //return divFloat32(fa, fb).f;
113}
114
115float __negsf2(float a)
116{
117 float32 fa;
118 fa.f=a;
119 fa.parts.sign=!fa.parts.sign;
120 return fa.f;
121}
122
123double __negdf2(double a)
124{
125 float64 fa;
126 fa.d=a;
127 fa.parts.sign=!fa.parts.sign;
128 return fa.d;
129}
130
131/* Conversion functions */
132
133double __extendsfdf2(float a)
134{
135 float32 fa;
136 fa.f = a;
137 return convertFloat32ToFloat64(fa).d;
138}
139
140float __truncdfsf2(double a)
141{
142 float64 da;
143 da.d = a;
144 return convertFloat64ToFloat32(da).f;
145}
146
147/* Comparison functions */
148
149/* a<b .. -1
150 * a=b .. 0
151 * a>b .. 1
152 * */
153
154int __cmpsf2(float a, float b)
155{
156 float32 fa,fb;
157 fa.f=a;
158 fb.f=b;
159 if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
160 return 1; /* no special constant for unordered - maybe signaled? */
161 };
162
163
164 if (isFloat32eq(fa,fb)) {
165 return 0;
166 };
167
168 if (isFloat32lt(fa,fb)) {
169 return -1;
170 };
171 return 1;
172}
173
174int __unordsf2(float a, float b)
175{
176 float32 fa,fb;
177 fa.f=a;
178 fb.f=b;
179 return ((isFloat32NaN(fa))||(isFloat32NaN(fb)));
180}
181
182/**
183 * @return zero, if neither argument is a NaN and are equal
184 * */
185int __eqsf2(float a, float b)
186{
187 float32 fa,fb;
188 fa.f=a;
189 fb.f=b;
190 if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
191 /* TODO: sigNaNs*/
192 return 1;
193 };
194 return isFloat32eq(fa,fb)-1;
195}
196
197/* strange behavior, but it was in gcc documentation */
198int __nesf2(float a, float b)
199{
200 return __eqsf2(a,b);
201}
202
203/* return value >= 0 if a>=b and neither is NaN */
204int __gesf2(float a, float b)
205{
206 float32 fa,fb;
207 fa.f=a;
208 fb.f=b;
209 if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
210 /* TODO: sigNaNs*/
211 return -1;
212 };
213
214 if (isFloat32eq(fa,fb)) {
215 return 0;
216 };
217
218 if (isFloat32gt(fa,fb)) {
219 return 1;
220 };
221
222 return -1;
223}
224
225/** Return negative value, if a<b and neither is NaN*/
226int __ltsf2(float a, float b)
227{
228 float32 fa,fb;
229 fa.f=a;
230 fb.f=b;
231 if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
232 /* TODO: sigNaNs*/
233 return 1;
234 };
235 if (isFloat32lt(fa, fb)) {
236 return -1;
237 };
238 return 0;
239}
240
241/* return value <= 0 if a<=b and neither is NaN */
242int __lesf2(float a, float b)
243{
244 float32 fa,fb;
245 fa.f=a;
246 fb.f=b;
247 if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
248 /* TODO: sigNaNs*/
249 return 1;
250 };
251
252 if (isFloat32eq(fa,fb)) {
253 return 0;
254 };
255
256 if (isFloat32lt(fa,fb)) {
257 return -1;
258 };
259
260 return 1;
261}
262
263/** Return positive value, if a>b and neither is NaN*/
264int __gtsf2(float a, float b)
265{
266 float32 fa,fb;
267 fa.f=a;
268 fb.f=b;
269 if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
270 /* TODO: sigNaNs*/
271 return -1;
272 };
273 if (isFloat32gt(fa, fb)) {
274 return 1;
275 };
276 return 0;
277}
278
279/* Other functions */
280
281float __powisf2(float a, int b)
282{
283//TODO:
284}
285
286float __mulsc3(float a, float b, float c, float d)
287{
288//TODO:
289}
290
291float __divsc3(float a, float b, float c, float d)
292{
293//TODO:
294}
295
Note: See TracBrowser for help on using the repository browser.