diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h index 78afb3bc1109..16da3046c8ce 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -313,6 +313,34 @@ T reverseBits(T Val) { return Val; } +#if __has_builtin(__builtin_bitreverse8) +template<> +inline uint8_t reverseBits(uint8_t Val) { + return __builtin_bitreverse8(Val); +} +#endif + +#if __has_builtin(__builtin_bitreverse16) +template<> +inline uint16_t reverseBits(uint16_t Val) { + return __builtin_bitreverse16(Val); +} +#endif + +#if __has_builtin(__builtin_bitreverse32) +template<> +inline uint32_t reverseBits(uint32_t Val) { + return __builtin_bitreverse32(Val); +} +#endif + +#if __has_builtin(__builtin_bitreverse64) +template<> +inline uint64_t reverseBits(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.