Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: missing-ndarray-attributes
Changeset: r58576:49ce76217456
Date: 2012-10-29 12:03 +0100
http://bitbucket.org/pypy/pypy/changeset/49ce76217456/

Log:    improve singlefloat byteswap

diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -533,6 +533,9 @@
     def __ne__(self, other):
         return not self.__eq__(other)
 
+    def __repr__(self):
+        return 'r_singlefloat(%s)' % (float(self),)
+
 class r_longfloat(object):
     """A value of the C type 'long double'.
 
@@ -595,22 +598,22 @@
     """ Convert little->big endian and the opposite
     """
     from pypy.rpython.lltypesystem import lltype, rffi
-    from pypy.rlib.longlong2float import longlong2float, float2longlong
+    from pypy.rlib.longlong2float import longlong2float, float2longlong,\
+         uint2singlefloat, singlefloat2uint
 
     T = lltype.typeOf(arg)
-    # XXX we cannot do arithmetics on small ints
-    #if isinstance(arg, base_int):
     is_float = False
     is_single_float = False
     if T == lltype.SingleFloat:
-        T = lltype.Float
-        arg = rffi.cast(T, arg)
+        T = rffi.UINT
         is_single_float = True
-    if T == lltype.Float:
+        arg = singlefloat2uint(arg)
+    elif T == lltype.Float:
         is_float = True
         T = rffi.LONGLONG
         arg = float2longlong(arg)
     else:
+        # we cannot do arithmetics on small ints
         arg = widen(arg)
     if rffi.sizeof(T) == 1:
         res = arg
@@ -634,9 +637,9 @@
                (f >> 24) | (g >> 40) | (h >> 56))
     else:
         assert False # unreachable code
+    if is_single_float:
+        return uint2singlefloat(rffi.cast(rffi.UINT, res))
     if is_float:
         res = rffi.cast(rffi.LONGLONG, res)
-        if is_single_float:
-            return rffi.cast(lltype.SingleFloat, longlong2float(res))
         return longlong2float(res)
     return rffi.cast(T, res)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to