Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r72309:049f1e96b1de
Date: 2014-07-02 08:24 +0200
http://bitbucket.org/pypy/pypy/changeset/049f1e96b1de/

Log:    Detect the x32 mode. (Note that there are compilation issues too
        which may prevent a translate.py from ever reaching this point, but
        well, if we fix these, then we'll hit this barrier rather than
        compile a buggy executable.)

diff --git a/rpython/jit/backend/detect_cpu.py 
b/rpython/jit/backend/detect_cpu.py
--- a/rpython/jit/backend/detect_cpu.py
+++ b/rpython/jit/backend/detect_cpu.py
@@ -73,11 +73,14 @@
             result = MODEL_X86_64
         else:
             assert sys.maxint == 2**31-1
-            from rpython.jit.backend.x86.detect_sse2 import detect_sse2
-            if detect_sse2():
+            from rpython.jit.backend.x86 import detect_sse2
+            if detect_sse2.detect_sse2():
                 result = MODEL_X86
             else:
                 result = MODEL_X86_NO_SSE2
+            if detect_sse2.detect_x32_mode():
+                raise ProcessorAutodetectError(
+                    'JITting in x32 mode is not implemented')
     #
     if result.startswith('arm'):
         from rpython.jit.backend.arm.detect import detect_float
diff --git a/rpython/jit/backend/x86/detect_sse2.py 
b/rpython/jit/backend/x86/detect_sse2.py
--- a/rpython/jit/backend/x86/detect_sse2.py
+++ b/rpython/jit/backend/x86/detect_sse2.py
@@ -1,3 +1,4 @@
+import sys
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.rmmap import alloc, free
 
@@ -18,9 +19,26 @@
     free(data, 4096)
     return bool(code & (1<<25)) and bool(code & (1<<26))
 
+def detect_x32_mode():
+    data = alloc(4096)
+    pos = 0                         # 32-bit         64-bit / x32
+    for c in ("\x48"                # DEC EAX
+              "\xB8\xC8\x00\x00\x00"# MOV EAX, 200   MOV RAX, 
0x40404040000000C8
+              "\x40\x40\x40\x40"    # 4x INC EAX
+              "\xC3"):              # RET            RET
+        data[pos] = c
+        pos += 1
+    fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
+    code = fnptr()
+    free(data, 4096)
+    assert code in (200, 204, 0x40404040000000C8)
+    return code == 200
+
 
 if __name__ == '__main__':
     if detect_sse2():
         print 'Processor supports sse2.'
     else:
         print 'Missing processor support for sse2.'
+    if detect_x32_mode():
+        print 'Process is running in "x32" mode.'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to