1 /* ===-- int_math.h - internal math inlines ---------------------------------===
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 * ===-----------------------------------------------------------------------===
10 * This file is not part of the interface of this library.
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.
18 * ===-----------------------------------------------------------------------===
25 # define __has_builtin(x) 0
28 #if defined(_MSC_VER) && !defined(__clang__)
34 #if defined(_MSC_VER) && !defined(__clang__)
35 #define CRT_INFINITY INFINITY
37 #define CRT_INFINITY __builtin_huge_valf()
40 #if defined(_MSC_VER) && !defined(__clang__)
41 #define crt_isfinite(x) _finite((x))
42 #define crt_isinf(x) !_finite((x))
43 #define crt_isnan(x) _isnan((x))
45 /* Define crt_isfinite in terms of the builtin if available, otherwise provide
46 * an alternate version in terms of our other functions. This supports some
47 * versions of GCC which didn't have __builtin_isfinite.
49 #if __has_builtin(__builtin_isfinite)
50 # define crt_isfinite(x) __builtin_isfinite((x))
51 #elif defined(__GNUC__)
52 # define crt_isfinite(x) \
54 __typeof((x)) x_ = (x); \
55 !crt_isinf(x_) && !crt_isnan(x_); \
58 # error "Do not know how to check for infinity"
59 #endif /* __has_builtin(__builtin_isfinite) */
60 #define crt_isinf(x) __builtin_isinf((x))
61 #define crt_isnan(x) __builtin_isnan((x))
64 #if defined(_MSC_VER) && !defined(__clang__)
65 #define crt_copysign(x, y) copysign((x), (y))
66 #define crt_copysignf(x, y) copysignf((x), (y))
67 #define crt_copysignl(x, y) copysignl((x), (y))
69 #define crt_copysign(x, y) __builtin_copysign((x), (y))
70 #define crt_copysignf(x, y) __builtin_copysignf((x), (y))
71 #define crt_copysignl(x, y) __builtin_copysignl((x), (y))
74 #if defined(_MSC_VER) && !defined(__clang__)
75 #define crt_fabs(x) fabs((x))
76 #define crt_fabsf(x) fabsf((x))
77 #define crt_fabsl(x) fabs((x))
79 #define crt_fabs(x) __builtin_fabs((x))
80 #define crt_fabsf(x) __builtin_fabsf((x))
81 #define crt_fabsl(x) __builtin_fabsl((x))
84 #if defined(_MSC_VER) && !defined(__clang__)
85 #define crt_fmax(x, y) __max((x), (y))
86 #define crt_fmaxf(x, y) __max((x), (y))
87 #define crt_fmaxl(x, y) __max((x), (y))
89 #define crt_fmax(x, y) __builtin_fmax((x), (y))
90 #define crt_fmaxf(x, y) __builtin_fmaxf((x), (y))
91 #define crt_fmaxl(x, y) __builtin_fmaxl((x), (y))
94 #if defined(_MSC_VER) && !defined(__clang__)
95 #define crt_logbl(x) logbl((x))
97 #define crt_logbl(x) __builtin_logbl((x))
100 #if defined(_MSC_VER) && !defined(__clang__)
101 #define crt_scalbn(x, y) scalbn((x), (y))
102 #define crt_scalbnf(x, y) scalbnf((x), (y))
103 #define crt_scalbnl(x, y) scalbnl((x), (y))
105 #define crt_scalbn(x, y) __builtin_scalbn((x), (y))
106 #define crt_scalbnf(x, y) __builtin_scalbnf((x), (y))
107 #define crt_scalbnl(x, y) __builtin_scalbnl((x), (y))
110 #endif /* INT_MATH_H */