Author: stian Branch: improve-rbigint Changeset: r56356:22b6be6db1ba Date: 2012-07-07 19:22 +0200 http://bitbucket.org/pypy/pypy/changeset/22b6be6db1ba/
Log: Reapply proofs of index >= 0 using unsigned (for mul this could in theory be done even quicker by making a unsigned longlonglong and avoid the cast) diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py --- a/pypy/rlib/rbigint.py +++ b/pypy/rlib/rbigint.py @@ -1048,7 +1048,7 @@ # via exploiting that each entry in the multiplication # pyramid appears twice (except for the size_a squares). z = rbigint([NULLDIGIT] * (size_a + size_b), 1) - i = 0 + i = UDIGIT_TYPE(0) while i < size_a: f = a.widedigit(i) pz = i << 1 @@ -1071,12 +1071,7 @@ carry >>= SHIFT #assert carry <= (_widen_digit(MASK) << 1) if carry: - carry += z.widedigit(pz) - z.setdigit(pz, carry) - pz += 1 - carry >>= SHIFT - if carry: - z.setdigit(pz, z.widedigit(pz) + carry) + z.setdigit(pz, z.widedigit(pz) + carry) assert (carry >> SHIFT) == 0 i += 1 z._positivenormalize() @@ -1087,7 +1082,7 @@ z = rbigint([NULLDIGIT] * (size_a + size_b), 1) # gradeschool long mult - i = 0 + i = UDIGIT_TYPE(0) while i < size_a: carry = 0 f = a.widedigit(i) @@ -1565,9 +1560,9 @@ size_a = size_v - size_w + 1 a = rbigint([NULLDIGIT] * size_a, 1) - assert size_w >= 2 - wm1 = w.widedigit(size_w-1) - wm2 = w.widedigit(size_w-2) + + wm1 = w.widedigit(abs(size_w-1)) + wm2 = w.widedigit(abs(size_w-2)) j = size_v k = size_a - 1 while k >= 0: @@ -1578,7 +1573,7 @@ vj = v.widedigit(j) carry = 0 - vj1 = v.widedigit(j-1) + vj1 = v.widedigit(abs(j-1)) if vj == wm1: q = MASK @@ -1588,7 +1583,7 @@ q = vv // wm1 r = _widen_digit(vv) - wm1 * q - vj2 = v.widedigit(j-2) + vj2 = v.widedigit(abs(j-2)) while wm2 * q > ((r << SHIFT) | vj2): q -= 1 r += wm1 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.887265 - 2.253981 - 2.480497 - 1.572440 - 3.941691 - 9.530685 - 1.786801 - 4.046154 - 4.844644 - 6.412511 - 0.038662 - 3.629173 - 8.155449 - 4.997199 - Sum: 56.577152 + 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 A pure python form of those tests where also run Improved pypy | Pypy | CPython 2.7.3 @@ -65,7 +65,7 @@ sumTime = 0.0 - t = time() + """t = time() by = rbigint.pow(rbigint.fromint(63), rbigint.fromint(100)) for n in xrange(9900): by2 = by.lshift(63) @@ -75,7 +75,7 @@ _time = time() - t sumTime += _time - print "Toom-cook effectivity 100-10000 digits:", _time + print "Toom-cook effectivity 100-10000 digits:", _time""" t = time() num = rbigint.pow(rbigint.fromint(100000000), rbigint.fromint(1024)) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit