Split BEType.h to util/v128.hpp and util/to_endian.hpp

This commit is contained in:
Nekotekina 2020-12-13 16:34:45 +03:00
parent 62fdcf50ea
commit e321765c54
68 changed files with 195 additions and 171 deletions

View file

@ -1,7 +1,6 @@
#include "File.h" #include "File.h"
#include "mutex.h" #include "mutex.h"
#include "StrFmt.h" #include "StrFmt.h"
#include "BEType.h"
#include "Crypto/sha1.h" #include "Crypto/sha1.h"
#include <unordered_map> #include <unordered_map>

View file

@ -1,8 +1,9 @@
#include "StrFmt.h" #include "StrFmt.h"
#include "BEType.h"
#include "StrUtil.h" #include "StrUtil.h"
#include "cfmt.h" #include "cfmt.h"
#include "util/endian.hpp"
#include "util/logs.hpp" #include "util/logs.hpp"
#include "util/v128.hpp"
#include <algorithm> #include <algorithm>
#include <string_view> #include <string_view>

View file

@ -119,6 +119,17 @@ struct fmt_unveil<b8, void>
} }
}; };
template <typename T, bool Se, std::size_t Align>
struct fmt_unveil<se_t<T, Se, Align>, void>
{
using type = typename fmt_unveil<T>::type;
static inline auto get(const se_t<T, Se, Align>& arg)
{
return fmt_unveil<T>::get(arg);
}
};
// String type format provider, also type classifier (format() called if an argument is formatted as "%s") // String type format provider, also type classifier (format() called if an argument is formatted as "%s")
template <typename T, typename = void> template <typename T, typename = void>
struct fmt_class_string struct fmt_class_string

View file

@ -1296,7 +1296,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no
if (op != X64OP_LOAD_BE) if (op != X64OP_LOAD_BE)
{ {
value = se_storage<u32>::swap(value); value = stx::se_storage<u32>::swap(value);
} }
if (op == X64OP_LOAD_CMP) if (op == X64OP_LOAD_CMP)
@ -1338,7 +1338,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no
} }
u32 val32 = static_cast<u32>(reg_value); u32 val32 = static_cast<u32>(reg_value);
if (!thread->write_reg(addr, op == X64OP_STORE ? se_storage<u32>::swap(val32) : val32)) if (!thread->write_reg(addr, op == X64OP_STORE ? stx::se_storage<u32>::swap(val32) : val32))
{ {
return false; return false;
} }

View file

@ -4,6 +4,9 @@
#include "version.h" #include "version.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "util/types.hpp"
#include "util/endian.hpp"
LOG_CHANNEL(patch_log, "PAT"); LOG_CHANNEL(patch_log, "PAT");
namespace config_key namespace config_key

View file

@ -1,10 +1,10 @@
#pragma once #pragma once
#include "BEType.h"
#include <vector> #include <vector>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include "util/types.hpp"
#include "util/yaml.hpp" #include "util/yaml.hpp"
namespace patch_key namespace patch_key

View file

@ -5,6 +5,8 @@
#include "Utilities/mutex.h" #include "Utilities/mutex.h"
#include <cmath> #include <cmath>
#include "util/v128.hpp"
LOG_CHANNEL(edat_log, "EDAT"); LOG_CHANNEL(edat_log, "EDAT");
// Static variables are being modified concurrently in ec.cpp, for now use a mutex // Static variables are being modified concurrently in ec.cpp, for now use a mutex

View file

@ -4,9 +4,10 @@
#include "utils.h" #include "utils.h"
#include "Utilities/BEType.h"
#include "Utilities/File.h" #include "Utilities/File.h"
#include "util/v128.hpp"
constexpr u32 SDAT_FLAG = 0x01000000; constexpr u32 SDAT_FLAG = 0x01000000;
constexpr u32 EDAT_COMPRESSED_FLAG = 0x00000001; constexpr u32 EDAT_COMPRESSED_FLAG = 0x00000001;
constexpr u32 EDAT_FLAG_0x02 = 0x00000002; constexpr u32 EDAT_FLAG_0x02 = 0x00000002;

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>

View file

@ -3,13 +3,14 @@
#include "sha1.h" #include "sha1.h"
#include "utils.h" #include "utils.h"
#include "unself.h" #include "unself.h"
#include "Utilities/BEType.h"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/System.h" #include "Emu/System.h"
#include <algorithm> #include <algorithm>
#include <zlib.h> #include <zlib.h>
#include "util/v128.hpp"
inline u8 Read8(const fs::file& f) inline u8 Read8(const fs::file& f)
{ {
u8 ret; u8 ret;

View file

@ -26,7 +26,6 @@
#include "util/types.hpp" #include "util/types.hpp"
#include "Utilities/StrFmt.h" #include "Utilities/StrFmt.h"
#include "Utilities/BEType.h"
#include "Utilities/BitField.h" #include "Utilities/BitField.h"
#include "util/logs.hpp" #include "util/logs.hpp"
#include "Utilities/JIT.h" #include "Utilities/JIT.h"
@ -38,6 +37,8 @@
#include <array> #include <array>
#include <vector> #include <vector>
#include "util/v128.hpp"
enum class i2 : char enum class i2 : char
{ {
}; };

View file

@ -174,7 +174,7 @@ struct audio_port
return addr.addr() + position(offset) * buf_size(); return addr.addr() + position(offset) * buf_size();
} }
to_be_t<float>* get_vm_ptr(s32 offset = 0) const be_t<f32>* get_vm_ptr(s32 offset = 0) const
{ {
return vm::_ptr<f32>(buf_addr(offset)); return vm::_ptr<f32>(buf_addr(offset));
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "Utilities/BEType.h" #include "util/types.hpp"
#include "util/endian.hpp"
// Error codes // Error codes
enum CellAudioInError enum CellAudioInError

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
static const float CELL_GEM_SPHERE_RADIUS_MM = 22.5f; static const float CELL_GEM_SPHERE_RADIUS_MM = 22.5f;
// Error codes // Error codes

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
//Return Codes //Return Codes
enum CellJpgDecError : u32 enum CellJpgDecError : u32
{ {

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
#include "Emu/Io/Keyboard.h" #include "Emu/Io/Keyboard.h"
enum CellKbError : u32 enum CellKbError : u32

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
#include "Utilities/Thread.h" #include "Utilities/Thread.h"
#include "3rdparty/OpenAL/include/alext.h" #include "3rdparty/OpenAL/include/alext.h"

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
enum CellMouseError : u32 enum CellMouseError : u32
{ {
CELL_MOUSE_ERROR_FATAL = 0x80121201, CELL_MOUSE_ERROR_FATAL = 0x80121201,

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
#include <array> #include <array>
enum CellPadError : u32 enum CellPadError : u32

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
enum CellRescError : u32 enum CellRescError : u32
{ {
CELL_RESC_ERROR_NOT_INITIALIZED = 0x80210301, CELL_RESC_ERROR_NOT_INITIALIZED = 0x80210301,

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
#include "Emu/Memory/vm_ptr.h" #include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h" #include "Emu/Cell/ErrorCodes.h"

View file

@ -3,6 +3,8 @@
#include "stdafx.h" #include "stdafx.h"
#include <Emu/Memory/vm_ptr.h> #include <Emu/Memory/vm_ptr.h>
#include "util/v128.hpp"
// Return codes // Return codes
enum CellSaveDataError : u32 enum CellSaveDataError : u32
{ {

View file

@ -15,6 +15,8 @@
#include "sysPrxForUser.h" #include "sysPrxForUser.h"
#include "cellSpurs.h" #include "cellSpurs.h"
#include "util/v128.hpp"
LOG_CHANNEL(cellSpurs); LOG_CHANNEL(cellSpurs);
template <> template <>

View file

@ -2,7 +2,7 @@
#include "cellSync.h" #include "cellSync.h"
#include "util/v128.hpp"
struct CellSpurs; struct CellSpurs;
struct CellSpursTaskset; struct CellSpursTaskset;

View file

@ -13,6 +13,8 @@
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include "util/v128.hpp"
LOG_CHANNEL(cellSpurs); LOG_CHANNEL(cellSpurs);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
// Return Codes // Return Codes
enum CellSubDisplayError : u32 enum CellSubDisplayError : u32
{ {

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
// Error Codes // Error Codes
enum CellVdecError : u32 enum CellVdecError : u32
{ {

View file

@ -18,8 +18,6 @@ extern "C"
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
#include "Utilities/BEType.h"
// Error Codes // Error Codes
enum CellVpostError : u32 enum CellVpostError : u32
{ {

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
// Error Codes // Error Codes
enum CellSoundSynth2Error : u32 enum CellSoundSynth2Error : u32
{ {

View file

@ -15,6 +15,8 @@
#include "Emu/NP/np_handler.h" #include "Emu/NP/np_handler.h"
#include "Emu/NP/np_contexts.h" #include "Emu/NP/np_contexts.h"
#include "util/v128.hpp"
LOG_CHANNEL(sceNp); LOG_CHANNEL(sceNp);
template <> template <>

View file

@ -3,8 +3,6 @@
#include "cellRtc.h" #include "cellRtc.h"
#include "Emu/Cell/ErrorCodes.h" #include "Emu/Cell/ErrorCodes.h"
#include "Utilities/BEType.h"
error_code sceNpInit(u32 poolsize, vm::ptr<void> poolptr); error_code sceNpInit(u32 poolsize, vm::ptr<void> poolptr);
error_code sceNpTerm(); error_code sceNpTerm();

View file

@ -2,8 +2,6 @@
#include "sceNp.h" #include "sceNp.h"
#include "Utilities/BEType.h"
// Return codes // Return codes
enum SceNpClansError : u32 enum SceNpClansError : u32
{ {

View file

@ -2,8 +2,6 @@
#include "cellRtc.h" #include "cellRtc.h"
#include "Utilities/BEType.h"
// Return codes // Return codes
enum SceNpCommerce2Error enum SceNpCommerce2Error
{ {

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
#include "cellRtc.h" #include "cellRtc.h"
#include "sceNp.h" #include "sceNp.h"

View file

@ -3,9 +3,10 @@
#include <string> #include <string>
#include <map> #include <map>
#include <set> #include <set>
#include "util/types.hpp"
#include "util/endian.hpp"
#include "Utilities/bit_set.h" #include "Utilities/bit_set.h"
#include "Utilities/BEType.h"
#include "PPUOpcodes.h" #include "PPUOpcodes.h"
// PPU Function Attributes // PPU Function Attributes

View file

@ -2,6 +2,8 @@
#include "Emu/Cell/PPUThread.h" #include "Emu/Cell/PPUThread.h"
#include "util/v128.hpp"
struct ppu_func_opd_t; struct ppu_func_opd_t;
namespace ppu_cb_detail namespace ppu_cb_detail

View file

@ -2,6 +2,8 @@
#include "PPUThread.h" #include "PPUThread.h"
#include "util/v128.hpp"
using ppu_function_t = bool(*)(ppu_thread&); using ppu_function_t = bool(*)(ppu_thread&);
// BIND_FUNC macro "converts" any appropriate HLE function to ppu_function_t, binding it to PPU thread context. // BIND_FUNC macro "converts" any appropriate HLE function to ppu_function_t, binding it to PPU thread context.

View file

@ -11,6 +11,7 @@
#include <cmath> #include <cmath>
#include "util/asm.hpp" #include "util/asm.hpp"
#include "util/v128.hpp"
#if !defined(_MSC_VER) && defined(__clang__) #if !defined(_MSC_VER) && defined(__clang__)
#pragma GCC diagnostic push #pragma GCC diagnostic push

View file

@ -66,6 +66,7 @@
#include <cctype> #include <cctype>
#include "util/asm.hpp" #include "util/asm.hpp"
#include "util/vm.hpp" #include "util/vm.hpp"
#include "util/v128.hpp"
const bool s_use_ssse3 = utils::has_ssse3(); const bool s_use_ssse3 = utils::has_ssse3();
@ -1240,8 +1241,8 @@ static T ppu_load_acquire_reservation(ppu_thread& ppu, u32 addr)
const auto inst = vm::_ptr<const nse_t<u32>>(cia); const auto inst = vm::_ptr<const nse_t<u32>>(cia);
// Search for STWCX or STDCX nearby (LDARX-STWCX and LWARX-STDCX loops will use accurate 128-byte reservations) // Search for STWCX or STDCX nearby (LDARX-STWCX and LWARX-STDCX loops will use accurate 128-byte reservations)
constexpr u32 store_cond = se_storage<u32>::swap(sizeof(T) == 8 ? 0x7C00012D : 0x7C0001AD); constexpr u32 store_cond = stx::se_storage<u32>::swap(sizeof(T) == 8 ? 0x7C00012D : 0x7C0001AD);
constexpr u32 mask = se_storage<u32>::swap(0xFC0007FF); constexpr u32 mask = stx::se_storage<u32>::swap(0xFC0007FF);
const auto store_vec = v128::from32p(store_cond); const auto store_vec = v128::from32p(store_cond);
const auto mask_vec = v128::from32p(mask); const auto mask_vec = v128::from32p(mask);

View file

@ -4,6 +4,8 @@
#include "../Memory/vm_ptr.h" #include "../Memory/vm_ptr.h"
#include "Utilities/lockless.h" #include "Utilities/lockless.h"
#include "util/v128.hpp"
LOG_CHANNEL(ppu_log, "PPU"); LOG_CHANNEL(ppu_log, "PPU");
enum class ppu_cmd : u32 enum class ppu_cmd : u32

View file

@ -5,7 +5,10 @@
#include "PPUThread.h" #include "PPUThread.h"
#include "PPUInterpreter.h" #include "PPUInterpreter.h"
#include "util/types.hpp"
#include "util/endian.hpp"
#include "util/logs.hpp" #include "util/logs.hpp"
#include "util/v128.hpp"
#include <algorithm> #include <algorithm>
using namespace llvm; using namespace llvm;

View file

@ -6,6 +6,8 @@
#include "PPUOpcodes.h" #include "PPUOpcodes.h"
#include "PPUAnalyser.h" #include "PPUAnalyser.h"
#include "util/types.hpp"
class PPUTranslator final : public cpu_translator class PPUTranslator final : public cpu_translator
{ {
// PPU Module // PPU Module

View file

@ -12,6 +12,7 @@
#include "Crypto/sha1.h" #include "Crypto/sha1.h"
#include "util/asm.hpp" #include "util/asm.hpp"
#include "util/v128.hpp"
#include <cmath> #include <cmath>
#include <mutex> #include <mutex>

View file

@ -5,6 +5,8 @@
#include <functional> #include <functional>
#include "util/v128.hpp"
// SPU ASMJIT Recompiler // SPU ASMJIT Recompiler
class spu_recompiler : public spu_recompiler_base class spu_recompiler : public spu_recompiler_base
{ {

View file

@ -7,6 +7,8 @@ const spu_decoder<SPUDisAsm> s_spu_disasm;
const spu_decoder<spu_itype> s_spu_itype; const spu_decoder<spu_itype> s_spu_itype;
const spu_decoder<spu_iflag> s_spu_iflag; const spu_decoder<spu_iflag> s_spu_iflag;
#include "util/v128.hpp"
u32 SPUDisAsm::disasm(u32 pc) u32 SPUDisAsm::disasm(u32 pc)
{ {
const u32 op = *reinterpret_cast<const be_t<u32>*>(offset + pc); const u32 op = *reinterpret_cast<const be_t<u32>*>(offset + pc);

View file

@ -3,6 +3,8 @@
#include "PPCDisAsm.h" #include "PPCDisAsm.h"
#include "SPUOpcodes.h" #include "SPUOpcodes.h"
#include "util/v128.hpp"
static constexpr const char* spu_reg_name[128] = static constexpr const char* spu_reg_name[128] =
{ {
"lr", "sp", "r2", "r3", "r4", "r5", "r6", "r7", "lr", "sp", "r2", "r3", "r4", "r5", "r6", "r7",

View file

@ -7,6 +7,7 @@
#include "Emu/Cell/Common.h" #include "Emu/Cell/Common.h"
#include "util/asm.hpp" #include "util/asm.hpp"
#include "util/v128.hpp"
#include <cmath> #include <cmath>
#include <cfenv> #include <cfenv>

View file

@ -18,6 +18,8 @@
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include "util/v128.hpp"
extern atomic_t<const char*> g_progr; extern atomic_t<const char*> g_progr;
extern atomic_t<u32> g_progr_ptotal; extern atomic_t<u32> g_progr_ptotal;
extern atomic_t<u32> g_progr_pdone; extern atomic_t<u32> g_progr_pdone;

View file

@ -31,6 +31,7 @@
#include <shared_mutex> #include <shared_mutex>
#include "util/vm.hpp" #include "util/vm.hpp"
#include "util/asm.hpp" #include "util/asm.hpp"
#include "util/v128.hpp"
using spu_rdata_t = decltype(spu_thread::rdata); using spu_rdata_t = decltype(spu_thread::rdata);

View file

@ -4,9 +4,10 @@
#include "Emu/Cell/SPUInterpreter.h" #include "Emu/Cell/SPUInterpreter.h"
#include "Emu/Memory/vm.h" #include "Emu/Memory/vm.h"
#include "MFC.h" #include "MFC.h"
#include "Utilities/BEType.h"
#include <map> #include <map>
#include "util/v128.hpp"
#include "util/to_endian.hpp"
LOG_CHANNEL(spu_log, "SPU"); LOG_CHANNEL(spu_log, "SPU");

View file

@ -4,7 +4,8 @@
#include <memory> #include <memory>
#include "util/types.hpp" #include "util/types.hpp"
#include "Utilities/StrFmt.h" #include "Utilities/StrFmt.h"
#include "Utilities/BEType.h"
#include "util/to_endian.hpp"
namespace utils namespace utils
{ {

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "util/types.hpp" #include "util/types.hpp"
#include "Utilities/BEType.h" #include "util/to_endian.hpp"
#include "vm.h" #include "vm.h"
class ppu_thread; class ppu_thread;

View file

@ -1,9 +1,10 @@
#pragma once #pragma once
#include <type_traits> #include <type_traits>
#include "Utilities/BEType.h"
#include "vm.h" #include "vm.h"
#include "util/to_endian.hpp"
namespace vm namespace vm
{ {
template <typename T, typename AT> template <typename T, typename AT>

View file

@ -1,7 +1,8 @@
#pragma once #pragma once
#include "vm_ptr.h" #include "vm_ptr.h"
#include "Utilities/BEType.h"
#include "util/to_endian.hpp"
namespace vm namespace vm
{ {

View file

@ -7,7 +7,6 @@
#include "rpcn_client.h" #include "rpcn_client.h"
#include "np_structs_extra.h" #include "np_structs_extra.h"
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "Utilities/BEType.h"
#include "Utilities/Thread.h" #include "Utilities/Thread.h"
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/System.h" #include "Emu/System.h"

View file

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "Utilities/BEType.h"
#include "Emu/Memory/vm.h" #include "Emu/Memory/vm.h"
#include "Emu/Memory/vm_ptr.h" #include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/Modules/sceNp.h" #include "Emu/Cell/Modules/sceNp.h"

View file

@ -4,7 +4,8 @@
#include "Utilities/sysinfo.h" #include "Utilities/sysinfo.h"
#include "../RSXThread.h" #include "../RSXThread.h"
#include <limits> #include "util/v128.hpp"
#include "util/to_endian.hpp"
#define DEBUG_VERTEX_STREAMING 0 #define DEBUG_VERTEX_STREAMING 0
@ -667,7 +668,7 @@ void write_vertex_array_data_to_buffer(gsl::span<std::byte> raw_dst_span, gsl::s
u32 src_value; u32 src_value;
memcpy(&src_value, src_ptr.subspan(attribute_src_stride * i).data(), sizeof(u32)); memcpy(&src_value, src_ptr.subspan(attribute_src_stride * i).data(), sizeof(u32));
if (swap_endianness) src_value = se_storage<u32>::swap(src_value); if (swap_endianness) src_value = stx::se_storage<u32>::swap(src_value);
const auto& decoded_vector = decode_cmp_vector(src_value); const auto& decoded_vector = decode_cmp_vector(src_value);
dst_span[i * dst_stride / sizeof(u16)] = decoded_vector[0]; dst_span[i * dst_stride / sizeof(u16)] = decoded_vector[0];

View file

@ -3,6 +3,7 @@
#include "Emu/system_config.h" #include "Emu/system_config.h"
#include <stack> #include <stack>
#include "util/v128.hpp"
using namespace program_hash_util; using namespace program_hash_util;

View file

@ -519,7 +519,8 @@
<ClInclude Include="Emu\system_config.h" /> <ClInclude Include="Emu\system_config.h" />
<ClInclude Include="Emu\system_config_types.h" /> <ClInclude Include="Emu\system_config_types.h" />
<ClInclude Include="util\atomic.hpp" /> <ClInclude Include="util\atomic.hpp" />
<ClInclude Include="..\Utilities\BEType.h" /> <ClInclude Include="util\v128.hpp" />
<ClInclude Include="util\to_endian.hpp" />
<ClInclude Include="..\Utilities\bin_patch.h" /> <ClInclude Include="..\Utilities\bin_patch.h" />
<ClInclude Include="..\Utilities\BitField.h" /> <ClInclude Include="..\Utilities\BitField.h" />
<ClInclude Include="..\Utilities\bit_set.h" /> <ClInclude Include="..\Utilities\bit_set.h" />

View file

@ -1069,7 +1069,10 @@
<ClInclude Include="stdafx.h"> <ClInclude Include="stdafx.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Utilities\BEType.h"> <ClInclude Include="util\v128.hpp">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="util\to_endian.hpp">
<Filter>Utilities</Filter> <Filter>Utilities</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Utilities\StrFmt.h"> <ClInclude Include="..\Utilities\StrFmt.h">

View file

@ -44,6 +44,8 @@ DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResoluti
#include <thread> #include <thread>
#include <charconv> #include <charconv>
#include "util/v128.hpp"
inline std::string sstr(const QString& _in) { return _in.toStdString(); } inline std::string sstr(const QString& _in) { return _in.toStdString(); }
static semaphore<> s_qt_init; static semaphore<> s_qt_init;

View file

@ -18,6 +18,7 @@
#include "Emu/Cell/PPUFunction.h" #include "Emu/Cell/PPUFunction.h"
#include "util/yaml.hpp" #include "util/yaml.hpp"
#include "util/to_endian.hpp"
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "Utilities/bin_patch.h" // get_patches_path() #include "Utilities/bin_patch.h" // get_patches_path()

View file

@ -14,6 +14,8 @@
#include <QMessageBox> #include <QMessageBox>
#include <charconv> #include <charconv>
#include "util/v128.hpp"
constexpr auto qstr = QString::fromStdString; constexpr auto qstr = QString::fromStdString;
inline std::string sstr(const QString& _in) { return _in.toStdString(); } inline std::string sstr(const QString& _in) { return _in.toStdString(); }
inline std::string sstr(const QVariant& _in) { return sstr(_in.toString()); } inline std::string sstr(const QVariant& _in) { return sstr(_in.toString()); }

View file

@ -3,7 +3,6 @@
#include "Crypto/md5.h" #include "Crypto/md5.h"
#include "Crypto/aes.h" #include "Crypto/aes.h"
#include "skylander_dialog.h" #include "skylander_dialog.h"
#include "Utilities/BEType.h"
#include "Emu/Io/Skylander.h" #include "Emu/Io/Skylander.h"
#include <QLabel> #include <QLabel>

View file

@ -14,8 +14,8 @@
#endif #endif
#include "util/types.hpp" #include "util/types.hpp"
#include "Utilities/BEType.h"
#include "util/atomic.hpp" #include "util/atomic.hpp"
#include "util/endian.hpp"
#include "Utilities/StrFmt.h" #include "Utilities/StrFmt.h"
#include "Utilities/File.h" #include "Utilities/File.h"
#include "util/logs.hpp" #include "util/logs.hpp"

78
rpcs3/util/to_endian.hpp Normal file
View file

@ -0,0 +1,78 @@
#pragma once
#include "util/types.hpp"
#include "util/endian.hpp"
union v128;
// Type converter: converts native endianness arithmetic/enum types to appropriate se_t<> type
template <typename T, bool Se, typename = void>
struct to_se
{
template <typename T2, typename = void>
struct to_se_
{
using type = T2;
};
template <typename T2>
struct to_se_<T2, std::enable_if_t<std::is_arithmetic<T2>::value || std::is_enum<T2>::value>>
{
using type = std::conditional_t<(sizeof(T2) > 1), se_t<T2, Se>, T2>;
};
// Convert arithmetic and enum types
using type = typename to_se_<T>::type;
};
template <bool Se>
struct to_se<v128, Se>
{
using type = se_t<v128, Se, 16>;
};
template <bool Se>
struct to_se<u128, Se>
{
using type = se_t<u128, Se>;
};
template <bool Se>
struct to_se<s128, Se>
{
using type = se_t<s128, Se>;
};
template <typename T, bool Se>
struct to_se<const T, Se, std::enable_if_t<!std::is_array<T>::value>>
{
// Move const qualifier
using type = const typename to_se<T, Se>::type;
};
template <typename T, bool Se>
struct to_se<volatile T, Se, std::enable_if_t<!std::is_array<T>::value && !std::is_const<T>::value>>
{
// Move volatile qualifier
using type = volatile typename to_se<T, Se>::type;
};
template <typename T, bool Se>
struct to_se<T[], Se>
{
// Move array qualifier
using type = typename to_se<T, Se>::type[];
};
template <typename T, bool Se, std::size_t N>
struct to_se<T[N], Se>
{
// Move array qualifier
using type = typename to_se<T, Se>::type[N];
};
// BE/LE aliases for to_se<>
template <typename T>
using to_be_t = typename to_se<T, std::endian::little == std::endian::native>::type;
template <typename T>
using to_le_t = typename to_se<T, std::endian::big == std::endian::native>::type;

View file

@ -213,6 +213,28 @@ namespace fmt
template <typename T, std::size_t Align> template <typename T, std::size_t Align>
class atomic_t; class atomic_t;
namespace stx
{
template <typename T, bool Se, std::size_t Align>
class se_t;
}
using stx::se_t;
// se_t<> with native endianness
template <typename T, std::size_t Align = alignof(T)>
using nse_t = se_t<T, false, Align>;
template <typename T, std::size_t Align = alignof(T)>
using be_t = se_t<T, std::endian::little == std::endian::native, Align>;
template <typename T, std::size_t Align = alignof(T)>
using le_t = se_t<T, std::endian::big == std::endian::native, Align>;
template <typename T, std::size_t Align = alignof(T)>
using atomic_be_t = atomic_t<be_t<T>, Align>;
template <typename T, std::size_t Align = alignof(T)>
using atomic_le_t = atomic_t<le_t<T>, Align>;
// Extract T::simple_type if available, remove cv qualifiers // Extract T::simple_type if available, remove cv qualifiers
template <typename T, typename = void> template <typename T, typename = void>
struct simple_type_helper struct simple_type_helper

View file

@ -1,17 +1,9 @@
#pragma once // No BOM and only basic ASCII in this header, or a neko will die #pragma once // No BOM and only basic ASCII in this header, or a neko will die
#include "util/types.hpp" #include "util/types.hpp"
#include "util/endian.hpp"
#include <cstring>
#include <cmath> #include <cmath>
#if __has_include(<bit>) // 128-bit vector type
#include <bit>
#else
#include <type_traits>
#endif
// 128-bit vector type and also se_storage<> storage type
union alignas(16) v128 union alignas(16) v128
{ {
uchar _bytes[16]; uchar _bytes[16];
@ -405,107 +397,3 @@ inline v128 operator~(const v128& other)
{ {
return other ^ v128::from32p(UINT32_MAX); // XOR with ones return other ^ v128::from32p(UINT32_MAX); // XOR with ones
} }
using stx::se_t;
using stx::se_storage;
// se_t<> with native endianness
template <typename T, std::size_t Align = alignof(T)>
using nse_t = se_t<T, false, Align>;
template <typename T, std::size_t Align = alignof(T)>
using be_t = se_t<T, std::endian::little == std::endian::native, Align>;
template <typename T, std::size_t Align = alignof(T)>
using le_t = se_t<T, std::endian::big == std::endian::native, Align>;
// Type converter: converts native endianness arithmetic/enum types to appropriate se_t<> type
template <typename T, bool Se, typename = void>
struct to_se
{
template <typename T2, typename = void>
struct to_se_
{
using type = T2;
};
template <typename T2>
struct to_se_<T2, std::enable_if_t<std::is_arithmetic<T2>::value || std::is_enum<T2>::value>>
{
using type = std::conditional_t<(sizeof(T2) > 1), se_t<T2, Se>, T2>;
};
// Convert arithmetic and enum types
using type = typename to_se_<T>::type;
};
template <bool Se>
struct to_se<v128, Se>
{
using type = se_t<v128, Se>;
};
template <bool Se>
struct to_se<u128, Se>
{
using type = se_t<u128, Se>;
};
template <bool Se>
struct to_se<s128, Se>
{
using type = se_t<s128, Se>;
};
template <typename T, bool Se>
struct to_se<const T, Se, std::enable_if_t<!std::is_array<T>::value>>
{
// Move const qualifier
using type = const typename to_se<T, Se>::type;
};
template <typename T, bool Se>
struct to_se<volatile T, Se, std::enable_if_t<!std::is_array<T>::value && !std::is_const<T>::value>>
{
// Move volatile qualifier
using type = volatile typename to_se<T, Se>::type;
};
template <typename T, bool Se>
struct to_se<T[], Se>
{
// Move array qualifier
using type = typename to_se<T, Se>::type[];
};
template <typename T, bool Se, std::size_t N>
struct to_se<T[N], Se>
{
// Move array qualifier
using type = typename to_se<T, Se>::type[N];
};
// BE/LE aliases for to_se<>
template <typename T>
using to_be_t = typename to_se<T, std::endian::little == std::endian::native>::type;
template <typename T>
using to_le_t = typename to_se<T, std::endian::big == std::endian::native>::type;
// BE/LE aliases for atomic_t
template <typename T, std::size_t Align = alignof(T)>
using atomic_be_t = atomic_t<be_t<T>, Align>;
template <typename T, std::size_t Align = alignof(T)>
using atomic_le_t = atomic_t<le_t<T>, Align>;
template <typename T, bool Se, std::size_t Align>
struct fmt_unveil<se_t<T, Se, Align>, void>
{
using type = typename fmt_unveil<T>::type;
static inline auto get(const se_t<T, Se, Align>& arg)
{
return fmt_unveil<T>::get(arg);
}
};
static_assert(be_t<u16>(1) + be_t<u32>(2) + be_t<u64>(3) == 6);
static_assert(le_t<u16>(1) + le_t<u32>(2) + le_t<u64>(3) == 6);