From patchwork Tue Mar 13 18:27:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 26301 Received: (qmail 64661 invoked by alias); 13 Mar 2018 18:27:44 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 64650 invoked by uid 89); 13 Mar 2018 18:27:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=GLIBC X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH v3 1/3] Cleanup __ieee754_sqrt(f/l) Date: Tue, 13 Mar 2018 18:27:37 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB1718; 7:Sk/lw9fCIuyH//7Ds08YeGQQYisqq+7W32kesa+i1zElSoO63ifh7GT6G0M6VIMxyDd7GlU+W67gOLRHizKjqTSGhYCN3s9LC0aK71RtcxseFlY0uMs8/jadDiXjrJ0GpwBKkz/nDZgktvwLMAaPV/DwX4CXjs2Muxu1cEDuRI15BppdER0jUUxSyRUnn38EYMmHPMJMOBc+nmM6ssQs+IZhiN8PZTjnqIdT/bJFmq1zJWjBvaQXjcjc5pHPO1bd x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 7ac10148-d848-45ee-1734-08d589101914 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(2017052603328)(7153060)(7193020); SRVR:DB6PR0801MB1718; x-ms-traffictypediagnostic: DB6PR0801MB1718: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(250305191791016)(180628864354917)(22074186197030); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231221)(944501244)(52105095)(6055026)(6041310)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:DB6PR0801MB1718; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB1718; x-forefront-prvs: 0610D16BBE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(376002)(346002)(39380400002)(366004)(39860400002)(54534003)(377424004)(189003)(199004)(26005)(316002)(59450400001)(4326008)(102836004)(2900100001)(105586002)(33656002)(478600001)(74316002)(6506007)(81156014)(8676002)(2351001)(72206003)(5640700003)(6436002)(305945005)(53936002)(7736002)(106356001)(66066001)(14454004)(68736007)(6116002)(55016002)(3280700002)(9686003)(5660300001)(6306002)(575784001)(86362001)(3846002)(97736004)(99286004)(25786009)(7696005)(6916009)(8936002)(2906002)(3660700001)(5250100002)(2501003)(81166006); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB1718; H:DB6PR0801MB2053.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: esOIOtA5IDiugJZ1VcHR34lggrR423ohLwKPtTwsgJMpbXfhekJDkyAWak9C8F32URCVXpROpaHRnUq+wRZtpIVEeXop6d13CpkBxVvO0xhxHqkSY3cIx0by1/+QwVDPyi1JALDeartojYeMqZKcUupU7jehwOK/SD4Ro9tCIVpD6JBq/EM8AbCXKxGjRCHRxjG/DSs6ivskDr8Ftp2Gj1Xol4jeRsG2dpygSbKVz4FM9yLCdmJ9S4punNtipPVBaSh57JgbAdoxVuirwtY5tfF/GUpSrrPGhbHLvMsC3cpmdQbq50JuZZqkxcrmoHyliTwni4OkGDy5zXWket+8PQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ac10148-d848-45ee-1734-08d589101914 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Mar 2018 18:27:37.4928 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1718 This patch series cleans up the many uses of __ieee754_sqrt(f/l) in GLIBC. The goal is to enable GCC to do the inlining, and if this fails call the __ieee754_sqrt function. This is done by internally declaring sqrt with asm redirects. The compat symbols and sqrt wrappers need to disable the redirect. The redirect is also disabled if there are already redirects defined when using -ffinite-math-only. The benchtests still use the libc internal headers (which is incorrect), so update sqrt-inputs to use the external math.h so there is no redirection. All math functions (but not math tests, non-library code and libnldbl) are built with -fno-math-errno which means GCC will typically inline sqrt as a single instruction. This means targets are no longer forced to add a special inline for sqrt. Tested using buildmanyglibc (13 most relevant variants since it keeps running out of diskspace...) ChangeLog: 2018-03-13 Wilco Dijkstra * include/math.h (sqrt): Declare with asm redirect. (sqrtf): Likewise. (sqrtl): Likewise. * benchtests/sqrt-inputs: Use correct math/math.h include. * Makeconfig: Add -fno-math-errno for libc/libm, but build testsuite, nonlib and libnldbl with -fmath-errno. * math/w_sqrt_compat.c: Define NO_MATH_REDIRECT. * math/w_sqrt_template.c: Likewise. * math/w_sqrtf_compat.c: Likewise. * math/w_sqrtl_compat.c: Likewise. * sysdeps/generic/math-type-macros-float128.h: Remove math.h and complex.h. * sysdeps/i386/fpu/w_sqrt.c: Likewise. * sysdeps/i386/fpu/w_sqrt_compat.c: Likewise. diff --git a/Makeconfig b/Makeconfig index 86a71e580213f6e5de6e619d9f3370f4365b4ae2..1afe86475c10ea208ed88b9b137cc7863510929f 100644 --- a/Makeconfig +++ b/Makeconfig @@ -831,6 +831,9 @@ endif # disable any optimization that assume default rounding mode. +math-flags = -frounding-math +# Build libc/libm using -fno-math-errno, but run testsuite with -fmath-errno. ++extra-math-flags = $(if $(filter libnldbl nonlib testsuite,$(in-module)),-fmath-errno,-fno-math-errno) + # We might want to compile with some stack-protection flag. ifneq ($(stack-protector),) +stack-protector=$(stack-protector) @@ -966,6 +969,7 @@ endif override CFLAGS = -std=gnu11 -fgnu89-inline $(config-extra-cflags) \ $(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \ + $(+extra-math-flags) \ $(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$( 0) +# ifndef NO_MATH_REDIRECT +/* Declare sqrt for use within GLIBC. Sqrt will typically inline into a + single instruction. Use an asm to avoid use of PLTs if it doesn't. */ +float (sqrtf) (float) asm ("__ieee754_sqrtf"); +double (sqrt) (double) asm ("__ieee754_sqrt"); +# ifndef __NO_LONG_DOUBLE_MATH +long double (sqrtl) (long double) asm ("__ieee754_sqrtl"); +# endif +# if __HAVE_DISTINCT_FLOAT128 > 0 +_Float128 (sqrtf128) (_Float128) asm ("__ieee754_sqrtf128"); +# endif +# endif +# endif + #endif #endif diff --git a/math/w_sqrt_compat.c b/math/w_sqrt_compat.c index 7884d146331d7c43c79e1957e3ba4f2dab608ead..e76a8079aa0a2dd4dc09aba48b6a82aaddd1a584 100644 --- a/math/w_sqrt_compat.c +++ b/math/w_sqrt_compat.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#define NO_MATH_REDIRECT #include #include #include diff --git a/math/w_sqrt_template.c b/math/w_sqrt_template.c index 52a21c0bf1cd7bdab164356635ffa5f10973b633..9c6ac75956ca8abf9448d631fd286b5e2d1deb73 100644 --- a/math/w_sqrt_template.c +++ b/math/w_sqrt_template.c @@ -21,6 +21,7 @@ for each floating-point type. */ #if __USE_WRAPPER_TEMPLATE +# define NO_MATH_REDIRECT # include # include # include diff --git a/math/w_sqrtf_compat.c b/math/w_sqrtf_compat.c index 824ce0ed4658210b75e38953ee39d3dcd0bbb3f7..cad9b4ad77f1707af6c1df5ada82b07537d79dfa 100644 --- a/math/w_sqrtf_compat.c +++ b/math/w_sqrtf_compat.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#define NO_MATH_REDIRECT #include #include #include diff --git a/math/w_sqrtl_compat.c b/math/w_sqrtl_compat.c index 56627a615dce25aae893f9d84292922a6e452b3f..16dda403b77144667e3f76b633f6f9165c8a38d3 100644 --- a/math/w_sqrtl_compat.c +++ b/math/w_sqrtl_compat.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#define NO_MATH_REDIRECT #include #include #include diff --git a/sysdeps/generic/math-type-macros-float128.h b/sysdeps/generic/math-type-macros-float128.h index 605996e0ba73f3ad1e421f516396442b2c2b1e25..485c13bb88a1995c69d62e11ea819d1323dd938b 100644 --- a/sysdeps/generic/math-type-macros-float128.h +++ b/sysdeps/generic/math-type-macros-float128.h @@ -19,9 +19,6 @@ #ifndef _MATH_TYPE_MACROS_FLOAT128 #define _MATH_TYPE_MACROS_FLOAT128 -#include -#include - #define M_LIT(c) __f128 (c) #define M_PFX FLT128 #define M_SUF(c) c ## f128 diff --git a/sysdeps/i386/fpu/w_sqrt.c b/sysdeps/i386/fpu/w_sqrt.c index d37a5d55bf439cebdff05f05dd66f910d6d48c18..8bef04e68a7be3d21d89e6eb41dcfa2561f3f6a5 100644 --- a/sysdeps/i386/fpu/w_sqrt.c +++ b/sysdeps/i386/fpu/w_sqrt.c @@ -1,5 +1,6 @@ /* The inline __ieee754_sqrt is not correctly rounding; it's OK for most internal uses in glibc, but not for sqrt itself. */ +#define NO_MATH_REDIRECT #define __ieee754_sqrt __avoid_ieee754_sqrt #include #include diff --git a/sysdeps/i386/fpu/w_sqrt_compat.c b/sysdeps/i386/fpu/w_sqrt_compat.c index ddd36d0964c2945579bc59b02f127af88384acca..dd485f4b88c7f5348abaab81a1308aeadc9594ec 100644 --- a/sysdeps/i386/fpu/w_sqrt_compat.c +++ b/sysdeps/i386/fpu/w_sqrt_compat.c @@ -1,5 +1,6 @@ /* The inline __ieee754_sqrt is not correctly rounding; it's OK for most internal uses in glibc, but not for sqrt itself. */ +#define NO_MATH_REDIRECT #define __ieee754_sqrt __avoid_ieee754_sqrt #include #include