[llvm] ea397a7 - Support: Add specializations for reverseBits to use builtin
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 3 11:53:24 PDT 2020
Author: Matt Arsenault
Date: 2020-04-03T14:52:54-04:00
New Revision: ea397a76f56fda7883f0104789d2084001409a49
URL: https://github.com/llvm/llvm-project/commit/ea397a76f56fda7883f0104789d2084001409a49
DIFF: https://github.com/llvm/llvm-project/commit/ea397a76f56fda7883f0104789d2084001409a49.diff
LOG: Support: Add specializations for reverseBits to use builtin
Added:
Modified:
llvm/include/llvm/Support/MathExtras.h
Removed:
################################################################################
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>(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.
More information about the llvm-commits
mailing list