aboutsummaryrefslogtreecommitdiff
path: root/src/lj_vmmath.c
diff options
context:
space:
mode:
authorMike Pall <mike>2022-12-07 18:38:22 +0100
committerMike Pall <mike>2022-12-07 18:38:22 +0100
commitde2e1ca9d3d87e74c0c20c1e4ad3c32b31a5875b (patch)
treec6dd3a9575b77c9f019c9d8627a814a955227acf /src/lj_vmmath.c
parent7d5d4a1b1a690d9fc87253868ba967bf25f4df6e (diff)
downloadluajit-de2e1ca9d3d87e74c0c20c1e4ad3c32b31a5875b.tar.gz
luajit-de2e1ca9d3d87e74c0c20c1e4ad3c32b31a5875b.tar.bz2
luajit-de2e1ca9d3d87e74c0c20c1e4ad3c32b31a5875b.zip
Disable FMA by default. Use -Ofma or jit.opt.start("+fma") to enable.
See the discussion in #918 for the rationale.
Diffstat (limited to 'src/lj_vmmath.c')
-rw-r--r--src/lj_vmmath.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/lj_vmmath.c b/src/lj_vmmath.c
index b6cc60ba..d0febd81 100644
--- a/src/lj_vmmath.c
+++ b/src/lj_vmmath.c
@@ -36,6 +36,17 @@ LJ_FUNCA double lj_wrap_fmod(double x, double y) { return fmod(x, y); }
36 36
37/* -- Helper functions ---------------------------------------------------- */ 37/* -- Helper functions ---------------------------------------------------- */
38 38
39/* Required to prevent the C compiler from applying FMA optimizations.
40**
41** Yes, there's -ffp-contract and the FP_CONTRACT pragma ... in theory.
42** But the current state of C compilers is a mess in this regard.
43** Also, this function is not performance sensitive at all.
44*/
45LJ_NOINLINE static double lj_vm_floormul(double x, double y)
46{
47 return lj_vm_floor(x / y) * y;
48}
49
39double lj_vm_foldarith(double x, double y, int op) 50double lj_vm_foldarith(double x, double y, int op)
40{ 51{
41 switch (op) { 52 switch (op) {
@@ -43,7 +54,7 @@ double lj_vm_foldarith(double x, double y, int op)
43 case IR_SUB - IR_ADD: return x-y; break; 54 case IR_SUB - IR_ADD: return x-y; break;
44 case IR_MUL - IR_ADD: return x*y; break; 55 case IR_MUL - IR_ADD: return x*y; break;
45 case IR_DIV - IR_ADD: return x/y; break; 56 case IR_DIV - IR_ADD: return x/y; break;
46 case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break; 57 case IR_MOD - IR_ADD: return x-lj_vm_floormul(x, y); break;
47 case IR_POW - IR_ADD: return pow(x, y); break; 58 case IR_POW - IR_ADD: return pow(x, y); break;
48 case IR_NEG - IR_ADD: return -x; break; 59 case IR_NEG - IR_ADD: return -x; break;
49 case IR_ABS - IR_ADD: return fabs(x); break; 60 case IR_ABS - IR_ADD: return fabs(x); break;