[pypy-svn] r76055 - in pypy/branch/interplevel-array/pypy: jit/tl module/array module/array/test

hakanardo at codespeak.net hakanardo at codespeak.net
Fri Jul 9 07:06:35 CEST 2010


Author: hakanardo
Date: Fri Jul  9 07:06:32 2010
New Revision: 76055

Modified:
   pypy/branch/interplevel-array/pypy/jit/tl/pypyjit_demo.py
   pypy/branch/interplevel-array/pypy/module/array/interp_array.py
   pypy/branch/interplevel-array/pypy/module/array/test/inttst.py
   pypy/branch/interplevel-array/pypy/module/array/test/sumtst.py
Log:
jit-able getitem/setitem

Modified: pypy/branch/interplevel-array/pypy/jit/tl/pypyjit_demo.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/jit/tl/pypyjit_demo.py	(original)
+++ pypy/branch/interplevel-array/pypy/jit/tl/pypyjit_demo.py	Fri Jul  9 07:06:32 2010
@@ -39,9 +39,11 @@
 
 from array import array
 def f(img):
+    i=0
     sa=0
-    for i in xrange(4):
+    while i<4:
         sa+=img[i]
+        i+=1
     return sa
 
 img=array('i',(1,2,3,4))

Modified: pypy/branch/interplevel-array/pypy/module/array/interp_array.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/module/array/interp_array.py	(original)
+++ pypy/branch/interplevel-array/pypy/module/array/interp_array.py	Fri Jul  9 07:06:32 2010
@@ -132,6 +132,17 @@
         descr_len.unwrap_spec = ['self']
 
 
+        def descr_getslice(self, start, stop, step):
+            size = (stop - start) / step
+            if (stop - start) % step > 0: size += 1
+            w_a=mytype.w_class(self.space)
+            w_a.setlen(size)
+            j=0
+            for i in range(start, stop, step):
+                w_a.buffer[j]=self.buffer[i]
+                j+=1
+            return w_a
+
         def descr_getitem(self, w_idx):
             space=self.space
             start, stop, step = space.decode_index(w_idx, self.len)
@@ -144,15 +155,7 @@
                     item = float(item)
                 return self.space.wrap(item)
             else:
-                size = (stop - start) / step
-                if (stop - start) % step > 0: size += 1
-                w_a=mytype.w_class(self.space)
-                w_a.setlen(size)
-                j=0
-                for i in range(start, stop, step):
-                    w_a.buffer[j]=self.buffer[i]
-                    j+=1
-                return w_a
+                return self.descr_getslice(start, stop, step)
         descr_getitem.unwrap_spec = ['self', W_Root]
 
 
@@ -199,28 +202,30 @@
                 self.descr_append(w_item)
         descr_extend.unwrap_spec = ['self', W_Root]
 
-
+        def descr_setslice(self, start, stop, step, w_item):
+            if isinstance(w_item, W_Array): # Implies mytype.typecode == w_item.typecode
+                size = (stop - start) / step
+                if (stop - start) % step > 0: size += 1
+                if w_item.len != size: # FIXME: Support for step=1
+                    msg = ('attempt to assign array of size %d to ' + 
+                           'slice of size %d') % (w_item.len, size)
+                    raise OperationError(self.space.w_ValueError,
+                                         self.space.wrap(msg))
+                j=0
+                for i in range(start, stop, step):
+                    self.buffer[i]=w_item.buffer[j]
+                    j+=1
+                return
+            msg='can only assign array to array slice'
+            raise OperationError(self.space.w_TypeError, self.space.wrap(msg))
+            
         def descr_setitem(self, w_idx, w_item):
             start, stop, step = self.space.decode_index(w_idx, self.len)
             if step==0:
                 item = self.item_w(w_item)
                 self.buffer[start] = item
             else:
-                if isinstance(w_item, W_Array): # Implies mytype.typecode == w_item.typecode
-                    size = (stop - start) / step
-                    if (stop - start) % step > 0: size += 1
-                    if w_item.len != size: # FIXME: Support for step=1
-                        msg = ('attempt to assign array of size %d to ' + 
-                               'slice of size %d') % (w_item.len, size)
-                        raise OperationError(self.space.w_ValueError,
-                                             self.space.wrap(msg))
-                    j=0
-                    for i in range(start, stop, step):
-                        self.buffer[i]=w_item.buffer[j]
-                        j+=1
-                    return
-                msg='can only assign array to array slice'
-                raise OperationError(self.space.w_TypeError, self.space.wrap(msg))
+                self.descr_setslice(start, stop, step, w_item)
         descr_setitem.unwrap_spec = ['self', W_Root, W_Root]
 
         def descr_fromstring(self, s):

Modified: pypy/branch/interplevel-array/pypy/module/array/test/inttst.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/module/array/test/inttst.py	(original)
+++ pypy/branch/interplevel-array/pypy/module/array/test/inttst.py	Fri Jul  9 07:06:32 2010
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 from time import time
 
-from array import array #, simple_array
+from array import array, simple_array
 
 def f(img, intimg):
     l=0

Modified: pypy/branch/interplevel-array/pypy/module/array/test/sumtst.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/module/array/test/sumtst.py	(original)
+++ pypy/branch/interplevel-array/pypy/module/array/test/sumtst.py	Fri Jul  9 07:06:32 2010
@@ -10,7 +10,7 @@
         i+=1
     return l
 
-if False:
+if True:
     img=array('d', '\x00'*640*480*8)
 else:
     img=simple_array(640*480)
@@ -19,5 +19,5 @@
 #print f(img)
 
 #           C          pypy-simple pypy        cpython
-# sumtst:   0m0.630s   0m0.659s    0m9.185s    0m33.447s
-# intimg:   0m0.646s   0m1.404s    0m26.850s   1m0.279s
+# sumtst:   0m0.630s   0m0.659s    0m0.762s    0m33.447s
+# intimg:   0m0.646s   0m1.078s    0m1.357s    1m0.279s



More information about the Pypy-commit mailing list