[pypy-commit] pypy optresult-unroll: Fix translation. Reduce the size of the constant attached to TEST.

arigo noreply at buildbot.pypy.org
Sun Sep 6 16:08:40 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: optresult-unroll
Changeset: r79479:bad77806a20f
Date: 2015-09-06 16:08 +0200
http://bitbucket.org/pypy/pypy/changeset/bad77806a20f/

Log:	Fix translation. Reduce the size of the constant attached to TEST.

diff --git a/rpython/jit/backend/llsupport/gc.py b/rpython/jit/backend/llsupport/gc.py
--- a/rpython/jit/backend/llsupport/gc.py
+++ b/rpython/jit/backend/llsupport/gc.py
@@ -706,13 +706,24 @@
 
     def _setup_guard_is_object(self):
         from rpython.memory.gctypelayout import GCData, T_IS_RPYTHON_INSTANCE
-        self._infobits_offset, _ = symbolic.get_field_token(GCData.TYPE_INFO,
-                                                            'infobits', True)
-        self._T_IS_RPYTHON_INSTANCE = T_IS_RPYTHON_INSTANCE
+        import struct
+        infobits_offset, _ = symbolic.get_field_token(GCData.TYPE_INFO,
+                                                      'infobits', True)
+        # compute the offset to the actual *byte*, and the byte mask
+        mask = struct.pack("l", T_IS_RPYTHON_INSTANCE)
+        assert mask.count('\x00') == len(mask) - 1
+        infobits_offset_plus = 0
+        while mask.startswith('\x00'):
+            infobits_offset_plus += 1
+            mask = mask[1:]
+        self._infobits_offset = infobits_offset
+        self._infobits_offset_plus = infobits_offset_plus
+        self._T_IS_RPYTHON_INSTANCE_BYTE = ord(mask[0])
 
     def get_translated_info_for_guard_is_object(self):
         infobits_offset = rffi.cast(lltype.Signed, self._infobits_offset)
-        return (infobits_offset, self._T_IS_RPYTHON_INSTANCE)
+        infobits_offset += self._infobits_offset_plus
+        return (infobits_offset, self._T_IS_RPYTHON_INSTANCE_BYTE)
 
 
 # ____________________________________________________________
diff --git a/rpython/jit/backend/x86/assembler.py b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -1357,24 +1357,24 @@
         else:
             not_implemented("save_into_mem size = %d" % size)
 
-    def _genop_getfield_gc(self, op, arglocs, resloc):
+    def _genop_getfield(self, op, arglocs, resloc):
         base_loc, ofs_loc, size_loc, sign_loc = arglocs
         assert isinstance(size_loc, ImmedLoc)
         source_addr = AddressLoc(base_loc, ofs_loc)
         self.load_from_mem(resloc, source_addr, size_loc, sign_loc)
 
-    genop_getfield_gc_i = _genop_getfield_gc
-    genop_getfield_gc_r = _genop_getfield_gc
-    genop_getfield_gc_f = _genop_getfield_gc
-    genop_getfield_raw_i = _genop_getfield_gc
-    genop_getfield_raw_f = _genop_getfield_gc
-    genop_getfield_raw_pure_i = _genop_getfield_gc
-    genop_getfield_raw_pure_f = _genop_getfield_gc
-    genop_getfield_gc_pure_i = _genop_getfield_gc
-    genop_getfield_gc_pure_r = _genop_getfield_gc
-    genop_getfield_gc_pure_f = _genop_getfield_gc
+    genop_getfield_gc_i = _genop_getfield
+    genop_getfield_gc_r = _genop_getfield
+    genop_getfield_gc_f = _genop_getfield
+    genop_getfield_raw_i = _genop_getfield
+    genop_getfield_raw_f = _genop_getfield
+    genop_getfield_raw_pure_i = _genop_getfield
+    genop_getfield_raw_pure_f = _genop_getfield
+    genop_getfield_gc_pure_i = _genop_getfield
+    genop_getfield_gc_pure_r = _genop_getfield
+    genop_getfield_gc_pure_f = _genop_getfield
 
-    def _genop_getarrayitem_gc(self, op, arglocs, resloc):
+    def _genop_getarrayitem(self, op, arglocs, resloc):
         base_loc, ofs_loc, size_loc, ofs, sign_loc = arglocs
         assert isinstance(ofs, ImmedLoc)
         assert isinstance(size_loc, ImmedLoc)
@@ -1382,16 +1382,16 @@
         src_addr = addr_add(base_loc, ofs_loc, ofs.value, scale)
         self.load_from_mem(resloc, src_addr, size_loc, sign_loc)
 
-    genop_getarrayitem_gc_i = _genop_getarrayitem_gc
-    genop_getarrayitem_gc_r = _genop_getarrayitem_gc
-    genop_getarrayitem_gc_f = _genop_getarrayitem_gc
-    genop_getarrayitem_gc_pure_i = _genop_getarrayitem_gc
-    genop_getarrayitem_gc_pure_r = _genop_getarrayitem_gc
-    genop_getarrayitem_gc_pure_f = _genop_getarrayitem_gc
-    genop_getarrayitem_raw_i = _genop_getarrayitem_gc
-    genop_getarrayitem_raw_f = _genop_getarrayitem_gc
-    genop_getarrayitem_raw_pure_i = _genop_getarrayitem_gc
-    genop_getarrayitem_raw_pure_f = _genop_getarrayitem_gc
+    genop_getarrayitem_gc_i = _genop_getarrayitem
+    genop_getarrayitem_gc_r = _genop_getarrayitem
+    genop_getarrayitem_gc_f = _genop_getarrayitem
+    genop_getarrayitem_gc_pure_i = _genop_getarrayitem
+    genop_getarrayitem_gc_pure_r = _genop_getarrayitem
+    genop_getarrayitem_gc_pure_f = _genop_getarrayitem
+    genop_getarrayitem_raw_i = _genop_getarrayitem
+    genop_getarrayitem_raw_f = _genop_getarrayitem
+    genop_getarrayitem_raw_pure_i = _genop_getarrayitem
+    genop_getarrayitem_raw_pure_f = _genop_getarrayitem
 
     def _genop_raw_load(self, op, arglocs, resloc):
         base_loc, ofs_loc, size_loc, ofs, sign_loc = arglocs
@@ -1446,16 +1446,16 @@
         assert isinstance(ofs_loc, ImmedLoc)
         return AddressLoc(base_loc, temp_loc, shift, ofs_loc.value)
 
-    def _genop_getinteriorfield_gc(self, op, arglocs, resloc):
+    def _genop_getinteriorfield(self, op, arglocs, resloc):
         (base_loc, ofs_loc, itemsize_loc, fieldsize_loc,
             index_loc, temp_loc, sign_loc) = arglocs
         src_addr = self._get_interiorfield_addr(temp_loc, index_loc,
                                                 itemsize_loc, base_loc,
                                                 ofs_loc)
         self.load_from_mem(resloc, src_addr, fieldsize_loc, sign_loc)
-    genop_getinteriorfield_gc_i = _genop_getinteriorfield_gc
-    genop_getinteriorfield_gc_r = _genop_getinteriorfield_gc
-    genop_getinteriorfield_gc_f = _genop_getinteriorfield_gc
+    genop_getinteriorfield_gc_i = _genop_getinteriorfield
+    genop_getinteriorfield_gc_r = _genop_getinteriorfield
+    genop_getinteriorfield_gc_f = _genop_getinteriorfield
 
     def genop_discard_increment_debug_counter(self, op, arglocs):
         # The argument should be an immediate address.  This should
@@ -1697,17 +1697,16 @@
         self.guard_success_cc = rx86.Conditions['E']
         self.implement_guard(guard_token)
 
-    def genop_guard_guard_gc_type(self, ign_1, guard_op,
-                                  guard_token, locs, ign_2):
+    def genop_guard_guard_gc_type(self, guard_op, guard_token, locs, ign):
         self._cmp_guard_gc_type(locs[0], locs[1])
-        self.implement_guard(guard_token, 'NE')
+        self.guard_success_cc = rx86.Conditions['E']
+        self.implement_guard(guard_token)
 
-    def genop_guard_guard_is_object(self, ign_1, guard_op,
-                                    guard_token, locs, ign_2):
+    def genop_guard_guard_is_object(self, guard_op, guard_token, locs, ign):
         assert self.cpu.supports_guard_gc_type
         [loc_object, loc_typeid] = locs
-        # idea: read the typeid, fetch the field 'infobits' from the big
-        # typeinfo table, and check the flag 'T_IS_RPYTHON_INSTANCE'.
+        # idea: read the typeid, fetch one byte of the field 'infobits' from
+        # the big typeinfo table, and check the flag 'T_IS_RPYTHON_INSTANCE'.
         if IS_X86_32:
             self.mc.MOVZX16(loc_typeid, mem(loc_object, 0))
         else:
@@ -1719,12 +1718,12 @@
             self.cpu.gc_ll_descr.get_translated_info_for_guard_is_object())
         loc_infobits = addr_add(imm(base_type_info), loc_typeid,
                                 scale=shift_by, offset=infobits_offset)
-        self.mc.TEST(loc_infobits, imm(IS_OBJECT_FLAG))
+        self.mc.TEST8(loc_infobits, imm(IS_OBJECT_FLAG))
         #
-        self.implement_guard(guard_token, 'Z')
+        self.guard_success_cc = rx86.Conditions['NZ']
+        self.implement_guard(guard_token)
 
-    def genop_guard_guard_subclass(self, op, guard_op,
-                                   guard_token, locs, ign_2):
+    def genop_guard_guard_subclass(self, guard_op, guard_token, locs, ign):
         assert self.cpu.supports_guard_gc_type
         [loc_object, loc_check_against_class, loc_tmp] = locs
         assert isinstance(loc_object, RegLoc)
@@ -1757,8 +1756,9 @@
         # check by doing the unsigned comparison (tmp - min) < (max - min)
         self.mc.SUB_ri(loc_tmp.value, check_min)
         self.mc.CMP_ri(loc_tmp.value, check_max - check_min)
-        # the guard fails if we get a "not below" result
-        self.implement_guard(guard_token, 'NB')
+        # the guard passes if we get a result of "below"
+        self.guard_success_cc = rx86.Conditions['B']
+        self.implement_guard(guard_token)
 
     def implement_guard_recovery(self, guard_opnum, faildescr, failargs,
                                  fail_locs, frame_depth):
diff --git a/rpython/jit/backend/x86/rx86.py b/rpython/jit/backend/x86/rx86.py
--- a/rpython/jit/backend/x86/rx86.py
+++ b/rpython/jit/backend/x86/rx86.py
@@ -671,6 +671,7 @@
     CDQ = insn(rex_nw, '\x99')
 
     TEST8_mi = insn(rex_nw, '\xF6', orbyte(0<<3), mem_reg_plus_const(1), immediate(2, 'b'))
+    TEST8_ai = insn(rex_nw, '\xF6', orbyte(0<<3), mem_reg_plus_scaled_reg_plus_const(1), immediate(2, 'b'))
     TEST8_bi = insn(rex_nw, '\xF6', orbyte(0<<3), stack_bp(1), immediate(2, 'b'))
     TEST8_ji = insn(rex_nw, '\xF6', orbyte(0<<3), abs_(1), immediate(2, 'b'))
     TEST_rr = insn(rex_w, '\x85', register(2,8), register(1), '\xC0')


More information about the pypy-commit mailing list