From 96fd8afbf4d93b6831ca119fd8c1f07dfa9abd07 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sat, 19 Jun 2021 14:02:53 -0700 Subject: [PATCH] Skip opt_case_dispatch --- yjit_codegen.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/yjit_codegen.c b/yjit_codegen.c index 049c72b6ba..6160169d62 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -2447,6 +2447,22 @@ gen_opt_regexpmatch2(jitstate_t *jit, ctx_t *ctx) return gen_opt_send_without_block(jit, ctx); } +static codegen_status_t +gen_opt_case_dispatch(jitstate_t* jit, ctx_t* ctx) +{ + // Normally this instruction would lookup the key in a hash and jump to an + // offset based on that. + // Instead we can take the fallback case and continue with the next + // instruciton. + // We'd hope that our jitted code will be sufficiently fast without the + // hash lookup, at least for small hashes, but it's worth revisiting this + // assumption in the future. + + ctx_stack_pop(ctx, 1); + + return YJIT_KEEP_COMPILING; // continue with the next instruction +} + void gen_branchif_branch(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_t shape) { @@ -4215,6 +4231,7 @@ yjit_init_codegen(void) yjit_reg_op(BIN(opt_getinlinecache), gen_opt_getinlinecache); yjit_reg_op(BIN(opt_invokebuiltin_delegate), gen_opt_invokebuiltin_delegate); yjit_reg_op(BIN(opt_invokebuiltin_delegate_leave), gen_opt_invokebuiltin_delegate); + yjit_reg_op(BIN(opt_case_dispatch), gen_opt_case_dispatch); yjit_reg_op(BIN(branchif), gen_branchif); yjit_reg_op(BIN(branchunless), gen_branchunless); yjit_reg_op(BIN(branchnil), gen_branchnil);