From aa89418e8b76026ea3f512fcf9ab692dd89a7ba0 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 6 Feb 2021 21:23:56 +0000 Subject: [PATCH] bit_util: Add SwapHalves32 --- src/common/bit_util.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 93e6e652..81a62b44 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -218,6 +218,11 @@ constexpr T RotateRight(T value, size_t amount) { return static_cast((x >> amount) | (x << (BitSize() - amount))); } +constexpr u32 SwapHalves32(u32 value) { + return ((value & 0xFFFF0000U) >> 16) | + ((value & 0x0000FFFFU) << 16); +} + constexpr u16 SwapBytes16(u16 value) { return static_cast(u32{value} >> 8 | u32{value} << 8); }