1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* bignum.c (DIGSPERLONG): Don't define if BDIGIT is bigger than long.

(DIGSPERLL): Don't define if BDIGIT is bigger than LONG_LONG
  (rb_absint_size): Consider environments BDIGIT is bigger than long.
  Use BIGLO and BIGDN.
  (rb_absint_singlebit_p): Ditto.
  (rb_integer_pack): Ditto.
  (bigsub_int): Consider environments BDIGIT is bigger than long.
  Use SIZEOF_BDIGITS instead of sizeof(BDIGIT).
  (bigadd_int): Ditto.
  (bigand_int): Ditto.
  (bigor_int): Ditto.
  (bigxor_int): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-06-19 10:36:22 +00:00
parent 9f473df72a
commit 9cff4e30c6
2 changed files with 39 additions and 22 deletions

View file

@ -1,3 +1,18 @@
Wed Jun 19 19:31:30 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (DIGSPERLONG): Don't define if BDIGIT is bigger than long.
(DIGSPERLL): Don't define if BDIGIT is bigger than LONG_LONG
(rb_absint_size): Consider environments BDIGIT is bigger than long.
Use BIGLO and BIGDN.
(rb_absint_singlebit_p): Ditto.
(rb_integer_pack): Ditto.
(bigsub_int): Consider environments BDIGIT is bigger than long.
Use SIZEOF_BDIGITS instead of sizeof(BDIGIT).
(bigadd_int): Ditto.
(bigand_int): Ditto.
(bigor_int): Ditto.
(bigxor_int): Ditto.
Wed Jun 19 15:14:30 2013 Koichi Sasada <ko1@atdot.net> Wed Jun 19 15:14:30 2013 Koichi Sasada <ko1@atdot.net>
* include/ruby/ruby.h (struct rb_data_type_struct), gc.c: add * include/ruby/ruby.h (struct rb_data_type_struct), gc.c: add

View file

@ -37,8 +37,10 @@ static VALUE big_three = Qnil;
#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT) #define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT)
#define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG) #define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG)
#define BIGRAD_HALF ((BDIGIT)(BIGRAD >> 1)) #define BIGRAD_HALF ((BDIGIT)(BIGRAD >> 1))
#define DIGSPERLONG (SIZEOF_LONG/SIZEOF_BDIGITS) #if SIZEOF_LONG >= SIZEOF_BDIGITS
#if HAVE_LONG_LONG # define DIGSPERLONG (SIZEOF_LONG/SIZEOF_BDIGITS)
#endif
#if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG >= SIZEOF_BDIGITS
# define DIGSPERLL (SIZEOF_LONG_LONG/SIZEOF_BDIGITS) # define DIGSPERLL (SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
#endif #endif
#define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG) #define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG)
@ -526,14 +528,14 @@ rb_absint_size(VALUE val, int *nlz_bits_ret)
if (v < 0) { if (v < 0) {
v = -v; v = -v;
} }
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
fixbuf[0] = v; fixbuf[0] = v;
#else #else
{ {
int i; int i;
for (i = 0; i < numberof(fixbuf); i++) { for (i = 0; i < numberof(fixbuf); i++) {
fixbuf[i] = (BDIGIT)(v & ((1L << (SIZEOF_BDIGITS * CHAR_BIT)) - 1)); fixbuf[i] = BIGLO(v);
v >>= SIZEOF_BDIGITS * CHAR_BIT; v = BIGDN(v);
} }
} }
#endif #endif
@ -690,14 +692,14 @@ rb_absint_singlebit_p(VALUE val)
if (v < 0) { if (v < 0) {
v = -v; v = -v;
} }
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
fixbuf[0] = v; fixbuf[0] = v;
#else #else
{ {
int i; int i;
for (i = 0; i < numberof(fixbuf); i++) { for (i = 0; i < numberof(fixbuf); i++) {
fixbuf[i] = (BDIGIT)(v & ((1L << (SIZEOF_BDIGITS * CHAR_BIT)) - 1)); fixbuf[i] = BIGLO(v);
v >>= SIZEOF_BDIGITS * CHAR_BIT; v = BIGDN(v);
} }
} }
#endif #endif
@ -1098,14 +1100,14 @@ rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t
else { else {
sign = 1; sign = 1;
} }
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
fixbuf[0] = v; fixbuf[0] = v;
#else #else
{ {
int i; int i;
for (i = 0; i < numberof(fixbuf); i++) { for (i = 0; i < numberof(fixbuf); i++) {
fixbuf[i] = (BDIGIT)(v & ((1L << (SIZEOF_BDIGITS * CHAR_BIT)) - 1)); fixbuf[i] = BIGLO(v);
v >>= SIZEOF_BDIGITS * CHAR_BIT; v = BIGDN(v);
} }
} }
#endif #endif
@ -2908,7 +2910,7 @@ bigsub_int(VALUE x, long y0)
z = bignew(xn, RBIGNUM_SIGN(x)); z = bignew(xn, RBIGNUM_SIGN(x));
zds = BDIGITS(z); zds = BDIGITS(z);
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
num = (BDIGIT_DBL_SIGNED)xds[0] - y; num = (BDIGIT_DBL_SIGNED)xds[0] - y;
if (xn == 1 && num < 0) { if (xn == 1 && num < 0) {
RBIGNUM_SET_SIGN(z, !RBIGNUM_SIGN(x)); RBIGNUM_SET_SIGN(z, !RBIGNUM_SIGN(x));
@ -2921,7 +2923,7 @@ bigsub_int(VALUE x, long y0)
i = 1; i = 1;
#else #else
num = 0; num = 0;
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) { for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
num += (BDIGIT_DBL_SIGNED)xds[i] - BIGLO(y); num += (BDIGIT_DBL_SIGNED)xds[i] - BIGLO(y);
zds[i] = BIGLO(num); zds[i] = BIGLO(num);
num = BIGDN(num); num = BIGDN(num);
@ -2965,14 +2967,14 @@ bigadd_int(VALUE x, long y)
z = bignew(zn, RBIGNUM_SIGN(x)); z = bignew(zn, RBIGNUM_SIGN(x));
zds = BDIGITS(z); zds = BDIGITS(z);
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
num = (BDIGIT_DBL)xds[0] + y; num = (BDIGIT_DBL)xds[0] + y;
zds[0] = BIGLO(num); zds[0] = BIGLO(num);
num = BIGDN(num); num = BIGDN(num);
i = 1; i = 1;
#else #else
num = 0; num = 0;
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) { for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
num += (BDIGIT_DBL)xds[i] + BIGLO(y); num += (BDIGIT_DBL)xds[i] + BIGLO(y);
zds[i] = BIGLO(num); zds[i] = BIGLO(num);
num = BIGDN(num); num = BIGDN(num);
@ -4369,7 +4371,7 @@ bigand_int(VALUE x, long y)
sign = (y > 0); sign = (y > 0);
xds = BDIGITS(x); xds = BDIGITS(x);
zn = xn = RBIGNUM_LEN(x); zn = xn = RBIGNUM_LEN(x);
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
if (sign) { if (sign) {
y &= xds[0]; y &= xds[0];
return LONG2NUM(y); return LONG2NUM(y);
@ -4379,14 +4381,14 @@ bigand_int(VALUE x, long y)
z = bignew(zn, RBIGNUM_SIGN(x) || sign); z = bignew(zn, RBIGNUM_SIGN(x) || sign);
zds = BDIGITS(z); zds = BDIGITS(z);
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
i = 1; i = 1;
zds[0] = xds[0] & y; zds[0] = xds[0] & y;
#else #else
{ {
BDIGIT_DBL num = y; BDIGIT_DBL num = y;
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) { for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
zds[i] = xds[i] & BIGLO(num); zds[i] = xds[i] & BIGLO(num);
num = BIGDN(num); num = BIGDN(num);
} }
@ -4475,14 +4477,14 @@ bigor_int(VALUE x, long y)
z = bignew(zn, RBIGNUM_SIGN(x) && sign); z = bignew(zn, RBIGNUM_SIGN(x) && sign);
zds = BDIGITS(z); zds = BDIGITS(z);
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
i = 1; i = 1;
zds[0] = xds[0] | y; zds[0] = xds[0] | y;
#else #else
{ {
BDIGIT_DBL num = y; BDIGIT_DBL num = y;
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) { for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
zds[i] = xds[i] | BIGLO(num); zds[i] = xds[i] | BIGLO(num);
num = BIGDN(num); num = BIGDN(num);
} }
@ -4571,14 +4573,14 @@ bigxor_int(VALUE x, long y)
z = bignew(zn, !(RBIGNUM_SIGN(x) ^ sign)); z = bignew(zn, !(RBIGNUM_SIGN(x) ^ sign));
zds = BDIGITS(z); zds = BDIGITS(z);
#if SIZEOF_BDIGITS == SIZEOF_LONG #if SIZEOF_BDIGITS >= SIZEOF_LONG
i = 1; i = 1;
zds[0] = xds[0] ^ y; zds[0] = xds[0] ^ y;
#else #else
{ {
BDIGIT_DBL num = y; BDIGIT_DBL num = y;
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) { for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
zds[i] = xds[i] ^ BIGLO(num); zds[i] = xds[i] ^ BIGLO(num);
num = BIGDN(num); num = BIGDN(num);
} }