Skip to contentSkip to conversation

A64: Neon support, fourth set

PATCH In review Peter Maydell 2 participants 5 messages Feb 11, 2014

lore
Share & tools
lore
#0 lore raw

v2 cover A64: Neon support, fourth set

I've applied patches 1..6 from this set to target-arm.next, since they passed code review. v2 therefore just has the old patches 7 and 8 in it (and 8 has been reviewed).

Changes v1->v2:
* handle the halving correctly in the "zero + something" case by using roundAndPackFloat32() rather than trying to do it incorrectly by hand

NB: forgot to mention first time round, but the softfloat patch is licensed under either the softfloat-2a or -2b license, at your option.

Peter Maydell (2):
softfloat: Support halving the result of muladd operation
target-arm: A64: Implement remaining 3-same instructions

 fpu/softfloat.c            | 32 +++++++++++++++++++++++++
 include/fpu/softfloat.h    |  3 +++
 target-arm/helper-a64.c    | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/helper-a64.h    |  4 ++++
 target-arm/helper.h        |  2 ++
 target-arm/neon_helper.c   | 16 +++++++++++++
 target-arm/translate-a64.c | 52 ++++++++++++++++++++++++++++++++++++----
 7 files changed, 165 insertions(+), 4 deletions(-)
Signature · 1 line
1.8.5
#1 lore raw

PATCH v2 1/2 softfloat: Support halving the result of muladd operation

The ARMv8 instruction set includes a fused floating point reciprocal square root step instruction which demands an "(x * y + z) / 2" fused operation. Support this by adding a flag to the softfloat muladd operations which requests that the result is halved before rounding.

---
 fpu/softfloat.c         | 32 ++++++++++++++++++++++++++++++++
 include/fpu/softfloat.h |  3 +++
 2 files changed, 35 insertions(+)
fpu/softfloat.c +32 -0
index e0ea599..b815356 100644
@@ -2372,6 +2372,14 @@ float32 float32_muladd(float32 a, float32 b, float32 c, int flags STATUS_PARAM)
             }
         }
         /* Zero plus something non-zero : just return the something */
+        if (flags & float_muladd_halve_result) {
+            if (cExp == 0) {
+                normalizeFloat32Subnormal(cSig, &cExp, &cSig);
+            }
+            cExp--;
+            cSig = (cSig | 0x00800000) << 7;
+            return roundAndPackFloat32(cSign ^ signflip, cExp, cSig STATUS_VAR);
+        }
         return packFloat32(cSign ^ signflip, cExp, cSig);
     }
 
@@ -2408,6 +2416,9 @@ float32 float32_muladd(float32 a, float32 b, float32 c, int flags STATUS_PARAM)
             /* Throw out the special case of c being an exact zero now */
             shift64RightJamming(pSig64, 32, &pSig64);
             pSig = pSig64;
+            if (flags & float_muladd_halve_result) {
+                pExp--;
+            }
             return roundAndPackFloat32(zSign, pExp - 1,
                                        pSig STATUS_VAR);
         }
@@ -2472,6 +2483,10 @@ float32 float32_muladd(float32 a, float32 b, float32 c, int flags STATUS_PARAM)
         zSig64 <<= shiftcount;
         zExp -= shiftcount;
     }
+    if (flags & float_muladd_halve_result) {
+        zExp--;
+    }
+
     shift64RightJamming(zSig64, 32, &zSig64);
     return roundAndPackFloat32(zSign, zExp, zSig64 STATUS_VAR);
 }
@@ -4088,6 +4103,14 @@ float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM)
             }
         }
         /* Zero plus something non-zero : just return the something */
+        if (flags & float_muladd_halve_result) {
+            if (cExp == 0) {
+                normalizeFloat64Subnormal(cSig, &cExp, &cSig);
+            }
+            cExp--;
+            cSig = (cSig | 0x0010000000000000ULL) << 10;
+            return roundAndPackFloat64(cSign ^ signflip, cExp, cSig STATUS_VAR);
+        }
         return packFloat64(cSign ^ signflip, cExp, cSig);
     }
 
@@ -4123,6 +4146,9 @@ float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM)
         if (!cSig) {
             /* Throw out the special case of c being an exact zero now */
             shift128RightJamming(pSig0, pSig1, 64, &pSig0, &pSig1);
+            if (flags & float_muladd_halve_result) {
+                pExp--;
+            }
             return roundAndPackFloat64(zSign, pExp - 1,
                                        pSig1 STATUS_VAR);
         }
@@ -4159,6 +4185,9 @@ float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM)
             zExp--;
         }
         shift128RightJamming(zSig0, zSig1, 64, &zSig0, &zSig1);
+        if (flags & float_muladd_halve_result) {
+            zExp--;
+        }
         return roundAndPackFloat64(zSign, zExp, zSig1 STATUS_VAR);
     } else {
         /* Subtraction */
@@ -4209,6 +4238,9 @@ float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM)
                 zExp -= (shiftcount + 64);
             }
         }
+        if (flags & float_muladd_halve_result) {
+            zExp--;
+        }
         return roundAndPackFloat64(zSign, zExp, zSig0 STATUS_VAR);
     }
 }
include/fpu/softfloat.h +3 -0
index 806ae13..4b4df88 100644
@@ -249,11 +249,14 @@ void float_raise( int8 flags STATUS_PARAM);
 | Using these differs from negating an input or output before calling
 | the muladd function in that this means that a NaN doesn't have its
 | sign bit inverted before it is propagated.
+| We also support halving the result before rounding, as a special
+| case to support the ARM fused-sqrt-step instruction FRSQRTS.
 *----------------------------------------------------------------------------*/
 enum {
     float_muladd_negate_c = 1,
     float_muladd_negate_product = 2,
     float_muladd_negate_result = 4,
+    float_muladd_halve_result = 8,
 };
 
 /*----------------------------------------------------------------------------
Signature · 1 line
1.8.5
#2 lore raw

PATCH v2 2/2 target-arm: A64: Implement remaining 3-same instructions

In reply to Peter Maydell

Implement the remaining instructions in the SIMD 3-reg-same and scalar-3-reg-same groups: FMULX, FRECPS, FRSQRTS, FACGE, FACGT, FMLA and FMLS.

---
 fpu/softfloat.c            |  4 ++--
 target-arm/helper-a64.c    | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/helper-a64.h    |  4 ++++
 target-arm/helper.h        |  2 ++
 target-arm/neon_helper.c   | 16 +++++++++++++
 target-arm/translate-a64.c | 52 ++++++++++++++++++++++++++++++++++++----
 6 files changed, 132 insertions(+), 6 deletions(-)
fpu/softfloat.c +2 -2
index b815356..1b49b70 100644
@@ -2376,7 +2376,7 @@ float32 float32_muladd(float32 a, float32 b, float32 c, int flags STATUS_PARAM)
             if (cExp == 0) {
                 normalizeFloat32Subnormal(cSig, &cExp, &cSig);
             }
-            cExp--;
+            cExp -= 2;
             cSig = (cSig | 0x00800000) << 7;
             return roundAndPackFloat32(cSign ^ signflip, cExp, cSig STATUS_VAR);
         }
@@ -4107,7 +4107,7 @@ float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM)
             if (cExp == 0) {
                 normalizeFloat64Subnormal(cSig, &cExp, &cSig);
             }
-            cExp--;
+            cExp -= 2;
             cSig = (cSig | 0x0010000000000000ULL) << 10;
             return roundAndPackFloat64(cSign ^ signflip, cExp, cSig STATUS_VAR);
         }
target-arm/helper-a64.c +60 -0

63 lines not on this page · raw message

target-arm/helper-a64.h +4 -0
index bf20466..ab9933c 100644
@@ -32,3 +32,7 @@ DEF_HELPER_FLAGS_3(vfp_mulxd, TCG_CALL_NO_RWG, f64, f64, f64, ptr)
 DEF_HELPER_FLAGS_3(neon_ceq_f64, TCG_CALL_NO_RWG, i64, i64, i64, ptr)
 DEF_HELPER_FLAGS_3(neon_cge_f64, TCG_CALL_NO_RWG, i64, i64, i64, ptr)
 DEF_HELPER_FLAGS_3(neon_cgt_f64, TCG_CALL_NO_RWG, i64, i64, i64, ptr)
+DEF_HELPER_FLAGS_3(recpsf_f32, TCG_CALL_NO_RWG, f32, f32, f32, ptr)
+DEF_HELPER_FLAGS_3(recpsf_f64, TCG_CALL_NO_RWG, f64, f64, f64, ptr)
+DEF_HELPER_FLAGS_3(rsqrtsf_f32, TCG_CALL_NO_RWG, f32, f32, f32, ptr)
+DEF_HELPER_FLAGS_3(rsqrtsf_f64, TCG_CALL_NO_RWG, f64, f64, f64, ptr)
target-arm/helper.h +2 -0
index 951e6ad..7c60121 100644
@@ -382,6 +382,8 @@ DEF_HELPER_3(neon_cge_f32, i32, i32, i32, ptr)
 DEF_HELPER_3(neon_cgt_f32, i32, i32, i32, ptr)
 DEF_HELPER_3(neon_acge_f32, i32, i32, i32, ptr)
 DEF_HELPER_3(neon_acgt_f32, i32, i32, i32, ptr)
+DEF_HELPER_3(neon_acge_f64, i64, i64, i64, ptr)
+DEF_HELPER_3(neon_acgt_f64, i64, i64, i64, ptr)
 
 /* iwmmxt_helper.c */
 DEF_HELPER_2(iwmmxt_maddsq, i64, i64, i64)
target-arm/neon_helper.c +16 -0
index b4c8690..13752ba 100644
@@ -1823,6 +1823,22 @@ uint32_t HELPER(neon_acgt_f32)(uint32_t a, uint32_t b, void *fpstp)
     return -float32_lt(f1, f0, fpst);
 }
 
+uint64_t HELPER(neon_acge_f64)(uint64_t a, uint64_t b, void *fpstp)
+{
+    float_status *fpst = fpstp;
+    float64 f0 = float64_abs(make_float64(a));
+    float64 f1 = float64_abs(make_float64(b));
+    return -float64_le(f1, f0, fpst);
+}
+
+uint64_t HELPER(neon_acgt_f64)(uint64_t a, uint64_t b, void *fpstp)
+{
+    float_status *fpst = fpstp;
+    float64 f0 = float64_abs(make_float64(a));
+    float64 f1 = float64_abs(make_float64(b));
+    return -float64_lt(f1, f0, fpst);
+}
+
 #define ELEM(V, N, SIZE) (((V) >> ((N) * (SIZE))) & ((1ull << (SIZE)) - 1))
 
 void HELPER(neon_qunzip8)(CPUARMState *env, uint32_t rd, uint32_t rm)
target-arm/translate-a64.c +48 -4

133 lines not on this page · raw message

Signature · 1 line
1.8.5
Reviewed-by on v2 2/2
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] target-arm: A64: Implement remaining 3-same instructions

Quoted 10 lines · Peter Maydell
fpu/softfloat.c +1 -1
@@ -2376,7 +2376,7 @@ float32 float32_muladd(float32 a, float32 b, float32 c, int flags STATUS_PARAM)
             if (cExp == 0) {
                 normalizeFloat32Subnormal(cSig, &cExp, &cSig);
             }
-            cExp--;
+            cExp -= 2;
             cSig = (cSig | 0x00800000) << 7;
             return roundAndPackFloat32(cSign ^ signflip, cExp, cSig STATUS_VAR);
         }

fpu/softfloat.c float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM) · line 4113

Quoted 8 lines
fpu/softfloat.c +1 -1
@@ -4107,7 +4107,7 @@ float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM)
             if (cExp == 0) {
                 normalizeFloat64Subnormal(cSig, &cExp, &cSig);
             }
-            cExp--;
+            cExp -= 2;
             cSig = (cSig | 0x0010000000000000ULL) << 10;
             return roundAndPackFloat64(cSign ^ signflip, cExp, cSig STATUS_VAR);
         }

This should obviously be folded into the previous patch.

Probably with a comment reminding about roundAndPackFloat wanting an off-by-one exponent.

Otherwise both get

r~

#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] target-arm: A64: Implement remaining 3-same instructions

Quoted 22 lines · Richard Henderson
Quoted 10 lines · Peter Maydell
fpu/softfloat.c +1 -1
@@ -2376,7 +2376,7 @@ float32 float32_muladd(float32 a, float32 b, float32 c, int flags STATUS_PARAM)
             if (cExp == 0) {
                 normalizeFloat32Subnormal(cSig, &cExp, &cSig);
             }
-            cExp--;
+            cExp -= 2;
             cSig = (cSig | 0x00800000) << 7;
             return roundAndPackFloat32(cSign ^ signflip, cExp, cSig STATUS_VAR);
         }

fpu/softfloat.c float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM) · line 4113

Quoted 8 lines
fpu/softfloat.c +1 -1
@@ -4107,7 +4107,7 @@ float64 float64_muladd(float64 a, float64 b, float64 c, int flags STATUS_PARAM)
             if (cExp == 0) {
                 normalizeFloat64Subnormal(cSig, &cExp, &cSig);
             }
-            cExp--;
+            cExp -= 2;
             cSig = (cSig | 0x0010000000000000ULL) << 10;
             return roundAndPackFloat64(cSign ^ signflip, cExp, cSig STATUS_VAR);
         }

This should obviously be folded into the previous patch.

Quoted 6 lines

Probably with a comment reminding about roundAndPackFloat wanting an off-by-one exponent.

Otherwise both get

Doh; thanks for the catch. Yeah, I was halfway to putting in a comment about why we were subtracting two, should have followed my first instinct.

Will make trivial fixups and put into target-arm.next.

(comment text: /* Subtract one to halve and one again because roundAndPackFloat wants one less than the true exponent. */)

thanks
-- PMM