From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=54703 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PfDOq-0002PL-7G for qemu-devel@nongnu.org; Tue, 18 Jan 2011 10:23:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PfDOo-0003Zv-Jd for qemu-devel@nongnu.org; Tue, 18 Jan 2011 10:23:11 -0500 Received: from srv1.whshost.com ([174.121.90.50]:52759) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PfDOo-0003VV-EF for qemu-devel@nongnu.org; Tue, 18 Jan 2011 10:23:10 -0500 Received: from [82.110.183.162] (helo=[10.0.1.64]) by srv1.whshost.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1PfDOk-00012C-4X for qemu-devel@nongnu.org; Tue, 18 Jan 2011 16:23:06 +0100 Message-ID: <4D35B148.9080003@loskot.net> Date: Tue, 18 Jan 2011 15:27:04 +0000 From: Mateusz Loskot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [sparc] Floating point exception issue List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hi, Recently, I have reported mysterious issues on NetBSD 5.1 emulated on SPARC. The whole first thread is here: http://lists.gnu.org/archive/html/qemu-devel/2011-01/msg01509.html I decided to investigate the problem deeper and with great help from NetBSD folks, I managed to find reproducible test case. Initially, it was AWK command: # echo NaN | awk '{print "test"}' awk: floating point exception 8 source line number 1 and next it boiled down to simple C program (see below). Details of the investigation are archived in the NetBSD Problem Report #44389 here: http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=44389 Here is final version of the test program which reproduces the problem: #include #include #include #include int is_number(const char *s) { double r; char *ep; errno = 0; r = strtod(s, &ep); if (r == HUGE_VAL) printf("X:%g\n", r); if (ep == s || r == HUGE_VAL || errno == ERANGE) return 0; while (*ep == ' ' || *ep == '\t' || *ep == '\n') ep++; if (*ep == '\0') return 1; else return 0; } int main(int argc, char **argv) { double v; if (is_number("NaN")) { printf("is a number\n"); v = atof("NaN"); } else { printf("not a number\n"); v = 0.0; } printf("%.4f\n", v); return 0; } On NetBSD/SPARC, the program receives SIGFPE: $ gcc ./nan_test_2.c $ ./a.out [1] Floating point exception (core dumped) ./a.out Specifically, it's caused by r == HUGE_VAL condition in if (ep == s || r == HUGE_VAL || errno == ERANGE) where r is NaN. All the signs indicate there is a bug in QEMU. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org Member of ACCU, http://accu.org