You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Floating point bug in range operation on Apple Silicon hardware #14140
I tested this on a few devices with my peers. Every x86 processor we tested worked as expected, but reliably got the erroneous result using different Apple M2 devices.
The investigation is complete. This is probably an Apple bug.
The following code:
// double.c
int main(void)
{
int i = 3;
double v = 0.03;
double v2 = 0.01;
double ret = v - (i * v2);
return 0;
}
compile:
clang -o double -g double.c
exec:
./double
If this continues, nothing will be output, so debug with gdb:
# gdb ./double
....
(gdb) b main
Breakpoint 1 at 0x724: file double.c, line 4.
(gdb) run
....
Breakpoint 1, main () at double.c:4
4 int i = 3;
(gdb) n
5 double v = 0.03;
(gdb)
6 double v2 = 0.01;
(gdb)
8 double ret = v - (i * v2);
(gdb)
10 return 0;
(gdb) p ret
$1 = -1.7347234759768071e-18
(gdb) p v
$2 = 0.029999999999999999
(gdb) p v2
$3 = 0.01
(gdb) p i
$4 = 3
(gdb) p i * v2
$5 = 0.029999999999999999
(gdb) p v - (i * v2)
$6 = 0
We can see that the calculation result ret is incorrect.
On a separate matter, I was investigating the behavior when using gcc and arm together.
So I discovered by chance that this only happens when compiled with clang. Compiling with gcc gives normal results.
I was able to get an answer right away. This is a problem with clang's compilation flags, and if -ffp-contract=off is not specified, calculation results may be slightly different from those of gcc etc.
Therefore, if you are building it yourself, please pass CFLAGS='-ffp-contract=off' in ./configure.
No feedback was provided. The issue is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so. Thank you.
Activity
SakiTakamachi commentedon May 5, 2024
I'll investigate this issue.
SakiTakamachi commentedon May 6, 2024
The investigation is complete. This is probably an Apple bug.
The following code:
compile:
exec:
If this continues, nothing will be output, so debug with gdb:
We can see that the calculation result
retis incorrect.SakiTakamachi commentedon May 6, 2024
However, I'm just trying to figure out if there's a workaround for this
devnexen commentedon May 6, 2024
If that helps, I have the same issue with my raspberry 4.
erjotek commentedon May 6, 2024
same problem occurred between 5.0 and 5.3.6 checking on 3v4l
SakiTakamachi commentedon May 6, 2024
Thanks. hmm, then, is this an arm-specific phenomenon? It might be a good idea to push the test code to Circle CI arm.
SakiTakamachi commentedon May 6, 2024
On a separate matter, I was investigating the behavior when using gcc and arm together.
So I discovered by chance that this only happens when compiled with clang. Compiling with gcc gives normal results.
youkidearitai commentedon May 6, 2024
In M1 MacBook Air is reproduced.
In Raspberry Pi 4 (build in GCC), result is bellow:
However, In Raspberry Pi 4 (build in clang), result is reproduced:
SakiTakamachi commentedon May 6, 2024
The combination of intel and clang works fine.
SakiTakamachi commentedon May 6, 2024
I reported it
llvm/llvm-project#91224
SakiTakamachi commentedon May 6, 2024
I was able to get an answer right away. This is a problem with clang's compilation flags, and if
-ffp-contract=offis not specified, calculation results may be slightly different from those of gcc etc.Therefore, if you are building it yourself, please pass
CFLAGS='-ffp-contract=off'in./configure.youkidearitai commentedon May 6, 2024
I confirmed correct behavior in M1 MacBook Air.
github-actions commentedon May 21, 2024
No feedback was provided. The issue is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so. Thank you.
erjotek commentedon May 21, 2024
@shivammathur Hi, do you plan to change this flag in yours brew packages?
SakiTakamachi commentedon May 21, 2024
This issue was resolved by the following PR:
#14162
shivammathur commentedon May 21, 2024
@erjotek
Yes, with the next releases.
judahnator commentedon May 21, 2024
Still having the problem, thanks GitHub actions.
add -ffp-contract=off per php#14140
add -ffp-contract=off per php#14140
add -ffp-contract=off per php#14140