[pypy-svn] r33969 - pypy/dist/pypy/translator/c/src
arigo at codespeak.net
arigo at codespeak.net
Tue Oct 31 17:41:15 CET 2006
Author: arigo
Date: Tue Oct 31 17:41:13 2006
New Revision: 33969
Added:
pypy/dist/pypy/translator/c/src/asm_gcc_x86.h (contents, props changed)
Modified:
pypy/dist/pypy/translator/c/src/g_include.h
pypy/dist/pypy/translator/c/src/int.h
Log:
Trying to use GCC's asm() on x86 to generate overflow-detecting
instructions. Doesn't seem to make a real difference anyway. If this
gives trouble to anyone feel free to de-#include it.
Added: pypy/dist/pypy/translator/c/src/asm_gcc_x86.h
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/c/src/asm_gcc_x86.h Tue Oct 31 17:41:13 2006
@@ -0,0 +1,57 @@
+/* This optional file only works for GCC on an i386.
+ * It replaces some complex macros with native assembler instructions.
+ */
+
+#undef OP_INT_ADD_OVF
+#define OP_INT_ADD_OVF(x,y,r) \
+ asm volatile("addl %2,%0\n\t" \
+ "jno 0f\n\t" \
+ "pusha\n\t" \
+ "call op_int_overflowed\n\t" \
+ "popa\n\t" \
+ "0:" \
+ : "=r"(r) /* outputs */ \
+ : "0"(x), "g"(y) /* inputs */ \
+ : "cc", "memory") /* clobber */
+
+#undef OP_INT_SUB_OVF
+#define OP_INT_SUB_OVF(x,y,r) \
+ asm volatile("subl %2,%0\n\t" \
+ "jno 0f\n\t" \
+ "pusha\n\t" \
+ "call op_int_overflowed\n\t" \
+ "popa\n\t" \
+ "0:" \
+ : "=r"(r) /* outputs */ \
+ : "0"(x), "g"(y) /* inputs */ \
+ : "cc", "memory") /* clobber */
+
+#undef OP_INT_MUL_OVF
+#define OP_INT_MUL_OVF(x,y,r) \
+ asm volatile("imull %2,%0\n\t" \
+ "jno 0f\n\t" \
+ "pusha\n\t" \
+ "call op_int_overflowed\n\t" \
+ "popa\n\t" \
+ "0:" \
+ : "=r"(r) /* outputs */ \
+ : "0"(x), "g"(y) /* inputs */ \
+ : "cc", "memory") /* clobber */
+
+
+/* prototypes */
+
+extern void op_int_overflowed(void)
+ asm ("op_int_overflowed")
+ __attribute__((used));
+
+/* implementations */
+
+#ifndef PYPY_NOT_MAIN_FILE
+
+void op_int_overflowed(void)
+{
+ FAIL_OVF("integer operation");
+}
+
+#endif
Modified: pypy/dist/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/g_include.h (original)
+++ pypy/dist/pypy/translator/c/src/g_include.h Tue Oct 31 17:41:13 2006
@@ -30,6 +30,11 @@
#include "src/float.h"
#include "src/address.h"
+/* optional assembler bits */
+#if defined(__GNUC__) && defined(__i386__)
+# include "src/asm_gcc_x86.h"
+#endif
+
/*** modules ***/
#ifdef HAVE_RTYPER /* only if we have an RTyper */
# include "src/rtyper.h"
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 Tue Oct 31 17:41:13 2006
@@ -145,7 +145,7 @@
#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) \
+ if ((y) == -1 && (x) == LONG_MIN) \
{ FAIL_OVF("integer division"); } \
else OP_INT_FLOORDIV(x,y,r)
@@ -174,7 +174,7 @@
#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) \
+ if ((y) == -1 && (x) == LONG_MIN) \
{ FAIL_OVF("integer modulo"); }\
else OP_INT_MOD(x,y,r)
More information about the Pypy-commit
mailing list