Alex Gaynor avatar Alex Gaynor committed 2bf2ca1

Support the same virtual resize magic with resize_le, allow inlining into default pop() (I don't think this effects app level code yet), and a small optimization for int_floordiv(i0, 1), which I'll add more tests for and port to default.

Comments (0)

Files changed (7)

pypy/jit/codewriter/effectinfo.py

     OS_MATH_SQRT                = 100
 
     OS_LIST_RESIZE_GE           = 120
+    OS_LIST_RESIZE_LE           = 121
 
     def __new__(cls, readonly_descrs_fields,
                 write_descrs_fields, write_descrs_arrays,
         result = object.__new__(cls)
         result.readonly_descrs_fields = readonly_descrs_fields
         if extraeffect == EffectInfo.EF_LOOPINVARIANT or \
-           extraeffect == EffectInfo.EF_PURE:            
+           extraeffect == EffectInfo.EF_PURE:
             result.write_descrs_fields = []
             result.write_descrs_arrays = []
         else:

pypy/jit/codewriter/jtransform.py

     def do_resizable_list__resize_ge(self, op, args, arraydescr, lengthdescr,
                                      itemsdescr, structdescr):
         return self._handle_oopspec_call(op, args, EffectInfo.OS_LIST_RESIZE_GE)
+    def do_resizable_list__resize_le(self, op, args, arraydescr, lengthdescr,
+                                     itemsdescr, structdescr):
+        return self._handle_oopspec_call(op, args, EffectInfo.OS_LIST_RESIZE_LE)
 
 
     # ----------
         assert vinfo is not None
         self.vable_flags[op.args[0]] = op.args[2].value
         return []
-        
+
     # ---------
     # ll_math.sqrt_nonneg()
-    
+
     def _handle_math_sqrt_call(self, op, oopspec_name, args):
         return self._handle_oopspec_call(op, args, EffectInfo.OS_MATH_SQRT,
                                          EffectInfo.EF_PURE)

pypy/jit/metainterp/optimizeopt/rewrite.py

         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
 
+        if v2.is_constant() and v2.box.getint() == 1:
+            self.make_equal_to(op.result, v1)
+            return
         if v1.intbound.known_ge(IntBound(0, 0)) and v2.is_constant():
             val = v2.box.getint()
             if val & (val - 1) == 0 and val > 0: # val == 2**shift

pypy/jit/metainterp/optimizeopt/virtualize.py

             elif oopspecindex == EffectInfo.OS_LIST_RESIZE_GE:
                 if self._optimize_CALL_LIST_RESIZE_GE(op):
                     return
+            elif oopspecindex == EffectInfo.OS_LIST_RESIZE_LE:
+                if self._optimize_CALL_LIST_RESIZE_LE(op):
+                    return
         self.emit_operation(op)
 
     def optimize_VIRTUAL_REF(self, op):
         if not self.optimizer.cpu.ts.CONST_NULL.same_constant(objbox):
             seo(ResOperation(rop.SETFIELD_GC, op.getarglist(), None,
                              descr = vrefinfo.descr_forced))
-        
+
         # - set 'virtual_token' to TOKEN_NONE
         args = [op.getarg(0), ConstInt(vrefinfo.TOKEN_NONE)]
         seo(ResOperation(rop.SETFIELD_GC, args, None,
             return True # 0-length arraycopy
         return False
 
-    def _optimize_CALL_LIST_RESIZE_GE(self, op):
+    def _optimize_CALL_LIST_RESIZE(self, op):
         list_value = self.getvalue(op.getarg(1))
         newsize_value = self.getvalue(op.getarg(2))
         newsize_box = self.get_constant_box(op.getarg(2))
                 list_value.setfield(length_descr, newsize_value)
                 return True
         return False
+    _optimize_CALL_LIST_RESIZE_LE = _optimize_CALL_LIST_RESIZE_GE = _optimize_CALL_LIST_RESIZE
 
     def propagate_forward(self, op):
         opnum = op.getopnum()

pypy/jit/metainterp/test/test_list.py

                 lst += [1]
                 n -= len(lst)
                 s += lst[0]
+                s /= lst.pop()
             return s
         res = self.meta_interp(f, [15], listops=True)
         assert res == f(15)

pypy/rpython/lltypesystem/rlist.py

         l.length = newsize
     else:
         _ll_list_resize_really(l, newsize)
-
+_ll_list_resize_le.oopspec = 'list._resize_le(l, newsize)'
 
 def ll_append_noresize(l, newitem):
     length = l.length
 
 def ll_both_none(lst1, lst2):
     return not lst1 and not lst2
-        
+
 
 # ____________________________________________________________
 #

pypy/rpython/rlist.py

         v_lst = hop.inputarg(self, 0)
         cRESLIST = hop.inputconst(Void, hop.r_result.LIST)
         return hop.gendirectcall(ll_copy, cRESLIST, v_lst)
-    
+
     def rtype_len(self, hop):
         v_lst, = hop.inputargs(self)
         if hop.args_s[0].listdef.listitem.resized:
         else:
             ll_func = ll_list_is_true_foldable
         return hop.gendirectcall(ll_func, v_lst)
-    
+
     def rtype_method_reverse(self, hop):
         v_lst, = hop.inputargs(self)
         hop.exception_cannot_occur()
         return pair(r_lst, r_int).rtype_getitem(hop, checkidx=True)
 
     rtype_getitem_idx_key = rtype_getitem_idx
-    
+
     def rtype_setitem((r_lst, r_int), hop):
         if hop.has_implicit_exception(IndexError):
             spec = dum_checkidx
 ##            return hop.gendirectcall(ll_both_none, v_lst1, v_lst2)
 
 ##        return pairtype(Repr, Repr).rtype_is_(pair(r_lst1, r_lst2), hop)
- 
+
     def rtype_eq((r_lst1, r_lst2), hop):
         assert r_lst1.item_repr == r_lst2.item_repr
         v_lst1, v_lst2 = hop.inputargs(r_lst1, r_lst2)
     else:
         check = item
     if (not malloc_zero_filled) or check: # as long as malloc it is known to zero the allocated memory avoid zeroing twice
-    
+
         i = 0
         while i < count:
             l.ll_setitem_fast(i, item)
         l.ll_setitem_fast(index, null)
     l._ll_resize_le(newlength)
     return res
-ll_pop_default.oopspec = 'list.pop(l)'
 
 def ll_pop_zero(func, l):
     length = l.ll_length()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.