All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Brook <paul@codesourcery.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [patch] ppc float entianness
Date: Sun, 20 Mar 2005 21:18:44 +0000	[thread overview]
Message-ID: <200503202118.44906.paul@codesourcery.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 173 bytes --]

The PPC FPU emulation is broken on hosts with with weird floating point word 
ordering (ie. arm).

The attached patch fixes this by using CPU_DoubleU as appropriate.

Paul


[-- Attachment #2: patch.qemu_ppc_double --]
[-- Type: text/x-diff, Size: 5714 bytes --]

Index: target-ppc/op_helper.c
===================================================================
RCS file: /cvsroot/qemu/qemu/target-ppc/op_helper.c,v
retrieving revision 1.12
diff -u -p -r1.12 op_helper.c
--- target-ppc/op_helper.c	13 Mar 2005 17:01:22 -0000	1.12
+++ target-ppc/op_helper.c	20 Mar 2005 21:09:33 -0000
@@ -180,25 +180,13 @@ void do_load_fpscr (void)
     /* The 32 MSB of the target fpr are undefined.
      * They'll be zero...
      */
-    union {
-        double d;
-        struct {
-            uint32_t u[2];
-        } s;
-    } u;
+    CPU_DoubleU u;
     int i;
 
-#ifdef WORDS_BIGENDIAN
-#define WORD0 0
-#define WORD1 1
-#else
-#define WORD0 1
-#define WORD1 0
-#endif
-    u.s.u[WORD0] = 0;
-    u.s.u[WORD1] = 0;
+    u.l.upper = 0;
+    u.l.lower = 0;
     for (i = 0; i < 8; i++)
-        u.s.u[WORD1] |= env->fpscr[i] << (4 * i);
+        u.l.lower |= env->fpscr[i] << (4 * i);
     FT0 = u.d;
 }
 
@@ -207,20 +195,15 @@ void do_store_fpscr (uint32_t mask)
     /*
      * We use only the 32 LSB of the incoming fpr
      */
-    union {
-        double d;
-        struct {
-            uint32_t u[2];
-        } s;
-    } u;
+    CPU_DoubleU u;
     int i, rnd_type;
 
     u.d = FT0;
     if (mask & 0x80)
-        env->fpscr[0] = (env->fpscr[0] & 0x9) | ((u.s.u[WORD1] >> 28) & ~0x9);
+        env->fpscr[0] = (env->fpscr[0] & 0x9) | ((u.l.lower >> 28) & ~0x9);
     for (i = 1; i < 7; i++) {
         if (mask & (1 << (7 - i)))
-            env->fpscr[i] = (u.s.u[WORD1] >> (4 * (7 - i))) & 0xF;
+            env->fpscr[i] = (u.l.lower >> (4 * (7 - i))) & 0xF;
     }
     /* TODO: update FEX & VX */
     /* Set rounding mode */
@@ -248,32 +231,30 @@ void do_store_fpscr (uint32_t mask)
 
 void do_fctiw (void)
 {
-    union {
-        double d;
-        uint64_t i;
-    } p;
+    CPU_DoubleU u;
+    uint64_t i;
 
     /* XXX: higher bits are not supposed to be significant.
      *      to make tests easier, return the same as a real PPC 750 (aka G3)
      */
-    p.i = float64_to_int32(FT0, &env->fp_status);
-    p.i |= 0xFFF80000ULL << 32;
-    FT0 = p.d;
+    i = float64_to_int32(FT0, &env->fp_status);
+    u.l.upper = i >> 32;
+    u.l.lower = i;
+    FT0 = u.d;
 }
 
 void do_fctiwz (void)
 {
-    union {
-        double d;
-        uint64_t i;
-    } p;
+    CPU_DoubleU u;
+    uint64_t i;
 
     /* XXX: higher bits are not supposed to be significant.
      *      to make tests easier, return the same as a real PPC 750 (aka G3)
      */
-    p.i = float64_to_int32_round_to_zero(FT0, &env->fp_status);
-    p.i |= 0xFFF80000ULL << 32;
-    FT0 = p.d;
+    i = float64_to_int32_round_to_zero(FT0, &env->fp_status);
+    u.l.upper = (i >> 32) | 0xFFF80000;
+    u.l.lower = i;
+    FT0 = u.d;
 }
 
 void do_fnmadd (void)
@@ -305,54 +286,55 @@ void do_fsqrt (void)
 
 void do_fres (void)
 {
-    union {
-        double d;
-        uint64_t i;
-    } p;
+    CPU_DoubleU u;
 
     if (isnormal(FT0)) {
         FT0 = (float)(1.0 / FT0);
     } else {
-        p.d = FT0;
-        if (p.i == 0x8000000000000000ULL) {
-            p.i = 0xFFF0000000000000ULL;
-        } else if (p.i == 0x0000000000000000ULL) {
-            p.i = 0x7FF0000000000000ULL;
+        u.d = FT0;
+        if (u.l.upper == 0x80000000u && u.l.lower == 0) {
+            u.l.upper = 0xFFF00000u;
+        } else if (u.l.upper == 0 && u.l.lower == 0) {
+            u.l.upper = 0x7FF00000u;
         } else if (isnan(FT0)) {
-            p.i = 0x7FF8000000000000ULL;
+            u.l.upper = 0x7FF80000u;
+            u.l.lower = 0;
         } else if (FT0 < 0.0) {
-            p.i = 0x8000000000000000ULL;
+            u.l.upper = 0x80000000u;
+            u.l.lower = 0;
         } else {
-            p.i = 0x0000000000000000ULL;
+            u.l.upper = 0;
+            u.l.lower = 0;
         }
-        FT0 = p.d;
+        FT0 = u.d;
     }
 }
 
 void do_frsqrte (void)
 {
-    union {
-        double d;
-        uint64_t i;
-    } p;
+    CPU_DoubleU u;
 
     if (isnormal(FT0) && FT0 > 0.0) {
         FT0 = (float)(1.0 / sqrt(FT0));
     } else {
-        p.d = FT0;
-        if (p.i == 0x8000000000000000ULL) {
-            p.i = 0xFFF0000000000000ULL;
-        } else if (p.i == 0x0000000000000000ULL) {
-            p.i = 0x7FF0000000000000ULL;
+        u.d = FT0;
+        if (u.l.upper == 0x80000000u && u.l.lower == 0) {
+            u.l.upper = 0xFFF00000u;
+        } else if (u.l.upper == 0 && u.l.lower == 0) {
+            u.l.upper = 0x7FF00000u;
         } else if (isnan(FT0)) {
-            if (!(p.i & 0x0008000000000000ULL))
-                p.i |= 0x000FFFFFFFFFFFFFULL;
-        } else if (FT0 < 0) {
-            p.i = 0x7FF8000000000000ULL;
+            if (!(u.l.upper & 0x00080000u)){
+                u.l.upper |= 0x000fffffu;
+                u.l.lower |= 0xffffffffu;
+            }
+        } else if (FT0 < 0.0) {
+            u.l.upper = 0x7ff80000u;
+            u.l.lower = 0;
         } else {
-            p.i = 0x0000000000000000ULL;
+            u.l.upper = 0;
+            u.l.lower = 0;
         }
-        FT0 = p.d;
+        FT0 = u.d;
     }
 }
 
@@ -406,26 +388,20 @@ void do_fcmpo (void)
 
 void do_fabs (void)
 {
-    union {
-        double d;
-        uint64_t i;
-    } p;
-
-    p.d = FT0;
-    p.i &= ~0x8000000000000000ULL;
-    FT0 = p.d;
+    CPU_DoubleU u;
+
+    u.d = FT0;
+    u.l.upper &= ~0x80000000u;
+    FT0 = u.d;
 }
 
 void do_fnabs (void)
 {
-    union {
-        double d;
-        uint64_t i;
-    } p;
-
-    p.d = FT0;
-    p.i |= 0x8000000000000000ULL;
-    FT0 = p.d;
+    CPU_DoubleU u;
+
+    u.d = FT0;
+    u.l.upper &= ~0x80000000u;
+    FT0 = u.d;
 }
 
 /* Instruction cache invalidation helper */

                 reply	other threads:[~2005-03-20 21:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200503202118.44906.paul@codesourcery.com \
    --to=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.