* bignum.c (bigdivrem_restoring): Extracted from bigdivrem_normal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-08-13 14:03:55 +00:00
Родитель 26feae3958
Коммит adaa5650cd
2 изменённых файлов: 27 добавлений и 14 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Tue Aug 13 23:01:16 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bigdivrem_restoring): Extracted from bigdivrem_normal.
Tue Aug 13 22:12:59 2013 Kenichi Kamiya <kachick1@gmail.com>
* random.c (rb_random_ulong_limited): coerce before check negative.

Просмотреть файл

@ -2697,23 +2697,11 @@ bigdivrem_single(BDIGIT *qds, const BDIGIT *xds, size_t xn, BDIGIT y)
}
static void
bigdivrem_normal(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn, int needs_mod)
bigdivrem_restoring(BDIGIT *zds, size_t zn, size_t xn, BDIGIT *yds, size_t yn)
{
struct big_div_struct bds;
BDIGIT q;
int shift;
q = yds[yn-1];
shift = nlz(q);
if (shift) {
bary_small_lshift(yds, yds, yn, shift);
zds[xn] = bary_small_lshift(zds, xds, xn, shift);
}
else {
MEMCPY(zds, xds, BDIGIT, xn);
zds[xn] = 0;
}
if (xn+1 < zn) zds[xn+1] = 0;
assert(BDIGIT_MSB(yds[yn-1]));
bds.xn = xn;
bds.yn = yn;
@ -2735,6 +2723,27 @@ bigdivrem_normal(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, BDIGIT *y
else {
bigdivrem1(&bds);
}
}
static void
bigdivrem_normal(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn, int needs_mod)
{
BDIGIT q;
int shift;
q = yds[yn-1];
shift = nlz(q);
if (shift) {
bary_small_lshift(yds, yds, yn, shift);
zds[xn] = bary_small_lshift(zds, xds, xn, shift);
}
else {
MEMCPY(zds, xds, BDIGIT, xn);
zds[xn] = 0;
}
if (xn+1 < zn) zds[xn+1] = 0;
bigdivrem_restoring(zds, zn, xn, yds, yn);
if (needs_mod && shift) {
bary_small_rshift(zds, zds, yn, shift, 0);