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

ruby-changes:74145

From: Nobuyoshi <ko1@a...>
Date: Thu, 20 Oct 2022 22:05:53 +0900 (JST)
Subject: [ruby-changes:74145] f55212bce9 (master): Move "special consts" so `Qundef` and `Qnil` differ just 1 bit

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

From f55212bce939f736559709a8cd16c409772389c8 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 20 Oct 2022 10:57:40 +0900
Subject: Move "special consts" so `Qundef` and `Qnil` differ just 1 bit

---
 include/ruby/internal/abi.h            |  2 +-
 include/ruby/internal/special_consts.h | 22 +++++++++++-----------
 ruby.c                                 |  1 +
 yjit/src/codegen.rs                    |  3 +--
 yjit/src/cruby.rs                      |  4 ++--
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/include/ruby/internal/abi.h b/include/ruby/internal/abi.h
index fe1977a9a1..d67aa0d509 100644
--- a/include/ruby/internal/abi.h
+++ b/include/ruby/internal/abi.h
@@ -24,7 +24,7 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/abi.h#L24
  * In released versions of Ruby, this number is not defined since teeny
  * versions of Ruby should guarantee ABI compatibility.
  */
-#define RUBY_ABI_VERSION 2
+#define RUBY_ABI_VERSION 3
 
 /* Windows does not support weak symbols so ruby_abi_version will not exist
  * in the shared library. */
diff --git a/include/ruby/internal/special_consts.h b/include/ruby/internal/special_consts.h
index 252f1a8ff5..a8c992ef5e 100644
--- a/include/ruby/internal/special_consts.h
+++ b/include/ruby/internal/special_consts.h
@@ -94,9 +94,9 @@ ruby_special_consts { https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/special_consts.h#L94
     RUBY_SYMBOL_FLAG,           /**< Flag to denote a static symbol. */
 #elif USE_FLONUM
     RUBY_Qfalse         = 0x00, /* ...0000 0000 */
+    RUBY_Qnil           = 0x04, /* ...0000 0100 */
     RUBY_Qtrue          = 0x14, /* ...0001 0100 */
-    RUBY_Qnil           = 0x08, /* ...0000 1000 */
-    RUBY_Qundef         = 0x34, /* ...0011 0100 */
+    RUBY_Qundef         = 0x24, /* ...0010 0100 */
     RUBY_IMMEDIATE_MASK = 0x07, /* ...0000 0111 */
     RUBY_FIXNUM_FLAG    = 0x01, /* ...xxxx xxx1 */
     RUBY_FLONUM_MASK    = 0x03, /* ...0000 0011 */
@@ -104,9 +104,9 @@ ruby_special_consts { https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/special_consts.h#L104
     RUBY_SYMBOL_FLAG    = 0x0c, /* ...xxxx 1100 */
 #else
     RUBY_Qfalse         = 0x00, /* ...0000 0000 */
-    RUBY_Qtrue          = 0x02, /* ...0000 0010 */
-    RUBY_Qnil           = 0x04, /* ...0000 0100 */
-    RUBY_Qundef         = 0x06, /* ...0000 0110 */
+    RUBY_Qnil           = 0x02, /* ...0000 0010 */
+    RUBY_Qtrue          = 0x06, /* ...0000 0110 */
+    RUBY_Qundef         = 0x0a, /* ...0000 1010 */
     RUBY_IMMEDIATE_MASK = 0x03, /* ...0000 0011 */
     RUBY_FIXNUM_FLAG    = 0x01, /* ...xxxx xxx1 */
     RUBY_FLONUM_MASK    = 0x00, /* any values ANDed with FLONUM_MASK cannot be FLONUM_FLAG */
@@ -138,19 +138,19 @@ RB_TEST(VALUE obj) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/special_consts.h#L138
     /*
      * if USE_FLONUM
      *  Qfalse:  ....0000 0000
-     *  Qnil:    ....0000 1000
-     * ~Qnil:    ....1111 0111
+     *  Qnil:    ....0000 0100
+     * ~Qnil:    ....1111 1011
      *  v        ....xxxx xxxx
      * ----------------------------
-     *  RTEST(v) ....xxxx 0xxx
+     *  RTEST(v) ....xxxx x0xx
      *
      * if ! USE_FLONUM
      *  Qfalse:  ....0000 0000
-     *  Qnil:    ....0000 0100
-     * ~Qnil:    ....1111 1011
+     *  Qnil:    ....0000 0010
+     * ~Qnil:    ....1111 1101
      *  v        ....xxxx xxxx
      * ----------------------------
-     *  RTEST(v) ....xxxx x0xx
+     *  RTEST(v) ....xxxx xx0x
      *
      *  RTEST(v) can be 0 if and only if (v == Qfalse || v == Qnil).
      */
diff --git a/ruby.c b/ruby.c
index 68da778ea6..640386fbda 100644
--- a/ruby.c
+++ b/ruby.c
@@ -64,6 +64,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby.c#L64
 
 #define singlebit_only_p(x) !((x) & ((x)-1))
 STATIC_ASSERT(Qnil_1bit_from_Qfalse, singlebit_only_p(Qnil^Qfalse));
+STATIC_ASSERT(Qundef_1bit_from_Qnil, singlebit_only_p(Qundef^Qnil));
 
 #ifndef MAXPATHLEN
 # define MAXPATHLEN 1024
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index 66750335f3..196baf9689 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -3219,8 +3219,7 @@ fn gen_branchif( https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L3219
     };
 
     // Test if any bit (outside of the Qnil bit) is on
-    // RUBY_Qfalse  /* ...0000 0000 */
-    // RUBY_Qnil    /* ...0000 1000 */
+    // See RB_TEST()
     let val_type = ctx.get_opnd_type(StackOpnd(0));
     let val_opnd = ctx.stack_pop(1);
 
diff --git a/yjit/src/cruby.rs b/yjit/src/cruby.rs
index d3e4ba4757..81db0deab3 100644
--- a/yjit/src/cruby.rs
+++ b/yjit/src/cruby.rs
@@ -597,11 +597,11 @@ where https://github.com/ruby/ruby/blob/trunk/yjit/src/cruby.rs#L597
 #[allow(non_upper_case_globals)]
 pub const Qfalse: VALUE = VALUE(0);
 #[allow(non_upper_case_globals)]
-pub const Qnil: VALUE = VALUE(8);
+pub const Qnil: VALUE = VALUE(4);
 #[allow(non_upper_case_globals)]
 pub const Qtrue: VALUE = VALUE(20);
 #[allow(non_upper_case_globals)]
-pub const Qundef: VALUE = VALUE(52);
+pub const Qundef: VALUE = VALUE(0x24);
 
 #[allow(unused)]
 mod manual_defs {
-- 
cgit v1.2.3


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

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