[pypy-commit] pypy missing-ndarray-attributes: fix translation

mattip noreply at buildbot.pypy.org
Mon Jan 21 22:52:47 CET 2013


Author: mattip <matti.picus at gmail.com>
Branch: missing-ndarray-attributes
Changeset: r60320:0f922676e9c6
Date: 2012-12-31 11:24 +0200
http://bitbucket.org/pypy/pypy/changeset/0f922676e9c6/

Log:	fix translation

diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -14,7 +14,7 @@
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.rstruct.runpack import runpack
 from rpython.rlib.rstruct.nativefmttable import native_is_bigendian
-from rpython.rlib.rstruct.ieee import (float_pack, float_unpack, pack_float,
+from rpython.rlib.rstruct.ieee import (float_pack, float_unpack, pack_float80,
                                     unpack_float, unpack_float128)
 from rpython.tool.sourcetools import func_with_new_name
 from rpython.rlib import jit
@@ -1569,7 +1569,7 @@
         def byteswap(self, w_v):
             value = self.unbox(w_v)
             result = StringBuilder(12)
-            pack_float(result, value, 12, not native_is_bigendian)
+            pack_float80(result, value, 12, not native_is_bigendian)
             return self.box(unpack_float128(result.build(), native_is_bigendian))
 
     class NonNativeFloat96(Float96):
@@ -1602,7 +1602,7 @@
         def byteswap(self, w_v):
             value = self.unbox(w_v)
             result = StringBuilder(16)
-            pack_float(result, value, 16, not native_is_bigendian)
+            pack_float80(result, value, 16, not native_is_bigendian)
             return self.box(unpack_float128(result.build(), native_is_bigendian))
 
     class NonNativeFloat128(Float128):
diff --git a/rpython/rlib/rstruct/ieee.py b/rpython/rlib/rstruct/ieee.py
--- a/rpython/rlib/rstruct/ieee.py
+++ b/rpython/rlib/rstruct/ieee.py
@@ -239,18 +239,23 @@
 
 
 @jit.unroll_safe
+def pack_float80(result, x, size, be):
+    l = []
+    unsigned = float_pack80(x)
+    for i in range(8):
+        l.append(chr((unsigned[0] >> (i * 8)) & 0xFF))
+    for i in range(size - 8):
+        l.append(chr((unsigned[1] >> (i * 8)) & 0xFF))
+    if be:
+        l.reverse()
+    result.append("".join(l))
+
+ at jit.unroll_safe
 def pack_float(result, x, size, be):
     l = []
-    if size == 12 or size == 16:
-        unsigned = float_pack80(x)
-        for i in range(8):
-            l.append(chr((unsigned[0] >> (i * 8)) & 0xFF))
-        for i in range(size - 8):
-            l.append(chr((unsigned[1] >> (i * 8)) & 0xFF))
-    else:
-        unsigned = float_pack(x, size)
-        for i in range(size):
-            l.append(chr((unsigned >> (i * 8)) & 0xFF))
+    unsigned = float_pack(x, size)
+    for i in range(size):
+        l.append(chr((unsigned >> (i * 8)) & 0xFF))
     if be:
         l.reverse()
     result.append("".join(l))


More information about the pypy-commit mailing list