From patchwork Wed Mar 13 20:25:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Ellcey X-Patchwork-Id: 31845 Received: (qmail 70269 invoked by alias); 13 Mar 2019 20:25:22 -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 70210 invoked by uid 89); 13 Mar 2019 20:25:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx0b-0016f401.pphosted.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : subject : date : message-id : content-type : mime-version; s=pfpt0818; bh=d2BrNCcgm46Bq8RXm8wt2VyGkLqr9o8SpVDENT70XEA=; b=MihUpfBfrctFzMabpcjKBP+Gn1MHVJgODyt1apfkVhu5s1i/W3bRLypblsYme5LYkH+C R9XHAT8zDamNeBoEOVEq/5pY7RwbXLVxCZrXDCnmWfQqV21hcjbL1isyYnoqIDHp3MBC s1EbFnIZ5I/6FU6NosDDHoOrFFiERKW2zTvjNr52givdtrUjp9loxH6rdYXQUnxTS7er rUE9EIhxItYMiYYwNaWqluTard9yfq/uPAoRIOkv6Nf625++++WryIb6hAOmE0DH6+a4 VGtM1I1GSSNPsNCnYXR5HlLN7nRQfleTxNCq5oRleH2nR5f5xc2y8o9X7VFUpZIDcscn Ew== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d2BrNCcgm46Bq8RXm8wt2VyGkLqr9o8SpVDENT70XEA=; b=ZKY6lBpzOEBxiB8J4kzadxb1BZ4801MLtO6UAw6cPT1tPRpBI3eAWJ/ZIjvHViVDQd+kaNjW0CLAAV+vkyLO9RvLjUESwWAAprHPdItGndxj8Qm/i0YilIVzK4GiGBJ+K7Jcsg6DVBuILMdbQ0gp/ac6kujGEwcQd9VEpjiw5kM= From: Steve Ellcey To: "libc-alpha@sourceware.org" Subject: RFC: Patch to avoid using _finite calls in some cases (including in libmvec names) Date: Wed, 13 Mar 2019 20:25:01 +0000 Message-ID: x-ms-exchange-purlcount: 2 received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED This RFC is related to this glibc patch: https://sourceware.org/ml/libc-alpha/2019-03/msg00106.html and to this GCC discussion: https://gcc.gnu.org/ml/gcc-patches/2019-03/msg00532.html The basic issue is that if you call a function like 'expf' with GCC -Ofast, the glibc header file 'math-finite.h' gives it the assembler name of __expf_finite. Then, if you have a vectorized version of this inlibmvec, GCC could wind up calling something like '_ZGVnN4v___expf_finite' instead of '_ZGVnN4v_expf', even though these are the same functionality on Aarch64 and X86. There are a number of ways to handle this: In my patch I just made _ZGVnN4v___expf_finite an alias for _ZGVnN4v_expf and exported both from libmvec.so. Joseph didn't like having the two different names visible as part of the interface between GCC and glibc. On X86 they have libmvec_nonshared.a, the *_finite routines are defined here and they just call the 'normal' functions that are in libmvec.so. I don't like this method because it means you have two calls to get to the libmvec routine. Joseph suggested putting a '__vector_name__' attribute on functions that have libmvec vector version, then we could use that name (expf) instead of the assembler name (__expf_finite) to form the libmvec name. The objection here is that both C and Fortran would have to handle this new attribute and anyone building glibc with a non GCC compiler would also have to add support for the new attribute. Here is another idea that I have and I would like to get opinions on this approach. On Aarch64, expf and expf_finite (and the other exp routines) are aliases for each other and the vector versions would also be aliases, so I would like to change math-finite.h to allow platforms to decide whether or not to use the _finite names in calls. This would affect both the scalar and vector versions and all types (float, double, long double). As Joseph has said in the email from the threads referenced there is really no reason why scalar and vector versions of different types of a function like 'exp (expf, expl, etc) would agree on whether or not they need different versions but in practice I am not sure this will come up. Here is an untested patch to give you an idea of what I would like to do, obviously a real patch would be extend to put the rest of the __MATH_REDIRCALL calls in math-finite.h inside of ifdefs. Comments? Steve Ellcey sellcey@marvell.com 2019-13-03 Steve Ellcey * bits/math-finite-funcs.h: New file. * bits/math-finite.h (exp): Put in ifdef. * math/Makefile: (headers): Add bits/math-finite-funcs.h. * math/math.h: Include bits/math-finite-funcs.h. * sysdeps/aarch64/fpu/bits/math-finite-funcs.h: New file. diff --git a/bits/math-finite-funcs.h b/bits/math-finite-funcs.h index e69de29..1ac64ac 100644 --- a/bits/math-finite-funcs.h +++ b/bits/math-finite-funcs.h @@ -0,0 +1,31 @@ +/* List of functions where the *_finite versions match the normal versions. + Copyright (C) 2011-2019 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 + . */ + +#ifndef _MATH_H +# error "Never use directly; include instead." +#endif + +/* By default we set the names of all the functions in math-finite.h to have + the _finite suffix so that when __FINITE_MATH_ONLY__ is set we call the + _finite version of the routines. On platforms where the normal version and + the _finite version are the same we allow the name to not be changed so that + the call is to the original name. This is done by setting + '__GLIBC_SKIP_MATH_FINITE_'. + + This has the side-affect of changing the name of the vectorized version of + the function if such a function exists. */ diff --git a/bits/math-finite.h b/bits/math-finite.h index 6141c12..b9a652a 100644 --- a/bits/math-finite.h +++ b/bits/math-finite.h @@ -65,7 +65,9 @@ __MATH_REDIRCALL (atanh, , (_Mdouble_)); __MATH_REDIRCALL (cosh, , (_Mdouble_)); /* exp. */ +#ifndef __GLIBC_SKIP_MATH_FINITE_EXP __MATH_REDIRCALL (exp, , (_Mdouble_)); +#endif #if __GLIBC_USE (IEC_60559_FUNCS_EXT) /* exp10. */ diff --git a/math/Makefile b/math/Makefile index cb4eaec..4306289 100644 --- a/math/Makefile +++ b/math/Makefile @@ -25,8 +25,8 @@ include ../Makeconfig headers := math.h bits/mathcalls.h bits/mathinline.h \ fpu_control.h complex.h bits/cmathcalls.h fenv.h \ bits/fenv.h bits/fenvinline.h bits/mathdef.h tgmath.h \ - bits/math-finite.h bits/math-vector.h \ - finclude/math-vector-fortran.h \ + bits/math-finite.h bits/math-finite-funcs.h \ + bits/math-vector.h finclude/math-vector-fortran.h \ bits/libm-simd-decl-stubs.h bits/iscanonical.h \ bits/flt-eval-method.h bits/fp-fast.h bits/fp-logb.h \ bits/long-double.h bits/mathcalls-helper-functions.h \ diff --git a/math/math.h b/math/math.h index ffbc24a..8ac35e6 100644 --- a/math/math.h +++ b/math/math.h @@ -1240,6 +1240,10 @@ iszero (__T __val) # include #endif +/* Get machine-depenedent list of functions that do not need + finite versions. */ +#include + /* Define special entry points to use when the compiler got told to only expect finite results. */ #if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0 diff --git a/sysdeps/aarch64/fpu/bits/math-finite-funcs.h b/sysdeps/aarch64/fpu/bits/math-finite-funcs.h index e69de29..e6e4154 100644 --- a/sysdeps/aarch64/fpu/bits/math-finite-funcs.h +++ b/sysdeps/aarch64/fpu/bits/math-finite-funcs.h @@ -0,0 +1,23 @@ +/* Platform specific list of functions that do not need *_finite versions. + Copyright (C) 2019 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 + . */ + +#ifndef _MATH_H +# error "Never use directly; include instead." +#endif + +#define __GLIBC_SKIP_MATH_FINITE_EXP 1