Skip to content

Commit ea397a7

Browse files
committed
Support: Add specializations for reverseBits to use builtin
1 parent 30ebafa commit ea397a7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

llvm/include/llvm/Support/MathExtras.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,34 @@ T reverseBits(T Val) {
313313
return Val;
314314
}
315315

316+
#if __has_builtin(__builtin_bitreverse8)
317+
template<>
318+
inline uint8_t reverseBits<uint8_t>(uint8_t Val) {
319+
return __builtin_bitreverse8(Val);
320+
}
321+
#endif
322+
323+
#if __has_builtin(__builtin_bitreverse16)
324+
template<>
325+
inline uint16_t reverseBits<uint16_t>(uint16_t Val) {
326+
return __builtin_bitreverse16(Val);
327+
}
328+
#endif
329+
330+
#if __has_builtin(__builtin_bitreverse32)
331+
template<>
332+
inline uint32_t reverseBits<uint32_t>(uint32_t Val) {
333+
return __builtin_bitreverse32(Val);
334+
}
335+
#endif
336+
337+
#if __has_builtin(__builtin_bitreverse64)
338+
template<>
339+
inline uint64_t reverseBits<uint64_t>(uint64_t Val) {
340+
return __builtin_bitreverse64(Val);
341+
}
342+
#endif
343+
316344
// NOTE: The following support functions use the _32/_64 extensions instead of
317345
// type overloading so that signed and unsigned integers can be used without
318346
// ambiguity.

0 commit comments

Comments
 (0)