Index: src/base/bits.h |
diff --git a/src/base/bits.h b/src/base/bits.h |
index 4ba3c47ad96acb1d4923ca8493ca024070e99259..0e7662488428899bb8ca96677d873fcabac284db 100644 |
--- a/src/base/bits.h |
+++ b/src/base/bits.h |
@@ -92,6 +92,20 @@ inline unsigned CountLeadingZeros64(uint64_t value) { |
} |
+// ReverseBits(value) returns |value| in reverse bit order. |
+template <typename T> |
+T ReverseBits(T value) { |
+ DCHECK((sizeof(value) == 1) || (sizeof(value) == 2) || (sizeof(value) == 4) || |
+ (sizeof(value) == 8)); |
+ T result = 0; |
+ for (unsigned i = 0; i < (sizeof(value) * 8); i++) { |
+ result = (result << 1) | (value & 1); |
+ value >>= 1; |
+ } |
+ return result; |
+} |
+ |
+ |
// CountTrailingZeros32(value) returns the number of zero bits preceding the |
// least significant 1 bit in |value| if |value| is non-zero, otherwise it |
// returns 32. |