Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r85391:84041f155fb8
Date: 2016-06-26 21:59 +0100
http://bitbucket.org/pypy/pypy/changeset/84041f155fb8/

Log:    hg backout 800377eb1f02, 99ea9c77a44c, 507eee5b4548, 469aff993fa6

        This plan didn't work out: the result is slower (on gcc linux64). I
        suspect now that it is because gcc normally turns "x / y", where y
        is a loop-constant, into a simpler instruction in the loop with
        precomputing something outside the loop.

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -1827,8 +1827,6 @@
     Divide bigint pin by non-zero digit n, storing quotient
     in pout, and returning the remainder. It's OK for pin == pout on entry.
     """
-    from rpython.rtyper.lltypesystem.lloperation import llop
-
     rem = _widen_digit(0)
     assert n > 0 and n <= MASK
     if not size:
@@ -1836,9 +1834,9 @@
     size -= 1
     while size >= 0:
         rem = (rem << SHIFT) | pin.widedigit(size)
-        hi = llop.long2_floordiv(lltype.Signed, rem, n)
+        hi = rem // n
         pout.setdigit(size, hi)
-        rem -= _widen_digit(hi) * n
+        rem -= hi * n
         size -= 1
     return rffi.cast(lltype.Signed, rem)
 
@@ -1926,7 +1924,6 @@
     z._normalize()
     return z
 _muladd1._annspecialcase_ = "specialize:argtype(2)"
-
 def _v_lshift(z, a, m, d):
     """ Shift digit vector a[0:m] d bits left, with 0 <= d < SHIFT. Put
         * result in z[0:m], and return the d bits shifted out of the top.
@@ -2011,7 +2008,7 @@
             vtop = v.widedigit(j)
         assert vtop <= wm1
         vv = (vtop << SHIFT) | v.widedigit(abs(j-1))
-        q = vv // wm1      # can't use long2_floordiv(), q may not fit
+        q = vv / wm1
         r = vv - wm1 * q
         while wm2 * q > ((r << SHIFT) | v.widedigit(abs(j-2))):
             q -= 1
diff --git a/rpython/rtyper/lltypesystem/lloperation.py 
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -319,9 +319,6 @@
     'lllong_rshift':         LLOp(canfold=True),  # args (r_longlonglong, int)
     'lllong_xor':            LLOp(canfold=True),
 
-    'long2_floordiv':       LLOp(canfold=True),  # r = x / y: r and y Signed,
-                                                 # x can have 2x the size
-
     'cast_primitive':       LLOp(canfold=True),
     'cast_bool_to_int':     LLOp(canfold=True),
     'cast_bool_to_uint':    LLOp(canfold=True),
diff --git a/rpython/rtyper/lltypesystem/opimpl.py 
b/rpython/rtyper/lltypesystem/opimpl.py
--- a/rpython/rtyper/lltypesystem/opimpl.py
+++ b/rpython/rtyper/lltypesystem/opimpl.py
@@ -16,7 +16,7 @@
                         'bool': True, 'is_true':True}
 
 # global synonyms for some types
-from rpython.rlib.rarithmetic import intmask, base_int
+from rpython.rlib.rarithmetic import intmask
 from rpython.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong, 
r_longlonglong
 from rpython.rtyper.lltypesystem.llmemory import AddressAsInt
 
@@ -733,16 +733,6 @@
     assert isinstance(x, bool)
     return x
 
-def op_long2_floordiv(x, y):
-    if lltype.typeOf(x) != lltype.Signed:
-        assert isinstance(x, base_int)
-        assert x.BITS == 2 * r_int.BITS
-        assert x.SIGNED
-    assert lltype.typeOf(y) is lltype.Signed
-    result = int(x) // y
-    assert result == intmask(result), "overflow in long2_floordiv"
-    return result
-
 # ____________________________________________________________
 
 def get_op_impl(opname):
diff --git a/rpython/translator/c/src/asm_gcc_x86.h 
b/rpython/translator/c/src/asm_gcc_x86.h
--- a/rpython/translator/c/src/asm_gcc_x86.h
+++ b/rpython/translator/c/src/asm_gcc_x86.h
@@ -106,13 +106,3 @@
 #define PYPY_X86_CHECK_SSE2_DEFINED
 RPY_EXTERN void pypy_x86_check_sse2(void);
 #endif
-
-
-#undef OP_LONG2_FLOORDIV
-/* assumes that 'y' and 'r' fit in a signed word, 
-   but 'x' takes up to two words */
-#define OP_LONG2_FLOORDIV(x, y, r)   do {               \
-        long ignored;                                   \
-        __asm__("idiv %2" : "=a"(r), "=d"(ignored) :    \
-                "r"((long)y), "A"((long long)x));       \
-    } while (0)
diff --git a/rpython/translator/c/src/asm_gcc_x86_64.h 
b/rpython/translator/c/src/asm_gcc_x86_64.h
--- a/rpython/translator/c/src/asm_gcc_x86_64.h
+++ b/rpython/translator/c/src/asm_gcc_x86_64.h
@@ -6,13 +6,3 @@
     asm volatile("rdtsc" : "=a"(_rax), "=d"(_rdx)); \
     val = (_rdx << 32) | _rax;                          \
 } while (0)
-
-#undef OP_LONG2_FLOORDIV
-/* assumes that 'y' and 'r' fit in a signed word, 
-   but 'x' takes up to two words */
-#define OP_LONG2_FLOORDIV(x, y, r)    do {                      \
-        long ignored;                                           \
-        __asm__("idiv %2" : "=a"(r), "=d"(ignored) :            \
-                "r"((long)y), "a"((long)x),                     \
-                "d"((long)((x >> 32) >> 32)));                  \
-    } while (0)
diff --git a/rpython/translator/c/src/int.h b/rpython/translator/c/src/int.h
--- a/rpython/translator/c/src/int.h
+++ b/rpython/translator/c/src/int.h
@@ -135,7 +135,6 @@
 #define OP_LLONG_FLOORDIV(x,y,r)  r = (x) / (y)
 #define OP_ULLONG_FLOORDIV(x,y,r) r = (x) / (y)
 #define OP_LLLONG_FLOORDIV(x,y,r)  r = (x) / (y)
-#define OP_LONG2_FLOORDIV(x,y,r)  r = (x) / (y)
 
 /* modulus */
 
diff --git a/rpython/translator/c/test/test_lltyped.py 
b/rpython/translator/c/test/test_lltyped.py
--- a/rpython/translator/c/test/test_lltyped.py
+++ b/rpython/translator/c/test/test_lltyped.py
@@ -1,7 +1,6 @@
-import py, sys, random
+import py
 from rpython.rtyper.lltypesystem.lltype import *
 from rpython.rtyper.lltypesystem import rffi
-from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.translator.c.test.test_genc import compile
 from rpython.tool.sourcetools import func_with_new_name
 
@@ -1024,27 +1023,3 @@
         assert fn(r_longlong(1)) == True
         assert fn(r_longlong(256)) == True
         assert fn(r_longlong(2**32)) == True
-
-    def test_long2_floordiv(self):
-        def f(a, b):
-            return llop.long2_floordiv(Signed, a, b)
-        fn = self.getcompiled(f, [int, int])
-        assert fn(100, 3) == 33
-        #
-        if sys.maxint > 2**32:
-            HUGE = getattr(rffi, '__INT128_T', None)
-            bits = 128
-        else:
-            HUGE = SignedLongLong
-            bits = 64
-        if HUGE is not None:
-            def f(a, b, c):
-                ab = (rffi.cast(HUGE, a) << (bits//2)) | b
-                return llop.long2_floordiv(Signed, ab, c)
-            fn = self.getcompiled(f, [int, int, int])
-            for i in range(100):
-                a = random.randrange(0, 10)
-                b = random.randrange(0, sys.maxint+1)
-                c = random.randrange(2*a+2, 25)
-                print a, b, c
-                assert fn(a, b, c) == ((a << (bits//2)) | b) // c
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to