Date: Thu, 19 Nov 2015 06:41:50 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 204671] clang floating point wrong around Inf (i386) Message-ID: <bug-204671-8@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204671 Bug ID: 204671 Summary: clang floating point wrong around Inf (i386) Product: Base System Version: 10.2-RELEASE Hardware: i386 OS: Any Status: New Severity: Affects Some People Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: netch@segfault.kiev.ua Created attachment 163320 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=163320&action=edit source files The test program, being called as "./t <a> <operator> <b> <rounding>", performs a single arithmetic operator with the specified rounding and prints its results. In some cases, output is wrong. Conditions to reproduce: 1. Clang of any available version (confirmed on 3.4 from base, clang36-3.6.2, clang37-3.7.2 from ports). I can't get this issue with gcc-4.8.5, gcc-5.2.0_1 from ports. 2. i386 (amd64 isn't affected, I guess, because the issue is bound to FPU variant). 3. no high -march= ("native" causes issues to disappear, I guess, for the same connection to FPU; clang starts emitting SSE for this CPU). 4. -O or higher optimization level (-O0 isn't affected). The OS is: FreeBSD 10.2-RELEASE-p7 i386. The CPU on the test machine is: AMD Athlon(tm) 64 Processor 3500+ (Origin="AuthenticAMD" Id=0x50ff2 Family=0xf Model=0x5f Stepping=2). The proper results are (as I see from available IEEE754 documents): $ ./t1 1e308 + 1e308 0 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t1 1e308 + 1e308 1 r=1.797693134862316e+308 ( 7F EF FF FF FF FF FF FF) $ ./t1 1e308 + 1e308 2 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t1 1e308 + 1e308 3 r=1.797693134862316e+308 ( 7F EF FF FF FF FF FF FF) This satisties the standard requirement that, e.g., "roundTowardZero, the result shall be the format's floating-point number closest to and no greater in magnitude than the infinitely precise result." The variant with t1.c from attachment when the issue is exposed (compiled as "cc -o t1 t1.c -g -Wall -W -lm -O"): $ ./t1 1e308 + 1e308 0 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t1 1e308 + 1e308 1 r=inf ( 7F EF FF FF FF FF FF FF) $ ./t1 1e308 + 1e308 2 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t1 1e308 + 1e308 3 r=inf ( 7F EF FF FF FF FF FF FF) So, the binary representation of result is correct, but the printf output is not. The same compilation with -DNO_HEX always prints "inf" (so, it rejects a guess of an aliasing issue): $ ./t1 1e308 + 1e308 0 r=inf () $ ./t1 1e308 + 1e308 1 r=inf () $ ./t1 1e308 + 1e308 2 r=inf () $ ./t1 1e308 + 1e308 3 r=inf () The variant in t2.c uses global union instead of local on-stack one for binary printing. The behavior differs so binary representation always shows "inf": $ ./t2 1e308 + 1e308 0 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t2 1e308 + 1e308 1 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t2 1e308 + 1e308 2 r=inf ( 7F F0 00 00 00 00 00 00) $ ./t2 1e308 + 1e308 3 r=inf ( 7F F0 00 00 00 00 00 00) Again, adding -DNO_HEX causes "inf" still printed in all cases. But: a variant with "r" declared as global variable instead of local one (-DR_GLOBAL for both source versions) stops the issue. -- You are receiving this mail because: You are the assignee for the bug.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-204671-8>