Author: stian Branch: improve-rbigint Changeset: r56357:88aaf442458b Date: 2012-07-07 20:24 +0200 http://bitbucket.org/pypy/pypy/changeset/88aaf442458b/
Log: Faster rshift since SHIFT >= sizeof(int) diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py --- a/pypy/rlib/rbigint.py +++ b/pypy/rlib/rbigint.py @@ -711,13 +711,12 @@ newsize = oldsize + wordshift + 1 z = rbigint([NULLDIGIT] * newsize, self.sign) accum = _widen_digit(0) - i = wordshift j = 0 while j < oldsize: accum += self.widedigit(j) << remshift - z.setdigit(i, accum) + z.setdigit(wordshift, accum) accum >>= SHIFT - i += 1 + wordshift += 1 j += 1 newsize -= 1 @@ -766,19 +765,19 @@ loshift = int_other % SHIFT hishift = SHIFT - loshift - lomask = UDIGIT_MASK((UDIGIT_TYPE(1) << hishift) - 1) - himask = MASK ^ lomask + # Not 100% sure here, but the reason why it won't be a problem is because + # int is max 63bit, same as our SHIFT now. + #lomask = UDIGIT_MASK((UDIGIT_TYPE(1) << hishift) - 1) + #himask = MASK ^ lomask z = rbigint([NULLDIGIT] * newsize, self.sign) i = 0 - j = wordshift - newdigit = UDIGIT_TYPE(0) while i < newsize: - newdigit = (self.digit(j) >> loshift) & lomask + newdigit = (self.udigit(wordshift) >> loshift) #& lomask if i+1 < newsize: - newdigit |= UDIGIT_MASK(self.digit(j+1) << hishift) & himask + newdigit |= (self.udigit(wordshift+1) << hishift) #& himask z.setdigit(i, newdigit) i += 1 - j += 1 + wordshift += 1 z._positivenormalize() return z rshift._always_inline_ = True # It's so fast that it's always benefitial. diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py --- a/pypy/rlib/test/test_rbigint.py +++ b/pypy/rlib/test/test_rbigint.py @@ -430,7 +430,7 @@ res2 = f1.rshift(int(y)).tolong() assert res1 == x << y assert res2 == x >> y - + def test_bitwise(self): for x in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30]): for y in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30, 3 ** 31]): diff --git a/pypy/translator/goal/targetbigintbenchmark.py b/pypy/translator/goal/targetbigintbenchmark.py --- a/pypy/translator/goal/targetbigintbenchmark.py +++ b/pypy/translator/goal/targetbigintbenchmark.py @@ -29,21 +29,21 @@ Sum: 901.7231250000001 Pypy with improvements: - 2.885155 - 2.301395 - 2.425767 - 1.526053 - 4.066191 - 9.405854 - 1.622019 - 3.089785 - 4.844679 - 6.211589 - 0.038158 - 3.629360 - 8.194571 - 5.000065 - Sum: 55.240641 + 2.873703 + 2.154623 + 2.427906 + 1.458865 + 4.101600 + 9.396741 + 1.613343 + 3.073679 + 4.862458 + 6.202641 + 0.038174 + 3.642065 + 8.126947 + 5.075265 + Sum: 55.048011 A pure python form of those tests where also run Improved pypy | Pypy | CPython 2.7.3 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit