Commits

Carl Friedrich Bolz  committed 658f358

use lists instead of dicts for opboolreflex, opboolinvers and opname

  • Participants
  • Parent commits 13859c0

Comments (0)

Files changed (5)

File rpython/jit/metainterp/optimizeopt/rewrite.py

 
 
     def find_rewritable_bool(self, op, args):
-        try:
-            oldopnum = opboolinvers[op.getopnum()]
-        except KeyError:
-            pass
-        else:
+        oldopnum = opboolinvers[op.getopnum()]
+        if oldopnum != -1:
             targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[0], args[1]],
                                                               None))
             if self.try_boolinvers(op, targs):
                 return True
 
-        try:
-            oldopnum = opboolreflex[op.getopnum()] # FIXME: add INT_ADD, INT_MUL
-        except KeyError:
-            pass
-        else:
+        oldopnum = opboolreflex[op.getopnum()] # FIXME: add INT_ADD, INT_MUL
+        if oldopnum != -1:
             targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]],
                                                               None))
             oldop = self.get_pure_result(targs)
                 self.make_equal_to(op.result, self.getvalue(oldop.result))
                 return True
 
-        try:
-            oldopnum = opboolinvers[opboolreflex[op.getopnum()]]
-        except KeyError:
-            pass
-        else:
-            targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]],
-                                                              None))
-            if self.try_boolinvers(op, targs):
-                return True
+        reflex = opboolreflex[op.getopnum()]
+        if reflex != -1:
+            oldopnum = opboolinvers[reflex]
+            if oldopnum != -1:
+                targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]],
+                                                                  None))
+                if self.try_boolinvers(op, targs):
+                    return True
 
         return False
 

File rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py

                 op = opname[opnum]
             except KeyError:
                 continue
-            if 'FLOAT' in op:
+            if 'float' in op:
                 continue
             args = []
             for _ in range(oparity[opnum]):

File rpython/jit/metainterp/optimizeopt/util.py

             opname = name[len(name_prefix):]
             if opname.isupper():
                 assert hasattr(resoperation.rop, opname)
-    for value, name in resoperation.opname.items():
+    for value, name in enumerate(resoperation.opname):
         if op_prefix and not name.startswith(op_prefix):
             continue
         if hasattr(Class, name_prefix + name):

File rpython/jit/metainterp/resoperation.py

                                              ['descr=%r' % descr]))
 
     def getopname(self):
-        try:
-            return opname[self.getopnum()].lower()
-        except KeyError:
-            return '<%d>' % self.getopnum()
+        return opname[self.getopnum()]
 
     def is_guard(self):
         return rop._GUARD_FIRST <= self.getopnum() <= rop._GUARD_LAST
     pass
 
 opclasses = []   # mapping numbers to the concrete ResOp class
-opname = {}      # mapping numbers to the original names, for debugging
+opname = []      # mapping numbers to the original names, for debugging
 oparity = []     # mapping numbers to the arity of the operation or -1
 opwithdescr = [] # mapping numbers to a flag "takes a descr"
 
             arity, withdescr, boolresult = -1, True, False       # default
         setattr(rop, name, i)
         if not name.startswith('_'):
-            opname[i] = name
             cls = create_class_for_op(name, i, arity, withdescr)
             cls._cls_has_bool_result = boolresult
         else:
+            name = '<%d>' % i
             cls = None
+        opname.append(name.lower())
         opclasses.append(cls)
         oparity.append(arity)
         opwithdescr.append(withdescr)
-    assert len(opclasses) == len(oparity) == len(opwithdescr) == len(_oplist)
+    assert len(opclasses) == len(oparity) == len(opwithdescr) == len(_oplist) == len(opname)
 
 def get_base_class(mixin, base):
     try:
 setup(__name__ == '__main__')   # print out the table when run directly
 del _oplist
 
-opboolinvers = {
+def opdict_to_list(d, default=-1):
+    return [d.get(i, default) for i in range(len(opname))]
+
+opboolinvers = opdict_to_list({
     rop.INT_EQ: rop.INT_NE,
     rop.INT_NE: rop.INT_EQ,
     rop.INT_LT: rop.INT_GE,
 
     rop.PTR_EQ: rop.PTR_NE,
     rop.PTR_NE: rop.PTR_EQ,
-}
+})
 
-opboolreflex = {
+opboolreflex = opdict_to_list({
     rop.INT_EQ: rop.INT_EQ,
     rop.INT_NE: rop.INT_NE,
     rop.INT_LT: rop.INT_GT,
 
     rop.PTR_EQ: rop.PTR_EQ,
     rop.PTR_NE: rop.PTR_NE,
-}
+})
 
 
 def get_deep_immutable_oplist(operations):

File rpython/jit/metainterp/test/test_executor.py

 
 def make_args_for_op(op, a, b):
     n=opname[op]
-    if n[0:3] == 'INT' or n[0:4] == 'UINT':
+    if n[0:3] == 'int' or n[0:4] == 'uint':
         arg1 = ConstInt(a)
         arg2 = ConstInt(b)
-    elif n[0:5] == 'FLOAT':
+    elif n[0:5] == 'float':
         arg1 = constfloat(float(a))
         arg2 = constfloat(float(b))
-    elif n[0:3] == 'PTR':
+    elif n[0:3] == 'ptr':
         arg1 = ConstPtr(rffi.cast(llmemory.GCREF, a))
         arg2 = ConstPtr(rffi.cast(llmemory.GCREF, b))
     else:
 
 def test_opboolinvers():
     cpu = FakeCPU()
-    for op1, op2 in opboolinvers.items():
+    for op1, op2 in enumerate(opboolinvers):
+        if op2 == -1:
+            continue
         for a in (1,2,3):
             for b in (1,2,3):
                 arg1, arg2 = make_args_for_op(op1, a, b)
 
 def test_opboolreflex():
     cpu = FakeCPU()
-    for op1, op2 in opboolreflex.items():
+    for op1, op2 in enumerate(opboolreflex):
+        if op2 == -1:
+            continue
         for a in (1,2,3):
             for b in (1,2,3):
                 arg1, arg2 = make_args_for_op(op1, a, b)