[pypy-commit] pypy arm-backed-float: (arigo, bivab) implement longlong2float and float2longlong in a way that is more close to the C standard. On ARM/32bit this code was causing a reodering of instructions that filled one of the two words with garbage

bivab noreply at buildbot.pypy.org
Mon Jun 6 18:06:43 CEST 2011


Author: David Schneider <david.schneider at picle.org>
Branch: arm-backed-float
Changeset: r44758:53622aa7b646
Date: 2011-06-06 18:07 +0200
http://bitbucket.org/pypy/pypy/changeset/53622aa7b646/

Log:	(arigo, bivab) implement longlong2float and float2longlong in a way
	that is more close to the C standard. On ARM/32bit this code was
	causing a reodering of instructions that filled one of the two words
	with garbage

diff --git a/pypy/rlib/longlong2float.py b/pypy/rlib/longlong2float.py
--- a/pypy/rlib/longlong2float.py
+++ b/pypy/rlib/longlong2float.py
@@ -32,12 +32,24 @@
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 eci = ExternalCompilationInfo(post_include_bits=["""
 static double pypy__longlong2float(long long x) {
+    int i;
+    double dd;
     char *p = (char*)&x;
-    return *((double*)p);
+    char *d = (char*)&dd;
+    for(i = 0; i < 8; i++) {
+        d[i] = p[i];
+    }
+    return dd;
 }
 static long long pypy__float2longlong(double x) {
+    int i;
+    long long ll;
     char *p = (char*)&x;
-    return *((long long*)p);
+    char *l = (char*)&ll;
+    for(i = 0; i < 8; i++) {
+        l[i] = p[i];
+    }
+    return ll;
 }
 """])
 


More information about the pypy-commit mailing list