aboutsummaryrefslogtreecommitdiffstats
path: root/insns.def
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-05 04:31:27 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-05 04:31:27 +0000
commit1f57a334daa4cd27decdc756cd709163e00e6a0c (patch)
tree9bdb85c498731821aa32bddb893bf0e93c30548a /insns.def
parentb658249cef3c0032be91e499dfc04cd00642d354 (diff)
downloadruby-1f57a334daa4cd27decdc756cd709163e00e6a0c.tar.gz
* 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
Diffstat (limited to 'insns.def')
-rw-r--r--insns.def25
1 files changed, 17 insertions, 8 deletions
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) &&