mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #5007 from lioncash/swap
Common: Move byte swapping utilities into their own header
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "AudioCommon/Mixer.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "AudioCommon/AudioCommon.h"
|
||||
#include "AudioCommon/Mixer.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "Common/Swap.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
|
||||
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "AudioCommon/WaveFile.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "AudioCommon/WaveFile.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "Common/Swap.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
|
||||
constexpr size_t WaveFileWriter::BUFFER_SIZE;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Common/ColorUtil.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
namespace ColorUtil
|
||||
{
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
<ClInclude Include="Semaphore.h" />
|
||||
<ClInclude Include="SettingsHandler.h" />
|
||||
<ClInclude Include="StringUtil.h" />
|
||||
<ClInclude Include="Swap.h" />
|
||||
<ClInclude Include="SymbolDB.h" />
|
||||
<ClInclude Include="SysConf.h" />
|
||||
<ClInclude Include="Thread.h" />
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
<ClInclude Include="SDCardUtil.h" />
|
||||
<ClInclude Include="SettingsHandler.h" />
|
||||
<ClInclude Include="StringUtil.h" />
|
||||
<ClInclude Include="Swap.h" />
|
||||
<ClInclude Include="SymbolDB.h" />
|
||||
<ClInclude Include="SysConf.h" />
|
||||
<ClInclude Include="Thread.h" />
|
||||
|
||||
@@ -4,12 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
@@ -29,13 +24,6 @@ constexpr size_t ArraySize(T (&arr)[N])
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <errno.h>
|
||||
#ifdef __linux__
|
||||
#include <byteswap.h>
|
||||
#elif defined __FreeBSD__
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
// go to debugger mode
|
||||
#define Crash() \
|
||||
{ \
|
||||
@@ -103,153 +91,3 @@ __declspec(dllimport) void __stdcall DebugBreak(void);
|
||||
// This function might change the error code.
|
||||
// Defined in Misc.cpp.
|
||||
std::string GetLastErrorMsg();
|
||||
|
||||
namespace Common
|
||||
{
|
||||
inline u8 swap8(u8 _data)
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
inline u32 swap24(const u8* _data)
|
||||
{
|
||||
return (_data[0] << 16) | (_data[1] << 8) | _data[2];
|
||||
}
|
||||
|
||||
#if defined(ANDROID) || defined(__OpenBSD__)
|
||||
#undef swap16
|
||||
#undef swap32
|
||||
#undef swap64
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
inline u16 swap16(u16 _data)
|
||||
{
|
||||
return _byteswap_ushort(_data);
|
||||
}
|
||||
inline u32 swap32(u32 _data)
|
||||
{
|
||||
return _byteswap_ulong(_data);
|
||||
}
|
||||
inline u64 swap64(u64 _data)
|
||||
{
|
||||
return _byteswap_uint64(_data);
|
||||
}
|
||||
#elif __linux__
|
||||
inline u16 swap16(u16 _data)
|
||||
{
|
||||
return bswap_16(_data);
|
||||
}
|
||||
inline u32 swap32(u32 _data)
|
||||
{
|
||||
return bswap_32(_data);
|
||||
}
|
||||
inline u64 swap64(u64 _data)
|
||||
{
|
||||
return bswap_64(_data);
|
||||
}
|
||||
#elif __APPLE__
|
||||
inline __attribute__((always_inline)) u16 swap16(u16 _data)
|
||||
{
|
||||
return OSSwapInt16(_data);
|
||||
}
|
||||
inline __attribute__((always_inline)) u32 swap32(u32 _data)
|
||||
{
|
||||
return OSSwapInt32(_data);
|
||||
}
|
||||
inline __attribute__((always_inline)) u64 swap64(u64 _data)
|
||||
{
|
||||
return OSSwapInt64(_data);
|
||||
}
|
||||
#elif __FreeBSD__
|
||||
inline u16 swap16(u16 _data)
|
||||
{
|
||||
return bswap16(_data);
|
||||
}
|
||||
inline u32 swap32(u32 _data)
|
||||
{
|
||||
return bswap32(_data);
|
||||
}
|
||||
inline u64 swap64(u64 _data)
|
||||
{
|
||||
return bswap64(_data);
|
||||
}
|
||||
#else
|
||||
// Slow generic implementation.
|
||||
inline u16 swap16(u16 data)
|
||||
{
|
||||
return (data >> 8) | (data << 8);
|
||||
}
|
||||
inline u32 swap32(u32 data)
|
||||
{
|
||||
return (swap16(data) << 16) | swap16(data >> 16);
|
||||
}
|
||||
inline u64 swap64(u64 data)
|
||||
{
|
||||
return ((u64)swap32(data) << 32) | swap32(data >> 32);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline u16 swap16(const u8* data)
|
||||
{
|
||||
u16 value;
|
||||
std::memcpy(&value, data, sizeof(u16));
|
||||
|
||||
return swap16(value);
|
||||
}
|
||||
inline u32 swap32(const u8* data)
|
||||
{
|
||||
u32 value;
|
||||
std::memcpy(&value, data, sizeof(u32));
|
||||
|
||||
return swap32(value);
|
||||
}
|
||||
inline u64 swap64(const u8* data)
|
||||
{
|
||||
u64 value;
|
||||
std::memcpy(&value, data, sizeof(u64));
|
||||
|
||||
return swap64(value);
|
||||
}
|
||||
|
||||
template <int count>
|
||||
void swap(u8*);
|
||||
|
||||
template <>
|
||||
inline void swap<1>(u8* data)
|
||||
{
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void swap<2>(u8* data)
|
||||
{
|
||||
const u16 value = swap16(data);
|
||||
|
||||
std::memcpy(data, &value, sizeof(u16));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void swap<4>(u8* data)
|
||||
{
|
||||
const u32 value = swap32(data);
|
||||
|
||||
std::memcpy(data, &value, sizeof(u32));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void swap<8>(u8* data)
|
||||
{
|
||||
const u64 value = swap64(data);
|
||||
|
||||
std::memcpy(data, &value, sizeof(u64));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T FromBigEndian(T data)
|
||||
{
|
||||
static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types");
|
||||
|
||||
swap<sizeof(data)>(reinterpret_cast<u8*>(&data));
|
||||
return data;
|
||||
}
|
||||
|
||||
} // Namespace Common
|
||||
|
||||
@@ -3,20 +3,17 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/NandPaths.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <sys/timeb.h>
|
||||
#include "Common/CommonFuncs.h" // snprintf
|
||||
#endif
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#elif defined(__linux__)
|
||||
#include <byteswap.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
inline u8 swap8(u8 data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
inline u32 swap24(const u8* data)
|
||||
{
|
||||
return (data[0] << 16) | (data[1] << 8) | data[2];
|
||||
}
|
||||
|
||||
#if defined(ANDROID) || defined(__OpenBSD__)
|
||||
#undef swap16
|
||||
#undef swap32
|
||||
#undef swap64
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
inline u16 swap16(u16 data)
|
||||
{
|
||||
return _byteswap_ushort(data);
|
||||
}
|
||||
inline u32 swap32(u32 data)
|
||||
{
|
||||
return _byteswap_ulong(data);
|
||||
}
|
||||
inline u64 swap64(u64 data)
|
||||
{
|
||||
return _byteswap_uint64(data);
|
||||
}
|
||||
#elif __linux__
|
||||
inline u16 swap16(u16 data)
|
||||
{
|
||||
return bswap_16(data);
|
||||
}
|
||||
inline u32 swap32(u32 data)
|
||||
{
|
||||
return bswap_32(data);
|
||||
}
|
||||
inline u64 swap64(u64 data)
|
||||
{
|
||||
return bswap_64(data);
|
||||
}
|
||||
#elif __APPLE__
|
||||
inline __attribute__((always_inline)) u16 swap16(u16 data)
|
||||
{
|
||||
return OSSwapInt16(data);
|
||||
}
|
||||
inline __attribute__((always_inline)) u32 swap32(u32 data)
|
||||
{
|
||||
return OSSwapInt32(data);
|
||||
}
|
||||
inline __attribute__((always_inline)) u64 swap64(u64 data)
|
||||
{
|
||||
return OSSwapInt64(data);
|
||||
}
|
||||
#elif __FreeBSD__
|
||||
inline u16 swap16(u16 data)
|
||||
{
|
||||
return bswap16(data);
|
||||
}
|
||||
inline u32 swap32(u32 data)
|
||||
{
|
||||
return bswap32(data);
|
||||
}
|
||||
inline u64 swap64(u64 data)
|
||||
{
|
||||
return bswap64(data);
|
||||
}
|
||||
#else
|
||||
// Slow generic implementation.
|
||||
inline u16 swap16(u16 data)
|
||||
{
|
||||
return (data >> 8) | (data << 8);
|
||||
}
|
||||
inline u32 swap32(u32 data)
|
||||
{
|
||||
return (swap16(data) << 16) | swap16(data >> 16);
|
||||
}
|
||||
inline u64 swap64(u64 data)
|
||||
{
|
||||
return ((u64)swap32(data) << 32) | swap32(data >> 32);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline u16 swap16(const u8* data)
|
||||
{
|
||||
u16 value;
|
||||
std::memcpy(&value, data, sizeof(u16));
|
||||
|
||||
return swap16(value);
|
||||
}
|
||||
inline u32 swap32(const u8* data)
|
||||
{
|
||||
u32 value;
|
||||
std::memcpy(&value, data, sizeof(u32));
|
||||
|
||||
return swap32(value);
|
||||
}
|
||||
inline u64 swap64(const u8* data)
|
||||
{
|
||||
u64 value;
|
||||
std::memcpy(&value, data, sizeof(u64));
|
||||
|
||||
return swap64(value);
|
||||
}
|
||||
|
||||
template <int count>
|
||||
void swap(u8*);
|
||||
|
||||
template <>
|
||||
inline void swap<1>(u8* data)
|
||||
{
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void swap<2>(u8* data)
|
||||
{
|
||||
const u16 value = swap16(data);
|
||||
|
||||
std::memcpy(data, &value, sizeof(u16));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void swap<4>(u8* data)
|
||||
{
|
||||
const u32 value = swap32(data);
|
||||
|
||||
std::memcpy(data, &value, sizeof(u32));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void swap<8>(u8* data)
|
||||
{
|
||||
const u64 value = swap64(data);
|
||||
|
||||
std::memcpy(data, &value, sizeof(u64));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T FromBigEndian(T data)
|
||||
{
|
||||
static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types");
|
||||
|
||||
swap<sizeof(data)>(reinterpret_cast<u8*>(&data));
|
||||
return data;
|
||||
}
|
||||
} // Namespace Common
|
||||
@@ -2,6 +2,8 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Common/SysConf.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
@@ -9,13 +11,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/SysConf.h"
|
||||
|
||||
#include "Common/Swap.h"
|
||||
#include "Core/Movie.h"
|
||||
|
||||
SysConf::SysConf(const Common::FromWhichRoot root_type)
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// GCNcrypt - GameCube AR Crypto Program
|
||||
// Copyright (C) 2003-2004 Parasyte
|
||||
|
||||
#include "Core/ARDecrypt.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
@@ -16,7 +18,7 @@
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Core/ARDecrypt.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
namespace ActionReplay
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/Boot/Boot_DOL.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/FileUtil.h"
|
||||
|
||||
#include "Core/Boot/Boot_DOL.h"
|
||||
#include "Common/Swap.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
|
||||
CDolLoader::CDolLoader(const std::vector<u8>& buffer)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Swap.h"
|
||||
#include "Core/Boot/Boot.h"
|
||||
#include "Core/Boot/ElfReader.h"
|
||||
#include "Core/HLE/HLE.h"
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/PowerPC/PPCSymbolDB.h"
|
||||
|
||||
@@ -9,11 +9,9 @@
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Event.h"
|
||||
#include "Common/Hash.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MemoryUtil.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
#include "Core/DSP/DSPHWInterface.h"
|
||||
|
||||
#include "Common/CPUDetect.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Intrinsics.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MemoryUtil.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
#include "Core/DSP/DSPAccelerator.h"
|
||||
#include "Core/DSP/DSPCore.h"
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
#include "Core/FifoPlayer/FifoAnalyzer.h"
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
#include "Core/FifoPlayer/FifoRecordAnalyzer.h"
|
||||
|
||||
#include "VideoCommon/OpcodeDecoding.h"
|
||||
#include "VideoCommon/VertexLoader.h"
|
||||
#include "VideoCommon/VertexLoader_Normal.h"
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
#include "Core/HW/DSPHLE/UCodes/AX.h"
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "Common/Swap.h"
|
||||
#include "Core/HW/DSP.h"
|
||||
#include "Core/HW/DSPHLE/DSPHLE.h"
|
||||
#include "Core/HW/DSPHLE/MailHandler.h"
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
#include "Core/HW/DSPHLE/UCodes/AXWii.h"
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Common/Swap.h"
|
||||
#include "Core/HW/DSPHLE/DSPHLE.h"
|
||||
#include "Core/HW/DSPHLE/MailHandler.h"
|
||||
#include "Core/HW/DSPHLE/UCodes/AXStructs.h"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user