int_math.h revision 256281
1218893Sdim/* ===-- int_math.h - internal math inlines ---------------------------------=== 2193323Sed * 3193323Sed * The LLVM Compiler Infrastructure 4193323Sed * 5193323Sed * This file is dual licensed under the MIT and the University of Illinois Open 6193323Sed * Source Licenses. See LICENSE.TXT for details. 7193323Sed * 8193323Sed * ===-----------------------------------------------------------------------=== 9193323Sed * 10218893Sdim * This file is not part of the interface of this library. 11218893Sdim * 12218893Sdim * This file defines substitutes for the libm functions used in some of the 13193323Sed * compiler-rt implementations, defined in such a way that there is not a direct 14193323Sed * dependency on libm or math.h. Instead, we use the compiler builtin versions 15193323Sed * where available. This reduces our dependencies on the system SDK by foisting 16249423Sdim * the responsibility onto the compiler. 17249423Sdim * 18249423Sdim * ===-----------------------------------------------------------------------=== 19193323Sed */ 20199989Srdivacky 21266715Sdim#ifndef INT_MATH_H 22266715Sdim#define INT_MATH_H 23249423Sdim 24266715Sdim#ifndef __has_builtin 25199989Srdivacky# define __has_builtin(x) 0 26199989Srdivacky#endif 27249423Sdim 28249423Sdim#define CRT_INFINITY __builtin_huge_valf() 29249423Sdim 30249423Sdim#define crt_isinf(x) __builtin_isinf((x)) 31249423Sdim#define crt_isnan(x) __builtin_isnan((x)) 32249423Sdim 33249423Sdim/* Define crt_isfinite in terms of the builtin if available, otherwise provide 34249423Sdim * an alternate version in terms of our other functions. This supports some 35249423Sdim * versions of GCC which didn't have __builtin_isfinite. 36249423Sdim */ 37249423Sdim#if __has_builtin(__builtin_isfinite) 38198090Srdivacky# define crt_isfinite(x) __builtin_isfinite((x)) 39212904Sdim#else 40249423Sdim# define crt_isfinite(x) \ 41193323Sed __extension__(({ \ 42193323Sed __typeof((x)) x_ = (x); \ 43193323Sed !crt_isinf(x_) && !crt_isnan(x_); \ 44266715Sdim })) 45266715Sdim#endif 46266715Sdim 47266715Sdim#define crt_copysign(x, y) __builtin_copysign((x), (y)) 48266715Sdim#define crt_copysignf(x, y) __builtin_copysignf((x), (y)) 49266715Sdim#define crt_copysignl(x, y) __builtin_copysignl((x), (y)) 50193323Sed 51193323Sed#define crt_fabs(x) __builtin_fabs((x)) 52193323Sed#define crt_fabsf(x) __builtin_fabsf((x)) 53193323Sed#define crt_fabsl(x) __builtin_fabsl((x)) 54193323Sed 55193323Sed#define crt_fmax(x, y) __builtin_fmax((x), (y)) 56193323Sed#define crt_fmaxf(x, y) __builtin_fmaxf((x), (y)) 57193323Sed#define crt_fmaxl(x, y) __builtin_fmaxl((x), (y)) 58198892Srdivacky 59199989Srdivacky#define crt_logb(x) __builtin_logb((x)) 60199989Srdivacky#define crt_logbf(x) __builtin_logbf((x)) 61199989Srdivacky#define crt_logbl(x) __builtin_logbl((x)) 62199989Srdivacky 63199989Srdivacky#define crt_scalbn(x, y) __builtin_scalbn((x), (y)) 64199989Srdivacky#define crt_scalbnf(x, y) __builtin_scalbnf((x), (y)) 65193323Sed#define crt_scalbnl(x, y) __builtin_scalbnl((x), (y)) 66193323Sed 67193323Sed#endif /* INT_MATH_H */ 68193323Sed