xref: /minix3/sys/external/bsd/compiler_rt/dist/lib/builtins/int_math.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* ===-- int_math.h - internal math inlines ---------------------------------===
2*0a6a1f1dSLionel Sambuc  *
3*0a6a1f1dSLionel Sambuc  *                     The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc  *
5*0a6a1f1dSLionel Sambuc  * This file is dual licensed under the MIT and the University of Illinois Open
6*0a6a1f1dSLionel Sambuc  * Source Licenses. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc  *
8*0a6a1f1dSLionel Sambuc  * ===-----------------------------------------------------------------------===
9*0a6a1f1dSLionel Sambuc  *
10*0a6a1f1dSLionel Sambuc  * This file is not part of the interface of this library.
11*0a6a1f1dSLionel Sambuc  *
12*0a6a1f1dSLionel Sambuc  * This file defines substitutes for the libm functions used in some of the
13*0a6a1f1dSLionel Sambuc  * compiler-rt implementations, defined in such a way that there is not a direct
14*0a6a1f1dSLionel Sambuc  * dependency on libm or math.h. Instead, we use the compiler builtin versions
15*0a6a1f1dSLionel Sambuc  * where available. This reduces our dependencies on the system SDK by foisting
16*0a6a1f1dSLionel Sambuc  * the responsibility onto the compiler.
17*0a6a1f1dSLionel Sambuc  *
18*0a6a1f1dSLionel Sambuc  * ===-----------------------------------------------------------------------===
19*0a6a1f1dSLionel Sambuc  */
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc #ifndef INT_MATH_H
22*0a6a1f1dSLionel Sambuc #define INT_MATH_H
23*0a6a1f1dSLionel Sambuc 
24*0a6a1f1dSLionel Sambuc #ifndef __has_builtin
25*0a6a1f1dSLionel Sambuc #  define  __has_builtin(x) 0
26*0a6a1f1dSLionel Sambuc #endif
27*0a6a1f1dSLionel Sambuc 
28*0a6a1f1dSLionel Sambuc #define CRT_INFINITY __builtin_huge_valf()
29*0a6a1f1dSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc #define crt_isinf(x) __builtin_isinf((x))
31*0a6a1f1dSLionel Sambuc #define crt_isnan(x) __builtin_isnan((x))
32*0a6a1f1dSLionel Sambuc 
33*0a6a1f1dSLionel Sambuc /* Define crt_isfinite in terms of the builtin if available, otherwise provide
34*0a6a1f1dSLionel Sambuc  * an alternate version in terms of our other functions. This supports some
35*0a6a1f1dSLionel Sambuc  * versions of GCC which didn't have __builtin_isfinite.
36*0a6a1f1dSLionel Sambuc  */
37*0a6a1f1dSLionel Sambuc #if __has_builtin(__builtin_isfinite)
38*0a6a1f1dSLionel Sambuc #  define crt_isfinite(x) __builtin_isfinite((x))
39*0a6a1f1dSLionel Sambuc #else
40*0a6a1f1dSLionel Sambuc #  define crt_isfinite(x) \
41*0a6a1f1dSLionel Sambuc   __extension__(({ \
42*0a6a1f1dSLionel Sambuc       __typeof((x)) x_ = (x); \
43*0a6a1f1dSLionel Sambuc       !crt_isinf(x_) && !crt_isnan(x_); \
44*0a6a1f1dSLionel Sambuc     }))
45*0a6a1f1dSLionel Sambuc #endif
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc #define crt_copysign(x, y) __builtin_copysign((x), (y))
48*0a6a1f1dSLionel Sambuc #define crt_copysignf(x, y) __builtin_copysignf((x), (y))
49*0a6a1f1dSLionel Sambuc #define crt_copysignl(x, y) __builtin_copysignl((x), (y))
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc #define crt_fabs(x) __builtin_fabs((x))
52*0a6a1f1dSLionel Sambuc #define crt_fabsf(x) __builtin_fabsf((x))
53*0a6a1f1dSLionel Sambuc #define crt_fabsl(x) __builtin_fabsl((x))
54*0a6a1f1dSLionel Sambuc 
55*0a6a1f1dSLionel Sambuc #define crt_fmax(x, y) __builtin_fmax((x), (y))
56*0a6a1f1dSLionel Sambuc #define crt_fmaxf(x, y) __builtin_fmaxf((x), (y))
57*0a6a1f1dSLionel Sambuc #define crt_fmaxl(x, y) __builtin_fmaxl((x), (y))
58*0a6a1f1dSLionel Sambuc 
59*0a6a1f1dSLionel Sambuc #define crt_logb(x) __builtin_logb((x))
60*0a6a1f1dSLionel Sambuc #define crt_logbf(x) __builtin_logbf((x))
61*0a6a1f1dSLionel Sambuc #define crt_logbl(x) __builtin_logbl((x))
62*0a6a1f1dSLionel Sambuc 
63*0a6a1f1dSLionel Sambuc #define crt_scalbn(x, y) __builtin_scalbn((x), (y))
64*0a6a1f1dSLionel Sambuc #define crt_scalbnf(x, y) __builtin_scalbnf((x), (y))
65*0a6a1f1dSLionel Sambuc #define crt_scalbnl(x, y) __builtin_scalbnl((x), (y))
66*0a6a1f1dSLionel Sambuc 
67*0a6a1f1dSLionel Sambuc #endif /* INT_MATH_H */
68