Merge pull request #13490 from hrydgard/byteswap-h-name-fail

ByteSwap.h results in a file name collision on some systems with byteswap.h
This commit is contained in:
Henrik Rydgård 2020-09-30 00:29:14 +02:00 committed by GitHub
commit fdc05bf53e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 36 additions and 43 deletions

View File

@ -444,7 +444,6 @@ add_library(Common STATIC
Common/BitSet.h Common/BitSet.h
Common/Buffer.h Common/Buffer.h
Common/Buffer.cpp Common/Buffer.cpp
Common/ByteSwap.h
Common/CodeBlock.h Common/CodeBlock.h
Common/ColorConv.cpp Common/ColorConv.cpp
Common/ColorConv.h Common/ColorConv.h

View File

@ -2,6 +2,8 @@
#pragma once #pragma once
#include <cstdint>
#include <cstdlib> // for byte swapping
#include <cstddef> #include <cstddef>
#include "CommonTypes.h" #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(u32 val) { return __builtin_ctz(val); }
inline int LeastSignificantSetBit(u64 val) { return __builtin_ctzll(val); } inline int LeastSignificantSetBit(u64 val) { return __builtin_ctzll(val); }
#endif #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); }

View File

@ -1,29 +0,0 @@
#pragma once
#include <cstdint>
#include <cstdlib> // 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); }

View File

@ -355,7 +355,6 @@
<ClInclude Include="BitScan.h" /> <ClInclude Include="BitScan.h" />
<ClInclude Include="BitSet.h" /> <ClInclude Include="BitSet.h" />
<ClInclude Include="Buffer.h" /> <ClInclude Include="Buffer.h" />
<ClInclude Include="ByteSwap.h" />
<ClInclude Include="FakeEmitter.h" /> <ClInclude Include="FakeEmitter.h" />
<ClInclude Include="Serialize\SerializeDeque.h" /> <ClInclude Include="Serialize\SerializeDeque.h" />
<ClInclude Include="Serialize\SerializeFuncs.h" /> <ClInclude Include="Serialize\SerializeFuncs.h" />

View File

@ -94,7 +94,6 @@
</ClInclude> </ClInclude>
<ClInclude Include="TimeUtil.h" /> <ClInclude Include="TimeUtil.h" />
<ClInclude Include="FakeEmitter.h" /> <ClInclude Include="FakeEmitter.h" />
<ClInclude Include="ByteSwap.h" />
<ClInclude Include="Buffer.h" /> <ClInclude Include="Buffer.h" />
<ClInclude Include="SysError.h" /> <ClInclude Include="SysError.h" />
</ItemGroup> </ItemGroup>

View File

@ -25,7 +25,7 @@
#include "Core/MIPS/ARM/ArmJit.h" #include "Core/MIPS/ARM/ArmJit.h"
#include "Core/MIPS/ARM/ArmRegCache.h" #include "Core/MIPS/ARM/ArmRegCache.h"
#include "Common/CPUDetect.h" #include "Common/CPUDetect.h"
#include "Common/ByteSwap.h" #include "Common/BitSet.h"
using namespace MIPSAnalyst; using namespace MIPSAnalyst;

View File

@ -20,7 +20,7 @@
#include <algorithm> #include <algorithm>
#include "Common/ByteSwap.h" #include "Common/BitSet.h"
#include "Common/CPUDetect.h" #include "Common/CPUDetect.h"
#include "Core/MIPS/MIPS.h" #include "Core/MIPS/MIPS.h"
#include "Core/MIPS/MIPSCodeUtils.h" #include "Core/MIPS/MIPSCodeUtils.h"

View File

@ -2,7 +2,7 @@
#include <cstring> #include <cstring>
#include <utility> #include <utility>
#include "Common/ByteSwap.h" #include "Common/BitSet.h"
#include "Common/Log.h" #include "Common/Log.h"
#include "Core/MIPS/IR/IRInterpreter.h" #include "Core/MIPS/IR/IRInterpreter.h"
#include "Core/MIPS/IR/IRPassSimplify.h" #include "Core/MIPS/IR/IRPassSimplify.h"

View File

@ -19,9 +19,9 @@
#include "math/math_util.h" #include "math/math_util.h"
#include "Common/ByteSwap.h" #include "Common/BitSet.h"
#include "Common/Common.h"
#include "Common/BitScan.h" #include "Common/BitScan.h"
#include "Common/Common.h"
#include "Core/Config.h" #include "Core/Config.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/Host.h" #include "Core/Host.h"

View File

@ -20,7 +20,7 @@
#include <algorithm> #include <algorithm>
#include "Common/ByteSwap.h" #include "Common/BitSet.h"
#include "Common/Common.h" #include "Common/Common.h"
#include "Core/MIPS/MIPSCodeUtils.h" #include "Core/MIPS/MIPSCodeUtils.h"
#include "Core/MIPS/x86/Jit.h" #include "Core/MIPS/x86/Jit.h"

View File

@ -386,7 +386,6 @@
<ClInclude Include="..\..\Common\BitScan.h" /> <ClInclude Include="..\..\Common\BitScan.h" />
<ClInclude Include="..\..\Common\BitSet.h" /> <ClInclude Include="..\..\Common\BitSet.h" />
<ClInclude Include="..\..\Common\Buffer.h" /> <ClInclude Include="..\..\Common\Buffer.h" />
<ClInclude Include="..\..\Common\ByteSwap.h" />
<ClInclude Include="..\..\Common\Serialize\Serializer.h" /> <ClInclude Include="..\..\Common\Serialize\Serializer.h" />
<ClInclude Include="..\..\Common\Serialize\SerializeDeque.h" /> <ClInclude Include="..\..\Common\Serialize\SerializeDeque.h" />
<ClInclude Include="..\..\Common\Serialize\SerializeFuncs.h" /> <ClInclude Include="..\..\Common\Serialize\SerializeFuncs.h" />

View File

@ -57,7 +57,6 @@
<ClInclude Include="..\..\Common\ArmEmitter.h" /> <ClInclude Include="..\..\Common\ArmEmitter.h" />
<ClInclude Include="..\..\Common\BitSet.h" /> <ClInclude Include="..\..\Common\BitSet.h" />
<ClInclude Include="..\..\Common\BitScan.h" /> <ClInclude Include="..\..\Common\BitScan.h" />
<ClInclude Include="..\..\Common\ByteSwap.h" />
<ClInclude Include="..\..\Common\Serialize\Serializer.h" /> <ClInclude Include="..\..\Common\Serialize\Serializer.h" />
<ClInclude Include="..\..\Common\Serialize\SerializerDeque.h" /> <ClInclude Include="..\..\Common\Serialize\SerializerDeque.h" />
<ClInclude Include="..\..\Common\Serialize\SerializerFuncs.h" /> <ClInclude Include="..\..\Common\Serialize\SerializerFuncs.h" />

View File

@ -2,7 +2,7 @@
#include <cstdint> #include <cstdint>
#include "Common/ByteSwap.h" #include "Common/BitSet.h"
// Should optimize out. // Should optimize out.
#define UTF16_IS_LITTLE_ENDIAN (*(const uint16_t *)"\0\xff" >= 0x100) #define UTF16_IS_LITTLE_ENDIAN (*(const uint16_t *)"\0\xff" >= 0x100)