aboutsummaryrefslogtreecommitdiff
path: root/system/include/libcxx/support
diff options
context:
space:
mode:
authorBruce Mitchener <bruce.mitchener@gmail.com>2013-02-17 14:29:14 +0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2013-03-25 00:34:11 +0700
commit59ff5a6a3c3e1f5255c5cf29f98df633a77b89b3 (patch)
treec7660fa62600366e3479dbf6b2fd1d25709af1b5 /system/include/libcxx/support
parent80fd6f0bce2b95db6ec539c9275ce24585550e7c (diff)
Update to current libcxx.
This doesn't work yet as it needs to be customized for use with emscripten still.
Diffstat (limited to 'system/include/libcxx/support')
-rw-r--r--system/include/libcxx/support/solaris/floatingpoint.h5
-rw-r--r--system/include/libcxx/support/solaris/wchar.h38
-rw-r--r--system/include/libcxx/support/solaris/xlocale.h146
-rw-r--r--system/include/libcxx/support/win32/limits_win32.h79
-rw-r--r--system/include/libcxx/support/win32/locale_win32.h116
-rw-r--r--system/include/libcxx/support/win32/math_win32.h113
-rw-r--r--system/include/libcxx/support/win32/support.h115
7 files changed, 612 insertions, 0 deletions
diff --git a/system/include/libcxx/support/solaris/floatingpoint.h b/system/include/libcxx/support/solaris/floatingpoint.h
new file mode 100644
index 00000000..21b0349a
--- /dev/null
+++ b/system/include/libcxx/support/solaris/floatingpoint.h
@@ -0,0 +1,5 @@
+#define atof sun_atof
+#define strtod sun_strtod
+#include_next "floatingpoint.h"
+#undef atof
+#undef strtod
diff --git a/system/include/libcxx/support/solaris/wchar.h b/system/include/libcxx/support/solaris/wchar.h
new file mode 100644
index 00000000..05a72417
--- /dev/null
+++ b/system/include/libcxx/support/solaris/wchar.h
@@ -0,0 +1,38 @@
+#define iswalpha sun_iswalpha
+#define iswupper sun_iswupper
+#define iswlower sun_iswlower
+#define iswdigit sun_iswdigit
+#define iswxdigit sun_iswxdigit
+#define iswalnum sun_iswalnum
+#define iswspace sun_iswspace
+#define iswpunct sun_iswpunct
+#define iswprint sun_iswprint
+#define iswgraph sun_iswgraph
+#define iswcntrl sun_iswcntrl
+#define iswctype sun_iswctype
+#define towlower sun_towlower
+#define towupper sun_towupper
+#define wcswcs sun_wcswcs
+#define wcswidth sun_wcswidth
+#define wcwidth sun_wcwidth
+#define wctype sun_wctype
+#define _WCHAR_T 1
+#include_next "wchar.h"
+#undef iswalpha
+#undef iswupper
+#undef iswlower
+#undef iswdigit
+#undef iswxdigit
+#undef iswalnum
+#undef iswspace
+#undef iswpunct
+#undef iswprint
+#undef iswgraph
+#undef iswcntrl
+#undef iswctype
+#undef towlower
+#undef towupper
+#undef wcswcs
+#undef wcswidth
+#undef wcwidth
+#undef wctype
diff --git a/system/include/libcxx/support/solaris/xlocale.h b/system/include/libcxx/support/solaris/xlocale.h
new file mode 100644
index 00000000..359508d9
--- /dev/null
+++ b/system/include/libcxx/support/solaris/xlocale.h
@@ -0,0 +1,146 @@
+////////////////////////////////////////////////////////////////////////////////
+// Minimal xlocale implementation for Solaris. This implements the subset of
+// the xlocale APIs that libc++ depends on.
+////////////////////////////////////////////////////////////////////////////////
+#ifndef __XLOCALE_H_INCLUDED
+#define __XLOCALE_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct _LC_locale_t* locale_t;
+
+#define LC_COLLATE_MASK (1<<0)
+#define LC_CTYPE_MASK (1<<1)
+#define LC_MESSAGES_MASK (1<<2)
+#define LC_MONETARY_MASK (1<<3)
+#define LC_NUMERIC_MASK (1<<4)
+#define LC_TIME_MASK (1<<5)
+#define LC_ALL_MASK (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK | \
+ LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK)
+
+#define LC_GLOBAL_LOCALE ((locale_t)-1)
+
+size_t __mb_cur_max(locale_t l);
+#define MB_CUR_MAX_L(l) __mb_cur_max(l)
+
+locale_t newlocale(int mask, const char * locale, locale_t base);
+void freelocale(locale_t loc);
+
+wint_t btowc_l(int __c, locale_t __l);
+
+int wctob_l(wint_t __c, locale_t __l);
+
+size_t wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l);
+
+size_t mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
+ mbstate_t *__ps, locale_t __l);
+
+int mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l);
+
+size_t mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l);
+
+struct lconv *localeconv_l(locale_t __l);
+
+size_t mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
+ mbstate_t *__ps, locale_t __l);
+
+int sprintf_l(char *__s, locale_t __l, const char *__format, ...);
+
+int snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...);
+
+int asprintf_l(char **__s, locale_t __l, const char *__format, ...);
+
+int sscanf_l(const char *__s, locale_t __l, const char *__format, ...);
+
+int isalnum_l(int,locale_t);
+int isalpha_l(int,locale_t);
+int isblank_l(int,locale_t);
+int iscntrl_l(int,locale_t);
+int isdigit_l(int,locale_t);
+int isgraph_l(int,locale_t);
+int islower_l(int,locale_t);
+int isprint_l(int,locale_t);
+int ispunct_l(int,locale_t);
+int isspace_l(int,locale_t);
+int isupper_l(int,locale_t);
+int isxdigit_l(int,locale_t);
+
+int iswalnum_l(wchar_t,locale_t);
+int iswalpha_l(wchar_t,locale_t);
+int iswblank_l(wchar_t,locale_t);
+int iswcntrl_l(wchar_t,locale_t);
+int iswdigit_l(wchar_t,locale_t);
+int iswgraph_l(wchar_t,locale_t);
+int iswlower_l(wchar_t,locale_t);
+int iswprint_l(wchar_t,locale_t);
+int iswpunct_l(wchar_t,locale_t);
+int iswspace_l(wchar_t,locale_t);
+int iswupper_l(wchar_t,locale_t);
+int iswxdigit_l(wchar_t,locale_t);
+
+int iswctype_l(wint_t, wctype_t, locale_t);
+
+int toupper_l(int __c, locale_t __l);
+int tolower_l(int __c, locale_t __l);
+wint_t towupper_l(wint_t __c, locale_t __l);
+wint_t towlower_l(wint_t __c, locale_t __l);
+
+
+int strcoll_l(const char *__s1, const char *__s2, locale_t __l);
+int wcscoll_l(const wchar_t *__s1, const wchar_t *__s2, locale_t __l);
+size_t strftime_l(char *__s, size_t __size, const char *__fmt, const struct tm
+ *__tm, locale_t __l);
+
+size_t strxfrm_l(char *__s1, const char *__s2, size_t __n, locale_t __l);
+
+size_t wcsxfrm_l(wchar_t *__ws1, const wchar_t *__ws2, size_t __n,
+ locale_t __l);
+
+
+
+size_t
+mbsnrtowcs_l(wchar_t * __restrict dst, const char ** __restrict src,
+ size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc);
+
+
+size_t
+wcsnrtombs_l(char * __restrict dst, const wchar_t ** __restrict src,
+ size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc);
+
+locale_t __cloc(void);
+
+// FIXME: These are quick-and-dirty hacks to make things pretend to work
+static inline
+long long strtoll_l(const char *__nptr, char **__endptr,
+ int __base, locale_t __loc) {
+ return strtoll(__nptr, __endptr, __base);
+}
+static inline
+long strtol_l(const char *__nptr, char **__endptr,
+ int __base, locale_t __loc) {
+ return strtol(__nptr, __endptr, __base);
+}
+static inline
+long double strtold_l(const char *__nptr, char **__endptr,
+ locale_t __loc) {
+ return strtold(__nptr, __endptr);
+}
+static inline
+unsigned long long strtoull_l(const char *__nptr, char **__endptr,
+ int __base, locale_t __loc) {
+ return strtoull(__nptr, __endptr, __base);
+}
+static inline
+unsigned long strtoul_l(const char *__nptr, char **__endptr,
+ int __base, locale_t __loc) {
+ return strtoul(__nptr, __endptr, __base);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/system/include/libcxx/support/win32/limits_win32.h b/system/include/libcxx/support/win32/limits_win32.h
new file mode 100644
index 00000000..671631df
--- /dev/null
+++ b/system/include/libcxx/support/win32/limits_win32.h
@@ -0,0 +1,79 @@
+// -*- C++ -*-
+//===--------------------- support/win32/limits_win32.h -------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
+#define _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
+
+#if !defined(_MSC_VER)
+#error "This header is MSVC specific, Clang and GCC should not include it"
+#else
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include <windows.h> // ymath.h works correctly
+
+#include <float.h> // limit constants
+
+#define __FLT_MANT_DIG__ FLT_MANT_DIG
+#define __FLT_DIG__ FLT_DIG
+#define __FLT_RADIX__ FLT_RADIX
+#define __FLT_MIN_EXP__ FLT_MIN_EXP
+#define __FLT_MIN_10_EXP__ FLT_MIN_10_EXP
+#define __FLT_MAX_EXP__ FLT_MAX_EXP
+#define __FLT_MAX_10_EXP__ FLT_MAX_10_EXP
+#define __FLT_MIN__ FLT_MIN
+#define __FLT_MAX__ FLT_MAX
+#define __FLT_EPSILON__ FLT_EPSILON
+// predefined by MinGW GCC
+#define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F
+
+#define __DBL_MANT_DIG__ DBL_MANT_DIG
+#define __DBL_DIG__ DBL_DIG
+#define __DBL_RADIX__ DBL_RADIX
+#define __DBL_MIN_EXP__ DBL_MIN_EXP
+#define __DBL_MIN_10_EXP__ DBL_MIN_10_EXP
+#define __DBL_MAX_EXP__ DBL_MAX_EXP
+#define __DBL_MAX_10_EXP__ DBL_MAX_10_EXP
+#define __DBL_MIN__ DBL_MIN
+#define __DBL_MAX__ DBL_MAX
+#define __DBL_EPSILON__ DBL_EPSILON
+// predefined by MinGW GCC
+#define __DBL_DENORM_MIN__ double(4.94065645841246544177e-324L)
+
+#define __LDBL_MANT_DIG__ LDBL_MANT_DIG
+#define __LDBL_DIG__ LDBL_DIG
+#define __LDBL_RADIX__ LDBL_RADIX
+#define __LDBL_MIN_EXP__ LDBL_MIN_EXP
+#define __LDBL_MIN_10_EXP__ LDBL_MIN_10_EXP
+#define __LDBL_MAX_EXP__ LDBL_MAX_EXP
+#define __LDBL_MAX_10_EXP__ LDBL_MAX_10_EXP
+#define __LDBL_MIN__ LDBL_MIN
+#define __LDBL_MAX__ LDBL_MAX
+#define __LDBL_EPSILON__ LDBL_EPSILON
+// predefined by MinGW GCC
+#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
+
+// __builtin replacements/workarounds
+#include <math.h> // HUGE_VAL
+#include <ymath.h> // internal MSVC header providing the needed functionality
+#define __builtin_huge_val() HUGE_VAL
+#define __builtin_huge_valf() _FInf._Float
+#define __builtin_huge_vall() _LInf._Long_double
+#define __builtin_nan(__dummy) _Nan._Double
+#define __builtin_nanf(__dummy) _FNan._Float
+#define __builtin_nanl(__dummmy) _LNan._Long_double
+#define __builtin_nans(__dummy) _Snan._Double
+#define __builtin_nansf(__dummy) _FSnan._Float
+#define __builtin_nansl(__dummy) _LSnan._Long_double
+
+#endif // _MSC_VER
+
+#endif // _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
diff --git a/system/include/libcxx/support/win32/locale_win32.h b/system/include/libcxx/support/win32/locale_win32.h
new file mode 100644
index 00000000..e035420f
--- /dev/null
+++ b/system/include/libcxx/support/win32/locale_win32.h
@@ -0,0 +1,116 @@
+// -*- C++ -*-
+//===--------------------- support/win32/locale_win32.h -------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
+#define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
+
+// ctype mask table defined in msvcrt.dll
+extern "C" unsigned short __declspec(dllimport) _ctype[];
+
+#include "support/win32/support.h"
+#include <memory>
+#include <xlocinfo.h> // _locale_t
+#define locale_t _locale_t
+#define LC_COLLATE_MASK _M_COLLATE
+#define LC_CTYPE_MASK _M_CTYPE
+#define LC_MONETARY_MASK _M_MONETARY
+#define LC_NUMERIC_MASK _M_NUMERIC
+#define LC_TIME_MASK _M_TIME
+#define LC_MESSAGES_MASK _M_MESSAGES
+#define LC_ALL_MASK ( LC_COLLATE_MASK \
+ | LC_CTYPE_MASK \
+ | LC_MESSAGES_MASK \
+ | LC_MONETARY_MASK \
+ | LC_NUMERIC_MASK \
+ | LC_TIME_MASK )
+#define freelocale _free_locale
+// FIXME: base currently unused. Needs manual work to construct the new locale
+locale_t newlocale( int mask, const char * locale, locale_t base );
+locale_t uselocale( locale_t newloc );
+lconv *localeconv_l( locale_t loc );
+size_t mbrlen_l( const char *__restrict__ s, size_t n,
+ mbstate_t *__restrict__ ps, locale_t loc);
+size_t mbsrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
+ size_t len, mbstate_t *__restrict__ ps, locale_t loc );
+size_t wcrtomb_l( char *__restrict__ s, wchar_t wc, mbstate_t *__restrict__ ps,
+ locale_t loc);
+size_t mbrtowc_l( wchar_t *__restrict__ pwc, const char *__restrict__ s,
+ size_t n, mbstate_t *__restrict__ ps, locale_t loc);
+size_t mbsnrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
+ size_t nms, size_t len, mbstate_t *__restrict__ ps, locale_t loc);
+size_t wcsnrtombs_l( char *__restrict__ dst, const wchar_t **__restrict__ src,
+ size_t nwc, size_t len, mbstate_t *__restrict__ ps, locale_t loc);
+wint_t btowc_l( int c, locale_t loc );
+int wctob_l( wint_t c, locale_t loc );
+typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
+typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
+_LIBCPP_ALWAYS_INLINE inline
+decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
+{
+ __locale_raii __current( uselocale(__l), uselocale );
+ return MB_CUR_MAX;
+}
+
+// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
+#include <stdio.h>
+#define mbtowc_l _mbtowc_l
+#define strtoll_l _strtoi64_l
+#define strtoull_l _strtoui64_l
+// FIXME: current msvcrt does not know about long double
+#define strtold_l _strtod_l
+#define islower_l _islower_l
+#define isupper_l _isupper_l
+#define isdigit_l _isdigit_l
+#define isxdigit_l _isxdigit_l
+#define strcoll_l _strcoll_l
+#define strxfrm_l _strxfrm_l
+#define wcscoll_l _wcscoll_l
+#define wcsxfrm_l _wcsxfrm_l
+#define toupper_l _toupper_l
+#define tolower_l _tolower_l
+#define iswspace_l _iswspace_l
+#define iswprint_l _iswprint_l
+#define iswcntrl_l _iswcntrl_l
+#define iswupper_l _iswupper_l
+#define iswlower_l _iswlower_l
+#define iswalpha_l _iswalpha_l
+#define iswdigit_l _iswdigit_l
+#define iswpunct_l _iswpunct_l
+#define iswxdigit_l _iswxdigit_l
+#define towupper_l _towupper_l
+#define towlower_l _towlower_l
+#define strftime_l _strftime_l
+#define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ )
+#define vsscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ )
+#define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ )
+#define snprintf_l( __s, __n, __l, __f, ... ) _snprintf_l( __s, __n, __f, __l, __VA_ARGS__ )
+#define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ )
+#define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ )
+int asprintf_l( char **ret, locale_t loc, const char *format, ... );
+int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap );
+
+
+// not-so-pressing FIXME: use locale to determine blank characters
+inline int isblank_l( int c, locale_t /*loc*/ )
+{
+ return ( c == ' ' || c == '\t' );
+}
+inline int iswblank_l( wint_t c, locale_t /*loc*/ )
+{
+ return ( c == L' ' || c == L'\t' );
+}
+
+#ifdef _MSC_VER
+inline int isblank( int c, locale_t /*loc*/ )
+{ return ( c == ' ' || c == '\t' ); }
+inline int iswblank( wint_t c, locale_t /*loc*/ )
+{ return ( c == L' ' || c == L'\t' ); }
+#endif // _MSC_VER
+#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
diff --git a/system/include/libcxx/support/win32/math_win32.h b/system/include/libcxx/support/win32/math_win32.h
new file mode 100644
index 00000000..41c50d62
--- /dev/null
+++ b/system/include/libcxx/support/win32/math_win32.h
@@ -0,0 +1,113 @@
+// -*- C++ -*-
+//===---------------------- support/win32/math_win32.h --------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
+#define _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
+
+#if !defined(_MSC_VER)
+#error "This header is MSVC specific, Clang and GCC should not include it"
+#else
+
+#include <math.h>
+
+typedef float float_t;
+typedef double double_t;
+
+_LIBCPP_ALWAYS_INLINE bool isfinite( double num )
+{
+ return _finite(num) != 0;
+}
+_LIBCPP_ALWAYS_INLINE bool isinf( double num )
+{
+ return !isfinite(num) && !_isnan(num);
+}
+_LIBCPP_ALWAYS_INLINE bool isnan( double num )
+{
+ return _isnan(num) != 0;
+}
+_LIBCPP_ALWAYS_INLINE bool isnormal( double num )
+{
+ int class_ = _fpclass(num);
+ return class_ == _FPCLASS_NN || class_ == _FPCLASS_PN;
+}
+
+_LIBCPP_ALWAYS_INLINE bool isgreater( double x, double y )
+{
+ if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x > y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool isgreaterequal( double x, double y )
+{
+ if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x >= y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool isless( double x, double y )
+{
+ if(_fpclass(x) == _FPCLASS_SNAN || _fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x < y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool islessequal( double x, double y )
+{
+ if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x <= y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool islessgreater( double x, double y )
+{
+ if(::_fpclass(x) == _FPCLASS_SNAN || ::_fpclass(y) == _FPCLASS_SNAN) return false;
+ else return x < y || x > y;
+}
+
+_LIBCPP_ALWAYS_INLINE bool isunordered( double x, double y )
+{
+ return isnan(x) || isnan(y);
+}
+_LIBCPP_ALWAYS_INLINE bool signbit( double num )
+{
+ switch(_fpclass(num))
+ {
+ case _FPCLASS_SNAN:
+ case _FPCLASS_QNAN:
+ case _FPCLASS_NINF:
+ case _FPCLASS_NN:
+ case _FPCLASS_ND:
+ case _FPCLASS_NZ:
+ return true;
+ case _FPCLASS_PZ:
+ case _FPCLASS_PD:
+ case _FPCLASS_PN:
+ case _FPCLASS_PINF:
+ return false;
+ }
+ return false;
+}
+_LIBCPP_ALWAYS_INLINE float copysignf( float x, float y )
+{
+ return (signbit (x) != signbit (y) ? - x : x);
+}
+_LIBCPP_ALWAYS_INLINE double copysign( double x, double y )
+{
+ return ::_copysign(x,y);
+}
+_LIBCPP_ALWAYS_INLINE double copysignl( long double x, long double y )
+{
+ return ::_copysignl(x,y);
+}
+_LIBCPP_ALWAYS_INLINE int fpclassify( double num )
+{
+ return _fpclass(num);
+}
+
+#endif // _MSC_VER
+
+#endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
diff --git a/system/include/libcxx/support/win32/support.h b/system/include/libcxx/support/win32/support.h
new file mode 100644
index 00000000..0b8a912a
--- /dev/null
+++ b/system/include/libcxx/support/win32/support.h
@@ -0,0 +1,115 @@
+// -*- C++ -*-
+//===----------------------- support/win32/support.h ----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H
+#define _LIBCPP_SUPPORT_WIN32_SUPPORT_H
+
+/*
+ Functions and constants used in libc++ that are missing from the Windows C library.
+ */
+
+#include <__config>
+#include <wchar.h> // mbstate_t
+#include <stdio.h> // _snwprintf
+#define swprintf _snwprintf
+#define vswprintf _vsnwprintf
+#define vfscnaf fscanf
+
+int vasprintf( char **sptr, const char *__restrict fmt , va_list ap );
+int asprintf( char **sptr, const char *__restrict fmt, ...);
+//int vfscanf( FILE *__restrict stream, const char *__restrict format,
+// va_list arg);
+
+size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src,
+ size_t nmc, size_t len, mbstate_t *__restrict ps );
+size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src,
+ size_t nwc, size_t len, mbstate_t *__restrict ps );
+
+#if defined(_MSC_VER)
+#define snprintf _snprintf
+
+#include <xlocinfo.h>
+#define atoll _atoi64
+#define strtoll _strtoi64
+#define strtoull _strtoui64
+#define wcstoll _wcstoi64
+#define wcstoull _wcstoui64
+_LIBCPP_ALWAYS_INLINE float strtof( const char *nptr, char **endptr )
+{ return _Stof(nptr, endptr, 0); }
+_LIBCPP_ALWAYS_INLINE double strtod( const char *nptr, char **endptr )
+{ return _Stod(nptr, endptr, 0); }
+_LIBCPP_ALWAYS_INLINE long double strtold( const char *nptr, char **endptr )
+{ return _Stold(nptr, endptr, 0); }
+
+#define _Exit _exit
+
+#ifndef __clang__ // MSVC-based Clang also defines _MSC_VER
+#include <intrin.h>
+
+_LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x) {
+ static const unsigned int m1 = 0x55555555; //binary: 0101...
+ static const unsigned int m2 = 0x33333333; //binary: 00110011..
+ static const unsigned int m4 = 0x0f0f0f0f; //binary: 4 zeros, 4 ones ...
+ static const unsigned int h01= 0x01010101; //the sum of 256 to the power of 0,1,2,3...
+ x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits
+ x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
+ x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits
+ return (x * h01) >> 24; //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24)
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_popcountl(unsigned long x) {
+ return __builtin_popcount(static_cast<int>(x));
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x) {
+ static const unsigned long long m1 = 0x5555555555555555; //binary: 0101...
+ static const unsigned long long m2 = 0x3333333333333333; //binary: 00110011..
+ static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f; //binary: 4 zeros, 4 ones ...
+ static const unsigned long long h01 = 0x0101010101010101; //the sum of 256 to the power of 0,1,2,3...
+ x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits
+ x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
+ x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits
+ return static_cast<int>((x * h01)>>56); //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
+}
+
+_LIBCPP_ALWAYS_INLINE int __builtin_ctz( unsigned int x )
+{
+ DWORD r = 0;
+ _BitScanReverse(&r, x);
+ return static_cast<int>(r);
+}
+// sizeof(long) == sizeof(int) on Windows
+_LIBCPP_ALWAYS_INLINE int __builtin_ctzl( unsigned long x )
+{ return __builtin_ctz( static_cast<int>(x) ); }
+_LIBCPP_ALWAYS_INLINE int __builtin_ctzll( unsigned long long x )
+{
+ DWORD r = 0;
+ _BitScanReverse64(&r, x);
+ return static_cast<int>(r);
+}
+_LIBCPP_ALWAYS_INLINE int __builtin_clz( unsigned int x )
+{
+ DWORD r = 0;
+ _BitScanForward(&r, x);
+ return static_cast<int>(r);
+}
+// sizeof(long) == sizeof(int) on Windows
+_LIBCPP_ALWAYS_INLINE int __builtin_clzl( unsigned long x )
+{ return __builtin_clz( static_cast<int>(x) ); }
+_LIBCPP_ALWAYS_INLINE int __builtin_clzll( unsigned long long x )
+{
+ DWORD r = 0;
+ _BitScanForward64(&r, x);
+ return static_cast<int>(r);
+}
+#endif // !__clang__
+#endif // _MSC_VER
+
+#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H