Skip to content

Commit 5655be4

Browse files
author
Mike Pall
committed
Cleanup math function compilation and fix inconsistencies.
1 parent c5b8e91 commit 5655be4

14 files changed

+48
-65
lines changed

src/lib_math.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ LJLIB_ASM(math_sqrt) LJLIB_REC(math_unary IRFPM_SQRT)
3333
lj_lib_checknum(L, 1);
3434
return FFH_RETRY;
3535
}
36-
LJLIB_ASM_(math_log10) LJLIB_REC(math_unary IRFPM_LOG10)
37-
LJLIB_ASM_(math_exp) LJLIB_REC(math_unary IRFPM_EXP)
38-
LJLIB_ASM_(math_sin) LJLIB_REC(math_unary IRFPM_SIN)
39-
LJLIB_ASM_(math_cos) LJLIB_REC(math_unary IRFPM_COS)
40-
LJLIB_ASM_(math_tan) LJLIB_REC(math_unary IRFPM_TAN)
41-
LJLIB_ASM_(math_asin) LJLIB_REC(math_atrig FF_math_asin)
42-
LJLIB_ASM_(math_acos) LJLIB_REC(math_atrig FF_math_acos)
43-
LJLIB_ASM_(math_atan) LJLIB_REC(math_atrig FF_math_atan)
44-
LJLIB_ASM_(math_sinh) LJLIB_REC(math_htrig IRCALL_sinh)
45-
LJLIB_ASM_(math_cosh) LJLIB_REC(math_htrig IRCALL_cosh)
46-
LJLIB_ASM_(math_tanh) LJLIB_REC(math_htrig IRCALL_tanh)
36+
LJLIB_ASM_(math_log10) LJLIB_REC(math_call IRCALL_log10)
37+
LJLIB_ASM_(math_exp) LJLIB_REC(math_call IRCALL_exp)
38+
LJLIB_ASM_(math_sin) LJLIB_REC(math_call IRCALL_sin)
39+
LJLIB_ASM_(math_cos) LJLIB_REC(math_call IRCALL_cos)
40+
LJLIB_ASM_(math_tan) LJLIB_REC(math_call IRCALL_tan)
41+
LJLIB_ASM_(math_asin) LJLIB_REC(math_call IRCALL_asin)
42+
LJLIB_ASM_(math_acos) LJLIB_REC(math_call IRCALL_acos)
43+
LJLIB_ASM_(math_atan) LJLIB_REC(math_call IRCALL_atan)
44+
LJLIB_ASM_(math_sinh) LJLIB_REC(math_call IRCALL_sinh)
45+
LJLIB_ASM_(math_cosh) LJLIB_REC(math_call IRCALL_cosh)
46+
LJLIB_ASM_(math_tanh) LJLIB_REC(math_call IRCALL_tanh)
4747
LJLIB_ASM_(math_frexp)
4848
LJLIB_ASM_(math_modf)
4949

src/lj_asm.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,14 +1657,13 @@ static void asm_ir(ASMState *as, IRIns *ir)
16571657
case IR_NEG: asm_neg(as, ir); break;
16581658
#if LJ_SOFTFP32
16591659
case IR_DIV: case IR_POW: case IR_ABS:
1660-
case IR_ATAN2: case IR_LDEXP: case IR_FPMATH: case IR_TOBIT:
1660+
case IR_LDEXP: case IR_FPMATH: case IR_TOBIT:
16611661
lua_assert(0); /* Unused for LJ_SOFTFP32. */
16621662
break;
16631663
#else
16641664
case IR_DIV: asm_div(as, ir); break;
16651665
case IR_POW: asm_pow(as, ir); break;
16661666
case IR_ABS: asm_abs(as, ir); break;
1667-
case IR_ATAN2: asm_atan2(as, ir); break;
16681667
case IR_LDEXP: asm_ldexp(as, ir); break;
16691668
case IR_FPMATH: asm_fpmath(as, ir); break;
16701669
case IR_TOBIT: asm_tobit(as, ir); break;
@@ -2158,11 +2157,6 @@ static void asm_setup_regsp(ASMState *as)
21582157
as->modset = RSET_SCRATCH;
21592158
break;
21602159
#if !LJ_SOFTFP
2161-
case IR_ATAN2:
2162-
#if LJ_TARGET_X86
2163-
if (as->evenspill < 4) /* Leave room to call atan2(). */
2164-
as->evenspill = 4;
2165-
#endif
21662160
#if !LJ_TARGET_X86ORX64
21672161
case IR_LDEXP:
21682162
#endif

src/lj_asm_arm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,6 @@ static void asm_mul(ASMState *as, IRIns *ir)
15101510
#define asm_div(as, ir) asm_fparith(as, ir, ARMI_VDIV_D)
15111511
#define asm_pow(as, ir) asm_callid(as, ir, IRCALL_lj_vm_powi)
15121512
#define asm_abs(as, ir) asm_fpunary(as, ir, ARMI_VABS_D)
1513-
#define asm_atan2(as, ir) asm_callid(as, ir, IRCALL_atan2)
15141513
#define asm_ldexp(as, ir) asm_callid(as, ir, IRCALL_ldexp)
15151514
#endif
15161515

src/lj_asm_arm64.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,6 @@ static void asm_pow(ASMState *as, IRIns *ir)
14551455
#define asm_mulov(as, ir) asm_mul(as, ir)
14561456

14571457
#define asm_abs(as, ir) asm_fpunary(as, ir, A64I_FABS)
1458-
#define asm_atan2(as, ir) asm_callid(as, ir, IRCALL_atan2)
14591458
#define asm_ldexp(as, ir) asm_callid(as, ir, IRCALL_ldexp)
14601459

14611460
static void asm_mod(ASMState *as, IRIns *ir)

src/lj_asm_mips.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,6 @@ static void asm_abs(ASMState *as, IRIns *ir)
18381838
}
18391839
#endif
18401840

1841-
#define asm_atan2(as, ir) asm_callid(as, ir, IRCALL_atan2)
18421841
#define asm_ldexp(as, ir) asm_callid(as, ir, IRCALL_ldexp)
18431842

18441843
static void asm_arithov(ASMState *as, IRIns *ir)

src/lj_asm_ppc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,6 @@ static void asm_neg(ASMState *as, IRIns *ir)
13871387
}
13881388

13891389
#define asm_abs(as, ir) asm_fpunary(as, ir, PPCI_FABS)
1390-
#define asm_atan2(as, ir) asm_callid(as, ir, IRCALL_atan2)
13911390
#define asm_ldexp(as, ir) asm_callid(as, ir, IRCALL_ldexp)
13921391

13931392
static void asm_arithov(ASMState *as, IRIns *ir, PPCIns pi)

src/lj_asm_x86.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,8 +1957,6 @@ static void asm_fpmath(ASMState *as, IRIns *ir)
19571957
}
19581958
}
19591959

1960-
#define asm_atan2(as, ir) asm_callid(as, ir, IRCALL_atan2)
1961-
19621960
static void asm_ldexp(ASMState *as, IRIns *ir)
19631961
{
19641962
int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */

src/lj_ffrecord.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static void LJ_FASTCALL recff_math_atan2(jit_State *J, RecordFFData *rd)
563563
{
564564
TRef tr = lj_ir_tonum(J, J->base[0]);
565565
TRef tr2 = lj_ir_tonum(J, J->base[1]);
566-
J->base[0] = emitir(IRTN(IR_ATAN2), tr, tr2);
566+
J->base[0] = lj_ir_call(J, IRCALL_atan2, tr, tr2);
567567
UNUSED(rd);
568568
}
569569

@@ -580,22 +580,7 @@ static void LJ_FASTCALL recff_math_ldexp(jit_State *J, RecordFFData *rd)
580580
UNUSED(rd);
581581
}
582582

583-
/* Record math.asin, math.acos, math.atan. */
584-
static void LJ_FASTCALL recff_math_atrig(jit_State *J, RecordFFData *rd)
585-
{
586-
TRef y = lj_ir_tonum(J, J->base[0]);
587-
TRef x = lj_ir_knum_one(J);
588-
uint32_t ffid = rd->data;
589-
if (ffid != FF_math_atan) {
590-
TRef tmp = emitir(IRTN(IR_MUL), y, y);
591-
tmp = emitir(IRTN(IR_SUB), x, tmp);
592-
tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_SQRT);
593-
if (ffid == FF_math_asin) { x = tmp; } else { x = y; y = tmp; }
594-
}
595-
J->base[0] = emitir(IRTN(IR_ATAN2), y, x);
596-
}
597-
598-
static void LJ_FASTCALL recff_math_htrig(jit_State *J, RecordFFData *rd)
583+
static void LJ_FASTCALL recff_math_call(jit_State *J, RecordFFData *rd)
599584
{
600585
TRef tr = lj_ir_tonum(J, J->base[0]);
601586
J->base[0] = emitir(IRTN(IR_CALLN), tr, rd->data);

src/lj_ir.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
_(NEG, N , ref, ref) \
7676
\
7777
_(ABS, N , ref, ref) \
78-
_(ATAN2, N , ref, ref) \
7978
_(LDEXP, N , ref, ref) \
8079
_(MIN, C , ref, ref) \
8180
_(MAX, C , ref, ref) \
@@ -178,8 +177,7 @@ LJ_STATIC_ASSERT((int)IR_XLOAD + IRDELTA_L2S == (int)IR_XSTORE);
178177
/* FPMATH sub-functions. ORDER FPM. */
179178
#define IRFPMDEF(_) \
180179
_(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \
181-
_(SQRT) _(EXP) _(EXP2) _(LOG) _(LOG2) _(LOG10) \
182-
_(SIN) _(COS) _(TAN) \
180+
_(SQRT) _(EXP2) _(LOG) _(LOG2) \
183181
_(OTHER)
184182

185183
typedef enum {

src/lj_ircall.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct CCallInfo {
2121

2222
#define CCI_OTSHIFT 16
2323
#define CCI_OPTYPE(ci) ((ci)->flags >> CCI_OTSHIFT) /* Get op/type. */
24+
#define CCI_TYPE(ci) (((ci)->flags>>CCI_OTSHIFT) & IRT_TYPE)
2425
#define CCI_OPSHIFT 24
2526
#define CCI_OP(ci) ((ci)->flags >> CCI_OPSHIFT) /* Get op. */
2627

@@ -172,6 +173,14 @@ typedef struct CCallInfo {
172173
_(ANY, lj_mem_newgco, 2, FS, PGC, CCI_L) \
173174
_(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64) \
174175
_(ANY, lj_vm_modi, 2, FN, INT, 0) \
176+
_(ANY, log10, 1, N, NUM, XA_FP) \
177+
_(ANY, exp, 1, N, NUM, XA_FP) \
178+
_(ANY, sin, 1, N, NUM, XA_FP) \
179+
_(ANY, cos, 1, N, NUM, XA_FP) \
180+
_(ANY, tan, 1, N, NUM, XA_FP) \
181+
_(ANY, asin, 1, N, NUM, XA_FP) \
182+
_(ANY, acos, 1, N, NUM, XA_FP) \
183+
_(ANY, atan, 1, N, NUM, XA_FP) \
175184
_(ANY, sinh, 1, N, NUM, XA_FP) \
176185
_(ANY, cosh, 1, N, NUM, XA_FP) \
177186
_(ANY, tanh, 1, N, NUM, XA_FP) \
@@ -183,14 +192,9 @@ typedef struct CCallInfo {
183192
_(FPMATH, lj_vm_ceil, 1, N, NUM, XA_FP) \
184193
_(FPMATH, lj_vm_trunc, 1, N, NUM, XA_FP) \
185194
_(FPMATH, sqrt, 1, N, NUM, XA_FP) \
186-
_(ANY, exp, 1, N, NUM, XA_FP) \
187195
_(ANY, lj_vm_exp2, 1, N, NUM, XA_FP) \
188196
_(ANY, log, 1, N, NUM, XA_FP) \
189197
_(ANY, lj_vm_log2, 1, N, NUM, XA_FP) \
190-
_(ANY, log10, 1, N, NUM, XA_FP) \
191-
_(ANY, sin, 1, N, NUM, XA_FP) \
192-
_(ANY, cos, 1, N, NUM, XA_FP) \
193-
_(ANY, tan, 1, N, NUM, XA_FP) \
194198
_(ANY, lj_vm_powi, 2, N, NUM, XA_FP) \
195199
_(ANY, pow, 2, N, NUM, XA2_FP) \
196200
_(ANY, atan2, 2, N, NUM, XA2_FP) \

0 commit comments

Comments
 (0)