diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-06 06:04:52 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-06 06:04:52 +0000 |
commit | 3106f9412ab7bd89cd9fd4931bb7b4865b892d78 (patch) | |
tree | 508d56481df15bcd86ad634e7e25a19e6c55bc9a /process.c | |
parent | c8921b5ef07c3193d7b9ad6c329b8ade8bef8460 (diff) | |
download | ruby-3106f9412ab7bd89cd9fd4931bb7b4865b892d78.tar.gz |
use HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW
We already check for __builtin_mul_overflow in configure but never
actually referred it before. Why not call it if available, because
that should render supposedly-optimial assembly outputs.
Optionally if __builtin_mul_overflow_p is available, which is the case
for recent GCC, use that to detect fixnum overflow. This is much
faster than the previous. On my machine generated assembly of
numeric.c:int_pow reduces from 480 to 448 bytes, according to nm(1).
Also on my machine, following script boosts from 7.819 to 6.929 sec.
time ./miniruby -e 'i=0; while i < 30_000_000 do i += 1; 7 ** 23; end'
Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -6916,11 +6916,13 @@ typedef LONG_LONG timetick_int_t; #define TIMETICK_INT_MIN LLONG_MIN #define TIMETICK_INT_MAX LLONG_MAX #define TIMETICK_INT2NUM(v) LL2NUM(v) +#define MUL_OVERFLOW_TIMETICK_P(a, b) MUL_OVERFLOW_LONG_LONG_P(a, b) #else typedef long timetick_int_t; #define TIMETICK_INT_MIN LONG_MIN #define TIMETICK_INT_MAX LONG_MAX #define TIMETICK_INT2NUM(v) LONG2NUM(v) +#define MUL_OVERFLOW_TIMETICK_P(a, b) MUL_OVERFLOW_LONG_P(a, b) #endif CONSTFUNC(static timetick_int_t gcd_timetick_int(timetick_int_t, timetick_int_t)); @@ -7036,8 +7038,7 @@ timetick2integer(struct timetick *ttp, timetick_int_t t = ttp->giga_count * 1000000000 + ttp->count; for (i = 0; i < num_numerators; i++) { timetick_int_t factor = numerators[i]; - if (MUL_OVERFLOW_SIGNED_INTEGER_P(factor, t, - TIMETICK_INT_MIN, TIMETICK_INT_MAX)) + if (MUL_OVERFLOW_TIMETICK_P(factor, t)) goto generic; t *= factor; } |