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

ruby-changes:73234

From: Zack <ko1@a...>
Date: Tue, 30 Aug 2022 01:03:28 +0900 (JST)
Subject: [ruby-changes:73234] 6ab71a8598 (master): Port gen_checktype to the new IR assembler backend (https://github.com/Shopify/ruby/pull/343)

https://git.ruby-lang.org/ruby.git/commit/?id=6ab71a8598

From 6ab71a8598c6eece25975ca262eb880462e47b06 Mon Sep 17 00:00:00 2001
From: Zack Deveau <zack.ref@g...>
Date: Wed, 27 Jul 2022 14:31:41 -0400
Subject: Port gen_checktype to the new IR assembler backend
 (https://github.com/Shopify/ruby/pull/343)

---
 bootstraptest/test_yjit.rb |  8 ++++++++
 yjit/src/codegen.rs        | 39 +++++++++++++++++----------------------
 2 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 966a5f3002..d82f3de95e 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -3066,3 +3066,11 @@ assert_equal '10', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L3066
 
   a.length
 }
+
+# checktype
+assert_equal 'false', %q{
+    def function()
+        [1, 2] in [Integer, String]
+    end
+    function()
+}
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index cb4b23e26e..b34cc7409a 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -2217,11 +2217,10 @@ fn gen_defined( https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L2217
     KeepCompiling
 }
 
-/*
 fn gen_checktype(
     jit: &mut JITState,
     ctx: &mut Context,
-    cb: &mut CodeBlock,
+    asm: &mut Assembler,
     _ocb: &mut OutlinedCb,
 ) -> CodegenStatus {
     let type_val = jit_get_arg(jit, 0).as_u32();
@@ -2235,42 +2234,37 @@ fn gen_checktype( https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L2234
         match val_type.known_value_type() {
             Some(value_type) => {
                 if value_type == type_val {
-                    jit_putobject(jit, ctx, cb, Qtrue);
+                    jit_putobject(jit, ctx, asm, Qtrue);
                     return KeepCompiling;
                 } else {
-                    jit_putobject(jit, ctx, cb, Qfalse);
+                    jit_putobject(jit, ctx, asm, Qfalse);
                     return KeepCompiling;
                 }
             },
             _ => (),
         }
 
-        mov(cb, REG0, val);
-        mov(cb, REG1, uimm_opnd(Qfalse.as_u64()));
-
-        let ret = cb.new_label("ret".to_string());
+        let ret = asm.new_label("ret");
 
         if !val_type.is_heap() {
             // if (SPECIAL_CONST_P(val)) {
             // Return Qfalse via REG1 if not on heap
-            test(cb, REG0, uimm_opnd(RUBY_IMMEDIATE_MASK as u64));
-            jnz_label(cb, ret);
-            cmp(cb, REG0, uimm_opnd(Qnil.as_u64()));
-            jbe_label(cb, ret);
+            asm.test(val, Opnd::UImm(RUBY_IMMEDIATE_MASK as u64));
+            asm.jnz(ret);
+            asm.cmp(val, Opnd::UImm(Qnil.into()));
+            asm.jbe(ret);
         }
 
         // Check type on object
-        mov(cb, REG0, mem_opnd(64, REG0, RUBY_OFFSET_RBASIC_FLAGS));
-        and(cb, REG0, uimm_opnd(RUBY_T_MASK as u64));
-        cmp(cb, REG0, uimm_opnd(type_val as u64));
-        mov(cb, REG0, uimm_opnd(Qtrue.as_u64()));
-        // REG1 contains Qfalse from above
-        cmove(cb, REG1, REG0);
+        let object_type = asm.and(
+            Opnd::mem(64, val, RUBY_OFFSET_RBASIC_FLAGS),
+            Opnd::UImm(RUBY_T_MASK.into()));
+        asm.cmp(object_type, Opnd::UImm(type_val.into()));
+        let ret_opnd = asm.csel_e(Opnd::UImm(Qfalse.into()), Opnd::UImm(Qtrue.into()));
 
-        cb.write_label(ret);
+        asm.write_label(ret);
         let stack_ret = ctx.stack_push(Type::UnknownImm);
-        mov(cb, stack_ret, REG1);
-        cb.link_labels();
+        asm.mov(stack_ret, ret_opnd);
 
         KeepCompiling
     } else {
@@ -2278,6 +2272,7 @@ fn gen_checktype( https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L2272
     }
 }
 
+/*
 fn gen_concatstrings(
     jit: &mut JITState,
     ctx: &mut Context,
@@ -5979,7 +5974,7 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> { https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L5974
         YARVINSN_duphash => Some(gen_duphash),
         YARVINSN_newarray => Some(gen_newarray),
         YARVINSN_duparray => Some(gen_duparray),
-        //YARVINSN_checktype => Some(gen_checktype),
+        YARVINSN_checktype => Some(gen_checktype),
         YARVINSN_opt_lt => Some(gen_opt_lt),
         /*
         YARVINSN_opt_le => Some(gen_opt_le),
-- 
cgit v1.2.1


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

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