qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [Bug 1233225] [NEW] mips/mipsel linux user float division problem
@ 2013-09-30 15:09 Johannes Schauer
  2013-10-01 17:51 ` [Qemu-devel] [Bug 1233225] " Stefan Weil
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Johannes Schauer @ 2013-09-30 15:09 UTC (permalink / raw)
  To: qemu-devel

Public bug reported:

Hi,

I tested the following with the qemu git HEAD as of 2013-09-30 on Debian
stable and testing. My host runs amd64 but I also tried this out inside
a i386 chroot with the same result. The problem occurs for mips and
mipsel. Given the following program:

#include <stdio.h>
int main(int argc, char **argv)
{
    int a = 1;
    double d = a/2.0;
    printf("%f\n", d);
    return 0;
}

Instead of printing 0.5, it will print 2.0 if executed in qemu user
mode.

$ mipsel-linux-gnu-gcc mipstest.c
$ ~/qemu/mipsel-linux-user/qemu-mipsel ./a.out
2.0

Expecting this to be a problem with my cross compiler (gcc-4.4 from
emdebian) I ran a fully emulated debian squeeze environment inside qemu.
There, I compiled the same program natively with gcc and as expected got
0.5 as the output. I also copied the cross compiled binary inside the
emulated environment and also got 0.5 when I ran it. So the same
mips/mipsel binary produces different output depending on whether it is
run in a fully emulated environment or qemu user mode.

Can anybody else reproduce this problem?

** Affects: qemu
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1233225

Title:
  mips/mipsel linux user float division problem

Status in QEMU:
  New

Bug description:
  Hi,

  I tested the following with the qemu git HEAD as of 2013-09-30 on
  Debian stable and testing. My host runs amd64 but I also tried this
  out inside a i386 chroot with the same result. The problem occurs for
  mips and mipsel. Given the following program:

  #include <stdio.h>
  int main(int argc, char **argv)
  {
      int a = 1;
      double d = a/2.0;
      printf("%f\n", d);
      return 0;
  }

  Instead of printing 0.5, it will print 2.0 if executed in qemu user
  mode.

  $ mipsel-linux-gnu-gcc mipstest.c
  $ ~/qemu/mipsel-linux-user/qemu-mipsel ./a.out
  2.0

  Expecting this to be a problem with my cross compiler (gcc-4.4 from
  emdebian) I ran a fully emulated debian squeeze environment inside
  qemu. There, I compiled the same program natively with gcc and as
  expected got 0.5 as the output. I also copied the cross compiled
  binary inside the emulated environment and also got 0.5 when I ran it.
  So the same mips/mipsel binary produces different output depending on
  whether it is run in a fully emulated environment or qemu user mode.

  Can anybody else reproduce this problem?

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1233225/+subscriptions

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

* [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-09-30 15:09 [Qemu-devel] [Bug 1233225] [NEW] mips/mipsel linux user float division problem Johannes Schauer
@ 2013-10-01 17:51 ` Stefan Weil
  2013-10-02  1:39   ` Peter Maydell
  2013-10-01 18:14 ` Stefan Weil
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Stefan Weil @ 2013-10-01 17:51 UTC (permalink / raw)
  To: qemu-devel

I can confirm that something is strange with MIPS Linux user emulation,
but get a different result (which is also wrong):

# Your test code is in file divtest.c.
$ mipsel-linux-gnu-gcc-4.7 -g -static divtest.c
$ mipsel-linux-user/qemu-mipsel a.out
0.000000

Some more tests:
    printf("%f\n", a * 1.0);        // 0.000000 = bad
    printf("%f\n", (double)a);  // 0.000000 = bad
    printf("%f\n", 1.0);              // 1.000000 = good


Test environment:
* latest QEMU sources + default configure & make on x86_64 Debian squeeze host
* gcc-4.7-mipsel-linux-gnu 4.7.2-5 amd64 GNU C compiler


** Changed in: qemu
       Status: New => Confirmed

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1233225

Title:
  mips/mipsel linux user float division problem

Status in QEMU:
  Confirmed

Bug description:
  Hi,

  I tested the following with the qemu git HEAD as of 2013-09-30 on
  Debian stable and testing. My host runs amd64 but I also tried this
  out inside a i386 chroot with the same result. The problem occurs for
  mips and mipsel. Given the following program:

  #include <stdio.h>
  int main(int argc, char **argv)
  {
      int a = 1;
      double d = a/2.0;
      printf("%f\n", d);
      return 0;
  }

  Instead of printing 0.5, it will print 2.0 if executed in qemu user
  mode.

  $ mipsel-linux-gnu-gcc mipstest.c
  $ ~/qemu/mipsel-linux-user/qemu-mipsel ./a.out
  2.0

  Expecting this to be a problem with my cross compiler (gcc-4.4 from
  emdebian) I ran a fully emulated debian squeeze environment inside
  qemu. There, I compiled the same program natively with gcc and as
  expected got 0.5 as the output. I also copied the cross compiled
  binary inside the emulated environment and also got 0.5 when I ran it.
  So the same mips/mipsel binary produces different output depending on
  whether it is run in a fully emulated environment or qemu user mode.

  Can anybody else reproduce this problem?

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1233225/+subscriptions

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

* [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-09-30 15:09 [Qemu-devel] [Bug 1233225] [NEW] mips/mipsel linux user float division problem Johannes Schauer
  2013-10-01 17:51 ` [Qemu-devel] [Bug 1233225] " Stefan Weil
@ 2013-10-01 18:14 ` Stefan Weil
  2013-10-01 20:43   ` Stefan Weil
  2013-10-02 16:48 ` Johannes Schauer
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Stefan Weil @ 2013-10-01 18:14 UTC (permalink / raw)
  To: qemu-devel

Here is the related commit found by git bisect:

$ git bisect bad
68473f15d4c9948986618f63828825beafcaf1cf is the first bad commit
commit 68473f15d4c9948986618f63828825beafcaf1cf
Author: Richard Henderson <rth@twiddle.net>
Date:   Sun Feb 10 10:30:46 2013 -0800

    mips64-linux-user: Enable 64-bit address mode and fpu
    
    Signed-off-by: Richard Henderson <rth@twiddle.net>
    Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

:040000 040000 de3caa25e43aaeb7d992715b2efc6804a7d0d633
b007b2a9809547197952ca4d36fbd29f89aab470 M      target-mips

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1233225

Title:
  mips/mipsel linux user float division problem

Status in QEMU:
  Confirmed

Bug description:
  Hi,

  I tested the following with the qemu git HEAD as of 2013-09-30 on
  Debian stable and testing. My host runs amd64 but I also tried this
  out inside a i386 chroot with the same result. The problem occurs for
  mips and mipsel. Given the following program:

  #include <stdio.h>
  int main(int argc, char **argv)
  {
      int a = 1;
      double d = a/2.0;
      printf("%f\n", d);
      return 0;
  }

  Instead of printing 0.5, it will print 2.0 if executed in qemu user
  mode.

  $ mipsel-linux-gnu-gcc mipstest.c
  $ ~/qemu/mipsel-linux-user/qemu-mipsel ./a.out
  2.0

  Expecting this to be a problem with my cross compiler (gcc-4.4 from
  emdebian) I ran a fully emulated debian squeeze environment inside
  qemu. There, I compiled the same program natively with gcc and as
  expected got 0.5 as the output. I also copied the cross compiled
  binary inside the emulated environment and also got 0.5 when I ran it.
  So the same mips/mipsel binary produces different output depending on
  whether it is run in a fully emulated environment or qemu user mode.

  Can anybody else reproduce this problem?

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1233225/+subscriptions

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

* Re: [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-10-01 18:14 ` Stefan Weil
@ 2013-10-01 20:43   ` Stefan Weil
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Weil @ 2013-10-01 20:43 UTC (permalink / raw)
  To: Aurelien Jarno, Richard Henderson; +Cc: Bug 1233225, qemu-devel

Am 01.10.2013 20:14, schrieb Stefan Weil:
> Here is the related commit found by git bisect:
>
> $ git bisect bad
> 68473f15d4c9948986618f63828825beafcaf1cf is the first bad commit
> commit 68473f15d4c9948986618f63828825beafcaf1cf
> Author: Richard Henderson <rth@twiddle.net>
> Date:   Sun Feb 10 10:30:46 2013 -0800
>
>     mips64-linux-user: Enable 64-bit address mode and fpu
>     
>     Signed-off-by: Richard Henderson <rth@twiddle.net>
>     Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
>
> :040000 040000 de3caa25e43aaeb7d992715b2efc6804a7d0d633
> b007b2a9809547197952ca4d36fbd29f89aab470 M      target-mips
>


Hi Aurelien, hi Richard,

the following patch is a workaround which fixes the reported problem
(see https://bugs.launchpad.net/qemu/+bug/1233225):

diff --git a/target-mips/translate.c b/target-mips/translate.c
index ad43d59..475b0f6 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -15990,7 +15990,7 @@ void cpu_state_reset(CPUMIPSState *env)
     }
     /* Enable 64-bit FPU if the target cpu supports it.  */
     if (env->active_fpu.fcr0 & (1 << FCR0_F64)) {
-        env->CP0_Status |= (1 << CP0St_FR);
+        // env->CP0_Status |= (1 << CP0St_FR);
     }
 #else
     if (env->hflags & MIPS_HFLAG_BMASK) {

Of course it's not the correct solution. I won't be able to look more
into this issue the next days, but maybe you already have a bug fix.

Regards,
Stefan

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

* Re: [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-10-01 17:51 ` [Qemu-devel] [Bug 1233225] " Stefan Weil
@ 2013-10-02  1:39   ` Peter Maydell
  2013-10-02  5:22     ` Stefan Weil
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2013-10-02  1:39 UTC (permalink / raw)
  To: Bug 1233225; +Cc: QEMU Developers

On 2 October 2013 02:51, Stefan Weil <1233225@bugs.launchpad.net> wrote:
> I can confirm that something is strange with MIPS Linux user emulation,
> but get a different result (which is also wrong):
>
> # Your test code is in file divtest.c.
> $ mipsel-linux-gnu-gcc-4.7 -g -static divtest.c
> $ mipsel-linux-user/qemu-mipsel a.out
> 0.000000

Does the CPU you're asking qemu to emulate match the CPU gcc is
generating code for? IIRC for MIPS there's no single "right" answer
for "which CPU do we default to"...

-- PMM

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

* Re: [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-10-02  1:39   ` Peter Maydell
@ 2013-10-02  5:22     ` Stefan Weil
  2013-10-02 12:58       ` Peter Maydell
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Weil @ 2013-10-02  5:22 UTC (permalink / raw)
  To: Peter Maydell, Bug 1233225
  Cc: QEMU Developers, Aurélien Jarno, Richard Henderson

Am 02.10.2013 03:39, schrieb Peter Maydell:
> On 2 October 2013 02:51, Stefan Weil <1233225@bugs.launchpad.net> wrote:
>> I can confirm that something is strange with MIPS Linux user emulation,
>> but get a different result (which is also wrong):
>>
>> # Your test code is in file divtest.c.
>> $ mipsel-linux-gnu-gcc-4.7 -g -static divtest.c
>> $ mipsel-linux-user/qemu-mipsel a.out
>> 0.000000
> Does the CPU you're asking qemu to emulate match the CPU gcc is
> generating code for? IIRC for MIPS there's no single "right" answer
> for "which CPU do we default to"...
>
> -- PMM
>

QEMU user mode emulation for MIPS knows two different default cpus:

#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
        cpu_model = "20Kc";
#else
        cpu_model = "24Kf";
#endif

In this case, it took 24Kf which seems to be ok.

I tested other cpus with -cpu xxx. They either show the same result
or fail with illegal instruction.

This is my executable:

divtest-mips: ELF 32-bit MSB executable, MIPS, MIPS-II version 1,
statically linked, for GNU/Linux 2.6.26

The original bug report said that it runs in QEMU system emulation
(which I did not test because of lack of time). As system emulation
uses the same cpu, it should be fine.

See also my previous mail: bit CP0St_FR makes a difference:
http://lists.nongnu.org/archive/html/qemu-devel/2013-10/msg00168.html

Stefan

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

* Re: [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-10-02  5:22     ` Stefan Weil
@ 2013-10-02 12:58       ` Peter Maydell
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Maydell @ 2013-10-02 12:58 UTC (permalink / raw)
  To: Stefan Weil
  Cc: Bug 1233225, QEMU Developers, Aurélien Jarno,
	Richard Henderson

On 2 October 2013 14:22, Stefan Weil <sw@weilnetz.de> wrote:
> The original bug report said that it runs in QEMU system emulation
> (which I did not test because of lack of time). As system emulation
> uses the same cpu, it should be fine.

...that's what prompted me to ask, actually -- system emulation will
pick a CPU based on whichever board you're emulating, which is
quite likely to be a different one from the default picked by linux-user.
The original bug report doesn't seem to say which board they used
for system emulation so I don't know which CPU it would be using.

-- PMM

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

* [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-09-30 15:09 [Qemu-devel] [Bug 1233225] [NEW] mips/mipsel linux user float division problem Johannes Schauer
  2013-10-01 17:51 ` [Qemu-devel] [Bug 1233225] " Stefan Weil
  2013-10-01 18:14 ` Stefan Weil
@ 2013-10-02 16:48 ` Johannes Schauer
  2013-10-08  0:21 ` Petar Jovanovic
  2016-12-06 11:43 ` Thomas Huth
  4 siblings, 0 replies; 10+ messages in thread
From: Johannes Schauer @ 2013-10-02 16:48 UTC (permalink / raw)
  To: qemu-devel

For system emulation I used the default which is malta.

cheers, josch

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1233225

Title:
  mips/mipsel linux user float division problem

Status in QEMU:
  Confirmed

Bug description:
  Hi,

  I tested the following with the qemu git HEAD as of 2013-09-30 on
  Debian stable and testing. My host runs amd64 but I also tried this
  out inside a i386 chroot with the same result. The problem occurs for
  mips and mipsel. Given the following program:

  #include <stdio.h>
  int main(int argc, char **argv)
  {
      int a = 1;
      double d = a/2.0;
      printf("%f\n", d);
      return 0;
  }

  Instead of printing 0.5, it will print 2.0 if executed in qemu user
  mode.

  $ mipsel-linux-gnu-gcc mipstest.c
  $ ~/qemu/mipsel-linux-user/qemu-mipsel ./a.out
  2.0

  Expecting this to be a problem with my cross compiler (gcc-4.4 from
  emdebian) I ran a fully emulated debian squeeze environment inside
  qemu. There, I compiled the same program natively with gcc and as
  expected got 0.5 as the output. I also copied the cross compiled
  binary inside the emulated environment and also got 0.5 when I ran it.
  So the same mips/mipsel binary produces different output depending on
  whether it is run in a fully emulated environment or qemu user mode.

  Can anybody else reproduce this problem?

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1233225/+subscriptions

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

* [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-09-30 15:09 [Qemu-devel] [Bug 1233225] [NEW] mips/mipsel linux user float division problem Johannes Schauer
                   ` (2 preceding siblings ...)
  2013-10-02 16:48 ` Johannes Schauer
@ 2013-10-08  0:21 ` Petar Jovanovic
  2016-12-06 11:43 ` Thomas Huth
  4 siblings, 0 replies; 10+ messages in thread
From: Petar Jovanovic @ 2013-10-08  0:21 UTC (permalink / raw)
  To: qemu-devel

This is a known issue.
There was a fix proposal by Thomas Schwinge back in June

http://patchwork.ozlabs.org/patch/250161/

but he has not updated the patch per suggestion ever since, though the patch
as is was much closer to correct behaviour than what it is now in the source.

If anyone is in hurry, he/she can pick up that change.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1233225

Title:
  mips/mipsel linux user float division problem

Status in QEMU:
  Confirmed

Bug description:
  Hi,

  I tested the following with the qemu git HEAD as of 2013-09-30 on
  Debian stable and testing. My host runs amd64 but I also tried this
  out inside a i386 chroot with the same result. The problem occurs for
  mips and mipsel. Given the following program:

  #include <stdio.h>
  int main(int argc, char **argv)
  {
      int a = 1;
      double d = a/2.0;
      printf("%f\n", d);
      return 0;
  }

  Instead of printing 0.5, it will print 2.0 if executed in qemu user
  mode.

  $ mipsel-linux-gnu-gcc mipstest.c
  $ ~/qemu/mipsel-linux-user/qemu-mipsel ./a.out
  2.0

  Expecting this to be a problem with my cross compiler (gcc-4.4 from
  emdebian) I ran a fully emulated debian squeeze environment inside
  qemu. There, I compiled the same program natively with gcc and as
  expected got 0.5 as the output. I also copied the cross compiled
  binary inside the emulated environment and also got 0.5 when I ran it.
  So the same mips/mipsel binary produces different output depending on
  whether it is run in a fully emulated environment or qemu user mode.

  Can anybody else reproduce this problem?

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1233225/+subscriptions

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

* [Qemu-devel] [Bug 1233225] Re: mips/mipsel linux user float division problem
  2013-09-30 15:09 [Qemu-devel] [Bug 1233225] [NEW] mips/mipsel linux user float division problem Johannes Schauer
                   ` (3 preceding siblings ...)
  2013-10-08  0:21 ` Petar Jovanovic
@ 2016-12-06 11:43 ` Thomas Huth
  4 siblings, 0 replies; 10+ messages in thread
From: Thomas Huth @ 2016-12-06 11:43 UTC (permalink / raw)
  To: qemu-devel

Looks like Petar's patch from comment #6 has been included here:
http://git.qemu.org/?p=qemu.git;a=commitdiff;h=4d66261f71f2efa31e1052e
==> Fix released

** Changed in: qemu
       Status: Confirmed => Fix Released

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1233225

Title:
  mips/mipsel linux user float division problem

Status in QEMU:
  Fix Released

Bug description:
  Hi,

  I tested the following with the qemu git HEAD as of 2013-09-30 on
  Debian stable and testing. My host runs amd64 but I also tried this
  out inside a i386 chroot with the same result. The problem occurs for
  mips and mipsel. Given the following program:

  #include <stdio.h>
  int main(int argc, char **argv)
  {
      int a = 1;
      double d = a/2.0;
      printf("%f\n", d);
      return 0;
  }

  Instead of printing 0.5, it will print 2.0 if executed in qemu user
  mode.

  $ mipsel-linux-gnu-gcc mipstest.c
  $ ~/qemu/mipsel-linux-user/qemu-mipsel ./a.out
  2.0

  Expecting this to be a problem with my cross compiler (gcc-4.4 from
  emdebian) I ran a fully emulated debian squeeze environment inside
  qemu. There, I compiled the same program natively with gcc and as
  expected got 0.5 as the output. I also copied the cross compiled
  binary inside the emulated environment and also got 0.5 when I ran it.
  So the same mips/mipsel binary produces different output depending on
  whether it is run in a fully emulated environment or qemu user mode.

  Can anybody else reproduce this problem?

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1233225/+subscriptions

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

end of thread, other threads:[~2016-12-06 12:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-30 15:09 [Qemu-devel] [Bug 1233225] [NEW] mips/mipsel linux user float division problem Johannes Schauer
2013-10-01 17:51 ` [Qemu-devel] [Bug 1233225] " Stefan Weil
2013-10-02  1:39   ` Peter Maydell
2013-10-02  5:22     ` Stefan Weil
2013-10-02 12:58       ` Peter Maydell
2013-10-01 18:14 ` Stefan Weil
2013-10-01 20:43   ` Stefan Weil
2013-10-02 16:48 ` Johannes Schauer
2013-10-08  0:21 ` Petar Jovanovic
2016-12-06 11:43 ` Thomas Huth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).