[pypy-svn] r25000 - in pypy/dist/pypy: rpython rpython/l3interp rpython/lltypesystem rpython/test translator/c/src translator/c/test

arigo at codespeak.net arigo at codespeak.net
Sat Mar 25 19:20:02 CET 2006


Author: arigo
Date: Sat Mar 25 19:19:57 2006
New Revision: 25000

Modified:
   pypy/dist/pypy/rpython/l3interp/model.py
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/lltypesystem/lloperation.py
   pypy/dist/pypy/rpython/rfloat.py
   pypy/dist/pypy/rpython/rint.py
   pypy/dist/pypy/rpython/test/test_llinterp.py
   pypy/dist/pypy/rpython/test/test_rint.py
   pypy/dist/pypy/translator/c/src/float.h
   pypy/dist/pypy/translator/c/src/int.h
   pypy/dist/pypy/translator/c/test/test_typed.py
Log:
Remove some of the division low-level operations.
Now we only have xxx_floordiv for integer types,
and float_truediv for floats.  The high-level
operations are mapped to one of these, possibly
with conversions (inserted automagically by the
rtyper).


Modified: pypy/dist/pypy/rpython/l3interp/model.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/model.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/model.py	Sat Mar 25 19:19:57 2006
@@ -31,10 +31,10 @@
     'flavored_free', 'flavored_malloc',
 
     #float operations:
-    'float_abs', 'float_add', 'float_div', 'float_eq', 'float_floor',
-    'float_floordiv', 'float_fmod', 'float_ge', 'float_gt', 'float_invert',
+    'float_abs', 'float_add', 'float_truediv', 'float_eq', 'float_floor',
+    'float_fmod', 'float_ge', 'float_gt', 'float_invert',
     'float_is_true', 'float_le', 'float_lt', 'float_mod', 'float_mul',
-    'float_ne', 'float_neg', 'float_sub', 'float_truediv',
+    'float_ne', 'float_neg', 'float_sub',
 
     #array operations:
     'getarrayitem_int', 'getarrayitem_ptr',
@@ -48,15 +48,14 @@
 
     #integer operations:
     'int_abs', 'int_abs_ovf', 'int_add', 'int_add_ovf', 'int_and',
-    'int_and_ovf', 'int_div', 'int_div_ovf', 'int_eq', 'int_eq_ovf',
+    'int_and_ovf', 'int_eq', 'int_eq_ovf',
     'int_floordiv', 'int_floordiv_ovf', 'int_floordiv_ovf_zer', 'int_ge',
     'int_ge_ovf', 'int_gt', 'int_gt_ovf', 'int_invert', 'int_invert_ovf',
     'int_is_true', 'int_is_true_ovf', 'int_le', 'int_le_ovf', 'int_lshift',
     'int_lshift_ovf', 'int_lt', 'int_lt_ovf', 'int_mod', 'int_mod_ovf',
     'int_mod_ovf_zer', 'int_mul', 'int_mul_ovf', 'int_ne', 'int_ne_ovf',
     'int_neg', 'int_neg_ovf', 'int_or', 'int_or_ovf', 'int_rshift',
-    'int_rshift_ovf', 'int_sub', 'int_sub_ovf', 'int_truediv',
-    'int_truediv_ovf', 'int_xor', 'int_xor_ovf',
+    'int_rshift_ovf', 'int_sub', 'int_sub_ovf', 'int_xor', 'int_xor_ovf',
 
     #regular object memory operations:
     'keepalive', 'malloc', 'malloc_varsize',
@@ -71,10 +70,10 @@
     'same_as',
 
     #operations with unsigned integers: 
-    'uint_abs', 'uint_add', 'uint_and', 'uint_div', 'uint_eq',
+    'uint_abs', 'uint_add', 'uint_and', 'uint_eq',
     'uint_floordiv', 'uint_ge', 'uint_gt', 'uint_invert', 'uint_is_true',
     'uint_le', 'uint_lshift', 'uint_lt', 'uint_mod', 'uint_mul', 'uint_ne',
-    'uint_neg', 'uint_or', 'uint_rshift', 'uint_sub', 'uint_truediv',
+    'uint_neg', 'uint_or', 'uint_rshift', 'uint_sub',
     'uint_xor',
 
     #operations with unicode characters

Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Sat Mar 25 19:19:57 2006
@@ -115,7 +115,6 @@
                         'lt': True, 'le': True,
                         'eq': True, 'ne': True,
                         'is_true': True}
-ops_returning_a_float = {'truediv': True}
 
 def checkptr(ptr):
     return isinstance(lltype.typeOf(ptr), lltype.Ptr)
@@ -689,7 +688,7 @@
 
     for typ in (float, int, r_uint, r_longlong, r_ulonglong):
         typname = typ.__name__
-        optup = ('add', 'sub', 'mul', 'div', 'truediv', 'floordiv',
+        optup = ('add', 'sub', 'mul', 'truediv', 'floordiv',
                  'mod', 'gt', 'lt', 'ge', 'ne', 'le', 'eq',)
         if typ is r_uint:
             opnameprefix = 'uint'
@@ -703,8 +702,11 @@
             optup += 'and_', 'or_', 'lshift', 'rshift', 'xor'
         for opname in optup:
             assert opname in opimpls
-            if typ is int and opname not in ops_returning_a_bool \
-                    and opname not in ops_returning_a_float:
+            if typ is float and opname == 'floordiv':
+                continue    # 'floordiv' is for integer types
+            if typ is not float and opname == 'truediv':
+                continue    # 'truediv' is for floats only
+            if typ is int and opname not in ops_returning_a_bool:
                 adjust_result = 'intmask'
             else:
                 adjust_result = ''

Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py	Sat Mar 25 19:19:57 2006
@@ -63,7 +63,6 @@
 # XXX Some clean-ups are needed:
 #      * many exception-raising operations are being replaced by calls to helpers
 #      * there are still many _ovf operations that cannot really raise OverflowError
-#      * the div/truediv/floordiv mess needs to be sorted out and reduced
 #      * float_mod vs float_fmod ?
 # Run test_lloperation after changes.  Feel free to clean up LLInterpreter too :-)
 
@@ -96,8 +95,6 @@
     'int_add':              LLOp(canfold=True),
     'int_sub':              LLOp(canfold=True),
     'int_mul':              LLOp(canfold=True),
-    'int_div':              LLOp(canfold=True),
-    'int_truediv':          LLOp(canfold=True),
     'int_floordiv':         LLOp(canfold=True),
     'int_mod':              LLOp(canfold=True),
     'int_lt':               LLOp(canfold=True),
@@ -114,8 +111,6 @@
     'int_add_ovf':          LLOp(canfold=True, canraise=(OverflowError,)),
     'int_sub_ovf':          LLOp(canfold=True, canraise=(OverflowError,)),
     'int_mul_ovf':          LLOp(canfold=True, canraise=(OverflowError,)),
-    'int_div_ovf':          LLOp(canfold=True, canraise=(OverflowError,)),
-    'int_truediv_ovf':      LLOp(canfold=True, canraise=(OverflowError,)),
     'int_floordiv_ovf':     LLOp(canfold=True, canraise=(OverflowError,)),
     'int_mod_ovf':          LLOp(canfold=True, canraise=(OverflowError,)),
     'int_lt_ovf':           LLOp(canfold=True, canraise=(OverflowError,)),
@@ -140,8 +135,6 @@
     'uint_add':             LLOp(canfold=True),
     'uint_sub':             LLOp(canfold=True),
     'uint_mul':             LLOp(canfold=True),
-    'uint_div':             LLOp(canfold=True),
-    'uint_truediv':         LLOp(canfold=True),
     'uint_floordiv':        LLOp(canfold=True),
     'uint_mod':             LLOp(canfold=True),
     'uint_lt':              LLOp(canfold=True),
@@ -163,9 +156,7 @@
     'float_add':            LLOp(canfold=True),
     'float_sub':            LLOp(canfold=True),
     'float_mul':            LLOp(canfold=True),
-    'float_div':            LLOp(canfold=True),
     'float_truediv':        LLOp(canfold=True),
-    'float_floordiv':       LLOp(canfold=True),
     'float_mod':            LLOp(canfold=True),
     'float_lt':             LLOp(canfold=True),
     'float_le':             LLOp(canfold=True),
@@ -184,8 +175,6 @@
     'llong_add':            LLOp(canfold=True),
     'llong_sub':            LLOp(canfold=True),
     'llong_mul':            LLOp(canfold=True),
-    'llong_div':            LLOp(canfold=True),
-    'llong_truediv':        LLOp(canfold=True),
     'llong_floordiv':       LLOp(canfold=True),
     'llong_mod':            LLOp(canfold=True),
     'llong_lt':             LLOp(canfold=True),
@@ -203,8 +192,6 @@
     'ullong_add':           LLOp(canfold=True),
     'ullong_sub':           LLOp(canfold=True),
     'ullong_mul':           LLOp(canfold=True),
-    'ullong_div':           LLOp(canfold=True),
-    'ullong_truediv':       LLOp(canfold=True),
     'ullong_floordiv':      LLOp(canfold=True),
     'ullong_mod':           LLOp(canfold=True),
     'ullong_lt':            LLOp(canfold=True),

Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py	(original)
+++ pypy/dist/pypy/rpython/rfloat.py	Sat Mar 25 19:19:57 2006
@@ -41,13 +41,16 @@
 
     rtype_inplace_mul = rtype_mul
 
-    def rtype_div(_, hop):
-        # turn 'div' on floats into 'truediv'
+    def rtype_truediv(_, hop):
         return _rtype_template(hop, 'truediv')
 
-    rtype_inplace_div     = rtype_div
-    rtype_truediv         = rtype_div
-    rtype_inplace_truediv = rtype_div
+    rtype_inplace_truediv = rtype_truediv
+
+    # turn 'div' on floats into 'truediv'
+    rtype_div         = rtype_truediv
+    rtype_inplace_div = rtype_inplace_truediv
+
+    # 'floordiv' on floats not supported in RPython
 
     def rtype_pow(_, hop):
         s_float3 = hop.args_s[2]

Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py	(original)
+++ pypy/dist/pypy/rpython/rint.py	Sat Mar 25 19:19:57 2006
@@ -74,14 +74,6 @@
     def rtype_mul_ovf(_, hop):
         return _rtype_template(hop, 'mul_ovf')
 
-    def rtype_div(_, hop):
-        # turn 'div' on integers into 'floordiv'
-        return _rtype_template(hop, 'floordiv', [ZeroDivisionError])
-    rtype_inplace_div = rtype_div
-
-    def rtype_div_ovf(_, hop):
-        return _rtype_template(hop, 'div_ovf', [ZeroDivisionError])
-
     def rtype_floordiv(_, hop):
         return _rtype_template(hop, 'floordiv', [ZeroDivisionError])
     rtype_inplace_floordiv = rtype_floordiv
@@ -89,9 +81,12 @@
     def rtype_floordiv_ovf(_, hop):
         return _rtype_template(hop, 'floordiv_ovf', [ZeroDivisionError])
 
-    def rtype_truediv(_, hop):
-        return _rtype_template(hop, 'truediv', [ZeroDivisionError])
-    rtype_inplace_truediv = rtype_truediv
+    # turn 'div' on integers into 'floordiv'
+    rtype_div         = rtype_floordiv
+    rtype_inplace_div = rtype_inplace_floordiv
+    rtype_div_ovf     = rtype_floordiv_ovf
+
+    # 'def rtype_truediv' is delegated to the superclass FloatRepr
 
     def rtype_mod(_, hop):
         return _rtype_template(hop, 'mod', [ZeroDivisionError])

Modified: pypy/dist/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llinterp.py	(original)
+++ pypy/dist/pypy/rpython/test/test_llinterp.py	Sat Mar 25 19:19:57 2006
@@ -290,7 +290,7 @@
     res = interpret(g, [-15])
     assert res == 15
 
-def test_div_ovf_zer():
+def test_floordiv_ovf_zer():
     import sys
     def f(x):
         try:
@@ -356,15 +356,6 @@
         assert interp.eval_graph(g, [1]) == 1
         assert interp.eval_graph(g, [0]) == 0
 
-def test_int_truediv():
-    from pypy.rpython.lltypesystem.lltype import Float
-    def f(i, j):
-        return llop.int_truediv(Float, i, j)
-    for args in (4, 2), (3, 4):
-        res = interpret(f, list(args))
-        assert isinstance(res, float)
-        assert res == float(args[0]) / args[1]
-
 #__________________________________________________________________
 #
 #  Test objects and instances

Modified: pypy/dist/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rint.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rint.py	Sat Mar 25 19:19:57 2006
@@ -139,3 +139,11 @@
         return space.wrap(x)
     res = interpret(wrap, [r_longlong(0)])
     assert res == 0
+
+def test_truediv():
+    import operator
+    def f(n, m):
+        return operator.truediv(n, m)
+    res = interpret(f, [20, 4])
+    assert type(res) is float
+    assert res == 5.0

Modified: pypy/dist/pypy/translator/c/src/float.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/float.h	(original)
+++ pypy/dist/pypy/translator/c/src/float.h	Sat Mar 25 19:19:57 2006
@@ -26,8 +26,7 @@
 #define OP_FLOAT_ADD(x,y,r,err)     r = x + y
 #define OP_FLOAT_SUB(x,y,r,err)     r = x - y
 #define OP_FLOAT_MUL(x,y,r,err)     r = x * y
-#define OP_FLOAT_DIV(x,y,r,err)     r = x / y
-#define OP_FLOAT_TRUEDIV(x,y,r,err) OP_FLOAT_DIV(x,y,r,err)
+#define OP_FLOAT_TRUEDIV(x,y,r,err) r = x / y
 #define OP_FLOAT_POW(x,y,r,err)     r = pow(x, y) 
 
 /*** conversions ***/

Modified: pypy/dist/pypy/translator/c/src/int.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/int.h	(original)
+++ pypy/dist/pypy/translator/c/src/int.h	Sat Mar 25 19:19:57 2006
@@ -290,7 +290,7 @@
 #define OP_LLONG_ADD OP_INT_ADD
 #define OP_LLONG_SUB OP_INT_SUB
 #define OP_LLONG_MUL OP_INT_MUL
-#define OP_LLONG_DIV OP_INT_DIV
+#define OP_LLONG_FLOORDIV OP_INT_FLOORDIV
 
 #define OP_LLONG_EQ  OP_INT_EQ
 #define OP_LLONG_NE  OP_INT_NE

Modified: pypy/dist/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_typed.py	Sat Mar 25 19:19:57 2006
@@ -205,7 +205,7 @@
         fn = self.getcompiled(snippet.add_func)
         raises(OverflowError, fn, sys.maxint)
 
-    def test_int_div_ovf_zer(self):
+    def test_int_floordiv_ovf_zer(self):
         fn = self.getcompiled(snippet.div_func)
         raises(OverflowError, fn, -1)
         raises(ZeroDivisionError, fn, 0)



More information about the Pypy-commit mailing list