[pypy-svn] pypy default: Kill all remaining "imm_fine".

arigo commits-noreply at bitbucket.org
Fri Jan 14 15:06:15 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r40670:fb25155406e0
Date: 2011-01-14 12:14 +0100
http://bitbucket.org/pypy/pypy/changeset/fb25155406e0/

Log:	Kill all remaining "imm_fine".

diff --git a/pypy/jit/backend/x86/rx86.py b/pypy/jit/backend/x86/rx86.py
--- a/pypy/jit/backend/x86/rx86.py
+++ b/pypy/jit/backend/x86/rx86.py
@@ -531,6 +531,7 @@
     CDQ = insn(rex_nw, '\x99')
 
     TEST8_mi = insn(rex_w, '\xF6', orbyte(0<<3), mem_reg_plus_const(1), immediate(2, 'b'))
+    TEST8_ji = insn(rex_w, '\xF6', orbyte(0<<3), '\x05', immediate(1), immediate(2, 'b'))
     TEST_rr = insn(rex_w, '\x85', register(2,8), register(1), '\xC0')
 
     # x87 instructions

diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -817,16 +817,22 @@
             self.mc.MOVZX8_rr(result_loc.value, rl.value)
         return genop_cmp
 
-    def _cmpop_float(cond, is_ne=False):
+    def _cmpop_float(cond, rev_cond, is_ne=False):
         def genop_cmp(self, op, arglocs, result_loc):
-            self.mc.UCOMISD(arglocs[0], arglocs[1])
+            if isinstance(arglocs[0], RegLoc):
+                self.mc.UCOMISD(arglocs[0], arglocs[1])
+                checkcond = cond
+            else:
+                self.mc.UCOMISD(arglocs[1], arglocs[0])
+                checkcond = rev_cond
+
             tmp1 = result_loc.lowest8bits()
             if IS_X86_32:
                 tmp2 = result_loc.higher8bits()
             elif IS_X86_64:
                 tmp2 = X86_64_SCRATCH_REG.lowest8bits()
 
-            self.mc.SET_ir(rx86.Conditions[cond], tmp1.value)
+            self.mc.SET_ir(rx86.Conditions[checkcond], tmp1.value)
             if is_ne:
                 self.mc.SET_ir(rx86.Conditions['P'], tmp2.value)
                 self.mc.OR8_rr(tmp1.value, tmp2.value)
@@ -990,12 +996,12 @@
     genop_ptr_eq = genop_int_eq
     genop_ptr_ne = genop_int_ne
 
-    genop_float_lt = _cmpop_float('B')
-    genop_float_le = _cmpop_float('BE')
-    genop_float_ne = _cmpop_float('NE', is_ne=True)
-    genop_float_eq = _cmpop_float('E')
-    genop_float_gt = _cmpop_float('A')
-    genop_float_ge = _cmpop_float('AE')
+    genop_float_lt = _cmpop_float('B', 'A')
+    genop_float_le = _cmpop_float('BE', 'AE')
+    genop_float_ne = _cmpop_float('NE', 'NE', is_ne=True)
+    genop_float_eq = _cmpop_float('E', 'E')
+    genop_float_gt = _cmpop_float('A', 'B')
+    genop_float_ge = _cmpop_float('AE', 'BE')
 
     genop_uint_gt = _cmpop("A", "B")
     genop_uint_lt = _cmpop("B", "A")
@@ -1818,8 +1824,13 @@
             cls = self.cpu.gc_ll_descr.has_write_barrier_class()
             assert cls is not None and isinstance(descr, cls)
         loc_base = arglocs[0]
-        self.mc.TEST8_mi((loc_base.value, descr.jit_wb_if_flag_byteofs),
-                descr.jit_wb_if_flag_singlebyte)
+        if isinstance(loc_base, RegLoc):
+            self.mc.TEST8_mi((loc_base.value, descr.jit_wb_if_flag_byteofs),
+                             descr.jit_wb_if_flag_singlebyte)
+        else:
+            assert isinstance(loc_base, ImmedLoc)
+            self.mc.TEST8_ji(loc_base.value + descr.jit_wb_if_flag_byteofs,
+                             descr.jit_wb_if_flag_singlebyte)
         self.mc.J_il8(rx86.Conditions['Z'], 0) # patched later
         jz_location = self.mc.get_relative_pos()
         # the following is supposed to be the slow path, so whenever possible

diff --git a/pypy/jit/backend/llsupport/regalloc.py b/pypy/jit/backend/llsupport/regalloc.py
--- a/pypy/jit/backend/llsupport/regalloc.py
+++ b/pypy/jit/backend/llsupport/regalloc.py
@@ -210,7 +210,7 @@
         except KeyError:
             return self.frame_manager.loc(box)
 
-    def return_constant(self, v, selected_reg=None):
+    def return_constant(self, v, forbidden_vars=[], selected_reg=None):
         """ Return the location of the constant v.  If 'selected_reg' is
         not None, it will first load its value into this register.
         """
@@ -235,7 +235,7 @@
         """
         self._check_type(v)
         if isinstance(v, Const):
-            return self.return_constant(v, selected_reg)
+            return self.return_constant(v, forbidden_vars, selected_reg)
         
         prev_loc = self.loc(v)
         loc = self.force_allocate_reg(v, forbidden_vars, selected_reg,
@@ -270,7 +270,7 @@
             if self.free_regs:
                 loc = self.free_regs.pop()
             else:
-                loc = self._spill_var(v, forbidden_vars)
+                loc = self._spill_var(v, forbidden_vars, None)
             self.assembler.regalloc_mov(self.convert_to_imm(v), loc)
             self.reg_bindings[result_v] = loc
             return loc

diff --git a/pypy/jit/backend/x86/test/test_rx86.py b/pypy/jit/backend/x86/test/test_rx86.py
--- a/pypy/jit/backend/x86/test/test_rx86.py
+++ b/pypy/jit/backend/x86/test/test_rx86.py
@@ -174,7 +174,12 @@
     assert_encodes_as(CodeBuilder32, 'OR8_rr', (bl, bh), '\x08\xFB')
 
 def test_test8_mi():
-    assert_encodes_as(CodeBuilder32, 'TEST8_mi', ((edx, 16), 99), '\xF6\x42\x10\x63')
+    assert_encodes_as(CodeBuilder32, 'TEST8_mi', ((edx, 16), 99),
+                      '\xF6\x42\x10\x63')
+
+def test_test8_ji():
+    assert_encodes_as(CodeBuilder32, 'TEST8_ji', (0x12345678, 99),
+                      '\xF6\x05\x78\x56\x34\x12\x63')
 
 def test_mov8():
     cb = CodeBuilder32

diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py
--- a/pypy/jit/backend/x86/regalloc.py
+++ b/pypy/jit/backend/x86/regalloc.py
@@ -4,7 +4,7 @@
 
 import os
 from pypy.jit.metainterp.history import (Box, Const, ConstInt, ConstPtr,
-                                         ResOperation, BoxPtr,
+                                         ResOperation, BoxPtr, BoxFloat,
                                          LoopToken, INT, REF, FLOAT)
 from pypy.jit.backend.x86.regloc import *
 from pypy.rpython.lltypesystem import lltype, ll2ctypes, rffi, rstr
@@ -210,17 +210,15 @@
                 self.possibly_free_var(var)
 
     def make_sure_var_in_reg(self, var, forbidden_vars=[],
-                             selected_reg=None, imm_fine=True,
-                             need_lower_byte=False):
+                             selected_reg=None, need_lower_byte=False):
         if var.type == FLOAT:
-            # always pass imm_fine=False for now in this case
+            assert isinstance(var, BoxFloat), (
+                "ConstFloats must be handled differently")
             return self.xrm.make_sure_var_in_reg(var, forbidden_vars,
-                                                 selected_reg, False,
-                                                 need_lower_byte)
+                                                 selected_reg, need_lower_byte)
         else:
             return self.rm.make_sure_var_in_reg(var, forbidden_vars,
-                                                selected_reg, imm_fine,
-                                                need_lower_byte)
+                                                selected_reg, need_lower_byte)
 
     def force_allocate_reg(self, var, forbidden_vars=[], selected_reg=None,
                            need_lower_byte=False):
@@ -590,11 +588,15 @@
     consider_float_truediv = _consider_float_op
 
     def _consider_float_cmp(self, op, guard_op):
-        args = op.getarglist()
-        loc0 = self.xrm.make_sure_var_in_reg(op.getarg(0), args,
-                                             imm_fine=False)
-        loc1 = self.xrm.loc(op.getarg(1))
-        arglocs = [loc0, loc1]
+        vx = op.getarg(0)
+        vy = op.getarg(1)
+        arglocs = [self.loc(vx), self.loc(vy)]
+        if not (isinstance(arglocs[0], RegLoc) or
+                isinstance(arglocs[1], RegLoc)):
+            if isinstance(vx, Const):
+                arglocs[1] = self.xrm.make_sure_var_in_reg(vy)
+            else:
+                arglocs[0] = self.xrm.make_sure_var_in_reg(vx)
         self.xrm.possibly_free_vars_for_op(op)
         if guard_op is None:
             res = self.rm.force_allocate_reg(op.result, need_lower_byte=True)
@@ -620,7 +622,7 @@
         self.xrm.possibly_free_var(op.getarg(0))
 
     def consider_cast_float_to_int(self, op):
-        loc0 = self.xrm.make_sure_var_in_reg(op.getarg(0), imm_fine=False)
+        loc0 = self.xrm.make_sure_var_in_reg(op.getarg(0))
         loc1 = self.rm.force_allocate_reg(op.result)
         self.Perform(op, [loc0], loc1)
         self.xrm.possibly_free_var(op.getarg(0))
@@ -691,8 +693,7 @@
         # ^^^ we force loc_newvalue in a reg (unless it's a Const),
         # because it will be needed anyway by the following setfield_gc.
         # It avoids loading it twice from the memory.
-        loc_base = self.rm.make_sure_var_in_reg(op.getarg(0), args,
-                                                imm_fine=False)
+        loc_base = self.rm.make_sure_var_in_reg(op.getarg(0), args)
         arglocs = [loc_base, loc_newvalue]
         # add eax, ecx and edx as extra "arguments" to ensure they are
         # saved and restored.  Fish in self.rm to know which of these


More information about the Pypy-commit mailing list