[前][次][番号順一覧][スレッド一覧]

ruby-changes:68665

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:11 +0900 (JST)
Subject: [ruby-changes:68665] 8ae354e9be (master): Implemented opt_lt. Prelude to branch instructions.

https://git.ruby-lang.org/ruby.git/commit/?id=8ae354e9be

From 8ae354e9bedbe5995e97206b170f3e406fc5b617 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Fri, 11 Dec 2020 13:22:37 -0500
Subject: Implemented opt_lt. Prelude to branch instructions.

---
 ujit_codegen.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/ujit_codegen.c b/ujit_codegen.c
index 4897e38cde..ec55600bae 100644
--- a/ujit_codegen.c
+++ b/ujit_codegen.c
@@ -496,6 +496,47 @@ gen_setinstancevariable(codeblock_t* cb, codeblock_t* ocb, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L496
     return true;
 }
 
+static bool
+gen_opt_lt(codeblock_t* cb, codeblock_t* ocb, ctx_t* ctx)
+{
+    // Create a size-exit to fall back to the interpreter
+    // Note: we generate the side-exit before popping operands from the stack
+    uint8_t* side_exit = ujit_side_exit(ocb, ctx, ctx->pc);
+
+    // TODO: make a helper function for guarding on op-not-redefined
+    // Make sure that minus isn't redefined for integers
+    mov(cb, RAX, const_ptr_opnd(ruby_current_vm_ptr));
+    test(
+        cb,
+        member_opnd_idx(RAX, rb_vm_t, redefined_flag, BOP_LT),
+        imm_opnd(INTEGER_REDEFINED_OP_FLAG)
+    );
+    jnz_ptr(cb, side_exit);
+
+    // Get the operands and destination from the stack
+    x86opnd_t arg1 = ctx_stack_pop(ctx, 1);
+    x86opnd_t arg0 = ctx_stack_pop(ctx, 1);
+
+    // If not fixnums, fall back
+    test(cb, arg0, imm_opnd(RUBY_FIXNUM_FLAG));
+    jz_ptr(cb, side_exit);
+    test(cb, arg1, imm_opnd(RUBY_FIXNUM_FLAG));
+    jz_ptr(cb, side_exit);
+
+    // Compare the arguments
+    mov(cb, REG0, arg0);
+    cmp(cb, REG0, arg1);
+    mov(cb, REG0, imm_opnd(Qfalse));
+    mov(cb, REG1, imm_opnd(Qtrue));
+    cmovl(cb, REG0, REG1);
+
+    // Push the output on the stack
+    x86opnd_t dst = ctx_stack_push(ctx, 1);
+    mov(cb, dst, REG0);
+
+    return true;
+}
+
 static bool
 gen_opt_minus(codeblock_t* cb, codeblock_t* ocb, ctx_t* ctx)
 {
@@ -531,7 +572,7 @@ gen_opt_minus(codeblock_t* cb, codeblock_t* ocb, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L572
 
     // Push the output on the stack
     x86opnd_t dst = ctx_stack_push(ctx, 1);
-    mov(cb, dst, RAX);
+    mov(cb, dst, REG0);
 
     return true;
 }
@@ -571,7 +612,7 @@ gen_opt_plus(codeblock_t* cb, codeblock_t* ocb, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L612
 
     // Push the output on the stack
     x86opnd_t dst = ctx_stack_push(ctx, 1);
-    mov(cb, dst, RAX);
+    mov(cb, dst, REG0);
 
     return true;
 }
@@ -883,6 +924,7 @@ ujit_init_codegen(void) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L924
     st_insert(gen_fns, (st_data_t)BIN(setlocal_WC_0), (st_data_t)&gen_setlocal_wc0);
     st_insert(gen_fns, (st_data_t)BIN(getinstancevariable), (st_data_t)&gen_getinstancevariable);
     st_insert(gen_fns, (st_data_t)BIN(setinstancevariable), (st_data_t)&gen_setinstancevariable);
+    st_insert(gen_fns, (st_data_t)BIN(opt_lt), (st_data_t)&gen_opt_lt);
     st_insert(gen_fns, (st_data_t)BIN(opt_minus), (st_data_t)&gen_opt_minus);
     st_insert(gen_fns, (st_data_t)BIN(opt_plus), (st_data_t)&gen_opt_plus);
     st_insert(gen_fns, (st_data_t)BIN(opt_send_without_block), (st_data_t)&gen_opt_send_without_block);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]