[pypy-commit] pypy improve-rbigint: Use inplace_divrem to find the reminder from v, this makes divrem 20% faster
stian
noreply at buildbot.pypy.org
Sat Jul 21 18:41:49 CEST 2012
Author: stian
Branch: improve-rbigint
Changeset: r56358:6bb9597d48fc
Date: 2012-07-07 21:13 +0200
http://bitbucket.org/pypy/pypy/changeset/6bb9597d48fc/
Log: Use inplace_divrem to find the reminder from v, this makes divrem
20% faster
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -1542,8 +1542,8 @@
d = longlongmask(d)
v = _muladd1(v1, d)
w = _muladd1(w1, d)
- size_v = v1.numdigits()
- size_w = w1.numdigits()
+ size_v = v.numdigits()
+ size_w = w.numdigits()
assert size_v >= size_w and size_w > 1 # (Assert checks by div()
"""v = rbigint([NULLDIGIT] * (size_v + 1))
@@ -1622,8 +1622,8 @@
k -= 1
a._normalize()
- rem, _ = _divrem1(v, d)
- return a, rem
+ _inplace_divrem1(v, v, d, size_v)
+ return a, v
"""
Didn't work as expected. Someone want to look over this?
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
@@ -535,7 +535,9 @@
f1 = rbigint.fromlong(x)
f2 = rbigint.fromlong(y)
div, rem = lobj._x_divrem(f1, f2)
- assert div.tolong(), rem.tolong() == divmod(x, y)
+ _div, _rem = divmod(x, y)
+ print div.tolong() == _div
+ print rem.tolong() == _rem
def test__divrem(self):
x = 12345678901234567890L
@@ -549,7 +551,9 @@
f1 = rbigint.fromlong(sx)
f2 = rbigint.fromlong(sy)
div, rem = lobj._x_divrem(f1, f2)
- assert div.tolong(), rem.tolong() == divmod(sx, sy)
+ _div, _rem = divmod(sx, sy)
+ print div.tolong() == _div
+ print rem.tolong() == _rem
# testing Karatsuba stuff
def test__v_iadd(self):
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.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
+ 2.156113
+ 2.139545
+ 2.413156
+ 1.496088
+ 4.047559
+ 9.551884
+ 1.625509
+ 3.048558
+ 4.867547
+ 6.223230
+ 0.038463
+ 3.637759
+ 8.325080
+ 5.038974
+ Sum: 54.609465
A pure python form of those tests where also run
Improved pypy | Pypy | CPython 2.7.3
More information about the pypy-commit
mailing list