Skip to contentSkip to conversation

ppc: Fix emulated single to double denormalized conversions

PATCH Applied Paul A. Clarke 3 participants 3 messages Aug 19, 2019 – Aug 20, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ppc: Fix emulated single to double denormalized conversions

From: "Paul A. Clarke" <[email protected]>

helper_todouble() was not properly converting any denormalized 32 bit float to 64 bit double.

v2:
- Splitting patch "ppc: Three floating point fixes"; this is just one part.
- Original suggested "fix" was likely flawed. v2 is rewritten by Richard Henderson (Thanks, Richard!); I reformatted the comments in a couple of places, compiled, and tested.

---
 target/ppc/fpu_helper.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
target/ppc/fpu_helper.c +13 -4
index 52bcda2..07bc905 100644
@@ -73,11 +73,20 @@ uint64_t helper_todouble(uint32_t arg)
         /* Zero or Denormalized operand.  */
         ret = (uint64_t)extract32(arg, 31, 1) << 63;
         if (unlikely(abs_arg != 0)) {
-            /* Denormalized operand.  */
-            int shift = clz32(abs_arg) - 9;
-            int exp = -126 - shift + 1023;
+            /*
+             * Denormalized operand.
+             * Shift fraction so that the msb is in the implicit bit position.
+             * Thus, shift is in the range [1:23].
+             */
+            int shift = clz32(abs_arg) - 8;
+            /*
+             * The first 3 terms compute the float64 exponent.  We then bias
+             * this result by -1 so that we can swallow the implicit bit below.
+             */
+            int exp = -126 - shift + 1023 - 1;
+
             ret |= (uint64_t)exp << 52;
-            ret |= abs_arg << (shift + 29);
+            ret += (uint64_t)abs_arg << (52 - 23 + shift);
         }
     }
     return ret;
Signature · 1 line
1.8.3.1
#1 lore raw

20.08.2019. 00.32, "Paul A. Clarke" <[email protected]> је написао/ла:

Quoted 11 lines

From: "Paul A. Clarke" <[email protected]>

helper_todouble() was not properly converting any denormalized 32 bit float to 64 bit double.

v2:
- Splitting patch "ppc: Three floating point fixes"; this is just one

part.

Quoted 4 lines

- Original suggested "fix" was likely flawed. v2 is rewritten by Richard Henderson (Thanks, Richard!); I reformatted the comments in a couple of places, compiled, and tested.
---

Paul, the fix looks great, it is also good that it is a stand-alone patch now, and thrre is a history too, and I just want to bring to your attention a couple of technicalities to make this patch perfect:

- our standard phrase for fix suggestion is "Suggested-by:" (without preceeding"Fix-");

- the patch history should be preceeded by a line with three dashes ("---")
- that way it will not become a part of the permanent commit message once the patch is applied to the main tree, and we want that, since patch history plays its role only during review process.

Looking forward to your sending even more patches!!

Aleksandar

Quoted 8 lines
 target/ppc/fpu_helper.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
target/ppc/fpu_helper.c +0 -0
index 52bcda2..07bc905 100644

target/ppc/fpu_helper.c uint64_t helper_todouble(uint32_t arg) · line 78

Quoted 9 lines
target/ppc/fpu_helper.c +3 -3
@@ -73,11 +73,20 @@ uint64_t helper_todouble(uint32_t arg)
         /* Zero or Denormalized operand.  */
         ret = (uint64_t)extract32(arg, 31, 1) << 63;
         if (unlikely(abs_arg != 0)) {
-            /* Denormalized operand.  */
-            int shift = clz32(abs_arg) - 9;
-            int exp = -126 - shift + 1023;
+            /*
+             * Denormalized operand.
+             * Shift fraction so that the msb is in the implicit bit

position.

target/ppc/fpu_helper.c uint64_t helper_todouble(uint32_t arg)

Quoted 5 lines
target/ppc/fpu_helper.c +5 -0
+             * Thus, shift is in the range [1:23].
+             */
+            int shift = clz32(abs_arg) - 8;
+            /*
+             * The first 3 terms compute the float64 exponent.  We then

bias

target/ppc/fpu_helper.c uint64_t helper_todouble(uint32_t arg) · line 84

Quoted 1 line
target/ppc/fpu_helper.c +1 -0
+             * this result by -1 so that we can swallow the implicit bit

below.

Quoted 13 lines
target/ppc/fpu_helper.c +4 -2
+             */
+            int exp = -126 - shift + 1023 - 1;
+
             ret |= (uint64_t)exp << 52;
-            ret |= abs_arg << (shift + 29);
+            ret += (uint64_t)abs_arg << (52 - 23 + shift);
         }
     }
     return ret;
--

1.8.3.1

Applied
#2 lore raw
In reply to Paul A. Clarke
Quoted 5 lines · Paul A. Clarke

From: "Paul A. Clarke" <[email protected]>

helper_todouble() was not properly converting any denormalized 32 bit float to 64 bit double.

Quoted 8 lines

v2:
- Splitting patch "ppc: Three floating point fixes"; this is just one part.
- Original suggested "fix" was likely flawed. v2 is rewritten by Richard Henderson (Thanks, Richard!); I reformatted the comments in a couple of places, compiled, and tested.

Applied to ppc-for-4.2, thanks.

Quoted 33 lines
---
 target/ppc/fpu_helper.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
target/ppc/fpu_helper.c +13 -4
index 52bcda2..07bc905 100644
@@ -73,11 +73,20 @@ uint64_t helper_todouble(uint32_t arg)
         /* Zero or Denormalized operand.  */
         ret = (uint64_t)extract32(arg, 31, 1) << 63;
         if (unlikely(abs_arg != 0)) {
-            /* Denormalized operand.  */
-            int shift = clz32(abs_arg) - 9;
-            int exp = -126 - shift + 1023;
+            /*
+             * Denormalized operand.
+             * Shift fraction so that the msb is in the implicit bit position.
+             * Thus, shift is in the range [1:23].
+             */
+            int shift = clz32(abs_arg) - 8;
+            /*
+             * The first 3 terms compute the float64 exponent.  We then bias
+             * this result by -1 so that we can swallow the implicit bit below.
+             */
+            int exp = -126 - shift + 1023 - 1;
+
             ret |= (uint64_t)exp << 52;
-            ret |= abs_arg << (shift + 29);
+            ret += (uint64_t)abs_arg << (52 - 23 + shift);
         }
     }
     return ret;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson