diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-20 11:10:43 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-20 11:10:43 +0000 |
commit | 148f1b9d57d06923796fff5200db140a69af6d20 (patch) | |
tree | b1eb4a99925f0af72c38f2d35546a9597f0d51f2 /internal.h | |
parent | 57638377cc22ed7b677f9826f79988ffb9451e5a (diff) |
* internal.h (DLONG): defined if long is 32bit (and LONG_LONG is 64bit;
but LONG_LONG is always defined as 64bit), or there's int128_t.
* internal.h (DL2NUM): defined if DLONG is defined.
* internal.h (rb_fix_mul_fix): defined for `Fixnum * Fixnum`.
* insns.def (opt_mul): use rb_fix_mul_fix().
* numeric.c (fix_mul): ditto.
* time.c (mul): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'internal.h')
-rw-r--r-- | internal.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/internal.h b/internal.h index c60f21947f..f28d050b12 100644 --- a/internal.h +++ b/internal.h @@ -266,6 +266,34 @@ nlz_int128(uint128_t x) } #endif +#if HAVE_LONG_LONG && SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG +# define DLONG LONG_LONG +# define DL2NUM(x) LL2NUM(x) +#elif defined(HAVE_INT128_T) +# define DLONG int128_t +# define DL2NUM(x) (RB_FIXABLE(x) ? LONG2FIX(x) : rb_int128t2big(x)) +#endif + +VALUE rb_int128t2big(int128_t n); + +/* arguments must be Fixnum */ +static inline VALUE +rb_fix_mul_fix(VALUE x, VALUE y) +{ + long lx = FIX2LONG(x); + long ly = FIX2LONG(y); +#ifdef DLONG + return DL2NUM((DLONG)lx * (DLONG)ly); +#else + if (MUL_OVERFLOW_FIXNUM_P(a, b)) { + return rb_big_mul(rb_int2big(a), rb_int2big(b)); + } + else { + return LONG2FIX(a * b); + } +#endif +} + /* * This behaves different from C99 for negative arguments. * Note that div may overflow fixnum. |