target-arm: Squash input denormals in FRECPS and FRSQRTS
PATCH 1/1 target-arm: Squash input denormals in FRECPS and FRSQRTS
The helper functions for FRECPS and FRSQRTS have special case handling that includes checks for zero inputs, so squash input denormals if necessary before those checks. This fixes incorrect output when the FPCR DZ bit is set to enable squashing of input denormals.
---
A quick eyeball of helper-a64.c suggests that these are the only other insns we needed to fix, and a risu test of these insns confirms that (a) they're buggy and (b) this patch fixes them. I haven't done an exhaustive coverage test of the whole instruction set with the DZ bit set, though...
target-arm/helper-a64.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
target-arm/helper-a64.c +12 -0
@@ -229,6 +229,9 @@ float32 HELPER(recpsf_f32)(float32 a, float32 b, void *fpstp) {float_status *fpst = fpstp; + a =float32_squash_input_denormal (a, fpst); + b =float32_squash_input_denormal (b, fpst); + a =float32_chs (a);if ((float32_is_infinity (a) &&float32_is_zero (b)) || (float32_is_infinity (b) &&float32_is_zero (a))) {
@@ -241,6 +244,9 @@ float64 HELPER(recpsf_f64)(float64 a, float64 b, void *fpstp) {float_status *fpst = fpstp; + a =float64_squash_input_denormal (a, fpst); + b =float64_squash_input_denormal (b, fpst); + a =float64_chs (a);if ((float64_is_infinity (a) &&float64_is_zero (b)) || (float64_is_infinity (b) &&float64_is_zero (a))) {
@@ -253,6 +259,9 @@ float32 HELPER(rsqrtsf_f32)(float32 a, float32 b, void *fpstp) {float_status *fpst = fpstp; + a =float32_squash_input_denormal (a, fpst); + b =float32_squash_input_denormal (b, fpst); + a =float32_chs (a);if ((float32_is_infinity (a) &&float32_is_zero (b)) || (float32_is_infinity (b) &&float32_is_zero (a))) {
@@ -265,6 +274,9 @@ float64 HELPER(rsqrtsf_f64)(float64 a, float64 b, void *fpstp) {float_status *fpst = fpstp; + a =float64_squash_input_denormal (a, fpst); + b =float64_squash_input_denormal (b, fpst); + a =float64_chs (a);if ((float64_is_infinity (a) &&float64_is_zero (b)) || (float64_is_infinity (b) &&float64_is_zero (a))) {
Signature · 1 line
1.9.1
Quoted 7 lines · Peter Maydell
The helper functions for FRECPS and FRSQRTS have special case handling that includes checks for zero inputs, so squash input denormals if necessary before those checks. This fixes incorrect output when the FPCR DZ bit is set to enable squashing of input denormals.
Signed-off-by Peter Maydell <[email protected]>
Thanks,
Laurent
Quoted 58 lines
---
A quick eyeball ofhelper-a64.csuggests that these are the only other insns we needed to fix, and a risu test of these insns confirms that (a) they're buggy and (b) this patch fixes them. I haven't done an exhaustive coverage test of the whole instruction set with the DZ bit set, though...target-arm/helper-a64.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-arm/helper-a64.c +12
-1@@ -229,6 +229,9 @@ float32 HELPER(recpsf_f32)(float32 a, float32 b, void *fpstp) {float_status *fpst = fpstp; + a =float32_squash_input_denormal (a, fpst); + b =float32_squash_input_denormal (b, fpst); + a =float32_chs (a);if ((float32_is_infinity (a) &&float32_is_zero (b)) || (float32_is_infinity (b) &&float32_is_zero (a))) {@@ -241,6 +244,9 @@ float64 HELPER(recpsf_f64)(float64 a, float64 b, void *fpstp) {float_status *fpst = fpstp; + a =float64_squash_input_denormal (a, fpst); + b =float64_squash_input_denormal (b, fpst); + a =float64_chs (a);if ((float64_is_infinity (a) &&float64_is_zero (b)) || (float64_is_infinity (b) &&float64_is_zero (a))) {@@ -253,6 +259,9 @@ float32 HELPER(rsqrtsf_f32)(float32 a, float32 b, void *fpstp) {float_status *fpst = fpstp; + a =float32_squash_input_denormal (a, fpst); + b =float32_squash_input_denormal (b, fpst); + a =float32_chs (a);if ((float32_is_infinity (a) &&float32_is_zero (b)) || (float32_is_infinity (b) &&float32_is_zero (a))) {@@ -265,6 +274,9 @@ float64 HELPER(rsqrtsf_f64)(float64 a, float64 b, void *fpstp) {float_status *fpst = fpstp; + a =float64_squash_input_denormal (a, fpst); + b =float64_squash_input_denormal (b, fpst); + a =float64_chs (a);if ((float64_is_infinity (a) &&float64_is_zero (b)) || (float64_is_infinity (b) &&float64_is_zero (a))) { --1.9.1
Quoted 57 lines · Laurent Desnogues
Quoted 7 lines · Peter Maydell
The helper functions for FRECPS and FRSQRTS have special case handling that includes checks for zero inputs, so squash input denormals if necessary before those checks. This fixes incorrect output when the FPCR DZ bit is set to enable squashing of input denormals.
Signed-off-by Peter Maydell <[email protected]>Tested-by Laurent Desnogues <[email protected]>Thanks,
Laurent
target-arm/helper-a64.c float32 HELPER(recpsf_f32)(float32 a, float32 b,
Quoted 15 lines
---
A quick eyeball ofhelper-a64.csuggests that these are the only other insns we needed to fix, and a risu test of these insns confirms that (a) they're buggy and (b) this patch fixes them. I haven't done an exhaustive coverage test of the whole instruction set with the DZ bit set, though...target-arm/helper-a64.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-arm/helper-a64.c +0
-0@@ -229,6 +229,9 @@ float32 HELPER(recpsf_f32)(float32 a, float32 b,void *fpstp)
target-arm/helper-a64.c float64 HELPER(recpsf_f64)(float64 a, float64 b,
Quoted 10 lines
target-arm/helper-a64.c +3
-0{float_status *fpst = fpstp; + a =float32_squash_input_denormal (a, fpst); + b =float32_squash_input_denormal (b, fpst); + a =float32_chs (a);if ((float32_is_infinity (a) &&float32_is_zero (b)) || (float32_is_infinity (b) &&float32_is_zero (a))) {@@ -241,6 +244,9 @@ float64 HELPER(recpsf_f64)(float64 a, float64 b,void *fpstp)
target-arm/helper-a64.c float32 HELPER(rsqrtsf_f32)(float32 a, float32 b,
Quoted 10 lines
target-arm/helper-a64.c +3
-0{float_status *fpst = fpstp; + a =float64_squash_input_denormal (a, fpst); + b =float64_squash_input_denormal (b, fpst); + a =float64_chs (a);if ((float64_is_infinity (a) &&float64_is_zero (b)) || (float64_is_infinity (b) &&float64_is_zero (a))) {@@ -253,6 +259,9 @@ float32 HELPER(rsqrtsf_f32)(float32 a, float32 b,void *fpstp)
Quoted 3 lines
target-arm/helper-a64.c +0
-0{float_status *fpst = fpstp;
Quoted 23 lines
target-arm/helper-a64.c float64 HELPER(rsqrtsf_f64)(float64 a, float64 b,
Quoted 7 lines
target-arm/helper-a64.c +3
-0+ a =float32_squash_input_denormal (a, fpst); + b =float32_squash_input_denormal (b, fpst); + a =float32_chs (a);if ((float32_is_infinity (a) &&float32_is_zero (b)) || (float32_is_infinity (b) &&float32_is_zero (a))) {@@ -265,6 +274,9 @@ float64 HELPER(rsqrtsf_f64)(float64 a, float64 b,void *fpstp)
Quoted 13 lines
target-arm/helper-a64.c +3
-1{float_status *fpst = fpstp; + a =float64_squash_input_denormal (a, fpst); + b =float64_squash_input_denormal (b, fpst); + a =float64_chs (a);if ((float64_is_infinity (a) &&float64_is_zero (b)) || (float64_is_infinity (b) &&float64_is_zero (a))) { --1.9.1
Reviewed-by: Greg Bellows <[email protected]>