Index: lib/builtins/CMakeLists.txt =================================================================== --- lib/builtins/CMakeLists.txt +++ lib/builtins/CMakeLists.txt @@ -329,7 +329,7 @@ add_subdirectory(Darwin-excludes) add_subdirectory(macho_embedded) darwin_add_builtin_libraries(${BUILTIN_SUPPORTED_OS}) -elseif (NOT WIN32 OR MINGW) +else () foreach (arch ${BUILTIN_SUPPORTED_ARCH}) if (CAN_TARGET_${arch}) # Filter out generic versions of routines that are re-implemented in Index: lib/builtins/divdc3.c =================================================================== --- lib/builtins/divdc3.c +++ lib/builtins/divdc3.c @@ -17,7 +17,7 @@ /* Returns: the quotient of (a + ib) / (c + id) */ -COMPILER_RT_ABI double _Complex +COMPILER_RT_ABI _Dcomplex __divdc3(double __a, double __b, double __c, double __d) { int __ilogbw = 0; @@ -29,31 +29,31 @@ __d = crt_scalbn(__d, -__ilogbw); } double __denom = __c * __c + __d * __d; - double _Complex z; - __real__ z = crt_scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); - __imag__ z = crt_scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); - if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) + _Dcomplex z; + _Creal(z) = crt_scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); + _Cimag(z) = crt_scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); + if (crt_isnan(_Creal(z)) && crt_isnan(_Cimag(z))) { if ((__denom == 0.0) && (!crt_isnan(__a) || !crt_isnan(__b))) { - __real__ z = crt_copysign(CRT_INFINITY, __c) * __a; - __imag__ z = crt_copysign(CRT_INFINITY, __c) * __b; + _Creal(z) = crt_copysign(CRT_INFINITY, __c) * __a; + _Cimag(z) = crt_copysign(CRT_INFINITY, __c) * __b; } else if ((crt_isinf(__a) || crt_isinf(__b)) && crt_isfinite(__c) && crt_isfinite(__d)) { __a = crt_copysign(crt_isinf(__a) ? 1.0 : 0.0, __a); __b = crt_copysign(crt_isinf(__b) ? 1.0 : 0.0, __b); - __real__ z = CRT_INFINITY * (__a * __c + __b * __d); - __imag__ z = CRT_INFINITY * (__b * __c - __a * __d); + _Creal(z) = CRT_INFINITY * (__a * __c + __b * __d); + _Cimag(z) = CRT_INFINITY * (__b * __c - __a * __d); } else if (crt_isinf(__logbw) && __logbw > 0.0 && crt_isfinite(__a) && crt_isfinite(__b)) { __c = crt_copysign(crt_isinf(__c) ? 1.0 : 0.0, __c); __d = crt_copysign(crt_isinf(__d) ? 1.0 : 0.0, __d); - __real__ z = 0.0 * (__a * __c + __b * __d); - __imag__ z = 0.0 * (__b * __c - __a * __d); + _Creal(z) = 0.0 * (__a * __c + __b * __d); + _Cimag(z) = 0.0 * (__b * __c - __a * __d); } } return z; Index: lib/builtins/divsc3.c =================================================================== --- lib/builtins/divsc3.c +++ lib/builtins/divsc3.c @@ -17,7 +17,7 @@ /* Returns: the quotient of (a + ib) / (c + id) */ -COMPILER_RT_ABI float _Complex +COMPILER_RT_ABI _Fcomplex __divsc3(float __a, float __b, float __c, float __d) { int __ilogbw = 0; @@ -29,31 +29,31 @@ __d = crt_scalbnf(__d, -__ilogbw); } float __denom = __c * __c + __d * __d; - float _Complex z; - __real__ z = crt_scalbnf((__a * __c + __b * __d) / __denom, -__ilogbw); - __imag__ z = crt_scalbnf((__b * __c - __a * __d) / __denom, -__ilogbw); - if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) + _Fcomplex z; + _Creal(z) = crt_scalbnf((__a * __c + __b * __d) / __denom, -__ilogbw); + _Cimag(z) = crt_scalbnf((__b * __c - __a * __d) / __denom, -__ilogbw); + if (crt_isnan(_Creal(z)) && crt_isnan(_Cimag(z))) { if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b))) { - __real__ z = crt_copysignf(CRT_INFINITY, __c) * __a; - __imag__ z = crt_copysignf(CRT_INFINITY, __c) * __b; + _Creal(z) = crt_copysignf(CRT_INFINITY, __c) * __a; + _Cimag(z) = crt_copysignf(CRT_INFINITY, __c) * __b; } else if ((crt_isinf(__a) || crt_isinf(__b)) && crt_isfinite(__c) && crt_isfinite(__d)) { __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a); __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b); - __real__ z = CRT_INFINITY * (__a * __c + __b * __d); - __imag__ z = CRT_INFINITY * (__b * __c - __a * __d); + _Creal(z) = CRT_INFINITY * (__a * __c + __b * __d); + _Cimag(z) = CRT_INFINITY * (__b * __c - __a * __d); } else if (crt_isinf(__logbw) && __logbw > 0 && crt_isfinite(__a) && crt_isfinite(__b)) { __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c); __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d); - __real__ z = 0 * (__a * __c + __b * __d); - __imag__ z = 0 * (__b * __c - __a * __d); + _Creal(z) = 0 * (__a * __c + __b * __d); + _Cimag(z) = 0 * (__b * __c - __a * __d); } } return z; Index: lib/builtins/divxc3.c =================================================================== --- lib/builtins/divxc3.c +++ lib/builtins/divxc3.c @@ -18,7 +18,7 @@ /* Returns: the quotient of (a + ib) / (c + id) */ -COMPILER_RT_ABI long double _Complex +COMPILER_RT_ABI _Lcomplex __divxc3(long double __a, long double __b, long double __c, long double __d) { int __ilogbw = 0; @@ -30,31 +30,31 @@ __d = crt_scalbnl(__d, -__ilogbw); } long double __denom = __c * __c + __d * __d; - long double _Complex z; - __real__ z = crt_scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw); - __imag__ z = crt_scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw); - if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) + _Lcomplex z; + _Creal(z) = crt_scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw); + _Cimag(z) = crt_scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw); + if (crt_isnan(_Creal(z)) && crt_isnan(_Cimag(z))) { if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b))) { - __real__ z = crt_copysignl(CRT_INFINITY, __c) * __a; - __imag__ z = crt_copysignl(CRT_INFINITY, __c) * __b; + _Creal(z) = crt_copysignl(CRT_INFINITY, __c) * __a; + _Cimag(z) = crt_copysignl(CRT_INFINITY, __c) * __b; } else if ((crt_isinf(__a) || crt_isinf(__b)) && crt_isfinite(__c) && crt_isfinite(__d)) { __a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a); __b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b); - __real__ z = CRT_INFINITY * (__a * __c + __b * __d); - __imag__ z = CRT_INFINITY * (__b * __c - __a * __d); + _Creal(z) = CRT_INFINITY * (__a * __c + __b * __d); + _Cimag(z) = CRT_INFINITY * (__b * __c - __a * __d); } else if (crt_isinf(__logbw) && __logbw > 0 && crt_isfinite(__a) && crt_isfinite(__b)) { __c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c); __d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d); - __real__ z = 0 * (__a * __c + __b * __d); - __imag__ z = 0 * (__b * __c - __a * __d); + _Creal(z) = 0 * (__a * __c + __b * __d); + _Cimag(z) = 0 * (__b * __c - __a * __d); } } return z; Index: lib/builtins/enable_execute_stack.c =================================================================== --- lib/builtins/enable_execute_stack.c +++ lib/builtins/enable_execute_stack.c @@ -21,8 +21,13 @@ #define HAVE_SYSCONF 1 #ifdef _WIN32 +#ifndef __wtypes_h__ +#include +#endif + +#ifndef __WINDEF_ #include -#include +#endif #else #ifndef __APPLE__ #include Index: lib/builtins/extendhfsf2.c =================================================================== --- lib/builtins/extendhfsf2.c +++ lib/builtins/extendhfsf2.c @@ -12,9 +12,15 @@ #define DST_SINGLE #include "fp_extend_impl.inc" +#ifdef _MSC_VER +#define __NOINLINE __declspec(noinline) +#else +#define __NOINLINE __attribute__((noinline)) +#endif + // Use a forwarding definition and noinline to implement a poor man's alias, // as there isn't a good cross-platform way of defining one. -COMPILER_RT_ABI __attribute__((noinline)) float __extendhfsf2(uint16_t a) { +COMPILER_RT_ABI __NOINLINE float __extendhfsf2(uint16_t a) { return __extendXfYf2__(a); } Index: lib/builtins/fixunsdfdi.c =================================================================== --- lib/builtins/fixunsdfdi.c +++ lib/builtins/fixunsdfdi.c @@ -22,8 +22,8 @@ __fixunsdfdi(double a) { if (a <= 0.0) return 0; - su_int high = a/0x1p32f; - su_int low = a - (double)high*0x1p32f; + su_int high = a/4294967296.f; + su_int low = a - (double)high*4294967296.f; return ((du_int)high << 32) | low; } Index: lib/builtins/fixunssfdi.c =================================================================== --- lib/builtins/fixunssfdi.c +++ lib/builtins/fixunssfdi.c @@ -23,8 +23,8 @@ { if (a <= 0.0f) return 0; double da = a; - su_int high = da/0x1p32f; - su_int low = da - (double)high*0x1p32f; + su_int high = da/4294967296.f; + su_int low = da - (double)high*4294967296.f; return ((du_int)high << 32) | low; } Index: lib/builtins/fp_lib.h =================================================================== --- lib/builtins/fp_lib.h +++ lib/builtins/fp_lib.h @@ -38,6 +38,41 @@ # endif #endif +#ifdef _MSC_VER +#include + +uint32_t __inline __builtin_ctz(uint32_t value) { + uint32_t trailing_zero = 0; + if (_BitScanForward(&trailing_zero, value)) { + return trailing_zero; + } else { + return 32; + } +} + +uint32_t __inline __builtin_clz(uint32_t value) { + uint32_t leading_zero = 0; + if (_BitScanReverse(&leading_zero, value)) { + return 31 - leading_zero; + } else { + return 32; + } +} + +uint32_t __inline __builtin_clzll(uint64_t value) { + uint32_t leading_zero = 0; + if (_BitScanReverse64(&leading_zero, value)) { + return 63 - leading_zero; + } else { + return 64; + } +} + +uint32_t __inline __builtin_clzl(uint64_t value) { + return __builtin_clzll(value); +} +#endif + #if defined SINGLE_PRECISION typedef uint32_t rep_t; Index: lib/builtins/int_lib.h =================================================================== --- lib/builtins/int_lib.h +++ lib/builtins/int_lib.h @@ -35,7 +35,7 @@ # define COMPILER_RT_ABI __attribute__((pcs("aapcs"))) #else # define ARM_EABI_FNALIAS(aeabi_name, name) -# if defined(__arm__) && defined(_WIN32) +# if defined(__arm__) && defined(_WIN32) && !defined(_MSC_VER) # define COMPILER_RT_ABI __attribute__((pcs("aapcs"))) # else # define COMPILER_RT_ABI Index: lib/builtins/int_math.h =================================================================== --- lib/builtins/int_math.h +++ lib/builtins/int_math.h @@ -25,24 +25,54 @@ # define __has_builtin(x) 0 #endif -#define CRT_INFINITY __builtin_huge_valf() - -#define crt_isinf(x) __builtin_isinf((x)) -#define crt_isnan(x) __builtin_isnan((x)) - /* 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 +#ifdef _MSC_VER +#include +#include +#include + +#define CRT_INFINITY INFINITY + +#define crt_isfinite(x) _finite((x)) +#define crt_isinf(x) !_finite((x)) +#define crt_isnan(x) _isnan((x)) + +#define crt_copysign(x, y) copysign((x), (y)) +#define crt_copysignf(x, y) copysignf((x), (y)) +#define crt_copysignl(x, y) copysignl((x), (y)) + +#define crt_fabs(x) fabs((x)) +#define crt_fabsf(x) fabsf((x)) +#define crt_fabsl(x) fabs((x)) + +#define crt_fmax(x, y) __max((x), (y)) +#define crt_fmaxf(x, y) __max((x), (y)) +#define crt_fmaxl(x, y) __max((x), (y)) + +#define crt_logb(x) logb((x)) +#define crt_logbf(x) logbf((x)) +#define crt_logbl(x) logbl((x)) + +#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_INFINITY __builtin_huge_valf() + +#define crt_isinf(x) __builtin_isinf((x)) +#define crt_isnan(x) __builtin_isnan((x)) #define crt_copysign(x, y) __builtin_copysign((x), (y)) #define crt_copysignf(x, y) __builtin_copysignf((x), (y)) @@ -63,5 +93,5 @@ #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 /* _MSC_VER */ #endif /* INT_MATH_H */ Index: lib/builtins/int_types.h =================================================================== --- lib/builtins/int_types.h +++ lib/builtins/int_types.h @@ -140,5 +140,31 @@ long double f; } long_double_bits; +#if __STDC_VERSION__ >= 199901L +typedef float _Complex _Fcomplex; +typedef double _Complex _Dcomplex; +typedef long double _Complex _Lcomplex; + +#define _Creal(x) __real__(x) +#define _Cimag(x) __imag__(x) +#else +typedef struct +{ + float re, im; +} _Fcomplex; + +typedef struct +{ + double re, im; +} _Dcomplex; + +typedef struct +{ + long double re, im; +} _Lcomplex; + +#define _Creal(x) (x).re +#define _Cimag(x) (x).im +#endif #endif /* INT_TYPES_H */ Index: lib/builtins/int_util.h =================================================================== --- lib/builtins/int_util.h +++ lib/builtins/int_util.h @@ -19,16 +19,26 @@ #ifndef INT_UTIL_H #define INT_UTIL_H +#ifdef _MSC_VER +#define __NORETURN_MSVC __declspec(noreturn) +#define __NORETURN_GNU +#define __UNUSED_GNU +#else +#define __NORETURN_MSVC +#define __NORETURN_GNU __attribute__((noreturn)) +#define __UNUSED_GNU __attribute__((unused)) +#endif + /** \brief Trigger a program abort (or panic for kernel code). */ #define compilerrt_abort() compilerrt_abort_impl(__FILE__, __LINE__, \ __func__) -void compilerrt_abort_impl(const char *file, int line, - const char *function) __attribute__((noreturn)); +__NORETURN_MSVC void compilerrt_abort_impl(const char *file, int line, + const char *function) __NORETURN_GNU; #define COMPILE_TIME_ASSERT(expr) COMPILE_TIME_ASSERT1(expr, __COUNTER__) #define COMPILE_TIME_ASSERT1(expr, cnt) COMPILE_TIME_ASSERT2(expr, cnt) #define COMPILE_TIME_ASSERT2(expr, cnt) \ - typedef char ct_assert_##cnt[(expr) ? 1 : -1] __attribute__((unused)) + typedef char ct_assert_##cnt[(expr) ? 1 : -1] __UNUSED_GNU #endif /* INT_UTIL_H */ Index: lib/builtins/muldc3.c =================================================================== --- lib/builtins/muldc3.c +++ lib/builtins/muldc3.c @@ -17,17 +17,17 @@ /* Returns: the product of a + ib and c + id */ -COMPILER_RT_ABI double _Complex +COMPILER_RT_ABI _Dcomplex __muldc3(double __a, double __b, double __c, double __d) { double __ac = __a * __c; double __bd = __b * __d; double __ad = __a * __d; double __bc = __b * __c; - double _Complex z; - __real__ z = __ac - __bd; - __imag__ z = __ad + __bc; - if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) + _Dcomplex z; + _Creal(z) = __ac - __bd; + _Cimag(z) = __ad + __bc; + if (crt_isnan(_Creal(z)) && crt_isnan(_Cimag(z))) { int __recalc = 0; if (crt_isinf(__a) || crt_isinf(__b)) @@ -65,8 +65,8 @@ } if (__recalc) { - __real__ z = CRT_INFINITY * (__a * __c - __b * __d); - __imag__ z = CRT_INFINITY * (__a * __d + __b * __c); + _Creal(z) = CRT_INFINITY * (__a * __c - __b * __d); + _Cimag(z) = CRT_INFINITY * (__a * __d + __b * __c); } } return z; Index: lib/builtins/mulsc3.c =================================================================== --- lib/builtins/mulsc3.c +++ lib/builtins/mulsc3.c @@ -17,17 +17,17 @@ /* Returns: the product of a + ib and c + id */ -COMPILER_RT_ABI float _Complex +COMPILER_RT_ABI _Fcomplex __mulsc3(float __a, float __b, float __c, float __d) { float __ac = __a * __c; float __bd = __b * __d; float __ad = __a * __d; float __bc = __b * __c; - float _Complex z; - __real__ z = __ac - __bd; - __imag__ z = __ad + __bc; - if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) + _Fcomplex z; + _Creal(z) = __ac - __bd; + _Cimag(z) = __ad + __bc; + if (crt_isnan(_Creal(z)) && crt_isnan(_Cimag(z))) { int __recalc = 0; if (crt_isinf(__a) || crt_isinf(__b)) @@ -65,8 +65,8 @@ } if (__recalc) { - __real__ z = CRT_INFINITY * (__a * __c - __b * __d); - __imag__ z = CRT_INFINITY * (__a * __d + __b * __c); + _Creal(z) = CRT_INFINITY * (__a * __c - __b * __d); + _Cimag(z) = CRT_INFINITY * (__a * __d + __b * __c); } } return z; Index: lib/builtins/mulxc3.c =================================================================== --- lib/builtins/mulxc3.c +++ lib/builtins/mulxc3.c @@ -19,17 +19,17 @@ /* Returns: the product of a + ib and c + id */ -COMPILER_RT_ABI long double _Complex +COMPILER_RT_ABI _Lcomplex __mulxc3(long double __a, long double __b, long double __c, long double __d) { long double __ac = __a * __c; long double __bd = __b * __d; long double __ad = __a * __d; long double __bc = __b * __c; - long double _Complex z; - __real__ z = __ac - __bd; - __imag__ z = __ad + __bc; - if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) + _Lcomplex z; + _Creal(z) = __ac - __bd; + _Cimag(z) = __ad + __bc; + if (crt_isnan(_Creal(z)) && crt_isnan(_Cimag(z))) { int __recalc = 0; if (crt_isinf(__a) || crt_isinf(__b)) @@ -67,8 +67,8 @@ } if (__recalc) { - __real__ z = CRT_INFINITY * (__a * __c - __b * __d); - __imag__ z = CRT_INFINITY * (__a * __d + __b * __c); + _Creal(z) = CRT_INFINITY * (__a * __c - __b * __d); + _Cimag(z) = CRT_INFINITY * (__a * __d + __b * __c); } } return z; Index: lib/builtins/truncsfhf2.c =================================================================== --- lib/builtins/truncsfhf2.c +++ lib/builtins/truncsfhf2.c @@ -11,9 +11,15 @@ #define DST_HALF #include "fp_trunc_impl.inc" +#ifdef _MSC_VER +#define __NOINLINE __declspec(noinline) +#else +#define __NOINLINE __attribute__((noinline)) +#endif + // Use a forwarding definition and noinline to implement a poor man's alias, // as there isn't a good cross-platform way of defining one. -COMPILER_RT_ABI __attribute__((noinline)) uint16_t __truncsfhf2(float a) { +COMPILER_RT_ABI __NOINLINE uint16_t __truncsfhf2(float a) { return __truncXfYf2__(a); }