diff mbox

[135/147] softfloat: Fix uint64_to_float64

Message ID 1348794721-28534-1-git-send-email-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson Sept. 28, 2012, 1:12 a.m. UTC
The interface to normalizeRoundAndPackFloat64 requires that the
high bit be clear.  Perform one shift-right-and-jam if needed.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 fpu/softfloat.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Peter Maydell Sept. 28, 2012, 2:14 p.m. UTC | #1
On 28 September 2012 02:12, Richard Henderson <rth@twiddle.net> wrote:
> The interface to normalizeRoundAndPackFloat64 requires that the
> high bit be clear.  Perform one shift-right-and-jam if needed.
>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  fpu/softfloat.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index b29256a..45f105a 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -1273,9 +1273,14 @@ float64 int64_to_float64( int64 a STATUS_PARAM )
>
>  float64 uint64_to_float64( uint64 a STATUS_PARAM )
>  {
> -    if ( a == 0 ) return float64_zero;
> -    return normalizeRoundAndPackFloat64( 0, 0x43C, a STATUS_VAR );
> +    int exp =  0x43C;
>
> +    if ( a == 0 ) return float64_zero;
> +    if ( (int64_t)a < 0 ) {
> +        a = (a >> 1) | (a & 1);
> +        exp += 1;
> +    }

You could just use
  shift64RightJamming(a, 1, &a);
rather than calculating a like that; gcc is smart enough to emit
the same code as your longhand version.

> +    return normalizeRoundAndPackFloat64( 0, exp, a STATUS_VAR );

I worked through it and I believe this patch does the right thing
with raising or not raising the inexact flag...

-- PMM
diff mbox

Patch

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index b29256a..45f105a 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -1273,9 +1273,14 @@  float64 int64_to_float64( int64 a STATUS_PARAM )
 
 float64 uint64_to_float64( uint64 a STATUS_PARAM )
 {
-    if ( a == 0 ) return float64_zero;
-    return normalizeRoundAndPackFloat64( 0, 0x43C, a STATUS_VAR );
+    int exp =  0x43C;
 
+    if ( a == 0 ) return float64_zero;
+    if ( (int64_t)a < 0 ) {
+        a = (a >> 1) | (a & 1);
+        exp += 1;
+    }
+    return normalizeRoundAndPackFloat64( 0, exp, a STATUS_VAR );
 }
 
 /*----------------------------------------------------------------------------