Project

General

Profile

Feature #15902 ยป 0001-Add-a-specialized-instruction-for-.nil-calls.patch

tenderlovemaking (Aaron Patterson), 06/05/2019 04:28 PM

View differences:

benchmark/nil_p.yml
1
prelude: |
2
  class Niller; def nil?; true; end; end
3
  xnil, notnil = nil, Object.new
4
  niller = Niller.new
5
benchmark:
6
  - xnil.nil?
7
  - notnil.nil?
8
  - niller.nil?
9
loop_count: 10000000
compile.c
3251 3251
		  case idLength: SP_INSN(length); return COMPILE_OK;
3252 3252
		  case idSize:	 SP_INSN(size);	  return COMPILE_OK;
3253 3253
		  case idEmptyP: SP_INSN(empty_p);return COMPILE_OK;
3254
		  case idNilP:   SP_INSN(nil_p);  return COMPILE_OK;
3254 3255
		  case idSucc:	 SP_INSN(succ);	  return COMPILE_OK;
3255 3256
		  case idNot:	 SP_INSN(not);	  return COMPILE_OK;
3256 3257
		}
defs/id.def
3 3
  max
4 4
  min
5 5
  freeze
6
  nil?
6 7
  inspect
7 8
  intern
8 9
  object_id
insns.def
808 808
    }
809 809
}
810 810

  
811
/* optimized nil? */
812
DEFINE_INSN
813
opt_nil_p
814
(CALL_INFO ci, CALL_CACHE cc)
815
(VALUE recv)
816
(VALUE val)
817
{
818
    val = vm_opt_nil_p(ci, cc, recv);
819

  
820
    if (val == Qundef) {
821
        CALL_SIMPLE_METHOD();
822
    }
823
}
824

  
811 825
DEFINE_INSN
812 826
opt_str_uminus
813 827
(VALUE str, CALL_INFO ci, CALL_CACHE cc)
object.c
1664 1664
 */
1665 1665

  
1666 1666

  
1667
static VALUE
1667
VALUE
1668 1668
rb_false(VALUE obj)
1669 1669
{
1670 1670
    return Qfalse;
vm.c
1657 1657
    OP(Call, CALL), (C(Proc));
1658 1658
    OP(And, AND), (C(Integer));
1659 1659
    OP(Or, OR), (C(Integer));
1660
    OP(NilP, NIL_P), (C(NilClass));
1660 1661
#undef C
1661 1662
#undef OP
1662 1663
}
vm_core.h
547 547
    BOP_LENGTH,
548 548
    BOP_SIZE,
549 549
    BOP_EMPTY_P,
550
    BOP_NIL_P,
550 551
    BOP_SUCC,
551 552
    BOP_GT,
552 553
    BOP_GE,
vm_insnhelper.c
4239 4239
    }
4240 4240
}
4241 4241

  
4242
VALUE rb_false(VALUE obj);
4243

  
4244
static VALUE
4245
vm_opt_nil_p(CALL_INFO ci, CALL_CACHE cc, VALUE recv)
4246
{
4247
    if (recv == Qnil) {
4248
        if (BASIC_OP_UNREDEFINED_P(BOP_NIL_P, NIL_REDEFINED_OP_FLAG)) {
4249
            return Qtrue;
4250
        } else {
4251
            return Qundef;
4252
        }
4253
    } else {
4254
        if (vm_method_cfunc_is(ci, cc, recv, rb_false)) {
4255
            return Qfalse;
4256
        } else {
4257
            return Qundef;
4258
        }
4259
    }
4260
}
4261

  
4242 4262
static VALUE
4243 4263
fix_succ(VALUE x)
4244 4264
{
4245
-