Skip to contentSkip to conversation

Floating point exception issue

Qemu-devel Mateusz Loskot 4 participants 9 messages Jan 18, 2011 – Jan 22, 2011

lore
Share & tools
lore
#0 lore raw

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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>

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,

Signature · 3 lines
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org
#1 lore raw
Quoted 71 lines · Mateusz Loskot

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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>

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
Quoted 5 lines

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.

I'll install 5.1, but on 4.0 which I had installed, the program works fine:

$ ./sigfpe
is a number
nan
#2 lore raw
Quoted 76 lines · Blue Swirl
Quoted 75 lines · Mateusz Loskot

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<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<errno.h>

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.

Quoted 6 lines
Quoted 1 line

All the signs indicate there is a bug in QEMU.

I'll install 5.1, but on 4.0 which I had installed, the program works fine:

$ ./sigfpe
is a number
nan

I just tested on NetBSD 5.0/SPARC under QEMU 0.13 (same version I use with NetBSD 5.1/SPARC) and it works well indeed:

mloskot@qemu-netbsd-50-sparc:~/tmp# ./a.out
is a number
nan
mloskot@qemu-netbsd-50-sparc:~/tmp#

Hmm, this is becoming interesting.

I run QEMU 0.13 on Windows Vista (64-bit). Perhaps host system and QEMU binaries are relevant here. I will try on Linux host system later tonight.

BTW, here are my images:

http://mateusz.loskot.net/tmp/qemu/

Best regards,

Signature · 3 lines
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org
#3 lore raw
Quoted 98 lines · Mateusz Loskot
Quoted 79 lines · Blue Swirl
Quoted 76 lines · Mateusz Loskot

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<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<errno.h>

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.

Quoted 7 lines
Quoted 1 line

All the signs indicate there is a bug in QEMU.

I'll install 5.1, but on 4.0 which I had installed, the program works fine:

$ ./sigfpe
is a number
nan

I just tested on NetBSD 5.0/SPARC under QEMU 0.13 (same version I use with NetBSD 5.1/SPARC) and it works well indeed:

mloskot@qemu-netbsd-50-sparc:~/tmp# ./a.out
is a number
nan
mloskot@qemu-netbsd-50-sparc:~/tmp#

Hmm, this is becoming interesting.

Quoted 7 lines

I run QEMU 0.13 on Windows Vista (64-bit). Perhaps host system and QEMU binaries are relevant here. I will try on Linux host system later tonight.

BTW, here are my images:

http://mateusz.loskot.net/tmp/qemu/

The problem was with NaN handling in fcmped instruction. I've committed a patch that fixes the problem, please test. Thanks for reporting and the test case.

#4 lore raw
Quoted 103 lines · Blue Swirl
Quoted 102 lines · Mateusz Loskot
Quoted 79 lines · Blue Swirl
Quoted 76 lines · Mateusz Loskot

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<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<errno.h>

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.

Quoted 7 lines
Quoted 1 line

All the signs indicate there is a bug in QEMU.

I'll install 5.1, but on 4.0 which I had installed, the program works fine:

$ ./sigfpe
is a number
nan

I just tested on NetBSD 5.0/SPARC under QEMU 0.13 (same version I use with NetBSD 5.1/SPARC) and it works well indeed:

mloskot@qemu-netbsd-50-sparc:~/tmp# ./a.out
is a number
nan
mloskot@qemu-netbsd-50-sparc:~/tmp#

Hmm, this is becoming interesting.

I run QEMU 0.13 on Windows Vista (64-bit). Perhaps host system and QEMU binaries are relevant here. I will try on Linux host system later tonight.

Quoted 6 lines
Quoted 3 lines

BTW, here are my images:

http://mateusz.loskot.net/tmp/qemu/

The problem was with NaN handling in fcmped instruction. I've committed a patch that fixes the problem, please test.

I'm having problems with building qemu under MinGW, so I will need to wait for someone to update binaries.

Stefan, are you planning to update your binaries?
I would be grateful.

Quoted 1 line

Thanks for reporting and the test case.

Thanks for fixing!

Best regards,

Signature · 3 lines
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org
#5 lore raw
In reply to Blue Swirl
Quoted 103 lines · Blue Swirl
Quoted 102 lines · Mateusz Loskot
Quoted 79 lines · Blue Swirl
Quoted 76 lines · Mateusz Loskot

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<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<errno.h>

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.

Quoted 7 lines
Quoted 1 line

All the signs indicate there is a bug in QEMU.

I'll install 5.1, but on 4.0 which I had installed, the program works fine:

$ ./sigfpe
is a number
nan

I just tested on NetBSD 5.0/SPARC under QEMU 0.13 (same version I use with NetBSD 5.1/SPARC) and it works well indeed:

mloskot@qemu-netbsd-50-sparc:~/tmp# ./a.out
is a number
nan
mloskot@qemu-netbsd-50-sparc:~/tmp#

Hmm, this is becoming interesting.

I run QEMU 0.13 on Windows Vista (64-bit). Perhaps host system and QEMU binaries are relevant here. I will try on Linux host system later tonight.

Quoted 7 lines
Quoted 3 lines

BTW, here are my images:

http://mateusz.loskot.net/tmp/qemu/

The problem was with NaN handling in fcmped instruction. I've committed a patch that fixes the problem, please test. Thanks for reporting and the test case.

FYI, this problem seems to be occurring in qemu on Windows only. I tested git version dated before you applied the fix and built on Linux and the problem does not happening there.

Best regards,

Signature · 3 lines
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org
#6 lore raw
Quoted 108 lines · Mateusz Loskot
Quoted 107 lines · Blue Swirl
Quoted 105 lines · Mateusz Loskot
Quoted 79 lines · Blue Swirl
Quoted 76 lines · Mateusz Loskot

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<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<errno.h>

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.

Quoted 7 lines
Quoted 1 line

All the signs indicate there is a bug in QEMU.

I'll install 5.1, but on 4.0 which I had installed, the program works fine:

$ ./sigfpe
is a number
nan

I just tested on NetBSD 5.0/SPARC under QEMU 0.13 (same version I use with NetBSD 5.1/SPARC) and it works well indeed:

mloskot@qemu-netbsd-50-sparc:~/tmp# ./a.out
is a number
nan
mloskot@qemu-netbsd-50-sparc:~/tmp#

Hmm, this is becoming interesting.

I run QEMU 0.13 on Windows Vista (64-bit). Perhaps host system and QEMU binaries are relevant here. I will try on Linux host system later tonight.

BTW, here are my images:

http://mateusz.loskot.net/tmp/qemu/

Quoted 7 lines
Quoted 3 lines

The problem was with NaN handling in fcmped instruction. I've committed a patch that fixes the problem, please test. Thanks for reporting and the test case.

FYI, this problem seems to be occurring in qemu on Windows only. I tested git version dated before you applied the fix and built on Linux and the problem does not happening there.

No, it was generic problem. I could reproduce it with your test case and with a small assembler program which only used fcmped using user emulator.

#7 lore raw
Quoted 116 lines · Blue Swirl
Quoted 114 lines · Mateusz Loskot
Quoted 112 lines · Blue Swirl
Quoted 98 lines · Mateusz Loskot
Quoted 78 lines · Blue Swirl
Quoted 75 lines · Mateusz Loskot

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<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<errno.h>

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.

Quoted 8 lines
Quoted 2 lines

All the signs indicate there is a bug in QEMU.

I'll install 5.1, but on 4.0 which I had installed, the program works fine:

$ ./sigfpe
is a number
nan

I just tested on NetBSD 5.0/SPARC under QEMU 0.13 (same version I use with NetBSD 5.1/SPARC) and it works well indeed:

mloskot@qemu-netbsd-50-sparc:~/tmp# ./a.out
is a number
nan
mloskot@qemu-netbsd-50-sparc:~/tmp#

Hmm, this is becoming interesting.

Quoted 8 lines

I run QEMU 0.13 on Windows Vista (64-bit). Perhaps host system and QEMU binaries are relevant here. I will try on Linux host system later tonight.

BTW, here are my images:

http://mateusz.loskot.net/tmp/qemu/

The problem was with NaN handling in fcmped instruction. I've committed a patch that fixes the problem, please test. Thanks for reporting and the test case.

Quoted 10 lines
Quoted 4 lines

FYI, this problem seems to be occurring in qemu on Windows only. I tested git version dated before you applied the fix and built on Linux and the problem does not happening there.

No, it was generic problem. I could reproduce it with your test case and with a small assembler program which only used fcmped using user emulator.

There is still a floating point exception problem that may or may not be related.

Booting an ss5-170 with a real sun ROM image still fails FP tests:

4.1.1  fpu    reg          regfile                  Pass
4.1.2  fpu    reg          misalign                 Pass
4.1.3  fpu    reg          single precision         Pass
4.1.4  fpu    reg          double precision         Pass
4.2.1  fpu    exceptions   single precision         Failed

Exception Didn't Block Store : 0 : exp= 00000000, obs= FFFFFFFF
4.2.2 fpu exceptions double precision Failed
Exception Didn't Block Store : 0 : exp= 00000000, obs= FFFFFFFF

#8 lore raw
Quoted 143 lines · Robert Reif
Quoted 130 lines · Blue Swirl
Quoted 126 lines · Mateusz Loskot
Quoted 122 lines · Blue Swirl
Quoted 105 lines · Mateusz Loskot
Quoted 81 lines · Blue Swirl
Quoted 77 lines · Mateusz Loskot

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<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<errno.h>

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.

Quoted 9 lines
Quoted 2 lines

All the signs indicate there is a bug in QEMU.

I'll install 5.1, but on 4.0 which I had installed, the program works fine:

$ ./sigfpe
is a number
nan

I just tested on NetBSD 5.0/SPARC under QEMU 0.13 (same version I use with
NetBSD 5.1/SPARC) and it works well indeed:

mloskot@qemu-netbsd-50-sparc:~/tmp# ./a.out
is a number
nan
mloskot@qemu-netbsd-50-sparc:~/tmp#

Hmm, this is becoming interesting.

Quoted 8 lines

I run QEMU 0.13 on Windows Vista (64-bit). Perhaps host system and QEMU binaries are relevant here. I will try on Linux host system later tonight.

BTW, here are my images:

http://mateusz.loskot.net/tmp/qemu/

The problem was with NaN handling in fcmped instruction. I've committed a patch that fixes the problem, please test. Thanks for reporting and the test case.

Quoted 11 lines
Quoted 4 lines

FYI, this problem seems to be occurring in qemu on Windows only. I tested git version dated before you applied the fix and built on Linux and the problem does not happening there.

No, it was generic problem. I could reproduce it with your test case and with a small assembler program which only used fcmped using user emulator.

Quoted 2 lines

There is still a floating point exception problem that may or may not be related.

AFAICS they are not related. Strictly speaking they are not FP problems but deferred trap processing problems.

Quoted 13 lines

Booting an ss5-170 with a real sun ROM image still fails FP tests:

4.1.1  fpu    reg          regfile                  Pass 4.1.2  fpu    reg          misalign                 Pass 4.1.3  fpu    reg          single precision         Pass 4.1.4  fpu    reg          double precision         Pass 4.2.1  fpu    exceptions   single precision         Failed Exception Didn't Block Store : 0 : exp= 00000000, obs= FFFFFFFF 4.2.2  fpu    exceptions   double precision         Failed Exception Didn't Block Store : 0 : exp= 00000000, obs= FFFFFFFF

Signature · 4 lines
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/