Fri May 20 16:30:05 2011 UTC ()
Add float128_to_uint32_round_to_zero


(matt)
diff -r1.5 -r1.5.20.1 src/lib/libc/softfloat/bits64/softfloat.c

cvs diff -r1.5 -r1.5.20.1 src/lib/libc/softfloat/bits64/softfloat.c (expand / switch to unified diff)

--- src/lib/libc/softfloat/bits64/softfloat.c 2007/11/08 21:31:04 1.5
+++ src/lib/libc/softfloat/bits64/softfloat.c 2011/05/20 16:30:05 1.5.20.1
@@ -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
36PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 36PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
37AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 37AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
38 38
39Derivative works are acceptable, even for commercial purposes, so long as 39Derivative 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
41include prominent notice akin to these four paragraphs for those parts of 41include prominent notice akin to these four paragraphs for those parts of
42this code that are retained. 42this 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 */
 4340unsigned 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-------------------------------------------------------------------------------
4339Returns the result of converting the quadruple-precision floating-point 4379Returns the result of converting the quadruple-precision floating-point
4340value `a' to the 64-bit two's complement integer format. The conversion 4380value `a' to the 64-bit two's complement integer format. The conversion
4341is performed according to the IEC/IEEE Standard for Binary Floating-Point 4381is performed according to the IEC/IEEE Standard for Binary Floating-Point
4342Arithmetic---which means in particular that the conversion is rounded 4382Arithmetic---which means in particular that the conversion is rounded
4343according to the current rounding mode. If `a' is a NaN, the largest 4383according to the current rounding mode. If `a' is a NaN, the largest
4344positive integer is returned. Otherwise, if the conversion overflows, the 4384positive integer is returned. Otherwise, if the conversion overflows, the
4345largest integer with the same sign as `a' is returned. 4385largest integer with the same sign as `a' is returned.
4346------------------------------------------------------------------------------- 4386-------------------------------------------------------------------------------
4347*/ 4387*/
4348int64 float128_to_int64( float128 a ) 4388int64 float128_to_int64( float128 a )
4349{ 4389{
4350 flag aSign; 4390 flag aSign;