diff --git a/CMakeLists.txt b/CMakeLists.txt index 01467f9b11..12f85e629d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -444,7 +444,6 @@ add_library(Common STATIC Common/BitSet.h Common/Buffer.h Common/Buffer.cpp - Common/ByteSwap.h Common/CodeBlock.h Common/ColorConv.cpp Common/ColorConv.h diff --git a/Common/BitSet.h b/Common/BitSet.h index 2fbc80011b..caf7951509 100644 --- a/Common/BitSet.h +++ b/Common/BitSet.h @@ -2,6 +2,8 @@ #pragma once +#include +#include // for byte swapping #include #include "CommonTypes.h" @@ -39,3 +41,28 @@ inline int CountSetBits(u64 val) { return __builtin_popcountll(val); } inline int LeastSignificantSetBit(u32 val) { return __builtin_ctz(val); } inline int LeastSignificantSetBit(u64 val) { return __builtin_ctzll(val); } #endif + +// Byteswapping +// Just in case this has been defined by platform +#undef swap16 +#undef swap32 +#undef swap64 + +#ifdef _WIN32 +inline uint16_t swap16(uint16_t _data) { return _byteswap_ushort(_data); } +inline uint32_t swap32(uint32_t _data) { return _byteswap_ulong(_data); } +inline uint64_t swap64(uint64_t _data) { return _byteswap_uint64(_data); } +#elif defined(__GNUC__) +inline uint16_t swap16(uint16_t _data) { return __builtin_bswap16(_data); } +inline uint32_t swap32(uint32_t _data) { return __builtin_bswap32(_data); } +inline uint64_t swap64(uint64_t _data) { return __builtin_bswap64(_data); } +#else +// Slow generic implementation. Hopefully this never hits +inline uint16_t swap16(uint16_t data) { return (data >> 8) | (data << 8); } +inline uint32_t swap32(uint32_t data) { return (swap16(data) << 16) | swap16(data >> 16); } +inline uint64_t swap64(uint64_t data) { return ((uint64_t)swap32(data) << 32) | swap32(data >> 32); } +#endif + +inline uint16_t swap16(const uint8_t* _pData) { return swap16(*(const uint16_t*)_pData); } +inline uint32_t swap32(const uint8_t* _pData) { return swap32(*(const uint32_t*)_pData); } +inline uint64_t swap64(const uint8_t* _pData) { return swap64(*(const uint64_t*)_pData); } diff --git a/Common/ByteSwap.h b/Common/ByteSwap.h deleted file mode 100644 index 21274cd7d1..0000000000 --- a/Common/ByteSwap.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include // for byte swapping - -// Byteswapping -// Just in case this has been defined by platform -#undef swap16 -#undef swap32 -#undef swap64 - -#ifdef _WIN32 -inline uint16_t swap16(uint16_t _data) { return _byteswap_ushort(_data); } -inline uint32_t swap32(uint32_t _data) { return _byteswap_ulong(_data); } -inline uint64_t swap64(uint64_t _data) { return _byteswap_uint64(_data); } -#elif defined(__GNUC__) -inline uint16_t swap16(uint16_t _data) { return __builtin_bswap16(_data); } -inline uint32_t swap32(uint32_t _data) { return __builtin_bswap32(_data); } -inline uint64_t swap64(uint64_t _data) { return __builtin_bswap64(_data); } -#else -// Slow generic implementation. Hopefully this never hits -inline uint16_t swap16(uint16_t data) { return (data >> 8) | (data << 8); } -inline uint32_t swap32(uint32_t data) { return (swap16(data) << 16) | swap16(data >> 16); } -inline uint64_t swap64(uint64_t data) { return ((uint64_t)swap32(data) << 32) | swap32(data >> 32); } -#endif - -inline uint16_t swap16(const uint8_t* _pData) { return swap16(*(const uint16_t*)_pData); } -inline uint32_t swap32(const uint8_t* _pData) { return swap32(*(const uint32_t*)_pData); } -inline uint64_t swap64(const uint8_t* _pData) { return swap64(*(const uint64_t*)_pData); } diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 7d48de5757..94af9b6ce9 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -355,7 +355,6 @@ - @@ -535,4 +534,4 @@ - \ No newline at end of file + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 981ac5d5a3..4f8646bace 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -94,7 +94,6 @@ - @@ -183,4 +182,4 @@ {7be79ad5-3520-46a1-a370-dce2a943978c} - \ No newline at end of file + diff --git a/Core/MIPS/ARM/ArmCompALU.cpp b/Core/MIPS/ARM/ArmCompALU.cpp index 67e5a70600..471b3e0dc2 100644 --- a/Core/MIPS/ARM/ArmCompALU.cpp +++ b/Core/MIPS/ARM/ArmCompALU.cpp @@ -25,7 +25,7 @@ #include "Core/MIPS/ARM/ArmJit.h" #include "Core/MIPS/ARM/ArmRegCache.h" #include "Common/CPUDetect.h" -#include "Common/ByteSwap.h" +#include "Common/BitSet.h" using namespace MIPSAnalyst; diff --git a/Core/MIPS/ARM64/Arm64CompALU.cpp b/Core/MIPS/ARM64/Arm64CompALU.cpp index df195209f6..a4e5ea25e9 100644 --- a/Core/MIPS/ARM64/Arm64CompALU.cpp +++ b/Core/MIPS/ARM64/Arm64CompALU.cpp @@ -20,7 +20,7 @@ #include -#include "Common/ByteSwap.h" +#include "Common/BitSet.h" #include "Common/CPUDetect.h" #include "Core/MIPS/MIPS.h" #include "Core/MIPS/MIPSCodeUtils.h" diff --git a/Core/MIPS/IR/IRPassSimplify.cpp b/Core/MIPS/IR/IRPassSimplify.cpp index d6f96876d2..d7f8195c98 100644 --- a/Core/MIPS/IR/IRPassSimplify.cpp +++ b/Core/MIPS/IR/IRPassSimplify.cpp @@ -2,7 +2,7 @@ #include #include -#include "Common/ByteSwap.h" +#include "Common/BitSet.h" #include "Common/Log.h" #include "Core/MIPS/IR/IRInterpreter.h" #include "Core/MIPS/IR/IRPassSimplify.h" diff --git a/Core/MIPS/MIPSInt.cpp b/Core/MIPS/MIPSInt.cpp index a48887f935..49847dc4a5 100644 --- a/Core/MIPS/MIPSInt.cpp +++ b/Core/MIPS/MIPSInt.cpp @@ -19,9 +19,9 @@ #include "math/math_util.h" -#include "Common/ByteSwap.h" -#include "Common/Common.h" +#include "Common/BitSet.h" #include "Common/BitScan.h" +#include "Common/Common.h" #include "Core/Config.h" #include "Core/Core.h" #include "Core/Host.h" diff --git a/Core/MIPS/x86/CompALU.cpp b/Core/MIPS/x86/CompALU.cpp index 06ee0e9231..4c262cf1a4 100644 --- a/Core/MIPS/x86/CompALU.cpp +++ b/Core/MIPS/x86/CompALU.cpp @@ -20,7 +20,7 @@ #include -#include "Common/ByteSwap.h" +#include "Common/BitSet.h" #include "Common/Common.h" #include "Core/MIPS/MIPSCodeUtils.h" #include "Core/MIPS/x86/Jit.h" diff --git a/UWP/CommonUWP/CommonUWP.vcxproj b/UWP/CommonUWP/CommonUWP.vcxproj index 21f6880a58..f4c80840cd 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj +++ b/UWP/CommonUWP/CommonUWP.vcxproj @@ -386,7 +386,6 @@ - diff --git a/UWP/CommonUWP/CommonUWP.vcxproj.filters b/UWP/CommonUWP/CommonUWP.vcxproj.filters index ece02a7b10..a4cbb48402 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj.filters +++ b/UWP/CommonUWP/CommonUWP.vcxproj.filters @@ -57,7 +57,6 @@ - diff --git a/ext/native/util/text/utf16.h b/ext/native/util/text/utf16.h index 542b1e94a6..a04949ed35 100644 --- a/ext/native/util/text/utf16.h +++ b/ext/native/util/text/utf16.h @@ -2,7 +2,7 @@ #include -#include "Common/ByteSwap.h" +#include "Common/BitSet.h" // Should optimize out. #define UTF16_IS_LITTLE_ENDIAN (*(const uint16_t *)"\0\xff" >= 0x100)