Author: stian
Branch: math-improvements
Changeset: r92854:12d7e0578291
Date: 2017-10-26 18:48 +0200
http://bitbucket.org/pypy/pypy/changeset/12d7e0578291/

Log:    uint128_t test and a tiny optimalization

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -849,6 +849,7 @@
             else:
                 # Perform
                 size = self.numdigits() - 1
+                
                 if size > 0:
                     rem = self.widedigit(size)
                     size -= 1
@@ -856,7 +857,7 @@
                         rem = ((rem << SHIFT) | self.digit(size)) % digit
                         size -= 1
                 else:
-                    rem = self.digit(0) % digit
+                    rem = self.widedigit(0) % digit
 
                 if rem == 0:
                     return NULLRBIGINT
@@ -2091,7 +2092,7 @@
         * result in z[0:m], and return the d bits shifted out of the top.
     """
 
-    carry = 0
+    carry = _unsigned_widen_digit(0)
     assert 0 <= d and d < SHIFT
     i = 0
     while i < m:
diff --git a/rpython/translator/c/test/test_typed.py 
b/rpython/translator/c/test/test_typed.py
--- a/rpython/translator/c/test/test_typed.py
+++ b/rpython/translator/c/test/test_typed.py
@@ -955,6 +955,20 @@
         res = f(217)
         assert res == 305123851
 
+    def test_uint128(self):
+        if not hasattr(rffi, '__UINT128_T'):
+            py.test.skip("no '__uint128_t'")
+        def func(n):
+            x = rffi.cast(getattr(rffi, '__UINT128_T'), n)
+            x *= x
+            x *= x
+            x *= x
+            x *= x
+            return intmask(x >> 96)
+        f = self.getcompiled(func, [int])
+        res = f(217)
+        assert res == 305123851
+
     def test_bool_2(self):
         def func(n):
             x = rffi.cast(lltype.Bool, n)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to