Commits

Alex Gaynor committed 1454edb

support for floats, except we need a convert_longlong_bytes_to_float llop

Comments (0)

Files changed (4)

pypy/rlib/rerased_raw.py

         self._write_index(hop, v_addr)
 
     def rtype_method_getfloat(self, hop):
-        v_value = self._read_index(hop)
-        return hop.genop("cast_adr_to_float", [v_value], resulttype=lltype.Float)
+        v_addr = self._read_index(hop)
+        v_longlong = hop.genop("force_cast", [v_addr], resulttype=lltype.SignedLongLong)
+        return hop.genop("convert_longlong_bytes_to_float", [v_longlong], resulttype=lltype.Float)
 
     def rtype_method_setfloat(self, hop):
         v_value = hop.inputarg(lltype.Float, arg=2)
-        v_addr = hop.genop("cast_float_to_adr", [v_value], resulttype=llmemory.Address)
+        v_longlong = hop.genop("convert_float_bytes_to_longlong", [v_value], resulttype=lltype.SignedLongLong)
+        v_addr = hop.genop("force_cast", [v_longlong], resulttype=llmemory.Address)
         self._write_index(hop, v_addr)
 
     def rtype_method_getinstance(self, hop):

pypy/rlib/test/test_rerased_raw.py

         assert res == True
 
     def test_float(self):
-        py.test.skip("no float support yet")
         def f(x):
             storage = rerased_raw.UntypedStorage("f")
             storage.setfloat(0, x)

pypy/rpython/llinterp.py

         checkadr(adr)
         return llmemory.cast_adr_to_int(adr, mode)
 
+    def op_convert_float_bytes_to_longlong(self, f):
+        from pypy.rlib import longlong2float
+        return longlong2float.float2longlong(f)
+
     def op_weakref_create(self, v_obj):
         def objgetter():    # special support for gcwrapper.py
             return self.getval(v_obj)

pypy/rpython/lltypesystem/lloperation.py

     'cast_float_to_ulonglong':LLOp(canfold=True),
     'truncate_longlong_to_int':LLOp(canfold=True),
     'force_cast':           LLOp(sideeffects=False),    # only for rffi.cast()
+    'convert_float_bytes_to_longlong': LLOp(canfold=True),
 
     # __________ pointer operations __________