1 /* Alias macros for functions returning a narrower type.
2    Copyright (C) 2018-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
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.
9 
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.
14 
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    <https://www.gnu.org/licenses/>.  */
18 
19 #ifndef	_MATH_NARROW_ALIAS_H
20 #define	_MATH_NARROW_ALIAS_H	1
21 
22 #include <bits/floatn.h>
23 #include <bits/long-double.h>
24 
25 /* The following macros declare aliases for a narrowing function.  The
26    sole argument is the base name of a family of functions, such as
27    "add".  If any platform changes long double format after the
28    introduction of narrowing functions, in a way requiring symbol
29    versioning compatibility, additional variants of these macros will
30    be needed.  */
31 
32 #define libm_alias_float_double_main(func)	\
33   weak_alias (__f ## func, f ## func)		\
34   weak_alias (__f ## func, f32 ## func ## f64)	\
35   weak_alias (__f ## func, f32 ## func ## f32x)
36 
37 #ifdef NO_LONG_DOUBLE
38 # define libm_alias_float_double(func)		\
39   libm_alias_float_double_main (func)		\
40   weak_alias (__f ## func, f ## func ## l)
41 #else
42 # define libm_alias_float_double(func)		\
43   libm_alias_float_double_main (func)
44 #endif
45 
46 #define libm_alias_float32x_float64_main(func)			\
47   weak_alias (__f32x ## func ## f64, f32x ## func ## f64)
48 
49 #ifdef NO_LONG_DOUBLE
50 # define libm_alias_float32x_float64(func)		\
51   libm_alias_float32x_float64_main (func)		\
52   weak_alias (__f32x ## func ## f64, d ## func ## l)
53 #elif defined __LONG_DOUBLE_MATH_OPTIONAL
54 # define libm_alias_float32x_float64(func)			\
55   libm_alias_float32x_float64_main (func)			\
56   weak_alias (__f32x ## func ## f64, __nldbl_d ## func ## l)
57 #else
58 # define libm_alias_float32x_float64(func)	\
59   libm_alias_float32x_float64_main (func)
60 #endif
61 
62 #if __HAVE_FLOAT128 && !__HAVE_DISTINCT_FLOAT128
63 # define libm_alias_float_ldouble_f128(func)		\
64   weak_alias (__f ## func ## l, f32 ## func ## f128)
65 # define libm_alias_double_ldouble_f128(func)		\
66   weak_alias (__d ## func ## l, f32x ## func ## f128)	\
67   weak_alias (__d ## func ## l, f64 ## func ## f128)
68 #else
69 # define libm_alias_float_ldouble_f128(func)
70 # define libm_alias_double_ldouble_f128(func)
71 #endif
72 
73 #if __HAVE_FLOAT64X_LONG_DOUBLE
74 # define libm_alias_float_ldouble_f64x(func)		\
75   weak_alias (__f ## func ## l, f32 ## func ## f64x)
76 # define libm_alias_double_ldouble_f64x(func)		\
77   weak_alias (__d ## func ## l, f32x ## func ## f64x)	\
78   weak_alias (__d ## func ## l, f64 ## func ## f64x)
79 #else
80 # define libm_alias_float_ldouble_f64x(func)
81 # define libm_alias_double_ldouble_f64x(func)
82 #endif
83 
84 #define libm_alias_float_ldouble(func)		\
85   weak_alias (__f ## func ## l, f ## func ## l) \
86   libm_alias_float_ldouble_f128 (func)		\
87   libm_alias_float_ldouble_f64x (func)
88 
89 #define libm_alias_double_ldouble(func)		\
90   weak_alias (__d ## func ## l, d ## func ## l) \
91   libm_alias_double_ldouble_f128 (func)		\
92   libm_alias_double_ldouble_f64x (func)
93 
94 #define libm_alias_float64x_float128(func)			\
95   weak_alias (__f64x ## func ## f128, f64x ## func ## f128)
96 
97 #define libm_alias_float32_float128_main(func)			\
98   weak_alias (__f32 ## func ## f128, f32 ## func ## f128)
99 
100 #define libm_alias_float64_float128_main(func)			\
101   weak_alias (__f64 ## func ## f128, f64 ## func ## f128)	\
102   weak_alias (__f64 ## func ## f128, f32x ## func ## f128)
103 
104 #include <math-narrow-alias-float128.h>
105 
106 /* The following macros declare narrowing-named aliases for a
107    non-narrowing function.  */
108 
109 #define libm_alias_double_narrow_main(from, to)	\
110   weak_alias (from, f32x ## to ## f64)
111 
112 #ifdef NO_LONG_DOUBLE
113 # define libm_alias_double_narrow(from, to)	\
114   libm_alias_double_narrow_main (from, to)	\
115   weak_alias (from, d ## to ## l)
116 #else
117 # define libm_alias_double_narrow(from, to)	\
118   libm_alias_double_narrow_main (from, to)
119 #endif
120 
121 #if __HAVE_FLOAT64X_LONG_DOUBLE && __HAVE_FLOAT128 && !__HAVE_DISTINCT_FLOAT128
122 # define libm_alias_ldouble_narrow(from, to)	\
123   weak_alias (from ## l, f64x ## to ## f128)
124 #else
125 # define libm_alias_ldouble_narrow(from, to)
126 #endif
127 
128 #if __HAVE_DISTINCT_FLOAT128 && __HAVE_FLOAT64X && !__HAVE_FLOAT64X_LONG_DOUBLE
129 # define libm_alias_float128_narrow(from, to)	\
130   weak_alias (from ## f128, f64x ## to ## f128)
131 #else
132 # define libm_alias_float128_narrow(from, to)
133 #endif
134 
135 #endif /* math-narrow-alias.h.  */
136