Commits

Armin Rigo  committed 611d19a Merge

merge heads

  • Participants
  • Parent commits 3cd8bf9, e640564
  • Branches ppc-jit-backend

Comments (0)

Files changed (4)

File pypy/jit/backend/ppc/ppcgen/assembler.py

                 return ln
             i += 1
 
+    def get_number_of_ops(self):
+        return len(self.insts)
+
+    def get_relative_pos(self):
+        return 4 * len(self.insts)
+
+    def patch_op(self, index):
+        last = self.insts.pop()
+        self.insts[index] = last
+
     def assemble0(self, dump=os.environ.has_key('PPY_DEBUG')):
         for i, inst in enumerate(self.insts):
             for f in inst.lfields:

File pypy/jit/backend/ppc/ppcgen/ppc_assembler.py

     xor = XS(31, XO1=316, Rc=0)
     xorx = XS(31, XO1=316, Rc=1)
 
-class PPCAssembler(BasicPPCAssembler, BlockBuilderMixin):
+class PPCAssembler(BasicPPCAssembler):
     BA = BasicPPCAssembler
 
     # awkward mnemonics:
 class PPCBuilder(PPCAssembler):
     def __init__(self):
         PPCAssembler.__init__(self)
-        self.init_block_builder()
-        self.patch_list = []
 
     def load_word(self, rD, word):
         self.addis(rD, 0, hi(word))
         if opnum == rop.INT_ADD:
             self.emit_int_add(trace_op, cpu)
         elif opnum == rop.FINISH:
-            self.emit_finish(cpu)
-    
+            self.emit_finish(trace_op, cpu)
+        elif opnum == rop.INT_LE:
+            self.emit_int_le(trace_op, cpu)
+        elif opnum == rop.JUMP:
+            self.emit_jump(trace_op, cpu)
+        elif opnum == rop.GUARD_TRUE:
+            self.emit_guard_true(trace_op, cpu)
+        else:
+            assert 0, "Don't know this opcode"
+
     # --------------------------------------- #
     #             CODE GENERATION             #
     # --------------------------------------- #
         arg0 = op.getarg(0)
         arg1 = op.getarg(1)
 
-        arg0_index = cpu.get_box_index(arg0)
-        addr_box_0 = cpu.fail_boxes_int.get_addr_for_num(arg0_index)
+        regnum = cpu.reg_map[arg0]
+
+        self.addi(cpu.next_free_register, regnum, arg1.value)
+
+        result = op.result
+        cpu.reg_map[result] = cpu.next_free_register
+        cpu.next_free_register += 1
+
+    def emit_int_le(self, op, cpu):
+        arg0 = op.getarg(0)
+        arg1 = op.getarg(1)
+
+        regnum = cpu.reg_map[arg0]
         
-        self.load_from(3, addr_box_0)
-        self.addi(3, 3, arg1.value)
-        self.store_reg(3, addr_box_0)
+        free_reg = cpu.next_free_register
+        self.load_word(free_reg, arg1.value)
+        self.cmp(7, 1, regnum, free_reg)
+        self.crnot(30, 29)
+        self.mfcr(free_reg)
+        self.rlwinm(free_reg, free_reg, 31, 31, 31)
 
-    def emit_finish(self, cpu):
+        result = op.result
+        cpu.reg_map[result] = cpu.next_free_register
+        cpu.next_free_register += 1
+
+    def emit_guard_true(self, op, cpu):
+        arg0 = op.getarg(0)
+        regnum = cpu.reg_map[arg0]
+        self.cmpi(0, 1, regnum, 0)              # result of comparison
+        
+        fail_index = len(cpu.saved_descr)
+        cpu.saved_descr[fail_index] = op.getdescr()
+
+        numops = self.get_number_of_ops()
+        self.beq(0)
+
+        failargs = op.getfailargs()
+        reglist = []
+        for failarg in failargs:
+            reglist.append(cpu.reg_map[failarg])
+
+        cpu.patch_list.append((numops, fail_index, op, reglist))
+
+    def emit_finish(self, op, cpu):
+        fail_index = len(cpu.saved_descr)
+        cpu.saved_descr[fail_index] = op.getdescr()
+
+        args = op.getarglist()
+        for index, arg in enumerate(args):
+            regnum = cpu.reg_map[arg]
+            addr = cpu.fail_boxes_int.get_addr_for_num(index)
+            self.store_reg(regnum, addr)
+
         self.load_word(3, 0)
         self.blr()
 
+    def emit_jump(self, op, cpu):
+        for index, arg in enumerate(op.getarglist()):
+            target = index + 3
+            regnum = cpu.reg_map[arg]
+            self.mr(target, regnum)
+
+        offset = self.get_relative_pos()
+        self.b(-offset + cpu.startpos)
+
 class BranchUpdater(PPCAssembler):
     def __init__(self):
         PPCAssembler.__init__(self)

File pypy/jit/backend/ppc/ppcgen/ppc_field.py

             v = self.decode(i)
             if pc+v in labels:
                 return "%s (%r)"%(v, ', '.join(labels[pc+v]))
-        else:
-            return self.decode(i)
+        return self.decode(i)
 
 
 class spr(Field):

File pypy/jit/backend/ppc/runner.py

 
         # pointer to an array of ints
         # XXX length of the integer array is 1000 for now
-        self.arg_to_box = {}
         self.fail_boxes_int = values_array(lltype.Signed, 1000)
-        self.saved_descr = {}
 
         # floats are not supported yet
         self.supports_floats = False
 
     # compile a given trace
     def compile_loop(self, inputargs, operations, looptoken, log=True):
+        self.saved_descr = {}
+        self.patch_list = []
+        self.reg_map = {}
+        self.inputargs = inputargs
+        
         codebuilder = PPCBuilder()
-        self.saved_descr[len(self.saved_descr)] = operations[-1].getdescr()
+        
+        self.next_free_register = 3
+        for index, arg in enumerate(inputargs):
+            self.reg_map[arg] = self.next_free_register
+            addr = self.fail_boxes_int.get_addr_for_num(index)
+            codebuilder.load_from(self.next_free_register, addr)
+            self.next_free_register += 1
+        
+        self.startpos = codebuilder.get_relative_pos()
 
-        for index, arg in enumerate(inputargs):
-            self.arg_to_box[arg] = index
-            
         self._walk_trace_ops(codebuilder, operations)
+        self._make_epilogue(codebuilder)
 
-        f = codebuilder.assemble()
+        f = codebuilder.assemble(True)
         looptoken.ppc_code = f
 
+    def _make_epilogue(self, codebuilder):
+        for op_index, fail_index, guard, reglist in self.patch_list:
+            curpos = codebuilder.get_relative_pos()
+            offset = curpos - (4 * op_index)
+            assert (1 << 15) > offset
+            codebuilder.beq(offset)
+            codebuilder.patch_op(op_index)
+
+            # store return parameters in memory
+            for index, reg in enumerate(reglist):
+                addr = self.fail_boxes_int.get_addr_for_num(index)
+                codebuilder.store_reg(reg, addr)
+
+            codebuilder.li(3, fail_index)            
+            codebuilder.blr()
+
     def set_future_value_int(self, index, value_int):
         self.fail_boxes_int.setitem(index, value_int)