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

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

32 bit float division added.
Some small bugs fixed.
Code cleanup.

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