diff mbox series

[v1,06/19] fpu/softfloat: propagate signalling NaNs in MINMAX

Message ID 20171211125705.16120-7-alex.bennee@linaro.org
State Superseded
Headers show
Series re-factor softfloat and add fp16 functions | expand

Commit Message

Alex Bennée Dec. 11, 2017, 12:56 p.m. UTC
While a comparison between a QNaN and a number will return the number
it is not the same with a signaling NaN. In this case the SNaN will
"win" and after potentially raising an exception it will be quietened.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>


---
v2
  - added return for propageFloat
---
 fpu/softfloat.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

-- 
2.15.1

Comments

Richard Henderson Dec. 18, 2017, 9:53 p.m. UTC | #1
On 12/11/2017 04:56 AM, Alex Bennée wrote:
> While a comparison between a QNaN and a number will return the number

> it is not the same with a signaling NaN. In this case the SNaN will

> "win" and after potentially raising an exception it will be quietened.

> 

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> 

> ---

> v2

>   - added return for propageFloat

> ---

>  fpu/softfloat.c | 8 ++++++--

>  1 file changed, 6 insertions(+), 2 deletions(-)


I suppose this fixes minmax for float128 too,
and is thus not redundant with patch 18?

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>



r~
Alex Bennée Jan. 5, 2018, 1:05 p.m. UTC | #2
Richard Henderson <richard.henderson@linaro.org> writes:

> On 12/11/2017 04:56 AM, Alex Bennée wrote:

>> While a comparison between a QNaN and a number will return the number

>> it is not the same with a signaling NaN. In this case the SNaN will

>> "win" and after potentially raising an exception it will be quietened.

>>

>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

>>

>> ---

>> v2

>>   - added return for propageFloat

>> ---

>>  fpu/softfloat.c | 8 ++++++--

>>  1 file changed, 6 insertions(+), 2 deletions(-)

>

> I suppose this fixes minmax for float128 too,

> and is thus not redundant with patch 18?


It was never expanded so I guess no one does float128 minmax's at the moment.

>

> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

>

>

> r~



--
Alex Bennée
diff mbox series

Patch

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 3a4ab1355f..44c043924e 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -7683,6 +7683,7 @@  int float128_compare_quiet(float128 a, float128 b, float_status *status)
  * minnum() and maxnum() functions. These are similar to the min()
  * and max() functions but if one of the arguments is a QNaN and
  * the other is numerical then the numerical argument is returned.
+ * SNaNs will get quietened before being returned.
  * minnum() and maxnum correspond to the IEEE 754-2008 minNum()
  * and maxNum() operations. min() and max() are the typical min/max
  * semantics provided by many CPUs which predate that specification.
@@ -7703,11 +7704,14 @@  static inline float ## s float ## s ## _minmax(float ## s a, float ## s b,     \
     if (float ## s ## _is_any_nan(a) ||                                 \
         float ## s ## _is_any_nan(b)) {                                 \
         if (isieee) {                                                   \
-            if (float ## s ## _is_quiet_nan(a, status) &&               \
+            if (float ## s ## _is_signaling_nan(a, status) ||           \
+                float ## s ## _is_signaling_nan(b, status)) {           \
+                return propagateFloat ## s ## NaN(a, b, status);        \
+            } else  if (float ## s ## _is_quiet_nan(a, status) &&       \
                 !float ## s ##_is_any_nan(b)) {                         \
                 return b;                                               \
             } else if (float ## s ## _is_quiet_nan(b, status) &&        \
-                       !float ## s ## _is_any_nan(a)) {                \
+                       !float ## s ## _is_any_nan(a)) {                 \
                 return a;                                               \
             }                                                           \
         }                                                               \