Boost logo

Boost :

From: Guillaume Melquiond (gmelquio_at_[hidden])
Date: 2003-07-04 23:27:26


On Fri, 4 Jul 2003, jvd wrote:

> [snip]
>
> > > does not work correctly on some machines.
> >
> > Could you be more specific. On which machines for instance ?
>
> Me, myself personally tested on Intel Celeron 733, OS WinXP.
> Compiler used: gcc 3.2 mingw port for windows.
>
> Also reported not to work on Sun machine although on some other computers
> this works.

Strange, I just tried it on a x86 (linux, cygwin, gcc 2.95, 3.2, 3.3) and
on sparc (gcc 2.95), and it works perfectly. The test program was:

int main() { double a = 0. / 0.; return a != a; }

> That mean sometimes this work and sometimes not :)
> Depends on processor perhaps, because I've read asm output (I'm just a crap
> when it comes to x86 asm reading but...):
>
> // g++ -save-temps -O0 (to avoid overoptimizations when variable comparison
> to itself is just replaced with some boolean constant)
>
> There we have is_nan for floats -
>
> .section .text$_ZN4math4geom6is_nanIfEEbRKT_,"x"
> .linkonce discard
> .align 2
> .globl __ZN4math4geom6is_nanIfEEbRKT_
> .def __ZN4math4geom6is_nanIfEEbRKT_; .scl 2; .type 32; .endef
> __ZN4math4geom6is_nanIfEEbRKT_:
> LFB29:
> // function prologue
> pushl %ebp
> LCFI225:
> movl %esp, %ebp
> LCFI226:
> movl 8(%ebp), %eax
> movl 8(%ebp), %edx
> // operations on stack, sweet
>
>
> flds (%eax) // load the same
> flds (%edx) // variable to 2 copr. registers
> fxch %st(1)
> fucompp // comparison (x != x), obviously
> fnstsw %ax
> andb $69, %ah
> xorb $64, %ah
> setne %al
> andl $255, %eax // && std::numeric_limits<float>::has_quiet_NaN
>
> popl %ebp // function epilogue
> ret
>
>
> Seems like this is not compilers fault. Correct me if I'm wrong. And as me

No, the code is correct. When fucom (unordered compare) encounters quiet
NaN arguments, it sets condition flags C0 (0x01), C1 (0x02) and C3 (0x40)
to 1. The status word is then put in %ax. The condition flags are
extracted ($69 = 0x45). C3 is then inverted. But C0 and C1 are still
non-zero. The function will answer true (according to Intel instruction
set reference, document 24547107).

Maybe you just found yourself a buggy processor :-)

> uses intervals lib and is_nan f-tion, specifically; I'm really concerned
> about such problems. If workaround is needed and it's not so simple, perhaps
> it could be separated from certain library and moved itself to
> numeric_utility.hpp or something?
>
> Respect,
> Justinas V.D.

Regards,

Guillaume


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk