blob: dcc45fc39561466678a9afd2071a0f452a0445f8 [file] [log] [blame]
Howard Hinnant3c78ca02011-09-22 19:10:18 +00001// -*- C++ -*-
Howard Hinnant34388892011-09-28 21:39:20 +00002//===----------------------- support/win32/support.h ----------------------===//
Howard Hinnant3c78ca02011-09-22 19:10:18 +00003//
4// The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
Howard Hinnant34388892011-09-28 21:39:20 +000011#ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H
12#define _LIBCPP_SUPPORT_WIN32_SUPPORT_H
13
Howard Hinnant3c78ca02011-09-22 19:10:18 +000014/*
15 Functions and constants used in libc++ that are missing from the Windows C library.
16 */
17
Howard Hinnante4383372011-10-22 20:59:45 +000018#include <__config>
Howard Hinnant34388892011-09-28 21:39:20 +000019#include <wchar.h> // mbstate_t
20#include <stdio.h> // _snwprintf
21#define swprintf _snwprintf
22#define vswprintf _vsnwprintf
Howard Hinnante4383372011-10-22 20:59:45 +000023#define vfscnaf fscanf
Howard Hinnant34388892011-09-28 21:39:20 +000024
Howard Hinnante4383372011-10-22 20:59:45 +000025int vasprintf( char **sptr, const char *__restrict fmt , va_list ap );
26int asprintf( char **sptr, const char *__restrict fmt, ...);
27//int vfscanf( FILE *__restrict stream, const char *__restrict format,
28// va_list arg);
Howard Hinnant34388892011-09-28 21:39:20 +000029
Howard Hinnante4383372011-10-22 20:59:45 +000030size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src,
31 size_t nmc, size_t len, mbstate_t *__restrict ps );
32size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src,
33 size_t nwc, size_t len, mbstate_t *__restrict ps );
34
35#if defined(_MSC_VER)
36#define snprintf _snprintf
37inline int isblank( int c, locale_t /*loc*/ )
38{ return ( c == ' ' || c == '\t' ); }
39inline int iswblank( wint_t c, locale_t /*loc*/ )
40{ return ( c == L' ' || c == L'\t' ); }
41#include <xlocinfo.h>
42#define atoll _atoi64
43#define strtoll _strtoi64
44#define strtoull _strtoui64
45#define wcstoll _wcstoi64
46#define wcstoull _wcstoui64
47_LIBCPP_ALWAYS_INLINE float strtof( const char *nptr, char **endptr )
48{ return _Stof(nptr, endptr, 0); }
49_LIBCPP_ALWAYS_INLINE double strtod( const char *nptr, char **endptr )
50{ return _Stod(nptr, endptr, 0); }
51_LIBCPP_ALWAYS_INLINE long double strtold( const char *nptr, char **endptr )
52{ return _Stold(nptr, endptr, 0); }
53_LIBCPP_ALWAYS_INLINE float wcstof( const wchar_t *nptr, char** endptr )
54
55#define _Exit _exit
56
57#include <intrin.h>
58#define __builtin_popcount __popcnt
59#define __builtin_popcountl __popcnt
60#define __builtin_popcountll(__i) static_cast<int>(__popcnt64(__i))
61
62_LIBCPP_ALWAYS_INLINE int __builtin_ctz( unsigned int x )
63{
64 DWORD r = 0;
65 _BitScanReverse(&r, x);
66 return static_cast<int>(r);
67}
68// sizeof(long) == sizeof(int) on Windows
69_LIBCPP_ALWAYS_INLINE int __builtin_ctzl( unsigned long x )
70{ return __builtin_ctz( static_cast<int>(x) ); }
71_LIBCPP_ALWAYS_INLINE int __builtin_ctzll( unsigned long long x )
72{
73 DWORD r = 0;
74 _BitScanReverse64(&r, x);
75 return static_cast<int>(r);
76}
77_LIBCPP_ALWAYS_INLINE int __builtin_clz( unsigned int x )
78{
79 DWORD r = 0;
80 _BitScanForward(&r, x);
81 return static_cast<int>(r);
82}
83// sizeof(long) == sizeof(int) on Windows
84_LIBCPP_ALWAYS_INLINE int __builtin_clzl( unsigned long x )
85{ return __builtin_clz( static_cast<int>(x) ); }
86_LIBCPP_ALWAYS_INLINE int __builtin_clzll( unsigned long long x )
87{
88 DWORD r = 0;
89 _BitScanForward64(&r, x);
90 return static_cast<int>(r);
91}
92
93#endif
Howard Hinnant34388892011-09-28 21:39:20 +000094
95#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H