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 "mutex.h"
#include "StrFmt.h"
#include "BEType.h"
#include "Crypto/sha1.h"
#include <unordered_map>

View File

@ -1,8 +1,9 @@
#include "StrFmt.h"
#include "BEType.h"
#include "StrUtil.h"
#include "cfmt.h"
#include "util/endian.hpp"
#include "util/logs.hpp"
#include "util/v128.hpp"
#include <algorithm>
#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")
template <typename T, typename = void>
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)
{
value = se_storage<u32>::swap(value);
value = stx::se_storage<u32>::swap(value);
}
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);
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -174,7 +174,7 @@ struct audio_port
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));
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,8 @@
#include "PPUThread.h"
#include "util/v128.hpp"
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.

View File

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

View File

@ -66,6 +66,7 @@
#include <cctype>
#include "util/asm.hpp"
#include "util/vm.hpp"
#include "util/v128.hpp"
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);
// 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 mask = se_storage<u32>::swap(0xFC0007FF);
constexpr u32 store_cond = stx::se_storage<u32>::swap(sizeof(T) == 8 ? 0x7C00012D : 0x7C0001AD);
constexpr u32 mask = stx::se_storage<u32>::swap(0xFC0007FF);
const auto store_vec = v128::from32p(store_cond);
const auto mask_vec = v128::from32p(mask);

View File

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

View File

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

View File

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

View File

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

View File

@ -5,6 +5,8 @@
#include <functional>
#include "util/v128.hpp"
// SPU ASMJIT Recompiler
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_iflag> s_spu_iflag;
#include "util/v128.hpp"
u32 SPUDisAsm::disasm(u32 pc)
{
const u32 op = *reinterpret_cast<const be_t<u32>*>(offset + pc);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,8 @@
#include "Utilities/sysinfo.h"
#include "../RSXThread.h"
#include <limits>
#include "util/v128.hpp"
#include "util/to_endian.hpp"
#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;
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);
dst_span[i * dst_stride / sizeof(u16)] = decoded_vector[0];

View File

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

View File

@ -519,7 +519,8 @@
<ClInclude Include="Emu\system_config.h" />
<ClInclude Include="Emu\system_config_types.h" />
<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\BitField.h" />
<ClInclude Include="..\Utilities\bit_set.h" />

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,8 +14,8 @@
#endif
#include "util/types.hpp"
#include "Utilities/BEType.h"
#include "util/atomic.hpp"
#include "util/endian.hpp"
#include "Utilities/StrFmt.h"
#include "Utilities/File.h"
#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>
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
template <typename T, typename = void>
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
#include "util/types.hpp"
#include "util/endian.hpp"
#include <cstring>
#include <cmath>
#if __has_include(<bit>)
#include <bit>
#else
#include <type_traits>
#endif
// 128-bit vector type and also se_storage<> storage type
// 128-bit vector type
union alignas(16) v128
{
uchar _bytes[16];
@ -405,107 +397,3 @@ inline v128 operator~(const v128& other)
{
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);