1
From 78a735b4ddae51f19cc32441d29625f864dfba78 Mon Sep 17 00:00:00 2001
2
From: Will Newton <will.newton@linaro.org>
3
Date: Fri, 6 Dec 2013 17:01:41 +0000
4
Subject: [PATCH 49/49] softfloat: Add minNum() and maxNum() functions to
7
Add floatnn_minnum() and floatnn_maxnum() functions which are equivalent
8
to the minNum() and maxNum() functions from IEEE 754-2008. They are
9
similar to min() and max() but differ in the handling of QNaN arguments.
11
Signed-off-by: Will Newton <will.newton@linaro.org>
12
Message-id: 1386158099-9239-5-git-send-email-will.newton@linaro.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
fpu/softfloat.c | 32 +++++++++++++++++++++++++++++---
16
include/fpu/softfloat.h | 4 ++++
17
2 files changed, 33 insertions(+), 3 deletions(-)
19
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
20
index 7ba51b6..a3ca7e0 100644
23
@@ -6705,10 +6705,17 @@ int float128_compare_quiet( float128 a, float128 b STATUS_PARAM )
24
/* min() and max() functions. These can't be implemented as
25
* 'compare and pick one input' because that would mishandle
28
+ * minnum() and maxnum() functions. These are similar to the min()
29
+ * and max() functions but if one of the arguments is a QNaN and
30
+ * the other is numerical then the numerical argument is returned.
31
+ * minnum() and maxnum correspond to the IEEE 754-2008 minNum()
32
+ * and maxNum() operations. min() and max() are the typical min/max
33
+ * semantics provided by many CPUs which predate that specification.
35
#define MINMAX(s, nan_exp) \
36
INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \
37
- int ismin STATUS_PARAM ) \
38
+ int ismin, int isieee STATUS_PARAM) \
41
uint ## s ## _t av, bv; \
42
@@ -6716,6 +6723,15 @@ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \
43
b = float ## s ## _squash_input_denormal(b STATUS_VAR); \
44
if (float ## s ## _is_any_nan(a) || \
45
float ## s ## _is_any_nan(b)) { \
47
+ if (float ## s ## _is_quiet_nan(a) && \
48
+ !float ## s ##_is_any_nan(b)) { \
50
+ } else if (float ## s ## _is_quiet_nan(b) && \
51
+ !float ## s ## _is_any_nan(a)) { \
55
return propagateFloat ## s ## NaN(a, b STATUS_VAR); \
57
aSign = extractFloat ## s ## Sign(a); \
58
@@ -6739,12 +6755,22 @@ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \
60
float ## s float ## s ## _min(float ## s a, float ## s b STATUS_PARAM) \
62
- return float ## s ## _minmax(a, b, 1 STATUS_VAR); \
63
+ return float ## s ## _minmax(a, b, 1, 0 STATUS_VAR); \
66
float ## s float ## s ## _max(float ## s a, float ## s b STATUS_PARAM) \
68
- return float ## s ## _minmax(a, b, 0 STATUS_VAR); \
69
+ return float ## s ## _minmax(a, b, 0, 0 STATUS_VAR); \
72
+float ## s float ## s ## _minnum(float ## s a, float ## s b STATUS_PARAM) \
74
+ return float ## s ## _minmax(a, b, 1, 1 STATUS_VAR); \
77
+float ## s float ## s ## _maxnum(float ## s a, float ## s b STATUS_PARAM) \
79
+ return float ## s ## _minmax(a, b, 0, 1 STATUS_VAR); \
83
diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
84
index f3927e2..2365274 100644
85
--- a/include/fpu/softfloat.h
86
+++ b/include/fpu/softfloat.h
87
@@ -302,6 +302,8 @@ int float32_compare( float32, float32 STATUS_PARAM );
88
int float32_compare_quiet( float32, float32 STATUS_PARAM );
89
float32 float32_min(float32, float32 STATUS_PARAM);
90
float32 float32_max(float32, float32 STATUS_PARAM);
91
+float32 float32_minnum(float32, float32 STATUS_PARAM);
92
+float32 float32_maxnum(float32, float32 STATUS_PARAM);
93
int float32_is_quiet_nan( float32 );
94
int float32_is_signaling_nan( float32 );
95
float32 float32_maybe_silence_nan( float32 );
96
@@ -408,6 +410,8 @@ int float64_compare( float64, float64 STATUS_PARAM );
97
int float64_compare_quiet( float64, float64 STATUS_PARAM );
98
float64 float64_min(float64, float64 STATUS_PARAM);
99
float64 float64_max(float64, float64 STATUS_PARAM);
100
+float64 float64_minnum(float64, float64 STATUS_PARAM);
101
+float64 float64_maxnum(float64, float64 STATUS_PARAM);
102
int float64_is_quiet_nan( float64 a );
103
int float64_is_signaling_nan( float64 );
104
float64 float64_maybe_silence_nan( float64 );