From 1f57a334daa4cd27decdc756cd709163e00e6a0c Mon Sep 17 00:00:00 2001
From: naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Fri, 5 Feb 2016 04:31:27 +0000
Subject: * insns.def (opt_mult): Use int128_t for overflow detection.

* bignum.c (rb_uint128t2big): added for opt_mult.

* bignum.c (rb_uint128t2big): added for rb_uint128t2big..

* configure.in: define int128_t, uint128_t and related MACROs.
  Initially introduced by r41379 but reverted by r50749.

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

(limited to 'insns.def')

diff --git a/insns.def b/insns.def
index ef0665c50c..72ce1d998f 100644
--- a/insns.def
+++ b/insns.def
@@ -1430,20 +1430,29 @@ opt_mult
 {
     if (FIXNUM_2_P(recv, obj) &&
 	BASIC_OP_UNREDEFINED_P(BOP_MULT, FIXNUM_REDEFINED_OP_FLAG)) {
-	long a, b;
-
-	a = FIX2LONG(recv);
+	long a = FIX2LONG(recv);
 	if (a == 0) {
 	    val = recv;
 	}
 	else {
-	    b = FIX2LONG(obj);
-            if (MUL_OVERFLOW_FIXNUM_P(a, b)) {
+#ifdef HAVE_INT128_T
+	    VALUE rb_int128t2big(int128_t n);
+	    int128_t r = (int128_t)a * FIX2LONG(obj);
+	    if (RB_FIXABLE(r)) {
+		val = LONG2FIX((long)r);
+	    }
+	    else {
+		val = rb_int128t2big(r);
+	    }
+#else
+	    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
 	}
     }
     else if (FLONUM_2_P(recv, obj) &&
-- 
cgit v1.2.3

