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