Skip to content

Commit

Permalink
[mono][interp] Completely remove short branches
Browse files Browse the repository at this point in the history
They don't seem to have any benefit at the expense of a lot of code and added complexity.
  • Loading branch information
BrzVlad committed Jul 24, 2024
1 parent 189a250 commit 6a54c14
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 377 deletions.
21 changes: 3 additions & 18 deletions src/mono/browser/runtime/jiterpreter-trace-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export function generateBackwardBranchTable (

switch (opcode) {
case MintOpcode.MINT_CALL_HANDLER:
case MintOpcode.MINT_CALL_HANDLER_S:
// While this formally isn't a backward branch target, we want to record
// the offset of its following instruction so that the jiterpreter knows
// to generate the necessary dispatch code to enable branching back to it.
Expand Down Expand Up @@ -506,21 +505,15 @@ export function generateWasmBody (
}

// Other conditional branch types are handled by the relop table.
case MintOpcode.MINT_BRFALSE_I4_S:
case MintOpcode.MINT_BRTRUE_I4_S:
case MintOpcode.MINT_BRFALSE_I4_SP:
case MintOpcode.MINT_BRTRUE_I4_SP:
case MintOpcode.MINT_BRFALSE_I8_S:
case MintOpcode.MINT_BRTRUE_I8_S:
if (!emit_branch(builder, ip, frame, opcode))
ip = abort;
else
isConditionallyExecuted = true;
break;

case MintOpcode.MINT_BR_S:
case MintOpcode.MINT_CALL_HANDLER:
case MintOpcode.MINT_CALL_HANDLER_S:
if (!emit_branch(builder, ip, frame, opcode))
ip = abort;
else {
Expand Down Expand Up @@ -1293,7 +1286,6 @@ export function generateWasmBody (
// These are generated in place of regular LEAVEs inside of the body of a catch clause.
// We can safely assume that during normal execution, catch clauses won't be running.
case MintOpcode.MINT_LEAVE_CHECK:
case MintOpcode.MINT_LEAVE_S_CHECK:
append_bailout(builder, ip, BailoutReason.LeaveCheck);
pruneOpcodes = true;
break;
Expand Down Expand Up @@ -2745,8 +2737,7 @@ function append_call_handler_store_ret_ip (
builder: WasmBuilder, ip: MintOpcodePtr,
frame: NativePointer, opcode: MintOpcode
) {
const shortOffset = (opcode === MintOpcode.MINT_CALL_HANDLER_S),
retIp = shortOffset ? <any>ip + (3 * 2) : <any>ip + (4 * 2),
const retIp = <any>ip + (4 * 2),
clauseIndex = getU16(retIp - 2),
clauseDataOffset = get_imethod_clause_data_offset(frame, clauseIndex);

Expand All @@ -2773,9 +2764,6 @@ function getBranchDisplacement (
case MintOpArgType.MintOpBranch:
result = getI32_unaligned(payloadAddress);
break;
case MintOpArgType.MintOpShortBranch:
result = getI16(payloadAddress);
break;
case MintOpArgType.MintOpShortAndBranch:
result = getI32_unaligned(payloadAddress + 2);
break;
Expand Down Expand Up @@ -2808,11 +2796,8 @@ function emit_branch (
// branch target (if possible), bailing out at the end otherwise
switch (opcode) {
case MintOpcode.MINT_CALL_HANDLER:
case MintOpcode.MINT_CALL_HANDLER_S:
case MintOpcode.MINT_BR:
case MintOpcode.MINT_BR_S: {
const isCallHandler = (opcode === MintOpcode.MINT_CALL_HANDLER) ||
(opcode === MintOpcode.MINT_CALL_HANDLER_S);
case MintOpcode.MINT_BR: {
const isCallHandler = opcode === MintOpcode.MINT_CALL_HANDLER;

const destination = <any>ip + (displacement * 2);

Expand Down
Loading

0 comments on commit 6a54c14

Please sign in to comment.