[Bug 59856] New: "musl: Use __builtin_rint if available" breaks rounding control in rint function family on x86_64
http://bugs.winehq.org/show_bug.cgi?id=59856 Bug ID: 59856 Summary: "musl: Use __builtin_rint if available" breaks rounding control in rint function family on x86_64 Product: Wine Version: 10.11 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: msvcrt Assignee: wine-bugs@list.winehq.org Reporter: martin@martin.st CC: piotr@codeweavers.com Regression SHA1: ee6e83dca874491329c5b376c2f9563093e3c69f Distribution: --- Created attachment 81156 --> http://bugs.winehq.org/attachment.cgi?id=81156 Test executable Since "musl: Use __builtin_rint if available", commit ee6e83dca874491329c5b376c2f9563093e3c69f, an x86_64 build no longer correctly handles rounding control for the rint family of functions. (Since 02f3e6ea8a67d95b800d39e32d79a625561cd7e1, "__builtin_rint" is only used in builds with GCC, not Clang. But this affects e.g. Ubuntu distribution builds of Wine on x86_64.) This can be reproduced with e.g. https://github.com/mstorsjo/llvm-mingw/blob/master/test/crt-test.c. I'm attaching a binary build of this testcase, built with MSVC with -MD. Before this commit, this executable outputs: 2905 tests, 0 failures After this commit, we instead get this output: test/crt-test.c:940: FE_DOWNWARD llrint(F(-3.3)) failed, expected -4, got -3 test/crt-test.c:940: FE_DOWNWARD llrint(F(-3.6)) failed, expected -4, got -3 test/crt-test.c:942: FE_DOWNWARD llrintl(F(-3.3)) failed, expected -4, got -3 test/crt-test.c:942: FE_DOWNWARD llrintl(F(-3.6)) failed, expected -4, got -3 test/crt-test.c:943: FE_DOWNWARD lrint(F(-3.3)) failed, expected -4, got -3 test/crt-test.c:943: FE_DOWNWARD lrint(F(-3.6)) failed, expected -4, got -3 test/crt-test.c:945: FE_DOWNWARD lrintl(F(-3.3)) failed, expected -4, got -3 test/crt-test.c:945: FE_DOWNWARD lrintl(F(-3.6)) failed, expected -4, got -3 test/crt-test.c:953: FE_DOWNWARD rint(F(-3.3)) failed, expected -4.000000, got -3.000000 test/crt-test.c:953: FE_DOWNWARD rint(F(-3.6)) failed, expected -4.000000, got -3.000000 test/crt-test.c:955: FE_DOWNWARD rintl(F(-3.3)) failed, expected -4.000000, got -3.000000 test/crt-test.c:955: FE_DOWNWARD rintl(F(-3.6)) failed, expected -4.000000, got -3.000000 test/crt-test.c:956: FE_DOWNWARD nearbyint(F(-3.3)) failed, expected -4.000000, got -3.000000 test/crt-test.c:956: FE_DOWNWARD nearbyint(F(-3.6)) failed, expected -4.000000, got -3.000000 test/crt-test.c:958: FE_DOWNWARD nearbyintl(F(-3.3)) failed, expected -4.000000, got -3.000000 test/crt-test.c:958: FE_DOWNWARD nearbyintl(F(-3.6)) failed, expected -4.000000, got -3.000000 test/crt-test.c:969: FE_UPWARD llrint(F(-3.3)) failed, expected -3, got -4 test/crt-test.c:969: FE_UPWARD llrint(F(-3.6)) failed, expected -3, got -4 test/crt-test.c:971: FE_UPWARD llrintl(F(-3.3)) failed, expected -3, got -4 test/crt-test.c:971: FE_UPWARD llrintl(F(-3.6)) failed, expected -3, got -4 test/crt-test.c:972: FE_UPWARD lrint(F(-3.3)) failed, expected -3, got -4 test/crt-test.c:972: FE_UPWARD lrint(F(-3.6)) failed, expected -3, got -4 test/crt-test.c:974: FE_UPWARD lrintl(F(-3.3)) failed, expected -3, got -4 test/crt-test.c:974: FE_UPWARD lrintl(F(-3.6)) failed, expected -3, got -4 test/crt-test.c:982: FE_UPWARD rint(F(-3.3)) failed, expected -3.000000, got -4.000000 test/crt-test.c:982: FE_UPWARD rint(F(-3.6)) failed, expected -3.000000, got -4.000000 test/crt-test.c:984: FE_UPWARD rintl(F(-3.3)) failed, expected -3.000000, got -4.000000 test/crt-test.c:984: FE_UPWARD rintl(F(-3.6)) failed, expected -3.000000, got -4.000000 test/crt-test.c:985: FE_UPWARD nearbyint(F(-3.3)) failed, expected -3.000000, got -4.000000 test/crt-test.c:985: FE_UPWARD nearbyint(F(-3.6)) failed, expected -3.000000, got -4.000000 test/crt-test.c:987: FE_UPWARD nearbyintl(F(-3.3)) failed, expected -3.000000, got -4.000000 test/crt-test.c:987: FE_UPWARD nearbyintl(F(-3.6)) failed, expected -3.000000, got -4.000000 2905 tests, 32 failures -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59856 Ken Sharp <imwellcushtymelike@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |source, testcase -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59856 Piotr Caban <piotr.caban@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |piotr.caban@gmail.com -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59856 Austin English <austinenglish@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |download, regression -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59856 qi'ao chen <gouziwu@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |gouziwu@gmail.com --- Comment #1 from qi'ao chen <gouziwu@gmail.com> --- For rint in gcc https://godbolt.org/z/4Prxxr469 for rint(-3.3)'s different behaviour With sse4.1, gcc emits roundsd If not, gcc falls back to ix86_expand_rint, whose behaviour is controlled by -frounding_math xa = fabs (operand1); if (!isless (xa, 2**52)) return operand1; two52 = 2**52; if (flag_rounding_math) { two52 = copysign (two52, operand1); xa = operand1; } xa = xa + two52 - two52; return copysign (xa, operand1); so for example, consider FE_DOWNWARD rint(-3.3) without rounding_math: xa = 3.3 + 2**52 - 2**52 = 3 + 2**52 - 2**52 = 3 return -3 with rounding_math: xa = -3.3 - 2**52 + 2**52 = -4 - 2**52 + 2**52 = -4 return -4 now in our code union {double f; uint64_t i;} u = {x}; int e = u.i>>52 & 0x7ff; int s = u.i>>63; double_t y; if (e >= 0x3ff+52) return x; if (s) y = x - toint + toint; else y = x + toint - toint; if (y == 0) return s ? -0.0 : 0; return y; s = u.i>>63 -> take sign into account, so basically its equivalent to -frounding_math so possible fix is only use __builtin_rint when we have SSE4.1 btw, seems there is no tests for musl, am i missing anything? -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59856 --- Comment #2 from Piotr Caban <piotr.caban@gmail.com> --- As of b9304e759a5decee2f6e7d55ba0043860d95a9f5 we're not using __builtin_rint. Please retest. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59856 Martin Storsjö <martin@martin.st> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |FIXED --- Comment #3 from Martin Storsjö <martin@martin.st> --- Thanks, I can confirm that it is fixed by b9304e759a5decee2f6e7d55ba0043860d95a9f5. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59856 Martin Storsjö <martin@martin.st> changed: What |Removed |Added ---------------------------------------------------------------------------- Fixed by SHA1| |b9304e759a5decee2f6e7d55ba0 | |043860d95a9f5 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
participants (1)
-
WineHQ Bugzilla