make opt_case_dispatch leaf
This instruction can be written without rb_funcall. It not only boosts performance of case statements, but also makes room of future JIT improvements. Because opt_case_dispatch is about optimization this should not be a bad thing to have. ---- trunk: ruby 2.6.0dev (2018-09-05 trunk 64634) [x86_64-darwin15] ours: ruby 2.6.0dev (2018-09-12 leaf-insn 64688) [x86_64-darwin15] last_commit=make opt_case_dispatch leaf Calculating ------------------------------------- trunk ours vm2_case_lit 1.366 2.012 i/s - 1.000 times in 0.731839s 0.497008s Comparison: vm2_case_lit ours: 2.0 i/s trunk: 1.4 i/s - 1.47x slower git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bddc28b2ae
commit
33c8171c65
56
compile.c
56
compile.c
@ -1743,27 +1743,57 @@ iseq_set_local_table(rb_iseq_t *iseq, const ID *tbl)
|
|||||||
static int
|
static int
|
||||||
cdhash_cmp(VALUE val, VALUE lit)
|
cdhash_cmp(VALUE val, VALUE lit)
|
||||||
{
|
{
|
||||||
if (val == lit) return 0;
|
int tval, tlit;
|
||||||
if (SPECIAL_CONST_P(lit)) {
|
|
||||||
return val != lit;
|
if (val == lit) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if (SPECIAL_CONST_P(val) || BUILTIN_TYPE(val) != BUILTIN_TYPE(lit)) {
|
else if ((tlit = OBJ_BUILTIN_TYPE(lit)) == -1) {
|
||||||
return -1;
|
return val != lit;
|
||||||
}
|
}
|
||||||
if (BUILTIN_TYPE(lit) == T_STRING) {
|
else if ((tval = OBJ_BUILTIN_TYPE(val)) == -1) {
|
||||||
return rb_str_hash_cmp(lit, val);
|
return -1;
|
||||||
|
}
|
||||||
|
else if (tlit != tval) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (tlit == T_SYMBOL) {
|
||||||
|
return val != lit;
|
||||||
|
}
|
||||||
|
else if (tlit == T_STRING) {
|
||||||
|
return rb_str_hash_cmp(lit, val);
|
||||||
|
}
|
||||||
|
else if (tlit == T_BIGNUM) {
|
||||||
|
long x = FIX2LONG(rb_big_cmp(lit, val));
|
||||||
|
|
||||||
|
/* Given lit and val are both Bignum, x must be -1, 0, 1.
|
||||||
|
* There is no need to call rb_fix2int here. */
|
||||||
|
RUBY_ASSERT((x == 1) || (x == 0) || (x == -1));
|
||||||
|
return (int)x;
|
||||||
|
}
|
||||||
|
else if (tlit == T_FLOAT) {
|
||||||
|
return rb_float_cmp(lit, val);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
UNREACHABLE_RETURN(-1);
|
||||||
}
|
}
|
||||||
return !rb_eql(lit, val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static st_index_t
|
static st_index_t
|
||||||
cdhash_hash(VALUE a)
|
cdhash_hash(VALUE a)
|
||||||
{
|
{
|
||||||
if (SPECIAL_CONST_P(a)) return (st_index_t)a;
|
switch (OBJ_BUILTIN_TYPE(a)) {
|
||||||
if (RB_TYPE_P(a, T_STRING)) return rb_str_hash(a);
|
case -1:
|
||||||
{
|
case T_SYMBOL:
|
||||||
VALUE hval = rb_hash(a);
|
return (st_index_t)a;
|
||||||
return (st_index_t)FIX2LONG(hval);
|
case T_STRING:
|
||||||
|
return rb_str_hash(a);
|
||||||
|
case T_BIGNUM:
|
||||||
|
return FIX2LONG(rb_big_hash(a));
|
||||||
|
case T_FLOAT:
|
||||||
|
return rb_dbl_long_hash(RFLOAT_VALUE(a));
|
||||||
|
default:
|
||||||
|
UNREACHABLE_RETURN(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1020,10 +1020,6 @@ opt_case_dispatch
|
|||||||
(CDHASH hash, OFFSET else_offset)
|
(CDHASH hash, OFFSET else_offset)
|
||||||
(..., VALUE key)
|
(..., VALUE key)
|
||||||
()
|
()
|
||||||
/* Case dispatch involves hash lookup, which inevitably compares
|
|
||||||
* several objects each other. The same discussion to
|
|
||||||
* opt_newarray_max also goes here. */
|
|
||||||
// attr bool leaf = false; /* has rb_any_cmp() */
|
|
||||||
// attr rb_snum_t sp_inc = -1;
|
// attr rb_snum_t sp_inc = -1;
|
||||||
{
|
{
|
||||||
OFFSET dst = vm_case_dispatch(hash, else_offset, key);
|
OFFSET dst = vm_case_dispatch(hash, else_offset, key);
|
||||||
|
@ -3355,7 +3355,7 @@ vm_case_dispatch(CDHASH hash, OFFSET else_offset, VALUE key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (st_lookup(RHASH_TBL_RAW(hash), key, &val)) {
|
if (st_lookup(RHASH_TBL_RAW(hash), key, &val)) {
|
||||||
return FIX2INT((VALUE)val);
|
return FIX2LONG((VALUE)val);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return else_offset;
|
return else_offset;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user