Skip to content

Commit

Permalink
Implement new superinsns in jiterpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Mar 5, 2024
1 parent 34748d9 commit 1736865
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/mono/browser/runtime/jiterpreter-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export const unopTable: { [opcode: number]: OpRec3 | undefined } = {
[MintOpcode.MINT_CLZ_I8]: [WasmOpcode.i64_clz, WasmOpcode.i64_load, WasmOpcode.i64_store],
[MintOpcode.MINT_CTZ_I8]: [WasmOpcode.i64_ctz, WasmOpcode.i64_load, WasmOpcode.i64_store],
[MintOpcode.MINT_POPCNT_I8]: [WasmOpcode.i64_popcnt, WasmOpcode.i64_load, WasmOpcode.i64_store],

[MintOpcode.MINT_ADD_I4_IMM2]: [WasmOpcode.i32_add, WasmOpcode.i32_load, WasmOpcode.i32_store],
[MintOpcode.MINT_MUL_I4_IMM2]: [WasmOpcode.i32_mul, WasmOpcode.i32_load, WasmOpcode.i32_store],
[MintOpcode.MINT_ADD_I8_IMM2]: [WasmOpcode.i64_add, WasmOpcode.i64_load, WasmOpcode.i64_store],
[MintOpcode.MINT_MUL_I8_IMM2]: [WasmOpcode.i64_mul, WasmOpcode.i64_load, WasmOpcode.i64_store],

[MintOpcode.MINT_AND_I4_IMM]: [WasmOpcode.i32_and, WasmOpcode.i32_load, WasmOpcode.i32_store],
[MintOpcode.MINT_AND_I4_IMM2]: [WasmOpcode.i32_and, WasmOpcode.i32_load, WasmOpcode.i32_store],
[MintOpcode.MINT_OR_I4_IMM]: [WasmOpcode.i32_or, WasmOpcode.i32_load, WasmOpcode.i32_store],
[MintOpcode.MINT_OR_I4_IMM2]: [WasmOpcode.i32_or, WasmOpcode.i32_load, WasmOpcode.i32_store],
};

// HACK: Generating correct wasm for these is non-trivial so we hand them off to C.
Expand Down
18 changes: 17 additions & 1 deletion src/mono/browser/runtime/jiterpreter-trace-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ export function generateWasmBody(
} else
ip = abort;
} else if (
(opcode >= MintOpcode.MINT_LDC_I4_M1) &&
(opcode >= MintOpcode.MINT_LDC_I4_0) &&
(opcode <= MintOpcode.MINT_LDC_R8)
) {
if (!emit_ldc(builder, ip, opcode))
Expand Down Expand Up @@ -2597,6 +2597,8 @@ function emit_unop(builder: WasmBuilder, ip: MintOpcodePtr, opcode: MintOpcode):

case MintOpcode.MINT_ADD_I4_IMM:
case MintOpcode.MINT_MUL_I4_IMM:
case MintOpcode.MINT_AND_I4_IMM:
case MintOpcode.MINT_OR_I4_IMM:
case MintOpcode.MINT_SHL_I4_IMM:
case MintOpcode.MINT_SHR_I4_IMM:
case MintOpcode.MINT_SHR_UN_I4_IMM:
Expand All @@ -2606,6 +2608,14 @@ function emit_unop(builder: WasmBuilder, ip: MintOpcodePtr, opcode: MintOpcode):
builder.i32_const(getArgI16(ip, 3));
break;

case MintOpcode.MINT_ADD_I4_IMM2:
case MintOpcode.MINT_MUL_I4_IMM2:
case MintOpcode.MINT_AND_I4_IMM2:
case MintOpcode.MINT_OR_I4_IMM2:
append_ldloc(builder, getArgU16(ip, 2), loadOp);
builder.i32_const(getArgI32(ip, 3));
break;

case MintOpcode.MINT_ADD_I8_IMM:
case MintOpcode.MINT_MUL_I8_IMM:
case MintOpcode.MINT_SHL_I8_IMM:
Expand All @@ -2617,6 +2627,12 @@ function emit_unop(builder: WasmBuilder, ip: MintOpcodePtr, opcode: MintOpcode):
builder.i52_const(getArgI16(ip, 3));
break;

case MintOpcode.MINT_ADD_I8_IMM2:
case MintOpcode.MINT_MUL_I8_IMM2:
append_ldloc(builder, getArgU16(ip, 2), loadOp);
builder.i52_const(getArgI32(ip, 3));
break;

default:
append_ldloc(builder, getArgU16(ip, 2), loadOp);
break;
Expand Down
8 changes: 5 additions & 3 deletions src/mono/mono/mini/interp/jiterpreter-opcode-values.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ OPRANGE(MINT_RET_I4_IMM, MINT_RET_I8_IMM, ABORT_OUTSIDE_BRANCH_BLOCK_NONE)

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

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

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

0 comments on commit 1736865

Please sign in to comment.