Overview
| Artifact ID: | 79f21aa24752d256b595f4ad410471f86105411d41b98c5bb3989bff1e1885ee |
|---|---|
| Ticket: | 713653b951c625ef974f5f06b2e96634ca5fb1f9
Floating point precision problems on x86 musl |
| User & Date: | kbk on 2022-07-14 18:49:04 |
Changes
- icomment:
Unfortunately, strange platform issues like this can be hard to debug "at arm's length". I don't have an Alpine machine to test on (and I think that all the Alpine machines I've ever encountered have been ARM rather than ix86). Disabling the rounding mode isn't the correct solution (obviously, since it starts breaking other things!) - so we need to get to the bottom of this. It would appear that it's something gone amiss in the environment. I've tested 8.6.11 with the standard Tcl test suite on both gcc and clang on Xubuntu 20.04 LTS, and the tests are passing. Likewise, all the test in the `math` module of tcllib are passing as well, with both gcc and clang builds. For starters, what compiler is this? (I don't know if Alpine uses gcc, clang, tcc or something all its own...) Are you changing optimization flags from the set that tcl/unix/configure provides? The testing of floating point conversion is pretty comprehensive. I don't think anything that would introduce breakage of this magnitude would slip through Tcl's own test suite. (You did say that everything in Tcl's own tests passed before you started adjusting the rounding modes, right?) The broken Tcllib math tests suggest that something very weird is going on. The 'Trig-2.3' test is probably the easiest to attack - it's not doing anything terribly out of the ordinary and its execution path is only a few lines of Tcl, but the outputs grow increasingly bizarre. (The nelderMead tests also indicate something very fundamental, because they just do basic arithmetic.) One very odd possibility is that the floating point mode setting is being reordered by the optimizer in the compiler you're using. I've heard rumoured that in some compilers it's necessary to replace the line ``` double retval; /* Value of the number. */ ``` in two places (the `MakeLowPrecisionDouble` and `MakeHighPrecisionDouble` functions in `tclStrToD.c`) with ``` volatile double retval; /* Value of the number */ ``` to prevent that from happening. I've not found that to be necessary at the -O2 setting that Tcl uses by default, whether using gcc, clang, or Visual C++. Beyond that, the next thing that I'd suspect is that something is messed up in the C library or the compiler intrinsics. As you've probably noticed, tclStrToD.c uses some odd functions - things like ldexp(), frexp() and copysign(). Of course, the change to tclStrToD.c might be entirely a red herring. Are we sure that 8.6.10 and 8.6.11 were built with the same compiler, include files, system libraries and optimization flags? (Another reason that I have for suspecting that the issue might be somewhere else is that the format-* tests that are failing don't go through tclStrToD.c. They eventually land in the sprintf() function of the C library.) If you can verify that 8.6.10 works and 8.6.11 fails when built in the same toolchain, the next step might be to make a shell script that exits with status 0 for success on a test case, and status 1 for failure, and feed that to [fossil bisect](https://fossil-scm.org/home/help/bisect). That's pretty heavyweight but might narrow it from the point release down to the individual commit.
- login: "kbk"
- mimetype: "text/x-markdown"