From patchwork Fri Dec 22 15:23:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 25075 Received: (qmail 21611 invoked by alias); 22 Dec 2017 15:24:00 -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 21594 invoked by uid 89); 22 Dec 2017 15:23:59 -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= X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: Joseph Myers CC: "libc-alpha@sourceware.org" , nd Subject: Re: [PATCH v2 1/3] Cleanup __ieee754_sqrt(f/l) Date: Fri, 22 Dec 2017 15:23:53 +0000 Message-ID: References: , , , In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB2053; 6:HVRUtsWLxnuahTzm36IZq5eKYm4DfliczeB8XQnZ6/ns54q6GRnxWUMXrzpHC4mkm33lSm2OKNKz3wdvt9EP0ZKuniiMie5M5oEnQy4RdqXjdx0eDp81UrF0LFI0/vuV1BqrrS1Fp5ILWtDyaPBHLCTDePTVG1gg6iujKNKWacNMGr19fw23n5pmmzvz+X8FDeal2vRDsyTtL1omLzfY0zdsAz6D5t4vyBWAgZ6c6QUKjiAji+37bDErfmYBJPd6vfxQrnz4kiBdjkz04+AaTds+46RcqwErQ1vPdSA12w5ApPIkXaMqxx5pZ89qP/wo+U+U8Uv4DmXGNI0egsrfT/GGetySV8Nz+MlHt+/N1sQ=; 5:OdbhYesUb7XAYAmpE2J1Lx9kMOql9oFT+eYI05zAOUTOzACHHYQ51+L1WR/NKAkJCruZQGwgW21ZUaoMeS2NZCgT+Vdl12//6WIhSSvuFkku3e1L5MbSl0ae/JSxthq/6oxQJKSbSQHTkeUyTOq1ruHfkU0ya6osTFqwbJFZjhY=; 24:UsAsJMlxcmPSc7HLfAd9DwX3/EmCcWaxO5EjtY2jJIutt4xtdqeedmR1MElDo/23OBV2f7SvhG7xqO5sMAaDnI7fsCKNNf6tyFTUn6uzVao=; 7:tqIK/69dwygaCo+guzSGWsmv+UgiwP0RExKZRrV3XY/b4eDeniLgLu4vcppbbpEVe81dtAZsvMxBjxCHPjTWQzi8pm5c2kVs9DnsY/1OduSyTCWntqDjQjjy9TkIRj+7b91NvOD4hUPaPw1J3tIxN06dxywmarfDb99+jBBecyO+VX0dtbcmIBDcAub/P3cvZFtE2sM7Zoh9T+lGTZb2qlYl7HhR30zyyfyq2imyUb3MMcXkJPanj+GqdWgfa2Cf x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 6e6df7d7-947f-4a43-d76b-08d5495002b8 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(48565401081)(5600026)(4604075)(3008031)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(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)(5005006)(8121501046)(3231023)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041268)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:DB6PR0801MB2053; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:DB6PR0801MB2053; x-forefront-prvs: 05299D545B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39380400002)(346002)(376002)(366004)(39840400004)(396003)(199004)(377424004)(54534003)(189003)(24454002)(66066001)(53936002)(5250100002)(81166006)(575784001)(54906003)(5660300001)(25786009)(4326008)(7696005)(316002)(59450400001)(4001150100001)(102836004)(478600001)(86362001)(72206003)(97736004)(76176011)(6246003)(55016002)(2900100001)(6506007)(14454004)(99286004)(8936002)(2906002)(7736002)(74316002)(93886005)(6436002)(305945005)(3280700002)(3660700001)(68736007)(33656002)(81156014)(6916009)(9686003)(3846002)(105586002)(2950100002)(6116002)(106356001)(6306002)(229853002)(8676002); 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: 6e6df7d7-947f-4a43-d76b-08d5495002b8 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Dec 2017 15:23:53.4047 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2053 Joseph Myers wrote: > float128_private.h isn't an external header.  It includes math.h and other > headers, then redefines symbols from them, and is included before the main > implementation of a float128 function.  Naturally your problem needs > debugging, since of course libm should be exporting sqrtf128.  (And > float128_private.h shouldn't be included at all when the type-generic > wrappers are, so shouldn't have any opportunity to cause trouble with the > automatically generated w_sqrtf128 which is what ought to be defining > sqrtf128 as an alias to __sqrtf128.) Well it seems the issue is all the autogenerated magic templates. It appears they are used to both define simple wrappers as well as complex float128 functions which happen to use sqrt (in the form of M_SQRT). For the former you want to disable the asm redirect, for the latter you must redirect it. Given they are all generated in the same way, it's impossible to do the right thing. So I don't think we can change M_SQRT until the wrapper magic has been removed or at least greatly simplified. Here is the latest version, which adds redirect for float128 but keeps M_SQRT as is - this passes on x86, x64, ppc, aarch64: 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. This means targets are no longer forced to add a special inline for sqrt. All math functions (but not math tests) are built with -fno-math-errno which means GCC will typically inline sqrt as a single instruction. ChangeLog: 2017-12-22 Wilco Dijkstra * math/Makefile: Emit NO_MATH_REDIRECT in wrapper templates. * 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_MATH_REDIRECT. * math/w_sqrt_template.c: Likewise. * math/w_sqrtf_compat.c: Likewise. * math/w_sqrtl_compat.c: Likewise. * sysdeps/i386/fpu/w_sqrt.c: Likewise. * sysdeps/i386/fpu/w_sqrt_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_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/Makefile b/math/Makefile index 8978f2ef963e67acb4e3d252733cdb0e19cf6921..f9b083d8c4049bdfdaaff0a78aa26139ace83bf5 100644 --- a/math/Makefile +++ b/math/Makefile @@ -397,6 +397,7 @@ $(objpfx)gen-libm-templates.stmp: Makefile type=$${type%__*}; \ file=$(objpfx)$${gcall%F*}$${suff}$${gcall#*F}.c; \ ( \ + echo "#define NO_MATH_REDIRECT"; \ echo "#include "; \ echo "#include <$${func}_template.c>"; \ ) > $${file}; \ diff --git a/math/w_sqrt_compat.c b/math/w_sqrt_compat.c index 3280d2fbb86af2aeaf6e686fd38579b209c901aa..1a8db2fdef87e57df2f7dda117ef3ee48581ca1d 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 5fae302382d10e9b05df2665c9cb05126cd62f02..f03f04751a9334fc7cdb8c954fbbcd845ac8670f 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 6c8c7e3857c7dacf52de6b575a2386095688b5dc..fe7418dbdcdbdb571cb1b9743cf9b17eaa5c8cb2 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 0590f6d155fee27d41bfd42c1dbdf19c381ba1c8..3fda9cf991e430f259b9d26f15219181b3e6dcbb 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/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