From patchwork Tue Apr 5 17:32:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 52647 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 307A23857C41 for ; Tue, 5 Apr 2022 17:32:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 307A23857C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649179959; bh=lagMs/b3oCwS8Z/ZZBu8nyBDRF5ZQorj+V319gGcjlo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QcDuJS+CqE+jKRy5NofrxzXHi7/aQzLsVbIwJ/uLl959VJJJc6M+WvehKBPwCW6zU iWiAYhjqpd06FI0nJ5yjhReybrGkojKGCTXKairq5p7hlLaKLe6fy697kX3qpCQmqy dsyPF5sDy+fQnQq7VdGvu89wBbuGRcVMoxQOVpw8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by sourceware.org (Postfix) with ESMTPS id CEDC63858C50 for ; Tue, 5 Apr 2022 17:32:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CEDC63858C50 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-d39f741ba0so73553fac.13 for ; Tue, 05 Apr 2022 10:32:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=lagMs/b3oCwS8Z/ZZBu8nyBDRF5ZQorj+V319gGcjlo=; b=FXWemoQ9X30rtbIkuMjE1RGx5SON9u+Vj7xwE2XK5a1rifan64tpkVsys10Mx7Mt0P mBSD43z+0W/BBbVtWSi62EBgxTP/OQQgnXcatm1JDMhmIkiYc0cn9HINJRqY3fso97lR a9amoT91SA4APmiHc8NtMM97rFX6e9gOdTRQOpLrqBcsWMBDwQafSWqxAvMlFgxWB+fE Ua8BJhQQWHDTgNoSB//+w3m54P6MLdMekoPbq82q0VsSqciFEG8wYc7zy6CB9P0JJRw7 yv0PZdn6RmqeWynYmRAUwekAuJvDj6d4uBHQ1NSr4HqfsrefuY3j36qg50CLxC25SBjS aCSA== X-Gm-Message-State: AOAM533l71uaSQSL1IIVvL5tiOnwJD2kNl5hK6whKbB+mOUkUlkh399J p1bpoBp6fuX9bc+cduMIktg1hNRjty8A/A== X-Google-Smtp-Source: ABdhPJwTjw9tkdtuahwE0VUN8xRVNqwdIUNZMFltz72UmqPfGMLqNuhMJdCuOPuRVsv94XgeHZZWMw== X-Received: by 2002:a05:6870:898c:b0:e2:165c:bfb2 with SMTP id f12-20020a056870898c00b000e2165cbfb2mr2199133oaq.204.1649179935533; Tue, 05 Apr 2022 10:32:15 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:a6c0:26f4:3c2a:73ae:3e2]) by smtp.gmail.com with ESMTPSA id f50-20020a9d03b5000000b005c959dd643csm5984396otf.3.2022.04.05.10.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 10:32:15 -0700 (PDT) To: libc-alpha@sourceware.org, Joseph Myers Subject: [PATCH v2] math: Add math-use-builtins-fabs (BZ#29027) Date: Tue, 5 Apr 2022 14:32:10 -0300 Message-Id: <20220405173210.3028668-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Both float, double, and _Float128 are assumed to be supported (float and double already only uses builtins). Only long double is parametrized due GCC bug 29253 which prevents its usage on powerpc. It allows to remove i686, ia64, x86_64, powerpc, and sparc arch specific implementation. On ia64 it also fixes the sNAN handling: math/test-float64x-fabs math/test-ldouble-fabs Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, powerpc64-linux-gnu, sparc64-linux-gnu, and ia64-linux-gnu. --- v2: Assume _Float128 support and handle GCC bug 29253 on powerpc. --- sysdeps/generic/math-use-builtins-fabs.h | 3 + sysdeps/generic/math-use-builtins.h | 1 + sysdeps/i386/fpu/s_fabsl.S | 10 --- sysdeps/ia64/fpu/s_fabsl.S | 82 ------------------- sysdeps/ieee754/ldbl-128/s_fabsl.c | 9 +- sysdeps/ieee754/ldbl-128ibm/s_fabsl.c | 5 ++ .../s_fabsl.S => ieee754/ldbl-96/s_fabsl.c} | 18 ++-- sysdeps/powerpc/fpu/math-use-builtins-fabs.h | 8 ++ sysdeps/powerpc/powerpc32/fpu/s_fabsl.S | 52 ------------ sysdeps/powerpc/powerpc64/fpu/s_fabsl.S | 34 -------- sysdeps/sparc/sparc32/fpu/s_fabsl.c | 9 -- sysdeps/sparc/sparc64/fpu/s_fabsl.c | 7 -- 12 files changed, 30 insertions(+), 208 deletions(-) create mode 100644 sysdeps/generic/math-use-builtins-fabs.h delete mode 100644 sysdeps/i386/fpu/s_fabsl.S delete mode 100644 sysdeps/ia64/fpu/s_fabsl.S rename sysdeps/{x86_64/fpu/s_fabsl.S => ieee754/ldbl-96/s_fabsl.c} (78%) create mode 100644 sysdeps/powerpc/fpu/math-use-builtins-fabs.h delete mode 100644 sysdeps/powerpc/powerpc32/fpu/s_fabsl.S delete mode 100644 sysdeps/powerpc/powerpc64/fpu/s_fabsl.S delete mode 100644 sysdeps/sparc/sparc32/fpu/s_fabsl.c delete mode 100644 sysdeps/sparc/sparc64/fpu/s_fabsl.c diff --git a/sysdeps/generic/math-use-builtins-fabs.h b/sysdeps/generic/math-use-builtins-fabs.h new file mode 100644 index 0000000000..ab9201c721 --- /dev/null +++ b/sysdeps/generic/math-use-builtins-fabs.h @@ -0,0 +1,3 @@ +/* Generic implementations already assume builtin support for + float, double, and _Float128. */ +#define USE_FABSL_BUILTIN 0 diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h index 3ec15e59d4..6bd424d900 100644 --- a/sysdeps/generic/math-use-builtins.h +++ b/sysdeps/generic/math-use-builtins.h @@ -36,5 +36,6 @@ #include #include #include +#include #endif /* MATH_USE_BUILTINS_H */ diff --git a/sysdeps/i386/fpu/s_fabsl.S b/sysdeps/i386/fpu/s_fabsl.S deleted file mode 100644 index 6642ed4151..0000000000 --- a/sysdeps/i386/fpu/s_fabsl.S +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - - .text -ENTRY(__fabsl) - fldt 4(%esp) - fabs - ret -END(__fabsl) -libm_alias_ldouble (__fabs, fabs) diff --git a/sysdeps/ia64/fpu/s_fabsl.S b/sysdeps/ia64/fpu/s_fabsl.S deleted file mode 100644 index 07838b1057..0000000000 --- a/sysdeps/ia64/fpu/s_fabsl.S +++ /dev/null @@ -1,82 +0,0 @@ -.file "fabsl.s" - - -// Copyright (c) 2000 - 2003, Intel Corporation -// All rights reserved. -// -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// * The name of Intel Corporation may not be used to endorse or promote -// products derived from this software without specific prior written -// permission. - -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Intel Corporation is the author of this code, and requests that all -// problem reports or change requests be submitted to it directly at -// http://www.intel.com/software/products/opensource/libraries/num.htm. -// -// History -//============================================================== -// 02/02/00 Initial version -// 02/07/02 Added __libm_fabsl entry point to test in case compiler inlines -// 05/20/02 Cleaned up namespace and sf0 syntax -// 02/10/03 Reordered header: .section, .global, .proc, .align -// -// API -//============================================================== -// long double fabsl (long double x) -// -// Overview of operation -//============================================================== -// returns absolute value of x - -// floating-point registers used: 1 -// f8, input - -.section .text -.global __libm_fabsl# - -.proc __libm_fabsl# -__libm_fabsl: -.endp __libm_fabsl# - -GLOBAL_IEEE754_ENTRY(fabsl) - -// set invalid or denormal flags and take fault if -// necessary - -{ .mfi - nop.m 999 - fcmp.eq.unc.s0 p6,p7 = f8,f1 - nop.i 999 ;; -} - -{ .mfb - nop.m 999 - fmerge.s f8 = f0,f8 - br.ret.sptk b0 ;; -} - -GLOBAL_IEEE754_END(fabsl) -libm_alias_ldouble_other (__fabs, fabs) diff --git a/sysdeps/ieee754/ldbl-128/s_fabsl.c b/sysdeps/ieee754/ldbl-128/s_fabsl.c index 7e08980252..d2603418c2 100644 --- a/sysdeps/ieee754/ldbl-128/s_fabsl.c +++ b/sysdeps/ieee754/ldbl-128/s_fabsl.c @@ -23,12 +23,11 @@ static char rcsid[] = "$NetBSD: $"; #include #include #include +#include -_Float128 __fabsl(_Float128 x) +_Float128 +__fabsl (_Float128 x) { - uint64_t hx; - GET_LDOUBLE_MSW64(hx,x); - SET_LDOUBLE_MSW64(x,hx&0x7fffffffffffffffLL); - return x; + return __builtin_fabsf128 (x); } libm_alias_ldouble (__fabs, fabs) diff --git a/sysdeps/ieee754/ldbl-128ibm/s_fabsl.c b/sysdeps/ieee754/ldbl-128ibm/s_fabsl.c index cba7de6660..7f26315e84 100644 --- a/sysdeps/ieee754/ldbl-128ibm/s_fabsl.c +++ b/sysdeps/ieee754/ldbl-128ibm/s_fabsl.c @@ -24,9 +24,13 @@ static char rcsid[] = "$NetBSD: $"; #include #include #include +#include long double __fabsl(long double x) { +#if USE_FABSL_BUILTIN + return __builtin_fabsl (x); +#else uint64_t hx, lx; double xhi, xlo; @@ -39,5 +43,6 @@ long double __fabsl(long double x) INSERT_WORDS64 (xlo, lx); x = ldbl_pack (xhi, xlo); return x; +#endif } long_double_symbol (libm, __fabsl, fabsl); diff --git a/sysdeps/x86_64/fpu/s_fabsl.S b/sysdeps/ieee754/ldbl-96/s_fabsl.c similarity index 78% rename from sysdeps/x86_64/fpu/s_fabsl.S rename to sysdeps/ieee754/ldbl-96/s_fabsl.c index cfcf01e027..0eceb0c997 100644 --- a/sysdeps/x86_64/fpu/s_fabsl.S +++ b/sysdeps/ieee754/ldbl-96/s_fabsl.c @@ -1,5 +1,5 @@ -/* Absolute value of floating point number. - Copyright (C) 2002-2022 Free Software Foundation, Inc. +/* Absolute value of floating-point number. + Copyright (C) 2022 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 @@ -16,13 +16,13 @@ License along with the GNU C Library; if not, see . */ -#include +#include #include +#include - .text -ENTRY(__fabsl) - fldt 8(%rsp) - fabs - ret -END(__fabsl) +long double +__fabsl (long double x) +{ + return __builtin_fabsl (x); +} libm_alias_ldouble (__fabs, fabs) diff --git a/sysdeps/powerpc/fpu/math-use-builtins-fabs.h b/sysdeps/powerpc/fpu/math-use-builtins-fabs.h new file mode 100644 index 0000000000..8976d0b956 --- /dev/null +++ b/sysdeps/powerpc/fpu/math-use-builtins-fabs.h @@ -0,0 +1,8 @@ +/* Generic implementations already assume builtin support for + float, double, and _Float128 . */ + +/* We can't enable it for long double due GCC Bugzilla Bug 29253 + "expand_abs wrong default code for floating point" where it can + cause spurious "invalid" exceptions from comparisons with NaN in + the code sequence generated. */ +#define USE_FABSL_BUILTIN 0 diff --git a/sysdeps/powerpc/powerpc32/fpu/s_fabsl.S b/sysdeps/powerpc/powerpc32/fpu/s_fabsl.S deleted file mode 100644 index 8bdcdc8cfb..0000000000 --- a/sysdeps/powerpc/powerpc32/fpu/s_fabsl.S +++ /dev/null @@ -1,52 +0,0 @@ -/* Copy a sign bit between floating-point values. - IBM extended format long double version. - Copyright (C) 2004-2022 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 - -ENTRY(__fabsl) -/* long double [f1,f2] fabs (long double [f1,f2] x); - fabs(x,y) returns a value with the magnitude of x and - with the sign bit of y. */ -#ifdef _ARCH_PPCGR - /* fsel available. */ - fmr fp0,fp1 -#else - /* Use integer operations to test sign of high part to avoid - exceptions on sNaNs. */ - stwu r1,-16(r1) - cfi_adjust_cfa_offset (16) - stfd fp1,8(r1) -#endif - fabs fp1,fp1 -#ifdef _ARCH_PPCGR - fneg fp3,fp2 - fsel fp2,fp0,fp2,fp3 -#else - lwz r3,8+HIWORD(r1) - cmpwi cr6,r3,0 - addi r1,r1,16 - cfi_adjust_cfa_offset (-16) - bgelr cr6 - fneg fp2,fp2 -#endif - blr -END (__fabsl) - -long_double_symbol (libm, __fabsl, fabsl) diff --git a/sysdeps/powerpc/powerpc64/fpu/s_fabsl.S b/sysdeps/powerpc/powerpc64/fpu/s_fabsl.S deleted file mode 100644 index ec796a1cd3..0000000000 --- a/sysdeps/powerpc/powerpc64/fpu/s_fabsl.S +++ /dev/null @@ -1,34 +0,0 @@ -/* Copy a sign bit between floating-point values. - IBM extended format long double version. - Copyright (C) 2004-2022 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 - -ENTRY_TOCLESS (__fabsl) -/* long double [f1,f2] fabs (long double [f1,f2] x); - fabs(x,y) returns a value with the magnitude of x and - with the sign bit of y. */ - fmr fp0,fp1 - fabs fp1,fp1 - fneg fp3,fp2 - fsel fp2,fp0,fp2,fp3 - blr -END (__fabsl) - -long_double_symbol (libm, __fabsl, fabsl) diff --git a/sysdeps/sparc/sparc32/fpu/s_fabsl.c b/sysdeps/sparc/sparc32/fpu/s_fabsl.c deleted file mode 100644 index 411a2e1511..0000000000 --- a/sysdeps/sparc/sparc32/fpu/s_fabsl.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include - -long double __fabsl (long double x) -{ - return __builtin_fabsl (x); -} -libm_alias_ldouble (__fabs, fabs) diff --git a/sysdeps/sparc/sparc64/fpu/s_fabsl.c b/sysdeps/sparc/sparc64/fpu/s_fabsl.c deleted file mode 100644 index 72e1c51340..0000000000 --- a/sysdeps/sparc/sparc64/fpu/s_fabsl.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -long double __fabsl (long double x) -{ - return __builtin_fabsl (x); -} -libm_alias_ldouble (__fabs, fabs)