* bignum.c (bytes_zero_p): Removed.
(bary_pack): Don't call bytes_zero_p. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f175d5259c
commit
93ec82ca77
@ -1,3 +1,8 @@
|
|||||||
|
Sun Jun 23 01:27:54 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* bignum.c (bytes_zero_p): Removed.
|
||||||
|
(bary_pack): Don't call bytes_zero_p.
|
||||||
|
|
||||||
Sun Jun 23 00:51:29 2013 Tanaka Akira <akr@fsij.org>
|
Sun Jun 23 00:51:29 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c (bytes_zero_p): Extracted from bary_pack.
|
* bignum.c (bytes_zero_p): Extracted from bary_pack.
|
||||||
|
40
bignum.c
40
bignum.c
@ -123,15 +123,6 @@ rb_big_dump(VALUE x)
|
|||||||
#define ON_DEBUG(x)
|
#define ON_DEBUG(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
|
||||||
bytes_zero_p(unsigned char *p, size_t n)
|
|
||||||
{
|
|
||||||
while (n--)
|
|
||||||
if (*p++)
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bary_zero_p(BDIGIT *xds, size_t nx)
|
bary_zero_p(BDIGIT *xds, size_t nx)
|
||||||
{
|
{
|
||||||
@ -922,7 +913,7 @@ bary_pack(int sign, BDIGIT *ds, size_t num_bdigits, void *words, size_t numwords
|
|||||||
if (nails == 0 && SIZEOF_BDIGITS == sizeof(BDIGIT) &&
|
if (nails == 0 && SIZEOF_BDIGITS == sizeof(BDIGIT) &&
|
||||||
(flags & INTEGER_PACK_WORDORDER_MASK) == INTEGER_PACK_LSWORD_FIRST &&
|
(flags & INTEGER_PACK_WORDORDER_MASK) == INTEGER_PACK_LSWORD_FIRST &&
|
||||||
(flags & INTEGER_PACK_BYTEORDER_MASK) != INTEGER_PACK_MSBYTE_FIRST) {
|
(flags & INTEGER_PACK_BYTEORDER_MASK) != INTEGER_PACK_MSBYTE_FIRST) {
|
||||||
size_t src_size = num_bdigits * SIZEOF_BDIGITS;
|
size_t src_size = (de - dp) * SIZEOF_BDIGITS;
|
||||||
size_t dst_size = numwords * wordsize;
|
size_t dst_size = numwords * wordsize;
|
||||||
int overflow = 0;
|
int overflow = 0;
|
||||||
while (0 < src_size && ((unsigned char *)ds)[src_size-1] == 0)
|
while (0 < src_size && ((unsigned char *)ds)[src_size-1] == 0)
|
||||||
@ -939,9 +930,8 @@ bary_pack(int sign, BDIGIT *ds, size_t num_bdigits, void *words, size_t numwords
|
|||||||
int zero_p = bytes_2comp(words, dst_size);
|
int zero_p = bytes_2comp(words, dst_size);
|
||||||
if (zero_p && overflow) {
|
if (zero_p && overflow) {
|
||||||
unsigned char *p = (unsigned char *)dp;
|
unsigned char *p = (unsigned char *)dp;
|
||||||
if (dst_size < src_size &&
|
if (dst_size == src_size-1 &&
|
||||||
p[dst_size] == 1 &&
|
p[dst_size] == 1) {
|
||||||
bytes_zero_p(p+dst_size+1, src_size-dst_size-1)) {
|
|
||||||
overflow = 0;
|
overflow = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -954,30 +944,30 @@ bary_pack(int sign, BDIGIT *ds, size_t num_bdigits, void *words, size_t numwords
|
|||||||
if (nails == 0 && SIZEOF_BDIGITS == sizeof(BDIGIT) &&
|
if (nails == 0 && SIZEOF_BDIGITS == sizeof(BDIGIT) &&
|
||||||
wordsize % SIZEOF_BDIGITS == 0 && (uintptr_t)words % ALIGNOF(BDIGIT) == 0) {
|
wordsize % SIZEOF_BDIGITS == 0 && (uintptr_t)words % ALIGNOF(BDIGIT) == 0) {
|
||||||
size_t bdigits_per_word = wordsize / SIZEOF_BDIGITS;
|
size_t bdigits_per_word = wordsize / SIZEOF_BDIGITS;
|
||||||
size_t buf_num_bdigits = numwords * bdigits_per_word;
|
size_t src_num_bdigits = de - dp;
|
||||||
|
size_t dst_num_bdigits = numwords * bdigits_per_word;
|
||||||
int overflow = 0;
|
int overflow = 0;
|
||||||
int mswordfirst_p = (flags & INTEGER_PACK_MSWORD_FIRST) != 0;
|
int mswordfirst_p = (flags & INTEGER_PACK_MSWORD_FIRST) != 0;
|
||||||
int msbytefirst_p = (flags & INTEGER_PACK_NATIVE_BYTE_ORDER) ? HOST_BIGENDIAN_P :
|
int msbytefirst_p = (flags & INTEGER_PACK_NATIVE_BYTE_ORDER) ? HOST_BIGENDIAN_P :
|
||||||
(flags & INTEGER_PACK_MSBYTE_FIRST) != 0;
|
(flags & INTEGER_PACK_MSBYTE_FIRST) != 0;
|
||||||
if (num_bdigits <= buf_num_bdigits) {
|
if (src_num_bdigits <= dst_num_bdigits) {
|
||||||
MEMCPY(words, dp, BDIGIT, num_bdigits);
|
MEMCPY(words, dp, BDIGIT, src_num_bdigits);
|
||||||
MEMZERO((BDIGIT*)words + num_bdigits, BDIGIT, buf_num_bdigits - num_bdigits);
|
MEMZERO((BDIGIT*)words + src_num_bdigits, BDIGIT, dst_num_bdigits - src_num_bdigits);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MEMCPY(words, dp, BDIGIT, buf_num_bdigits);
|
MEMCPY(words, dp, BDIGIT, dst_num_bdigits);
|
||||||
overflow = 1;
|
overflow = 1;
|
||||||
}
|
}
|
||||||
if (sign < 0 && (flags & INTEGER_PACK_2COMP)) {
|
if (sign < 0 && (flags & INTEGER_PACK_2COMP)) {
|
||||||
int zero_p = bary_2comp(words, buf_num_bdigits);
|
int zero_p = bary_2comp(words, dst_num_bdigits);
|
||||||
if (overflow &&
|
if (zero_p && overflow &&
|
||||||
buf_num_bdigits == num_bdigits-1 &&
|
dst_num_bdigits == src_num_bdigits-1 &&
|
||||||
dp[buf_num_bdigits] == 1 &&
|
dp[dst_num_bdigits] == 1)
|
||||||
zero_p)
|
|
||||||
overflow = 0;
|
overflow = 0;
|
||||||
}
|
}
|
||||||
if (msbytefirst_p != HOST_BIGENDIAN_P) {
|
if (msbytefirst_p != HOST_BIGENDIAN_P) {
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < buf_num_bdigits; i++) {
|
for (i = 0; i < dst_num_bdigits; i++) {
|
||||||
BDIGIT d = ((BDIGIT*)words)[i];
|
BDIGIT d = ((BDIGIT*)words)[i];
|
||||||
((BDIGIT*)words)[i] = swap_bdigit(d);
|
((BDIGIT*)words)[i] = swap_bdigit(d);
|
||||||
}
|
}
|
||||||
@ -991,7 +981,7 @@ bary_pack(int sign, BDIGIT *ds, size_t num_bdigits, void *words, size_t numwords
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mswordfirst_p) {
|
if (mswordfirst_p) {
|
||||||
bary_swap(words, buf_num_bdigits);
|
bary_swap(words, dst_num_bdigits);
|
||||||
}
|
}
|
||||||
if (overflow)
|
if (overflow)
|
||||||
sign *= 2;
|
sign *= 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user