Commits

Lenard Lindstrom committed 8662367

switch the order of the blit arguments

Comments (0)

Files changed (7)

     """Does nothing"""
     pass
 
-def blit(destination, source):
+def blit(source, destination):
     """Copy source array onto destination"""
+    saddr = int(ffi.cast('uintptr_t', source))
     daddr = int(ffi.cast('uintptr_t', destination))
-    saddr = int(ffi.cast('uintptr_t', source))
-    blitter.blit_buffer(rffi.cast(ARRAYVIEW_P, daddr),
-                        rffi.cast(ARRAYVIEW_P, saddr))
+    blitter.blit_buffer(rffi.cast(ARRAYVIEW_P, saddr),
+                        rffi.cast(ARRAYVIEW_P, daddr))
 
 def config_jit(option, value):
     """Set JIT parameter"""
         unsigned char *data;
     } ArrayView;
 
-    void blit(ArrayView *destination, ArrayView *source);
+    void blit(ArrayView *source, ArrayView *destination);
     void config_jit(int option, int value);
     void rpython_startup_code(void);
 """)
 
 _blitter.rpython_startup_code()
 
-def blit(destination, source):
+def blit(source, destination):
     """Copy source array to destination
 
     Both destination and source are Python side version 3 array interfaces.
                   ffi.new('ssize_t[]', src_strides),
                   ffi.cast('unsigned char *', src_data)]
     src = ffi.new('ArrayView *', src_values)
-    _blitter.blit(dst, src)
+    _blitter.blit(src, dst)
 
 def get_field(array_interface, name):
     """Return an array interface field

blit_interpreter.py

     return "%d:%s %d %d" %  (ip, name, ord(code[ip + 1]), ord(code[ip + 2]))
 
 
-def compile_loop(ndim, dst_bytesize, dst_offsets, src_bytesize, src_offsets):
+def compile_loop(ndim, src_bytesize, src_offsets, dst_bytesize, dst_offsets):
     """Compile a blit loop"""
 
     # loop start positions
         return -2
     return 0
 
-def execute_loop(code, dst, src, shape, dst_strides, src_strides):
+def execute_loop(code, src, dst, shape, src_strides, dst_strides):
     assert isinstance(code, str)
     ip = 0
     ndim = ord(code[ip])
 config_jit('trace_eagerness', 1)
 for i in range(20):
     start_time = clock()
-    blit(dst, array)
+    blit(array, dst)
     stop_time = clock()
     arrblit_times.append(stop_time - start_time)
 
 
 code_cache = {}
 
-def blit_buffer(destination, source):
+def blit_buffer(source, destination):
     """Copy source array onto destination
 
-destination_ai, source_ai: Python side version 3 array interfaces
+source, destination: Python side version 3 array interface pointers
 
 The source and destination arrays must be integer and the same dimensions.
 
         code = code_cache[key]
     except KeyError:
         code = compile_loop(ndim,
-                            dst_bytesize, dst_offsets,
-                            src_bytesize, src_offsets)
+                            src_bytesize, src_offsets,
+                            dst_bytesize, dst_offsets)
         code_cache[key] = code
-    execute_loop(code, dst_data, src_data,
-                 dst_shape, dst_strides, src_strides)
+    execute_loop(code, src_data, dst_data,
+                 src_shape, src_strides, dst_strides)
 
 def decode_int_type(typestr):
     """Return (is_signed, size, is_lil_endian)"""
     src = np.arange(1, 11, dtype='<u1')
     dst = np.empty(src.shape, dtype='<u1')
     dst.fill(-1)
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src).all()
 
 def test_dst_byte_zeroing():
     # Little-endian destination
     dst = np.empty(src.shape, dtype='<u2')
     dst[...] = -1
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src).all()
 
     # Big-endian destination
     dst = np.empty(src.shape, dtype='>u2')
     dst[...] = -1
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src).all()
 
 def test_2D():
     # C-contiguous destination
     dst = np.empty(src.shape, dtype='<u1')
     dst[...] = -1
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src).all()
 
     # F-contiguous destination
     dst = np.empty(src.shape, dtype='<u1', order='F')
     dst[...] = -1
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src).all()
 
 def test_big_endian_src():
     # Little-endian 4 byte integer destination
     dst = np.empty(src.shape, dtype='<u4')
     dst.fill(-1)
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src).all()
 
     # Big-endian 4 byte integer destination
     dst = np.empty(src.shape, dtype='>u4')
     dst.fill(-1)
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src).all()
 
     # Little-endian 2 byte integer destination
     dst = np.empty(src.shape, dtype='<u2')
     dst.fill(-1)
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src & 0xFFFF).all()
 
     # Big-endian 2 byte integer destination
     dst = np.empty(src.shape, dtype='>u2')
     dst.fill(-1)
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src & 0xFFFF).all()
 
 def test_strides():
     dst_parent = np.empty((2 * shape[0], shape[1] + 1, shape[2]), dtype='<u4')
     dst = dst_parent[::2,:-1,:]
     dst.fill(-1)
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src & 0xFFFF).all()
 
 def test_big_row():
     src = np.arange(10000, dtype='<u4')
     src.shape = 10, src.size // 10
     dst = np.zeros(src.shape, dtype='<u4')
-    blit(dst, src)
+    blit(src, dst)
     assert (dst == src).all()