From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: libc-alpha@sourceware.org
Cc: adhemerval.zanella@linaro.org, fweimer@redhat.com,
joseph@codesourcery.com
Subject: [PATCH v2 5/5] x86 long double: Add tests for pseudo normal numbers
Date: Wed, 23 Dec 2020 17:26:02 +0530 [thread overview]
Message-ID: <20201223115602.3472627-6-siddhesh@sourceware.org> (raw)
In-Reply-To: <20201223115602.3472627-1-siddhesh@sourceware.org>
Add some tests for fpclassify, isnanl, isinfl and issignaling.
---
sysdeps/x86/fpu/Makefile | 3 +-
sysdeps/x86/fpu/test-unnormal.c | 132 ++++++++++++++++++++++++++++++++
2 files changed, 134 insertions(+), 1 deletion(-)
create mode 100644 sysdeps/x86/fpu/test-unnormal.c
diff --git a/sysdeps/x86/fpu/Makefile b/sysdeps/x86/fpu/Makefile
index 600e42c3db..e77de56d14 100644
--- a/sysdeps/x86/fpu/Makefile
+++ b/sysdeps/x86/fpu/Makefile
@@ -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
diff --git a/sysdeps/x86/fpu/test-unnormal.c b/sysdeps/x86/fpu/test-unnormal.c
new file mode 100644
index 0000000000..a6baa01802
--- /dev/null
+++ b/sysdeps/x86/fpu/test-unnormal.c
@@ -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>
--
2.29.2
prev parent reply other threads:[~2020-12-23 11:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-23 11:55 [PATCH v2 0/5] x86 pseudo-normal numbers Siddhesh Poyarekar
2020-12-23 11:55 ` [PATCH v2 1/5] x86 long double: Support pseudo numbers in fpclassifyl Siddhesh Poyarekar
2020-12-23 17:59 ` Adhemerval Zanella
2020-12-23 11:55 ` [PATCH v2 2/5] x86 long double: Support pseudo numbers in isnanl Siddhesh Poyarekar
2020-12-23 18:03 ` Adhemerval Zanella
2020-12-23 11:56 ` [PATCH v2 3/5] Partially revert 681900d29683722b1cb0a8e565a0585846ec5a61 Siddhesh Poyarekar
2020-12-23 12:09 ` Florian Weimer
2020-12-23 11:56 ` [PATCH v2 4/5] x86 long double: Consider pseudo numbers as signaling Siddhesh Poyarekar
2020-12-23 18:14 ` Adhemerval Zanella
2020-12-23 11:56 ` Siddhesh Poyarekar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201223115602.3472627-6-siddhesh@sourceware.org \
--to=siddhesh@sourceware.org \
--cc=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=joseph@codesourcery.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).