This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Incorrect runtime behavior involving comparison



> bool t1 = z1.priority() > z2.priority();
> bool t2 = z2.priority() > z1.priority();

This fails on i386 because of the so-called extra-precise fpu register
effect.  It is a feature, not a bug.

If you look at the generated assembly language

        call priority__4zone
        addl $16,%esp
        fstpl -40(%ebp)
        addl $-12,%esp
        leal -8(%ebp),%eax
        pushl %eax
        call priority__4zone
        addl $16,%esp
        fcompl -40(%ebp)

you see that one result is stored out to memory and gets rounded off
from the extended register precision to double precision.  The
other result is not stored; it remains in the fpu register as an
extra-precise value during the compare.

The program succeeds if you set the i386 math coprocessor to double
precision mode.  Some systems, such as Microsoft Windows, do that by
default, but in doing so they throw away the extended precision long
double data type.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]