[PATCH] D13409: Use MSVCRT functions for floating-point builtins unavailable on MSVC

angelsl via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 10:33:17 PDT 2015


angelsl created this revision.
angelsl added a reviewer: compnerd.
angelsl added subscribers: compnerd, llvm-commits.

http://reviews.llvm.org/D13409

Files:
  lib/builtins/int_math.h

Index: lib/builtins/int_math.h
===================================================================
--- lib/builtins/int_math.h
+++ lib/builtins/int_math.h
@@ -25,43 +25,88 @@
 #  define  __has_builtin(x) 0
 #endif
 
-#define CRT_INFINITY __builtin_huge_valf()
+#ifdef _MSC_VER
+#include <math.h>
+#include <stdlib.h>
+#include <ymath.h>
+#endif
 
-#define crt_isinf(x) __builtin_isinf((x))
-#define crt_isnan(x) __builtin_isnan((x))
+#ifdef _MSC_VER
+#define CRT_INFINITY INFINITY
+#else
+#define CRT_INFINITY __builtin_huge_valf()
+#endif
 
+#ifdef _MSC_VER
+#define crt_isfinite(x) _finite((x))
+#define crt_isinf(x) !_finite((x))
+#define crt_isnan(x) _isnan((x))
+#else
 /* Define crt_isfinite in terms of the builtin if available, otherwise provide
  * an alternate version in terms of our other functions. This supports some
  * versions of GCC which didn't have __builtin_isfinite.
  */
 #if __has_builtin(__builtin_isfinite)
 #  define crt_isfinite(x) __builtin_isfinite((x))
-#else
+#elif !defined(_MSC_VER)
 #  define crt_isfinite(x) \
   __extension__(({ \
       __typeof((x)) x_ = (x); \
       !crt_isinf(x_) && !crt_isnan(x_); \
     }))
-#endif
+#endif /* __has_builtin(__builtin_isfinite) */
+#define crt_isinf(x) __builtin_isinf((x))
+#define crt_isnan(x) __builtin_isnan((x))
+#endif /* _MSC_VER */
 
+#ifdef _MSC_VER
+#define crt_copysign(x, y) copysign((x), (y))
+#define crt_copysignf(x, y) copysignf((x), (y))
+#define crt_copysignl(x, y) copysignl((x), (y))
+#else
 #define crt_copysign(x, y) __builtin_copysign((x), (y))
 #define crt_copysignf(x, y) __builtin_copysignf((x), (y))
 #define crt_copysignl(x, y) __builtin_copysignl((x), (y))
+#endif
 
+#ifdef _MSC_VER
+#define crt_fabs(x) fabs((x))
+#define crt_fabsf(x) fabsf((x))
+#define crt_fabsl(x) fabs((x))
+#else
 #define crt_fabs(x) __builtin_fabs((x))
 #define crt_fabsf(x) __builtin_fabsf((x))
 #define crt_fabsl(x) __builtin_fabsl((x))
+#endif
 
+#ifdef _MSC_VER
+#define crt_fmax(x, y) __max((x), (y))
+#define crt_fmaxf(x, y) __max((x), (y))
+#define crt_fmaxl(x, y) __max((x), (y))
+#else
 #define crt_fmax(x, y) __builtin_fmax((x), (y))
 #define crt_fmaxf(x, y) __builtin_fmaxf((x), (y))
 #define crt_fmaxl(x, y) __builtin_fmaxl((x), (y))
+#endif
 
+#ifdef _MSC_VER
+#define crt_logb(x) logb((x))
+#define crt_logbf(x) logbf((x))
+#define crt_logbl(x) logbl((x))
+#else
 #define crt_logb(x) __builtin_logb((x))
 #define crt_logbf(x) __builtin_logbf((x))
 #define crt_logbl(x) __builtin_logbl((x))
+#endif
 
+#ifdef _MSC_VER
+#define crt_scalbn(x, y) scalbn((x), (y))
+#define crt_scalbnf(x, y) scalbnf((x), (y))
+#define crt_scalbnl(x, y) scalbnl((x), (y))
+#else
 #define crt_scalbn(x, y) __builtin_scalbn((x), (y))
 #define crt_scalbnf(x, y) __builtin_scalbnf((x), (y))
 #define crt_scalbnl(x, y) __builtin_scalbnl((x), (y))
+#endif
 
 #endif /* INT_MATH_H */


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13409.36435.patch
Type: text/x-patch
Size: 2851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151003/13b2bb88/attachment.bin>


More information about the llvm-commits mailing list