ruby-changes:68806
From: Max <ko1@a...>
Date: Thu, 21 Oct 2021 08:13:38 +0900 (JST)
Subject: [ruby-changes:68806] 3a365afaf5 (master): Support memory operands to push
https://git.ruby-lang.org/ruby.git/commit/?id=3a365afaf5 From 3a365afaf555e3c1b6758df4431b8f659ff310a2 Mon Sep 17 00:00:00 2001 From: Max Bernstein <emacs@f...> Date: Thu, 25 Feb 2021 23:22:01 -0800 Subject: Support memory operands to push --- ujit_asm.c | 21 +++++++++++++-------- ujit_asm.h | 2 +- ujit_asm_tests.c | 5 +++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ujit_asm.c b/ujit_asm.c index 3355acae90..8eb5da7593 100644 --- a/ujit_asm.c +++ b/ujit_asm.c @@ -1452,17 +1452,22 @@ void popfq(codeblock_t* cb) https://github.com/ruby/ruby/blob/trunk/ujit_asm.c#L1452 cb_write_bytes(cb, 2, 0x48, 0x9D); } -/// push - Push a register on the stack -void push(codeblock_t* cb, x86opnd_t reg) +/// push - Push an operand on the stack +void push(codeblock_t* cb, x86opnd_t opnd) { - assert (reg.num_bits == 64); + assert (opnd.num_bits == 64); - //cb.writeASM("push", reg); + //cb.writeASM("push", opnd); - if (rex_needed(reg)) - cb_write_rex(cb, false, 0, 0, reg.as.reg.reg_no); - - cb_write_opcode(cb, 0x50, reg); + if (opnd.type == OPND_REG) { + if (rex_needed(opnd)) + cb_write_rex(cb, false, 0, 0, opnd.as.reg.reg_no); + cb_write_opcode(cb, 0x50, opnd); + } else if (opnd.type == OPND_MEM) { + cb_write_rm(cb, false, false, NO_OPND, opnd, 6, 1, 0xFF); + } else { + assert(false && "unexpected operand type"); + } } /// pushfq - Push the flags register (64-bit) diff --git a/ujit_asm.h b/ujit_asm.h index 1b7030dfb6..282cd294a9 100644 --- a/ujit_asm.h +++ b/ujit_asm.h @@ -367,7 +367,7 @@ void not(codeblock_t* cb, x86opnd_t opnd); https://github.com/ruby/ruby/blob/trunk/ujit_asm.h#L367 void or(codeblock_t* cb, x86opnd_t opnd0, x86opnd_t opnd1); void pop(codeblock_t* cb, x86opnd_t reg); void popfq(codeblock_t* cb); -void push(codeblock_t* cb, x86opnd_t reg); +void push(codeblock_t* cb, x86opnd_t opnd); void pushfq(codeblock_t* cb); void ret(codeblock_t* cb); void sal(codeblock_t* cb, x86opnd_t opnd0, x86opnd_t opnd1); diff --git a/ujit_asm_tests.c b/ujit_asm_tests.c index 7569032019..10e9845eaf 100644 --- a/ujit_asm_tests.c +++ b/ujit_asm_tests.c @@ -284,6 +284,11 @@ void run_tests() https://github.com/ruby/ruby/blob/trunk/ujit_asm_tests.c#L284 cb_set_pos(cb, 0); push(cb, RAX); check_bytes(cb, "50"); cb_set_pos(cb, 0); push(cb, RBX); check_bytes(cb, "53"); cb_set_pos(cb, 0); push(cb, R12); check_bytes(cb, "4154"); + cb_set_pos(cb, 0); push(cb, mem_opnd(64, RAX, 0)); check_bytes(cb, "FF30"); + cb_set_pos(cb, 0); push(cb, mem_opnd(64, R8, 0)); check_bytes(cb, "41FF30"); + cb_set_pos(cb, 0); push(cb, mem_opnd(64, R8, 3)); check_bytes(cb, "41FF7003"); + cb_set_pos(cb, 0); push(cb, mem_opnd_sib(64, RAX, RCX, 8, 3)); check_bytes(cb, "FF74C803"); + cb_set_pos(cb, 0); push(cb, mem_opnd_sib(64, R8, RCX, 8, 3)); check_bytes(cb, "41FF74C803"); // ret cb_set_pos(cb, 0); ret(cb); check_bytes(cb, "C3"); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/