Commit c0b82333 by Jeff Gilbert Committed by Commit Bot

Polyfill BitCount for ARM/ARM64 on MSVC.

Also _WIN64 implies _WIN32. Bug: angleproject:2858 Change-Id: I63e2ffd2e9e304171ea6adb99836733981cc1813 Reviewed-on: https://chromium-review.googlesource.com/1248441 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent e8dd0796
...@@ -70,4 +70,15 @@ void convert999E5toRGBFloats(unsigned int input, float *red, float *green, float ...@@ -70,4 +70,15 @@ void convert999E5toRGBFloats(unsigned int input, float *red, float *green, float
*blue = inputData->B * pow(2.0f, (int)inputData->E - g_sharedexp_bias - g_sharedexp_mantissabits); *blue = inputData->B * pow(2.0f, (int)inputData->E - g_sharedexp_bias - g_sharedexp_mantissabits);
} }
int BitCountPolyfill(uint32_t bits)
{
int ones = 0;
while (bits)
{
ones += bool(bits & 1);
bits >>= 1;
}
return ones;
}
} // namespace gl } // namespace gl
...@@ -929,26 +929,30 @@ inline uint32_t BitfieldReverse(uint32_t value) ...@@ -929,26 +929,30 @@ inline uint32_t BitfieldReverse(uint32_t value)
} }
// Count the 1 bits. // Count the 1 bits.
#if defined(ANGLE_PLATFORM_WINDOWS) #if defined(_M_IX86) || defined(_M_X64)
#define ANGLE_HAS_BITCOUNT_32
inline int BitCount(uint32_t bits) inline int BitCount(uint32_t bits)
{ {
return static_cast<int>(__popcnt(bits)); return static_cast<int>(__popcnt(bits));
} }
#if defined(ANGLE_IS_64_BIT_CPU) #if defined(_M_X64)
#define ANGLE_HAS_BITCOUNT_64
inline int BitCount(uint64_t bits) inline int BitCount(uint64_t bits)
{ {
return static_cast<int>(__popcnt64(bits)); return static_cast<int>(__popcnt64(bits));
} }
#endif // defined(ANGLE_IS_64_BIT_CPU) #endif // defined(_M_X64)
#endif // defined(ANGLE_PLATFORM_WINDOWS) #endif // defined(_M_IX86) || defined(_M_X64)
#if defined(ANGLE_PLATFORM_POSIX) #if defined(ANGLE_PLATFORM_POSIX)
#define ANGLE_HAS_BITCOUNT_32
inline int BitCount(uint32_t bits) inline int BitCount(uint32_t bits)
{ {
return __builtin_popcount(bits); return __builtin_popcount(bits);
} }
#if defined(ANGLE_IS_64_BIT_CPU) #if defined(ANGLE_IS_64_BIT_CPU)
#define ANGLE_HAS_BITCOUNT_64
inline int BitCount(uint64_t bits) inline int BitCount(uint64_t bits)
{ {
return __builtin_popcountll(bits); return __builtin_popcountll(bits);
...@@ -956,6 +960,24 @@ inline int BitCount(uint64_t bits) ...@@ -956,6 +960,24 @@ inline int BitCount(uint64_t bits)
#endif // defined(ANGLE_IS_64_BIT_CPU) #endif // defined(ANGLE_IS_64_BIT_CPU)
#endif // defined(ANGLE_PLATFORM_POSIX) #endif // defined(ANGLE_PLATFORM_POSIX)
int BitCountPolyfill(uint32_t bits);
#if !defined(ANGLE_HAS_BITCOUNT_32)
inline int BitCount(const uint32_t bits)
{
return BitCountPolyfill(bits);
}
#endif // !defined(ANGLE_HAS_BITCOUNT_32)
#if !defined(ANGLE_HAS_BITCOUNT_64)
inline int BitCount(const uint64_t bits)
{
return BitCount(static_cast<uint32_t>(bits >> 32)) + BitCount(static_cast<uint32_t>(bits));
}
#endif // !defined(ANGLE_HAS_BITCOUNT_64)
#undef ANGLE_HAS_BITCOUNT_32
#undef ANGLE_HAS_BITCOUNT_64
inline int BitCount(uint8_t bits) inline int BitCount(uint8_t bits)
{ {
return BitCount(static_cast<uint32_t>(bits)); return BitCount(static_cast<uint32_t>(bits));
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef COMMON_PLATFORM_H_ #ifndef COMMON_PLATFORM_H_
#define COMMON_PLATFORM_H_ #define COMMON_PLATFORM_H_
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32)
# define ANGLE_PLATFORM_WINDOWS 1 # define ANGLE_PLATFORM_WINDOWS 1
#elif defined(__APPLE__) #elif defined(__APPLE__)
# define ANGLE_PLATFORM_APPLE 1 # define ANGLE_PLATFORM_APPLE 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment