ruby-changes:68616
From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:10:43 +0900 (JST)
Subject: [ruby-changes:68616] 30c4237b06 (master): Fixed bug with ctx_stack_pop. Implemented dup bytecode.
https://git.ruby-lang.org/ruby.git/commit/?id=30c4237b06 From 30c4237b06573d068624739f6f6d5aaf59a675e1 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Fri, 18 Sep 2020 12:40:05 -0400 Subject: Fixed bug with ctx_stack_pop. Implemented dup bytecode. --- ujit_compile.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ujit_compile.c b/ujit_compile.c index 84bafe52bd..254a986d85 100644 --- a/ujit_compile.c +++ b/ujit_compile.c @@ -103,11 +103,13 @@ Return a pointer to the stack top before the pop operation https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L103 */ x86opnd_t ctx_stack_pop(ctx_t* ctx, size_t n) { - ctx->stack_diff -= n; - // SP points just above the topmost value int32_t offset = (ctx->stack_diff - 1) * 8; - return mem_opnd(64, RSI, offset); + x86opnd_t top = mem_opnd(64, RSI, offset); + + ctx->stack_diff -= n; + + return top; } /* @@ -217,6 +219,16 @@ ujit_compile_insn(rb_iseq_t *iseq, unsigned int insn_idx, unsigned int* next_uji https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L219 return code_ptr; } +void gen_dup(codeblock_t* cb, ctx_t* ctx) +{ + x86opnd_t dup_val = ctx_stack_pop(ctx, 1); + x86opnd_t loc0 = ctx_stack_push(ctx, 1); + x86opnd_t loc1 = ctx_stack_push(ctx, 1); + mov(cb, RAX, dup_val); + mov(cb, loc0, RAX); + mov(cb, loc1, RAX); +} + void gen_nop(codeblock_t* cb, ctx_t* ctx) { // Do nothing @@ -294,6 +306,7 @@ static void ujit_init() https://github.com/ruby/ruby/blob/trunk/ujit_compile.c#L306 gen_fns = rb_st_init_numtable(); // Map YARV opcodes to the corresponding codegen functions + st_insert(gen_fns, (st_data_t)BIN(dup), (st_data_t)&gen_dup); st_insert(gen_fns, (st_data_t)BIN(nop), (st_data_t)&gen_nop); st_insert(gen_fns, (st_data_t)BIN(pop), (st_data_t)&gen_pop); st_insert(gen_fns, (st_data_t)BIN(putnil), (st_data_t)&gen_putnil); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/