diff options
| author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2025-11-10 10:28:56 -0300 |
|---|---|---|
| committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2025-11-17 11:17:07 -0300 |
| commit | 13cfd77bf5679e8a888a63e233fb60529177b278 (patch) | |
| tree | 5a5df83fab6cd1d08f0a225a10a6cd39c2749f31 /include | |
| parent | a0ce8b0779e290596e99ca6d96c301684a2d7cfe (diff) | |
math: Don't redirect inlined builtin math functions
When we want to inline builtin math functions, like truncf, for
extern float truncf (float __x) __attribute__ ((__nothrow__ )) __attribute__ ((__const__));
extern float __truncf (float __x) __attribute__ ((__nothrow__ )) __attribute__ ((__const__));
float (truncf) (float) asm ("__truncf");
compiler may redirect truncf calls to __truncf, instead of inlining it
(for instance, clang). The USE_TRUNCF_BUILTIN is 1 to indicate that
truncf should be inlined. In this case, we don't want the truncf
redirection:
1. For each math function which may be inlined, we define
#if USE_TRUNCF_BUILTIN
# define NO_truncf_BUILTIN inline_truncf
#else
# define NO_truncf_BUILTIN truncf
#endif
in <math-use-builtins.h>.
2. Include <math-use-builtins.h> in include/math.h.
3. Change MATH_REDIRECT to
#define MATH_REDIRECT(FUNC, PREFIX, ARGS) \
float (NO_ ## FUNC ## f ## _BUILTIN) (ARGS (float)) \
asm (PREFIX #FUNC "f");
With this change If USE_TRUNCF_BUILTIN is 0, we get
float (truncf) (float) asm ("__truncf");
truncf will be redirected to __truncf.
And for USE_TRUNCF_BUILTIN 1, we get:
float (inline_truncf) (float) asm ("__truncf");
In both cases either truncf will be inlined or the internal alias
(__truncf) will be called.
It is not required for all math-use-builtin symbol, only the one
defined in math.h. It also allows to remove all the math-use-builtin
inclusion, since it is now implicitly included by math.h.
For MIPS, some math-use-builtin headers include sysdep.h and this
in turn includes a lot of extra headers that do not allow ldbl-128
code to override alias definition (math.h will include
some stdlib.h definition). The math-use-builtin only requires
the __mips_isa_rev, so move the defintion to sgidefs.h.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/math.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/include/math.h b/include/math.h index 1236268804..84d44d44dc 100644 --- a/include/math.h +++ b/include/math.h @@ -139,25 +139,35 @@ fabsf128 (_Float128 x) /* NB: Internal tests don't have access to internal symbols. */ # if !IS_IN (testsuite_internal) \ && !(defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0) +/* NO_MATH_REDIRECT must be defined in the source implementing function, + FUNC, if FUNC is implemented as an alias of __FUNC or vice versa to + avoid redirecting FUNC to __FUNC. */ +# include <math-use-builtins.h> +/* NB: Do not redirect math builtin functions when they are inlined. */ # ifndef NO_MATH_REDIRECT /* Declare some functions for use within GLIBC. Compilers typically inline those functions as a single instruction. Use an asm to avoid use of PLTs if it doesn't. */ # define MATH_REDIRECT(FUNC, PREFIX, ARGS) \ - float (FUNC ## f) (ARGS (float)) asm (PREFIX #FUNC "f"); \ - double (FUNC) (ARGS (double)) asm (PREFIX #FUNC ); \ + float (NO_ ## FUNC ## f ## _BUILTIN) (ARGS (float)) \ + asm (PREFIX #FUNC "f"); \ + double (NO_ ## FUNC ## _BUILTIN) (ARGS (double)) \ + asm (PREFIX #FUNC ); \ MATH_REDIRECT_LDBL (FUNC, PREFIX, ARGS) \ MATH_REDIRECT_F128 (FUNC, PREFIX, ARGS) + # if defined __NO_LONG_DOUBLE_MATH \ || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 # define MATH_REDIRECT_LDBL(FUNC, PREFIX, ARGS) # else -# define MATH_REDIRECT_LDBL(FUNC, PREFIX, ARGS) \ - long double (FUNC ## l) (ARGS (long double)) asm (PREFIX #FUNC "l"); +# define MATH_REDIRECT_LDBL(FUNC, PREFIX, ARGS) \ + long double (NO_ ## FUNC ## l ## _BUILTIN) (ARGS (long double)) \ + asm (PREFIX #FUNC "l"); # endif # if __HAVE_DISTINCT_FLOAT128 -# define MATH_REDIRECT_F128(FUNC, PREFIX, ARGS) \ - _Float128 (FUNC ## f128) (ARGS (_Float128)) asm (PREFIX #FUNC "f128"); +# define MATH_REDIRECT_F128(FUNC, PREFIX, ARGS) \ + _Float128 (NO_ ## FUNC ## f128 ## _BUILTIN) (ARGS (_Float128)) \ + asm (PREFIX #FUNC "f128"); # else # define MATH_REDIRECT_F128(FUNC, PREFIX, ARGS) # endif |
