| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: softfloat.c,v 1.5 2007/11/08 21:31:04 martin Exp $ */ | | 1 | /* softfloat.c,v 1.5 2007/11/08 21:31:04 martin Exp */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * This version hacked for use with gcc -msoft-float by bjh21. | | 4 | * This version hacked for use with gcc -msoft-float by bjh21. |
5 | * (Mostly a case of #ifdefing out things GCC doesn't need or provides | | 5 | * (Mostly a case of #ifdefing out things GCC doesn't need or provides |
6 | * itself). | | 6 | * itself). |
7 | */ | | 7 | */ |
8 | | | 8 | |
9 | /* | | 9 | /* |
10 | * Things you may want to define: | | 10 | * Things you may want to define: |
11 | * | | 11 | * |
12 | * SOFTFLOAT_FOR_GCC - build only those functions necessary for GCC (with | | 12 | * SOFTFLOAT_FOR_GCC - build only those functions necessary for GCC (with |
13 | * -msoft-float) to work. Include "softfloat-for-gcc.h" to get them | | 13 | * -msoft-float) to work. Include "softfloat-for-gcc.h" to get them |
14 | * properly renamed. | | 14 | * properly renamed. |
| @@ -36,27 +36,27 @@ TIMES RESULT IN INCORRECT BEHAVIOR. USE | | | @@ -36,27 +36,27 @@ TIMES RESULT IN INCORRECT BEHAVIOR. USE |
36 | PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY | | 36 | PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY |
37 | AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. | | 37 | AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. |
38 | | | 38 | |
39 | Derivative works are acceptable, even for commercial purposes, so long as | | 39 | Derivative works are acceptable, even for commercial purposes, so long as |
40 | (1) they include prominent notice that the work is derivative, and (2) they | | 40 | (1) they include prominent notice that the work is derivative, and (2) they |
41 | include prominent notice akin to these four paragraphs for those parts of | | 41 | include prominent notice akin to these four paragraphs for those parts of |
42 | this code that are retained. | | 42 | this code that are retained. |
43 | | | 43 | |
44 | =============================================================================== | | 44 | =============================================================================== |
45 | */ | | 45 | */ |
46 | | | 46 | |
47 | #include <sys/cdefs.h> | | 47 | #include <sys/cdefs.h> |
48 | #if defined(LIBC_SCCS) && !defined(lint) | | 48 | #if defined(LIBC_SCCS) && !defined(lint) |
49 | __RCSID("$NetBSD: softfloat.c,v 1.5 2007/11/08 21:31:04 martin Exp $"); | | 49 | __RCSID("softfloat.c,v 1.5 2007/11/08 21:31:04 martin Exp"); |
50 | #endif /* LIBC_SCCS and not lint */ | | 50 | #endif /* LIBC_SCCS and not lint */ |
51 | | | 51 | |
52 | #ifdef SOFTFLOAT_FOR_GCC | | 52 | #ifdef SOFTFLOAT_FOR_GCC |
53 | #include "softfloat-for-gcc.h" | | 53 | #include "softfloat-for-gcc.h" |
54 | #endif | | 54 | #endif |
55 | | | 55 | |
56 | #include "milieu.h" | | 56 | #include "milieu.h" |
57 | #include "softfloat.h" | | 57 | #include "softfloat.h" |
58 | | | 58 | |
59 | /* | | 59 | /* |
60 | * Conversions between floats as stored in memory and floats as | | 60 | * Conversions between floats as stored in memory and floats as |
61 | * SoftFloat uses them | | 61 | * SoftFloat uses them |
62 | */ | | 62 | */ |
| @@ -4325,26 +4325,66 @@ int32 float128_to_int32_round_to_zero( f | | | @@ -4325,26 +4325,66 @@ int32 float128_to_int32_round_to_zero( f |
4325 | if ( ( z < 0 ) ^ aSign ) { | | 4325 | if ( ( z < 0 ) ^ aSign ) { |
4326 | invalid: | | 4326 | invalid: |
4327 | float_raise( float_flag_invalid ); | | 4327 | float_raise( float_flag_invalid ); |
4328 | return aSign ? (sbits32) 0x80000000 : 0x7FFFFFFF; | | 4328 | return aSign ? (sbits32) 0x80000000 : 0x7FFFFFFF; |
4329 | } | | 4329 | } |
4330 | if ( ( aSig0<<shiftCount ) != savedASig ) { | | 4330 | if ( ( aSig0<<shiftCount ) != savedASig ) { |
4331 | float_exception_flags |= float_flag_inexact; | | 4331 | float_exception_flags |= float_flag_inexact; |
4332 | } | | 4332 | } |
4333 | return z; | | 4333 | return z; |
4334 | | | 4334 | |
4335 | } | | 4335 | } |
4336 | | | 4336 | |
4337 | /* | | 4337 | /* |
| | | 4338 | * just like above - but do not care for overflow of signed results |
| | | 4339 | */ |
| | | 4340 | unsigned int float128_to_uint32_round_to_zero( float128 a ) |
| | | 4341 | { |
| | | 4342 | flag aSign; |
| | | 4343 | int32 aExp, shiftCount; |
| | | 4344 | bits64 aSig0, aSig1, savedASig; |
| | | 4345 | uint32 z; |
| | | 4346 | |
| | | 4347 | aSig1 = extractFloat128Frac1( a ); |
| | | 4348 | aSig0 = extractFloat128Frac0( a ); |
| | | 4349 | aExp = extractFloat128Exp( a ); |
| | | 4350 | aSign = extractFloat128Sign( a ); |
| | | 4351 | aSig0 |= ( aSig1 != 0 ); |
| | | 4352 | if ( 0x401E < aExp ) { |
| | | 4353 | if ( ( aExp == 0x7FFF ) && aSig0 ) aSign = 0; |
| | | 4354 | goto invalid; |
| | | 4355 | } |
| | | 4356 | else if ( aExp < 0x3FFF ) { |
| | | 4357 | if ( aExp || aSig0 ) float_exception_flags |= float_flag_inexact; |
| | | 4358 | return 0; |
| | | 4359 | } |
| | | 4360 | aSig0 |= LIT64( 0x0001000000000000 ); |
| | | 4361 | shiftCount = 0x402F - aExp; |
| | | 4362 | savedASig = aSig0; |
| | | 4363 | aSig0 >>= shiftCount; |
| | | 4364 | z = aSig0; |
| | | 4365 | if ( aSign ) { |
| | | 4366 | invalid: |
| | | 4367 | float_raise( float_flag_invalid ); |
| | | 4368 | return 0xFFFFFFFF; |
| | | 4369 | } |
| | | 4370 | if ( ( aSig0<<shiftCount ) != savedASig ) { |
| | | 4371 | float_exception_flags |= float_flag_inexact; |
| | | 4372 | } |
| | | 4373 | return z; |
| | | 4374 | |
| | | 4375 | } |
| | | 4376 | |
| | | 4377 | /* |
4338 | ------------------------------------------------------------------------------- | | 4378 | ------------------------------------------------------------------------------- |
4339 | Returns the result of converting the quadruple-precision floating-point | | 4379 | Returns the result of converting the quadruple-precision floating-point |
4340 | value `a' to the 64-bit two's complement integer format. The conversion | | 4380 | value `a' to the 64-bit two's complement integer format. The conversion |
4341 | is performed according to the IEC/IEEE Standard for Binary Floating-Point | | 4381 | is performed according to the IEC/IEEE Standard for Binary Floating-Point |
4342 | Arithmetic---which means in particular that the conversion is rounded | | 4382 | Arithmetic---which means in particular that the conversion is rounded |
4343 | according to the current rounding mode. If `a' is a NaN, the largest | | 4383 | according to the current rounding mode. If `a' is a NaN, the largest |
4344 | positive integer is returned. Otherwise, if the conversion overflows, the | | 4384 | positive integer is returned. Otherwise, if the conversion overflows, the |
4345 | largest integer with the same sign as `a' is returned. | | 4385 | largest integer with the same sign as `a' is returned. |
4346 | ------------------------------------------------------------------------------- | | 4386 | ------------------------------------------------------------------------------- |
4347 | */ | | 4387 | */ |
4348 | int64 float128_to_int64( float128 a ) | | 4388 | int64 float128_to_int64( float128 a ) |
4349 | { | | 4389 | { |
4350 | flag aSign; | | 4390 | flag aSign; |