diff options
| author | Mike Pall <mike> | 2021-07-19 16:41:29 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2021-07-19 16:46:27 +0200 |
| commit | 02bcbea8b0f1b30b75460f31fb8749fec55d1e2e (patch) | |
| tree | 741a23b5d54e6bda4f254d2c4f5cec70e8a2d8d8 /src | |
| parent | 1d5ef35fed472140fcb4c5f9a1fee6d05a8a6591 (diff) | |
| download | luajit-02bcbea8b0f1b30b75460f31fb8749fec55d1e2e.tar.gz luajit-02bcbea8b0f1b30b75460f31fb8749fec55d1e2e.tar.bz2 luajit-02bcbea8b0f1b30b75460f31fb8749fec55d1e2e.zip | |
String buffers, part 3c: Add IRBUFHDR_WRITE mode.
Sponsored by fmad.io.
Diffstat (limited to 'src')
| -rw-r--r-- | src/jit/dis_arm64.lua | 2 | ||||
| -rw-r--r-- | src/jit/dump.lua | 2 | ||||
| -rw-r--r-- | src/lj_asm.c | 8 | ||||
| -rw-r--r-- | src/lj_asm_arm.h | 24 | ||||
| -rw-r--r-- | src/lj_asm_arm64.h | 15 | ||||
| -rw-r--r-- | src/lj_asm_mips.h | 21 | ||||
| -rw-r--r-- | src/lj_asm_ppc.h | 15 | ||||
| -rw-r--r-- | src/lj_asm_x86.h | 15 | ||||
| -rw-r--r-- | src/lj_emit_mips.h | 2 | ||||
| -rw-r--r-- | src/lj_ir.h | 1 | ||||
| -rw-r--r-- | src/lj_opt_fold.c | 7 | ||||
| -rw-r--r-- | src/lj_target_arm.h | 1 | ||||
| -rw-r--r-- | src/lj_target_arm64.h | 2 | ||||
| -rw-r--r-- | src/lj_target_mips.h | 2 |
14 files changed, 112 insertions, 5 deletions
diff --git a/src/jit/dis_arm64.lua b/src/jit/dis_arm64.lua index ea7ca828..ad909fbd 100644 --- a/src/jit/dis_arm64.lua +++ b/src/jit/dis_arm64.lua | |||
| @@ -1089,7 +1089,7 @@ local function disass_ins(ctx) | |||
| 1089 | last = "#"..(sf+32 - immr) | 1089 | last = "#"..(sf+32 - immr) |
| 1090 | operands[#operands] = last | 1090 | operands[#operands] = last |
| 1091 | x = x + 1 | 1091 | x = x + 1 |
| 1092 | elseif x >= immr then | 1092 | else |
| 1093 | name = a2 | 1093 | name = a2 |
| 1094 | x = x - immr + 1 | 1094 | x = x - immr + 1 |
| 1095 | end | 1095 | end |
diff --git a/src/jit/dump.lua b/src/jit/dump.lua index 4806f4c4..03140196 100644 --- a/src/jit/dump.lua +++ b/src/jit/dump.lua | |||
| @@ -288,7 +288,7 @@ local litname = { | |||
| 288 | ["FREF "] = vmdef.irfield, | 288 | ["FREF "] = vmdef.irfield, |
| 289 | ["FPMATH"] = vmdef.irfpm, | 289 | ["FPMATH"] = vmdef.irfpm, |
| 290 | ["TMPREF"] = { [0] = "", "IN", "OUT", "INOUT", "", "", "OUT2", "INOUT2" }, | 290 | ["TMPREF"] = { [0] = "", "IN", "OUT", "INOUT", "", "", "OUT2", "INOUT2" }, |
| 291 | ["BUFHDR"] = { [0] = "RESET", "APPEND" }, | 291 | ["BUFHDR"] = { [0] = "RESET", "APPEND", "WRITE" }, |
| 292 | ["TOSTR "] = { [0] = "INT", "NUM", "CHAR" }, | 292 | ["TOSTR "] = { [0] = "INT", "NUM", "CHAR" }, |
| 293 | } | 293 | } |
| 294 | 294 | ||
diff --git a/src/lj_asm.c b/src/lj_asm.c index 9dae2707..fae5b241 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c | |||
| @@ -1145,6 +1145,9 @@ static void asm_gcstep(ASMState *as, IRIns *ir) | |||
| 1145 | /* -- Buffer operations --------------------------------------------------- */ | 1145 | /* -- Buffer operations --------------------------------------------------- */ |
| 1146 | 1146 | ||
| 1147 | static void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode); | 1147 | static void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode); |
| 1148 | #if LJ_HASBUFFER | ||
| 1149 | static void asm_bufhdr_write(ASMState *as, Reg sb); | ||
| 1150 | #endif | ||
| 1148 | 1151 | ||
| 1149 | static void asm_bufhdr(ASMState *as, IRIns *ir) | 1152 | static void asm_bufhdr(ASMState *as, IRIns *ir) |
| 1150 | { | 1153 | { |
| @@ -1172,6 +1175,11 @@ static void asm_bufhdr(ASMState *as, IRIns *ir) | |||
| 1172 | } | 1175 | } |
| 1173 | break; | 1176 | break; |
| 1174 | } | 1177 | } |
| 1178 | #if LJ_HASBUFFER | ||
| 1179 | case IRBUFHDR_WRITE: | ||
| 1180 | asm_bufhdr_write(as, sb); | ||
| 1181 | break; | ||
| 1182 | #endif | ||
| 1175 | default: lj_assertA(0, "bad BUFHDR op2 %d", ir->op2); break; | 1183 | default: lj_assertA(0, "bad BUFHDR op2 %d", ir->op2); break; |
| 1176 | } | 1184 | } |
| 1177 | #if LJ_TARGET_X86ORX64 | 1185 | #if LJ_TARGET_X86ORX64 |
diff --git a/src/lj_asm_arm.h b/src/lj_asm_arm.h index 208c3203..96703d7d 100644 --- a/src/lj_asm_arm.h +++ b/src/lj_asm_arm.h | |||
| @@ -501,6 +501,30 @@ static void asm_retf(ASMState *as, IRIns *ir) | |||
| 501 | emit_lso(as, ARMI_LDR, RID_TMP, base, -4); | 501 | emit_lso(as, ARMI_LDR, RID_TMP, base, -4); |
| 502 | } | 502 | } |
| 503 | 503 | ||
| 504 | /* -- Buffer operations --------------------------------------------------- */ | ||
| 505 | |||
| 506 | #if LJ_HASBUFFER | ||
| 507 | static void asm_bufhdr_write(ASMState *as, Reg sb) | ||
| 508 | { | ||
| 509 | Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); | ||
| 510 | IRIns irgc; | ||
| 511 | int32_t addr = i32ptr((void *)&J2G(as->J)->cur_L); | ||
| 512 | irgc.ot = IRT(0, IRT_PGC); /* GC type. */ | ||
| 513 | emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L)); | ||
| 514 | if ((as->flags & JIT_F_ARMV6T2)) { | ||
| 515 | emit_dnm(as, ARMI_BFI, RID_TMP, lj_fls(SBUF_MASK_FLAG), tmp); | ||
| 516 | } else { | ||
| 517 | emit_dnm(as, ARMI_ORR, RID_TMP, RID_TMP, tmp); | ||
| 518 | emit_dn(as, ARMI_AND|ARMI_K12|SBUF_MASK_FLAG, tmp, tmp); | ||
| 519 | } | ||
| 520 | emit_lso(as, ARMI_LDR, RID_TMP, | ||
| 521 | ra_allock(as, (addr & ~4095), | ||
| 522 | rset_exclude(rset_exclude(RSET_GPR, sb), tmp)), | ||
| 523 | (addr & 4095)); | ||
| 524 | emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L)); | ||
| 525 | } | ||
| 526 | #endif | ||
| 527 | |||
| 504 | /* -- Type conversions ---------------------------------------------------- */ | 528 | /* -- Type conversions ---------------------------------------------------- */ |
| 505 | 529 | ||
| 506 | #if !LJ_SOFTFP | 530 | #if !LJ_SOFTFP |
diff --git a/src/lj_asm_arm64.h b/src/lj_asm_arm64.h index 5bd4e0d5..dde52347 100644 --- a/src/lj_asm_arm64.h +++ b/src/lj_asm_arm64.h | |||
| @@ -522,6 +522,21 @@ static void asm_retf(ASMState *as, IRIns *ir) | |||
| 522 | emit_lso(as, A64I_LDRx, RID_TMP, base, -8); | 522 | emit_lso(as, A64I_LDRx, RID_TMP, base, -8); |
| 523 | } | 523 | } |
| 524 | 524 | ||
| 525 | /* -- Buffer operations --------------------------------------------------- */ | ||
| 526 | |||
| 527 | #if LJ_HASBUFFER | ||
| 528 | static void asm_bufhdr_write(ASMState *as, Reg sb) | ||
| 529 | { | ||
| 530 | Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); | ||
| 531 | IRIns irgc; | ||
| 532 | irgc.ot = IRT(0, IRT_PGC); /* GC type. */ | ||
| 533 | emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L)); | ||
| 534 | emit_dn(as, A64I_BFMx | A64F_IMMS(lj_fls(SBUF_MASK_FLAG)) | A64F_IMMR(0), RID_TMP, tmp); | ||
| 535 | emit_getgl(as, RID_TMP, cur_L); | ||
| 536 | emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L)); | ||
| 537 | } | ||
| 538 | #endif | ||
| 539 | |||
| 525 | /* -- Type conversions ---------------------------------------------------- */ | 540 | /* -- Type conversions ---------------------------------------------------- */ |
| 526 | 541 | ||
| 527 | static void asm_tointg(ASMState *as, IRIns *ir, Reg left) | 542 | static void asm_tointg(ASMState *as, IRIns *ir, Reg left) |
diff --git a/src/lj_asm_mips.h b/src/lj_asm_mips.h index 058df8be..22aa88bf 100644 --- a/src/lj_asm_mips.h +++ b/src/lj_asm_mips.h | |||
| @@ -465,6 +465,27 @@ static void asm_retf(ASMState *as, IRIns *ir) | |||
| 465 | emit_tsi(as, MIPSI_AL, RID_TMP, base, -8); | 465 | emit_tsi(as, MIPSI_AL, RID_TMP, base, -8); |
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | /* -- Buffer operations --------------------------------------------------- */ | ||
| 469 | |||
| 470 | #if LJ_HASBUFFER | ||
| 471 | static void asm_bufhdr_write(ASMState *as, Reg sb) | ||
| 472 | { | ||
| 473 | Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); | ||
| 474 | IRIns irgc; | ||
| 475 | irgc.ot = IRT(0, IRT_PGC); /* GC type. */ | ||
| 476 | emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L)); | ||
| 477 | if ((as->flags & JIT_F_MIPSXXR2)) { | ||
| 478 | emit_tsml(as, LJ_64 ? MIPSI_DINS : MIPSI_INS, RID_TMP, tmp, | ||
| 479 | lj_fls(SBUF_MASK_FLAG), 0); | ||
| 480 | } else { | ||
| 481 | emit_dst(as, MIPSI_OR, RID_TMP, RID_TMP, tmp); | ||
| 482 | emit_tsi(as, MIPSI_ANDI, tmp, tmp, SBUF_MASK_FLAG); | ||
| 483 | } | ||
| 484 | emit_getgl(as, RID_TMP, cur_L); | ||
| 485 | emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L)); | ||
| 486 | } | ||
| 487 | #endif | ||
| 488 | |||
| 468 | /* -- Type conversions ---------------------------------------------------- */ | 489 | /* -- Type conversions ---------------------------------------------------- */ |
| 469 | 490 | ||
| 470 | #if !LJ_SOFTFP | 491 | #if !LJ_SOFTFP |
diff --git a/src/lj_asm_ppc.h b/src/lj_asm_ppc.h index caef8fd7..c27ee71c 100644 --- a/src/lj_asm_ppc.h +++ b/src/lj_asm_ppc.h | |||
| @@ -392,6 +392,21 @@ static void asm_retf(ASMState *as, IRIns *ir) | |||
| 392 | emit_tai(as, PPCI_LWZ, RID_TMP, base, -8); | 392 | emit_tai(as, PPCI_LWZ, RID_TMP, base, -8); |
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | /* -- Buffer operations --------------------------------------------------- */ | ||
| 396 | |||
| 397 | #if LJ_HASBUFFER | ||
| 398 | static void asm_bufhdr_write(ASMState *as, Reg sb) | ||
| 399 | { | ||
| 400 | Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); | ||
| 401 | IRIns irgc; | ||
| 402 | irgc.ot = IRT(0, IRT_PGC); /* GC type. */ | ||
| 403 | emit_storeofs(as, &irgc, RID_TMP, sb, offsetof(SBuf, L)); | ||
| 404 | emit_rot(as, PPCI_RLWIMI, RID_TMP, tmp, 0, 31-lj_fls(SBUF_MASK_FLAG), 31); | ||
| 405 | emit_getgl(as, RID_TMP, cur_L); | ||
| 406 | emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L)); | ||
| 407 | } | ||
| 408 | #endif | ||
| 409 | |||
| 395 | /* -- Type conversions ---------------------------------------------------- */ | 410 | /* -- Type conversions ---------------------------------------------------- */ |
| 396 | 411 | ||
| 397 | #if !LJ_SOFTFP | 412 | #if !LJ_SOFTFP |
diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index b8abf9d6..c8ed46d2 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h | |||
| @@ -791,6 +791,21 @@ static void asm_retf(ASMState *as, IRIns *ir) | |||
| 791 | #endif | 791 | #endif |
| 792 | } | 792 | } |
| 793 | 793 | ||
| 794 | /* -- Buffer operations --------------------------------------------------- */ | ||
| 795 | |||
| 796 | #if LJ_HASBUFFER | ||
| 797 | static void asm_bufhdr_write(ASMState *as, Reg sb) | ||
| 798 | { | ||
| 799 | Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb)); | ||
| 800 | IRIns irgc; | ||
| 801 | irgc.ot = IRT(0, IRT_PGC); /* GC type. */ | ||
| 802 | emit_storeofs(as, &irgc, tmp, sb, offsetof(SBuf, L)); | ||
| 803 | emit_opgl(as, XO_ARITH(XOg_OR), tmp|REX_GC64, cur_L); | ||
| 804 | emit_gri(as, XG_ARITHi(XOg_AND), tmp, SBUF_MASK_FLAG); | ||
| 805 | emit_loadofs(as, &irgc, tmp, sb, offsetof(SBuf, L)); | ||
| 806 | } | ||
| 807 | #endif | ||
| 808 | |||
| 794 | /* -- Type conversions ---------------------------------------------------- */ | 809 | /* -- Type conversions ---------------------------------------------------- */ |
| 795 | 810 | ||
| 796 | static void asm_tointg(ASMState *as, IRIns *ir, Reg left) | 811 | static void asm_tointg(ASMState *as, IRIns *ir, Reg left) |
diff --git a/src/lj_emit_mips.h b/src/lj_emit_mips.h index 7825eabb..c13615dd 100644 --- a/src/lj_emit_mips.h +++ b/src/lj_emit_mips.h | |||
| @@ -70,7 +70,7 @@ static void emit_rotr(ASMState *as, Reg dest, Reg src, Reg tmp, uint32_t shift) | |||
| 70 | } | 70 | } |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | #if LJ_64 | 73 | #if LJ_64 || LJ_HASBUFFER |
| 74 | static void emit_tsml(ASMState *as, MIPSIns mi, Reg rt, Reg rs, uint32_t msb, | 74 | static void emit_tsml(ASMState *as, MIPSIns mi, Reg rt, Reg rs, uint32_t msb, |
| 75 | uint32_t lsb) | 75 | uint32_t lsb) |
| 76 | { | 76 | { |
diff --git a/src/lj_ir.h b/src/lj_ir.h index af10cc4f..fa10f4bc 100644 --- a/src/lj_ir.h +++ b/src/lj_ir.h | |||
| @@ -240,6 +240,7 @@ IRFLDEF(FLENUM) | |||
| 240 | /* BUFHDR mode, stored in op2. */ | 240 | /* BUFHDR mode, stored in op2. */ |
| 241 | #define IRBUFHDR_RESET 0 /* Reset buffer. */ | 241 | #define IRBUFHDR_RESET 0 /* Reset buffer. */ |
| 242 | #define IRBUFHDR_APPEND 1 /* Append to buffer. */ | 242 | #define IRBUFHDR_APPEND 1 /* Append to buffer. */ |
| 243 | #define IRBUFHDR_WRITE 2 /* Write to string buffer. */ | ||
| 243 | 244 | ||
| 244 | /* CONV mode, stored in op2. */ | 245 | /* CONV mode, stored in op2. */ |
| 245 | #define IRCONV_SRCMASK 0x001f /* Source IRType. */ | 246 | #define IRCONV_SRCMASK 0x001f /* Source IRType. */ |
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index 06731c7a..4d179f3f 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
| @@ -579,7 +579,11 @@ LJFOLDF(kfold_strcmp) | |||
| 579 | ** fragments left over from CSE are eliminated by DCE. | 579 | ** fragments left over from CSE are eliminated by DCE. |
| 580 | */ | 580 | */ |
| 581 | 581 | ||
| 582 | /* BUFHDR is emitted like a store, see below. */ | 582 | LJFOLD(BUFHDR any any) |
| 583 | LJFOLDF(bufhdr_merge) | ||
| 584 | { | ||
| 585 | return fins->op2 == IRBUFHDR_WRITE ? CSEFOLD : EMITFOLD; | ||
| 586 | } | ||
| 583 | 587 | ||
| 584 | LJFOLD(BUFPUT BUFHDR BUFSTR) | 588 | LJFOLD(BUFPUT BUFHDR BUFSTR) |
| 585 | LJFOLDF(bufput_append) | 589 | LJFOLDF(bufput_append) |
| @@ -2432,7 +2436,6 @@ LJFOLD(TNEW any any) | |||
| 2432 | LJFOLD(TDUP any) | 2436 | LJFOLD(TDUP any) |
| 2433 | LJFOLD(CNEW any any) | 2437 | LJFOLD(CNEW any any) |
| 2434 | LJFOLD(XSNEW any any) | 2438 | LJFOLD(XSNEW any any) |
| 2435 | LJFOLD(BUFHDR any any) | ||
| 2436 | LJFOLDX(lj_ir_emit) | 2439 | LJFOLDX(lj_ir_emit) |
| 2437 | 2440 | ||
| 2438 | /* ------------------------------------------------------------------------ */ | 2441 | /* ------------------------------------------------------------------------ */ |
diff --git a/src/lj_target_arm.h b/src/lj_target_arm.h index f41f53e9..72516bc2 100644 --- a/src/lj_target_arm.h +++ b/src/lj_target_arm.h | |||
| @@ -211,6 +211,7 @@ typedef enum ARMIns { | |||
| 211 | /* ARMv6T2 */ | 211 | /* ARMv6T2 */ |
| 212 | ARMI_MOVW = 0xe3000000, | 212 | ARMI_MOVW = 0xe3000000, |
| 213 | ARMI_MOVT = 0xe3400000, | 213 | ARMI_MOVT = 0xe3400000, |
| 214 | ARMI_BFI = 0xe7c00010, | ||
| 214 | 215 | ||
| 215 | /* VFP */ | 216 | /* VFP */ |
| 216 | ARMI_VMOV_D = 0xeeb00b40, | 217 | ARMI_VMOV_D = 0xeeb00b40, |
diff --git a/src/lj_target_arm64.h b/src/lj_target_arm64.h index c2f71153..bf568a8d 100644 --- a/src/lj_target_arm64.h +++ b/src/lj_target_arm64.h | |||
| @@ -210,6 +210,8 @@ typedef enum A64Ins { | |||
| 210 | 210 | ||
| 211 | A64I_EXTRw = 0x13800000, | 211 | A64I_EXTRw = 0x13800000, |
| 212 | A64I_EXTRx = 0x93c00000, | 212 | A64I_EXTRx = 0x93c00000, |
| 213 | A64I_BFMw = 0x33000000, | ||
| 214 | A64I_BFMx = 0xb3400000, | ||
| 213 | A64I_SBFMw = 0x13000000, | 215 | A64I_SBFMw = 0x13000000, |
| 214 | A64I_SBFMx = 0x93400000, | 216 | A64I_SBFMx = 0x93400000, |
| 215 | A64I_SXTBw = 0x13001c00, | 217 | A64I_SXTBw = 0x13001c00, |
diff --git a/src/lj_target_mips.h b/src/lj_target_mips.h index 8d8f68ec..5da94605 100644 --- a/src/lj_target_mips.h +++ b/src/lj_target_mips.h | |||
| @@ -256,6 +256,8 @@ typedef enum MIPSIns { | |||
| 256 | MIPSI_ROTRV = 0x00000046, /* MIPSXXR2 */ | 256 | MIPSI_ROTRV = 0x00000046, /* MIPSXXR2 */ |
| 257 | MIPSI_DROTRV = 0x00000056, | 257 | MIPSI_DROTRV = 0x00000056, |
| 258 | 258 | ||
| 259 | MIPSI_INS = 0x7c000004, /* MIPSXXR2 */ | ||
| 260 | |||
| 259 | MIPSI_SEB = 0x7c000420, /* MIPSXXR2 */ | 261 | MIPSI_SEB = 0x7c000420, /* MIPSXXR2 */ |
| 260 | MIPSI_SEH = 0x7c000620, /* MIPSXXR2 */ | 262 | MIPSI_SEH = 0x7c000620, /* MIPSXXR2 */ |
| 261 | MIPSI_WSBH = 0x7c0000a0, /* MIPSXXR2 */ | 263 | MIPSI_WSBH = 0x7c0000a0, /* MIPSXXR2 */ |
