mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-01-09 07:58:16 +01:00
Merge pull request #417 from lioncash/swap
common: Move byte swapping functions to bit_utils.h
This commit is contained in:
commit
ad14a33672
2 changed files with 30 additions and 12 deletions
|
|
@ -12,6 +12,7 @@
|
|||
#include <type_traits>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Dynarmic::Common {
|
||||
|
||||
|
|
@ -199,4 +200,26 @@ inline T RotateRight(T value, size_t amount) {
|
|||
return static_cast<T>((x >> amount) | (x << (BitSize<T>() - amount)));
|
||||
}
|
||||
|
||||
constexpr u16 Swap16(u16 value) {
|
||||
return static_cast<u16>(u32{value} >> 8 | u32{value} << 8);
|
||||
}
|
||||
|
||||
constexpr u32 Swap32(u32 value) {
|
||||
return ((value & 0xFF000000U) >> 24) |
|
||||
((value & 0x00FF0000U) >> 8) |
|
||||
((value & 0x0000FF00U) << 8) |
|
||||
((value & 0x000000FFU) << 24);
|
||||
}
|
||||
|
||||
constexpr u64 Swap64(u64 value) {
|
||||
return ((value & 0xFF00000000000000ULL) >> 56) |
|
||||
((value & 0x00FF000000000000ULL) >> 40) |
|
||||
((value & 0x0000FF0000000000ULL) >> 24) |
|
||||
((value & 0x000000FF00000000ULL) >> 8) |
|
||||
((value & 0x00000000FF000000ULL) << 8) |
|
||||
((value & 0x0000000000FF0000ULL) << 24) |
|
||||
((value & 0x000000000000FF00ULL) << 40) |
|
||||
((value & 0x00000000000000FFULL) << 56);
|
||||
}
|
||||
|
||||
} // namespace Dynarmic::Common
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue