aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2026-01-09 18:46:32 +0100
committerMike Pall <mike>2026-01-09 18:46:32 +0100
commit707c12bf00dafdfd3899b1a6c36435dbbf6c7022 (patch)
tree0b1d335e5c4700fd8b5a4955d3365c8cdf4bc646
parent3015b6187e00bf39b4b263a1006654600b554eb3 (diff)
downloadluajit-v2.1.tar.gz
luajit-v2.1.tar.bz2
luajit-v2.1.zip
DUALNUM: Improve/fix edge cases of unary minus.HEADv2.1
Thanks to Sergey Kaplun. #1422 #1418
-rw-r--r--src/lj_opt_narrow.c5
-rw-r--r--src/vm_arm.dasc5
-rw-r--r--src/vm_arm64.dasc2
-rw-r--r--src/vm_mips.dasc6
-rw-r--r--src/vm_mips64.dasc6
-rw-r--r--src/vm_ppc.dasc7
-rw-r--r--src/vm_x64.dasc4
-rw-r--r--src/vm_x86.dasc5
8 files changed, 33 insertions, 7 deletions
diff --git a/src/lj_opt_narrow.c b/src/lj_opt_narrow.c
index db5e8b5b..593bec39 100644
--- a/src/lj_opt_narrow.c
+++ b/src/lj_opt_narrow.c
@@ -545,10 +545,9 @@ TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc)
545 rc = conv_str_tonum(J, rc, vc); 545 rc = conv_str_tonum(J, rc, vc);
546 if (tref_isinteger(rc)) { 546 if (tref_isinteger(rc)) {
547 uint32_t k = (uint32_t)numberVint(vc); 547 uint32_t k = (uint32_t)numberVint(vc);
548 if ((tvisint(vc) || k != 0) && k != 0x80000000u) { 548 if (k != 0 && k != 0x80000000u) {
549 TRef zero = lj_ir_kint(J, 0); 549 TRef zero = lj_ir_kint(J, 0);
550 if (!tvisint(vc)) 550 emitir(IRTGI(IR_NE), rc, zero);
551 emitir(IRTGI(IR_NE), rc, zero);
552 return emitir(IRTGI(IR_SUBOV), zero, rc); 551 return emitir(IRTGI(IR_SUBOV), zero, rc);
553 } 552 }
554 rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT); 553 rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);
diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc
index d99cdaca..d67dbffc 100644
--- a/src/vm_arm.dasc
+++ b/src/vm_arm.dasc
@@ -3125,13 +3125,16 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3125 | bhi ->vmeta_unm 3125 | bhi ->vmeta_unm
3126 | eorne CARG2, CARG2, #0x80000000 3126 | eorne CARG2, CARG2, #0x80000000
3127 | bne >5 3127 | bne >5
3128 | rsbseq CARG1, CARG1, #0 3128 | rsbs CARG1, CARG1, #0
3129 | ldrdeq CARG12, >8
3129 | ldrdvs CARG12, >9 3130 | ldrdvs CARG12, >9
3130 |5: 3131 |5:
3131 | strd CARG12, [BASE, RA] 3132 | strd CARG12, [BASE, RA]
3132 | ins_next3 3133 | ins_next3
3133 | 3134 |
3134 |.align 8 3135 |.align 8
3136 |8:
3137 | .long 0x00000000, 0x80000000 // -0.
3135 |9: 3138 |9:
3136 | .long 0x00000000, 0x41e00000 // 2^31. 3139 | .long 0x00000000, 0x41e00000 // 2^31.
3137 break; 3140 break;
diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
index a0789efb..be8b76a7 100644
--- a/src/vm_arm64.dasc
+++ b/src/vm_arm64.dasc
@@ -2687,6 +2687,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2687 | movz CARG3, #0x41e0, lsl #48 // 2^31. 2687 | movz CARG3, #0x41e0, lsl #48 // 2^31.
2688 | add_TISNUM TMP0, TMP0 2688 | add_TISNUM TMP0, TMP0
2689 | csel TMP0, TMP0, CARG3, vc 2689 | csel TMP0, TMP0, CARG3, vc
2690 | movz CARG3, #0x8000, lsl #48 // -0.
2691 | csel TMP0, TMP0, CARG3, ne
2690 |5: 2692 |5:
2691 | str TMP0, [BASE, RA, lsl #3] 2693 | str TMP0, [BASE, RA, lsl #3]
2692 | ins_next 2694 | ins_next
diff --git a/src/vm_mips.dasc b/src/vm_mips.dasc
index 5063e7c6..9a39edd6 100644
--- a/src/vm_mips.dasc
+++ b/src/vm_mips.dasc
@@ -3566,7 +3566,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3566 | addu RA, BASE, RA 3566 | addu RA, BASE, RA
3567 | bne SFARG1HI, TISNUM, >2 3567 | bne SFARG1HI, TISNUM, >2
3568 |. lw SFARG1LO, LO(RB) 3568 |. lw SFARG1LO, LO(RB)
3569 | lui TMP1, 0x8000 3569 | beqz SFARG1LO, >3
3570 |. lui TMP1, 0x8000
3570 | beq SFARG1LO, TMP1, ->vmeta_unm // Meta handler deals with -2^31. 3571 | beq SFARG1LO, TMP1, ->vmeta_unm // Meta handler deals with -2^31.
3571 |. negu SFARG1LO, SFARG1LO 3572 |. negu SFARG1LO, SFARG1LO
3572 |1: 3573 |1:
@@ -3580,6 +3581,9 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3580 |. lui TMP1, 0x8000 3581 |. lui TMP1, 0x8000
3581 | b <1 3582 | b <1
3582 |. xor SFARG1HI, SFARG1HI, TMP1 3583 |. xor SFARG1HI, SFARG1HI, TMP1
3584 |3:
3585 | b <1
3586 |. lui SFARG1HI, 0x8000 // -0.
3583 break; 3587 break;
3584 case BC_LEN: 3588 case BC_LEN:
3585 | // RA = dst*8, RD = src*8 3589 | // RA = dst*8, RD = src*8
diff --git a/src/vm_mips64.dasc b/src/vm_mips64.dasc
index 8365da8e..310269ce 100644
--- a/src/vm_mips64.dasc
+++ b/src/vm_mips64.dasc
@@ -3804,7 +3804,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3804 | sextw CARG1, CARG1 3804 | sextw CARG1, CARG1
3805 | beq CARG1, TMP1, ->vmeta_unm // Meta handler deals with -2^31. 3805 | beq CARG1, TMP1, ->vmeta_unm // Meta handler deals with -2^31.
3806 |. negu CARG1, CARG1 3806 |. negu CARG1, CARG1
3807 | zextw CARG1, CARG1 3807 | beqz CARG1, >3
3808 |. zextw CARG1, CARG1
3808 | settp CARG1, TISNUM 3809 | settp CARG1, TISNUM
3809 |1: 3810 |1:
3810 | ins_next1 3811 | ins_next1
@@ -3816,6 +3817,9 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3816 |. dsll TMP1, TMP1, 32 3817 |. dsll TMP1, TMP1, 32
3817 | b <1 3818 | b <1
3818 |. xor CARG1, CARG1, TMP1 3819 |. xor CARG1, CARG1, TMP1
3820 |3:
3821 | b <1
3822 |. dsll CARG1, TMP1, 32
3819 break; 3823 break;
3820 case BC_LEN: 3824 case BC_LEN:
3821 | // RA = dst*8, RD = src*8 3825 | // RA = dst*8, RD = src*8
diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc
index 37be772d..440bf1c4 100644
--- a/src/vm_ppc.dasc
+++ b/src/vm_ppc.dasc
@@ -3962,11 +3962,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3962 | bne >5 3962 | bne >5
3963 |.if GPR64 3963 |.if GPR64
3964 | lus TMP2, 0x8000 3964 | lus TMP2, 0x8000
3965 | neg TMP0, TMP0 3965 | neg. TMP0, TMP0
3966 | beq >8
3966 | cmplw TMP0, TMP2 3967 | cmplw TMP0, TMP2
3967 | beq >4 3968 | beq >4
3968 |.else 3969 |.else
3969 | nego. TMP0, TMP0 3970 | nego. TMP0, TMP0
3971 | beq >8
3970 | bso >4 3972 | bso >4
3971 |1: 3973 |1:
3972 |.endif 3974 |.endif
@@ -3993,6 +3995,9 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3993 | stw TMP0, 4(RA) 3995 | stw TMP0, 4(RA)
3994 |.if DUALNUM 3996 |.if DUALNUM
3995 | b <3 3997 | b <3
3998 |8:
3999 | lus TMP1, 0x8000 // -0.
4000 | b <7
3996 |.else 4001 |.else
3997 | ins_next2 4002 | ins_next2
3998 |.endif 4003 |.endif
diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc
index a2fa9bfa..9e0f58fd 100644
--- a/src/vm_x64.dasc
+++ b/src/vm_x64.dasc
@@ -3266,11 +3266,15 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3266 |.if DUALNUM 3266 |.if DUALNUM
3267 | checkint RB, >5 3267 | checkint RB, >5
3268 | neg RBd 3268 | neg RBd
3269 | jz >3
3269 | jo >4 3270 | jo >4
3270 | setint RB 3271 | setint RB
3271 |9: 3272 |9:
3272 | mov [BASE+RA*8], RB 3273 | mov [BASE+RA*8], RB
3273 | ins_next 3274 | ins_next
3275 |3:
3276 | mov64 RB, U64x(80000000,00000000) // -0.
3277 | jmp <9
3274 |4: 3278 |4:
3275 | mov64 RB, U64x(41e00000,00000000) // 2^31. 3279 | mov64 RB, U64x(41e00000,00000000) // 2^31.
3276 | jmp <9 3280 | jmp <9
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc
index d7d82b32..7e3d68a0 100644
--- a/src/vm_x86.dasc
+++ b/src/vm_x86.dasc
@@ -3856,11 +3856,16 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
3856 | checkint RD, >5 3856 | checkint RD, >5
3857 | mov RB, [BASE+RD*8] 3857 | mov RB, [BASE+RD*8]
3858 | neg RB 3858 | neg RB
3859 | jz >3
3859 | jo >4 3860 | jo >4
3860 | mov dword [BASE+RA*8+4], LJ_TISNUM 3861 | mov dword [BASE+RA*8+4], LJ_TISNUM
3862 |8:
3861 | mov dword [BASE+RA*8], RB 3863 | mov dword [BASE+RA*8], RB
3862 |9: 3864 |9:
3863 | ins_next 3865 | ins_next
3866 |3:
3867 | mov dword [BASE+RA*8+4], 0x80000000 // -0.
3868 | jmp <8
3864 |4: 3869 |4:
3865 | mov dword [BASE+RA*8+4], 0x41e00000 // 2^31. 3870 | mov dword [BASE+RA*8+4], 0x41e00000 // 2^31.
3866 | mov dword [BASE+RA*8], 0 3871 | mov dword [BASE+RA*8], 0