Skip to content

Commit 8ca896c

Browse files
authored
[wasm] Implement integer log2 in jiterpreter (#84068)
1 parent 91df184 commit 8ca896c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/mono/mono/mini/interp/jiterpreter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,11 @@ jiterp_should_abort_trace (InterpInst *ins, gboolean *inside_branch_block)
702702
case MINT_CLZ_I4:
703703
case MINT_CTZ_I4:
704704
case MINT_POPCNT_I4:
705+
case MINT_LOG2_I4:
705706
case MINT_CLZ_I8:
706707
case MINT_CTZ_I8:
707708
case MINT_POPCNT_I8:
709+
case MINT_LOG2_I8:
708710
return TRACE_CONTINUE;
709711

710712
case MINT_BR:

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,28 @@ export function generate_wasm_body (
10751075
builder.callImport("cmpxchg_i64");
10761076
break;
10771077

1078+
case MintOpcode.MINT_LOG2_I4:
1079+
case MintOpcode.MINT_LOG2_I8: {
1080+
const isI64 = (opcode === MintOpcode.MINT_LOG2_I8);
1081+
1082+
builder.local("pLocals");
1083+
1084+
append_ldloc(builder, getArgU16(ip, 2), isI64 ? WasmOpcode.i64_load : WasmOpcode.i32_load);
1085+
if (isI64)
1086+
builder.i52_const(1);
1087+
else
1088+
builder.i32_const(1);
1089+
builder.appendU8(isI64 ? WasmOpcode.i64_or : WasmOpcode.i32_or);
1090+
builder.appendU8(isI64 ? WasmOpcode.i64_clz : WasmOpcode.i32_clz);
1091+
if (isI64)
1092+
builder.appendU8(WasmOpcode.i32_wrap_i64);
1093+
builder.i32_const(isI64 ? 63 : 31);
1094+
builder.appendU8(WasmOpcode.i32_xor);
1095+
1096+
append_stloc_tail(builder, getArgU16(ip, 1), WasmOpcode.i32_store);
1097+
break;
1098+
}
1099+
10781100
case MintOpcode.MINT_FMA:
10791101
case MintOpcode.MINT_FMAF: {
10801102
const isF32 = (opcode === MintOpcode.MINT_FMAF),

0 commit comments

Comments
 (0)