[pypy-svn] r75817 - in pypy/trunk/pypy/jit: backend/llgraph metainterp metainterp/test

fijal at codespeak.net fijal at codespeak.net
Sat Jul 3 10:03:07 CEST 2010


Author: fijal
Date: Sat Jul  3 10:03:05 2010
New Revision: 75817

Modified:
   pypy/trunk/pypy/jit/backend/llgraph/llimpl.py
   pypy/trunk/pypy/jit/backend/llgraph/runner.py
   pypy/trunk/pypy/jit/metainterp/blackhole.py
   pypy/trunk/pypy/jit/metainterp/test/test_basic.py
Log:
Teach about floats


Modified: pypy/trunk/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/trunk/pypy/jit/backend/llgraph/llimpl.py	Sat Jul  3 10:03:05 2010
@@ -1207,6 +1207,10 @@
     array = array._obj.container
     return cast_to_float(array.getitem(index))
 
+def do_getarrayitem_raw_float(array, index):
+    array = array.adr.ptr._obj
+    return cast_to_float(array.getitem(index))
+
 def do_getarrayitem_gc_ptr(array, index):
     array = array._obj.container
     return cast_to_ptr(array.getitem(index))
@@ -1267,6 +1271,12 @@
     newvalue = cast_from_float(ITEMTYPE, newvalue)
     array.setitem(index, newvalue)
 
+def do_setarrayitem_raw_float(array, index, newvalue):
+    array = array.adr.ptr
+    ITEMTYPE = lltype.typeOf(array).TO.OF
+    newvalue = cast_from_int(ITEMTYPE, newvalue)
+    array._obj.setitem(index, newvalue)
+
 def do_setarrayitem_gc_ptr(array, index, newvalue):
     array = array._obj.container
     ITEMTYPE = lltype.typeOf(array).OF

Modified: pypy/trunk/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/trunk/pypy/jit/backend/llgraph/runner.py	Sat Jul  3 10:03:05 2010
@@ -325,6 +325,9 @@
     def bh_getarrayitem_gc_f(self, arraydescr, array, index):
         assert isinstance(arraydescr, Descr)
         return llimpl.do_getarrayitem_gc_float(array, index)
+    def bh_getarrayitem_raw_f(self, arraydescr, array, index):
+        assert isinstance(arraydescr, Descr)
+        return llimpl.do_getarrayitem_raw_float(array, index)
 
     def bh_getfield_gc_i(self, struct, fielddescr):
         assert isinstance(fielddescr, Descr)
@@ -386,6 +389,10 @@
         assert isinstance(arraydescr, Descr)
         llimpl.do_setarrayitem_gc_float(array, index, newvalue)
 
+    def bh_setarrayitem_raw_f(self, arraydescr, array, index, newvalue):
+        assert isinstance(arraydescr, Descr)
+        llimpl.do_setarrayitem_raw_float(array, index, newvalue)
+
     def bh_setfield_gc_i(self, struct, fielddescr, newvalue):
         assert isinstance(fielddescr, Descr)
         llimpl.do_setfield_gc_int(struct, fielddescr.ofs, newvalue)

Modified: pypy/trunk/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/blackhole.py	Sat Jul  3 10:03:05 2010
@@ -993,6 +993,9 @@
     @arguments("cpu", "i", "d", "i", returns="i")
     def bhimpl_getarrayitem_raw_i(cpu, array, arraydescr, index):
         return cpu.bh_getarrayitem_raw_i(arraydescr, array, index)
+    @arguments("cpu", "i", "d", "i", returns="f")
+    def bhimpl_getarrayitem_raw_f(cpu, array, arraydescr, index):
+        return cpu.bh_getarrayitem_raw_f(arraydescr, array, index)
 
     @arguments("cpu", "r", "d", "i", "i")
     def bhimpl_setarrayitem_gc_i(cpu, array, arraydescr, index, newvalue):
@@ -1007,6 +1010,9 @@
     @arguments("cpu", "i", "d", "i", "i")
     def bhimpl_setarrayitem_raw_i(cpu, array, arraydescr, index, newvalue):
         cpu.bh_setarrayitem_raw_i(arraydescr, array, index, newvalue)
+    @arguments("cpu", "i", "d", "i", "f")
+    def bhimpl_setarrayitem_raw_f(cpu, array, arraydescr, index, newvalue):
+        cpu.bh_setarrayitem_raw_f(arraydescr, array, index, newvalue)
 
     # note, there is no 'r' here, since it can't happen
 

Modified: pypy/trunk/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_basic.py	Sat Jul  3 10:03:05 2010
@@ -1577,6 +1577,20 @@
         res = self.interp_operations(f, [10])
         assert res == 10
 
+    def test_raw_malloc_and_access_float(self):
+        from pypy.rpython.lltypesystem import rffi
+        
+        TP = rffi.CArray(lltype.Float)
+        
+        def f(n, f):
+            a = lltype.malloc(TP, n, flavor='raw')
+            a[0] = f
+            res = a[0]
+            lltype.free(a, flavor='raw')
+            return res
+
+        res = self.interp_operations(f, [10, 3.5])
+        assert res == 3.5
 
 class TestOOtype(BasicTests, OOJitMixin):
 



More information about the Pypy-commit mailing list