Skip to contentSkip to conversation

FMULX should flushes operators to zero when FZ is set.

PATCH In review Xiangyu Hu 4 participants 10 messages Jan 28, 2015 – Feb 3, 2015

lore
Share & tools
lore

Xiangyu Hu

author
#0 lore raw

PATCH 1/1 FMULX should flushes operators to zero when FZ is set.

The difference between FMULX and FMUL is that FMULX will return 2.0f when one operator is FPInfinity and the other one is FPZero, whilst FMUL will return a Default NaN. Without this patch, the emulation would result in inconsistency.

---
 target-arm/helper-a64.c | 6 ++++++
 1 file changed, 6 insertions(+)
target-arm/helper-a64.c +6 -0
index 81066ca..ebd9247 100644
@@ -135,6 +135,9 @@ float32 HELPER(vfp_mulxs)(float32 a, float32 b, void *fpstp)
 {
     float_status *fpst = fpstp;
 
+    a = float32_squash_input_denormal(a, fpst);
+    b = float32_squash_input_denormal(b, fpst);
+
     if ((float32_is_zero(a) && float32_is_infinity(b)) ||
         (float32_is_infinity(a) && float32_is_zero(b))) {
         /* 2.0 with the sign bit set to sign(A) XOR sign(B) */
@@ -148,6 +151,9 @@ float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp)
 {
     float_status *fpst = fpstp;
 
+    a = float64_squash_input_denormal(a, fpst);
+    b = float64_squash_input_denormal(b, fpst);
+
     if ((float64_is_zero(a) && float64_is_infinity(b)) ||
         (float64_is_infinity(a) && float64_is_zero(b))) {
         /* 2.0 with the sign bit set to sign(A) XOR sign(B) */
Signature · 1 line
1.9.1
#1 lore raw
Quoted 24 lines · Xiangyu Hu

The difference between FMULX and FMUL is that FMULX will return 2.0f when one operator is FPInfinity and the other one is FPZero, whilst FMUL will return a Default NaN. Without this patch, the emulation would result in inconsistency.

---
 target-arm/helper-a64.c | 6 ++++++
 1 file changed, 6 insertions(+)
target-arm/helper-a64.c +3 -0
index 81066ca..ebd9247 100644
@@ -135,6 +135,9 @@ float32 HELPER(vfp_mulxs)(float32 a, float32 b, void *fpstp)
 {
     float_status *fpst = fpstp;
 
+    a = float32_squash_input_denormal(a, fpst);
+    b = float32_squash_input_denormal(b, fpst);
+
     if ((float32_is_zero(a) && float32_is_infinity(b)) ||
         (float32_is_infinity(a) && float32_is_zero(b))) {
         /* 2.0 with the sign bit set to sign(A) XOR sign(B) */

target-arm/helper-a64.c float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp) · line 159

Quoted 9 lines
target-arm/helper-a64.c +3 -0
@@ -148,6 +151,9 @@ float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp)
 {
     float_status *fpst = fpstp;
 
+    a = float64_squash_input_denormal(a, fpst);
+    b = float64_squash_input_denormal(b, fpst);
+
     if ((float64_is_zero(a) && float64_is_infinity(b)) ||
         (float64_is_infinity(a) && float64_is_zero(b))) {
         /* 2.0 with the sign bit set to sign(A) XOR sign(B) */

I think this code change is correct but the commit message doesn't do a very good job of describing what the change is or why it is needed... (in particular the difference between FMULX and FMUL is completely irrelevant to the need for this fix, but it is pretty much the only thing the commit message talks about).

thanks
-- PMM

author
#2 lore raw

Thanks Peter.

I have sent another patch with updated commit message.

- xiangyu

Quoted 45 lines · Peter Maydell
Quoted 24 lines · On 28 January 2015 at 14:51, Xiangyu Hu <[email protected]…

The difference between FMULX and FMUL is that FMULX will return 2.0f when one operator is FPInfinity and the other one is FPZero, whilst FMUL will return a Default NaN. Without this patch, the emulation would result in inconsistency.

---
target-arm/helper-a64.c | 6 ++++++

1 file changed, 6 insertions(+)
target-arm/helper-a64.c +3 -0
index 81066ca..ebd9247 100644
@@ -135,6 +135,9 @@ float32 HELPER(vfp_mulxs)(float32 a, float32 b, void *fpstp)
 {
    float_status *fpst = fpstp;
 
+    a = float32_squash_input_denormal(a, fpst);
+    b = float32_squash_input_denormal(b, fpst);
+
    if ((float32_is_zero(a) && float32_is_infinity(b)) ||
        (float32_is_infinity(a) && float32_is_zero(b))) {
        /* 2.0 with the sign bit set to sign(A) XOR sign(B) */

target-arm/helper-a64.c float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp) · line 159

Quoted 9 lines
target-arm/helper-a64.c +3 -0
@@ -148,6 +151,9 @@ float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp)
 {
    float_status *fpst = fpstp;
 
+    a = float64_squash_input_denormal(a, fpst);
+    b = float64_squash_input_denormal(b, fpst);
+
    if ((float64_is_zero(a) && float64_is_infinity(b)) ||
        (float64_is_infinity(a) && float64_is_zero(b))) {
        /* 2.0 with the sign bit set to sign(A) XOR sign(B) */

I think this code change is correct but the commit message doesn't do a very good job of describing what the change is or why it is needed... (in particular the difference between FMULX and FMUL is completely irrelevant to the need for this fix, but it is pretty much the only thing the commit message talks about).

thanks
-- PMM

#3 lore raw
In reply to Xiangyu Hu
Quoted 24 lines · Xiangyu Hu

The difference between FMULX and FMUL is that FMULX will return 2.0f when one operator is FPInfinity and the other one is FPZero, whilst FMUL will return a Default NaN. Without this patch, the emulation would result in inconsistency.

---
 target-arm/helper-a64.c | 6 ++++++
 1 file changed, 6 insertions(+)
target-arm/helper-a64.c +3 -0
index 81066ca..ebd9247 100644
@@ -135,6 +135,9 @@ float32 HELPER(vfp_mulxs)(float32 a, float32 b, void *fpstp)
 {
     float_status *fpst = fpstp;
 
+    a = float32_squash_input_denormal(a, fpst);
+    b = float32_squash_input_denormal(b, fpst);
+
     if ((float32_is_zero(a) && float32_is_infinity(b)) ||
         (float32_is_infinity(a) && float32_is_zero(b))) {
         /* 2.0 with the sign bit set to sign(A) XOR sign(B) */

target-arm/helper-a64.c float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp) · line 159

Quoted 9 lines
target-arm/helper-a64.c +3 -0
@@ -148,6 +151,9 @@ float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp)
 {
     float_status *fpst = fpstp;
 
+    a = float64_squash_input_denormal(a, fpst);
+    b = float64_squash_input_denormal(b, fpst);
+
     if ((float64_is_zero(a) && float64_is_infinity(b)) ||
         (float64_is_infinity(a) && float64_is_zero(b))) {
         /* 2.0 with the sign bit set to sign(A) XOR sign(B) */

Do we have test cases that trip up here? It would be nice to include them in our testing as the random nature of RISU has obviously failed to trip up on this instruction.

Signature · 1 line
Alex Bennée
#4 lore raw
Quoted 3 lines · Alex Bennée

Do we have test cases that trip up here? It would be nice to include them in our testing as the random nature of RISU has obviously failed to trip up on this instruction.

Risu would probably catch this if we generated and ran test cases which set the FPSCR bits to something other than the default. (At least the 32-bit risugen lets you do this; I forget whether we wired up that bit in the 64-bit support code.)

-- PMM

author
#5 lore raw

If RISU sets random FPSCR (FZ bit) values, I think such cases would be covered; it doesn’t look like such a corner case.

Maybe I can include some focus tests on this scenario if RISU failed to generate this pattern?

Thanks

- xiangyu

Quoted 13 lines · Peter Maydell
Quoted 3 lines · Alex Bennée

Do we have test cases that trip up here? It would be nice to include them in our testing as the random nature of RISU has obviously failed to trip up on this instruction.

Risu would probably catch this if we generated and ran test cases which set the FPSCR bits to something other than the default. (At least the 32-bit risugen lets you do this; I forget whether we wired up that bit in the 64-bit support code.)

-- PMM

#6 lore raw
In reply to Peter Maydell

Hi Peter,

Quoted 5 lines · Peter Maydell
Quoted 3 lines · Alex Bennée

Do we have test cases that trip up here? It would be nice to include them in our testing as the random nature of RISU has obviously failed to trip up on this instruction.

Quoted 7 lines

Risu would probably catch this if we generated and ran test cases which set the FPSCR bits to something other than the default. (At least the 32-bit risugen lets you do this; I forget whether we wired up that bit in the 64-bit support code.)

-- PMM

If nobody improved it from my implementation, the risugen script
will generate code which sets FPSR always unconditionally to 0,
while the FPCR is wired up with the user-provided "fpscr" option.
Not that there's any good reason behind it, probably both should be configurable..

Ciao,

Claudio

#7 lore raw
Quoted 5 lines · Claudio Fontana

If nobody improved it from my implementation, the risugen script will generate code which sets FPSR always unconditionally to 0, while the FPCR is wired up with the user-provided "fpscr" option. Not that there's any good reason behind it, probably both should be configurable..

That's all you actually require, really -- there's not much benefit from setting the FPSR flags on startup.

-- PMM

#8 lore raw
In reply to Peter Maydell
Quoted 7 lines · Peter Maydell
Quoted 3 lines · Alex Bennée

Do we have test cases that trip up here? It would be nice to include them in our testing as the random nature of RISU has obviously failed to trip up on this instruction.

Risu would probably catch this if we generated and ran test cases which set the FPSCR bits to something other than the default.

This bug is indeed caught by the following risugen:
./risugen --numinsns 10000 --pattern "FMULX A64_V" --fpscr 0x01000000 aarch64.risu FMULX_S3SAME_V_squash.out

(that fpscr value being "set DZ, nothing else".)

Alex, I don't suppose your automation of these tests makes it easy to do a complete extra run (or better, just of the Neon and FP insn tests) with different FPSCR flags?

-- PMM

#9 lore raw
Quoted 13 lines · Peter Maydell
Quoted 7 lines · Peter Maydell
Quoted 3 lines · Alex Bennée

Do we have test cases that trip up here? It would be nice to include them in our testing as the random nature of RISU has obviously failed to trip up on this instruction.

Risu would probably catch this if we generated and ran test cases which set the FPSCR bits to something other than the default.

This bug is indeed caught by the following risugen:
./risugen --numinsns 10000 --pattern "FMULX A64_V" --fpscr 0x01000000 aarch64.risu FMULX_S3SAME_V_squash.out

Quoted 5 lines

(that fpscr value being "set DZ, nothing else".)

Alex, I don't suppose your automation of these tests makes it easy to do a complete extra run (or better, just of the Neon and FP insn tests) with different FPSCR flags?

I just need to add the additional test sequence and trace to the tarball and the script should pick it up automatically.

Quoted 2 lines

-- PMM

Signature · 1 line
Alex Bennée