All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [5771] target-alpha: use CPU_Float/CPU_Double instead of ugly casts
Date: Fri, 21 Nov 2008 23:49:41 +0000	[thread overview]
Message-ID: <E1L3fkr-0002we-1W@cvs.savannah.gnu.org> (raw)

Revision: 5771
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5771
Author:   aurel32
Date:     2008-11-21 23:49:40 +0000 (Fri, 21 Nov 2008)

Log Message:
-----------
target-alpha: use CPU_Float/CPU_Double instead of ugly casts

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

Modified Paths:
--------------
    trunk/target-alpha/op_helper.c

Modified: trunk/target-alpha/op_helper.c
===================================================================
--- trunk/target-alpha/op_helper.c	2008-11-21 22:33:15 UTC (rev 5770)
+++ trunk/target-alpha/op_helper.c	2008-11-21 23:49:40 UTC (rev 5771)
@@ -345,13 +345,13 @@
 /* F floating (VAX) */
 static always_inline uint64_t float32_to_f (float32 fa)
 {
-    uint32_t a;
     uint64_t r, exp, mant, sig;
+    CPU_FloatU a;
 
-    a = *(uint32_t*)(&fa);
-    sig = ((uint64_t)a & 0x80000000) << 32;
-    exp = (a >> 23) & 0xff;
-    mant = ((uint64_t)a & 0x007fffff) << 29;
+    a.f = fa;
+    sig = ((uint64_t)a.l & 0x80000000) << 32;
+    exp = (a.l >> 23) & 0xff;
+    mant = ((uint64_t)a.l & 0x007fffff) << 29;
 
     if (exp == 255) {
         /* NaN or infinity */
@@ -378,7 +378,8 @@
 
 static always_inline float32 f_to_float32 (uint64_t a)
 {
-    uint32_t r, exp, mant_sig;
+    uint32_t exp, mant_sig;
+    CPU_FloatU r;
 
     exp = ((a >> 55) & 0x80) | ((a >> 52) & 0x7f);
     mant_sig = ((a >> 32) & 0x80000000) | ((a >> 29) & 0x007fffff);
@@ -390,12 +391,12 @@
 
     if (exp < 3) {
         /* Underflow */
-        r = 0;
+        r.l = 0;
     } else {
-        r = ((exp - 2) << 23) | mant_sig;
+        r.l = ((exp - 2) << 23) | mant_sig;
     }
 
-    return *(float32*)(&a);
+    return r.f;
 }
 
 uint32_t helper_f_to_memory (uint64_t a)
@@ -471,12 +472,13 @@
 /* G floating (VAX) */
 static always_inline uint64_t float64_to_g (float64 fa)
 {
-    uint64_t a, r, exp, mant, sig;
+    uint64_t r, exp, mant, sig;
+    CPU_DoubleU a;
 
-    a = *(uint64_t*)(&fa);
-    sig = a & 0x8000000000000000ull;
-    exp = (a >> 52) & 0x7ff;
-    mant = a & 0x000fffffffffffffull;
+    a.d = fa;
+    sig = a.ll & 0x8000000000000000ull;
+    exp = (a.ll >> 52) & 0x7ff;
+    mant = a.ll & 0x000fffffffffffffull;
 
     if (exp == 2047) {
         /* NaN or infinity */
@@ -503,7 +505,8 @@
 
 static always_inline float64 g_to_float64 (uint64_t a)
 {
-    uint64_t r, exp, mant_sig;
+    uint64_t exp, mant_sig;
+    CPU_DoubleU r;
 
     exp = (a >> 52) & 0x7ff;
     mant_sig = a & 0x800fffffffffffffull;
@@ -515,12 +518,12 @@
 
     if (exp < 3) {
         /* Underflow */
-        r = 0;
+        r.ll = 0;
     } else {
-        r = ((exp - 2) << 52) | mant_sig;
+        r.ll = ((exp - 2) << 52) | mant_sig;
     }
 
-    return *(float64*)(&a);
+    return r.d;
 }
 
 uint64_t helper_g_to_memory (uint64_t a)
@@ -596,21 +599,22 @@
 /* S floating (single) */
 static always_inline uint64_t float32_to_s (float32 fa)
 {
-    uint32_t a;
+    CPU_FloatU a;
     uint64_t r;
 
-    a = *(uint32_t*)(&fa);
+    a.f = fa;
 
-    r = (((uint64_t)(a & 0xc0000000)) << 32) | (((uint64_t)(a & 0x3fffffff)) << 29);
-    if (((a & 0x7f800000) != 0x7f800000) && (!(a & 0x40000000)))
+    r = (((uint64_t)(a.l & 0xc0000000)) << 32) | (((uint64_t)(a.l & 0x3fffffff)) << 29);
+    if (((a.l & 0x7f800000) != 0x7f800000) && (!(a.l & 0x40000000)))
         r |= 0x7ll << 59;
     return r;
 }
 
 static always_inline float32 s_to_float32 (uint64_t a)
 {
-    uint32_t r = ((a >> 32) & 0xc0000000) | ((a >> 29) & 0x3fffffff);
-    return *(float32*)(&r);
+    CPU_FloatU r;
+    r.l = ((a >> 32) & 0xc0000000) | ((a >> 29) & 0x3fffffff);
+    return r.f;
 }
 
 uint32_t helper_s_to_memory (uint64_t a)
@@ -680,13 +684,17 @@
 static always_inline float64 t_to_float64 (uint64_t a)
 {
     /* Memory format is the same as float64 */
-    return *(float64*)(&a);
+    CPU_DoubleU r;
+    r.ll = a;
+    return r.d;
 }
 
 static always_inline uint64_t float64_to_t (float64 fa)
 {
     /* Memory format is the same as float64 */
-    return *(uint64*)(&fa);
+    CPU_DoubleU r;
+    r.d = fa;
+    return r.ll;
 }
 
 uint64_t helper_addt (uint64_t a, uint64_t b)

                 reply	other threads:[~2008-11-21 23:49 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=E1L3fkr-0002we-1W@cvs.savannah.gnu.org \
    --to=aurelien@aurel32.net \
    --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.