Support mcount/gprof test with GCC defaulting to PIE
[glibc.git] / sysdeps / generic / math-type-macros.h
blobb4c2aee6aa5981abb4711f18bfe1e25e38ef83aa
1 /* Helper macros for type generic function implementations within libm.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _MATH_TYPE_MACROS
20 #define _MATH_TYPE_MACROS
22 /* Each type imports a header which is expected to
23 define:
25 M_LIT(x) - Paste the type specific suffix onto the constant x.
26 M_MLIT(x) - Paste the type specific suffix used by the macro
27 constants in math.h, i.e M_PI or M_PIl.
28 M_PFX - The prefixed used by float.h macros like FLT_MANT_DIG.
29 M_SUF(x) - Paste the the type specific suffix used by functions
30 i.e expf expl exp.
31 FLOAT - Resolves to the C typename of M_TYPE.
32 CFLOAT - Resolves to the complex typename of M_TYPE.
33 M_STRTO_NAN - Resolves to the internal libc function which
34 converts a string into the appropriate FLOAT nan
35 value.
37 Optionally, these headers may inject a non-standard
38 definition for the following:
40 declare_mgen_alias(from,to)
41 This exposes the appropriate symbol(s) for a
42 function f of type FLOAT.
44 declare_mgen_alias_2(from,to,to2)
45 This exposes the appropriate symbol(s) for a
46 function f of type FLOAT when it is aliased
47 to two symbols.
49 M_LIBM_NEED_COMPAT(func)
50 This is utilized in macro context to indicate
51 whether func should declare compat symbols.
53 declare_mgen_libm_compat(from,to)
54 This is used in conjunction with the above macro
55 outside of macro context to paste whatever is
56 required to generate a compat symbol. */
58 #ifndef M_PFX
59 # error "M_PFX must be defined."
60 #endif
61 #ifndef M_LIT
62 # error "M_LIT must be defined."
63 #endif
64 #ifndef M_MLIT
65 # error "M_MLIT must be defined."
66 #endif
67 #ifndef M_SUF
68 # error "M_SUF must be defined."
69 #endif
70 #ifndef FLOAT
71 # error "FLOAT must be defined."
72 #endif
73 #ifndef CFLOAT
74 # error "CFLOAT must be defined."
75 #endif
77 #define __M_CONCAT(a,b) a ## b
78 #define __M_CONCATX(a,b) __M_CONCAT(a,b)
80 #define M_NAN M_SUF (__builtin_nan) ("")
81 #define M_MIN_EXP __M_CONCATX (M_PFX, _MIN_EXP)
82 #define M_MAX_EXP __M_CONCATX (M_PFX, _MAX_EXP)
83 #define M_MIN __M_CONCATX (M_PFX, _MIN)
84 #define M_MAX __M_CONCATX (M_PFX, _MAX)
85 #define M_MANT_DIG __M_CONCATX (M_PFX, _MANT_DIG)
86 #define M_HUGE_VAL (M_SUF (__builtin_huge_val) ())
88 /* Helper macros for commonly used functions. */
89 #define M_COPYSIGN M_SUF (__copysign)
90 #define M_FABS M_SUF (fabs)
91 #define M_SINCOS M_SUF (__sincos)
92 #define M_SCALBN M_SUF (__scalbn)
93 #define M_LOG1P M_SUF (__log1p)
95 #define M_ATAN2 M_SUF (__ieee754_atan2)
96 #define M_COSH M_SUF (__ieee754_cosh)
97 #define M_EXP M_SUF (__ieee754_exp)
98 #define M_HYPOT M_SUF (__ieee754_hypot)
99 #define M_LOG M_SUF (__ieee754_log)
100 #define M_SINH M_SUF (__ieee754_sinh)
101 #define M_SQRT M_SUF (__ieee754_sqrt)
103 /* Needed to evaluate M_MANT_DIG below. */
104 #include <float.h>
106 /* Use a special epsilon value for IBM long double
107 to avoid spurious overflows/underflows. */
108 #if M_MANT_DIG != 106
109 # define M_EPSILON __M_CONCATX (M_PFX, _EPSILON)
110 #else
111 # define M_EPSILON M_LIT (0x1p-106)
112 #endif
114 /* Enable overloading of function name to assist reuse. */
115 #ifndef M_DECL_FUNC
116 # define M_DECL_FUNC(f) M_SUF (f)
117 #endif
119 /* If the type does not declare special aliasing, use the default. */
120 #ifndef declare_mgen_alias
121 # define declare_mgen_alias(from, to) weak_alias (M_SUF (from), M_SUF (to))
122 #endif
124 /* Likewise, if two aliases are derived from the same symbol. */
125 #ifndef declare_mgen_alias_2
126 # define declare_mgen_alias_2(from, to, to2) \
127 declare_mgen_alias (from, to) \
128 declare_mgen_alias (from, to2)
129 #endif
131 /* Do not generate anything for compat symbols by default. */
132 #ifndef M_LIBM_NEED_COMPAT
133 # define M_LIBM_NEED_COMPAT(func) 0
134 # define declare_mgen_libm_compat(from, to)
135 #endif
137 #endif /* _MATH_TYPE_MACROS */