include/fpu/softfloat: implement float16_abs helper
authorAlex Bennée <alex.bennee@linaro.org>
Mon, 3 Jul 2017 13:33:08 +0000 (14:33 +0100)
committerAlex Bennée <alex.bennee@linaro.org>
Wed, 21 Feb 2018 10:20:26 +0000 (10:20 +0000)
This will be required when expanding the MINMAX() macro for 16
bit/half-precision operations.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
include/fpu/softfloat.h

index f3b9008f78689ec6829446bf8908710f8ad0efab..1d34f2c3eb33573c3c32bc26b5111e8f0741aa02 100644 (file)
@@ -265,6 +265,13 @@ static inline int float16_is_zero_or_denormal(float16 a)
     return (float16_val(a) & 0x7c00) == 0;
 }
 
+static inline float16 float16_abs(float16 a)
+{
+    /* Note that abs does *not* handle NaN specially, nor does
+     * it flush denormal inputs to zero.
+     */
+    return make_float16(float16_val(a) & 0x7fff);
+}
 /*----------------------------------------------------------------------------
 | The pattern for a default generated half-precision NaN.
 *----------------------------------------------------------------------------*/