[pypy-svn] r32711 - in pypy/dist/pypy: rpython rpython/lltypesystem translator/c/src translator/cli translator/llvm

arigo at codespeak.net arigo at codespeak.net
Thu Sep 28 19:44:57 CEST 2006


Author: arigo
Date: Thu Sep 28 19:44:54 2006
New Revision: 32711

Removed:
   pypy/dist/pypy/translator/c/src/mkuint.py
Modified:
   pypy/dist/pypy/rpython/lltypesystem/lloperation.py
   pypy/dist/pypy/rpython/rint.py
   pypy/dist/pypy/translator/c/src/int.h
   pypy/dist/pypy/translator/cli/opcodes.py
   pypy/dist/pypy/translator/llvm/opwriter.py
Log:
(pedronis, arigo)

- removed uint_abs, uint_neg, ullong_abs, ullong_neg

- genc was not supporting all of the llong/ullong operations
  at all!  Fixed, maybe



Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py	Thu Sep 28 19:44:54 2006
@@ -179,8 +179,6 @@
     'int_lshift_ovf_val':   LLOp(canraise=(OverflowError, ValueError,)),
 
     'uint_is_true':         LLOp(canfold=True),
-    'uint_neg':             LLOp(canfold=True),
-    'uint_abs':             LLOp(canfold=True),
     'uint_invert':          LLOp(canfold=True),
 
     'uint_add':             LLOp(canfold=True),
@@ -250,8 +248,6 @@
     'llong_xor':            LLOp(canfold=True),
 
     'ullong_is_true':       LLOp(canfold=True),
-    'ullong_neg':           LLOp(canfold=True),
-    'ullong_abs':           LLOp(canfold=True),
     'ullong_invert':        LLOp(canfold=True),
 
     'ullong_add':           LLOp(canfold=True),

Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py	(original)
+++ pypy/dist/pypy/rpython/rint.py	Thu Sep 28 19:44:54 2006
@@ -246,11 +246,10 @@
     
     def rtype_abs(self, hop):
         self = self.as_int
+        vlist = hop.inputargs(self)
         if hop.s_result.unsigned:
-            vlist = hop.inputargs(self)
             return vlist[0]
         else:
-            vlist = hop.inputargs(self)
             return hop.genop(self.opprefix + 'abs', vlist, resulttype=self)
 
     def rtype_abs_ovf(self, hop):
@@ -271,7 +270,12 @@
     def rtype_neg(self, hop):
         self = self.as_int
         vlist = hop.inputargs(self)
-        return hop.genop(self.opprefix + 'neg', vlist, resulttype=self)
+        if hop.s_result.unsigned:
+            zero = self.lowleveltype._defl()
+            vlist.insert(0, hop.inputconst(self.lowleveltype, zero))
+            return hop.genop(self.opprefix + 'sub', vlist, resulttype=self)
+        else:
+            return hop.genop(self.opprefix + 'neg', vlist, resulttype=self)
 
     def rtype_neg_ovf(self, hop):
         self = self.as_int

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	Thu Sep 28 19:44:54 2006
@@ -8,8 +8,6 @@
 
 #define OP_INT_INVERT(x,r)    r = ~((x))
 
-#define OP_INT_POS(x,r)    r = x
-
 #define OP_INT_NEG(x,r)    r = -(x)
 
 #define OP_INT_NEG_OVF(x,r) \
@@ -18,7 +16,6 @@
 	else FAIL_OVF("integer negate")
 
 #define OP_INT_ABS(x,r)    r = (x) >= 0 ? x : -(x)
-#define OP_UINT_ABS(x,r)   r = (x)
 
 #define OP_INT_ABS_OVF(x,r) \
 	OP_INT_ABS(x,r); \
@@ -34,9 +31,6 @@
 #define OP_INT_LT(x,y,r)	  r = ((x) <  (y))
 #define OP_INT_GE(x,y,r)	  r = ((x) >= (y))
 
-#define OP_INT_CMP(x,y,r) \
-	r = (((x) > (y)) - ((x) < (y)))
-
 /* addition, subtraction */
 
 #define OP_INT_ADD(x,y,r)     r = (x) + (y)
@@ -78,9 +72,13 @@
        >= 0 and < LONG_BITS. */
 #define OP_INT_RSHIFT(x,y,r)    r = Py_ARITHMETIC_RIGHT_SHIFT(long, x, y)
 #define OP_UINT_RSHIFT(x,y,r)   r = (x) >> (y)
+#define OP_LLONG_RSHIFT(x,y,r)  r = Py_ARITHMETIC_RIGHT_SHIFT(PY_LONG_LONG,x,y)
+#define OP_ULLONG_RSHIFT(x,y,r) r = (x) >> (y)
 
 #define OP_INT_LSHIFT(x,y,r)    r = (x) << (y)
 #define OP_UINT_LSHIFT(x,y,r)   r = (x) << (y)
+#define OP_LLONG_LSHIFT(x,y,r)  r = (x) << (y)
+#define OP_ULLONG_LSHIFT(x,y,r) r = (x) << (y)
 
 #define OP_INT_LSHIFT_OVF(x,y,r) \
 	OP_INT_LSHIFT(x,y,r); \
@@ -92,20 +90,43 @@
 #define OP_INT_RSHIFT_VAL(x,y,r) \
 	if ((y) >= 0) { OP_INT_RSHIFT(x,y,r); } \
 	else FAIL_VAL("negative shift count")
+#define OP_LLONG_RSHIFT_VAL(x,y,r) \
+	if ((y) >= 0) { OP_LLONG_RSHIFT(x,y,r); } \
+	else FAIL_VAL("negative shift count")
 
 #define OP_INT_LSHIFT_VAL(x,y,r) \
 	if ((y) >= 0) { OP_INT_LSHIFT(x,y,r); } \
 	else FAIL_VAL("negative shift count")
+#define OP_LLONG_LSHIFT_VAL(x,y,r) \
+	if ((y) >= 0) { OP_LLONG_LSHIFT(x,y,r); } \
+	else FAIL_VAL("negative shift count")
 
 #define OP_INT_LSHIFT_OVF_VAL(x,y,r) \
 	if ((y) >= 0) { OP_INT_LSHIFT_OVF(x,y,r); } \
 	else FAIL_VAL("negative shift count")
 
+/* pff */
+#define OP_UINT_LSHIFT_VAL(x,y,r) \
+	if ((y) >= 0) { OP_UINT_LSHIFT(x,y,r); } \
+	else FAIL_VAL("negative shift count")
+#define OP_ULLONG_LSHIFT_VAL(x,y,r) \
+	if ((y) >= 0) { OP_ULLONG_LSHIFT(x,y,r); } \
+	else FAIL_VAL("negative shift count")
+
+#define OP_UINT_RSHIFT_VAL(x,y,r) \
+	if ((y) >= 0) { OP_UINT_RSHIFT(x,y,r); } \
+	else FAIL_VAL("negative shift count")
+#define OP_ULLONG_RSHIFT_VAL(x,y,r) \
+	if ((y) >= 0) { OP_ULLONG_RSHIFT(x,y,r); } \
+	else FAIL_VAL("negative shift count")
+
 
 /* floor division */
 
 #define OP_INT_FLOORDIV(x,y,r)    r = op_divmod_adj(x, y, NULL)
 #define OP_UINT_FLOORDIV(x,y,r)   r = (x) / (y)
+#define OP_LLONG_FLOORDIV(x,y,r)  r = op_llong_divmod_adj(x, y, NULL)
+#define OP_ULLONG_FLOORDIV(x,y,r) r = (x) / (y)
 
 #define OP_INT_FLOORDIV_OVF(x,y,r) \
 	if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
@@ -118,6 +139,12 @@
 #define OP_UINT_FLOORDIV_ZER(x,y,r) \
 	if ((y)) { OP_UINT_FLOORDIV(x,y,r); } \
 	else FAIL_ZER("unsigned integer division")
+#define OP_LLONG_FLOORDIV_ZER(x,y,r) \
+	if ((y)) { OP_LLONG_FLOORDIV(x,y,r); } \
+	else FAIL_ZER("integer division")
+#define OP_ULLONG_FLOORDIV_ZER(x,y,r) \
+	if ((y)) { OP_ULLONG_FLOORDIV(x,y,r); } \
+	else FAIL_ZER("unsigned integer division")
 
 #define OP_INT_FLOORDIV_OVF_ZER(x,y,r) \
 	if ((y)) { OP_INT_FLOORDIV_OVF(x,y,r); } \
@@ -127,6 +154,8 @@
 
 #define OP_INT_MOD(x,y,r)     op_divmod_adj(x, y, &r)
 #define OP_UINT_MOD(x,y,r)    r = (x) % (y)
+#define OP_LLONG_MOD(x,y,r)   op_llong_divmod_adj(x, y, &r)
+#define OP_ULLONG_MOD(x,y,r)  r = (x) % (y)
 
 #define OP_INT_MOD_OVF(x,y,r) \
 	if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
@@ -139,6 +168,12 @@
 #define OP_UINT_MOD_ZER(x,y,r) \
 	if ((y)) { OP_UINT_MOD(x,y,r); } \
 	else FAIL_ZER("unsigned integer modulo")
+#define OP_LLONG_MOD_ZER(x,y,r) \
+	if ((y)) { OP_LLONG_MOD(x,y,r); } \
+	else FAIL_ZER("integer modulo")
+#define OP_ULLONG_MOD_ZER(x,y,r) \
+	if ((y)) { OP_ULLONG_MOD(x,y,r); } \
+	else FAIL_ZER("integer modulo")
 
 #define OP_INT_MOD_OVF_ZER(x,y,r) \
 	if ((y)) { OP_INT_MOD_OVF(x,y,r); } \
@@ -225,6 +260,8 @@
 /* prototypes */
 
 long op_divmod_adj(long x, long y, long *p_rem);
+PY_LONG_LONG op_llong_divmod_adj(PY_LONG_LONG x, PY_LONG_LONG y,
+                                 PY_LONG_LONG *p_rem);
 
 /* implementations */
 
@@ -249,63 +286,72 @@
 	return xdivy;
 }
 
-#endif /* PYPY_NOT_MAIN_FILE */
+PY_LONG_LONG op_llong_divmod_adj(PY_LONG_LONG x, PY_LONG_LONG y,
+				 PY_LONG_LONG *p_rem)
+{
+	PY_LONG_LONG xdivy = x / y;
+	PY_LONG_LONG xmody = x - xdivy * y;
+	/* If the signs of x and y differ, and the remainder is non-0,
+	 * C89 doesn't define whether xdivy is now the floor or the
+	 * ceiling of the infinitely precise quotient.  We want the floor,
+	 * and we have it iff the remainder's sign matches y's.
+	 */
+	if (xmody && ((y ^ xmody) < 0) /* i.e. and signs differ */) {
+		xmody += y;
+		--xdivy;
+		assert(xmody && ((y ^ xmody) >= 0));
+	}
+	if (p_rem)
+		*p_rem = xmody;
+	return xdivy;
+}
 
-/* no editing below this point */
-/* following lines are generated by mkuint.py */
+#endif /* PYPY_NOT_MAIN_FILE */
 
 #define OP_UINT_IS_TRUE OP_INT_IS_TRUE
 #define OP_UINT_INVERT OP_INT_INVERT
-#define OP_UINT_POS OP_INT_POS
-#define OP_UINT_NEG OP_INT_NEG
-/* skipping OP_UINT_ABS */
+#define OP_UINT_ADD OP_INT_ADD
+#define OP_UINT_SUB OP_INT_SUB
+#define OP_UINT_MUL OP_INT_MUL
+#define OP_UINT_LT OP_INT_LT
+#define OP_UINT_LE OP_INT_LE
 #define OP_UINT_EQ OP_INT_EQ
 #define OP_UINT_NE OP_INT_NE
-#define OP_UINT_LE OP_INT_LE
 #define OP_UINT_GT OP_INT_GT
-#define OP_UINT_LT OP_INT_LT
 #define OP_UINT_GE OP_INT_GE
-#define OP_UINT_CMP OP_INT_CMP
-#define OP_UINT_ADD OP_INT_ADD
-#define OP_UINT_SUB OP_INT_SUB
-#define OP_UINT_MUL OP_INT_MUL
-/* skipping OP_UINT_RSHIFT */
-/* skipping OP_UINT_LSHIFT */
-/* skipping OP_UINT_FLOORDIV */
-/* skipping OP_UINT_FLOORDIV_ZER */
-/* skipping OP_UINT_MOD */
-/* skipping OP_UINT_MOD_ZER */
 #define OP_UINT_AND OP_INT_AND
 #define OP_UINT_OR OP_INT_OR
 #define OP_UINT_XOR OP_INT_XOR
 
-#define OP_ULLONG_MUL OP_INT_MUL
-#define OP_ULLONG_GT OP_INT_GT
-
 #define OP_LLONG_IS_TRUE OP_INT_IS_TRUE
-#define OP_LLONG_INVERT OP_INT_INVERT
-
-#define OP_LLONG_POS OP_INT_POS
-#define OP_LLONG_NEG OP_INT_NEG
+#define OP_LLONG_NEG     OP_INT_NEG
+#define OP_LLONG_ABS     OP_INT_ABS
+#define OP_LLONG_INVERT  OP_INT_INVERT
 
 #define OP_LLONG_ADD OP_INT_ADD
 #define OP_LLONG_SUB OP_INT_SUB
 #define OP_LLONG_MUL OP_INT_MUL
-#define OP_LLONG_FLOORDIV OP_INT_FLOORDIV
-
-#define OP_LLONG_EQ  OP_INT_EQ
-#define OP_LLONG_NE  OP_INT_NE
 #define OP_LLONG_LT  OP_INT_LT
 #define OP_LLONG_LE  OP_INT_LE
+#define OP_LLONG_EQ  OP_INT_EQ
+#define OP_LLONG_NE  OP_INT_NE
 #define OP_LLONG_GT  OP_INT_GT
 #define OP_LLONG_GE  OP_INT_GE
-
-#define OP_LLONG_CMP OP_INT_CMP
-
 #define OP_LLONG_AND    OP_INT_AND
 #define OP_LLONG_OR     OP_INT_OR
 #define OP_LLONG_XOR    OP_INT_XOR
 
-#define OP_LLONG_ABS    OP_INT_ABS
-#define OP_LLONG_RSHIFT OP_INT_RSHIFT
-#define OP_LLONG_LSHIFT OP_INT_LSHIFT
+#define OP_ULLONG_IS_TRUE OP_LLONG_IS_TRUE
+#define OP_ULLONG_INVERT  OP_LLONG_INVERT
+#define OP_ULLONG_ADD OP_LLONG_ADD
+#define OP_ULLONG_SUB OP_LLONG_SUB
+#define OP_ULLONG_MUL OP_LLONG_MUL
+#define OP_ULLONG_LT OP_LLONG_LT
+#define OP_ULLONG_LE OP_LLONG_LE
+#define OP_ULLONG_EQ OP_LLONG_EQ
+#define OP_ULLONG_NE OP_LLONG_NE
+#define OP_ULLONG_GT OP_LLONG_GT
+#define OP_ULLONG_GE OP_LLONG_GE
+#define OP_ULLONG_AND OP_LLONG_AND
+#define OP_ULLONG_OR OP_LLONG_OR
+#define OP_ULLONG_XOR OP_LLONG_XOR

Modified: pypy/dist/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/cli/opcodes.py	(original)
+++ pypy/dist/pypy/translator/cli/opcodes.py	Thu Sep 28 19:44:54 2006
@@ -117,8 +117,6 @@
     'int_mod_ovf_zer':          _check_zer('rem'),
 
     'uint_is_true':             [PushAllArgs, 'ldc.i4.0', 'cgt.un'],
-    'uint_neg':                 'neg',
-    'uint_abs':                 _abs('unsigned int32'), # TODO: ?
     'uint_invert':              'not',
 
     'uint_add':                 'add',
@@ -183,8 +181,6 @@
     'llong_xor':                'xor',
 
     'ullong_is_true':            [PushAllArgs, 'ldc.i8 0', 'cgt.un'],
-    'ullong_neg':                None,
-    'ullong_abs':                _abs('unsigned int64'),
     'ullong_invert':             'not',
 
     'ullong_add':               'add',

Modified: pypy/dist/pypy/translator/llvm/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/opwriter.py	(original)
+++ pypy/dist/pypy/translator/llvm/opwriter.py	Thu Sep 28 19:44:54 2006
@@ -193,10 +193,6 @@
     def int_neg(self, opr):
         self._generic_neg(opr, "0")
 
-    # this is really generated, don't know why
-    # XXX rxe: Surely that cant be right?
-    uint_neg = int_neg
-
     llong_neg = int_neg
 
     def float_neg(self, opr):



More information about the Pypy-commit mailing list