From patchwork Wed Dec 20 17:08:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 25055 Received: (qmail 124959 invoked by alias); 20 Dec 2017 17:08:12 -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 124945 invoked by uid 89); 20 Dec 2017 17:08:12 -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=9666 X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH v2 1/3] Cleanup __ieee754_sqrt(f/l) Date: Wed, 20 Dec 2017 17:08:01 +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; DB6PR0801MB2053; 6:OS9zFvryILSIh9Ai2XsuiMx2OCPxijITb3VykvBEW349jJS4E5DBfcVf3Ld7WILqX80rIApLWeELcZumNkTQWqXD+Wt88/ccCdCJJPdACx+AL9AP9WQ4IjvhO1OhEdozmr6xv8XZO62zV7Xlr8SoufTQWCuEKe1MOlTavZTyvn7KSWTBphoph3lP3Bk/1h8qzL72qrWTKd4uh5aBpKj42TL7RZEySrq4LEc8qbLBgeLqUJ/JdocfzHOm8LFVwEY44t/VAfgBe8rs/i5hr6ENbgBI0AYAqAzWmb7ZrEIRuIuScsLnqL/tnwWDf39kX+FJ7iq47YFAmxvrE3TcNP7YBSXj4XdLLr2P1mN7CZ1UX2M=; 5:jxu1fLptc8tyzqZFmiN06nA5xkC/5U9q0AGRmtRTHBl8sVynSye/FgJ4SiShx+bAeSwDfWJZdUekED+tFwRsdVxRP/AGZmmDjh2hFqBb2E4ZDznetT7NmprBR/Wb3SvWQ7PgxWokhUxbNNIs9uBnyZAs06Jvkz5eC4jlQHNcjRM=; 24:c5axvxo5yDA1iOpxwwh5T3ipjmurdeUmoMBEyimpEqoM12eNlgZu16/RsttYA1zX/PsxJYDdfRj4d+w0VZ1R7Z6m4s1hf53uO9t18Gokyr8=; 7:wf3t64pmrAJ/ZFgmg+odC5JwU0xbGaTz8lzs5bT4GbhIFazytIJfMFMPBGVSVj70DyrcWQuBlevGa7UnfVB2CkMI6WIA0381X72H5VmUfexBFNTttZe+WrCEoEPtogQybX+06ncsUeTpJC72WmwMTTM48IhzBAXCGyWsSK/9nYPh4U5wISieLe5Rdt8KLzk5tvN9Q0UYeL2CZiBWPwvjWn6cwsGttKq/aFhG6+D9Ezpeezb1ONYbM3de+AIb8k+k x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 8f86a875-a036-4115-3aee-08d547cc3a54 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7153060); SRVR:DB6PR0801MB2053; x-ms-traffictypediagnostic: DB6PR0801MB2053: 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:(6040470)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231023)(6055026)(6041268)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DB6PR0801MB2053; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DB6PR0801MB2053; x-forefront-prvs: 0527DFA348 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(366004)(376002)(396003)(39380400002)(346002)(39860400002)(377424004)(54534003)(199004)(189003)(68736007)(3660700001)(305945005)(7736002)(3280700002)(33656002)(2906002)(8936002)(6436002)(74316002)(99286004)(6306002)(8676002)(5640700003)(3846002)(106356001)(81156014)(105586002)(6916009)(102836003)(6116002)(9686003)(5660300001)(25786009)(7696005)(4326008)(316002)(86362001)(66066001)(81166006)(575784001)(2351001)(5250100002)(53936002)(55016002)(2900100001)(6506007)(97736004)(4001150100001)(14454004)(59450400001)(478600001)(2501003)(72206003)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB2053; H:DB6PR0801MB2053.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f86a875-a036-4115-3aee-08d547cc3a54 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Dec 2017 17:08:01.9511 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2053 Here is the updated version of the sqrt cleanup. Makefile magic is now fixed to do a single selection at the top level (I couldn't add this to math-flags as somehow that doesn't work properly). 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. All math functions (but not math tests) 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. Build & test OK on AArch64. ChangeLog: 2017-12-20 Wilco Dijkstra * include/math.h (sqrt): Declare with asm redirect. (sqrtf): Likewise. (sqrtl): Likewise. * Makeconfig: Add -fno-math-errno for libc/libm, but build tests with -fmath-errno. * math/w_sqrt_compat.c: Define NO_SQRT_REDIRECT. * math/w_sqrt_template.c: Likewise. * math/w_sqrtf_compat.c: Likewise. * math/w_sqrtl_compat.c: Likewise. diff --git a/Makeconfig b/Makeconfig index 34bed9790fac1fd0be9e16b7fe2fa6f5c479b32b..b9da1c137bc495a2f63064765225dc8878cde306 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 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_SQRT_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 +# endif +# endif + #endif #endif diff --git a/math/w_sqrt_compat.c b/math/w_sqrt_compat.c index 3280d2fbb86af2aeaf6e686fd38579b209c901aa..fe068af9597ffb0f15b32cd454b4c34ba8bc060e 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_SQRT_REDIRECT #include #include #include diff --git a/math/w_sqrt_template.c b/math/w_sqrt_template.c index 5fae302382d10e9b05df2665c9cb05126cd62f02..235c263e60c85422e41bca7c817148b66030438f 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_SQRT_REDIRECT # include # include # include diff --git a/math/w_sqrtf_compat.c b/math/w_sqrtf_compat.c index 6c8c7e3857c7dacf52de6b575a2386095688b5dc..880be0936d9a20f9aa75cf2d66000f0c621f090f 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_SQRT_REDIRECT #include #include #include diff --git a/math/w_sqrtl_compat.c b/math/w_sqrtl_compat.c index 0590f6d155fee27d41bfd42c1dbdf19c381ba1c8..bff77fd31bf2c62394e0d54e6b2e7bc9296226d6 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_SQRT_REDIRECT #include #include #include