From 016e6db57e2fb9a8623493399efe2089b2870813 Mon Sep 17 00:00:00 2001
From: naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Fri, 5 Feb 2016 06:52:41 +0000
Subject: 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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
 insns.def | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

(limited to 'insns.def')

diff --git a/insns.def b/insns.def
index 72ce1d998f..506bbe21a7 100644
--- a/insns.def
+++ b/insns.def
@@ -1431,29 +1431,24 @@ opt_mult
     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)) {
-- 
cgit v1.2.3

