mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* random.c (int_pair_to_real_inclusive): Add a cast to BDIGIT.
(random_load): Fix shift width for fixnums. Re-implement bignum extraction without ifdefs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3fb267e501
commit
99638b5d1f
2 changed files with 37 additions and 41 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Wed Jun 5 20:05:29 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* random.c (int_pair_to_real_inclusive): Add a cast to BDIGIT.
|
||||||
|
(random_load): Fix shift width for fixnums.
|
||||||
|
Re-implement bignum extraction without ifdefs.
|
||||||
|
|
||||||
Wed Jun 5 15:26:10 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
Wed Jun 5 15:26:10 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* gc.c (before_gc_sweep): don't optimize it to avoid segv on Ubuntu
|
* gc.c (before_gc_sweep): don't optimize it to avoid segv on Ubuntu
|
||||||
|
|
72
random.c
72
random.c
|
@ -294,7 +294,7 @@ int_pair_to_real_inclusive(unsigned int a, unsigned int b)
|
||||||
#if BITSPERDIG < 53
|
#if BITSPERDIG < 53
|
||||||
MEMZERO(xd, BDIGIT, roomof(53, BITSPERDIG) - 1);
|
MEMZERO(xd, BDIGIT, roomof(53, BITSPERDIG) - 1);
|
||||||
#endif
|
#endif
|
||||||
xd[53 / BITSPERDIG] = 1 << 53 % BITSPERDIG;
|
xd[53 / BITSPERDIG] = (BDIGIT)1 << 53 % BITSPERDIG;
|
||||||
xd[0] |= 1;
|
xd[0] |= 1;
|
||||||
x = rb_big_mul(x, m);
|
x = rb_big_mul(x, m);
|
||||||
if (FIXNUM_P(x)) {
|
if (FIXNUM_P(x)) {
|
||||||
|
@ -709,54 +709,44 @@ random_load(VALUE obj, VALUE dump)
|
||||||
x = FIX2ULONG(state);
|
x = FIX2ULONG(state);
|
||||||
mt->state[0] = (unsigned int)x;
|
mt->state[0] = (unsigned int)x;
|
||||||
#if SIZEOF_LONG / SIZEOF_INT >= 2
|
#if SIZEOF_LONG / SIZEOF_INT >= 2
|
||||||
mt->state[1] = (unsigned int)(x >> BITSPERDIG);
|
mt->state[1] = (unsigned int)(x >> (sizeof(int) * CHAR_BIT));
|
||||||
#endif
|
#endif
|
||||||
#if SIZEOF_LONG / SIZEOF_INT >= 3
|
#if SIZEOF_LONG / SIZEOF_INT >= 3
|
||||||
mt->state[2] = (unsigned int)(x >> 2 * BITSPERDIG);
|
mt->state[2] = (unsigned int)(x >> 2 * (sizeof(int) * CHAR_BIT));
|
||||||
#endif
|
#endif
|
||||||
#if SIZEOF_LONG / SIZEOF_INT >= 4
|
#if SIZEOF_LONG / SIZEOF_INT >= 4
|
||||||
mt->state[3] = (unsigned int)(x >> 3 * BITSPERDIG);
|
mt->state[3] = (unsigned int)(x >> 3 * (sizeof(int) * CHAR_BIT));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BDIGIT *d;
|
BDIGIT *dp, *de;
|
||||||
long len;
|
unsigned int *sp, *se;
|
||||||
|
BDIGIT_DBL dd;
|
||||||
|
int numbytes_in_dd;
|
||||||
Check_Type(state, T_BIGNUM);
|
Check_Type(state, T_BIGNUM);
|
||||||
len = RBIGNUM_LEN(state);
|
dp = RBIGNUM_DIGITS(state);
|
||||||
if (len > roomof(sizeof(mt->state), SIZEOF_BDIGITS)) {
|
de = dp + RBIGNUM_LEN(state);
|
||||||
len = roomof(sizeof(mt->state), SIZEOF_BDIGITS);
|
sp = mt->state;
|
||||||
}
|
se = sp + sizeof(mt->state) / sizeof(*mt->state);;
|
||||||
#if SIZEOF_BDIGITS < SIZEOF_INT
|
dd = 0;
|
||||||
else if (len % DIGSPERINT) {
|
numbytes_in_dd = 0;
|
||||||
d = RBIGNUM_DIGITS(state) + len;
|
while (dp < de && sp < se) {
|
||||||
# if DIGSPERINT == 2
|
while (dp < de && SIZEOF_BDIGITS <= (int)sizeof(dd) - numbytes_in_dd) {
|
||||||
--len;
|
dd |= (BDIGIT_DBL)(*dp++) << (numbytes_in_dd * CHAR_BIT);
|
||||||
x = *--d;
|
numbytes_in_dd += SIZEOF_BDIGITS;
|
||||||
# else
|
}
|
||||||
x = 0;
|
while (sp < se && (int)sizeof(int) <= numbytes_in_dd) {
|
||||||
do {
|
*sp++ = (unsigned int)dd;
|
||||||
x = (x << BITSPERDIG) | *--d;
|
if (sizeof(dd) == sizeof(int))
|
||||||
} while (--len % DIGSPERINT);
|
dd = 0;
|
||||||
# endif
|
else
|
||||||
mt->state[len / DIGSPERINT] = (unsigned int)x;
|
dd >>= SIZEOF_INT * CHAR_BIT;
|
||||||
}
|
numbytes_in_dd -= SIZEOF_INT;
|
||||||
#endif
|
}
|
||||||
if (len > 0) {
|
}
|
||||||
d = BDIGITS(state) + len;
|
if (numbytes_in_dd && sp < se) {
|
||||||
do {
|
*sp = (unsigned int)dd;
|
||||||
--len;
|
}
|
||||||
x = *--d;
|
|
||||||
# if DIGSPERINT == 2
|
|
||||||
--len;
|
|
||||||
x = (x << BITSPERDIG) | *--d;
|
|
||||||
# elif SIZEOF_BDIGITS < SIZEOF_INT
|
|
||||||
do {
|
|
||||||
x = (x << BITSPERDIG) | *--d;
|
|
||||||
} while (--len % DIGSPERINT);
|
|
||||||
# endif
|
|
||||||
mt->state[len / DIGSPERINT] = (unsigned int)x;
|
|
||||||
} while (len > 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
x = NUM2ULONG(left);
|
x = NUM2ULONG(left);
|
||||||
if (x > numberof(mt->state)) {
|
if (x > numberof(mt->state)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue