ruby-changes:41670
From: naruse <ko1@a...>
Date: Fri, 5 Feb 2016 15:52:40 +0900 (JST)
Subject: [ruby-changes:41670] naruse:r53744 (trunk): improve r53741
naruse 2016-02-05 15:52:41 +0900 (Fri, 05 Feb 2016) New Revision: 53744 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53744 Log: improve r53741 * Remove branching by a==0 case Before r53741: % perf stat ./miniruby -e'a=100;i=0;while i<0xfffffff;i+=1;a=(a*557+2)%100000;end' Performance counter stats for './miniruby -vea=100;i=0;while i<0xfffffff;i+=1;a=(a*557+2)%100000;end': 16412.994492 task-clock (msec) # 0.999 CPUs utilized 195 context-switches # 0.012 K/sec 2 cpu-migrations # 0.000 K/sec 876 page-faults # 0.053 K/sec 48488588328 cycles # 2.954 GHz 18464835712 stalled-cycles-frontend # 38.08% frontend cycles idle <not supported> stalled-cycles-backend 85665428518 instructions # 1.77 insns per cycle # 0.22 stalled cycles # per insn 10207419707 branches # 621.911 M/sec 6334713 branch-misses # 0.06% of all branches 16.426858699 seconds time elapsed After this: % perf stat ./miniruby -ve'a=100;i=0;while i<0xfffffff;i+=1;a=(a*557+2)%100000;end' Performance counter stats for './miniruby -vea=100;i=0;while i<0xfffffff;i+=1;a=(a*557+2)%100000;end': 13363.540634 task-clock (msec) # 0.999 CPUs utilized 137 context-switches # 0.010 K/sec 2 cpu-migrations # 0.000 K/sec 874 page-faults # 0.065 K/sec 39477429278 cycles # 2.954 GHz 14615402375 stalled-cycles-frontend # 37.02% frontend cycles idle <not supported> stalled-cycles-backend 83514678452 instructions # 2.12 insns per cycle # 0.18 stalled cycles per insn 9401528135 branches # 703.521 M/sec 432567 branch-misses # 0.00% of all branches 13.371484310 seconds time elapsed Modified files: trunk/insns.def Index: insns.def =================================================================== --- insns.def (revision 53743) +++ insns.def (revision 53744) @@ -1431,29 +1431,24 @@ opt_mult https://github.com/ruby/ruby/blob/trunk/insns.def#L1431 if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED_P(BOP_MULT, FIXNUM_REDEFINED_OP_FLAG)) { long a = FIX2LONG(recv); - if (a == 0) { - val = recv; - } - else { #ifdef HAVE_INT128_T - VALUE rb_int128t2big(int128_t n); - int128_t r = (int128_t)a * FIX2LONG(obj); - if (RB_FIXABLE(r)) { + VALUE rb_int128t2big(int128_t n); + int128_t r = (int128_t)a * (int128_t)FIX2LONG(obj); + if (RB_FIXABLE(r)) { val = LONG2FIX((long)r); - } - else { + } + else { val = rb_int128t2big(r); - } + } #else - long b = FIX2LONG(obj); - if (MUL_OVERFLOW_FIXNUM_P(a, b)) { + long b = FIX2LONG(obj); + if (MUL_OVERFLOW_FIXNUM_P(a, b)) { val = rb_big_mul(rb_int2big(a), rb_int2big(b)); - } - else { + } + else { val = LONG2FIX(a * b); - } -#endif } +#endif } else if (FLONUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED_P(BOP_MULT, FLOAT_REDEFINED_OP_FLAG)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/