[pypy-svn] r68801 - in pypy/trunk/pypy: config jit/backend jit/backend/x86

arigo at codespeak.net arigo at codespeak.net
Tue Oct 27 18:40:53 CET 2009


Author: arigo
Date: Tue Oct 27 18:40:53 2009
New Revision: 68801

Added:
   pypy/trunk/pypy/jit/backend/x86/detect_sse2.py
Modified:
   pypy/trunk/pypy/config/translationoption.py
   pypy/trunk/pypy/jit/backend/detect_cpu.py
   pypy/trunk/pypy/jit/backend/x86/runner.py
Log:
Detect if the CPU is old enough to not support SSE2,
and just disable float support in that case.


Modified: pypy/trunk/pypy/config/translationoption.py
==============================================================================
--- pypy/trunk/pypy/config/translationoption.py	(original)
+++ pypy/trunk/pypy/config/translationoption.py	Tue Oct 27 18:40:53 2009
@@ -102,7 +102,7 @@
                          ("translation.gcrootfinder", "asmgcc"),
                          ("translation.list_comprehension_operations", True)]),
     ChoiceOption("jit_backend", "choose the backend for the JIT",
-                 ["auto", "x86", "llvm"],
+                 ["auto", "x86", "x86-without-sse2", "llvm"],
                  default="auto", cmdline="--jit-backend"),
     ChoiceOption("jit_debug", "the amount of debugging dumps made by the JIT",
                  ["off", "profile", "steps", "detailed"],

Modified: pypy/trunk/pypy/jit/backend/detect_cpu.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/detect_cpu.py	(original)
+++ pypy/trunk/pypy/jit/backend/detect_cpu.py	Tue Oct 27 18:40:53 2009
@@ -1,13 +1,14 @@
 """
 Processor auto-detection
 """
+import autopath
 import sys, os
 
 
 class ProcessorAutodetectError(Exception):
     pass
 
-def autodetect():
+def autodetect_main_model():
     mach = None
     try:
         import platform
@@ -40,11 +41,21 @@
     except KeyError:
         raise ProcessorAutodetectError, "unsupported processor '%s'" % mach
 
+def autodetect():
+    model = autodetect_main_model()
+    if model in ('i386', 'x86'):
+        from pypy.jit.backend.x86.detect_sse2 import detect_sse2
+        if not detect_sse2():
+            model = 'x86-without-sse2'
+    return model
+
 def getcpuclass(backend_name="auto"):
     if backend_name == "auto":
         backend_name = autodetect()
     if backend_name in ('i386', 'x86'):
         from pypy.jit.backend.x86.runner import CPU
+    elif backend_name == 'x86-without-sse2':
+        from pypy.jit.backend.x86.runner import CPU386_NO_SSE2 as CPU
     elif backend_name == 'cli':
         from pypy.jit.backend.cli.runner import CliCPU as CPU
     elif backend_name == 'llvm':

Added: pypy/trunk/pypy/jit/backend/x86/detect_sse2.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/jit/backend/x86/detect_sse2.py	Tue Oct 27 18:40:53 2009
@@ -0,0 +1,27 @@
+import autopath
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rlib.rmmap import alloc, free
+
+
+def detect_sse2():
+    data = alloc(4096)
+    pos = 0
+    for c in ("\xB8\x01\x00\x00\x00"     # MOV EAX, 1
+              "\x53"                     # PUSH EBX
+              "\x0F\xA2"                 # CPUID
+              "\x5B"                     # POP EBX
+              "\x92"                     # XCHG EAX, EDX
+              "\xC3"):                   # RET
+        data[pos] = c
+        pos += 1
+    fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data)
+    code = fnptr()
+    free(data, 4096)
+    return bool(code & (1<<25)) and bool(code & (1<<26))
+
+
+if __name__ == '__main__':
+    if detect_sse2():
+        print 'Processor supports sse2.'
+    else:
+        print 'Missing processor support for sse2.'

Modified: pypy/trunk/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/trunk/pypy/jit/backend/x86/runner.py	Tue Oct 27 18:40:53 2009
@@ -88,6 +88,10 @@
         return CPU386.cast_adr_to_int(adr)
 
 
+class CPU386_NO_SSE2(CPU386):
+    supports_floats = False
+
+
 CPU = CPU386
 
 import pypy.jit.metainterp.executor



More information about the Pypy-commit mailing list