mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Define a popcount util
add include Define a popcount util Update MathUtils.h
This commit is contained in:
@@ -19,6 +19,10 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#if SWIFT_COMPILER_IS_MSVC
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
namespace swift {
|
||||
|
||||
/// Round the given value up to the given alignment, as a power of two.
|
||||
@@ -33,6 +37,15 @@ static inline size_t roundUpToAlignMask(size_t size, size_t alignMask) {
|
||||
return (size + alignMask) & ~alignMask;
|
||||
}
|
||||
|
||||
static inline unsigned popcount(unsigned value) {
|
||||
#if SWIFT_COMPILER_IS_MSVC
|
||||
return __popcnt(value);
|
||||
#else
|
||||
// Assume we have a compiler with this intrinsic.
|
||||
return __builtin_popcount(value);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace swift
|
||||
|
||||
#endif // #ifndef SWIFT_BASIC_MATH_UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user