[pypy-svn] r53414 - pypy/branch/jit-hotpath/pypy/jit/codegen/test

fijal at codespeak.net fijal at codespeak.net
Sun Apr 6 03:20:22 CEST 2008


Author: fijal
Date: Sun Apr  6 03:20:20 2008
New Revision: 53414

Modified:
   pypy/branch/jit-hotpath/pypy/jit/codegen/test/rgenop_tests.py
Log:
A test for float frame_place_write


Modified: pypy/branch/jit-hotpath/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/codegen/test/rgenop_tests.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/codegen/test/rgenop_tests.py	Sun Apr  6 03:20:20 2008
@@ -1,4 +1,5 @@
 import random, sys, py
+from pypy.rlib.objectmodel import specialize
 from pypy.rpython.annlowlevel import MixLevelAnnotatorPolicy, llhelper
 from pypy.rlib.rarithmetic import intmask, r_uint
 from pypy.rlib.objectmodel import keepalive_until_here
@@ -729,39 +730,58 @@
         return res
     return read_frame_var_runner
 
-class FramePlaceWriter:
-    FUNC = lltype.Ptr(lltype.FuncType([llmemory.Address, lltype.Signed],
-                                      lltype.Void))
-    def __init__(self, RGenOp):
-        def writer(base, value):
-            if value > 5:
-                RGenOp.write_frame_place(lltype.Signed, base,
-                                         self.place1, value * 7)
-            RGenOp.write_frame_place(lltype.Signed, base,
-                                     self.place2, value * 10)
-        self.writer = writer
-    def get_writer(self, place1, place2):
-        self.place1 = place1
-        self.place2 = place2
-        return llhelper(self.FUNC, self.writer)
-
-def make_write_frame_place(rgenop, get_writer):
-    signed_kind = rgenop.kindToken(lltype.Signed)
-    sigtoken = rgenop.sigToken(FUNC)
-    writertoken = rgenop.sigToken(FramePlaceWriter.FUNC.TO)
+def get_frame_place_writer(TP):
+    class FramePlaceWriter:
+        FUNC = lltype.Ptr(lltype.FuncType([llmemory.Address, TP],
+                                          lltype.Void))
+        def __init__(self, RGenOp):
+            def writer(base, value):
+                if value > 5:
+                    RGenOp.write_frame_place(TP, base,
+                                             self.place1, value * 7)
+                RGenOp.write_frame_place(TP, base,
+                                         self.place2, value * 10)
+            self.writer = writer
+        def get_writer(self, place1, place2):
+            self.place1 = place1
+            self.place2 = place2
+            return llhelper(self.FUNC, self.writer)
+    return FramePlaceWriter
+
+FramePlaceWriter = get_frame_place_writer(lltype.Signed)
+FramePlaceWriterFloat = get_frame_place_writer(lltype.Float)
+
+ at specialize.arg(2, 3)
+def make_write_frame_place(rgenop, get_writer, TP, frame_writer):
+    kind = rgenop.kindToken(TP)
+    if TP is lltype.Signed:
+        F = FUNC
+    else:
+        F = FLOATFUNC
+    sigtoken = rgenop.sigToken(F)
+    writertoken = rgenop.sigToken(frame_writer.FUNC.TO)
 
     builder, gv_f, [gv_x] = rgenop.newgraph(sigtoken, "f")
     builder.start_writing()
 
     gv_base = builder.genop_get_frame_base()
-    gv_k = rgenop.genconst(-100)
-    place1 = builder.alloc_frame_place(signed_kind, gv_initial_value=gv_k)
-    place2 = builder.alloc_frame_place(signed_kind)
+    if TP is lltype.Signed:
+        gv_k = rgenop.genconst(-100)
+    elif TP is lltype.Float:
+        gv_k = rgenop.genconst(-33.3)
+    else:
+        raise NotImplementedError
+    place1 = builder.alloc_frame_place(kind, gv_initial_value=gv_k)
+    place2 = builder.alloc_frame_place(kind)
     gv_writer = rgenop.constPrebuiltGlobal(get_writer(place1, place2))
     builder.genop_call(writertoken, gv_writer, [gv_base, gv_x])
     gv_y = builder.genop_absorb_place(place1)
     gv_z = builder.genop_absorb_place(place2)
-    gv_diff = builder.genop2("int_sub", gv_y, gv_z)
+    if TP is lltype.Float:
+        op = "float_sub"
+    else:
+        op = "int_sub"
+    gv_diff = builder.genop2(op, gv_y, gv_z)
     builder.finish_and_return(sigtoken, gv_diff)
     builder.end()
 
@@ -772,7 +792,8 @@
 
     def write_frame_place_runner(x):
         rgenop = RGenOp()
-        gv_f = make_write_frame_place(rgenop, fvw.get_writer)
+        gv_f = make_write_frame_place(rgenop, fvw.get_writer, lltype.Signed,
+                                      FramePlaceWriter)
         fn = gv_f.revealconst(lltype.Ptr(FUNC))
         res = fn(x)
         keepalive_until_here(rgenop)    # to keep the code blocks alive
@@ -1574,13 +1595,31 @@
             return writer_ptr
 
         rgenop = self.RGenOp()
-        gv_callable = make_write_frame_place(rgenop, get_writer)
+        gv_callable = make_write_frame_place(rgenop, get_writer,
+                                             lltype.Signed, FramePlaceWriter)
         fnptr = self.cast(gv_callable, 1)
         res = fnptr(3)
         assert res == -100 - 30
         res = fnptr(6)
         assert res == 42 - 60
 
+    def test_write_frame_place_float_direct(self):
+        def get_writer(place1, place2):
+            fvw = FramePlaceWriterFloat(self.RGenOp)
+            fvw.place1 = place1
+            fvw.place2 = place2
+            writer_ptr = self.directtesthelper(fvw.FUNC, fvw.writer)
+            return writer_ptr
+
+        rgenop = self.RGenOp()
+        gv_callable = make_write_frame_place(rgenop, get_writer, lltype.Float,
+                                             FramePlaceWriterFloat)
+        fnptr = self.cast_float(gv_callable, 1)
+        res = fnptr(3.3)
+        assert res == -33.3 - 33.
+        res = fnptr(6.3)
+        assert res == -18.9    
+
     def test_write_lots_of_frame_places_direct(self):
         def get_writer(places):
             fvw = ManyFramePlaceWriter(self.RGenOp)



More information about the Pypy-commit mailing list