[pypy-commit] pypy ppc-jit-backend: Made test_field_basic pass.

hager noreply at buildbot.pypy.org
Wed Aug 24 13:24:34 CEST 2011


Author: hager <sven.hager at uni-duesseldorf.de>
Branch: ppc-jit-backend
Changeset: r46756:6c0cd428f9d5
Date: 2011-08-24 13:26 +0200
http://bitbucket.org/pypy/pypy/changeset/6c0cd428f9d5/

Log:	Made test_field_basic pass. Added a test concerning pointers.
	Reordered some tests in runner.test.

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
@@ -5,11 +5,12 @@
 from pypy.jit.backend.ppc.ppcgen.assembler import Assembler
 from pypy.jit.backend.ppc.ppcgen.symbol_lookup import lookup
 from pypy.jit.backend.ppc.ppcgen.arch import IS_PPC_32
+from pypy.jit.metainterp.history import Const, ConstPtr
 from pypy.jit.backend.llsupport.asmmemmgr import BlockBuilderMixin
 from pypy.jit.backend.llsupport.asmmemmgr import AsmMemoryManager
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.jit.metainterp.resoperation import rop
-from pypy.jit.metainterp.history import BoxInt, ConstInt
+from pypy.jit.metainterp.history import BoxInt, ConstInt, Box
 
 A = Form("frD", "frA", "frB", "XO3", "Rc")
 A1 = Form("frD", "frB", "XO3", "Rc")
@@ -948,7 +949,7 @@
         
     def _unary_int_op_prolog(self, op, cpu):
         arg0 = op.getarg(0)
-        if isinstance(arg0, BoxInt):
+        if isinstance(arg0, Box):
             reg0 = cpu.reg_map[arg0]
         else:
             reg0 = cpu.get_next_register()
@@ -959,12 +960,12 @@
     def _binary_int_op_prolog(self, op, cpu):
         arg0 = op.getarg(0)
         arg1 = op.getarg(1)
-        if isinstance(arg0, BoxInt):
+        if isinstance(arg0, Box):
             reg0 = cpu.reg_map[arg0]
         else:
             reg0 = cpu.get_next_register()
             self.load_word(reg0, arg0.value)
-        if isinstance(arg1, BoxInt):
+        if isinstance(arg1, Box):
             reg1 = cpu.reg_map[arg1]
         else:
             reg1 = cpu.get_next_register()
@@ -1114,6 +1115,53 @@
         self.li(free_reg, 0)
         self.adde(free_reg, free_reg, free_reg)
 
+    def emit_setfield_gc(self, op, cpu):
+        args = op.getarglist()
+        fptr = args[0]
+        value = args[1]
+        fdescr = op.getdescr()
+        offset = fdescr.offset
+        width = fdescr.get_field_size(0)
+        addr_reg = cpu.reg_map[fptr]
+
+        if isinstance(value, Box):
+            value_reg = cpu.reg_map[args[1]]
+        elif isinstance(value, Const):
+            value_reg = cpu.get_next_register()
+            if isinstance(value, ConstInt):
+                self.load_word(value_reg, value.value)
+            elif isinstance(value, ConstPtr):
+                self.load_word(value_reg, rffi.cast(lltype.Signed, value.value))
+            else:
+                assert 0, "%s not supported" % value
+        else:
+            assert 0, "%s not supported" % value
+
+        if width == 4:
+            self.stw(value_reg, addr_reg, offset)
+        elif width == 2:
+            self.sth(value_reg, addr_reg, offset)
+        elif width == 1:
+            self.stb(value_reg, addr_reg, offset)
+
+    def emit_getfield_gc(self, op, cpu):
+        args = op.getarglist()
+        fptr = args[0]
+        fdescr = op.getdescr()
+        offset = fdescr.offset
+        width = fdescr.get_field_size(0)
+        free_reg = cpu.next_free_register
+        field_addr_reg = cpu.reg_map[fptr]
+        if width == 4:
+            self.lwz(free_reg, field_addr_reg, offset)
+        elif width == 2:
+            self.lhz(free_reg, field_addr_reg, offset)
+        elif width == 1:
+            self.lbz(free_reg, field_addr_reg, offset)
+        result = op.result
+        cpu.reg_map[result] = cpu.next_free_register
+        cpu.next_free_register += 1
+
     ############################
     # unary integer operations #
     ############################
@@ -1165,7 +1213,7 @@
         cpu.saved_descr[identifier] = descr
         args = op.getarglist()
         for index, arg in enumerate(args):
-            if isinstance(arg, BoxInt):
+            if isinstance(arg, Box):
                 regnum = cpu.reg_map[arg]
                 addr = cpu.fail_boxes_int.get_addr_for_num(index)
                 self.store_reg(regnum, addr)
@@ -1173,6 +1221,8 @@
                 addr = cpu.fail_boxes_int.get_addr_for_num(index)
                 self.load_word(cpu.next_free_register, arg.value)
                 self.store_reg(cpu.next_free_register, addr)
+            else:
+                assert 0, "arg type not suported"
         self.load_word(3, identifier)
         self.blr()
 
diff --git a/pypy/jit/backend/ppc/runner.py b/pypy/jit/backend/ppc/runner.py
--- a/pypy/jit/backend/ppc/runner.py
+++ b/pypy/jit/backend/ppc/runner.py
@@ -4,6 +4,7 @@
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.jit.metainterp import history, compile
+from pypy.jit.metainterp.history import BoxPtr
 from pypy.jit.backend.x86.assembler import Assembler386
 from pypy.jit.backend.x86.arch import FORCE_INDEX_OFS
 from pypy.jit.backend.x86.profagent import ProfileAgent
@@ -135,6 +136,10 @@
     def set_future_value_int(self, index, value_int):
         self.fail_boxes_int.setitem(index, value_int)
 
+    def set_future_value_ref(self, index, pointer):
+        sign_ptr = rffi.cast(lltype.Signed, pointer)
+        self.fail_boxes_int.setitem(index, sign_ptr)
+
     def clear_latest_values(self, count):
         for index in range(count):
             self.fail_boxes_int.setitem(index, 0)
@@ -153,6 +158,10 @@
         value = self.fail_boxes_int.getitem(index)
         return value
 
+    def get_latest_value_ref(self, index):
+        value = self.fail_boxes_int.getitem(index)
+        return rffi.cast(llmemory.GCREF, value)
+    
     # walk through the given trace and generate machine code
     def _walk_trace_ops(self, codebuilder, operations):
         for op in operations:
diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -457,7 +457,89 @@
 
     def test_ovf_operations_reversed(self):
         self.test_ovf_operations(reversed=True)
-        
+    
+    def test_return_pointer(self):
+        u_box, U_box = self.alloc_instance(self.U)
+        i0 = BoxInt()
+        i1 = BoxInt()
+        ptr = BoxPtr()
+
+        operations = [
+            ResOperation(rop.FINISH, [ptr], None, descr=BasicFailDescr(1))
+            ]
+        inputargs = [i0, ptr, i1]
+        looptoken = LoopToken()
+        self.cpu.compile_loop(inputargs, operations, looptoken)
+        self.cpu.set_future_value_int(0, 10)
+        self.cpu.set_future_value_ref(1, u_box.value)
+        self.cpu.set_future_value_int(2, 20)
+        fail = self.cpu.execute_token(looptoken)
+        result = self.cpu.get_latest_value_ref(0)
+        assert result == u_box.value
+
+    def test_field_basic(self):
+        t_box, T_box = self.alloc_instance(self.T)
+        fielddescr = self.cpu.fielddescrof(self.S, 'value')
+        assert not fielddescr.is_pointer_field()
+        #
+        res = self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(39082)],
+                                     'void', descr=fielddescr)
+        assert res is None
+        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+                                     'int', descr=fielddescr)
+        assert res.value == 39082 
+        #
+        fielddescr1 = self.cpu.fielddescrof(self.S, 'chr1')
+        fielddescr2 = self.cpu.fielddescrof(self.S, 'chr2')
+        shortdescr = self.cpu.fielddescrof(self.S, 'short')
+        self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(250)],
+                               'void', descr=fielddescr2)
+        self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(133)],
+                               'void', descr=fielddescr1)
+        self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(1331)],
+                               'void', descr=shortdescr)
+        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+                                     'int', descr=fielddescr2)
+        assert res.value == 250
+        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+                                     'int', descr=fielddescr1)
+        assert res.value == 133
+        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+                                     'int', descr=shortdescr)
+        assert res.value == 1331
+        #
+        u_box, U_box = self.alloc_instance(self.U)
+        fielddescr2 = self.cpu.fielddescrof(self.S, 'next')
+        assert fielddescr2.is_pointer_field()
+        res = self.execute_operation(rop.SETFIELD_GC, [t_box, u_box],
+                                     'void', descr=fielddescr2)
+        assert res is None
+        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+                                     'ref', descr=fielddescr2)
+        assert res.value == u_box.value
+        #
+        fielddescr2 = self.cpu.fielddescrof(self.S, 'next')
+        null_const = self.null_instance().constbox()
+        res = self.execute_operation(rop.SETFIELD_GC, [t_box, null_const],
+                                     'void', descr=fielddescr2)
+        assert res is None
+        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+                                     'ref', descr=fielddescr2)
+        assert res.value == null_const.value
+        if self.cpu.supports_floats:
+            floatdescr = self.cpu.fielddescrof(self.S, 'float')
+            self.execute_operation(rop.SETFIELD_GC, [t_box, boxfloat(3.4)],
+                                   'void', descr=floatdescr)
+            res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+                                         'float', descr=floatdescr)
+            assert res.getfloat() == 3.4
+            #
+            self.execute_operation(rop.SETFIELD_GC, [t_box, constfloat(-3.6)],
+                                   'void', descr=floatdescr)
+            res = self.execute_operation(rop.GETFIELD_GC, [t_box],
+                                         'float', descr=floatdescr)
+            assert res.getfloat() == -3.6
+
     def test_bh_call(self):
         cpu = self.cpu
         #
@@ -620,71 +702,6 @@
                                      descr=calldescr)
         assert res.getfloat() == 4.0
 
-
-    def test_field_basic(self):
-        t_box, T_box = self.alloc_instance(self.T)
-        fielddescr = self.cpu.fielddescrof(self.S, 'value')
-        assert not fielddescr.is_pointer_field()
-        #
-        res = self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(39082)],
-                                     'void', descr=fielddescr)
-        assert res is None
-        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
-                                     'int', descr=fielddescr)
-        assert res.value == 39082
-        #
-        fielddescr1 = self.cpu.fielddescrof(self.S, 'chr1')
-        fielddescr2 = self.cpu.fielddescrof(self.S, 'chr2')
-        shortdescr = self.cpu.fielddescrof(self.S, 'short')
-        self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(250)],
-                               'void', descr=fielddescr2)
-        self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(133)],
-                               'void', descr=fielddescr1)
-        self.execute_operation(rop.SETFIELD_GC, [t_box, BoxInt(1331)],
-                               'void', descr=shortdescr)
-        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
-                                     'int', descr=fielddescr2)
-        assert res.value == 250
-        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
-                                     'int', descr=fielddescr1)
-        assert res.value == 133
-        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
-                                     'int', descr=shortdescr)
-        assert res.value == 1331
-        
-        #
-        u_box, U_box = self.alloc_instance(self.U)
-        fielddescr2 = self.cpu.fielddescrof(self.S, 'next')
-        assert fielddescr2.is_pointer_field()
-        res = self.execute_operation(rop.SETFIELD_GC, [t_box, u_box],
-                                     'void', descr=fielddescr2)
-        assert res is None
-        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
-                                     'ref', descr=fielddescr2)
-        assert res.value == u_box.value
-        #
-        null_const = self.null_instance().constbox()
-        res = self.execute_operation(rop.SETFIELD_GC, [t_box, null_const],
-                                     'void', descr=fielddescr2)
-        assert res is None
-        res = self.execute_operation(rop.GETFIELD_GC, [t_box],
-                                     'ref', descr=fielddescr2)
-        assert res.value == null_const.value
-        if self.cpu.supports_floats:
-            floatdescr = self.cpu.fielddescrof(self.S, 'float')
-            self.execute_operation(rop.SETFIELD_GC, [t_box, boxfloat(3.4)],
-                                   'void', descr=floatdescr)
-            res = self.execute_operation(rop.GETFIELD_GC, [t_box],
-                                         'float', descr=floatdescr)
-            assert res.getfloat() == 3.4
-            #
-            self.execute_operation(rop.SETFIELD_GC, [t_box, constfloat(-3.6)],
-                                   'void', descr=floatdescr)
-            res = self.execute_operation(rop.GETFIELD_GC, [t_box],
-                                         'float', descr=floatdescr)
-            assert res.getfloat() == -3.6
-
-
     def test_passing_guards(self):
         t_box, T_box = self.alloc_instance(self.T)
         nullbox = self.null_instance()


More information about the pypy-commit mailing list