diff options
author | Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> | 2020-09-10 11:09:45 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:23 -0400 |
commit | 251531bdf06b03a6531ca6863d19c693fc62631a (patch) | |
tree | a616ee2ec83109432043205d3d4812a3288d3f5a /iseq.c | |
parent | efcaa49a7be1ea016a57bed5080c02df3f88f884 (diff) |
Reimplement Alan's pop instruction with the new assembler
Diffstat (limited to 'iseq.c')
-rw-r--r-- | iseq.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -3178,6 +3178,14 @@ typedef struct insn_data_struct { } 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) 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) 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); |