ruby-changes:58838
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 19 Nov 2019 13:57:13 +0900 (JST)
Subject: [ruby-changes:58838] f6239ce0fc (master): peep-hole optimize VM instructions
https://git.ruby-lang.org/ruby.git/commit/?id=f6239ce0fc From f6239ce0fc906c9d407e7da33f447575670a79bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Tue, 19 Nov 2019 13:16:04 +0900 Subject: peep-hole optimize VM instructions Some minor optimizations. Calculating ------------------------------------- ours trunk vm2_regexp 8.479M 8.346M i/s - 6.000M times in 0.707612s 0.718916s vm2_regexp_invert 8.605M 8.350M i/s - 6.000M times in 0.697298s 0.718576s Comparison: vm2_regexp ours: 8479223.3 i/s trunk: 8345893.8 i/s - 1.02x slower vm2_regexp_invert ours: 8604647.4 i/s trunk: 8349852.8 i/s - 1.03x slower Calculating ------------------------------------- ours+jit trunk+jit Optcarrot Lan_Master.nes 68.603 64.167 fps Comparison: Optcarrot Lan_Master.nes ours+jit: 68.6 fps trunk+jit: 64.2 fps - 1.07x slower diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 77f4d70..e3087d3 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -4453,7 +4453,7 @@ vm_opt_and(VALUE recv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L4453 { if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED_P(BOP_AND, INTEGER_REDEFINED_OP_FLAG)) { - return LONG2NUM(FIX2LONG(recv) & FIX2LONG(obj)); + return (recv & obj) | 1; } else { return Qundef; @@ -4465,7 +4465,7 @@ vm_opt_or(VALUE recv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L4465 { if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED_P(BOP_OR, INTEGER_REDEFINED_OP_FLAG)) { - return LONG2NUM(FIX2LONG(recv) | FIX2LONG(obj)); + return recv | obj; } else { return Qundef; @@ -4476,7 +4476,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L4476 vm_opt_aref(VALUE recv, VALUE obj) { if (SPECIAL_CONST_P(recv)) { - if (FIXNUM_P(recv) && FIXNUM_P(obj) && + if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED_P(BOP_AREF, INTEGER_REDEFINED_OP_FLAG)) { return rb_fix_aref(recv, obj); } @@ -4591,21 +4591,15 @@ VALUE rb_false(VALUE obj); https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L4591 static VALUE vm_opt_nil_p(CALL_DATA cd, VALUE recv) { - if (recv == Qnil) { - if (BASIC_OP_UNREDEFINED_P(BOP_NIL_P, NIL_REDEFINED_OP_FLAG)) { - return Qtrue; - } - else { - return Qundef; - } + if (recv == Qnil && + BASIC_OP_UNREDEFINED_P(BOP_NIL_P, NIL_REDEFINED_OP_FLAG)) { + return Qtrue; + } + else if (vm_method_cfunc_is(cd, recv, rb_false)) { + return Qfalse; } else { - if (vm_method_cfunc_is(cd, recv, rb_false)) { - return Qfalse; - } - else { - return Qundef; - } + return Qundef; } } @@ -4670,12 +4664,15 @@ vm_opt_not(CALL_DATA cd, VALUE recv) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L4664 static VALUE vm_opt_regexpmatch2(VALUE recv, VALUE obj) { - if (CLASS_OF(recv) == rb_cString && + if (SPECIAL_CONST_P(recv)) { + return Qundef; + } + else if (RBASIC_CLASS(recv) == rb_cString && CLASS_OF(obj) == rb_cRegexp && BASIC_OP_UNREDEFINED_P(BOP_MATCH, STRING_REDEFINED_OP_FLAG)) { return rb_reg_match(obj, recv); } - else if (CLASS_OF(recv) == rb_cRegexp && + else if (RBASIC_CLASS(recv) == rb_cRegexp && BASIC_OP_UNREDEFINED_P(BOP_MATCH, REGEXP_REDEFINED_OP_FLAG)) { return rb_reg_match(recv, obj); } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/