[pypy-commit] pypy ffi-backend: write more tests

fijal noreply at buildbot.pypy.org
Sun Jun 24 22:20:12 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: ffi-backend
Changeset: r55812:33416a0cad0b
Date: 2012-06-24 22:15 +0200
http://bitbucket.org/pypy/pypy/changeset/33416a0cad0b/

Log:	write more tests

diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py
--- a/pypy/jit/backend/llgraph/llimpl.py
+++ b/pypy/jit/backend/llgraph/llimpl.py
@@ -835,17 +835,17 @@
 
     def op_raw_store(self, arraydescr, addr, offset, value):
         if arraydescr.typeinfo == REF:
-            xxx
+            raise AssertionError("cannot store GC pointer in raw storage")
         elif arraydescr.typeinfo == INT:
             do_raw_store_int(addr, offset, arraydescr.ofs, value)
         elif arraydescr.typeinfo == FLOAT:
-            xxx
+            do_raw_store_float(addr, offset, arraydescr.ofs, value)
         else:
             raise NotImplementedError
 
     def op_raw_load(self, arraydescr, addr, offset):
-        if arraydescr.typeinfo == REF:
-            xxx
+        if arraydescr.typeinfo == REF: 
+            raise AssertionError("cannot store GC pointer in raw storage")
         elif arraydescr.typeinfo == INT:
             return do_raw_load_int(addr, offset, arraydescr.ofs)
         elif arraydescr.typeinfo == FLOAT:
@@ -1526,6 +1526,7 @@
     ll_p = rffi.cast(rffi.CCHARP, struct)
     ll_p = rffi.cast(lltype.Ptr(TYPE), rffi.ptradd(ll_p, offset))
     ll_p[0] = rffi.cast(TYPE.OF, value)
+do_raw_store_float = do_raw_store_int
 
 def do_new(size):
     TYPE = symbolic.Size2Type[size]
diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -3392,6 +3392,54 @@
             assert result == rffi.cast(lltype.Float, value)
             rawstorage.free_raw_storage(p)
 
+    def test_raw_store_int(self):
+        from pypy.rlib import rawstorage
+        for T in [rffi.UCHAR, rffi.SIGNEDCHAR,
+                  rffi.USHORT, rffi.SHORT,
+                  rffi.UINT, rffi.INT,
+                  rffi.ULONG, rffi.LONG]:
+            ops = """
+            [i0, i1, i2]
+            raw_store(i0, i1, i2, descr=arraydescr)
+            finish()
+            """
+            arraydescr = self.cpu.arraydescrof(rffi.CArray(T))
+            p = rawstorage.alloc_raw_storage(31)
+            for i in range(31):
+                p[i] = '\xDD'
+            value = 0x4243444546474849
+            loop = parse(ops, self.cpu, namespace=locals())
+            looptoken = JitCellToken()
+            self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
+            self.cpu.execute_token(looptoken,
+                                   rffi.cast(lltype.Signed, p), 16, value)
+            result = rawstorage.raw_storage_getitem(T, p, 16)
+            assert result == rffi.cast(T, value)
+            rawstorage.free_raw_storage(p)
+
+    def test_raw_store_float(self):
+        if not self.cpu.supports_floats:
+            py.test.skip("requires floats")
+        from pypy.rlib import rawstorage
+        for T in [rffi.DOUBLE]:
+            ops = """
+            [i0, i1, f2]
+            raw_store(i0, i1, f2, descr=arraydescr)
+            finish()
+            """
+            arraydescr = self.cpu.arraydescrof(rffi.CArray(T))
+            p = rawstorage.alloc_raw_storage(31)
+            for i in range(31):
+                p[i] = '\xDD'
+            value = 1.23e20
+            loop = parse(ops, self.cpu, namespace=locals())
+            looptoken = JitCellToken()
+            self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
+            self.cpu.execute_token(looptoken,
+                                   rffi.cast(lltype.Signed, p), 16, value)
+            result = rawstorage.raw_storage_getitem(T, p, 16)
+            assert result == rffi.cast(T, value)
+            rawstorage.free_raw_storage(p)
 
 class OOtypeBackendTest(BaseBackendTest):
 


More information about the pypy-commit mailing list