Skip to content

Commit

Permalink
Support: Add specializations for reverseBits to use builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenm committed Apr 3, 2020
1 parent 30ebafa commit ea397a7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions llvm/include/llvm/Support/MathExtras.h
Expand Up @@ -313,6 +313,34 @@ T reverseBits(T Val) {
return Val;
}

#if __has_builtin(__builtin_bitreverse8)
template<>
inline uint8_t reverseBits<uint8_t>(uint8_t Val) {
return __builtin_bitreverse8(Val);
}
#endif

#if __has_builtin(__builtin_bitreverse16)
template<>
inline uint16_t reverseBits<uint16_t>(uint16_t Val) {
return __builtin_bitreverse16(Val);
}
#endif

#if __has_builtin(__builtin_bitreverse32)
template<>
inline uint32_t reverseBits<uint32_t>(uint32_t Val) {
return __builtin_bitreverse32(Val);
}
#endif

#if __has_builtin(__builtin_bitreverse64)
template<>
inline uint64_t reverseBits<uint64_t>(uint64_t Val) {
return __builtin_bitreverse64(Val);
}
#endif

// NOTE: The following support functions use the _32/_64 extensions instead of
// type overloading so that signed and unsigned integers can be used without
// ambiguity.
Expand Down

0 comments on commit ea397a7

Please sign in to comment.