Commits

Antonio Cuni committed f72e39c

implement jit_ffi_save_result_float

Comments (0)

Files changed (3)

rpython/jit/metainterp/blackhole.py

         data_out = rffi.ptradd(exchange_buffer, cif_description.exchange_result)
         rffi.cast(ARRAY, data_out)[0] = result
 
+    @arguments("cpu", "i", "i", "f")
+    def bhimpl_libffi_save_result_float(self, cif_description, exchange_buffer, result):
+        from rpython.rtyper.lltypesystem import llmemory, rffi
+        from rpython.rlib.jit_libffi import CIF_DESCRIPTION_P
+        ARRAY = lltype.Ptr(rffi.CArray(lltype.Float))
+        
+        cif_description = llmemory.cast_int_to_adr(cif_description)
+        cif_description = llmemory.cast_adr_to_ptr(cif_description,
+                                                   CIF_DESCRIPTION_P)
+
+        exchange_buffer = llmemory.cast_int_to_adr(exchange_buffer)
+        exchange_buffer = llmemory.cast_adr_to_ptr(exchange_buffer,
+                                                   rffi.CCHARP)
+
+        data_out = rffi.ptradd(exchange_buffer, cif_description.exchange_result)
+        rffi.cast(ARRAY, data_out)[0] = result
+
+
     # ----------
     # helpers to resume running in blackhole mode when a guard failed
 

rpython/jit/metainterp/pyjitpl.py

                                             ConstInt(ofs // itemsize), box_result],
                                            None, descr)
 
+    opimpl_libffi_save_result_float = opimpl_libffi_save_result_int
+
     # ------------------------------
 
     def setup_call(self, argboxes):

rpython/jit/metainterp/test/test_fficall.py

 
         unroll_avalues = unrolling_iterable(avalues)
 
-        @jit.oopspec("libffi_call(cif_description,func_addr,exchange_buffer)")
-        def fake_call_impl(cif_description, func_addr, exchange_buffer):
+        def fake_call_impl_any(cif_description, func_addr, exchange_buffer):
             ofs = 16
             for avalue in unroll_avalues:
                 TYPE = rffi.CArray(lltype.typeOf(avalue))
             TYPE = rffi.CArray(lltype.typeOf(write_rvalue))
             data = rffi.ptradd(exchange_buffer, ofs)
             rffi.cast(lltype.Ptr(TYPE), data)[0] = write_rvalue
+
+        @jit.oopspec("libffi_call(cif_description,func_addr,exchange_buffer)")
+        def fake_call_impl_void(cif_description, func_addr, exchange_buffer):
+            fake_call_impl_any(cif_description, func_addr, exchange_buffer)
+            return None
+
+        @jit.oopspec("libffi_call(cif_description,func_addr,exchange_buffer)")
+        def fake_call_impl_int(cif_description, func_addr, exchange_buffer):
+            fake_call_impl_any(cif_description, func_addr, exchange_buffer)
             return NonConstant(-1)
 
+        @jit.oopspec("libffi_call(cif_description,func_addr,exchange_buffer)")
+        def fake_call_impl_float(cif_description, func_addr, exchange_buffer):
+            fake_call_impl_any(cif_description, func_addr, exchange_buffer)
+            return NonConstant(-1.0)
+
         def fake_call(cif_description, func_addr, exchange_buffer):
-            result = fake_call_impl(cif_description, func_addr, exchange_buffer)
-            jit_ffi_save_result('int', cif_description, exchange_buffer, result)
-
+            if cif_description.rtype == types.void:
+                fake_call_impl_void(cif_description, func_addr, exchange_buffer)
+            elif cif_description.rtype == types.double:
+                result = fake_call_impl_float(cif_description, func_addr, exchange_buffer)
+                jit_ffi_save_result('float', cif_description, exchange_buffer, result)
+            else:
+                result = fake_call_impl_int(cif_description, func_addr, exchange_buffer)
+                jit_ffi_save_result('int', cif_description, exchange_buffer, result)
 
         def f():
             exbuf = lltype.malloc(rffi.CCHARP.TO, (len(avalues)+2) * 16,