[pypy-svn] r40940 - in pypy/dist/pypy: jit/codegen/ppc rpython translator/c translator/c/src

mwh at codespeak.net mwh at codespeak.net
Wed Mar 21 15:46:29 CET 2007


Author: mwh
Date: Wed Mar 21 15:46:27 2007
New Revision: 40940

Added:
   pypy/dist/pypy/jit/codegen/ppc/_flush_icache.c
Modified:
   pypy/dist/pypy/jit/codegen/ppc/rgenop.py
   pypy/dist/pypy/rpython/extfuncregistry.py
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/g_include.h
Log:
flush the icache after we generate code


Added: pypy/dist/pypy/jit/codegen/ppc/_flush_icache.c
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/ppc/_flush_icache.c	Wed Mar 21 15:46:27 2007
@@ -0,0 +1,20 @@
+#include <Python.h>
+#include "../../../translator/c/src/asm_ppc.h"
+
+static PyObject*
+_flush_icache(PyObject *self, PyObject *args)
+{
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+PyMethodDef _flush_icache_methods[] = {
+	{"_flush_icache", _flush_icache, METH_VARARGS, ""},
+	{0, 0}
+};
+
+PyMODINIT_FUNC
+init_flush_icache(void)
+{
+	Py_InitModule("_flush_icache", _flush_icache_methods);
+}

Modified: pypy/dist/pypy/jit/codegen/ppc/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/ppc/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/ppc/rgenop.py	Wed Mar 21 15:46:27 2007
@@ -6,7 +6,7 @@
 from pypy.rpython.lltypesystem import lloperation
 from pypy.rlib.objectmodel import specialize, we_are_translated
 from pypy.jit.codegen.conftest import option
-from ctypes import POINTER, cast, c_void_p, c_int
+from ctypes import POINTER, cast, c_void_p, c_int, CFUNCTYPE
 
 from pypy.jit.codegen.ppc import codebuf
 from pypy.jit.codegen.ppc.instruction import rSP, rFP, rSCRATCH, gprs
@@ -18,6 +18,7 @@
 from pypy.jit.codegen.ppc.ppcgen.ppc_assembler import MyPPCAssembler
 
 from pypy.jit.codegen.i386.rgenop import gc_malloc_fnaddr
+from pypy.rpython.annlowlevel import llhelper
 
 class RPPCAssembler(make_rassembler(MyPPCAssembler)):
     def emit(self, value):
@@ -26,6 +27,14 @@
 _PPC = RPPCAssembler
 
 
+_flush_icache = None
+def flush_icache(base, size):
+    global _flush_icache
+    if _flush_icache == None:
+        cpath = py.magic.autopath().dirpath().join('_flush_icache.c')
+        _flush_icache  = cpath._getpymodule()._flush_icache
+    _flush_icache(base, size)
+
 NSAVEDREGISTERS = 19
 
 DEBUG_TRAP = option.trap
@@ -652,9 +661,13 @@
 
     def _open(self):
         self.asm.mc = self.rgenop.open_mc()
+        self._code_start = self.asm.mc.tell()
         self.closed = False
 
     def _close(self):
+        _code_stop = self.asm.mc.tell()
+        code_size = self._code_start - _code_stop
+        flush_icache(self._code_start, code_size)
         self.rgenop.close_mc(self.asm.mc)
         self.asm.mc = None
 

Modified: pypy/dist/pypy/rpython/extfuncregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/extfuncregistry.py	(original)
+++ pypy/dist/pypy/rpython/extfuncregistry.py	Wed Mar 21 15:46:27 2007
@@ -51,6 +51,12 @@
                       annotation_hook = hook)
 
 # ___________________________
+# bit of magic for the ppc jit
+from pypy.jit.codegen.ppc.rgenop import flush_icache
+register_external(flush_icache, [int, int], None, "LL_flush_icache")
+
+
+# ___________________________
 # os.path functions
 
 from pypy.tool.sourcetools import func_with_new_name

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Wed Mar 21 15:46:27 2007
@@ -99,6 +99,7 @@
 for name in math_functions:
     EXTERNALS['ll_math.ll_math_%s' % name] = 'LL_math_%s' % name
 
+EXTERNALS['LL_flush_icache'] = 'LL_flush_icache'
 
 #______________________________________________________
 

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	Wed Mar 21 15:46:27 2007
@@ -43,6 +43,11 @@
 #  include "src/asm_gcc_x86.h"
 #endif
 
+#if defined(__GNUC__) && defined(__ppc__)
+#  include "src/asm_ppc.h"
+#endif
+
+
 /*** modules ***/
 #ifdef HAVE_RTYPER      /* only if we have an RTyper */
 #  include "src/rtyper.h"



More information about the Pypy-commit mailing list