From f4a91e1e5a05d66d7003a8390a7d1fd6d9f38ed8 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Wed, 28 Apr 2021 16:55:56 -0400 Subject: [PATCH] Implement setn bytecode (#15) --- yjit_codegen.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/yjit_codegen.c b/yjit_codegen.c index f02c5196125d1c..ace2df622dfc02 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -456,6 +456,13 @@ yjit_gen_block(block_t *block, rb_execution_context_t *ec) } } +static codegen_status_t +gen_nop(jitstate_t* jit, ctx_t* ctx) +{ + // Do nothing + return YJIT_KEEP_COMPILING; +} + static codegen_status_t gen_dup(jitstate_t* jit, ctx_t* ctx) { @@ -471,10 +478,22 @@ gen_dup(jitstate_t* jit, ctx_t* ctx) return YJIT_KEEP_COMPILING; } +// set Nth stack entry to stack top static codegen_status_t -gen_nop(jitstate_t* jit, ctx_t* ctx) +gen_setn(jitstate_t* jit, ctx_t* ctx) { - // Do nothing + rb_num_t n = (rb_num_t)jit_get_arg(jit, 0); + + // Get the top value and its type + val_type_t top_type = ctx_get_opnd_type(ctx, OPND_STACK(0)); + x86opnd_t top_val = ctx_stack_pop(ctx, 0); + + // Set the destination and its type + ctx_set_opnd_type(ctx, OPND_STACK(n), top_type); + x86opnd_t dst_opnd = ctx_stack_opnd(ctx, (int32_t)n); + mov(cb, REG0, top_val); + mov(cb, dst_opnd, REG0); + return YJIT_KEEP_COMPILING; } @@ -2220,8 +2239,9 @@ yjit_init_codegen(void) leave_exit_code = yjit_gen_leave_exit(cb); // Map YARV opcodes to the corresponding codegen functions - yjit_reg_op(BIN(dup), gen_dup); yjit_reg_op(BIN(nop), gen_nop); + yjit_reg_op(BIN(dup), gen_dup); + yjit_reg_op(BIN(setn), gen_setn); yjit_reg_op(BIN(pop), gen_pop); yjit_reg_op(BIN(putnil), gen_putnil); yjit_reg_op(BIN(putobject), gen_putobject);