From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J5eF7-0008Rf-3S for qemu-devel@nongnu.org; Fri, 21 Dec 2007 04:32:33 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J5eF6-0008Pr-2z for qemu-devel@nongnu.org; Fri, 21 Dec 2007 04:32:32 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J5eF5-0008PV-Ur for qemu-devel@nongnu.org; Fri, 21 Dec 2007 04:32:31 -0500 Received: from mk-outboundfilter-4.mail.uk.tiscali.com ([212.74.114.32]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J5eF5-0000Be-Kz for qemu-devel@nongnu.org; Fri, 21 Dec 2007 04:32:31 -0500 Received: from richard by firetop.home with local (Exim 4.63) (envelope-from ) id 1J5IAj-0000i1-0E for qemu-devel@nongnu.org; Thu, 20 Dec 2007 09:58:33 +0000 From: Richard Sandiford Date: Thu, 20 Dec 2007 09:58:32 +0000 Message-ID: <8763ytadrr.fsf@firetop.home> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Subject: [Qemu-devel] Host FPE for overflowing division on MIPS Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --=-=-= [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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=ddiv-fpe.patch 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; + } } } --=-=-=--