All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/1] Fix conversion from uint64 to float128
@ 2018-05-11  7:10 Petr Tesarik
  2018-05-11  7:38 ` Petr Tesarik
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Petr Tesarik @ 2018-05-11  7:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Petr Tesarik, qemu-stable, Aurelien Jarno, Peter Maydell

The significand is passed to normalizeRoundAndPackFloat128() as high
first, low second. The current code passes the integer first, so the
result is incorrectly shifted left by 64 bits.

This bug affects the emulation of s390x instruction CXLGBR (convert
from logical 64-bit binary-integer operand to extended BFP result).

Cc: qemu-stable@nongnu.org
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 fpu/softfloat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 70e0c40a1c..386805475b 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -3139,7 +3139,7 @@ float128 uint64_to_float128(uint64_t a, float_status *status)
     if (a == 0) {
         return float128_zero;
     }
-    return normalizeRoundAndPackFloat128(0, 0x406E, a, 0, status);
+    return normalizeRoundAndPackFloat128(0, 0x406E, 0, a, status);
 }
 
 
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 1/1] Fix conversion from uint64 to float128
  2018-05-11  7:10 [Qemu-devel] [PATCH 1/1] Fix conversion from uint64 to float128 Petr Tesarik
@ 2018-05-11  7:38 ` Petr Tesarik
  2018-05-11 12:37 ` Peter Maydell
  2018-05-12  0:52 ` Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Petr Tesarik @ 2018-05-11  7:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Aurelien Jarno, Peter Maydell

On Fri, 11 May 2018 09:10:52 +0200
Petr Tesarik <ptesarik@suse.com> wrote:

> The significand is passed to normalizeRoundAndPackFloat128() as high
> first, low second. The current code passes the integer first, so the
> result is incorrectly shifted left by 64 bits.
> 
> This bug affects the emulation of s390x instruction CXLGBR (convert
> from logical 64-bit binary-integer operand to extended BFP result).

I forgot to add a simple reproducer:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
        unsigned long long x = atoll(argv[1]);
        long double d = x;

        printf("%llu -> %Lf\n", x, d);

        return 0;
}

On a real s390x, I get this:
linux-nig1:~ # ./cast 1
1 -> 1.000000

An s390x emulated with (unpatched) qemu-system-s390x gives:
linux-2s2c:~ # ./cast 1
1 -> 18446744073709551616.000000

That is 2^64.

Petr T

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 1/1] Fix conversion from uint64 to float128
  2018-05-11  7:10 [Qemu-devel] [PATCH 1/1] Fix conversion from uint64 to float128 Petr Tesarik
  2018-05-11  7:38 ` Petr Tesarik
@ 2018-05-11 12:37 ` Peter Maydell
  2018-05-12  0:52 ` Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2018-05-11 12:37 UTC (permalink / raw)
  To: Petr Tesarik; +Cc: QEMU Developers, qemu-stable, Aurelien Jarno

On 11 May 2018 at 08:10, Petr Tesarik <ptesarik@suse.com> wrote:
> The significand is passed to normalizeRoundAndPackFloat128() as high
> first, low second. The current code passes the integer first, so the
> result is incorrectly shifted left by 64 bits.
>
> This bug affects the emulation of s390x instruction CXLGBR (convert
> from logical 64-bit binary-integer operand to extended BFP result).
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Petr Tesarik <ptesarik@suse.com>
> ---
>  fpu/softfloat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index 70e0c40a1c..386805475b 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -3139,7 +3139,7 @@ float128 uint64_to_float128(uint64_t a, float_status *status)
>      if (a == 0) {
>          return float128_zero;
>      }
> -    return normalizeRoundAndPackFloat128(0, 0x406E, a, 0, status);
> +    return normalizeRoundAndPackFloat128(0, 0x406E, 0, a, status);
>  }

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 1/1] Fix conversion from uint64 to float128
  2018-05-11  7:10 [Qemu-devel] [PATCH 1/1] Fix conversion from uint64 to float128 Petr Tesarik
  2018-05-11  7:38 ` Petr Tesarik
  2018-05-11 12:37 ` Peter Maydell
@ 2018-05-12  0:52 ` Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2018-05-12  0:52 UTC (permalink / raw)
  To: Petr Tesarik, qemu-devel; +Cc: Peter Maydell, qemu-stable, Aurelien Jarno

On 05/11/2018 12:10 AM, Petr Tesarik wrote:
> The significand is passed to normalizeRoundAndPackFloat128() as high
> first, low second. The current code passes the integer first, so the
> result is incorrectly shifted left by 64 bits.
> 
> This bug affects the emulation of s390x instruction CXLGBR (convert
> from logical 64-bit binary-integer operand to extended BFP result).
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Petr Tesarik <ptesarik@suse.com>
> ---
>  fpu/softfloat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Queued, thanks.


r~

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-12  0:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-11  7:10 [Qemu-devel] [PATCH 1/1] Fix conversion from uint64 to float128 Petr Tesarik
2018-05-11  7:38 ` Petr Tesarik
2018-05-11 12:37 ` Peter Maydell
2018-05-12  0:52 ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.