[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Test tstdiomisc fails when multiplication of NAN by -1 results in NAN again.


The following testcase is an example of code used in a glibc testcase.
I'm trying hard to shake out the bugs in the glibc testsuite for
debian, and one testsuite failure looks like a compiler issue.

The expected behaviour is for the testcase to print the raw IEEE754
value of -NAN.

The observed behaviour, when -DALT is on the command line, is that the
testcase prints the incorrect raw value e.g. NAN.

GCC 4.4.3 in debian doesn't compile this code correctly. Could you
have a loot at my analysis and tell me if you have seen this before?

cat >> tst-mul-nan.c <<EOF
#include <stdio.h>
#include <math.h>

#ifdef ALT
volatile double nanval;
#define nanval NAN

main ()
#ifdef ALT
  nanval = NAN;
  printf ("0x%llx\n", -nanval);
  return 0;

gcc -g3 -O0 -save-temps -o test-mul-nan-OK test-mul-nan.c; ./test-mul-nan-OK

This is the correct result e.g. -NAN. In the correct case the compiler
has already computer -NAN and it's loaded directly from the local
symbol e.g.

        .word   -524289
        .word   -1

This is the case that is not working correctly:

gcc -g3 -O0 -save-temps -DALT -o test-mul-nan-NG test-mul-nan.c;

That result is not -NAN, it is NAN. This is incorrect.

In the incorrect compilation the compiler loads NAN from a local constant:

        .word   2146959359
        .word   -1

This is 0x7ff7ffffffffffff e.g. NAN.

Then it loads something which I assume *should* be -1, but isn't:

        .word   -1074790400
        .word   0

What is this value, it's 0xbff0000000000000 e.g. -1.875. Should it be
0xbf80000000000000 e.g. -1.0 exactly, but it's not? Is this a mistake?

In the incorrect case the compiler tries to multiply this value by NAN
to get a result of -NAN.

        addil LR'nanval-$global$,%r27
        copy %r1,%r19
        ldo RR'nanval-$global$(%r19),%r19
        fldds 0(%r19),%fr23
        ldil LR'.LC2,%r19
        ldo RR'.LC2(%r19),%r19
        fldds 0(%r19),%fr22
        fmpy,dbl %fr23,%fr22,%fr22

It seems like it should work (even if fr22 is -1.875), since the sign
of the output NAN is the XOR of the signs of the inputs, therefore "-
XOR + = -" and the the result should be -NAN, but it's not, it's NAN?

PA-RISC 2.0 Architecture, Floating Coprocessor 8-23 "Operations With
NaNs", and 8-24 "Sign Bit" can be referenced for information on NANs.

After the multiplication fr22 still contains NAN, and that is what is
printed instead of the expected result of -NAN.

Any idea what is going on here? Thanks for your help.


Reply to: