From 4d3ec20082a78fd6da3834846053c9592017e6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 30 Sep 2020 00:06:51 +0200 Subject: [PATCH] ByteSwap.h results in a file name collision on some systems with byteswap.h. Fix this by merging it into BitSet.h. --- CMakeLists.txt | 1 - Common/BitSet.h | 27 +++++++++++++++++++++++ Common/ByteSwap.h | 29 ------------------------- Common/Common.vcxproj | 3 +-- Common/Common.vcxproj.filters | 3 +-- Core/MIPS/ARM/ArmCompALU.cpp | 2 +- Core/MIPS/ARM64/Arm64CompALU.cpp | 2 +- Core/MIPS/IR/IRPassSimplify.cpp | 2 +- Core/MIPS/MIPSInt.cpp | 4 ++-- Core/MIPS/x86/CompALU.cpp | 2 +- UWP/CommonUWP/CommonUWP.vcxproj | 1 - UWP/CommonUWP/CommonUWP.vcxproj.filters | 1 - ext/native/util/text/utf16.h | 2 +- 13 files changed, 36 insertions(+), 43 deletions(-) delete mode 100644 Common/ByteSwap.h 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)