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?= Date: Tue, 19 Nov 2019 13:16:04 +0900 Subject: [PATCH] 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 --- vm_insnhelper.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 77f4d701d6..e3087d321c 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -4453,7 +4453,7 @@ vm_opt_and(VALUE recv, VALUE obj) { 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) { 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 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); 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) 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); }