Subversion Repositories HelenOS-historic

Rev

Rev 1657 | 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
 
1740 jermar 29
/** @addtogroup softfloat generic
30
 * @ingroup sfl
1657 cejka 31
 * @brief Architecture independent parts of FPU software emulation library.
32
 * @{
33
 */
34
/** @file
35
 */
36
 
535 cejka 37
#include<softfloat.h>
647 cejka 38
#include<sftypes.h>
731 cejka 39
 
40
#include<add.h>
41
#include<sub.h>
42
#include<mul.h>
43
#include<div.h>
44
 
647 cejka 45
#include<conversion.h>
46
#include<comparison.h>
47
#include<other.h>
535 cejka 48
 
857 cejka 49
#include<functions.h>
50
 
647 cejka 51
/* Arithmetic functions */
542 cejka 52
 
53
float __addsf3(float a, float b)
54
{
55
	float32 fa, fb;
804 cejka 56
	fa.f = a;
57
	fb.f = b;
58
	if (fa.parts.sign != fb.parts.sign) {
647 cejka 59
		if (fa.parts.sign) {
804 cejka 60
			fa.parts.sign = 0;
61
			return subFloat32(fb, fa).f;
647 cejka 62
		};
804 cejka 63
		fb.parts.sign = 0;
64
		return subFloat32(fa, fb).f;
647 cejka 65
	}
804 cejka 66
	return addFloat32(fa, fb).f;
698 cejka 67
}
542 cejka 68
 
734 cejka 69
double __adddf3(double a, double b)
70
{
71
	float64 da, db;
804 cejka 72
	da.d = a;
73
	db.d = b;
74
	if (da.parts.sign != db.parts.sign) {
734 cejka 75
		if (da.parts.sign) {
804 cejka 76
			da.parts.sign = 0;
77
			return subFloat64(db, da).d;
734 cejka 78
		};
804 cejka 79
		db.parts.sign = 0;
80
		return subFloat64(da, db).d;
734 cejka 81
	}
804 cejka 82
	return addFloat64(da, db).d;
734 cejka 83
}
84
 
542 cejka 85
float __subsf3(float a, float b)
86
{
87
	float32 fa, fb;
804 cejka 88
	fa.f = a;
89
	fb.f = b;
90
	if (fa.parts.sign != fb.parts.sign) {
91
		fb.parts.sign = !fb.parts.sign;
92
		return addFloat32(fa, fb).f;
647 cejka 93
	}
804 cejka 94
	return subFloat32(fa, fb).f;
698 cejka 95
}
542 cejka 96
 
734 cejka 97
double __subdf3(double a, double b)
98
{
99
	float64 da, db;
100
	da.d = a;
101
	db.d = b;
102
	if (da.parts.sign != db.parts.sign) {
103
		db.parts.sign = !db.parts.sign;
104
		return addFloat64(da, db).d;
105
	}
106
	return subFloat64(da, db).d;
107
}
108
 
688 cejka 109
float __mulsf3(float a, float b) 
110
{
111
	float32 fa, fb;
804 cejka 112
	fa.f = a;
113
	fb.f = b;
688 cejka 114
	return 	mulFloat32(fa, fb).f;
115
}
116
 
737 cejka 117
double __muldf3(double a, double b) 
118
{
119
	float64 da, db;
120
	da.d = a;
121
	db.d = b;
122
	return 	mulFloat64(da, db).d;
123
}
124
 
697 cejka 125
float __divsf3(float a, float b) 
126
{
127
	float32 fa, fb;
804 cejka 128
	fa.f = a;
129
	fb.f = b;
130
	return 	divFloat32(fa, fb).f;
698 cejka 131
}
697 cejka 132
 
828 cejka 133
double __divdf3(double a, double b) 
134
{
135
	float64 da, db;
136
	da.d = a;
137
	db.d = b;
138
	return 	divFloat64(da, db).d;
139
}
140
 
542 cejka 141
float __negsf2(float a)
142
{
143
	float32 fa;
804 cejka 144
	fa.f = a;
145
	fa.parts.sign = !fa.parts.sign;
542 cejka 146
	return fa.f;
698 cejka 147
}
542 cejka 148
 
149
double __negdf2(double a)
150
{
151
	float64 fa;
804 cejka 152
	fa.d = a;
153
	fa.parts.sign = !fa.parts.sign;
563 cejka 154
	return fa.d;
698 cejka 155
}
542 cejka 156
 
647 cejka 157
/* Conversion functions */
542 cejka 158
 
697 cejka 159
double __extendsfdf2(float a) 
160
{
161
	float32 fa;
162
	fa.f = a;
163
	return convertFloat32ToFloat64(fa).d;
698 cejka 164
}
697 cejka 165
 
166
float __truncdfsf2(double a) 
167
{
168
	float64 da;
169
	da.d = a;
170
	return convertFloat64ToFloat32(da).f;
171
}
698 cejka 172
 
857 cejka 173
int __fixsfsi(float a)
174
{
175
	float32 fa;
176
	fa.f = a;
177
 
178
	return float32_to_int(fa);
179
}
180
int __fixdfsi(double a)
181
{
865 cejka 182
	float64 da;
183
	da.d = a;
184
 
185
	return float64_to_int(da);
857 cejka 186
}
187
 
188
long __fixsfdi(float a)
189
{
190
	float32 fa;
191
	fa.f = a;
192
 
193
	return float32_to_long(fa);
194
}
195
long __fixdfdi(double a)
196
{
865 cejka 197
	float64 da;
198
	da.d = a;
199
 
200
	return float64_to_long(da);
857 cejka 201
}
202
 
203
long long __fixsfti(float a)
204
{
865 cejka 205
	float32 fa;
206
	fa.f = a;
207
 
208
	return float32_to_longlong(fa);
857 cejka 209
}
210
long long __fixdfti(double a)
211
{
865 cejka 212
	float64 da;
213
	da.d = a;
214
 
215
	return float64_to_longlong(da);
857 cejka 216
}
217
 
218
unsigned int __fixunssfsi(float a)
219
{
220
	float32 fa;
221
	fa.f = a;
222
 
223
	return float32_to_uint(fa);
224
}
225
unsigned int __fixunsdfsi(double a)
226
{
865 cejka 227
	float64 da;
228
	da.d = a;
229
 
230
	return float64_to_uint(da);
857 cejka 231
}
232
 
233
unsigned long __fixunssfdi(float a)
234
{
235
	float32 fa;
236
	fa.f = a;
237
 
858 cejka 238
	return float32_to_ulong(fa);
857 cejka 239
}
240
unsigned long __fixunsdfdi(double a)
241
{
865 cejka 242
	float64 da;
243
	da.d = a;
244
 
245
	return float64_to_ulong(da);
857 cejka 246
}
247
 
248
unsigned long long __fixunssfti(float a)
249
{
865 cejka 250
	float32 fa;
251
	fa.f = a;
252
 
253
	return float32_to_ulonglong(fa);
857 cejka 254
}
255
unsigned long long __fixunsdfti(double a)
256
{
865 cejka 257
	float64 da;
258
	da.d = a;
259
 
260
	return float64_to_ulonglong(da);
857 cejka 261
}
262
 
263
float __floatsisf(int i)
264
{
874 cejka 265
	float32 fa;
266
 
267
	fa = int_to_float32(i);
268
	return fa.f;
857 cejka 269
}
270
double __floatsidf(int i)
271
{
876 cejka 272
	float64 da;
273
 
274
	da = int_to_float64(i);
275
	return da.d;
857 cejka 276
}
277
 
278
float __floatdisf(long i)
279
{
874 cejka 280
	float32 fa;
281
 
282
	fa = long_to_float32(i);
283
	return fa.f;
857 cejka 284
}
285
double __floatdidf(long i)
286
{
876 cejka 287
	float64 da;
288
 
289
	da = long_to_float64(i);
290
	return da.d;
857 cejka 291
}
292
 
293
float __floattisf(long long i)
294
{
874 cejka 295
	float32 fa;
296
 
297
	fa = longlong_to_float32(i);
298
	return fa.f;
857 cejka 299
}
300
double __floattidf(long long i)
301
{
876 cejka 302
	float64 da;
303
 
304
	da = longlong_to_float64(i);
305
	return da.d;
857 cejka 306
}
307
 
308
float __floatunsisf(unsigned int i)
309
{
874 cejka 310
	float32 fa;
311
 
312
	fa = uint_to_float32(i);
313
	return fa.f;
857 cejka 314
}
315
double __floatunsidf(unsigned int i)
316
{
876 cejka 317
	float64 da;
318
 
319
	da = uint_to_float64(i);
320
	return da.d;
857 cejka 321
}
322
 
323
float __floatundisf(unsigned long i)
324
{
874 cejka 325
	float32 fa;
326
 
327
	fa = ulong_to_float32(i);
328
	return fa.f;
857 cejka 329
}
330
double __floatundidf(unsigned long i)
331
{
876 cejka 332
	float64 da;
333
 
334
	da = ulong_to_float64(i);
335
	return da.d;
857 cejka 336
}
337
 
338
float __floatuntisf(unsigned long long i)
339
{
874 cejka 340
	float32 fa;
341
 
342
	fa = ulonglong_to_float32(i);
343
	return fa.f;
857 cejka 344
}
345
double __floatuntidf(unsigned long long i)
346
{
876 cejka 347
	float64 da;
348
 
349
	da = ulonglong_to_float64(i);
350
	return da.d;
857 cejka 351
}
352
 
647 cejka 353
/* Comparison functions */
857 cejka 354
/* Comparison functions */
542 cejka 355
 
652 cejka 356
/* a<b .. -1
357
 * a=b ..  0
358
 * a>b ..  1
359
 * */
360
 
660 cejka 361
int __cmpsf2(float a, float b) 
652 cejka 362
{
804 cejka 363
	float32 fa, fb;
364
	fa.f = a;
365
	fb.f = b;
366
	if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
652 cejka 367
		return 1; /* no special constant for unordered - maybe signaled? */
368
	};
369
 
370
 
804 cejka 371
	if (isFloat32eq(fa, fb)) {
652 cejka 372
		return 0;
373
	};
374
 
804 cejka 375
	if (isFloat32lt(fa, fb)) {
652 cejka 376
		return -1;
377
		};
378
	return 1;
379
}
380
 
381
int __unordsf2(float a, float b) 
382
{
804 cejka 383
	float32 fa, fb;
384
	fa.f = a;
385
	fb.f = b;
386
	return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) );
698 cejka 387
}
652 cejka 388
 
389
/** 
390
 * @return zero, if neither argument is a NaN and are equal
391
 * */
392
int __eqsf2(float a, float b) 
393
{
804 cejka 394
	float32 fa, fb;
395
	fa.f = a;
396
	fb.f = b;
397
	if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
652 cejka 398
		/* TODO: sigNaNs*/
399
		return 1;
400
		};
804 cejka 401
	return isFloat32eq(fa, fb) - 1;
698 cejka 402
}
652 cejka 403
 
404
/* strange behavior, but it was in gcc documentation */
405
int __nesf2(float a, float b) 
406
{
804 cejka 407
	return __eqsf2(a, b);
698 cejka 408
}
653 cejka 409
 
410
/* return value >= 0 if a>=b and neither is NaN */
411
int __gesf2(float a, float b)
412
{
804 cejka 413
	float32 fa, fb;
414
	fa.f = a;
415
	fb.f = b;
416
	if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
653 cejka 417
		/* TODO: sigNaNs*/
660 cejka 418
		return -1;
653 cejka 419
		};
420
 
804 cejka 421
	if (isFloat32eq(fa, fb)) {
653 cejka 422
		return 0;
423
	};
424
 
804 cejka 425
	if (isFloat32gt(fa, fb)) {
653 cejka 426
		return 1;
427
		};
428
 
429
	return -1;
430
}
431
 
432
/** Return negative value, if a<b and neither is NaN*/
433
int __ltsf2(float a, float b)
434
{
804 cejka 435
	float32 fa, fb;
436
	fa.f = a;
437
	fb.f = b;
438
	if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
653 cejka 439
		/* TODO: sigNaNs*/
440
		return 1;
441
		};
442
	if (isFloat32lt(fa, fb)) {
443
		return -1;
444
		};
445
	return 0;
446
}
447
 
448
/* return value <= 0 if a<=b and neither is NaN */
449
int __lesf2(float a, float b)
450
{
804 cejka 451
	float32 fa, fb;
452
	fa.f = a;
453
	fb.f = b;
454
	if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
653 cejka 455
		/* TODO: sigNaNs*/
456
		return 1;
457
		};
458
 
804 cejka 459
	if (isFloat32eq(fa, fb)) {
653 cejka 460
		return 0;
461
	};
462
 
804 cejka 463
	if (isFloat32lt(fa, fb)) {
653 cejka 464
		return -1;
465
		};
466
 
467
	return 1;
468
}
469
 
470
/** Return positive value, if a>b and neither is NaN*/
660 cejka 471
int __gtsf2(float a, float b)
653 cejka 472
{
804 cejka 473
	float32 fa, fb;
474
	fa.f = a;
475
	fb.f = b;
476
	if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
653 cejka 477
		/* TODO: sigNaNs*/
660 cejka 478
		return -1;
653 cejka 479
		};
480
	if (isFloat32gt(fa, fb)) {
481
		return 1;
482
		};
483
	return 0;
484
}
485
 
647 cejka 486
/* Other functions */
542 cejka 487
 
698 cejka 488
float __powisf2(float a, int b)
489
{
804 cejka 490
/* TODO: */
1035 cejka 491
	float32 fa;
492
	fa.binary = FLOAT32_NAN;
493
	return fa.f;
698 cejka 494
}
495
 
1657 cejka 496
 
1740 jermar 497
/** @}
1657 cejka 498
 */
499