[pypy-commit] pypy ppc-jit-backend: (bivab, hager): Implementation of CALL_ASSEMBLER seems to work

hager noreply at buildbot.pypy.org
Tue Dec 13 21:01:33 CET 2011


Author: hager <sven.hager at uni-duesseldorf.de>
Branch: ppc-jit-backend
Changeset: r50470:eb94afc2c1cd
Date: 2011-12-13 21:01 +0100
http://bitbucket.org/pypy/pypy/changeset/eb94afc2c1cd/

Log:	(bivab, hager): Implementation of CALL_ASSEMBLER seems to work

diff --git a/pypy/jit/backend/ppc/ppcgen/opassembler.py b/pypy/jit/backend/ppc/ppcgen/opassembler.py
--- a/pypy/jit/backend/ppc/ppcgen/opassembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/opassembler.py
@@ -362,11 +362,12 @@
         for i, arg in enumerate(stack_args):
             offset = param_offset + i * WORD
             if arg is not None:
-                self.mc.load_imm(r.r0, arg.value)
+                #self.mc.load_imm(r.SCRATCH, arg.value)
+                self.regalloc_mov(regalloc.loc(arg), r.SCRATCH)
             if IS_PPC_32:
-                self.mc.stw(r.r0.value, r.SP.value, offset)
+                self.mc.stw(r.SCRATCH.value, r.SP.value, offset)
             else:
-                self.mc.std(r.r0.value, r.SP.value, offset)
+                self.mc.std(r.SCRATCH.value, r.SP.value, offset)
         self.mc.free_scratch_reg()
 
         # collect variables that need to go in registers
@@ -397,16 +398,16 @@
         regalloc.before_call(save_all_regs=2)
 
         # remap values stored in core registers
-        remap_frame_layout(self, non_float_locs, non_float_regs, r.r0)
+        remap_frame_layout(self, non_float_locs, non_float_regs, r.SCRATCH)
 
         # the actual call
         if IS_PPC_32:
             self.mc.bl_abs(adr)
         else:
-            self.mc.load_from_addr(r.r0, adr)
-            self.mc.load_from_addr(r.r2, adr + WORD)
+            self.mc.load_from_addr(r.SCRATCH, adr)
+            self.mc.load_from_addr(r.TOC, adr + WORD)
             self.mc.load_from_addr(r.r11, adr + 2 * WORD)
-            self.mc.mtctr(r.r0.value)
+            self.mc.mtctr(r.SCRATCH.value)
             self.mc.bctrl()
             
 
@@ -855,12 +856,12 @@
                 raise AssertionError(kind)
         # check value
         resloc = regalloc.try_allocate_reg(resbox)
-        assert resloc is r.r3
+        assert resloc is r.RES
         self.mc.alloc_scratch_reg(value)
         if IS_PPC_32:
-            self.mc.cmpw(0, resloc.value, r.r0.value)
+            self.mc.cmpw(0, resloc.value, r.SCRATCH.value)
         else:
-            self.mc.cmpd(0, resloc.value, r.r0.value)
+            self.mc.cmpd(0, resloc.value, r.SCRATCH.value)
         self.mc.free_scratch_reg()
         regalloc.possibly_free_var(resbox)
 
@@ -874,21 +875,22 @@
         jd = descr.outermost_jitdriver_sd
         assert jd is not None
         asm_helper_adr = self.cpu.cast_adr_to_int(jd.assembler_helper_adr)
-        with saved_registers(self.mc, r.NONVOLATILES + [r.r3]):
-            # resbox is already in r3
-            self.mov_loc_loc(arglocs[1], r.r4)
-            if IS_PPC_32:
-                self.mc.bl_abs(asm_helper_adr)
-            else:
-                self.mc.load_from_addr(r.r0, asm_helper_adr)
-                self.mc.load_from_addr(r.r2, asm_helper_adr + WORD)
-                self.mc.load_from_addr(r.r11, asm_helper_adr + 2 * WORD)
-                self.mc.mtctr(r.r0.value)
-                self.mc.bctrl()
-            if op.result:
-                resloc = regalloc.after_call(op.result)
-                if resloc.is_vfp_reg():
-                    assert 0, "not implemented yet"
+
+        # do call to helper function
+        self.mov_loc_loc(arglocs[1], r.r4)
+        if IS_PPC_32:
+            self.mc.bl_abs(asm_helper_adr)
+        else:
+            self.mc.load_from_addr(r.SCRATCH, asm_helper_adr)
+            self.mc.load_from_addr(r.TOC, asm_helper_adr + WORD)
+            self.mc.load_from_addr(r.r11, asm_helper_adr + 2 * WORD)
+            self.mc.mtctr(r.r0.value)
+            self.mc.bctrl()
+
+        if op.result:
+            resloc = regalloc.after_call(op.result)
+            if resloc.is_vfp_reg():
+                assert 0, "not implemented yet"
 
         # jump to merge point
         jmp_pos = self.mc.currpos()
@@ -898,8 +900,10 @@
         # Fast Path using result boxes
         # patch the jump to the fast path
         offset = self.mc.currpos() - fast_jmp_pos
-        pmc = OverwritingBuilder(self.mc, fast_jmp_pos, WORD)
-        pmc.b(offset)
+        pmc = OverwritingBuilder(self.mc, fast_jmp_pos, 1)
+        # 12 and 2 mean: jump if the 3rd bit in CR is set
+        pmc.bc(12, 2, offset)
+        pmc.overwrite()
 
         # Reset the vable token --- XXX really too much special logic here:-(
         if jd.index_of_virtualizable >= 0:
@@ -909,12 +913,12 @@
             ofs = fielddescr.offset
             resloc = regalloc.force_allocate_reg(resbox)
             self.alloc_scratch_reg()
-            self.mov_loc_loc(arglocs[1], r.r0)
+            self.mov_loc_loc(arglocs[1], r.SCRATCH)
             self.mc.li(resloc.value, 0)
             if IS_PPC_32:
-                self.mc.stwx(resloc.value, 0, r.r0.value)
+                self.mc.stwx(resloc.value, 0, r.SCRATCH.value)
             else:
-                self.mc.stdx(resloc.value, 0, r.r0.value)
+                self.mc.stdx(resloc.value, 0, r.SCRATCH.value)
             self.free_scratch_reg()
             regalloc.possibly_free_var(resbox)
 
@@ -936,21 +940,25 @@
                 assert 0, "not implemented yet"
             else:
                 if IS_PPC_32:
-                    self.mc.lwzx(resloc.value, 0, r.r0.value)
+                    self.mc.lwzx(resloc.value, 0, r.SCRATCH.value)
                 else:
-                    self.mc.ldx(resloc.value, 0, r.r0.value)
+                    self.mc.ldx(resloc.value, 0, r.SCRATCH.value)
             self.mc.free_scratch_reg()
 
         # merge point
         offset = self.mc.currpos() - jmp_pos
+        if offset >= 0:
+            pmc = OverwritingBuilder(self.mc, jmp_pos, 1)
+            pmc.b(offset)
+            pmc.overwrite()
 
         self.mc.alloc_scratch_reg()
         if IS_PPC_32:
-            self.mc.cmpwi(0, r.r0.value, 0)
-            self.mc.lwz(r.r0.value, r.SPP.value, 0)
+            self.mc.cmpwi(0, r.SCRATCH.value, 0)
+            self.mc.lwz(r.SCRATCH.value, r.SPP.value, 0)
         else:
-            self.mc.cmpdi(0, r.r0.value, 0)
-            self.mc.ld(r.r0.value, r.SPP.value, 0)
+            self.mc.cmpdi(0, r.SCRATCH.value, 0)
+            self.mc.ld(r.SCRATCH.value, r.SPP.value, 0)
         self.mc.cror(2, 1, 2)
         self.mc.free_scratch_reg()
 
diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
--- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
@@ -145,15 +145,15 @@
         if IS_PPC_32:
             # save it in previous frame (Backchain)
             self.mc.stwu(r.SP.value, r.SP.value, -frame_depth)
-            self.mc.mflr(r.r0.value)  # move old link register
+            self.mc.mflr(r.SCRATCH.value)  # move old link register
             # save old link register in previous frame
-            self.mc.stw(r.r0.value, r.SP.value, frame_depth + WORD) 
+            self.mc.stw(r.SCRATCH.value, r.SP.value, frame_depth + WORD) 
             # save r31 at the bottom of the stack frame
             self.mc.stw(r.SPP.value, r.SP.value, WORD)
         else:
             self.mc.stdu(r.SP.value, r.SP.value, -frame_depth)
-            self.mc.mflr(r.r0.value)
-            self.mc.std(r.r0.value, r.SP.value, frame_depth + 2 * WORD)
+            self.mc.mflr(r.SCRATCH.value)
+            self.mc.std(r.SCRATCH.value, r.SP.value, frame_depth + 2 * WORD)
             self.mc.std(r.SPP.value, r.SP.value, WORD)
 
         # compute spilling pointer (SPP)
@@ -328,7 +328,7 @@
         mc.mr(r.r4.value, r.SP.value)          # load stack pointer
         mc.mr(r.r5.value, r.SPP.value)         # load spilling pointer
         #
-        # load address of decoding function into r0
+        # load address of decoding function into SCRATCH
         mc.alloc_scratch_reg(addr)
         if IS_PPC_64:
             mc.std(r.r2.value, r.SP.value, 3 * WORD)
@@ -336,7 +336,7 @@
             mc.load_imm(r.r2, r2_value)
             mc.load_imm(r.r11, r11_value)
         # ... and branch there
-        mc.mtctr(r.r0.value)
+        mc.mtctr(r.SCRATCH.value)
         mc.free_scratch_reg()
         mc.bctrl()
         if IS_PPC_64:
@@ -386,10 +386,10 @@
             if loc.is_reg():
                 reg = loc
             else:
-                reg = r.r0
+                reg = r.SCRATCH
             self.mc.load_from_addr(reg, addr)
             if loc.is_stack():
-                self.regalloc_mov(r.r0, loc)
+                self.regalloc_mov(r.SCRATCH, loc)
 
     def gen_direct_bootstrap_code(self, loophead, looptoken, inputargs, frame_depth):
         self._make_frame(frame_depth)
@@ -424,7 +424,7 @@
 
         # remap values stored in core registers
         self.mc.alloc_scratch_reg()
-        remap_frame_layout(self, nonfloat_args, nonfloat_regs, r.r0)
+        remap_frame_layout(self, nonfloat_args, nonfloat_regs, r.SCRATCH)
         self.mc.free_scratch_reg()
 
         # load values passed on the stack to the corresponding locations
@@ -453,10 +453,10 @@
                     count += 1
                     self.mc.alloc_scratch_reg()
                     if IS_PPC_32:
-                        self.mc.lwz(r.r0.value, r.SPP.value, stack_position)
+                        self.mc.lwz(r.SCRATCH.value, r.SPP.value, stack_position)
                     else:
-                        self.mc.ld(r.r0.value, r.SPP.value, stack_position)
-                    self.mov_loc_loc(r.r0, loc)
+                        self.mc.ld(r.SCRATCH.value, r.SPP.value, stack_position)
+                    self.mov_loc_loc(r.SCRATCH, loc)
                     self.mc.free_scratch_reg()
                 else:
                     assert 0, 'invalid location'
@@ -767,9 +767,9 @@
         # store addr in force index field
         self.mc.alloc_scratch_reg(memaddr)
         if IS_PPC_32:
-            self.mc.stw(r.r0.value, r.SPP.value, self.ENCODING_AREA)
+            self.mc.stw(r.SCRATCH.value, r.SPP.value, self.ENCODING_AREA)
         else:
-            self.mc.std(r.r0.value, r.SPP.value, self.ENCODING_AREA)
+            self.mc.std(r.SCRATCH.value, r.SPP.value, self.ENCODING_AREA)
         self.mc.free_scratch_reg()
 
         if save_exc:
@@ -819,12 +819,14 @@
                 return
             # move immediate value to memory
             elif loc.is_stack():
+                self.mc.alloc_scratch_reg()
                 offset = loc.as_key() * WORD - WORD
-                self.mc.load_imm(r.r0.value, value)
+                self.mc.load_imm(r.SCRATCH.value, value)
                 if IS_PPC_32:
-                    self.mc.stw(r.r0.value, r.SPP.value, offset)
+                    self.mc.stw(r.SCRATCH.value, r.SPP.value, offset)
                 else:
-                    self.mc.std(r.r0.value, r.SPP.value, offset)
+                    self.mc.std(r.SCRATCH.value, r.SPP.value, offset)
+                self.mc.free_scratch_reg()
                 return
             assert 0, "not supported location"
         elif prev_loc.is_stack():
@@ -840,12 +842,14 @@
             # move in memory
             elif loc.is_stack():
                 target_offset = loc.as_key() * WORD - WORD
+                self.mc.alloc_scratch_reg()
                 if IS_PPC_32:
-                    self.mc.lwz(r.r0.value, r.SPP.value, offset)
-                    self.mc.stw(r.r0.value, r.SPP.value, target_offset)
+                    self.mc.lwz(r.SCRATCH.value, r.SPP.value, offset)
+                    self.mc.stw(r.SCRATCH.value, r.SPP.value, target_offset)
                 else:
-                    self.mc.ld(r.r0.value, r.SPP.value, offset)
-                    self.mc.std(r.r0.value, r.SPP.value, target_offset)
+                    self.mc.ld(r.SCRATCH.value, r.SPP.value, offset)
+                    self.mc.std(r.SCRATCH.value, r.SPP.value, target_offset)
+                self.mc.free_scratch_reg()
                 return
             assert 0, "not supported location"
         elif prev_loc.is_reg():
@@ -869,7 +873,7 @@
 
     def regalloc_push(self, loc):
         """Pushes the value stored in loc to the stack
-        Can trash the current value of r0 when pushing a stack
+        Can trash the current value of SCRATCH when pushing a stack
         loc"""
 
         if loc.is_stack():
@@ -896,7 +900,7 @@
 
     def regalloc_pop(self, loc):
         """Pops the value on top of the stack to loc. Can trash the current
-        value of r0 when popping to a stack loc"""
+        value of SCRATCH when popping to a stack loc"""
         if loc.is_stack():
             if loc.type == FLOAT:
                 assert 0, "not implemented yet"
@@ -962,11 +966,11 @@
             return 0
 
     def _write_fail_index(self, fail_index):
-        self.mc.load_imm(r.r0, fail_index)
+        self.mc.load_imm(r.SCRATCH, fail_index)
         if IS_PPC_32:
-            self.mc.stw(r.r0.value, r.SPP.value, self.ENCODING_AREA)
+            self.mc.stw(r.SCRATCH.value, r.SPP.value, self.ENCODING_AREA)
         else:
-            self.mc.std(r.r0.value, r.SPP.value, self.ENCODING_AREA)
+            self.mc.std(r.SCRATCH.value, r.SPP.value, self.ENCODING_AREA)
             
     def load(self, loc, value):
         assert loc.is_reg() and value.is_imm()


More information about the pypy-commit mailing list