@@ -4,11 +4,12 @@ CPPFLAGS += -I../soft-fp
libm-support += powl_helper
tests += test-fenv-sse test-fenv-clear-sse test-fenv-x87 test-fenv-sse-2 \
- test-flt-eval-method-387 test-flt-eval-method-sse
+ test-flt-eval-method-387 test-flt-eval-method-sse test-unnormal
CFLAGS-test-fenv-sse.c += -msse2 -mfpmath=sse
CFLAGS-test-fenv-clear-sse.c += -msse2 -mfpmath=sse
CFLAGS-test-fenv-sse-2.c += -msse2 -mfpmath=sse
CFLAGS-test-flt-eval-method-387.c += -fexcess-precision=standard -mfpmath=387
CFLAGS-test-flt-eval-method-sse.c += -fexcess-precision=standard -msse2 \
-mfpmath=sse
+CFLAGS-test-unnormal.c += -fsignaling-nans -std=c2x
endif
new file mode 100644
@@ -0,0 +1,132 @@
+/* Test long double classification with x86 pseudo normal numbers.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#include <math_ldbl.h>
+#include <support/test-driver.h>
+#include <support/check.h>
+
+/* If we need to add regular NaNs here then we need another member specifying
+ whether the NaN is signaling and then issignaling test should be updated to
+ use it. Additionally, all pseudo-numbers should be classified as
+ signaling. */
+struct tests
+{
+ ieee_long_double_shape_type d;
+ int class;
+} inputs[] = {
+ /* Normal. */
+ {
+ .d.parts.lsw = 0x00000400,
+ .d.parts.msw = 0x00000000,
+ .d.parts.sign_exponent = 0x0400,
+ .class = FP_NAN
+ },
+ {
+ .d.parts.lsw = 0x00000400,
+ .d.parts.msw = 0xf0000000,
+ .d.parts.sign_exponent = 0x0400,
+ .class = FP_NORMAL
+ },
+ /* Pseudo-infinite. */
+ {
+ .d.parts.lsw = 0x00000000,
+ .d.parts.msw = 0x00000000,
+ .d.parts.sign_exponent = 0x7fff,
+ .class = FP_NAN
+ },
+ {
+ .d.parts.lsw = 0x00000000,
+ .d.parts.msw = 0x80000000,
+ .d.parts.sign_exponent = 0x7fff,
+ .class = FP_INFINITE
+ },
+ /* Pseudo-zero. */
+ {
+ .d.parts.lsw = 0x00000000,
+ .d.parts.msw = 0x00000000,
+ .d.parts.sign_exponent = 0x0100,
+ .class = FP_NAN
+ },
+ {
+ .d.parts.lsw = 0x00000000,
+ .d.parts.msw = 0x00000000,
+ .d.parts.sign_exponent = 0x0000,
+ .class = FP_ZERO
+ },
+};
+
+typedef void (*testfunc_t) (long double, int);
+
+static int
+test_func (const char *testname, testfunc_t testfunc)
+{
+ verbose_printf ("* %s:\n", testname);
+
+ for (int i = 0; i < sizeof (inputs)/sizeof (struct tests); i++)
+ {
+ verbose_printf ("Testing 0x%04x %08x %08x\n",
+ inputs[i].d.parts.sign_exponent, inputs[i].d.parts.msw,
+ inputs[i].d.parts.lsw);
+ testfunc (inputs[i].d.value, inputs[i].class);
+ }
+
+ return 0;
+}
+
+static void
+test_fpclassify (long double value, int class)
+{
+ TEST_COMPARE (fpclassify (value), class);
+}
+
+static void
+test_isinf (long double value, int class)
+{
+ TEST_COMPARE ((isinf (value) != 0), (class == FP_INFINITE));
+}
+
+static void
+test_isnan (long double value, int class)
+{
+ TEST_COMPARE ((isnan (value) != 0), (class == FP_NAN));
+}
+
+static void
+test_issignaling (long double value, int class)
+{
+ TEST_COMPARE ((issignaling (value) != 0), (class == FP_NAN));
+}
+
+int
+do_test (void)
+{
+ int ret = 0;
+
+ test_func ("fpclassify", test_fpclassify);
+ test_func ("isinf", test_isinf);
+ test_func ("isnan", test_isnan);
+ test_func ("issignaling", test_issignaling);
+
+ return ret;
+}
+
+#include <support/test-driver.c>