diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-08-02 23:25:38 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2019-08-02 23:25:38 +0900 |
commit | 086ffe72c711179c30a773027e0b4113e908d399 (patch) | |
tree | 1ed14b8037dfe0f60d858ec5a1fa019bd1e592dc | |
parent | e9e17cbc051e894dfd27eda5feca2939f65552db (diff) |
Revert "Revert "Add a specialized instruction for `.nil?` calls""
This reverts commit a0980f2446c0db735b8ffeb37e241370c458a626.
Retry for macOS Mojave.
-rw-r--r-- | benchmark/nil_p.yml | 9 | ||||
-rw-r--r-- | compile.c | 1 | ||||
-rw-r--r-- | defs/id.def | 1 | ||||
-rw-r--r-- | insns.def | 14 | ||||
-rw-r--r-- | object.c | 2 | ||||
-rw-r--r-- | vm.c | 1 | ||||
-rw-r--r-- | vm_core.h | 1 | ||||
-rw-r--r-- | vm_insnhelper.c | 20 |
8 files changed, 48 insertions, 1 deletions
diff --git a/benchmark/nil_p.yml b/benchmark/nil_p.yml new file mode 100644 index 0000000000..79ba4f2177 --- /dev/null +++ b/benchmark/nil_p.yml @@ -0,0 +1,9 @@ +prelude: | + class Niller; def nil?; true; end; end + xnil, notnil = nil, Object.new + niller = Niller.new +benchmark: + - xnil.nil? + - notnil.nil? + - niller.nil? +loop_count: 10000000 @@ -3255,6 +3255,7 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj) case idLength: SP_INSN(length); return COMPILE_OK; case idSize: SP_INSN(size); return COMPILE_OK; case idEmptyP: SP_INSN(empty_p);return COMPILE_OK; + case idNilP: SP_INSN(nil_p); return COMPILE_OK; case idSucc: SP_INSN(succ); return COMPILE_OK; case idNot: SP_INSN(not); return COMPILE_OK; } diff --git a/defs/id.def b/defs/id.def index 66dfdf915a..25677ffdc2 100644 --- a/defs/id.def +++ b/defs/id.def @@ -3,6 +3,7 @@ firstline, predefined = __LINE__+1, %[\ max min freeze + nil? inspect intern object_id @@ -808,6 +808,20 @@ opt_str_freeze } } +/* optimized nil? */ +DEFINE_INSN +opt_nil_p +(CALL_INFO ci, CALL_CACHE cc) +(VALUE recv) +(VALUE val) +{ + val = vm_opt_nil_p(ci, cc, recv); + + if (val == Qundef) { + CALL_SIMPLE_METHOD(); + } +} + DEFINE_INSN opt_str_uminus (VALUE str, CALL_INFO ci, CALL_CACHE cc) @@ -1687,7 +1687,7 @@ rb_true(VALUE obj) */ -static VALUE +MJIT_FUNC_EXPORTED VALUE rb_false(VALUE obj) { return Qfalse; @@ -1656,6 +1656,7 @@ vm_init_redefined_flag(void) OP(Call, CALL), (C(Proc)); OP(And, AND), (C(Integer)); OP(Or, OR), (C(Integer)); + OP(NilP, NIL_P), (C(NilClass)); #undef C #undef OP } @@ -550,6 +550,7 @@ enum ruby_basic_operators { BOP_LENGTH, BOP_SIZE, BOP_EMPTY_P, + BOP_NIL_P, BOP_SUCC, BOP_GT, BOP_GE, diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 57f6d91e88..1875d35de1 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -4228,6 +4228,26 @@ vm_opt_empty_p(VALUE recv) } } +VALUE rb_false(VALUE obj); + +static VALUE +vm_opt_nil_p(CALL_INFO ci, CALL_CACHE cc, VALUE recv) +{ + if (recv == Qnil) { + if (BASIC_OP_UNREDEFINED_P(BOP_NIL_P, NIL_REDEFINED_OP_FLAG)) { + return Qtrue; + } else { + return Qundef; + } + } else { + if (vm_method_cfunc_is(ci, cc, recv, rb_false)) { + return Qfalse; + } else { + return Qundef; + } + } +} + static VALUE fix_succ(VALUE x) { |