qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Host FPE for overflowing division on MIPS
@ 2007-12-19 18:12 Richard Sandiford
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2007-12-19 18:12 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

Running the libjava testsuite for -mabi=64 on a x86_64-linux-gnu-x-mips64
QEMU causes the emulator to exit with an FPE.  The problem is that we use
lldiv for ddiv, and lldiv is undefined for both divisions by zero and for
divisions whose result is not representable.  We special-case divisions
in the first case, but we don't special-case -0x8000000000000000 / -1.

(div is OK because we use 64-bit division and truncate the result.)

I've tested this with Divide_1 on x86_64-linux-gnu- and i686-pc-linux-gnu-
hosted QEMUs.  Please install if OK.

Richard


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ddiv-fpe.patch --]
[-- Type: text/x-diff, Size: 967 bytes --]

Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v
retrieving revision 1.74
diff -u -r1.74 op_helper.c
--- target-mips/op_helper.c	18 Nov 2007 14:33:24 -0000	1.74
+++ target-mips/op_helper.c	19 Dec 2007 17:31:23 -0000
@@ -230,9 +237,16 @@
 void do_ddiv (void)
 {
     if (T1 != 0) {
-        lldiv_t res = lldiv((int64_t)T0, (int64_t)T1);
-        env->LO[0][env->current_tc] = res.quot;
-        env->HI[0][env->current_tc] = res.rem;
+        int64_t arg0 = (int64_t)T0;
+        int64_t arg1 = (int64_t)T1;
+        if (arg0 == ((int64_t)-1 << 63) && arg1 == (int64_t)-1) {
+            env->LO[0][env->current_tc] = arg0;
+            env->HI[0][env->current_tc] = 0;
+        } else {
+            lldiv_t res = lldiv(arg0, arg1);
+            env->LO[0][env->current_tc] = res.quot;
+            env->HI[0][env->current_tc] = res.rem;
+        }
     }
 }
 

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

* [Qemu-devel] Host FPE for overflowing division on MIPS
@ 2007-12-20  9:58 Richard Sandiford
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2007-12-20  9:58 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 631 bytes --]

[Sorry if this is a dup.  Wasn't sure if the list was subscribers-only.]

Running the libjava testsuite for -mabi=64 on a x86_64-linux-gnu-x-mips64
QEMU causes the emulator to exit with an FPE.  The problem is that we use
lldiv for ddiv, and lldiv is undefined for both divisions by zero and for
divisions whose result is not representable.  We special-case divisions
in the first case, but we don't special-case -0x8000000000000000 / -1.

(div is OK because we use 64-bit division and truncate the result.)

I've tested this with Divide_1 on x86_64-linux-gnu- and i686-pc-linux-gnu-
hosted QEMUs.  Please install if OK.

Richard


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ddiv-fpe.patch --]
[-- Type: text/x-diff, Size: 967 bytes --]

Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v
retrieving revision 1.74
diff -u -r1.74 op_helper.c
--- target-mips/op_helper.c	18 Nov 2007 14:33:24 -0000	1.74
+++ target-mips/op_helper.c	19 Dec 2007 17:31:23 -0000
@@ -230,9 +237,16 @@
 void do_ddiv (void)
 {
     if (T1 != 0) {
-        lldiv_t res = lldiv((int64_t)T0, (int64_t)T1);
-        env->LO[0][env->current_tc] = res.quot;
-        env->HI[0][env->current_tc] = res.rem;
+        int64_t arg0 = (int64_t)T0;
+        int64_t arg1 = (int64_t)T1;
+        if (arg0 == ((int64_t)-1 << 63) && arg1 == (int64_t)-1) {
+            env->LO[0][env->current_tc] = arg0;
+            env->HI[0][env->current_tc] = 0;
+        } else {
+            lldiv_t res = lldiv(arg0, arg1);
+            env->LO[0][env->current_tc] = res.quot;
+            env->HI[0][env->current_tc] = res.rem;
+        }
     }
 }
 

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

end of thread, other threads:[~2007-12-21  9:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-19 18:12 [Qemu-devel] Host FPE for overflowing division on MIPS Richard Sandiford
  -- strict thread matches above, loose matches on Subject: below --
2007-12-20  9:58 Richard Sandiford

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).