Commits

mattip committed 6196be9

test non-aligned float read, add arm specific raw_load_f

Comments (0)

Files changed (3)

+ - fix jitted assembler
+ - add fast path for aligned float
+ - test non-aligned write, fix

rpython/jit/backend/arm/runner.py

 from rpython.jit.backend.llsupport import jitframe
 from rpython.jit.backend.llsupport.llmodel import AbstractLLCPU
 from rpython.rlib.jit_hooks import LOOP_RUN_CONTAINER
-from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.jit.backend.arm.detect import detect_hardfloat
 from rpython.jit.backend.arm.detect import detect_arch_version
+from rpython.jit.codewriter import longlong
 
 jitframe.STATICSIZE = JITFRAME_FIXED_SIZE
 
         assert self.assembler is not None
         return Regalloc(self.assembler)
 
+    def bh_raw_load_f(self, struct, offset, descr):
+        ll_p = rffi.cast(rffi.CCHARP, struct)
+        ll_p_offset = rffi.ptradd(ll_p, offset)
+	if rffi.cast(lltype.Signed, ll_p_offset) & 3:
+            with lltype.scoped_alloc(rffi.CArray(longlong.FLOATSTORAGE), 1) as s_array:
+		rffi.c_memcpy(rffi.cast(rffi.VOIDP, s_array),
+                              rffi.cast(rffi.VOIDP, ll_p_offset),
+                              rffi.sizeof(rffi.DOUBLE))
+        	ll_p = rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE),
+                         s_array)
+		return ll_p[0]
+        ll_p = rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE),
+                         ll_p_offset)
+        return ll_p[0]
+
 
 class CPU_ARM(AbstractARMCPU):
     """ARM"""

rpython/jit/backend/test/runner_test.py

             assert result == rffi.cast(lltype.Float, value)
             rawstorage.free_raw_storage(p)
 
+    def test_raw_load_float_unaligned(self):
+        if not self.cpu.supports_floats:
+            py.test.skip("requires floats")
+        from rpython.rlib import rawstorage
+        for T in [rffi.DOUBLE]:
+            ops = """
+            [i0, i1]
+            f2 = raw_load(i0, i1, descr=arraydescr)
+            finish(f2)
+            """
+            arraydescr = self.cpu.arraydescrof(rffi.CArray(T))
+            p_aligned = rawstorage.alloc_raw_storage(33)
+            for i in range(33):
+                p_aligned[i] = '\xDD'
+            value = rffi.cast(T, 1.12e20)
+            p = rffi.ptradd(p_aligned,1)
+            rawstorage.raw_storage_setitem(p, 16, value)
+            got = self.cpu.bh_raw_load_f(rffi.cast(lltype.Signed, p), 16,
+                                         arraydescr)
+            got = longlong.getrealfloat(got)
+            assert got == rffi.cast(lltype.Float, value)
+            #
+            loop = parse(ops, self.cpu, namespace=locals())
+            looptoken = JitCellToken()
+            self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
+            deadframe = self.cpu.execute_token(looptoken,
+                                               rffi.cast(lltype.Signed, p), 16)
+            result = self.cpu.get_float_value(deadframe, 0)
+            result = longlong.getrealfloat(result)
+            assert result == rffi.cast(lltype.Float, value)
+            rawstorage.free_raw_storage(p_aligned)
+
     def test_raw_load_singlefloat(self):
         if not self.cpu.supports_singlefloats:
             py.test.skip("requires singlefloats")