Path: blob/master/libs/compiler-rt/lib/builtins/int_math.h
4395 views
/* ===-- int_math.h - internal math inlines ---------------------------------===1*2* The LLVM Compiler Infrastructure3*4* This file is dual licensed under the MIT and the University of Illinois Open5* Source Licenses. See LICENSE.TXT for details.6*7* ===-----------------------------------------------------------------------===8*9* This file is not part of the interface of this library.10*11* This file defines substitutes for the libm functions used in some of the12* compiler-rt implementations, defined in such a way that there is not a direct13* dependency on libm or math.h. Instead, we use the compiler builtin versions14* where available. This reduces our dependencies on the system SDK by foisting15* the responsibility onto the compiler.16*17* ===-----------------------------------------------------------------------===18*/1920#ifndef INT_MATH_H21#define INT_MATH_H2223#ifndef __has_builtin24# define __has_builtin(x) 025#endif2627#if defined(_MSC_VER) && !defined(__clang__)28#include <math.h>29#include <stdlib.h>30#include <ymath.h>31#endif3233#if defined(_MSC_VER) && !defined(__clang__)34#define CRT_INFINITY INFINITY35#else36#define CRT_INFINITY __builtin_huge_valf()37#endif3839#if defined(_MSC_VER) && !defined(__clang__)40#define crt_isfinite(x) _finite((x))41#define crt_isinf(x) !_finite((x))42#define crt_isnan(x) _isnan((x))43#else44/* Define crt_isfinite in terms of the builtin if available, otherwise provide45* an alternate version in terms of our other functions. This supports some46* versions of GCC which didn't have __builtin_isfinite.47*/48#if __has_builtin(__builtin_isfinite)49# define crt_isfinite(x) __builtin_isfinite((x))50#elif defined(__GNUC__)51# define crt_isfinite(x) \52__extension__(({ \53__typeof((x)) x_ = (x); \54!crt_isinf(x_) && !crt_isnan(x_); \55}))56#else57# error "Do not know how to check for infinity"58#endif /* __has_builtin(__builtin_isfinite) */59#define crt_isinf(x) __builtin_isinf((x))60#define crt_isnan(x) __builtin_isnan((x))61#endif /* _MSC_VER */6263#if defined(_MSC_VER) && !defined(__clang__)64#define crt_copysign(x, y) copysign((x), (y))65#define crt_copysignf(x, y) copysignf((x), (y))66#define crt_copysignl(x, y) copysignl((x), (y))67#else68#define crt_copysign(x, y) __builtin_copysign((x), (y))69#define crt_copysignf(x, y) __builtin_copysignf((x), (y))70#define crt_copysignl(x, y) __builtin_copysignl((x), (y))71#endif7273#if defined(_MSC_VER) && !defined(__clang__)74#define crt_fabs(x) fabs((x))75#define crt_fabsf(x) fabsf((x))76#define crt_fabsl(x) fabs((x))77#else78#define crt_fabs(x) __builtin_fabs((x))79#define crt_fabsf(x) __builtin_fabsf((x))80#define crt_fabsl(x) __builtin_fabsl((x))81#endif8283#if defined(_MSC_VER) && !defined(__clang__)84#define crt_fmax(x, y) __max((x), (y))85#define crt_fmaxf(x, y) __max((x), (y))86#define crt_fmaxl(x, y) __max((x), (y))87#else88#define crt_fmax(x, y) __builtin_fmax((x), (y))89#define crt_fmaxf(x, y) __builtin_fmaxf((x), (y))90#define crt_fmaxl(x, y) __builtin_fmaxl((x), (y))91#endif9293#if defined(_MSC_VER) && !defined(__clang__)94#define crt_logbl(x) logbl((x))95#else96#define crt_logbl(x) __builtin_logbl((x))97#endif9899#if defined(_MSC_VER) && !defined(__clang__)100#define crt_scalbn(x, y) scalbn((x), (y))101#define crt_scalbnf(x, y) scalbnf((x), (y))102#define crt_scalbnl(x, y) scalbnl((x), (y))103#else104#define crt_scalbn(x, y) __builtin_scalbn((x), (y))105#define crt_scalbnf(x, y) __builtin_scalbnf((x), (y))106#define crt_scalbnl(x, y) __builtin_scalbnl((x), (y))107#endif108109#endif /* INT_MATH_H */110111112