Patchwork [11/20] target-i386: fix helper_flbd_ST0() wrt softfloat

login
register
mail settings
Submitter Aurelien Jarno
Date April 18, 2011, 9 p.m.
Message ID <1303160412-8107-12-git-send-email-aurelien@aurel32.net>
Download mbox | patch
Permalink /patch/91844/
State New
Headers show

Comments

Aurelien Jarno - April 18, 2011, 9 p.m.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 target-i386/op_helper.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
Peter Maydell - April 19, 2011, 5:06 p.m.
On 18 April 2011 22:00, Aurelien Jarno <aurelien@aurel32.net> wrote:
> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
> ---
>  target-i386/op_helper.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
> index f614893..7dddd37 100644
> --- a/target-i386/op_helper.c
> +++ b/target-i386/op_helper.c
> @@ -3920,9 +3920,10 @@ void helper_fbld_ST0(target_ulong ptr)
>         v = ldub(ptr + i);
>         val = (val * 100) + ((v >> 4) * 10) + (v & 0xf);
>     }
> -    tmp = val;
> -    if (ldub(ptr + 9) & 0x80)
> -        tmp = -tmp;
> +    if (ldub(ptr + 9) & 0x80) {
> +        val = -val;
> +    }
> +    tmp = int64_to_floatx(val, &env->fp_status);
>     fpush();
>     ST0 = tmp;
>  }

This doesn't do the right thing for -0 (should generate -0,
not +0). I think:

 tmp = int64_to_floatx(val, &env->fp_status);
 if (ldub(ptr + 9) & 0x80) {
     floatx_chs(tmp);
 }

ought to do the right thing and work for both softfloat and
sf-native, but I haven't tested it.

-- PMM
Aurelien Jarno - April 20, 2011, 9:37 a.m.
On Tue, Apr 19, 2011 at 06:06:57PM +0100, Peter Maydell wrote:
> On 18 April 2011 22:00, Aurelien Jarno <aurelien@aurel32.net> wrote:
> > Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
> > ---
> >  target-i386/op_helper.c |    7 ++++---
> >  1 files changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
> > index f614893..7dddd37 100644
> > --- a/target-i386/op_helper.c
> > +++ b/target-i386/op_helper.c
> > @@ -3920,9 +3920,10 @@ void helper_fbld_ST0(target_ulong ptr)
> >         v = ldub(ptr + i);
> >         val = (val * 100) + ((v >> 4) * 10) + (v & 0xf);
> >     }
> > -    tmp = val;
> > -    if (ldub(ptr + 9) & 0x80)
> > -        tmp = -tmp;
> > +    if (ldub(ptr + 9) & 0x80) {
> > +        val = -val;
> > +    }
> > +    tmp = int64_to_floatx(val, &env->fp_status);
> >     fpush();
> >     ST0 = tmp;
> >  }
> 
> This doesn't do the right thing for -0 (should generate -0,
> not +0). I think:
> 
>  tmp = int64_to_floatx(val, &env->fp_status);
>  if (ldub(ptr + 9) & 0x80) {
>      floatx_chs(tmp);
>  }
> 
> ought to do the right thing and work for both softfloat and
> sf-native, but I haven't tested it.
> 

Good catch, this solution works. Thanks.

Patch

diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index f614893..7dddd37 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -3920,9 +3920,10 @@  void helper_fbld_ST0(target_ulong ptr)
         v = ldub(ptr + i);
         val = (val * 100) + ((v >> 4) * 10) + (v & 0xf);
     }
-    tmp = val;
-    if (ldub(ptr + 9) & 0x80)
-        tmp = -tmp;
+    if (ldub(ptr + 9) & 0x80) {
+        val = -val;
+    }
+    tmp = int64_to_floatx(val, &env->fp_status);
     fpush();
     ST0 = tmp;
 }