mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (bary2bdigitdbl): New function.
(bdigitdbl2bary): Ditto. (bary_mul_single): Use bdigitdbl2bary. (power_cache_get_power): Ditto. (bary_divmod): Use bary2bdigitdbl. (big2str_orig): Ditto. (bigdivrem): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f12ef626d1
commit
606a03dc59
2 changed files with 38 additions and 15 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Sun Aug 4 00:22:34 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* bignum.c (bary2bdigitdbl): New function.
|
||||
(bdigitdbl2bary): Ditto.
|
||||
(bary_mul_single): Use bdigitdbl2bary.
|
||||
(power_cache_get_power): Ditto.
|
||||
(bary_divmod): Use bary2bdigitdbl.
|
||||
(big2str_orig): Ditto.
|
||||
(bigdivrem): Ditto.
|
||||
|
||||
Sat Aug 3 22:47:11 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* bignum.c: The branch condition of selecting multiplication
|
||||
|
|
43
bignum.c
43
bignum.c
|
@ -482,6 +482,27 @@ maxpow_in_bdigit(int base, int *exp_ret)
|
|||
return maxpow;
|
||||
}
|
||||
|
||||
static inline BDIGIT_DBL
|
||||
bary2bdigitdbl(const BDIGIT *ds, size_t n)
|
||||
{
|
||||
assert(n <= 2);
|
||||
|
||||
if (n == 2)
|
||||
return ds[0] | BIGUP(ds[1]);
|
||||
if (n == 1)
|
||||
return ds[0];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
bdigitdbl2bary(BDIGIT *ds, size_t n, BDIGIT_DBL num)
|
||||
{
|
||||
assert(n == 2);
|
||||
|
||||
ds[0] = BIGLO(num);
|
||||
ds[1] = (BDIGIT)BIGDN(num);
|
||||
}
|
||||
|
||||
static int
|
||||
bary_cmp(const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
|
||||
{
|
||||
|
@ -1551,9 +1572,7 @@ bary_mul_single(BDIGIT *zds, size_t zl, BDIGIT x, BDIGIT y)
|
|||
assert(2 <= zl);
|
||||
|
||||
n = (BDIGIT_DBL)x * y;
|
||||
zds[0] = BIGLO(n);
|
||||
zds[1] = (BDIGIT)BIGDN(n);
|
||||
|
||||
bdigitdbl2bary(zds, 2, n);
|
||||
BDIGITS_ZERO(zds + 2, zl - 2);
|
||||
}
|
||||
|
||||
|
@ -2724,8 +2743,8 @@ bary_divmod(BDIGIT *qds, size_t nq, BDIGIT *rds, size_t nr, const BDIGIT *xds, s
|
|||
BDIGITS_ZERO(rds+1, nr-1);
|
||||
}
|
||||
else if (nx == 2 && ny == 2) {
|
||||
BDIGIT_DBL x = xds[0] | BIGUP(xds[1]);
|
||||
BDIGIT_DBL y = yds[0] | BIGUP(yds[1]);
|
||||
BDIGIT_DBL x = bary2bdigitdbl(xds, 2);
|
||||
BDIGIT_DBL y = bary2bdigitdbl(yds, 2);
|
||||
BDIGIT_DBL q = x / y;
|
||||
BDIGIT_DBL r = x % y;
|
||||
qds[0] = BIGLO(q);
|
||||
|
@ -4151,8 +4170,7 @@ power_cache_get_power(int base, int power_level, size_t *numdigits_ret)
|
|||
int numdigits0;
|
||||
BDIGIT_DBL dd = maxpow_in_bdigit_dbl(base, &numdigits0);
|
||||
power = bignew(2, 1);
|
||||
BDIGITS(power)[0] = BIGLO(dd);
|
||||
BDIGITS(power)[1] = (BDIGIT)BIGDN(dd);
|
||||
bdigitdbl2bary(BDIGITS(power), 2, dd);
|
||||
numdigits = numdigits0;
|
||||
}
|
||||
else {
|
||||
|
@ -4256,12 +4274,7 @@ big2str_orig(struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t taillen)
|
|||
size_t len = 0;
|
||||
|
||||
assert(xn <= 2);
|
||||
|
||||
num = 0;
|
||||
if (0 < xn)
|
||||
num = xds[0];
|
||||
if (1 < xn)
|
||||
num |= BIGUP(xds[1]);
|
||||
num = bary2bdigitdbl(xds, xn);
|
||||
|
||||
if (beginning) {
|
||||
if (num == 0)
|
||||
|
@ -5575,8 +5588,8 @@ bigdivrem(VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
|
|||
return Qnil;
|
||||
}
|
||||
if (nx == 2 && ny == 2) {
|
||||
BDIGIT_DBL x0 = xds[0] | BIGUP(xds[1]);
|
||||
BDIGIT_DBL y0 = yds[0] | BIGUP(yds[1]);
|
||||
BDIGIT_DBL x0 = bary2bdigitdbl(xds, 2);
|
||||
BDIGIT_DBL y0 = bary2bdigitdbl(yds, 2);
|
||||
BDIGIT_DBL q0 = x0 / y0;
|
||||
BDIGIT_DBL r0 = x0 % y0;
|
||||
if (divp) {
|
||||
|
|
Loading…
Add table
Reference in a new issue