Fuse multiply-adds in the Math port on macOS arm64, as Node's build does

Node for macOS on arm64 is compiled by clang, which contracts a multiply
and an add within one expression into a fused multiply-add. Its sin, cos,
tan, asin, acos, atan, sinh, asinh, acosh, atanh, exp, expm1, log, log1p
and log10 differ from the unfused results in the last bit for some inputs,
so corpus 7717 and 7718 failed on macOS. scr_ieee754.c now sets
FP_CONTRACT ON for Apple arm64 targets. Other targets keep it off and
compile to the same code as before.
This commit is contained in:
Chris Tate
2026-10-25 19:55:14 -05:00
parent dd418b067a
commit b6a1058f24
+9 -2
View File
@@ -32,9 +32,16 @@
#include "scr_ieee754.h"
/* Each operation rounds on its own, as in V8's build: no fused
* multiply-add, which would change the results on targets that have one. */
/* Floating-point contraction follows Node's build of this file. Node for
* macOS on arm64 is compiled by clang, which fuses a multiply and an add
* within one expression into a fused multiply-add; the results differ from
* the unfused ones in the last bit for some inputs. Other builds round each
* operation on its own, as Node's x86-64 builds do. */
#if defined(__APPLE__) && defined(__aarch64__)
#pragma STDC FP_CONTRACT ON
#else
#pragma STDC FP_CONTRACT OFF
#endif
static inline uint64_t scr_fd_bits(double d) {
uint64_t bits;