80 cols fixes.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@198482 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c8d1bbab02
commit
6c27250223
@ -11,14 +11,13 @@
|
|||||||
#ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H
|
#ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H
|
||||||
#define _LIBCPP_SUPPORT_WIN32_SUPPORT_H
|
#define _LIBCPP_SUPPORT_WIN32_SUPPORT_H
|
||||||
|
|
||||||
/*
|
// Functions and constants used in libc++ that
|
||||||
Functions and constants used in libc++ that are missing from the Windows C library.
|
// are missing from the Windows C library.
|
||||||
*/
|
|
||||||
|
|
||||||
#include <wchar.h> // mbstate_t
|
#include <wchar.h> // mbstate_t
|
||||||
#include <cstdarg> // va_ macros
|
#include <cstdarg> // va_ macros
|
||||||
// "builtins" not implemented here for Clang or GCC as they provide implementations.
|
// "builtins" not implemented here for Clang or GCC as they provide
|
||||||
// Assuming required for elsewhere else, certainly MSVC.
|
// implementations. Assuming required for elsewhere else, certainly MSVC.
|
||||||
#if defined(_LIBCPP_MSVC)
|
#if defined(_LIBCPP_MSVC)
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#endif
|
#endif
|
||||||
@ -50,52 +49,77 @@ size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src,
|
|||||||
#define wcstoll _wcstoi64
|
#define wcstoll _wcstoi64
|
||||||
#define wcstoull _wcstoui64
|
#define wcstoull _wcstoui64
|
||||||
_LIBCPP_ALWAYS_INLINE float strtof(const char *nptr, char **endptr)
|
_LIBCPP_ALWAYS_INLINE float strtof(const char *nptr, char **endptr)
|
||||||
{ return _Stof(nptr, endptr, 0); }
|
{
|
||||||
|
return _Stof(nptr, endptr, 0);
|
||||||
|
}
|
||||||
_LIBCPP_ALWAYS_INLINE double strtod(const char *nptr, char **endptr)
|
_LIBCPP_ALWAYS_INLINE double strtod(const char *nptr, char **endptr)
|
||||||
{ return _Stod(nptr, endptr, 0); }
|
{
|
||||||
|
return _Stod(nptr, endptr, 0);
|
||||||
|
}
|
||||||
_LIBCPP_ALWAYS_INLINE long double strtold(const char *nptr, char **endptr)
|
_LIBCPP_ALWAYS_INLINE long double strtold(const char *nptr, char **endptr)
|
||||||
{ return _Stold(nptr, endptr, 0); }
|
{
|
||||||
|
return _Stold(nptr, endptr, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#define _Exit _exit
|
#define _Exit _exit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_LIBCPP_MSVC)
|
#if defined(_LIBCPP_MSVC)
|
||||||
|
|
||||||
// Bit builtin's make these assumptions when calling _BitScanForward/Reverse etc.
|
// Bit builtin's make these assumptions when calling _BitScanForward/Reverse
|
||||||
// These assumptions are expected to be true for Win32/Win64 which this file supports.
|
// etc. These assumptions are expected to be true for Win32/Win64 which this
|
||||||
|
// file supports.
|
||||||
static_assert(sizeof(unsigned long long) == 8, "");
|
static_assert(sizeof(unsigned long long) == 8, "");
|
||||||
static_assert(sizeof(unsigned long) == 4, "");
|
static_assert(sizeof(unsigned long) == 4, "");
|
||||||
static_assert(sizeof(unsigned int) == 4, "");
|
static_assert(sizeof(unsigned int) == 4, "");
|
||||||
|
|
||||||
_LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x) {
|
_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..
|
// Binary: 0101...
|
||||||
static const unsigned int m4 = 0x0f0f0f0f; //binary: 4 zeros, 4 ones ...
|
static const unsigned int m1 = 0x55555555;
|
||||||
static const unsigned int h01= 0x01010101; //the sum of 256 to the power of 0,1,2,3...
|
// Binary: 00110011..
|
||||||
x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits
|
static const unsigned int m2 = 0x33333333;
|
||||||
x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
|
// Binary: 4 zeros, 4 ones ...
|
||||||
x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits
|
static const unsigned int m4 = 0x0f0f0f0f;
|
||||||
return (x * h01) >> 24; //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24)
|
// The sum of 256 to the power of 0,1,2,3...
|
||||||
|
static const unsigned int h01 = 0x01010101;
|
||||||
|
// Put count of each 2 bits into those 2 bits.
|
||||||
|
x -= (x >> 1) & m1;
|
||||||
|
// Put count of each 4 bits into those 4 bits.
|
||||||
|
x = (x & m2) + ((x >> 2) & m2);
|
||||||
|
// Put count of each 8 bits into those 8 bits.
|
||||||
|
x = (x + (x >> 4)) & m4;
|
||||||
|
// Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24).
|
||||||
|
return (x * h01) >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
_LIBCPP_ALWAYS_INLINE int __builtin_popcountl(unsigned long x) {
|
_LIBCPP_ALWAYS_INLINE int __builtin_popcountl(unsigned long x)
|
||||||
|
{
|
||||||
return __builtin_popcount(static_cast<int>(x));
|
return __builtin_popcount(static_cast<int>(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
_LIBCPP_ALWAYS_INLINE int __builtin_popcountll(unsigned long long 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..
|
// Binary: 0101...
|
||||||
static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f; //binary: 4 zeros, 4 ones ...
|
static const unsigned long long m1 = 0x5555555555555555;
|
||||||
static const unsigned long long h01 = 0x0101010101010101; //the sum of 256 to the power of 0,1,2,3...
|
// Binary: 00110011..
|
||||||
x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits
|
static const unsigned long long m2 = 0x3333333333333333;
|
||||||
x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits
|
// Binary: 4 zeros, 4 ones ...
|
||||||
x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits
|
static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f;
|
||||||
return static_cast<int>((x * h01)>>56); //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
// The sum of 256 to the power of 0,1,2,3...
|
||||||
|
static const unsigned long long h01 = 0x0101010101010101;
|
||||||
|
// Put count of each 2 bits into those 2 bits.
|
||||||
|
x -= (x >> 1) & m1;
|
||||||
|
// Put count of each 4 bits into those 4 bits.
|
||||||
|
x = (x & m2) + ((x >> 2) & m2);
|
||||||
|
// Put count of each 8 bits into those 8 bits.
|
||||||
|
x = (x + (x >> 4)) & m4;
|
||||||
|
// Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
|
||||||
|
return static_cast<int>((x * h01) >> 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the number of trailing 0-bits in x,
|
// Returns the number of trailing 0-bits in x, starting at the least significant
|
||||||
// starting at the least significant bit position.
|
// bit position. If x is 0, the result is undefined.
|
||||||
// If x is 0, the result is undefined.
|
|
||||||
_LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
|
_LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
|
||||||
{
|
{
|
||||||
unsigned long where;
|
unsigned long where;
|
||||||
@ -106,10 +130,10 @@ _LIBCPP_ALWAYS_INLINE int __builtin_ctzll( unsigned long long mask )
|
|||||||
return static_cast<int>(where);
|
return static_cast<int>(where);
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
// Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
|
// Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
|
||||||
// Scan the Low Word
|
// Scan the Low Word.
|
||||||
if (_BitScanForward(&where, static_cast<unsigned long>(mask)))
|
if (_BitScanForward(&where, static_cast<unsigned long>(mask)))
|
||||||
return static_cast<int>(where);
|
return static_cast<int>(where);
|
||||||
// Scan the High Word
|
// Scan the High Word.
|
||||||
if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
|
if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
|
||||||
return static_cast<int>(where + 32); // Create a bit offset from the LSB.
|
return static_cast<int>(where + 32); // Create a bit offset from the LSB.
|
||||||
#else
|
#else
|
||||||
@ -136,9 +160,8 @@ _LIBCPP_ALWAYS_INLINE int __builtin_ctz( unsigned int mask )
|
|||||||
return __builtin_ctzl(static_cast<unsigned long>(mask));
|
return __builtin_ctzl(static_cast<unsigned long>(mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the number of leading 0-bits in x,
|
// Returns the number of leading 0-bits in x, starting at the most significant
|
||||||
// starting at the most significant bit position.
|
// bit position. If x is 0, the result is undefined.
|
||||||
// If x is 0, the result is undefined.
|
|
||||||
_LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
|
_LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
|
||||||
{
|
{
|
||||||
unsigned long where;
|
unsigned long where;
|
||||||
@ -150,7 +173,8 @@ _LIBCPP_ALWAYS_INLINE int __builtin_clzll( unsigned long long mask )
|
|||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
// Scan the high 32 bits.
|
// Scan the high 32 bits.
|
||||||
if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
|
if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
|
||||||
return static_cast<int>(63-(where+32)); // Create a bit offset from the MSB.
|
return static_cast<int>(63 -
|
||||||
|
(where + 32)); // Create a bit offset from the MSB.
|
||||||
// Scan the low 32 bits.
|
// Scan the low 32 bits.
|
||||||
if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
|
if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
|
||||||
return static_cast<int>(63 - where);
|
return static_cast<int>(63 - where);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user