From patchwork Thu Feb 1 20:55:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 25749 Received: (qmail 105487 invoked by alias); 1 Feb 2018 20:55:41 -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 105464 invoked by uid 89); 1 Feb 2018 20:55:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=nios X-HELO: relay1.mentorg.com Date: Thu, 1 Feb 2018 20:55:32 +0000 From: Joseph Myers To: Subject: Move fenv.h override inline functions to generic math_private.h [committed] Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) The tile version of math_private.h defines some inline functions for fenv.h functions, to optimize away internal calls to these functions that do nothing given no support for floating-point exceptions and rounding modes. (Some functions may have error cases for invalid arguments, but those aren't applicable to the internal calls from within glibc.) Other configurations lacking support for exceptions and rounding modes lack such inline functions. This patch moves them to the generic math_private.h, appropriately conditioned, so that all such configurations can benefit from the. include/fenv.h is made to check whether there are any non-default rounding modes; that needs to be done there, rather than later, because get-rounding-mode.h defines values for otherwise unsupported FE_* rounding modes. It also gives an error for FE_TONEAREST undefined, a case that already did not work for building the glibc testsuite; the convention has by now been established that all architectures need to provide a version of bits/fenv.h that at least defines FE_TONEAREST. Tested with build-many-glibcs.py. As expected, installed stripped shared libraries are unchanged for tile and for architectures supporting exceptions and rounding modes, but changed for non-tile architectures not supporting exceptions and rounding modes that previously lacked this optimization (e.g. Nios II libm.so is about 1kB smaller). The optimization is not in fact complete (does not cover feholdexcept / __feholdexcept, so a few calls to those remain unnecessarily within libm even after this patch), but that can be dealt with separately. Committed. 2018-02-01 Joseph Myers * include/fenv.h [!_ISOMAC && !FE_TONEAREST]: Give #error. [!_ISOMAC] (FE_HAVE_ROUNDING_MODES): New macro. * sysdeps/generic/math_private.h [!FE_HAVE_ROUNDING_MODES && FE_ALL_EXCEPT == 0] (fegetenv): New inline function. [!FE_HAVE_ROUNDING_MODES && FE_ALL_EXCEPT == 0] (__fegetenv): Likewise. [!FE_HAVE_ROUNDING_MODES && FE_ALL_EXCEPT == 0] (fesetenv): Likewise. [!FE_HAVE_ROUNDING_MODES && FE_ALL_EXCEPT == 0] (__fesetenv): Likewise. [!FE_HAVE_ROUNDING_MODES && FE_ALL_EXCEPT == 0] (feupdateenv): Likewise. [!FE_HAVE_ROUNDING_MODES && FE_ALL_EXCEPT == 0] (__feupdateenv): Likewise. [!FE_HAVE_ROUNDING_MODES] (fegetround): Likewise. [!FE_HAVE_ROUNDING_MODES] (__fegetround): Likewise. [!FE_HAVE_ROUNDING_MODES] (fesetround): Likewise. [!FE_HAVE_ROUNDING_MODES] (__fesetround): Likewise. * sysdeps/tile/math_private.h (fegetenv): Remove inline function. (__fegetenv): Likewise. (fesetenv): Likewise. (__fesetenv): Likewise. (feupdateenv): Likewise. (__feupdateenv): Likewise. (fegetround): Likewise. (__fegetround): Likewise. (fesetround): Likewise. (__fesetround): Likewise. diff --git a/include/fenv.h b/include/fenv.h index de4d46f..76679e1 100644 --- a/include/fenv.h +++ b/include/fenv.h @@ -42,6 +42,21 @@ struct rm_ctx fenv_t env; bool updated_status; }; + +/* Track whether rounding mode macros were defined, since + get-rounding-mode.h may define default versions if they weren't. + FE_TONEAREST must always be defined (even if no changes of rounding + mode are supported, glibc requires it to be defined to represent + the default rounding mode). */ +# ifndef FE_TONEAREST +# error "FE_TONEAREST not defined" +# endif +# if defined FE_DOWNWARD || defined FE_TOWARDZERO || defined FE_UPWARD +# define FE_HAVE_ROUNDING_MODES 1 +# else +# define FE_HAVE_ROUNDING_MODES 0 +# endif + #endif #endif diff --git a/sysdeps/generic/math_private.h b/sysdeps/generic/math_private.h index acfbd9b..f93cf69 100644 --- a/sysdeps/generic/math_private.h +++ b/sysdeps/generic/math_private.h @@ -654,4 +654,72 @@ libc_feresetround_noex_ctx (struct rm_ctx *ctx) # define __feraiseexcept(excepts) ((void) 0) #endif +/* Similarly, most functions have trivial implementations in + the absence of support for floating-point exceptions and rounding + modes. */ + +#if !FE_HAVE_ROUNDING_MODES +# if FE_ALL_EXCEPT == 0 +extern inline int +fegetenv (fenv_t *__e) +{ + return 0; +} + +extern inline int +__fegetenv (fenv_t *__e) +{ + return 0; +} + +extern inline int +fesetenv (const fenv_t *__e) +{ + return 0; +} + +extern inline int +__fesetenv (const fenv_t *__e) +{ + return 0; +} + +extern inline int +feupdateenv (const fenv_t *__e) +{ + return 0; +} + +extern inline int +__feupdateenv (const fenv_t *__e) +{ + return 0; +} +# endif + +extern inline int +fegetround (void) +{ + return FE_TONEAREST; +} + +extern inline int +__fegetround (void) +{ + return FE_TONEAREST; +} + +extern inline int +fesetround (int __d) +{ + return 0; +} + +extern inline int +__fesetround (int __d) +{ + return 0; +} +#endif + #endif /* _MATH_PRIVATE_H_ */ diff --git a/sysdeps/tile/math_private.h b/sysdeps/tile/math_private.h index 6dc43f4..32b549f 100644 --- a/sysdeps/tile/math_private.h +++ b/sysdeps/tile/math_private.h @@ -15,9 +15,7 @@ success in every case. The overrides for libc_ functions must happen before we include - the generic math_private.h, and the overrides for regular - functions must happen afterwards, to avoid clashing with - the declarations of those functions. */ + the generic math_private.h. */ #define libc_fesetround(rnd) ({ 0; }) #define libc_fetestexcept(exc) ({ 0; }) @@ -26,15 +24,4 @@ #include_next -extern inline int fegetenv (fenv_t *__e) { return 0; } -extern inline int __fegetenv (fenv_t *__e) { return 0; } -extern inline int fesetenv (const fenv_t *__e) { return 0; } -extern inline int __fesetenv (const fenv_t *__e) { return 0; } -extern inline int feupdateenv (const fenv_t *__e) { return 0; } -extern inline int __feupdateenv (const fenv_t *__e) { return 0; } -extern inline int fegetround (void) { return FE_TONEAREST; } -extern inline int __fegetround (void) { return FE_TONEAREST; } -extern inline int fesetround (int __d) { return 0; } -extern inline int __fesetround (int __d) { return 0; } - #endif