From 448b91d9779abc7c16ccb549e0d9549f5a8bd1fa Mon Sep 17 00:00:00 2001 From: Chih-Min Chao Date: Mon, 23 Mar 2020 01:52:44 -0700 Subject: sf: simplify sNaN handling for fmax and fmin Signed-off-by: Chih-Min Chao --- softfloat/fall_maxmin.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'softfloat') diff --git a/softfloat/fall_maxmin.c b/softfloat/fall_maxmin.c index 6405cf1..32a9ade 100644 --- a/softfloat/fall_maxmin.c +++ b/softfloat/fall_maxmin.c @@ -45,43 +45,31 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define COMPARE_MAX(a, b, bits) \ float ## bits ## _t f ## bits ## _max( float ## bits ## _t a, float ## bits ## _t b ) \ { \ - if (f ## bits ## _isSignalingNaN(a) || \ - f ## bits ## _isSignalingNaN(b)) { \ - union ui ## bits ## _f ## bits ui; \ - ui.ui = defaultNaNF ## bits ## UI; \ - softfloat_raiseFlags( softfloat_flag_invalid ); \ - return ui.f; \ - } else if (isNaNF ## bits ## UI(a.v) && isNaNF ## bits ## UI(b.v)) { \ + bool greater = f ## bits ## _lt_quiet(b, a) || \ + (f ## bits ## _eq(b, a) && signF ## bits ## UI(b.v)); \ + \ + if (isNaNF ## bits ## UI(a.v) && isNaNF ## bits ## UI(b.v)) { \ union ui ## bits ## _f ## bits ui; \ ui.ui = defaultNaNF ## bits ## UI; \ return ui.f; \ + } else { \ + return greater || isNaNF ## bits ## UI((b).v) ? a : b; \ } \ - \ - bool greater = f ## bits ## _lt_quiet(b, a) || \ - (f ## bits ## _eq(b, a) && signF ## bits ## UI(b.v)); \ - \ - return greater || isNaNF ## bits ## UI((b).v) ? a : b; \ } #define COMPARE_MIN(a, b, bits) \ float ## bits ## _t f ## bits ## _min( float ## bits ## _t a, float ## bits ## _t b ) \ { \ - if (f ## bits ## _isSignalingNaN(a) || \ - f ## bits ## _isSignalingNaN(b)) { \ - union ui ## bits ## _f ## bits ui; \ - ui.ui = defaultNaNF ## bits ## UI; \ - softfloat_raiseFlags( softfloat_flag_invalid ); \ - return ui.f; \ - } else if (isNaNF ## bits ## UI(a.v) && isNaNF ## bits ## UI(b.v)) { \ + bool less = f ## bits ## _lt_quiet(a, b) || \ + (f ## bits ## _eq(a, b) && signF ## bits ## UI(a.v)); \ + \ + if (isNaNF ## bits ## UI(a.v) && isNaNF ## bits ## UI(b.v)) { \ union ui ## bits ## _f ## bits ui; \ ui.ui = defaultNaNF ## bits ## UI; \ return ui.f; \ + } else { \ + return less || isNaNF ## bits ## UI((b).v) ? a : b; \ } \ - \ - bool greater = f ## bits ## _lt_quiet(a, b) || \ - (f ## bits ## _eq(a, b) && signF ## bits ## UI(a.v)); \ - \ - return greater || isNaNF ## bits ## UI((b).v) ? a : b; \ } COMPARE_MAX(a, b, 16); -- cgit v1.1