diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-08 04:50:22 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-08 04:50:22 +0000 |
commit | c99247143e484e4739ab2c495656925424165495 (patch) | |
tree | 154cb627902a55ea3e0238829d79f5c983e74088 /include/ruby | |
parent | 502ebd379495d28a6535f259a2e8ce237126a097 (diff) | |
download | ruby-c99247143e484e4739ab2c495656925424165495.tar.gz |
re-introduce __builtin_add_overflow
r57789 (74cdd89) was gradually "improve"d by naruse through r57793 to
r57806, resulted in reverting the efect of r57789 while retaining its
complexity. I think the current situation is slightly worse than
before (same output complicated source code).
Here I introduce __builtin_add_overflow again, which (I think) is what
naruse wanted to do in r57793.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include/ruby')
-rw-r--r-- | include/ruby/ruby.h | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 212ba82dd7..f99264f105 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1505,15 +1505,14 @@ rb_integer_type_p(VALUE obj) #endif static inline int -rb_long2fix_overflow(long l, VALUE *ptr) +rb_long_is_fixable_p(long v) { - if (RB_FIXABLE(l)) { - *ptr = RB_LONG2FIX(l); - return 0; - } - else { - return 1; - } +#ifdef HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW + SIGNED_VALUE w; + return! __builtin_add_overflow(v, v, &w); +#else + return RB_FIXABLE(v); +#endif } #if SIZEOF_INT < SIZEOF_LONG @@ -1523,11 +1522,10 @@ rb_long2fix_overflow(long l, VALUE *ptr) static inline VALUE rb_int2num_inline(int v) { - VALUE ret; - if (rb_long2fix_overflow(v, &ret)) - return rb_int2big(v); + if (rb_long_is_fixable_p(v)) + return RB_INT2FIX(v); else - return ret; + return rb_int2big(v); } #define RB_INT2NUM(x) rb_int2num_inline(x) @@ -1547,11 +1545,10 @@ rb_uint2num_inline(unsigned int v) static inline VALUE rb_long2num_inline(long v) { - VALUE ret; - if (rb_long2fix_overflow(v, &ret)) - return rb_int2big(v); + if (rb_long_is_fixable_p(v)) + return RB_LONG2FIX(v); else - return ret; + return rb_int2big(v); } #define RB_LONG2NUM(x) rb_long2num_inline(x) |