qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Sandiford <rsandifo@nildram.co.uk>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Host FPE for overflowing division on MIPS
Date: Wed, 19 Dec 2007 18:12:26 +0000	[thread overview]
Message-ID: <87r6hia705.fsf@firetop.home> (raw)

[-- 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;
+        }
     }
 }
 

             reply	other threads:[~2007-12-19 18:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-19 18:12 Richard Sandiford [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-12-20  9:58 [Qemu-devel] Host FPE for overflowing division on MIPS Richard Sandiford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r6hia705.fsf@firetop.home \
    --to=rsandifo@nildram.co.uk \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).