Commit c9a10845 authored by Maciej W. Rozycki's avatar Maciej W. Rozycki Committed by Ralf Baechle

MIPS: math-emu: Optimise NaN handling in comparisons

We have the input operands already classified in `ieee754sp_cmp' and
`ieee754dp_cmp' comparison operations, so use the class obtained to tell
NaNs and numbers apart rather than classifying inputs again for this
purpose, reducing the size of code by 24 and 40 instructions or 96 and
160 bytes respectively.
Signed-off-by: default avatarMaciej W. Rozycki <macro@linux-mips.org>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/9689/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent d5afa7e9
...@@ -35,7 +35,7 @@ int ieee754dp_cmp(union ieee754dp x, union ieee754dp y, int cmp, int sig) ...@@ -35,7 +35,7 @@ int ieee754dp_cmp(union ieee754dp x, union ieee754dp y, int cmp, int sig)
FLUSHYDP; FLUSHYDP;
ieee754_clearcx(); /* Even clear inexact flag here */ ieee754_clearcx(); /* Even clear inexact flag here */
if (ieee754dp_isnan(x) || ieee754dp_isnan(y)) { if (ieee754_class_nan(xc) || ieee754_class_nan(yc)) {
if (sig || if (sig ||
xc == IEEE754_CLASS_SNAN || yc == IEEE754_CLASS_SNAN) xc == IEEE754_CLASS_SNAN || yc == IEEE754_CLASS_SNAN)
ieee754_setcx(IEEE754_INVALID_OPERATION); ieee754_setcx(IEEE754_INVALID_OPERATION);
......
...@@ -32,7 +32,7 @@ int ieee754dp_class(union ieee754dp x) ...@@ -32,7 +32,7 @@ int ieee754dp_class(union ieee754dp x)
int ieee754dp_isnan(union ieee754dp x) int ieee754dp_isnan(union ieee754dp x)
{ {
return ieee754dp_class(x) >= IEEE754_CLASS_SNAN; return ieee754_class_nan(ieee754dp_class(x));
} }
static inline int ieee754dp_issnan(union ieee754dp x) static inline int ieee754dp_issnan(union ieee754dp x)
......
...@@ -44,6 +44,11 @@ static inline int ieee754_setandtestcx(const unsigned int x) ...@@ -44,6 +44,11 @@ static inline int ieee754_setandtestcx(const unsigned int x)
return ieee754_csr.mx & x; return ieee754_csr.mx & x;
} }
static inline int ieee754_class_nan(int xc)
{
return xc >= IEEE754_CLASS_SNAN;
}
#define COMPXSP \ #define COMPXSP \
unsigned xm; int xe; int xs __maybe_unused; int xc unsigned xm; int xe; int xs __maybe_unused; int xc
......
...@@ -32,7 +32,7 @@ int ieee754sp_class(union ieee754sp x) ...@@ -32,7 +32,7 @@ int ieee754sp_class(union ieee754sp x)
int ieee754sp_isnan(union ieee754sp x) int ieee754sp_isnan(union ieee754sp x)
{ {
return ieee754sp_class(x) >= IEEE754_CLASS_SNAN; return ieee754_class_nan(ieee754sp_class(x));
} }
static inline int ieee754sp_issnan(union ieee754sp x) static inline int ieee754sp_issnan(union ieee754sp x)
......
...@@ -35,7 +35,7 @@ int ieee754sp_cmp(union ieee754sp x, union ieee754sp y, int cmp, int sig) ...@@ -35,7 +35,7 @@ int ieee754sp_cmp(union ieee754sp x, union ieee754sp y, int cmp, int sig)
FLUSHYSP; FLUSHYSP;
ieee754_clearcx(); /* Even clear inexact flag here */ ieee754_clearcx(); /* Even clear inexact flag here */
if (ieee754sp_isnan(x) || ieee754sp_isnan(y)) { if (ieee754_class_nan(xc) || ieee754_class_nan(yc)) {
if (sig || if (sig ||
xc == IEEE754_CLASS_SNAN || yc == IEEE754_CLASS_SNAN) xc == IEEE754_CLASS_SNAN || yc == IEEE754_CLASS_SNAN)
ieee754_setcx(IEEE754_INVALID_OPERATION); ieee754_setcx(IEEE754_INVALID_OPERATION);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment