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
This commit is contained in:
parent
63c7ccc64b
commit
b515528271
@ -1505,15 +1505,14 @@ rb_integer_type_p(VALUE obj)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
rb_long2fix_overflow(long l, VALUE *ptr)
|
rb_long_is_fixable_p(long v)
|
||||||
{
|
{
|
||||||
if (RB_FIXABLE(l)) {
|
#ifdef HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW
|
||||||
*ptr = RB_LONG2FIX(l);
|
SIGNED_VALUE w;
|
||||||
return 0;
|
return! __builtin_add_overflow(v, v, &w);
|
||||||
}
|
#else
|
||||||
else {
|
return RB_FIXABLE(v);
|
||||||
return 1;
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SIZEOF_INT < SIZEOF_LONG
|
#if SIZEOF_INT < SIZEOF_LONG
|
||||||
@ -1523,11 +1522,10 @@ rb_long2fix_overflow(long l, VALUE *ptr)
|
|||||||
static inline VALUE
|
static inline VALUE
|
||||||
rb_int2num_inline(int v)
|
rb_int2num_inline(int v)
|
||||||
{
|
{
|
||||||
VALUE ret;
|
if (rb_long_is_fixable_p(v))
|
||||||
if (rb_long2fix_overflow(v, &ret))
|
return RB_INT2FIX(v);
|
||||||
return rb_int2big(v);
|
|
||||||
else
|
else
|
||||||
return ret;
|
return rb_int2big(v);
|
||||||
}
|
}
|
||||||
#define RB_INT2NUM(x) rb_int2num_inline(x)
|
#define RB_INT2NUM(x) rb_int2num_inline(x)
|
||||||
|
|
||||||
@ -1547,11 +1545,10 @@ rb_uint2num_inline(unsigned int v)
|
|||||||
static inline VALUE
|
static inline VALUE
|
||||||
rb_long2num_inline(long v)
|
rb_long2num_inline(long v)
|
||||||
{
|
{
|
||||||
VALUE ret;
|
if (rb_long_is_fixable_p(v))
|
||||||
if (rb_long2fix_overflow(v, &ret))
|
return RB_LONG2FIX(v);
|
||||||
return rb_int2big(v);
|
|
||||||
else
|
else
|
||||||
return ret;
|
return rb_int2big(v);
|
||||||
}
|
}
|
||||||
#define RB_LONG2NUM(x) rb_long2num_inline(x)
|
#define RB_LONG2NUM(x) rb_long2num_inline(x)
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ ntz_intptr(uintptr_t x)
|
|||||||
# define DL2NUM(x) LL2NUM(x)
|
# define DL2NUM(x) LL2NUM(x)
|
||||||
#elif defined(HAVE_INT128_T)
|
#elif defined(HAVE_INT128_T)
|
||||||
# define DLONG int128_t
|
# define DLONG int128_t
|
||||||
# define DL2NUM(x) ((RB_POSFIXABLE(x) && RB_NEGFIXABLE(x)) ? LONG2FIX(x) : rb_int128t2big(x))
|
# define DL2NUM(x) (RB_FIXABLE(x) ? LONG2FIX(x) : rb_int128t2big(x))
|
||||||
VALUE rb_int128t2big(int128_t n);
|
VALUE rb_int128t2big(int128_t n);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1386,12 +1386,11 @@ rb_float_new_inline(double d)
|
|||||||
static inline VALUE
|
static inline VALUE
|
||||||
rb_dbl2ival(double d)
|
rb_dbl2ival(double d)
|
||||||
{
|
{
|
||||||
VALUE val;
|
if (RB_FIXABLE(d)) {
|
||||||
if (rb_long2fix_overflow(d, &val)) {
|
return LONG2FIX((long)d);
|
||||||
return rb_dbl2big(d);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return val;
|
return rb_dbl2big(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3007,16 +3007,15 @@ VALUE
|
|||||||
rb_num2fix(VALUE val)
|
rb_num2fix(VALUE val)
|
||||||
{
|
{
|
||||||
long v;
|
long v;
|
||||||
VALUE w;
|
|
||||||
|
|
||||||
if (FIXNUM_P(val)) {
|
if (FIXNUM_P(val)) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
else if (rb_long2fix_overflow((v = rb_num2long(val)), &w)) {
|
else if (rb_long_is_fixable_p(v = rb_num2long(val))) {
|
||||||
rb_raise(rb_eRangeError, "integer %ld out of range of fixnum", v);
|
return LONG2FIX(v);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return w;
|
rb_raise(rb_eRangeError, "integer %ld out of range of fixnum", v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user