[pypy-commit] pypy ppc-jit-backend-rpythonization: (fijal, edelsohn) improve rassembler until it works. more work required to make it rpython

fijal noreply at buildbot.pypy.org
Tue Feb 7 00:16:45 CET 2012


Author: fijal
Branch: ppc-jit-backend-rpythonization
Changeset: r52154:39f8e2a9fd18
Date: 2012-02-06 15:15 -0800
http://bitbucket.org/pypy/pypy/changeset/39f8e2a9fd18/

Log:	(fijal, edelsohn) improve rassembler until it works. more work
	required to make it rpython

diff --git a/pypy/jit/backend/ppc/ppcgen/asmfunc.py b/pypy/jit/backend/ppc/ppcgen/asmfunc.py
--- a/pypy/jit/backend/ppc/ppcgen/asmfunc.py
+++ b/pypy/jit/backend/ppc/ppcgen/asmfunc.py
@@ -5,6 +5,7 @@
 from pypy.jit.backend.llsupport.asmmemmgr import AsmMemoryManager
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.jit.backend.ppc.ppcgen.arch import IS_PPC_32, IS_PPC_64, WORD
+from pypy.rlib.rarithmetic import r_uint
 
 _ppcgen = None
 
@@ -19,17 +20,14 @@
         self.code = MachineCodeBlockWrapper()
         if IS_PPC_64:
             # allocate function descriptor - 3 doublewords
-            self.emit(0)
-            self.emit(0)
-            self.emit(0)
-            self.emit(0)
-            self.emit(0)
-            self.emit(0)
+            for i in range(6):
+                self.emit(r_uint(0))
 
-    def emit(self, insn):
-        bytes = struct.pack("i", insn)
-        for byte in bytes:
-            self.code.writechar(byte)
+    def emit(self, word):
+        self.code.writechar(chr((word >> 24) & 0xFF))
+        self.code.writechar(chr((word >> 16) & 0xFF))
+        self.code.writechar(chr((word >> 8) & 0xFF))
+        self.code.writechar(chr(word & 0xFF))
 
     def get_function(self):
         i = self.code.materialize(AsmMemoryManager(), [])
diff --git a/pypy/jit/backend/ppc/ppcgen/assembler.py b/pypy/jit/backend/ppc/ppcgen/assembler.py
--- a/pypy/jit/backend/ppc/ppcgen/assembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/assembler.py
@@ -51,7 +51,7 @@
                 inst.fields[f] = l
         buf = []
         for inst in self.insts:
-            buf.append(inst.assemble())
+            buf.append(inst)#.assemble())
         if dump:
             for i in range(len(buf)):
                 inst = self.disassemble(buf[i], self.rlabels, i*4)
@@ -61,11 +61,11 @@
         return buf
 
     def assemble(self, dump=os.environ.has_key('PPY_DEBUG')):
-        insns = self.assemble0(dump)
+        #insns = self.assemble0(dump)
         from pypy.jit.backend.ppc.ppcgen import asmfunc
-        c = asmfunc.AsmCode(len(insns)*4)
-        for i in insns:
-            c.emit(i)
+        c = asmfunc.AsmCode(len(self.insts)*4)
+        for i in self.insts:
+            c.emit(i)#.assemble())
         return c.get_function()
 
     def get_idescs(cls):
diff --git a/pypy/jit/backend/ppc/ppcgen/codebuilder.py b/pypy/jit/backend/ppc/ppcgen/codebuilder.py
--- a/pypy/jit/backend/ppc/ppcgen/codebuilder.py
+++ b/pypy/jit/backend/ppc/ppcgen/codebuilder.py
@@ -27,6 +27,7 @@
 from pypy.rlib.objectmodel import we_are_translated
 
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.jit.backend.ppc.ppcgen.rassemblermaker import make_rassembler
 
 A = Form("frD", "frA", "frB", "XO3", "Rc")
 A1 = Form("frD", "frB", "XO3", "Rc")
@@ -888,10 +889,7 @@
 
     mtcr = BA.mtcrf(CRM=0xFF)
 
-    def emit(self, insn):
-        bytes = struct.pack("i", insn)
-        for byte in bytes:
-            self.writechar(byte)
+PPCAssembler = make_rassembler(PPCAssembler)
 
 def hi(w):
     return w >> 16
@@ -967,6 +965,14 @@
         self.fail_boxes_int = values_array(lltype.Signed, failargs_limit)
         self.r0_in_use = r0_in_use
 
+    def check(self, desc, v, *args):
+        desc.__get__(self)(*args)
+        ins = self.insts.pop()
+        expected = ins.assemble()
+        if expected < 0:
+            expected += 1<<32
+        assert v == expected
+
     def load_imm(self, rD, word):
         rD = rD.as_key()
         if word <= 32767 and word >= -32768:
@@ -1075,7 +1081,7 @@
         self.assemble(show)
         insts = self.insts
         for inst in insts:
-            self.write32(inst.assemble())
+            self.write32(inst)#.assemble())
 
     def _dump_trace(self, addr, name, formatter=-1):
         if not we_are_translated():
diff --git a/pypy/jit/backend/ppc/ppcgen/form.py b/pypy/jit/backend/ppc/ppcgen/form.py
--- a/pypy/jit/backend/ppc/ppcgen/form.py
+++ b/pypy/jit/backend/ppc/ppcgen/form.py
@@ -14,8 +14,8 @@
         self.fields = fields
         self.lfields = [k for (k,v) in fields.iteritems()
                         if isinstance(v, str)]
-        if not self.lfields:
-            self.assemble() # for error checking only
+        #if not self.lfields:
+        #    self.assemble() # for error checking only
     def assemble(self):
         r = 0
         for field in self.fields:
diff --git a/pypy/jit/backend/ppc/ppcgen/rassemblermaker.py b/pypy/jit/backend/ppc/ppcgen/rassemblermaker.py
--- a/pypy/jit/backend/ppc/ppcgen/rassemblermaker.py
+++ b/pypy/jit/backend/ppc/ppcgen/rassemblermaker.py
@@ -1,6 +1,7 @@
 from pypy.tool.sourcetools import compile2
 from pypy.rlib.rarithmetic import r_uint
 from pypy.jit.backend.ppc.ppcgen.form import IDesc, IDupDesc
+from pypy.jit.backend.ppc.ppcgen.ppc_field import IField
 
 ##     "opcode": ( 0,  5),
 ##     "rA":     (11, 15, 'unsigned', regname._R),
@@ -37,14 +38,24 @@
     #body.append('print %r'%name + ', ' + ', '.join(["'%s:', %s"%(s, s) for s in sig]))
     for field, value in fieldvalues:
         if field.name == 'spr':
-            body.append('spr = (%s&31) << 5 | (%s >> 5 & 31)'%(value, value))
-            value = 'spr'
-        body.append('v |= (%3s & r_uint(%#05x)) << %d'%(value,
-                                           field.mask,
-                                           (32 - field.right - 1)))
+            body.append('spr1 = (%s&31) << 5 | (%s >> 5 & 31)'%(value, value))
+            value = 'spr1'
+        elif field.name == 'mbe':
+            body.append('mbe1 = (%s & 31) << 1 | (%s & 32) >> 5' % (value, value))
+            value = 'mbe1'
+        elif field.name == 'sh':
+            body.append('sh1 = (%s & 31) << 10 | (%s & 32) >> 5' % (value, value))
+            value = 'sh1'
+        if isinstance(field, IField):
+            body.append('v |= ((%3s >> 2) & r_uint(%#05x)) << 2' % (value, field.mask))
+        else:
+            body.append('v |= (%3s & r_uint(%#05x)) << %d'%(value,
+                                                            field.mask,
+                                                            (32 - field.right - 1)))
+    #body.append('self.check(desc, v, %s)' % ', '.join(sig))
     body.append('self.emit(v)')
     src = 'def %s(self, %s):\n    %s'%(name, ', '.join(sig), '\n    '.join(body))
-    d = {'r_uint':r_uint}
+    d = {'r_uint':r_uint, 'desc': desc}
     #print src
     exec compile2(src) in d
     return d[name]


More information about the pypy-commit mailing list