fpu/softfloat.c | 41 +++++++++++++++++++++++++++++++++++------ include/fpu/softfloat.h | 4 ++++ 2 files changed, 39 insertions(+), 6 deletions(-)
QEMU currently implements IEEE 754-2008 minNum/maxNum. This patch adds
support for IEEE 754-201x minimumNumber/maximumNumber which is required
by the RISC-V port.
minNum(x, y) is defined as
- min(x, y) if neither is NaN
- if one of x and y is a number and one is qNaN, return the number
- if both are qNaN, or either is sNaN, return NaN
minimumNumber(x, y) is defined as
- min(x, y) if neither is NaN
- if one of x and y is a number and one is qNaN or sNaN, return the number
- if both are NaN, return the number
Both functions signal the invalid exception on sNaN inputs.
Signed-off-by: Michael Clark <mjc@sifive.com>
---
fpu/softfloat.c | 41 +++++++++++++++++++++++++++++++++++------
include/fpu/softfloat.h | 4 ++++
2 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 433c5da..5793cc9 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -7675,6 +7675,9 @@ int float128_compare_quiet(float128 a, float128 b, float_status *status)
* minnummag() and maxnummag() functions correspond to minNumMag()
* and minNumMag() from the IEEE-754 2008.
*/
+
+enum { ieee2008 = 1, ieee201x = 2 };
+
#define MINMAX(s) \
static inline float ## s float ## s ## _minmax(float ## s a, float ## s b, \
int ismin, int isieee, \
@@ -7687,12 +7690,26 @@ static inline float ## s float ## s ## _minmax(float ## s a, float ## s b, \
b = float ## s ## _squash_input_denormal(b, status); \
if (float ## s ## _is_any_nan(a) || \
float ## s ## _is_any_nan(b)) { \
- if (isieee) { \
+ if (isieee == ieee2008) { \
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; \
+ } \
+ } else if (isieee == ieee201x) { \
+ if (float ## s ## _is_any_nan(a) && \
+ !float ## s ##_is_any_nan(b)) { \
+ if (!float ## s ## _is_quiet_nan(a, status)) { \
+ float_raise(float_flag_invalid, status); \
+ } \
+ return b; \
+ } else if (float ## s ## _is_any_nan(b) && \
+ !float ## s ## _is_any_nan(a)) { \
+ if (!float ## s ## _is_quiet_nan(b, status)) { \
+ float_raise(float_flag_invalid, status); \
+ } \
return a; \
} \
} \
@@ -7743,25 +7760,37 @@ float ## s float ## s ## _max(float ## s a, float ## s b, \
float ## s float ## s ## _minnum(float ## s a, float ## s b, \
float_status *status) \
{ \
- return float ## s ## _minmax(a, b, 1, 1, 0, status); \
+ return float ## s ## _minmax(a, b, 1, ieee2008, 0, status); \
} \
\
float ## s float ## s ## _maxnum(float ## s a, float ## s b, \
float_status *status) \
{ \
- return float ## s ## _minmax(a, b, 0, 1, 0, status); \
+ return float ## s ## _minmax(a, b, 0, ieee2008, 0, status); \
+} \
+ \
+float ## s float ## s ## _minimumnumber(float ## s a, float ## s b, \
+ float_status *status) \
+{ \
+ return float ## s ## _minmax(a, b, 1, ieee201x, 0, status); \
+} \
+ \
+float ## s float ## s ## _maximumnumber(float ## s a, float ## s b, \
+ float_status *status) \
+{ \
+ return float ## s ## _minmax(a, b, 0, ieee201x, 0, status); \
} \
\
float ## s float ## s ## _minnummag(float ## s a, float ## s b, \
float_status *status) \
{ \
- return float ## s ## _minmax(a, b, 1, 1, 1, status); \
+ return float ## s ## _minmax(a, b, 1, ieee2008, 1, status); \
} \
\
float ## s float ## s ## _maxnummag(float ## s a, float ## s b, \
float_status *status) \
{ \
- return float ## s ## _minmax(a, b, 0, 1, 1, status); \
+ return float ## s ## _minmax(a, b, 0, ieee2008, 1, status); \
}
MINMAX(32)
diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
index 0f96a0e..e0d0259 100644
--- a/include/fpu/softfloat.h
+++ b/include/fpu/softfloat.h
@@ -424,6 +424,8 @@ float32 float32_min(float32, float32, float_status *status);
float32 float32_max(float32, float32, float_status *status);
float32 float32_minnum(float32, float32, float_status *status);
float32 float32_maxnum(float32, float32, float_status *status);
+float32 float32_minimumnumber(float32, float32, float_status *status);
+float32 float32_maximumnumber(float32, float32, float_status *status);
float32 float32_minnummag(float32, float32, float_status *status);
float32 float32_maxnummag(float32, float32, float_status *status);
int float32_is_quiet_nan(float32, float_status *status);
@@ -536,6 +538,8 @@ float64 float64_min(float64, float64, float_status *status);
float64 float64_max(float64, float64, float_status *status);
float64 float64_minnum(float64, float64, float_status *status);
float64 float64_maxnum(float64, float64, float_status *status);
+float64 float64_minimumnumber(float64, float64, float_status *status);
+float64 float64_maximumnumber(float64, float64, float_status *status);
float64 float64_minnummag(float64, float64, float_status *status);
float64 float64_maxnummag(float64, float64, float_status *status);
int float64_is_quiet_nan(float64 a, float_status *status);
--
2.7.0
Hi,
This series seems to have some coding style problems. See output below for
more information:
Type: series
Message-id: 1518046997-22714-1-git-send-email-mjc@sifive.com
Subject: [Qemu-devel] [PATCH v1] Implement support for IEEE 754-201x minimumNumber/maximumNumber
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
1dbe78092c Implement support for IEEE 754-201x minimumNumber/maximumNumber
=== OUTPUT BEGIN ===
Checking PATCH 1/1: Implement support for IEEE 754-201x minimumNumber/maximumNumber...
ERROR: spaces required around that '*' (ctx:WxV)
#85: FILE: fpu/softfloat.c:7773:
+ float_status *status) \
^
ERROR: spaces required around that '*' (ctx:WxV)
#91: FILE: fpu/softfloat.c:7779:
+ float_status *status) \
^
total: 2 errors, 0 warnings, 94 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
I've included this patch in the RISC-V patch series just submitted.
The change is enclosed within a simple conditional so there is no risk of
affecting any other ports.
There was one line whitespace fix to the pre-existing code however it fell
nicely within the diff hunk so I included the fix.
On Thu, Feb 8, 2018 at 12:43 PM, Michael Clark <mjc@sifive.com> wrote:
> QEMU currently implements IEEE 754-2008 minNum/maxNum. This patch adds
> support for IEEE 754-201x minimumNumber/maximumNumber which is required
> by the RISC-V port.
>
> minNum(x, y) is defined as
> - min(x, y) if neither is NaN
> - if one of x and y is a number and one is qNaN, return the number
> - if both are qNaN, or either is sNaN, return NaN
>
> minimumNumber(x, y) is defined as
> - min(x, y) if neither is NaN
> - if one of x and y is a number and one is qNaN or sNaN, return the number
> - if both are NaN, return the number
>
> Both functions signal the invalid exception on sNaN inputs.
>
> Signed-off-by: Michael Clark <mjc@sifive.com>
> ---
> fpu/softfloat.c | 41 +++++++++++++++++++++++++++++++++++------
> include/fpu/softfloat.h | 4 ++++
> 2 files changed, 39 insertions(+), 6 deletions(-)
>
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index 433c5da..5793cc9 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -7675,6 +7675,9 @@ int float128_compare_quiet(float128 a, float128 b,
> float_status *status)
> * minnummag() and maxnummag() functions correspond to minNumMag()
> * and minNumMag() from the IEEE-754 2008.
> */
> +
> +enum { ieee2008 = 1, ieee201x = 2 };
> +
> #define MINMAX(s) \
> static inline float ## s float ## s ## _minmax(float ## s a, float ## s
> b, \
> int ismin, int isieee, \
> @@ -7687,12 +7690,26 @@ static inline float ## s float ## s ##
> _minmax(float ## s a, float ## s b, \
> b = float ## s ## _squash_input_denormal(b, status); \
> if (float ## s ## _is_any_nan(a) || \
> float ## s ## _is_any_nan(b)) { \
> - if (isieee) { \
> + if (isieee == ieee2008) { \
> 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; \
> + } \
> + } else if (isieee == ieee201x) { \
> + if (float ## s ## _is_any_nan(a) && \
> + !float ## s ##_is_any_nan(b)) { \
> + if (!float ## s ## _is_quiet_nan(a, status)) { \
> + float_raise(float_flag_invalid, status); \
> + } \
> + return b; \
> + } else if (float ## s ## _is_any_nan(b) && \
> + !float ## s ## _is_any_nan(a)) { \
> + if (!float ## s ## _is_quiet_nan(b, status)) { \
> + float_raise(float_flag_invalid, status); \
> + } \
> return a; \
> } \
> } \
> @@ -7743,25 +7760,37 @@ float ## s float ## s ## _max(float ## s a, float
> ## s b, \
> float ## s float ## s ## _minnum(float ## s a, float ## s b, \
> float_status *status) \
> { \
> - return float ## s ## _minmax(a, b, 1, 1, 0, status); \
> + return float ## s ## _minmax(a, b, 1, ieee2008, 0, status); \
> } \
> \
> float ## s float ## s ## _maxnum(float ## s a, float ## s b, \
> float_status *status) \
> { \
> - return float ## s ## _minmax(a, b, 0, 1, 0, status); \
> + return float ## s ## _minmax(a, b, 0, ieee2008, 0, status); \
> +} \
> + \
> +float ## s float ## s ## _minimumnumber(float ## s a, float ## s b, \
> + float_status *status) \
> +{ \
> + return float ## s ## _minmax(a, b, 1, ieee201x, 0, status); \
> +} \
> + \
> +float ## s float ## s ## _maximumnumber(float ## s a, float ## s b, \
> + float_status *status) \
> +{ \
> + return float ## s ## _minmax(a, b, 0, ieee201x, 0, status); \
> } \
> \
> float ## s float ## s ## _minnummag(float ## s a, float ## s b, \
> float_status *status) \
> { \
> - return float ## s ## _minmax(a, b, 1, 1, 1, status); \
> + return float ## s ## _minmax(a, b, 1, ieee2008, 1, status); \
> } \
> \
> float ## s float ## s ## _maxnummag(float ## s a, float ## s b, \
> float_status *status) \
> { \
> - return float ## s ## _minmax(a, b, 0, 1, 1, status); \
> + return float ## s ## _minmax(a, b, 0, ieee2008, 1, status); \
> }
>
> MINMAX(32)
> diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
> index 0f96a0e..e0d0259 100644
> --- a/include/fpu/softfloat.h
> +++ b/include/fpu/softfloat.h
> @@ -424,6 +424,8 @@ float32 float32_min(float32, float32, float_status
> *status);
> float32 float32_max(float32, float32, float_status *status);
> float32 float32_minnum(float32, float32, float_status *status);
> float32 float32_maxnum(float32, float32, float_status *status);
> +float32 float32_minimumnumber(float32, float32, float_status *status);
> +float32 float32_maximumnumber(float32, float32, float_status *status);
> float32 float32_minnummag(float32, float32, float_status *status);
> float32 float32_maxnummag(float32, float32, float_status *status);
> int float32_is_quiet_nan(float32, float_status *status);
> @@ -536,6 +538,8 @@ float64 float64_min(float64, float64, float_status
> *status);
> float64 float64_max(float64, float64, float_status *status);
> float64 float64_minnum(float64, float64, float_status *status);
> float64 float64_maxnum(float64, float64, float_status *status);
> +float64 float64_minimumnumber(float64, float64, float_status *status);
> +float64 float64_maximumnumber(float64, float64, float_status *status);
> float64 float64_minnummag(float64, float64, float_status *status);
> float64 float64_maxnummag(float64, float64, float_status *status);
> int float64_is_quiet_nan(float64 a, float_status *status);
> --
> 2.7.0
>
>
© 2016 - 2026 Red Hat, Inc.