From adaa5650cd948674e51db36b4c6af8e4304a711a Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 13 Aug 2013 14:03:55 +0000 Subject: [PATCH] * 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 --- ChangeLog | 4 ++++ bignum.c | 37 +++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index c11db0171f..ac13f54eee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Aug 13 23:01:16 2013 Tanaka Akira + + * bignum.c (bigdivrem_restoring): Extracted from bigdivrem_normal. + Tue Aug 13 22:12:59 2013 Kenichi Kamiya * random.c (rb_random_ulong_limited): coerce before check negative. diff --git a/bignum.c b/bignum.c index 61f0fa42c8..b209d4059f 100644 --- a/bignum.c +++ b/bignum.c @@ -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);