From patchwork Tue Dec 15 14:13:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 41397 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5EA72386EC4F; Tue, 15 Dec 2020 14:14:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5EA72386EC4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608041665; bh=bgTXLQQ9UtZu5a53G/bXzF8TQ/337oHM3I145NQVToE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jORYhW+dn2V8mWt1PQPkXmnMy2VkgIEfsODMF3KHcQduI9lV+oXfpvm8CJXMXgPgF GosuDSxRHhyugotJaRuKL42QxgZNveC3e+X/bmojmBArbiZo/8g9BdMWwtqFWtMaJ7 NnjcDcU7yNU3PsxqdYVFXg3Y1y1HNLrSWjmY8+O8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from cyan.elm.relay.mailchannels.net (cyan.elm.relay.mailchannels.net [23.83.212.47]) by sourceware.org (Postfix) with ESMTPS id 96FAE384B00F for ; Tue, 15 Dec 2020 14:14:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 96FAE384B00F X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id F2FD71223A2; Tue, 15 Dec 2020 14:14:17 +0000 (UTC) Received: from pdx1-sub0-mail-a35.g.dreamhost.com (100-96-87-21.trex.outbound.svc.cluster.local [100.96.87.21]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E4A03122EAE; Tue, 15 Dec 2020 14:14:16 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a35.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.18.11); Tue, 15 Dec 2020 14:14:17 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Interest-Plucky: 53f284dc0ed2e890_1608041657284_3010144328 X-MC-Loop-Signature: 1608041657284:974736753 X-MC-Ingress-Time: 1608041657284 Received: from pdx1-sub0-mail-a35.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a35.g.dreamhost.com (Postfix) with ESMTP id 9BA797E63B; Tue, 15 Dec 2020 06:14:16 -0800 (PST) Received: from rhbox.redhat.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a35.g.dreamhost.com (Postfix) with ESMTPSA id C2DCD7E357; Tue, 15 Dec 2020 06:14:14 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a35 To: libc-alpha@sourceware.org Subject: [PATCH 5/5] x86 long double: Add tests for pseudo normal numbers Date: Tue, 15 Dec 2020 19:43:39 +0530 Message-Id: <20201215141339.2684384-6-siddhesh@sourceware.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201215141339.2684384-1-siddhesh@sourceware.org> References: <20201215141339.2684384-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: fweimer@redhat.com, joseph@codesourcery.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Add some tests for fpclassify, isnanl, isinfl and issignaling. --- sysdeps/x86/fpu/Makefile | 3 +- sysdeps/x86/fpu/test-unnormal.c | 196 ++++++++++++++++++++++++++++++++ 2 files changed, 198 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..fc65d9290f --- /dev/null +++ b/sysdeps/x86/fpu/test-unnormal.c @@ -0,0 +1,196 @@ +/* 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 + . */ + +#include +#include +#include + +struct tests +{ + const char *val; + int class; +} inputs[] = { + /* Normal. */ + {"\x00\x04\x00\x00\x00\x00\x00\x00\x00\x04", FP_NAN}, + {"\x00\x04\x00\x00\x00\x00\x00\xf0\x00\x04", FP_NORMAL}, + /* Pseudo-infinite. */ + {"\x00\x00\x00\x00\x00\x00\x00\x00\xff\x7f", FP_NAN}, + {"\x00\x00\x00\x00\x00\x00\x00\x80\xff\x7f", FP_INFINITE}, + /* Pseudo-zero. */ + {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", FP_NAN}, + {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", FP_ZERO}, +}; + +const char *classes[5]; +#define stringify(N) #N + +static void +initialize (void) +{ + classes[FP_NAN] = stringify(FP_NAN); + classes[FP_INFINITE] = stringify(FP_INFINITY); + classes[FP_ZERO] = stringify(FP_ZERO); + classes[FP_SUBNORMAL] = stringify(FP_SUBNORMAL); + classes[FP_NORMAL] = stringify(FP_NORMAL); +} + +static void +unnormal_str (const char *val, char *ret) +{ + for (int i = 9; i >= 0; i--) + { + if (i == 7 || i == 3) + *ret++ = ' '; + snprintf(ret, 3, "%02x", (unsigned char) val[i]); + ret += 2; + } +} + +static int +test_fpclassify (void) +{ + int ret = 0; + + printf ("* fpclassify tests:\n"); + for (int i = 0; i < sizeof (inputs)/sizeof (struct tests); i++) + { + long double value; + char buf[22]; + + memcpy (&value, inputs[i].val, 10); + unnormal_str(inputs[i].val, buf); + int class = fpclassify(value); + + if (class != inputs[i].class) + { + printf ("0x%s: got %s, expected %s\n", buf, + classes[fpclassify(value)], + classes[inputs[i].class]); + ret |= 1; + } + else + printf ("0x%s: OK\n", buf); + } + return ret; +} + +static int +test_isinf (void) +{ + int ret = 0; + + printf ("* isinfl tests:\n"); + for (int i = 0; i < sizeof (inputs)/sizeof (struct tests); i++) + { + long double value; + char buf[22]; + + memcpy (&value, inputs[i].val, 10); + unnormal_str(inputs[i].val, buf); + int inf = isinf (value); + + if ((inputs[i].class == FP_INFINITE && inf) + || (inputs[i].class != FP_INFINITE && !inf)) + printf ("0x%s: OK\n", buf); + else + { + printf ("0x%s: got %s, expected %s\n", buf, + inf ? "INFINITE" : "NOT INFINITE", + classes[inputs[i].class]); + ret |= 1; + } + } + + return ret; +} + +static int +test_isnan (void) +{ + int ret = 0; + + printf ("* isnanl tests:\n"); + for (int i = 0; i < sizeof (inputs)/sizeof (struct tests); i++) + { + long double value; + char buf[22]; + + memcpy (&value, inputs[i].val, 10); + unnormal_str(inputs[i].val, buf); + int nan = isnan (value); + + if ((inputs[i].class == FP_NAN && nan) + || (inputs[i].class != FP_NAN && !nan)) + printf ("0x%s: OK\n", buf); + else + { + printf ("0x%s: got %s, expected %s\n", buf, + nan ? "NAN" : "NOT NAN", + classes[inputs[i].class]); + ret |= 1; + } + } + return ret; +} + +static int +test_issignaling (void) +{ + int ret = 0; + + printf ("* issignaling tests:\n"); + for (int i = 0; i < sizeof (inputs)/sizeof (struct tests); i++) + { + long double value; + char buf[22]; + + memcpy (&value, inputs[i].val, 10); + unnormal_str(inputs[i].val, buf); + int signaling = issignaling (value); + + if ((inputs[i].class == FP_NAN && signaling) + || (inputs[i].class != FP_NAN && !signaling)) + printf ("0x%s: OK\n", buf); + else + { + printf ("0x%s: got %s, expected %s\n", buf, + signaling ? "SIGNALING" : "NOT SIGNALING", + classes[inputs[i].class]); + ret |= 1; + } + } + return ret; +} + +int +do_test (void) +{ + int ret = 0; + + initialize (); + + ret |= test_fpclassify (); + ret |= test_isinf (); + ret |= test_isnan (); + ret |= test_issignaling (); + + return ret; +} + +#include