예제 #1
0
        def f(points, result_point, n):
            i = 0
            while i < n:
                myjitdriver.jit_merge_point(i=i,
                                            points=points,
                                            n=n,
                                            result_point=result_point)
                x = array_getitem(types.slong,
                                  rffi.sizeof(lltype.Signed) * 2, points, i, 0)
                y = array_getitem(types.slong,
                                  rffi.sizeof(lltype.Signed) * 2, points, i,
                                  rffi.sizeof(lltype.Signed))

                cur_x = array_getitem(types.slong,
                                      rffi.sizeof(lltype.Signed) * 2,
                                      result_point, 0, 0)
                cur_y = array_getitem(types.slong,
                                      rffi.sizeof(lltype.Signed) * 2,
                                      result_point, 0,
                                      rffi.sizeof(lltype.Signed))

                array_setitem(types.slong,
                              rffi.sizeof(lltype.Signed) * 2, result_point, 0,
                              0, cur_x + x)
                array_setitem(types.slong,
                              rffi.sizeof(lltype.Signed) * 2, result_point, 0,
                              rffi.sizeof(lltype.Signed), cur_y + y)
                i += 1
예제 #2
0
        def f(points, result_point, n):
            i = 0
            while i < n:
                myjitdriver.jit_merge_point(i=i, points=points, n=n,
                                            result_point=result_point)
                x = array_getitem(
                    types.slong, rffi.sizeof(lltype.Signed) * 2, points, i, 0
                )
                y = array_getitem(
                    types.slong, rffi.sizeof(lltype.Signed) * 2, points, i, rffi.sizeof(lltype.Signed)
                )

                cur_x = array_getitem(
                    types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, 0
                )
                cur_y = array_getitem(
                    types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, rffi.sizeof(lltype.Signed)
                )

                array_setitem(
                    types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, 0, cur_x + x
                )
                array_setitem(
                    types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, rffi.sizeof(lltype.Signed), cur_y + y
                )
                i += 1
예제 #3
0
 def test_array_fields(self):
     POINT = lltype.Struct("POINT",
         ("x", lltype.Float),
         ("y", lltype.Float),
     )
     points = lltype.malloc(rffi.CArray(POINT), 2, flavor="raw")
     points[0].x = 1.0
     points[0].y = 2.0
     points[1].x = 3.0
     points[1].y = 4.0
     points = rffi.cast(rffi.CArrayPtr(lltype.Char), points)
     assert array_getitem(types.double, 16, points, 0, 0) == 1.0
     assert array_getitem(types.double, 16, points, 0, 8) == 2.0
     assert array_getitem(types.double, 16, points, 1, 0) == 3.0
     assert array_getitem(types.double, 16, points, 1, 8) == 4.0
     #
     array_setitem(types.double, 16, points, 0, 0, 10.0)
     array_setitem(types.double, 16, points, 0, 8, 20.0)
     array_setitem(types.double, 16, points, 1, 0, 30.0)
     array_setitem(types.double, 16, points, 1, 8, 40.0)
     #
     assert array_getitem(types.double, 16, points, 0, 0) == 10.0
     assert array_getitem(types.double, 16, points, 0, 8) == 20.0
     assert array_getitem(types.double, 16, points, 1, 0) == 30.0
     assert array_getitem(types.double, 16, points, 1, 8) == 40.0
     #
     lltype.free(points, flavor="raw")
예제 #4
0
파일: test_libffi.py 프로젝트: njues/Sypy
 def test_array_fields(self):
     POINT = lltype.Struct(
         "POINT",
         ("x", lltype.Float),
         ("y", lltype.Float),
     )
     points = lltype.malloc(rffi.CArray(POINT), 2, flavor="raw")
     points[0].x = 1.0
     points[0].y = 2.0
     points[1].x = 3.0
     points[1].y = 4.0
     points = rffi.cast(rffi.CArrayPtr(lltype.Char), points)
     assert array_getitem(types.double, 16, points, 0, 0) == 1.0
     assert array_getitem(types.double, 16, points, 0, 8) == 2.0
     assert array_getitem(types.double, 16, points, 1, 0) == 3.0
     assert array_getitem(types.double, 16, points, 1, 8) == 4.0
     #
     array_setitem(types.double, 16, points, 0, 0, 10.0)
     array_setitem(types.double, 16, points, 0, 8, 20.0)
     array_setitem(types.double, 16, points, 1, 0, 30.0)
     array_setitem(types.double, 16, points, 1, 8, 40.0)
     #
     assert array_getitem(types.double, 16, points, 0, 0) == 10.0
     assert array_getitem(types.double, 16, points, 0, 8) == 20.0
     assert array_getitem(types.double, 16, points, 1, 0) == 30.0
     assert array_getitem(types.double, 16, points, 1, 8) == 40.0
     #
     lltype.free(points, flavor="raw")
예제 #5
0
 def _read(self, storage, width, i, offset):
     if we_are_translated():
         res = libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T),
                                     width, storage, i, offset)
     else:
         res = libffi.array_getitem_T(self.T, width, storage, i, offset)
     return byteswap(res)
예제 #6
0
파일: types.py 프로젝트: njues/Sypy
 def _read(self, storage, width, i, offset):
     if we_are_translated():
         res = libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T),
                                     width, storage, i, offset)
     else:
         res = libffi.array_getitem_T(self.T, width, storage, i, offset)
     return byteswap(res)
예제 #7
0
 def f(data, n):
     i = 0
     s = rffi.cast(COMPUTE_TYPE, 0)
     while i < n:
         myjitdriver.jit_merge_point(n=n, i=i, s=s, data=data)
         s += rffi.cast(COMPUTE_TYPE, array_getitem(ffitype, rffi.sizeof(TYPE), data, 0, 0))
         i += 1
     return s
예제 #8
0
 def f(data, n):
     i = 0
     s = rffi.cast(COMPUTE_TYPE, 0)
     while i < n:
         myjitdriver.jit_merge_point(n=n, i=i, s=s, data=data)
         s += rffi.cast(
             COMPUTE_TYPE,
             array_getitem(ffitype, rffi.sizeof(TYPE), data, 0, 0))
         i += 1
     return s
예제 #9
0
 def read(self, storage, width, i, offset):
     return self.box(libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T),
         width, storage, i, offset
     ))
예제 #10
0
 def read_bool(self, storage, width, i, offset):
     return bool(self.for_computation(
         libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T),
                              width, storage, i, offset)))
예제 #11
0
 def read(self, storage, width, i, offset):
     return self.box(
         libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T), width,
                              storage, i, offset))