aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2022-03-08 19:44:10 +0100
committerMike Pall <mike>2022-03-08 19:44:10 +0100
commit96d6d5032098ea9f0002165394a8774dcaa0c0ce (patch)
tree84712e02c1452d8f0c48a6f506a9aa1ebe0f4a32
parentaa0550e3f0999cc6ef62f7ef80493ebef8c9a2f7 (diff)
downloadluajit-96d6d5032098ea9f0002165394a8774dcaa0c0ce.tar.gz
luajit-96d6d5032098ea9f0002165394a8774dcaa0c0ce.tar.bz2
luajit-96d6d5032098ea9f0002165394a8774dcaa0c0ce.zip
Revert to trival pow() optimizations to prevent inaccuracies.
-rw-r--r--src/lj_asm.c3
-rw-r--r--src/lj_dispatch.h2
-rw-r--r--src/lj_ffrecord.c4
-rw-r--r--src/lj_ircall.h3
-rw-r--r--src/lj_iropt.h1
-rw-r--r--src/lj_opt_fold.c37
-rw-r--r--src/lj_opt_narrow.c24
-rw-r--r--src/lj_opt_split.c2
-rw-r--r--src/lj_record.c2
-rw-r--r--src/lj_vm.h3
-rw-r--r--src/lj_vmmath.c44
-rw-r--r--src/vm_arm.dasc13
-rw-r--r--src/vm_arm64.dasc11
-rw-r--r--src/vm_mips.dasc11
-rw-r--r--src/vm_mips64.dasc11
-rw-r--r--src/vm_ppc.dasc11
-rw-r--r--src/vm_x64.dasc9
-rw-r--r--src/vm_x86.dasc11
18 files changed, 45 insertions, 157 deletions
diff --git a/src/lj_asm.c b/src/lj_asm.c
index eaee5547..32dd7e87 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -1680,8 +1680,7 @@ static void asm_pow(ASMState *as, IRIns *ir)
1680 IRCALL_lj_carith_powu64); 1680 IRCALL_lj_carith_powu64);
1681 else 1681 else
1682#endif 1682#endif
1683 asm_callid(as, ir, irt_isnum(IR(ir->op2)->t) ? IRCALL_lj_vm_pow : 1683 asm_callid(as, ir, IRCALL_pow);
1684 IRCALL_lj_vm_powi);
1685} 1684}
1686 1685
1687static void asm_div(ASMState *as, IRIns *ir) 1686static void asm_div(ASMState *as, IRIns *ir)
diff --git a/src/lj_dispatch.h b/src/lj_dispatch.h
index d0f86fab..0594af51 100644
--- a/src/lj_dispatch.h
+++ b/src/lj_dispatch.h
@@ -44,7 +44,7 @@ extern double __divdf3(double a, double b);
44#define GOTDEF(_) \ 44#define GOTDEF(_) \
45 _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \ 45 _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \
46 _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \ 46 _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \
47 _(lj_vm_pow) _(fmod) _(ldexp) _(lj_vm_modi) \ 47 _(pow) _(fmod) _(ldexp) _(lj_vm_modi) \
48 _(lj_dispatch_call) _(lj_dispatch_ins) _(lj_dispatch_stitch) \ 48 _(lj_dispatch_call) _(lj_dispatch_ins) _(lj_dispatch_stitch) \
49 _(lj_dispatch_profile) _(lj_err_throw) \ 49 _(lj_dispatch_profile) _(lj_err_throw) \
50 _(lj_ffh_coroutine_wrap_err) _(lj_func_closeuv) _(lj_func_newL_gc) \ 50 _(lj_ffh_coroutine_wrap_err) _(lj_func_closeuv) _(lj_func_newL_gc) \
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c
index a19f6fdc..60c1d84f 100644
--- a/src/lj_ffrecord.c
+++ b/src/lj_ffrecord.c
@@ -638,8 +638,8 @@ static void LJ_FASTCALL recff_math_call(jit_State *J, RecordFFData *rd)
638 638
639static void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd) 639static void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd)
640{ 640{
641 J->base[0] = lj_opt_narrow_pow(J, J->base[0], J->base[1], 641 J->base[0] = lj_opt_narrow_arith(J, J->base[0], J->base[1],
642 &rd->argv[0], &rd->argv[1]); 642 &rd->argv[0], &rd->argv[1], IR_POW);
643 UNUSED(rd); 643 UNUSED(rd);
644} 644}
645 645
diff --git a/src/lj_ircall.h b/src/lj_ircall.h
index c4d4a7b8..67fb58ae 100644
--- a/src/lj_ircall.h
+++ b/src/lj_ircall.h
@@ -217,8 +217,7 @@ typedef struct CCallInfo {
217 _(FPMATH, sqrt, 1, N, NUM, XA_FP) \ 217 _(FPMATH, sqrt, 1, N, NUM, XA_FP) \
218 _(ANY, log, 1, N, NUM, XA_FP) \ 218 _(ANY, log, 1, N, NUM, XA_FP) \
219 _(ANY, lj_vm_log2, 1, N, NUM, XA_FP) \ 219 _(ANY, lj_vm_log2, 1, N, NUM, XA_FP) \
220 _(ANY, lj_vm_powi, 2, N, NUM, XA_FP) \ 220 _(ANY, pow, 2, N, NUM, XA2_FP) \
221 _(ANY, lj_vm_pow, 2, N, NUM, XA2_FP) \
222 _(ANY, atan2, 2, N, NUM, XA2_FP) \ 221 _(ANY, atan2, 2, N, NUM, XA2_FP) \
223 _(ANY, ldexp, 2, N, NUM, XA_FP) \ 222 _(ANY, ldexp, 2, N, NUM, XA_FP) \
224 _(SOFTFP, lj_vm_tobit, 1, N, INT, XA_FP32) \ 223 _(SOFTFP, lj_vm_tobit, 1, N, INT, XA_FP32) \
diff --git a/src/lj_iropt.h b/src/lj_iropt.h
index 7bce34c7..d239f173 100644
--- a/src/lj_iropt.h
+++ b/src/lj_iropt.h
@@ -145,7 +145,6 @@ LJ_FUNC TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,
145 TValue *vb, TValue *vc, IROp op); 145 TValue *vb, TValue *vc, IROp op);
146LJ_FUNC TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc); 146LJ_FUNC TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc);
147LJ_FUNC TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc); 147LJ_FUNC TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc);
148LJ_FUNC TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc);
149LJ_FUNC IRType lj_opt_narrow_forl(jit_State *J, cTValue *forbase); 148LJ_FUNC IRType lj_opt_narrow_forl(jit_State *J, cTValue *forbase);
150 149
151/* Optimization passes. */ 150/* Optimization passes. */
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c
index 34f70e27..92bdc553 100644
--- a/src/lj_opt_fold.c
+++ b/src/lj_opt_fold.c
@@ -236,14 +236,10 @@ LJFOLDF(kfold_fpcall2)
236 return NEXTFOLD; 236 return NEXTFOLD;
237} 237}
238 238
239LJFOLD(POW KNUM KINT)
240LJFOLD(POW KNUM KNUM) 239LJFOLD(POW KNUM KNUM)
241LJFOLDF(kfold_numpow) 240LJFOLDF(kfold_numpow)
242{ 241{
243 lua_Number a = knumleft; 242 return lj_ir_knum(J, lj_vm_foldarith(knumleft, knumright, IR_POW - IR_ADD));
244 lua_Number b = fright->o == IR_KINT ? (lua_Number)fright->i : knumright;
245 lua_Number y = lj_vm_foldarith(a, b, IR_POW - IR_ADD);
246 return lj_ir_knum(J, y);
247} 243}
248 244
249/* Must not use kfold_kref for numbers (could be NaN). */ 245/* Must not use kfold_kref for numbers (could be NaN). */
@@ -1113,34 +1109,17 @@ LJFOLDF(simplify_nummuldiv_negneg)
1113 return RETRYFOLD; 1109 return RETRYFOLD;
1114} 1110}
1115 1111
1116LJFOLD(POW any KINT) 1112LJFOLD(POW any KNUM)
1117LJFOLDF(simplify_numpow_xkint) 1113LJFOLDF(simplify_numpow_k)
1118{ 1114{
1119 int32_t k = fright->i; 1115 if (knumright == 0) /* x ^ 0 ==> 1 */
1120 TRef ref = fins->op1;
1121 if (k == 0) /* x ^ 0 ==> 1 */
1122 return lj_ir_knum_one(J); /* Result must be a number, not an int. */ 1116 return lj_ir_knum_one(J); /* Result must be a number, not an int. */
1123 if (k == 1) /* x ^ 1 ==> x */ 1117 else if (knumright == 1) /* x ^ 1 ==> x */
1124 return LEFTFOLD; 1118 return LEFTFOLD;
1125 if ((uint32_t)(k+65536) > 2*65536u) /* Limit code explosion. */ 1119 else if (knumright == 2) /* x ^ 2 ==> x * x */
1120 return emitir(IRTN(IR_MUL), fins->op1, fins->op1);
1121 else
1126 return NEXTFOLD; 1122 return NEXTFOLD;
1127 if (k < 0) { /* x ^ (-k) ==> (1/x) ^ k. */
1128 ref = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), ref);
1129 k = -k;
1130 }
1131 /* Unroll x^k for 1 <= k <= 65536. */
1132 for (; (k & 1) == 0; k >>= 1) /* Handle leading zeros. */
1133 ref = emitir(IRTN(IR_MUL), ref, ref);
1134 if ((k >>= 1) != 0) { /* Handle trailing bits. */
1135 TRef tmp = emitir(IRTN(IR_MUL), ref, ref);
1136 for (; k != 1; k >>= 1) {
1137 if (k & 1)
1138 ref = emitir(IRTN(IR_MUL), ref, tmp);
1139 tmp = emitir(IRTN(IR_MUL), tmp, tmp);
1140 }
1141 ref = emitir(IRTN(IR_MUL), ref, tmp);
1142 }
1143 return ref;
1144} 1123}
1145 1124
1146/* -- Simplify conversions ------------------------------------------------ */ 1125/* -- Simplify conversions ------------------------------------------------ */
diff --git a/src/lj_opt_narrow.c b/src/lj_opt_narrow.c
index fe92468e..586f1bc7 100644
--- a/src/lj_opt_narrow.c
+++ b/src/lj_opt_narrow.c
@@ -584,30 +584,6 @@ TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc)
584 return emitir(IRTN(IR_SUB), rb, tmp); 584 return emitir(IRTN(IR_SUB), rb, tmp);
585} 585}
586 586
587/* Narrowing of power operator or math.pow. */
588TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc)
589{
590 rb = conv_str_tonum(J, rb, vb);
591 rb = lj_ir_tonum(J, rb); /* Left arg is always treated as an FP number. */
592 rc = conv_str_tonum(J, rc, vc);
593 if (tvisint(vc) || numisint(numV(vc))) {
594 int32_t k = numberVint(vc);
595 if (!(k >= -65536 && k <= 65536)) goto force_pow_num;
596 if (!tref_isinteger(rc)) {
597 /* Guarded conversion to integer! */
598 rc = emitir(IRTGI(IR_CONV), rc, IRCONV_INT_NUM|IRCONV_CHECK);
599 }
600 if (!tref_isk(rc)) { /* Range guard: -65536 <= i <= 65536 */
601 TRef tmp = emitir(IRTI(IR_ADD), rc, lj_ir_kint(J, 65536));
602 emitir(IRTGI(IR_ULE), tmp, lj_ir_kint(J, 2*65536));
603 }
604 } else {
605force_pow_num:
606 rc = lj_ir_tonum(J, rc); /* Want POW(num, num), not POW(num, int). */
607 }
608 return emitir(IRTN(IR_POW), rb, rc);
609}
610
611/* -- Predictive narrowing of induction variables ------------------------- */ 587/* -- Predictive narrowing of induction variables ------------------------- */
612 588
613/* Narrow a single runtime value. */ 589/* Narrow a single runtime value. */
diff --git a/src/lj_opt_split.c b/src/lj_opt_split.c
index 6d32712b..18937c30 100644
--- a/src/lj_opt_split.c
+++ b/src/lj_opt_split.c
@@ -400,7 +400,7 @@ static void split_ir(jit_State *J)
400 hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_div); 400 hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_div);
401 break; 401 break;
402 case IR_POW: 402 case IR_POW:
403 hi = split_call_li(J, hisubst, oir, ir, IRCALL_lj_vm_powi); 403 hi = split_call_li(J, hisubst, oir, ir, IRCALL_pow);
404 break; 404 break;
405 case IR_FPMATH: 405 case IR_FPMATH:
406 hi = split_call_l(J, hisubst, oir, ir, IRCALL_lj_vm_floor + ir->op2); 406 hi = split_call_l(J, hisubst, oir, ir, IRCALL_lj_vm_floor + ir->op2);
diff --git a/src/lj_record.c b/src/lj_record.c
index d4d687e7..59798844 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -2394,7 +2394,7 @@ void lj_record_ins(jit_State *J)
2394 2394
2395 case BC_POW: 2395 case BC_POW:
2396 if (tref_isnumber_str(rb) && tref_isnumber_str(rc)) 2396 if (tref_isnumber_str(rb) && tref_isnumber_str(rc))
2397 rc = lj_opt_narrow_pow(J, rb, rc, rbv, rcv); 2397 rc = lj_opt_narrow_arith(J, rb, rc, rbv, rcv, IR_POW);
2398 else 2398 else
2399 rc = rec_mm_arith(J, &ix, MM_pow); 2399 rc = rec_mm_arith(J, &ix, MM_pow);
2400 break; 2400 break;
diff --git a/src/lj_vm.h b/src/lj_vm.h
index bfa7e0fd..c66db004 100644
--- a/src/lj_vm.h
+++ b/src/lj_vm.h
@@ -98,9 +98,6 @@ LJ_ASMF int lj_vm_errno(void);
98LJ_ASMF TValue *lj_vm_next(GCtab *t, uint32_t idx); 98LJ_ASMF TValue *lj_vm_next(GCtab *t, uint32_t idx);
99#endif 99#endif
100 100
101LJ_ASMF double lj_vm_powi(double, int32_t);
102LJ_ASMF double lj_vm_pow(double, double);
103
104/* Continuations for metamethods. */ 101/* Continuations for metamethods. */
105LJ_ASMF void lj_cont_cat(void); /* Continue with concatenation. */ 102LJ_ASMF void lj_cont_cat(void); /* Continue with concatenation. */
106LJ_ASMF void lj_cont_ra(void); /* Store result in RA from instruction. */ 103LJ_ASMF void lj_cont_ra(void); /* Store result in RA from instruction. */
diff --git a/src/lj_vmmath.c b/src/lj_vmmath.c
index fa0de922..b6cc60ba 100644
--- a/src/lj_vmmath.c
+++ b/src/lj_vmmath.c
@@ -30,52 +30,12 @@ LJ_FUNCA double lj_wrap_sinh(double x) { return sinh(x); }
30LJ_FUNCA double lj_wrap_cosh(double x) { return cosh(x); } 30LJ_FUNCA double lj_wrap_cosh(double x) { return cosh(x); }
31LJ_FUNCA double lj_wrap_tanh(double x) { return tanh(x); } 31LJ_FUNCA double lj_wrap_tanh(double x) { return tanh(x); }
32LJ_FUNCA double lj_wrap_atan2(double x, double y) { return atan2(x, y); } 32LJ_FUNCA double lj_wrap_atan2(double x, double y) { return atan2(x, y); }
33LJ_FUNCA double lj_wrap_pow(double x, double y) { return pow(x, y); }
33LJ_FUNCA double lj_wrap_fmod(double x, double y) { return fmod(x, y); } 34LJ_FUNCA double lj_wrap_fmod(double x, double y) { return fmod(x, y); }
34#endif 35#endif
35 36
36/* -- Helper functions ---------------------------------------------------- */ 37/* -- Helper functions ---------------------------------------------------- */
37 38
38/* Unsigned x^k. */
39static double lj_vm_powui(double x, uint32_t k)
40{
41 double y;
42 lj_assertX(k != 0, "pow with zero exponent");
43 for (; (k & 1) == 0; k >>= 1) x *= x;
44 y = x;
45 if ((k >>= 1) != 0) {
46 for (;;) {
47 x *= x;
48 if (k == 1) break;
49 if (k & 1) y *= x;
50 k >>= 1;
51 }
52 y *= x;
53 }
54 return y;
55}
56
57/* Signed x^k. */
58double lj_vm_powi(double x, int32_t k)
59{
60 if (k > 1)
61 return lj_vm_powui(x, (uint32_t)k);
62 else if (k == 1)
63 return x;
64 else if (k == 0)
65 return 1.0;
66 else
67 return 1.0 / lj_vm_powui(x, (uint32_t)-k);
68}
69
70double lj_vm_pow(double x, double y)
71{
72 int32_t k = lj_num2int(y);
73 if ((k >= -65536 && k <= 65536) && y == (double)k)
74 return lj_vm_powi(x, k);
75 else
76 return pow(x, y);
77}
78
79double lj_vm_foldarith(double x, double y, int op) 39double lj_vm_foldarith(double x, double y, int op)
80{ 40{
81 switch (op) { 41 switch (op) {
@@ -84,7 +44,7 @@ double lj_vm_foldarith(double x, double y, int op)
84 case IR_MUL - IR_ADD: return x*y; break; 44 case IR_MUL - IR_ADD: return x*y; break;
85 case IR_DIV - IR_ADD: return x/y; break; 45 case IR_DIV - IR_ADD: return x/y; break;
86 case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break; 46 case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break;
87 case IR_POW - IR_ADD: return lj_vm_pow(x, y); break; 47 case IR_POW - IR_ADD: return pow(x, y); break;
88 case IR_NEG - IR_ADD: return -x; break; 48 case IR_NEG - IR_ADD: return -x; break;
89 case IR_ABS - IR_ADD: return fabs(x); break; 49 case IR_ABS - IR_ADD: return fabs(x); break;
90#if LJ_HASJIT 50#if LJ_HASJIT
diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc
index 636619fd..770c1602 100644
--- a/src/vm_arm.dasc
+++ b/src/vm_arm.dasc
@@ -1477,11 +1477,11 @@ static void build_subroutines(BuildCtx *ctx)
1477 |.endif 1477 |.endif
1478 |.endmacro 1478 |.endmacro
1479 | 1479 |
1480 |.macro math_extern2, name, func 1480 |.macro math_extern2, func
1481 |.if HFABI 1481 |.if HFABI
1482 | .ffunc_dd math_ .. name 1482 | .ffunc_dd math_ .. func
1483 |.else 1483 |.else
1484 | .ffunc_nn math_ .. name 1484 | .ffunc_nn math_ .. func
1485 |.endif 1485 |.endif
1486 | .IOS mov RA, BASE 1486 | .IOS mov RA, BASE
1487 | bl extern func 1487 | bl extern func
@@ -1492,9 +1492,6 @@ static void build_subroutines(BuildCtx *ctx)
1492 | b ->fff_restv 1492 | b ->fff_restv
1493 |.endif 1493 |.endif
1494 |.endmacro 1494 |.endmacro
1495 |.macro math_extern2, func
1496 | math_extern2 func, func
1497 |.endmacro
1498 | 1495 |
1499 |.if FPU 1496 |.if FPU
1500 | .ffunc_d math_sqrt 1497 | .ffunc_d math_sqrt
@@ -1540,7 +1537,7 @@ static void build_subroutines(BuildCtx *ctx)
1540 | math_extern sinh 1537 | math_extern sinh
1541 | math_extern cosh 1538 | math_extern cosh
1542 | math_extern tanh 1539 | math_extern tanh
1543 | math_extern2 pow, lj_vm_pow 1540 | math_extern2 pow
1544 | math_extern2 atan2 1541 | math_extern2 atan2
1545 | math_extern2 fmod 1542 | math_extern2 fmod
1546 | 1543 |
@@ -3206,7 +3203,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3206 break; 3203 break;
3207 case BC_POW: 3204 case BC_POW:
3208 | // NYI: (partial) integer arithmetic. 3205 | // NYI: (partial) integer arithmetic.
3209 | ins_arithfp extern, extern lj_vm_pow 3206 | ins_arithfp extern, extern pow
3210 break; 3207 break;
3211 3208
3212 case BC_CAT: 3209 case BC_CAT:
diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
index 7ef9ffba..f5f1b5f1 100644
--- a/src/vm_arm64.dasc
+++ b/src/vm_arm64.dasc
@@ -1387,14 +1387,11 @@ static void build_subroutines(BuildCtx *ctx)
1387 | b ->fff_resn 1387 | b ->fff_resn
1388 |.endmacro 1388 |.endmacro
1389 | 1389 |
1390 |.macro math_extern2, name, func 1390 |.macro math_extern2, func
1391 | .ffunc_nn math_ .. name 1391 | .ffunc_nn math_ .. func
1392 | bl extern func 1392 | bl extern func
1393 | b ->fff_resn 1393 | b ->fff_resn
1394 |.endmacro 1394 |.endmacro
1395 |.macro math_extern2, func
1396 | math_extern2 func, func
1397 |.endmacro
1398 | 1395 |
1399 |.ffunc_n math_sqrt 1396 |.ffunc_n math_sqrt
1400 | fsqrt d0, d0 1397 | fsqrt d0, d0
@@ -1423,7 +1420,7 @@ static void build_subroutines(BuildCtx *ctx)
1423 | math_extern sinh 1420 | math_extern sinh
1424 | math_extern cosh 1421 | math_extern cosh
1425 | math_extern tanh 1422 | math_extern tanh
1426 | math_extern2 pow, lj_vm_pow 1423 | math_extern2 pow
1427 | math_extern2 atan2 1424 | math_extern2 atan2
1428 | math_extern2 fmod 1425 | math_extern2 fmod
1429 | 1426 |
@@ -2677,7 +2674,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2677 | ins_arithload FARG1, FARG2 2674 | ins_arithload FARG1, FARG2
2678 | ins_arithfallback ins_arithcheck_num 2675 | ins_arithfallback ins_arithcheck_num
2679 |.if "fpins" == "fpow" 2676 |.if "fpins" == "fpow"
2680 | bl extern lj_vm_pow 2677 | bl extern pow
2681 |.else 2678 |.else
2682 | fpins FARG1, FARG1, FARG2 2679 | fpins FARG1, FARG1, FARG2
2683 |.endif 2680 |.endif
diff --git a/src/vm_mips.dasc b/src/vm_mips.dasc
index cf791f74..34645bf1 100644
--- a/src/vm_mips.dasc
+++ b/src/vm_mips.dasc
@@ -1623,17 +1623,14 @@ static void build_subroutines(BuildCtx *ctx)
1623 |. nop 1623 |. nop
1624 |.endmacro 1624 |.endmacro
1625 | 1625 |
1626 |.macro math_extern2, name, func 1626 |.macro math_extern2, func
1627 | .ffunc_nn math_ .. name 1627 | .ffunc_nn math_ .. func
1628 |. load_got func 1628 |. load_got func
1629 | call_extern 1629 | call_extern
1630 |. nop 1630 |. nop
1631 | b ->fff_resn 1631 | b ->fff_resn
1632 |. nop 1632 |. nop
1633 |.endmacro 1633 |.endmacro
1634 |.macro math_extern2, func
1635 | math_extern2 func, func
1636 |.endmacro
1637 | 1634 |
1638 |// TODO: Return integer type if result is integer (own sf implementation). 1635 |// TODO: Return integer type if result is integer (own sf implementation).
1639 |.macro math_round, func 1636 |.macro math_round, func
@@ -1687,7 +1684,7 @@ static void build_subroutines(BuildCtx *ctx)
1687 | math_extern sinh 1684 | math_extern sinh
1688 | math_extern cosh 1685 | math_extern cosh
1689 | math_extern tanh 1686 | math_extern tanh
1690 | math_extern2 pow, lj_vm_pow 1687 | math_extern2 pow
1691 | math_extern2 atan2 1688 | math_extern2 atan2
1692 | math_extern2 fmod 1689 | math_extern2 fmod
1693 | 1690 |
@@ -3692,7 +3689,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3692 | sltiu AT, SFARG1HI, LJ_TISNUM 3689 | sltiu AT, SFARG1HI, LJ_TISNUM
3693 | sltiu TMP0, SFARG2HI, LJ_TISNUM 3690 | sltiu TMP0, SFARG2HI, LJ_TISNUM
3694 | and AT, AT, TMP0 3691 | and AT, AT, TMP0
3695 | load_got lj_vm_pow 3692 | load_got pow
3696 | beqz AT, ->vmeta_arith 3693 | beqz AT, ->vmeta_arith
3697 |. addu RA, BASE, RA 3694 |. addu RA, BASE, RA
3698 |.if FPU 3695 |.if FPU
diff --git a/src/vm_mips64.dasc b/src/vm_mips64.dasc
index 3b916379..651bc42e 100644
--- a/src/vm_mips64.dasc
+++ b/src/vm_mips64.dasc
@@ -1667,17 +1667,14 @@ static void build_subroutines(BuildCtx *ctx)
1667 |. nop 1667 |. nop
1668 |.endmacro 1668 |.endmacro
1669 | 1669 |
1670 |.macro math_extern2, name, func 1670 |.macro math_extern2, func
1671 | .ffunc_nn math_ .. name 1671 | .ffunc_nn math_ .. func
1672 |. load_got func 1672 |. load_got func
1673 | call_extern 1673 | call_extern
1674 |. nop 1674 |. nop
1675 | b ->fff_resn 1675 | b ->fff_resn
1676 |. nop 1676 |. nop
1677 |.endmacro 1677 |.endmacro
1678 |.macro math_extern2, func
1679 | math_extern2 func, func
1680 |.endmacro
1681 | 1678 |
1682 |// TODO: Return integer type if result is integer (own sf implementation). 1679 |// TODO: Return integer type if result is integer (own sf implementation).
1683 |.macro math_round, func 1680 |.macro math_round, func
@@ -1731,7 +1728,7 @@ static void build_subroutines(BuildCtx *ctx)
1731 | math_extern sinh 1728 | math_extern sinh
1732 | math_extern cosh 1729 | math_extern cosh
1733 | math_extern tanh 1730 | math_extern tanh
1734 | math_extern2 pow, lj_vm_pow 1731 | math_extern2 pow
1735 | math_extern2 atan2 1732 | math_extern2 atan2
1736 | math_extern2 fmod 1733 | math_extern2 fmod
1737 | 1734 |
@@ -3918,7 +3915,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3918 | sltiu TMP0, TMP0, LJ_TISNUM 3915 | sltiu TMP0, TMP0, LJ_TISNUM
3919 | sltiu TMP1, TMP1, LJ_TISNUM 3916 | sltiu TMP1, TMP1, LJ_TISNUM
3920 | and AT, TMP0, TMP1 3917 | and AT, TMP0, TMP1
3921 | load_got lj_vm_pow 3918 | load_got pow
3922 | beqz AT, ->vmeta_arith 3919 | beqz AT, ->vmeta_arith
3923 |. daddu RA, BASE, RA 3920 |. daddu RA, BASE, RA
3924 |.if FPU 3921 |.if FPU
diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc
index cc4d56d7..3cad37d2 100644
--- a/src/vm_ppc.dasc
+++ b/src/vm_ppc.dasc
@@ -2012,14 +2012,11 @@ static void build_subroutines(BuildCtx *ctx)
2012 | b ->fff_resn 2012 | b ->fff_resn
2013 |.endmacro 2013 |.endmacro
2014 | 2014 |
2015 |.macro math_extern2, name, func 2015 |.macro math_extern2, func
2016 | .ffunc_nn math_ .. name 2016 | .ffunc_nn math_ .. func
2017 | blex func 2017 | blex func
2018 | b ->fff_resn 2018 | b ->fff_resn
2019 |.endmacro 2019 |.endmacro
2020 |.macro math_extern2, func
2021 | math_extern2 func, func
2022 |.endmacro
2023 | 2020 |
2024 |.macro math_round, func 2021 |.macro math_round, func
2025 | .ffunc_1 math_ .. func 2022 | .ffunc_1 math_ .. func
@@ -2144,7 +2141,7 @@ static void build_subroutines(BuildCtx *ctx)
2144 | math_extern sinh 2141 | math_extern sinh
2145 | math_extern cosh 2142 | math_extern cosh
2146 | math_extern tanh 2143 | math_extern tanh
2147 | math_extern2 pow, lj_vm_pow 2144 | math_extern2 pow
2148 | math_extern2 atan2 2145 | math_extern2 atan2
2149 | math_extern2 fmod 2146 | math_extern2 fmod
2150 | 2147 |
@@ -4142,7 +4139,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
4142 | checknum cr1, CARG3 4139 | checknum cr1, CARG3
4143 | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt 4140 | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
4144 | bge ->vmeta_arith_vv 4141 | bge ->vmeta_arith_vv
4145 | blex lj_vm_pow 4142 | blex pow
4146 | ins_next1 4143 | ins_next1
4147 |.if FPU 4144 |.if FPU
4148 | stfdx FARG1, BASE, RA 4145 | stfdx FARG1, BASE, RA
diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc
index 4aa8589c..8dd48b84 100644
--- a/src/vm_x64.dasc
+++ b/src/vm_x64.dasc
@@ -1755,16 +1755,13 @@ static void build_subroutines(BuildCtx *ctx)
1755 | jmp ->fff_resxmm0 1755 | jmp ->fff_resxmm0
1756 |.endmacro 1756 |.endmacro
1757 | 1757 |
1758 |.macro math_extern2, name, func 1758 |.macro math_extern2, func
1759 | .ffunc_nn math_ .. name 1759 | .ffunc_nn math_ .. func
1760 | mov RB, BASE 1760 | mov RB, BASE
1761 | call extern func 1761 | call extern func
1762 | mov BASE, RB 1762 | mov BASE, RB
1763 | jmp ->fff_resxmm0 1763 | jmp ->fff_resxmm0
1764 |.endmacro 1764 |.endmacro
1765 |.macro math_extern2, func
1766 | math_extern2 func, func
1767 |.endmacro
1768 | 1765 |
1769 | math_extern log10 1766 | math_extern log10
1770 | math_extern exp 1767 | math_extern exp
@@ -1777,7 +1774,7 @@ static void build_subroutines(BuildCtx *ctx)
1777 | math_extern sinh 1774 | math_extern sinh
1778 | math_extern cosh 1775 | math_extern cosh
1779 | math_extern tanh 1776 | math_extern tanh
1780 | math_extern2 pow, lj_vm_pow 1777 | math_extern2 pow
1781 | math_extern2 atan2 1778 | math_extern2 atan2
1782 | math_extern2 fmod 1779 | math_extern2 fmod
1783 | 1780 |
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc
index 36af852d..de12ac64 100644
--- a/src/vm_x86.dasc
+++ b/src/vm_x86.dasc
@@ -2138,8 +2138,8 @@ static void build_subroutines(BuildCtx *ctx)
2138 | jmp ->fff_resfp 2138 | jmp ->fff_resfp
2139 |.endmacro 2139 |.endmacro
2140 | 2140 |
2141 |.macro math_extern2, name, func 2141 |.macro math_extern2, func
2142 | .ffunc_nnsse math_ .. name 2142 | .ffunc_nnsse math_ .. func
2143 |.if not X64 2143 |.if not X64
2144 | movsd FPARG1, xmm0 2144 | movsd FPARG1, xmm0
2145 | movsd FPARG3, xmm1 2145 | movsd FPARG3, xmm1
@@ -2149,9 +2149,6 @@ static void build_subroutines(BuildCtx *ctx)
2149 | mov BASE, RB 2149 | mov BASE, RB
2150 | jmp ->fff_resfp 2150 | jmp ->fff_resfp
2151 |.endmacro 2151 |.endmacro
2152 |.macro math_extern2, func
2153 | math_extern2 func, func
2154 |.endmacro
2155 | 2152 |
2156 | math_extern log10 2153 | math_extern log10
2157 | math_extern exp 2154 | math_extern exp
@@ -2164,7 +2161,7 @@ static void build_subroutines(BuildCtx *ctx)
2164 | math_extern sinh 2161 | math_extern sinh
2165 | math_extern cosh 2162 | math_extern cosh
2166 | math_extern tanh 2163 | math_extern tanh
2167 | math_extern2 pow, lj_vm_pow 2164 | math_extern2 pow
2168 | math_extern2 atan2 2165 | math_extern2 atan2
2169 | math_extern2 fmod 2166 | math_extern2 fmod
2170 | 2167 |
@@ -3922,7 +3919,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3922 | movsd FPARG1, xmm0 3919 | movsd FPARG1, xmm0
3923 | movsd FPARG3, xmm1 3920 | movsd FPARG3, xmm1
3924 |.endif 3921 |.endif
3925 | call extern lj_vm_pow 3922 | call extern pow
3926 | movzx RA, PC_RA 3923 | movzx RA, PC_RA
3927 | mov BASE, RB 3924 | mov BASE, RB
3928 |.if X64 3925 |.if X64