[pypy-commit] pypy win64_gborg: adjusted the overflow checks
ctismer
noreply at buildbot.pypy.org
Sun Nov 6 14:18:55 CET 2011
Author: Christian Tismer <tismer at stackless.com>
Branch: win64_gborg
Changeset: r48823:f8438a89169b
Date: 2011-11-06 13:24 +0100
http://bitbucket.org/pypy/pypy/changeset/f8438a89169b/
Log: adjusted the overflow checks
diff --git a/pypy/rpython/rint.py b/pypy/rpython/rint.py
--- a/pypy/rpython/rint.py
+++ b/pypy/rpython/rint.py
@@ -7,7 +7,8 @@
SignedLongLong, build_number, Number, cast_primitive, typeOf
from pypy.rpython.rmodel import IntegerRepr, inputconst
from pypy.rpython.robject import PyObjRepr, pyobj_repr
-from pypy.rlib.rarithmetic import intmask, r_int, r_uint, r_ulonglong, r_longlong
+from pypy.rlib.rarithmetic import intmask, r_int, r_uint, r_ulonglong, \
+ r_longlong, is_emulated_long
from pypy.rpython.error import TyperError, MissingRTypeOperation
from pypy.rpython.rmodel import log
from pypy.rlib import objectmodel
@@ -440,6 +441,11 @@
Unsigned: ('RPyLong_AsUnsignedLong', lambda pyo: r_uint(pyo._obj.value)),
Signed: ('PyInt_AsLong', lambda pyo: int(pyo._obj.value))
}
+if is_emulated_long: # win64
+ py_to_ll_conversion_functions.update( {
+ Unsigned: ('RPyLong_AsUnsignedLongLong', lambda pyo: r_ulonglong(pyo._obj.value)),
+ Signed: ('RPyLong_AsLongLong', lambda pyo: r_longlong(pyo._obj.value)),
+ } )
ll_to_py_conversion_functions = {
UnsignedLongLong: ('PyLong_FromUnsignedLongLong', lambda i: pyobjectptr(i)),
@@ -447,6 +453,11 @@
Unsigned: ('PyLong_FromUnsignedLong', lambda i: pyobjectptr(i)),
Signed: ('PyInt_FromLong', lambda i: pyobjectptr(i)),
}
+if is_emulated_long: # win64
+ ll_to_py_conversion_functions.update( {
+ Unsigned: ('PyLong_FromUnsignedLongLong', lambda i: pyobjectptr(i)),
+ Signed: ('PyLong_FromLongLong', lambda i: pyobjectptr(i)),
+ } )
class __extend__(pairtype(PyObjRepr, IntegerRepr)):
diff --git a/pypy/translator/c/src/g_prerequisite.h b/pypy/translator/c/src/g_prerequisite.h
--- a/pypy/translator/c/src/g_prerequisite.h
+++ b/pypy/translator/c/src/g_prerequisite.h
@@ -2,13 +2,22 @@
/**************************************************************/
/*** this is included before any code produced by genc.py ***/
-
#ifdef PYPY_STANDALONE
# include "src/commondefs.h"
#else
# include "Python.h"
#endif
+#ifdef _WIN64
+# define new_long __int64
+# define NEW_LONG_MIN LLONG_MIN
+# define NEW_LONG_MAX LLONG_MAX
+#else
+# define new_log long
+# define NEW_LONG_MIN LONG_MIN
+# define NEW_LONG_MAX LONG_MAX
+#endif
+
#ifdef _WIN32
# include <io.h> /* needed, otherwise _lseeki64 truncates to 32-bits (??) */
#endif
diff --git a/pypy/translator/c/src/int.h b/pypy/translator/c/src/int.h
--- a/pypy/translator/c/src/int.h
+++ b/pypy/translator/c/src/int.h
@@ -5,18 +5,24 @@
/*** unary operations ***/
+/************ win64 support:
+ 'new_long' must be defined as
+ __int64 in case of win64
+ long in all other cases
+ */
+
#define OP_INT_IS_TRUE(x,r) r = ((x) != 0)
#define OP_INT_INVERT(x,r) r = ~(x)
#define OP_INT_NEG(x,r) r = -(x)
#define OP_INT_NEG_OVF(x,r) \
- if ((x) == LONG_MIN) FAIL_OVF("integer negate"); \
+ if ((x) == NEW_LONG_MIN) FAIL_OVF("integer negate"); \
OP_INT_NEG(x,r)
#define OP_INT_ABS(x,r) r = (x) >= 0 ? x : -(x)
#define OP_INT_ABS_OVF(x,r) \
- if ((x) == LONG_MIN) FAIL_OVF("integer absolute"); \
+ if ((x) == NEW_LONG_MIN) FAIL_OVF("integer absolute"); \
OP_INT_ABS(x,r)
/*** binary operations ***/
@@ -33,8 +39,8 @@
for the case of a == 0 (both subtractions are then constant-folded).
Note that the following line only works if a <= c in the first place,
which we assume is true. */
-#define OP_INT_BETWEEN(a,b,c,r) r = (((unsigned long)b - (unsigned long)a) \
- < ((unsigned long)c - (unsigned long)a))
+#define OP_INT_BETWEEN(a,b,c,r) r = (((unsigned new_long)b - (unsigned new_long)a) \
+ < ((unsigned new_long)c - (unsigned new_long)a))
/* addition, subtraction */
@@ -42,22 +48,22 @@
/* cast to avoid undefined behaviour on overflow */
#define OP_INT_ADD_OVF(x,y,r) \
- r = (long)((unsigned long)x + y); \
+ r = (new_long)((unsigned new_long)x + y); \
if ((r^x) < 0 && (r^y) < 0) FAIL_OVF("integer addition")
#define OP_INT_ADD_NONNEG_OVF(x,y,r) /* y can be assumed >= 0 */ \
- r = (long)((unsigned long)x + y); \
+ r = (new_long)((unsigned new_long)x + y); \
if ((r&~x) < 0) FAIL_OVF("integer addition")
#define OP_INT_SUB(x,y,r) r = (x) - (y)
#define OP_INT_SUB_OVF(x,y,r) \
- r = (long)((unsigned long)x - y); \
+ r = (new_long)((unsigned new_long)x - y); \
if ((r^x) < 0 && (r^~y) < 0) FAIL_OVF("integer subtraction")
#define OP_INT_MUL(x,y,r) r = (x) * (y)
-#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG
+#if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG && !defined(_WIN64)
#define OP_INT_MUL_OVF(x,y,r) \
{ \
long long _lr = (long long)x * y; \
@@ -78,7 +84,7 @@
#define OP_INT_RSHIFT(x,y,r) CHECK_SHIFT_RANGE(y, PYPY_LONG_BIT); \
- r = Py_ARITHMETIC_RIGHT_SHIFT(long, x, (y))
+ r = Py_ARITHMETIC_RIGHT_SHIFT(new_long, x, (y))
#define OP_UINT_RSHIFT(x,y,r) CHECK_SHIFT_RANGE(y, PYPY_LONG_BIT); \
r = (x) >> (y)
#define OP_LLONG_RSHIFT(x,y,r) CHECK_SHIFT_RANGE(y, PYPY_LONGLONG_BIT); \
@@ -98,7 +104,7 @@
#define OP_INT_LSHIFT_OVF(x,y,r) \
OP_INT_LSHIFT(x,y,r); \
- if ((x) != Py_ARITHMETIC_RIGHT_SHIFT(long, r, (y))) \
+ if ((x) != Py_ARITHMETIC_RIGHT_SHIFT(new_long, r, (y))) \
FAIL_OVF("x<<y losing bits or changing sign")
/* floor division */
@@ -109,7 +115,7 @@
#define OP_ULLONG_FLOORDIV(x,y,r) r = (x) / (y)
#define OP_INT_FLOORDIV_OVF(x,y,r) \
- if ((y) == -1 && (x) == LONG_MIN) \
+ if ((y) == -1 && (x) == NEW_LONG_MIN) \
{ FAIL_OVF("integer division"); r=0; } \
else \
r = (x) / (y)
@@ -149,7 +155,7 @@
#define OP_ULLONG_MOD(x,y,r) r = (x) % (y)
#define OP_INT_MOD_OVF(x,y,r) \
- if ((y) == -1 && (x) == LONG_MIN) \
+ if ((y) == -1 && (x) == NEW_LONG_MIN) \
{ FAIL_OVF("integer modulo"); r=0; } \
else \
r = (x) % (y)
@@ -188,18 +194,18 @@
/*** conversions ***/
-#define OP_CAST_BOOL_TO_INT(x,r) r = (long)(x)
-#define OP_CAST_BOOL_TO_UINT(x,r) r = (unsigned long)(x)
-#define OP_CAST_UINT_TO_INT(x,r) r = (long)(x)
-#define OP_CAST_INT_TO_UINT(x,r) r = (unsigned long)(x)
+#define OP_CAST_BOOL_TO_INT(x,r) r = (new_long)(x)
+#define OP_CAST_BOOL_TO_UINT(x,r) r = (unsigned new_long)(x)
+#define OP_CAST_UINT_TO_INT(x,r) r = (new_long)(x)
+#define OP_CAST_INT_TO_UINT(x,r) r = (unsigned new_long)(x)
#define OP_CAST_INT_TO_LONGLONG(x,r) r = (long long)(x)
-#define OP_CAST_CHAR_TO_INT(x,r) r = (long)((unsigned char)(x))
+#define OP_CAST_CHAR_TO_INT(x,r) r = (new_long)((unsigned char)(x))
#define OP_CAST_INT_TO_CHAR(x,r) r = (char)(x)
-#define OP_CAST_PTR_TO_INT(x,r) r = (long)(x) /* XXX */
+#define OP_CAST_PTR_TO_INT(x,r) r = (new_long)(x) /* XXX */
-#define OP_TRUNCATE_LONGLONG_TO_INT(x,r) r = (long)(x)
+#define OP_TRUNCATE_LONGLONG_TO_INT(x,r) r = (new_long)(x)
-#define OP_CAST_UNICHAR_TO_INT(x,r) r = (long)((unsigned long)(x)) /*?*/
+#define OP_CAST_UNICHAR_TO_INT(x,r) r = (new_long)((unsigned new_long)(x)) /*?*/
#define OP_CAST_INT_TO_UNICHAR(x,r) r = (unsigned int)(x)
/* bool operations */
More information about the pypy-commit
mailing list