Skip to content

Commit 3a0cf69

Browse files
author
Mike Pall
committed
String buffers, part 3b: Change IR_BUFHDR op2 mode bits to mode.
Sponsored by fmad.io.
1 parent 6df650f commit 3a0cf69

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/lj_asm.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,24 +1149,30 @@ static void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode);
11491149
static void asm_bufhdr(ASMState *as, IRIns *ir)
11501150
{
11511151
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: {
11531162
/* Rematerialize const buffer pointer instead of likely spill. */
11541163
IRIns *irp = IR(ir->op1);
11551164
if (!(ra_hasreg(irp->r) || irp == ir-1 ||
11561165
(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))
11581167
irp = IR(irp->op1);
11591168
if (irref_isk(irp->op1)) {
11601169
ra_weak(as, ra_allocref(as, ir->op1, RSET_GPR));
11611170
ir = irp;
11621171
}
11631172
}
1164-
} else {
1165-
Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));
1166-
IRIns irbp;
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));
1173+
break;
1174+
}
1175+
default: lj_assertA(0, "bad BUFHDR op2 %d", ir->op2); break;
11701176
}
11711177
#if LJ_TARGET_X86ORX64
11721178
ra_left(as, sb, ir->op1);

src/lj_opt_fold.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,11 @@ LJFOLDF(bufput_append)
586586
{
587587
/* New buffer, no other buffer op inbetween and same buffer? */
588588
if ((J->flags & JIT_F_OPT_FWD) &&
589-
!(fleft->op2 & IRBUFHDR_APPEND) &&
589+
fleft->op2 == IRBUFHDR_RESET &&
590590
fleft->prev == fright->op2 &&
591591
fleft->op1 == IR(fright->op2)->op1) {
592592
IRRef ref = fins->op1;
593-
IR(ref)->op2 = (fleft->op2 | IRBUFHDR_APPEND); /* Modify BUFHDR. */
593+
IR(ref)->op2 = IRBUFHDR_APPEND; /* Modify BUFHDR. */
594594
IR(ref)->op1 = fright->op1;
595595
return ref;
596596
}
@@ -626,14 +626,14 @@ LJFOLDF(bufstr_kfold_cse)
626626
"bad buffer constructor IR op %d", fleft->o);
627627
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
628628
if (fleft->o == IR_BUFHDR) { /* No put operations? */
629-
if (!(fleft->op2 & IRBUFHDR_APPEND)) /* Empty buffer? */
629+
if (fleft->op2 == IRBUFHDR_RESET) /* Empty buffer? */
630630
return lj_ir_kstr(J, &J2G(J)->strempty);
631631
fins->op1 = fleft->op1;
632632
fins->op2 = fleft->prev; /* Relies on checks in bufput_append. */
633633
return CSEFOLD;
634634
} else if (fleft->o == IR_BUFPUT) {
635635
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)
637637
return fleft->op2; /* Shortcut for a single put operation. */
638638
}
639639
}
@@ -646,7 +646,7 @@ LJFOLDF(bufstr_kfold_cse)
646646
lj_assertJ(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT ||
647647
ira->o == IR_CALLL || ira->o == IR_CARG,
648648
"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)
650650
return ref; /* CSE succeeded. */
651651
if (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab)
652652
break;

0 commit comments

Comments
 (0)