diff options
author | Lioncash <mathew1800@gmail.com> | 2019-04-12 03:20:22 +0200 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2019-04-12 06:07:39 +0200 |
commit | 0d8ef2d3b9cea849d83b4d96529576f28bae5c7c (patch) | |
tree | 6e110e347e4b8e90887c945ce1271bbe88a666d4 /src | |
parent | common/swap: Mark byte swapping free functions with [[nodiscard]] and noexcept (diff) | |
download | yuzu-0d8ef2d3b9cea849d83b4d96529576f28bae5c7c.tar yuzu-0d8ef2d3b9cea849d83b4d96529576f28bae5c7c.tar.gz yuzu-0d8ef2d3b9cea849d83b4d96529576f28bae5c7c.tar.bz2 yuzu-0d8ef2d3b9cea849d83b4d96529576f28bae5c7c.tar.lz yuzu-0d8ef2d3b9cea849d83b4d96529576f28bae5c7c.tar.xz yuzu-0d8ef2d3b9cea849d83b4d96529576f28bae5c7c.tar.zst yuzu-0d8ef2d3b9cea849d83b4d96529576f28bae5c7c.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/common/swap.h | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/common/swap.h b/src/common/swap.h index 086449028..71932c2bb 100644 --- a/src/common/swap.h +++ b/src/common/swap.h @@ -83,15 +83,19 @@ namespace Common { return __builtin_bswap64(data); } #else -// Slow generic implementation. +// Generic implementation. [[nodiscard]] inline u16 swap16(u16 data) noexcept { return (data >> 8) | (data << 8); } [[nodiscard]] inline u32 swap32(u32 data) noexcept { - return (swap16(data) << 16) | swap16(data >> 16); + return ((data & 0xFF000000U) >> 24) | ((data & 0x00FF0000U) >> 8) | + ((data & 0x0000FF00U) << 8) | ((data & 0x000000FFU) << 24); } [[nodiscard]] inline u64 swap64(u64 data) noexcept { - return ((u64)swap32(data) << 32) | swap32(data >> 32); + return ((data & 0xFF00000000000000ULL) >> 56) | ((data & 0x00FF000000000000ULL) >> 40) | + ((data & 0x0000FF0000000000ULL) >> 24) | ((data & 0x000000FF00000000ULL) >> 8) | + ((data & 0x00000000FF000000ULL) << 8) | ((data & 0x0000000000FF0000ULL) << 24) | + ((data & 0x000000000000FF00ULL) << 40) | ((data & 0x00000000000000FFULL) << 56); } #endif |