1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
卜部昌平 2019-11-19 13:16:04 +09:00
parent 75e8dd58f6
commit f6239ce0fc

View file

@ -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);
}