Skip to contentSkip to conversation

Hexagon (target/hexagon) properly handle NaN in dfmin/dfmax/sfmin/sfmax

PATCH Superseded Taylor Simpson 2 participants 3 messages Feb 16, 2022 – Mar 8, 2022

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Hexagon (target/hexagon) properly handle NaN in dfmin/dfmax/sfmin/sfmax

The float??_minnum implementation differs from Hexagon for SNaN, it returns NaN, but Hexagon returns the other input. So, we use float??_minimum_number. For double precision, we check for QNaN and raise the invalid flag.

test cases added in a subsequent patch to more extensively test USR bits

---
 target/hexagon/op_helper.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
target/hexagon/op_helper.c +8 -6
index 057baf9a48..daf0b0d348 100644
@@ -948,7 +948,7 @@ float32 HELPER(sfmax)(CPUHexagonState *env, float32 RsV, float32 RtV)
 {
     float32 RdV;
     arch_fpop_start(env);
-    RdV = float32_maxnum(RsV, RtV, &env->fp_status);
+    RdV = float32_maximum_number(RsV, RtV, &env->fp_status);
     arch_fpop_end(env);
     return RdV;
 }
@@ -957,7 +957,7 @@ float32 HELPER(sfmin)(CPUHexagonState *env, float32 RsV, float32 RtV)
 {
     float32 RdV;
     arch_fpop_start(env);
-    RdV = float32_minnum(RsV, RtV, &env->fp_status);
+    RdV = float32_minimum_number(RsV, RtV, &env->fp_status);
     arch_fpop_end(env);
     return RdV;
 }
@@ -1041,8 +1041,9 @@ float64 HELPER(dfmax)(CPUHexagonState *env, float64 RssV, float64 RttV)
 {
     float64 RddV;
     arch_fpop_start(env);
-    RddV = float64_maxnum(RssV, RttV, &env->fp_status);
-    if (float64_is_any_nan(RssV) || float64_is_any_nan(RttV)) {
+    RddV = float64_maximum_number(RssV, RttV, &env->fp_status);
+    if (float64_is_quiet_nan(RssV, &env->fp_status) ||
+        float64_is_quiet_nan(RttV, &env->fp_status)) {
         float_raise(float_flag_invalid, &env->fp_status);
     }
     arch_fpop_end(env);
@@ -1053,8 +1054,9 @@ float64 HELPER(dfmin)(CPUHexagonState *env, float64 RssV, float64 RttV)
 {
     float64 RddV;
     arch_fpop_start(env);
-    RddV = float64_minnum(RssV, RttV, &env->fp_status);
-    if (float64_is_any_nan(RssV) || float64_is_any_nan(RttV)) {
+    RddV = float64_minimum_number(RssV, RttV, &env->fp_status);
+    if (float64_is_quiet_nan(RssV, &env->fp_status) ||
+        float64_is_quiet_nan(RttV, &env->fp_status)) {
         float_raise(float_flag_invalid, &env->fp_status);
     }
     arch_fpop_end(env);
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · Taylor Simpson

The float??_minnum implementation differs from Hexagon for SNaN, it returns NaN, but Hexagon returns the other input. So, we use float??_minimum_number. For double precision, we check for QNaN and raise the invalid flag.

I'm surprised that the behaviour for double differs from single, but the docs are light on the subject. Anyway,

r~

#2 lore raw
Quoted 17 lines

-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Wednesday, February 16, 2022 4:53 PM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Brian Cain <[email protected]>; Michael Lambert <[email protected]>
Subject: Re: [PATCH v3] Hexagon (target/hexagon) properly handle NaN in dfmin/dfmax/sfmin/sfmax

Quoted 4 lines · Taylor Simpson

The float??_minnum implementation differs from Hexagon for SNaN, it returns NaN, but Hexagon returns the other input. So, we use float??_minimum_number. For double precision, we check for QNaN and raise the invalid flag.

Quoted 4 lines

I'm surprised that the behaviour for double differs from single, but the docs are light on the subject. Anyway,

The dfmin/dfmax were added in a later version of the hardware than sfmin/sfmax. I was seeing the different behavior on the reference simulator. I was able to get my hands on the newer hardware to run the test and found that the reference simulator behaves differently. I'll respin this patch to match the behavior of the hardware.

Thanks,
Taylor