From patchwork Wed Dec 23 11:56:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 41535 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 BAC4F3892024; Wed, 23 Dec 2020 11:56:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAC4F3892024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608724597; bh=t8oCTFvV1HgrMG1OUglmYQlPFljMlNBQM2WNOCFEQJw=; 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=tMWv8OL1daDHpqZFrqX4KK4IPMdO12Csv7WSJT+vAkroePOIQveFIN2QizC+cC2dl CiS1koAeorh+aKy6Fr6/raNDAaV/sedbI23cLCY/fg3znDR08eCBeCRfhnnU+o+BJd 86qNZoRnhtRa3/iqpz/r7avSaG9TOM/ICTqUniuA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from olivedrab.birch.relay.mailchannels.net (olivedrab.birch.relay.mailchannels.net [23.83.209.135]) by sourceware.org (Postfix) with ESMTPS id 63ADA3892015 for ; Wed, 23 Dec 2020 11:56:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 63ADA3892015 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 66FE01E1F07; Wed, 23 Dec 2020 11:56:33 +0000 (UTC) Received: from pdx1-sub0-mail-a1.g.dreamhost.com (100-100-138-63.trex.outbound.svc.cluster.local [100.100.138.63]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id DB7C21E1A6C; Wed, 23 Dec 2020 11:56:32 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a1.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); Wed, 23 Dec 2020 11:56:33 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Rock-Snatch: 646d6fb704ecc995_1608724593175_3944238564 X-MC-Loop-Signature: 1608724593175:1167196700 X-MC-Ingress-Time: 1608724593174 Received: from pdx1-sub0-mail-a1.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a1.g.dreamhost.com (Postfix) with ESMTP id A69AA7F0A6; Wed, 23 Dec 2020 03:56:32 -0800 (PST) Received: from rhbox.intra.reserved-bit.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-a1.g.dreamhost.com (Postfix) with ESMTPSA id 6747A7F0A0; Wed, 23 Dec 2020 03:56:29 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a1 To: libc-alpha@sourceware.org Subject: [PATCH v2 5/5] x86 long double: Add tests for pseudo normal numbers Date: Wed, 23 Dec 2020 17:26:02 +0530 Message-Id: <20201223115602.3472627-6-siddhesh@sourceware.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201223115602.3472627-1-siddhesh@sourceware.org> References: <20201223115602.3472627-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-9.1 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_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 | 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 + . */ + +#include +#include +#include +#include +#include +#include + +/* 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