Skip to content

Commit 1736865

Browse files
committed
Implement new superinsns in jiterpreter
1 parent 34748d9 commit 1736865

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/mono/browser/runtime/jiterpreter-tables.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ export const unopTable: { [opcode: number]: OpRec3 | undefined } = {
8585
[MintOpcode.MINT_CLZ_I8]: [WasmOpcode.i64_clz, WasmOpcode.i64_load, WasmOpcode.i64_store],
8686
[MintOpcode.MINT_CTZ_I8]: [WasmOpcode.i64_ctz, WasmOpcode.i64_load, WasmOpcode.i64_store],
8787
[MintOpcode.MINT_POPCNT_I8]: [WasmOpcode.i64_popcnt, WasmOpcode.i64_load, WasmOpcode.i64_store],
88+
89+
[MintOpcode.MINT_ADD_I4_IMM2]: [WasmOpcode.i32_add, WasmOpcode.i32_load, WasmOpcode.i32_store],
90+
[MintOpcode.MINT_MUL_I4_IMM2]: [WasmOpcode.i32_mul, WasmOpcode.i32_load, WasmOpcode.i32_store],
91+
[MintOpcode.MINT_ADD_I8_IMM2]: [WasmOpcode.i64_add, WasmOpcode.i64_load, WasmOpcode.i64_store],
92+
[MintOpcode.MINT_MUL_I8_IMM2]: [WasmOpcode.i64_mul, WasmOpcode.i64_load, WasmOpcode.i64_store],
93+
94+
[MintOpcode.MINT_AND_I4_IMM]: [WasmOpcode.i32_and, WasmOpcode.i32_load, WasmOpcode.i32_store],
95+
[MintOpcode.MINT_AND_I4_IMM2]: [WasmOpcode.i32_and, WasmOpcode.i32_load, WasmOpcode.i32_store],
96+
[MintOpcode.MINT_OR_I4_IMM]: [WasmOpcode.i32_or, WasmOpcode.i32_load, WasmOpcode.i32_store],
97+
[MintOpcode.MINT_OR_I4_IMM2]: [WasmOpcode.i32_or, WasmOpcode.i32_load, WasmOpcode.i32_store],
8898
};
8999

90100
// HACK: Generating correct wasm for these is non-trivial so we hand them off to C.

src/mono/browser/runtime/jiterpreter-trace-generator.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ export function generateWasmBody(
15121512
} else
15131513
ip = abort;
15141514
} else if (
1515-
(opcode >= MintOpcode.MINT_LDC_I4_M1) &&
1515+
(opcode >= MintOpcode.MINT_LDC_I4_0) &&
15161516
(opcode <= MintOpcode.MINT_LDC_R8)
15171517
) {
15181518
if (!emit_ldc(builder, ip, opcode))
@@ -2597,6 +2597,8 @@ function emit_unop(builder: WasmBuilder, ip: MintOpcodePtr, opcode: MintOpcode):
25972597

25982598
case MintOpcode.MINT_ADD_I4_IMM:
25992599
case MintOpcode.MINT_MUL_I4_IMM:
2600+
case MintOpcode.MINT_AND_I4_IMM:
2601+
case MintOpcode.MINT_OR_I4_IMM:
26002602
case MintOpcode.MINT_SHL_I4_IMM:
26012603
case MintOpcode.MINT_SHR_I4_IMM:
26022604
case MintOpcode.MINT_SHR_UN_I4_IMM:
@@ -2606,6 +2608,14 @@ function emit_unop(builder: WasmBuilder, ip: MintOpcodePtr, opcode: MintOpcode):
26062608
builder.i32_const(getArgI16(ip, 3));
26072609
break;
26082610

2611+
case MintOpcode.MINT_ADD_I4_IMM2:
2612+
case MintOpcode.MINT_MUL_I4_IMM2:
2613+
case MintOpcode.MINT_AND_I4_IMM2:
2614+
case MintOpcode.MINT_OR_I4_IMM2:
2615+
append_ldloc(builder, getArgU16(ip, 2), loadOp);
2616+
builder.i32_const(getArgI32(ip, 3));
2617+
break;
2618+
26092619
case MintOpcode.MINT_ADD_I8_IMM:
26102620
case MintOpcode.MINT_MUL_I8_IMM:
26112621
case MintOpcode.MINT_SHL_I8_IMM:
@@ -2617,6 +2627,12 @@ function emit_unop(builder: WasmBuilder, ip: MintOpcodePtr, opcode: MintOpcode):
26172627
builder.i52_const(getArgI16(ip, 3));
26182628
break;
26192629

2630+
case MintOpcode.MINT_ADD_I8_IMM2:
2631+
case MintOpcode.MINT_MUL_I8_IMM2:
2632+
append_ldloc(builder, getArgU16(ip, 2), loadOp);
2633+
builder.i52_const(getArgI32(ip, 3));
2634+
break;
2635+
26202636
default:
26212637
append_ldloc(builder, getArgU16(ip, 2), loadOp);
26222638
break;

src/mono/mono/mini/interp/jiterpreter-opcode-values.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ OPRANGE(MINT_RET_I4_IMM, MINT_RET_I8_IMM, ABORT_OUTSIDE_BRANCH_BLOCK_NONE)
3535

3636
// High value because interp has to do a memory load for the immediate
3737
// but we can inline it into the trace
38-
OPRANGE(MINT_LDC_I4_M1, MINT_LDC_R8, HIGH)
38+
OPRANGE(MINT_LDC_I4_0, MINT_LDC_R8, HIGH)
3939

4040
OPRANGE(MINT_MOV_I4_I1, MINT_MOV_4, NORMAL)
4141
// High value for large/complex moves
4242
OPRANGE(MINT_MOV_8, MINT_MOV_8_4, HIGH)
4343

4444
// Binops. Assume most of them are not any faster in jiterp
4545
OPRANGE(MINT_ADD_I4, MINT_CLT_UN_R8, NORMAL)
46-
// Unops and some superinsns. Most will not be faster in jiterp.
47-
OPRANGE(MINT_ADD1_I4, MINT_SHR_I8_IMM, NORMAL)
46+
// Unops. Most will not be faster in jiterp.
47+
OPRANGE(MINT_ADD1_I4, MINT_CEQ0_I4, NORMAL)
48+
// Some superinsns that will be faster in jiterp due to inline constants
49+
OPRANGE(MINT_ADD_I4_IMM, MINT_ADD_MUL_I8_IMM, HIGH)
4850
// Math intrinsics. We implement most of these by calling libc or using wasm opcodes
4951
OPRANGE(MINT_ASIN, MINT_MAXF, NORMAL)
5052
// Field operations. Null check optimization makes these more efficient than interp

0 commit comments

Comments
 (0)