aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2021-07-19 16:33:13 +0200
committerMike Pall <mike>2021-07-19 16:33:13 +0200
commit3a0cf697306c995dbac9d26067686d65f77a2df2 (patch)
tree178d9fcc127cd4056babc5ac2d43d2d2b2269c84
parent6df650fe3fa0e06d9645524918a9935e3a282156 (diff)
downloadluajit-3a0cf697306c995dbac9d26067686d65f77a2df2.tar.gz
luajit-3a0cf697306c995dbac9d26067686d65f77a2df2.tar.bz2
luajit-3a0cf697306c995dbac9d26067686d65f77a2df2.zip
String buffers, part 3b: Change IR_BUFHDR op2 mode bits to mode.
Sponsored by fmad.io.
-rw-r--r--src/lj_asm.c22
-rw-r--r--src/lj_opt_fold.c10
2 files changed, 19 insertions, 13 deletions
diff --git a/src/lj_asm.c b/src/lj_asm.c
index ebcff43c..9dae2707 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -1149,24 +1149,30 @@ static void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode);
1149static void asm_bufhdr(ASMState *as, IRIns *ir) 1149static void asm_bufhdr(ASMState *as, IRIns *ir)
1150{ 1150{
1151 Reg sb = ra_dest(as, ir, RSET_GPR); 1151 Reg sb = ra_dest(as, ir, RSET_GPR);
1152 if ((ir->op2 & IRBUFHDR_APPEND)) { 1152 switch (ir->op2) {
1153 case IRBUFHDR_RESET: {
1154 Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));
1155 IRIns irbp;
1156 irbp.ot = IRT(0, IRT_PTR); /* Buffer data pointer type. */
1157 emit_storeofs(as, &irbp, tmp, sb, offsetof(SBuf, w));
1158 emit_loadofs(as, &irbp, tmp, sb, offsetof(SBuf, b));
1159 break;
1160 }
1161 case IRBUFHDR_APPEND: {
1153 /* Rematerialize const buffer pointer instead of likely spill. */ 1162 /* Rematerialize const buffer pointer instead of likely spill. */
1154 IRIns *irp = IR(ir->op1); 1163 IRIns *irp = IR(ir->op1);
1155 if (!(ra_hasreg(irp->r) || irp == ir-1 || 1164 if (!(ra_hasreg(irp->r) || irp == ir-1 ||
1156 (irp == ir-2 && !ra_used(ir-1)))) { 1165 (irp == ir-2 && !ra_used(ir-1)))) {
1157 while (!(irp->o == IR_BUFHDR && !(irp->op2 & IRBUFHDR_APPEND))) 1166 while (!(irp->o == IR_BUFHDR && irp->op2 == IRBUFHDR_RESET))
1158 irp = IR(irp->op1); 1167 irp = IR(irp->op1);
1159 if (irref_isk(irp->op1)) { 1168 if (irref_isk(irp->op1)) {
1160 ra_weak(as, ra_allocref(as, ir->op1, RSET_GPR)); 1169 ra_weak(as, ra_allocref(as, ir->op1, RSET_GPR));
1161 ir = irp; 1170 ir = irp;
1162 } 1171 }
1163 } 1172 }
1164 } else { 1173 break;
1165 Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); 1174 }
1166 IRIns irbp; 1175 default: lj_assertA(0, "bad BUFHDR op2 %d", ir->op2); break;
1167 irbp.ot = IRT(0, IRT_PTR); /* Buffer data pointer type. */
1168 emit_storeofs(as, &irbp, tmp, sb, offsetof(SBuf, w));
1169 emit_loadofs(as, &irbp, tmp, sb, offsetof(SBuf, b));
1170 } 1176 }
1171#if LJ_TARGET_X86ORX64 1177#if LJ_TARGET_X86ORX64
1172 ra_left(as, sb, ir->op1); 1178 ra_left(as, sb, ir->op1);
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c
index 9a41a5a4..06731c7a 100644
--- a/src/lj_opt_fold.c
+++ b/src/lj_opt_fold.c
@@ -586,11 +586,11 @@ LJFOLDF(bufput_append)
586{ 586{
587 /* New buffer, no other buffer op inbetween and same buffer? */ 587 /* New buffer, no other buffer op inbetween and same buffer? */
588 if ((J->flags & JIT_F_OPT_FWD) && 588 if ((J->flags & JIT_F_OPT_FWD) &&
589 !(fleft->op2 & IRBUFHDR_APPEND) && 589 fleft->op2 == IRBUFHDR_RESET &&
590 fleft->prev == fright->op2 && 590 fleft->prev == fright->op2 &&
591 fleft->op1 == IR(fright->op2)->op1) { 591 fleft->op1 == IR(fright->op2)->op1) {
592 IRRef ref = fins->op1; 592 IRRef ref = fins->op1;
593 IR(ref)->op2 = (fleft->op2 | IRBUFHDR_APPEND); /* Modify BUFHDR. */ 593 IR(ref)->op2 = IRBUFHDR_APPEND; /* Modify BUFHDR. */
594 IR(ref)->op1 = fright->op1; 594 IR(ref)->op1 = fright->op1;
595 return ref; 595 return ref;
596 } 596 }
@@ -626,14 +626,14 @@ LJFOLDF(bufstr_kfold_cse)
626 "bad buffer constructor IR op %d", fleft->o); 626 "bad buffer constructor IR op %d", fleft->o);
627 if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { 627 if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
628 if (fleft->o == IR_BUFHDR) { /* No put operations? */ 628 if (fleft->o == IR_BUFHDR) { /* No put operations? */
629 if (!(fleft->op2 & IRBUFHDR_APPEND)) /* Empty buffer? */ 629 if (fleft->op2 == IRBUFHDR_RESET) /* Empty buffer? */
630 return lj_ir_kstr(J, &J2G(J)->strempty); 630 return lj_ir_kstr(J, &J2G(J)->strempty);
631 fins->op1 = fleft->op1; 631 fins->op1 = fleft->op1;
632 fins->op2 = fleft->prev; /* Relies on checks in bufput_append. */ 632 fins->op2 = fleft->prev; /* Relies on checks in bufput_append. */
633 return CSEFOLD; 633 return CSEFOLD;
634 } else if (fleft->o == IR_BUFPUT) { 634 } else if (fleft->o == IR_BUFPUT) {
635 IRIns *irb = IR(fleft->op1); 635 IRIns *irb = IR(fleft->op1);
636 if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND)) 636 if (irb->o == IR_BUFHDR && irb->op2 == IRBUFHDR_RESET)
637 return fleft->op2; /* Shortcut for a single put operation. */ 637 return fleft->op2; /* Shortcut for a single put operation. */
638 } 638 }
639 } 639 }
@@ -646,7 +646,7 @@ LJFOLDF(bufstr_kfold_cse)
646 lj_assertJ(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT || 646 lj_assertJ(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT ||
647 ira->o == IR_CALLL || ira->o == IR_CARG, 647 ira->o == IR_CALLL || ira->o == IR_CARG,
648 "bad buffer constructor IR op %d", ira->o); 648 "bad buffer constructor IR op %d", ira->o);
649 if (ira->o == IR_BUFHDR && !(ira->op2 & IRBUFHDR_APPEND)) 649 if (ira->o == IR_BUFHDR && ira->op2 == IRBUFHDR_RESET)
650 return ref; /* CSE succeeded. */ 650 return ref; /* CSE succeeded. */
651 if (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab) 651 if (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab)
652 break; 652 break;