ruby-changes:68563
From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:08:40 +0900 (JST)
Subject: [ruby-changes:68563] 251531bdf0 (master): Reimplement Alan's pop instruction with the new assembler
https://git.ruby-lang.org/ruby.git/commit/?id=251531bdf0 From 251531bdf06b03a6531ca6863d19c693fc62631a Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Thu, 10 Sep 2020 11:09:45 -0400 Subject: Reimplement Alan's pop instruction with the new assembler --- iseq.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/iseq.c b/iseq.c index 03f322e514..51d923cf8e 100644 --- a/iseq.c +++ b/iseq.c @@ -3178,6 +3178,14 @@ typedef struct insn_data_struct { https://github.com/ruby/ruby/blob/trunk/iseq.c#L3178 } insn_data_t; static insn_data_t insn_data[VM_INSTRUCTION_SIZE/2]; + + + +#include "ujit_asm.h" + + + + void rb_vm_encoded_insn_data_table_init(void) { @@ -3210,6 +3218,8 @@ rb_vm_encoded_insn_data_table_init(void) https://github.com/ruby/ruby/blob/trunk/iseq.c#L3218 st_add_direct(encoded_insn_data, key2, (st_data_t)&insn_data[insn]); } + + /* native_pop_code = mmap(0, 4096, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, 0, 0); if (native_pop_code == MAP_FAILED) rb_bug("mmap failed"); uint8_t *head = native_pop_code; @@ -3225,11 +3235,27 @@ rb_vm_encoded_insn_data_table_init(void) https://github.com/ruby/ruby/blob/trunk/iseq.c#L3235 head += sizeof(handmade_pop); memcpy(head, ujit_post_call_bytes, sizeof(ujit_post_call_bytes)); // TODO this is small enough to fit in the page we allocated but that can change + */ + + + // I decided to start by replicating Alan's code above using the new assembler + codeblock_t block; + codeblock_t* cb = █ + cb_init(cb, 4096); + // Write the pre call bytes + cb_write_prologue(cb); + sub(cb, mem_opnd(64, RDI, 8), imm_opnd(8)); // decrement SP + add(cb, RSI, imm_opnd(8)); // increment PC + mov(cb, mem_opnd(64, RDI, 0), RSI); // write new PC to EC object, not necessary for pop bytecode? + mov(cb, RAX, RSI); // return new PC + // Write the post call bytes + cb_write_epilogue(cb); + native_pop_code = cb_get_ptr(cb, 0); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/