From 0d28f378a76fd78bfd3095c034818a168a46c066 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 19 Jan 2015 01:54:56 +0300 Subject: [PATCH] fmt::format() optimization (fmt::unveil template) --- Utilities/BEType.h | 28 ++-- Utilities/Log.cpp | 15 ++ Utilities/Log.h | 25 +-- Utilities/StrFmt.cpp | 102 +++++++++++- Utilities/StrFmt.h | 207 ++++++++++-------------- Utilities/Thread.cpp | 24 +-- rpcs3/Emu/ARMv7/PSVFuncList.h | 6 +- rpcs3/Emu/CPU/CPUDisAsm.h | 8 +- rpcs3/Emu/CPU/CPUThread.h | 10 +- rpcs3/Emu/CPU/CPUThreadManager.cpp | 2 +- rpcs3/Emu/Cell/PPCThread.h | 2 +- rpcs3/Emu/Memory/vm_ptr.h | 52 +++--- rpcs3/Emu/Memory/vm_ref.h | 52 +++--- rpcs3/Emu/SysCalls/CB_FUNC.h | 12 +- rpcs3/Emu/SysCalls/LogBase.cpp | 22 +-- rpcs3/Emu/SysCalls/LogBase.h | 71 +++----- rpcs3/Emu/SysCalls/Modules/cellDmux.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellGame.cpp | 4 +- rpcs3/Emu/SysCalls/SC_FUNC.h | 6 +- rpcs3/Emu/SysCalls/lv2/cellFs.cpp | 2 +- 20 files changed, 343 insertions(+), 309 deletions(-) diff --git a/Utilities/BEType.h b/Utilities/BEType.h index dbb289208e..27997618bd 100644 --- a/Utilities/BEType.h +++ b/Utilities/BEType.h @@ -758,86 +758,86 @@ template struct _se, T1, value> : pub #define se32(x) _se::value #define se64(x) _se::value -template __forceinline static u8 Read8(T& f) +template __forceinline u8 Read8(T& f) { u8 ret; f.Read(&ret, sizeof(ret)); return ret; } -template __forceinline static u16 Read16(T& f) +template __forceinline u16 Read16(T& f) { be_t ret; f.Read(&ret, sizeof(ret)); return ret; } -template __forceinline static u32 Read32(T& f) +template __forceinline u32 Read32(T& f) { be_t ret; f.Read(&ret, sizeof(ret)); return ret; } -template __forceinline static u64 Read64(T& f) +template __forceinline u64 Read64(T& f) { be_t ret; f.Read(&ret, sizeof(ret)); return ret; } -template __forceinline static u16 Read16LE(T& f) +template __forceinline u16 Read16LE(T& f) { u16 ret; f.Read(&ret, sizeof(ret)); return ret; } -template __forceinline static u32 Read32LE(T& f) +template __forceinline u32 Read32LE(T& f) { u32 ret; f.Read(&ret, sizeof(ret)); return ret; } -template __forceinline static u64 Read64LE(T& f) +template __forceinline u64 Read64LE(T& f) { u64 ret; f.Read(&ret, sizeof(ret)); return ret; } -template __forceinline static void Write8(T& f, const u8 data) +template __forceinline void Write8(T& f, const u8 data) { f.Write(&data, sizeof(data)); } -template __forceinline static void Write16LE(T& f, const u16 data) +template __forceinline void Write16LE(T& f, const u16 data) { f.Write(&data, sizeof(data)); } -template __forceinline static void Write32LE(T& f, const u32 data) +template __forceinline void Write32LE(T& f, const u32 data) { f.Write(&data, sizeof(data)); } -template __forceinline static void Write64LE(T& f, const u64 data) +template __forceinline void Write64LE(T& f, const u64 data) { f.Write(&data, sizeof(data)); } -template __forceinline static void Write16(T& f, const u16 data) +template __forceinline void Write16(T& f, const u16 data) { Write16LE(f, re16(data)); } -template __forceinline static void Write32(T& f, const u32 data) +template __forceinline void Write32(T& f, const u32 data) { Write32LE(f, re32(data)); } -template __forceinline static void Write64(T& f, const u64 data) +template __forceinline void Write64(T& f, const u64 data) { Write64LE(f, re64(data)); } diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 562be95d8a..a6b3319940 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -235,3 +235,18 @@ LogChannel &LogManager::getChannel(LogType type) { return mChannels[static_cast(type)]; } + +void log_message(Log::LogType type, Log::LogSeverity sev, const char* text) +{ + //another msvc bug makes this not work, uncomment this and delete everything else in this function when it's fixed + //Log::LogManager::getInstance().log({logType, severity, text}) + + Log::LogMessage msg{ type, sev, text }; + Log::LogManager::getInstance().log(msg); +} + +void log_message(Log::LogType type, Log::LogSeverity sev, const std::string& text) +{ + Log::LogMessage msg{ type, sev, text }; + Log::LogManager::getInstance().log(msg); +} diff --git a/Utilities/Log.h b/Utilities/Log.h index 23e0de0dc4..2eaf876f27 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -126,24 +126,11 @@ static struct { inline operator Log::LogType() { return Log::LogType::SPU; } } S static struct { inline operator Log::LogType() { return Log::LogType::ARMv7; } } ARMv7; static struct { inline operator Log::LogType() { return Log::LogType::TTY; } } TTY; -inline void log_message(Log::LogType type, Log::LogSeverity sev, const char* text) -{ - //another msvc bug makes this not work, uncomment this and delete everything else in this function when it's fixed - //Log::LogManager::getInstance().log({logType, severity, text}) +void log_message(Log::LogType type, Log::LogSeverity sev, const char* text); +void log_message(Log::LogType type, Log::LogSeverity sev, const std::string& text); - Log::LogMessage msg{ type, sev, text }; - Log::LogManager::getInstance().log(msg); +template +__noinline void log_message(Log::LogType type, Log::LogSeverity sev, const char* fmt, Targs... args) +{ + log_message(type, sev, fmt::detail::format(fmt, strlen(fmt), fmt::do_unveil(args)...)); } - -inline void log_message(Log::LogType type, Log::LogSeverity sev, const std::string& text) -{ - Log::LogMessage msg{ type, sev, text }; - Log::LogManager::getInstance().log(msg); -} - -template -inline void log_message(Log::LogType type, Log::LogSeverity sev, const char* text, T arg, Ts... args) -{ - Log::LogMessage msg{ type, sev, fmt::format(text, arg, args...) }; - Log::LogManager::getInstance().log(msg); -} \ No newline at end of file diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index 7835bf0c9e..dcd7214430 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -3,7 +3,7 @@ std::string u128::to_hex() const { - return fmt::Format("%016llx%016llx", _u64[1], _u64[0]); + return fmt::format("%016llx%016llx", _u64[1], _u64[0]); } std::string u128::to_xyzw() const @@ -11,6 +11,106 @@ std::string u128::to_xyzw() const return fmt::Format("x: %g y: %g z: %g w: %g", _f[3], _f[2], _f[1], _f[0]); } +std::string fmt::detail::to_hex(u64 value, size_t count) +{ + assert(count - 1 < 16); + count = std::max(count, 16 - cntlz64(value) / 4); + + char res[16] = {}; + + for (size_t i = count - 1; ~i; i--, value /= 16) + { + res[i] = "0123456789abcdef"[value % 16]; + } + + return std::string(res, count); +} + +size_t fmt::detail::get_fmt_start(const char* fmt, size_t len) +{ + for (size_t i = 0; i < len; i++) + { + if (fmt[i] == '%') + { + return i; + } + } + + return len; +} + +size_t fmt::detail::get_fmt_len(const char* fmt, size_t len) +{ + assert(len >= 2 && fmt[0] == '%'); + + size_t res = 2; + + if (fmt[1] == '.' || fmt[1] == '0') + { + assert(len >= 4 && fmt[2] - '1' < 9); + res += 2; + fmt += 2; + len -= 2; + + if (fmt[1] == '1') + { + assert(len >= 3 && fmt[2] - '0' < 7); + res++; + fmt++; + len--; + } + } + + if (fmt[1] == 'l') + { + assert(len >= 3); + res++; + fmt++; + len--; + } + + if (fmt[1] == 'l') + { + assert(len >= 3); + res++; + fmt++; + len--; + } + + return res; +} + +size_t fmt::detail::get_fmt_precision(const char* fmt, size_t len) +{ + assert(len >= 2); + + if (fmt[1] == '.' || fmt[1] == '0') + { + assert(len >= 4 && fmt[2] - '1' < 9); + + if (fmt[2] == '1') + { + assert(len >= 5 && fmt[3] - '0' < 7); + return 10 + fmt[3] - '0'; + } + + return fmt[2] - '0'; + } + + return 1; +} + +std::string fmt::detail::format(const char* fmt, size_t len) +{ + const size_t fmt_start = get_fmt_start(fmt, len); + if (fmt_start != len) + { + throw "Excessive formatting: " + std::string(fmt, len); + } + + return std::string(fmt, len); +} + extern const std::string fmt::placeholder = "???"; std::string replace_first(const std::string& src, const std::string& from, const std::string& to) diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 8e9c2bfb5a..8e19d8c5df 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -175,114 +175,16 @@ namespace fmt namespace detail { - static std::string to_hex(u64 value, size_t count = 1) - { - assert(count - 1 < 16); - count = std::max(count, 16 - cntlz64(value) / 4); + std::string to_hex(u64 value, size_t count = 1); - char res[16] = {}; + size_t get_fmt_start(const char* fmt, size_t len); + size_t get_fmt_len(const char* fmt, size_t len); + size_t get_fmt_precision(const char* fmt, size_t len); - for (size_t i = count - 1; ~i; i--, value /= 16) - { - res[i] = "0123456789abcdef"[value % 16]; - } - - return std::string(res, count); - } - - static size_t get_fmt_start(const char* fmt, size_t len) - { - for (size_t i = 0; i < len; i++) - { - if (fmt[i] == '%') - { - return i; - } - } - - return len; - } - - static size_t get_fmt_len(const char* fmt, size_t len) - { - assert(len >= 2 && fmt[0] == '%'); - - size_t res = 2; - - if (fmt[1] == '.' || fmt[1] == '0') - { - assert(len >= 4 && fmt[2] - '1' < 9); - res += 2; - fmt += 2; - len -= 2; - - if (fmt[1] == '1') - { - assert(len >= 3 && fmt[2] - '0' < 7); - res++; - fmt++; - len--; - } - } - - if (fmt[1] == 'l') - { - assert(len >= 3); - res++; - fmt++; - len--; - } - - if (fmt[1] == 'l') - { - assert(len >= 3); - res++; - fmt++; - len--; - } - - return res; - } - - static size_t get_fmt_precision(const char* fmt, size_t len) - { - assert(len >= 2); - - if (fmt[1] == '.' || fmt[1] == '0') - { - assert(len >= 4 && fmt[2] - '1' < 9); - - if (fmt[2] == '1') - { - assert(len >= 5 && fmt[3] - '0' < 7); - return 10 + fmt[3] - '0'; - } - - return fmt[2] - '0'; - } - - return 1; - } - - template::value> + template struct get_fmt { - static_assert(is_enum, "Unsupported fmt::format argument"); - typedef typename std::underlying_type::type underlying_type; - - static std::string text(const char* fmt, size_t len, const T& arg) - { - return get_fmt::text(fmt, len, (underlying_type)arg); - } - }; - - template - struct get_fmt, false> - { - static std::string text(const char* fmt, size_t len, const be_t& arg) - { - return get_fmt::text(fmt, len, arg.value()); - } + static_assert(!sizeof(T), "Unsupported fmt::format argument"); }; template<> @@ -621,16 +523,10 @@ namespace fmt } }; - static std::string format(const char* fmt, size_t len) - { - const size_t fmt_start = get_fmt_start(fmt, len); - assert(fmt_start == len); - - return std::string(fmt, len); - } + std::string format(const char* fmt, size_t len); // terminator template - static std::string format(const char* fmt, size_t len, const T& arg, Args... args) + std::string format(const char* fmt, size_t len, const T& arg, Args... args) { const size_t fmt_start = get_fmt_start(fmt, len); const size_t fmt_len = get_fmt_len(fmt + fmt_start, len - fmt_start); @@ -640,8 +536,72 @@ namespace fmt } }; - // formatting function with very limited functionality (compared to printf-like formatting) and be_t<> support + template::value> + struct unveil + { + typedef T result_type; + + __forceinline static result_type get_value(const T& arg) + { + return arg; + } + }; + + template + struct unveil + { + typedef const char* result_type; + + __forceinline static result_type get_value(const char(&arg)[N]) + { + return arg; + } + }; + + template<> + struct unveil + { + typedef const std::string& result_type; + + __forceinline static result_type get_value(const std::string& arg) + { + return arg; + } + }; + + template + struct unveil + { + typedef typename std::underlying_type::type result_type; + + __forceinline static result_type get_value(const T& arg) + { + return static_cast(arg); + } + }; + + template + struct unveil, false> + { + typedef typename unveil::result_type result_type; + + __forceinline static result_type get_value(const be_t& arg) + { + return unveil::get_value(arg.value()); + } + }; + + template + __forceinline typename unveil::result_type do_unveil(const T& arg) + { + return unveil::get_value(arg); + } + /* + fmt::format(const char* fmt, args...) + + Formatting function with very limited functionality (compared to printf-like formatting) and be_t<> support + Supported types: u8, s8 (%x, %d) @@ -652,16 +612,17 @@ namespace fmt double (%x, %f) bool (%x, %d, %s) char*, const char*, std::string (%s) - be_t<> of any appropriate type in this list - enum of any appropriate type in this list + + be_t<> of any appropriate type in this list (fmt::unveil) + enum of any appropriate type in this list (fmt::unveil) External specializations (can be found in another headers): - vm::ps3::ptr (vm_ptr.h) (with appropriate address type, using .addr() can be avoided) - vm::ps3::bptr (vm_ptr.h) - vm::psv::ptr (vm_ptr.h) - vm::ps3::ref (vm_ref.h) - vm::ps3::bref (vm_ref.h) - vm::psv::ref (vm_ref.h) + vm::ps3::ptr (fmt::unveil) (vm_ptr.h) (with appropriate address type, using .addr() can be avoided) + vm::ps3::bptr (fmt::unveil) (vm_ptr.h) + vm::psv::ptr (fmt::unveil) (vm_ptr.h) + vm::ps3::ref (fmt::unveil) (vm_ref.h) + vm::ps3::bref (fmt::unveil) (vm_ref.h) + vm::psv::ref (fmt::unveil) (vm_ref.h) Supported formatting: %d - decimal; only basic std::to_string() functionality @@ -672,9 +633,9 @@ namespace fmt Other features are not supported. */ template - __forceinline static std::string format(const char* fmt, Args... args) + __forceinline std::string format(const char* fmt, Args... args) { - return detail::format(fmt, strlen(fmt), args...); + return detail::format(fmt, strlen(fmt), do_unveil(args)...); } //convert a wxString to a std::string encoded in utf8 diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index a3a6599e67..2539c791cd 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -90,9 +90,9 @@ void decode_x64_reg_op(const u8* code, x64_op_t& decoded_op, x64_reg_t& decoded_ { switch (const u8 prefix = *code) { - case 0xf0: throw fmt::Format("decode_x64_reg_op(%.16llXh): 0x%.2X (LOCK prefix) found", code - decoded_size, prefix); // group 1 - case 0xf2: throw fmt::Format("decode_x64_reg_op(%.16llXh): 0x%.2X (REPNE/REPNZ prefix) found", code - decoded_size, prefix); // group 1 - case 0xf3: throw fmt::Format("decode_x64_reg_op(%.16llXh): 0x%.2X (REP/REPE/REPZ prefix) found", code - decoded_size, prefix); // group 1 + case 0xf0: throw fmt::format("decode_x64_reg_op(%016llxh): 0x%02x (LOCK prefix) found", (size_t)code - decoded_size, prefix); // group 1 + case 0xf2: throw fmt::format("decode_x64_reg_op(%016llxh): 0x%02x (REPNE/REPNZ prefix) found", (size_t)code - decoded_size, prefix); // group 1 + case 0xf3: throw fmt::format("decode_x64_reg_op(%016llxh): 0x%02x (REP/REPE/REPZ prefix) found", (size_t)code - decoded_size, prefix); // group 1 case 0x2e: // group 2 case 0x36: @@ -108,12 +108,12 @@ void decode_x64_reg_op(const u8* code, x64_op_t& decoded_op, x64_reg_t& decoded_ } else { - throw fmt::Format("decode_x64_reg_op(%.16llXh): 0x%.2X (group 2 prefix) found after 0x%.2X", code - decoded_size, prefix, pg2); + throw fmt::format("decode_x64_reg_op(%016llxh): 0x%02x (group 2 prefix) found after 0x%02x", (size_t)code - decoded_size, prefix, pg2); } } - case 0x66: throw fmt::Format("decode_x64_reg_op(%.16llXh): 0x%.2X (operand-size override prefix) found", code - decoded_size, prefix); // group 3 - case 0x67: throw fmt::Format("decode_x64_reg_op(%.16llXh): 0x%.2X (address-size override prefix) found", code - decoded_size, prefix); // group 4 + case 0x66: throw fmt::format("decode_x64_reg_op(%016llxh): 0x%02x (operand-size override prefix) found", (size_t)code - decoded_size, prefix); // group 3 + case 0x67: throw fmt::format("decode_x64_reg_op(%016llxh): 0x%02x (address-size override prefix) found", (size_t)code - decoded_size, prefix); // group 4 default: { @@ -121,11 +121,11 @@ void decode_x64_reg_op(const u8* code, x64_op_t& decoded_op, x64_reg_t& decoded_ { if (rex) { - throw fmt::Format("decode_x64_reg_op(%.16llXh): 0x%.2X (REX prefix) found after 0x%.2X", code - decoded_size, prefix, rex); + throw fmt::format("decode_x64_reg_op(%016llxh): 0x%02x (REX prefix) found after 0x%02x", (size_t)code - decoded_size, prefix, rex); } if (prefix & 0x80) // check REX.W bit { - throw fmt::Format("decode_x64_reg_op(%.16llXh): 0x%.2X (REX.W bit) found", code - decoded_size, prefix); + throw fmt::format("decode_x64_reg_op(%016llxh): 0x%02x (REX.W bit) found", (size_t)code - decoded_size, prefix); } if (prefix & 0x04) // check REX.R bit { @@ -185,7 +185,7 @@ void decode_x64_reg_op(const u8* code, x64_op_t& decoded_op, x64_reg_t& decoded_ } default: { - throw fmt::Format("decode_x64_reg_op(%.16llXh): unsupported opcode found (0x%.2X, 0x%.2X, 0x%.2X)", code - decoded_size, op1, code[0], code[1]); + throw fmt::format("decode_x64_reg_op(%016llxh): unsupported opcode found (0x%02x, 0x%02x, 0x%02x)", (size_t)code - decoded_size, op1, code[0], code[1]); } } } @@ -297,7 +297,7 @@ void _se_translator(unsigned int u, EXCEPTION_POINTERS* pExp) // it's dangerous because destructors won't be executed } - throw fmt::Format("Access violation %s location 0x%llx", is_writing ? "writing" : "reading", addr64); + throw fmt::format("Access violation %s location 0x%llx", is_writing ? "writing" : "reading", addr64); } // else some fatal error (should crash) @@ -316,7 +316,7 @@ void signal_handler(int sig, siginfo_t* info, void* uct) } // TODO: this may be wrong - throw fmt::Format("Access violation %s location 0x%llx", /*is_writing ? "writing" : "reading"*/ "at", addr64); + throw fmt::format("Access violation at location 0x%llx", addr64); } // else some fatal error @@ -354,7 +354,7 @@ void SetCurrentNamedThread(NamedThreadBase* value) if (value && value->m_tls_assigned.exchange(true)) { - LOG_ERROR(GENERAL, "Thread '%s' was already assigned to g_tls_this_thread of another thread", value->GetThreadName().c_str()); + LOG_ERROR(GENERAL, "Thread '%s' was already assigned to g_tls_this_thread of another thread", value->GetThreadName()); g_tls_this_thread = nullptr; } else diff --git a/rpcs3/Emu/ARMv7/PSVFuncList.h b/rpcs3/Emu/ARMv7/PSVFuncList.h index 5dda63c3db..dfd97f6166 100644 --- a/rpcs3/Emu/ARMv7/PSVFuncList.h +++ b/rpcs3/Emu/ARMv7/PSVFuncList.h @@ -519,21 +519,21 @@ namespace psv_func_detail }; template - static __forceinline RT call(F f, Tuple && t) + __forceinline RT call(F f, Tuple && t) { typedef typename std::decay::type ttype; return psv_func_detail::call_impl::value, std::tuple_size::value>::call(f, std::forward(t)); } template - static __forceinline std::tuple<> iterate(ARMv7Thread& CPU) + __forceinline std::tuple<> iterate(ARMv7Thread& CPU) { // terminator return std::tuple<>(); } template - static __forceinline std::tuple iterate(ARMv7Thread& CPU) + __forceinline std::tuple iterate(ARMv7Thread& CPU) { static_assert(!std::is_pointer::value, "Invalid function argument type (pointer)"); static_assert(!std::is_reference::value, "Invalid function argument type (reference)"); diff --git a/rpcs3/Emu/CPU/CPUDisAsm.h b/rpcs3/Emu/CPU/CPUDisAsm.h index 9fe6ce1692..7c4d9badb0 100644 --- a/rpcs3/Emu/CPU/CPUDisAsm.h +++ b/rpcs3/Emu/CPU/CPUDisAsm.h @@ -18,19 +18,19 @@ protected: switch(m_mode) { case CPUDisAsm_DumpMode: - last_opcode = fmt::Format("\t%08x:\t%02x %02x %02x %02x\t%s\n", dump_pc, + last_opcode = fmt::format("\t%08x:\t%02x %02x %02x %02x\t%s\n", dump_pc, offset[dump_pc], offset[dump_pc + 1], offset[dump_pc + 2], - offset[dump_pc + 3], value.c_str()); + offset[dump_pc + 3], value); break; case CPUDisAsm_InterpreterMode: - last_opcode = fmt::Format("[%08x] %02x %02x %02x %02x: %s", dump_pc, + last_opcode = fmt::format("[%08x] %02x %02x %02x %02x: %s", dump_pc, offset[dump_pc], offset[dump_pc + 1], offset[dump_pc + 2], - offset[dump_pc + 3], value.c_str()); + offset[dump_pc + 3], value); break; case CPUDisAsm_CompilerElfMode: diff --git a/rpcs3/Emu/CPU/CPUThread.h b/rpcs3/Emu/CPU/CPUThread.h index 6b1471705b..7261d0f28d 100644 --- a/rpcs3/Emu/CPU/CPUThread.h +++ b/rpcs3/Emu/CPU/CPUThread.h @@ -70,12 +70,7 @@ public: std::string GetName() const { return NamedThreadBase::GetThreadName(); } std::string GetFName() const { - return - fmt::Format("%s[%d] Thread%s", - GetTypeString().c_str(), - m_id, - (GetName().empty() ? std::string("") : fmt::Format(" (%s)", GetName().c_str())).c_str() - ); + return fmt::format("%s[%d] Thread (%s)", GetTypeString(), m_id, GetName()); } static std::string CPUThreadTypeToString(CPUThreadType type) @@ -111,8 +106,7 @@ public: virtual std::string GetThreadName() const { - std::string temp = (GetFName() + fmt::Format("[0x%08x]", PC)); - return temp; + return fmt::format("%s[0x%08x]", GetFName(), PC); } CPUDecoder * GetDecoder() { return m_dec; }; diff --git a/rpcs3/Emu/CPU/CPUThreadManager.cpp b/rpcs3/Emu/CPU/CPUThreadManager.cpp index 493d1896cc..fa682b4e82 100644 --- a/rpcs3/Emu/CPU/CPUThreadManager.cpp +++ b/rpcs3/Emu/CPU/CPUThreadManager.cpp @@ -55,7 +55,7 @@ CPUThread& CPUThreadManager::AddThread(CPUThreadType type) default: assert(0); } - new_thread->SetId(Emu.GetIdManager().GetNewID(fmt::Format("%s Thread", new_thread->GetTypeString().c_str()), new_thread)); + new_thread->SetId(Emu.GetIdManager().GetNewID(new_thread->GetTypeString() + " Thread", new_thread)); m_threads.push_back(new_thread); SendDbgCommand(DID_CREATE_THREAD, new_thread.get()); diff --git a/rpcs3/Emu/Cell/PPCThread.h b/rpcs3/Emu/Cell/PPCThread.h index c7e5dab93c..99471f7a80 100644 --- a/rpcs3/Emu/Cell/PPCThread.h +++ b/rpcs3/Emu/Cell/PPCThread.h @@ -9,7 +9,7 @@ public: virtual std::string GetThreadName() const { - return (GetFName() + fmt::Format("[0x%08x]", PC)); + return fmt::format("%s[0x%08x]", GetFName(), PC); } protected: diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 122753b0ee..d0c061c096 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -501,33 +501,37 @@ namespace vm namespace fmt { // external specializations for fmt::format function - namespace detail + + template + struct unveil, false> { - template - struct get_fmt, false> - { - __forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::ptr& arg) - { - return get_fmt::text(fmt, len, arg.addr()); - } - }; + typedef typename unveil::result_type result_type; - template - struct get_fmt, false> + __forceinline static result_type get_value(const vm::ps3::ptr& arg) { - __forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::bptr& arg) - { - return get_fmt::text(fmt, len, arg.addr()); - } - }; + return unveil::get_value(arg.addr()); + } + }; - template - struct get_fmt, false> + template + struct unveil, false> + { + typedef typename unveil::result_type result_type; + + __forceinline static result_type get_value(const vm::ps3::bptr& arg) { - __forceinline static std::string text(const char* fmt, size_t len, const vm::psv::ptr& arg) - { - return get_fmt::text(fmt, len, arg.addr()); - } - }; - } + return unveil::get_value(arg.addr()); + } + }; + + template + struct unveil, false> + { + typedef typename unveil::result_type result_type; + + __forceinline static result_type get_value(const vm::psv::ptr& arg) + { + return unveil::get_value(arg.addr()); + } + }; } diff --git a/rpcs3/Emu/Memory/vm_ref.h b/rpcs3/Emu/Memory/vm_ref.h index 1cb8353442..7a21693bf0 100644 --- a/rpcs3/Emu/Memory/vm_ref.h +++ b/rpcs3/Emu/Memory/vm_ref.h @@ -113,33 +113,37 @@ namespace vm namespace fmt { // external specializations for fmt::format function - namespace detail + + template + struct unveil, false> { - template - struct get_fmt, false> - { - __forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::ref& arg) - { - return get_fmt::text(fmt, len, arg.addr()); - } - }; + typedef typename unveil::result_type result_type; - template - struct get_fmt, false> + __forceinline static result_type get_value(const vm::ps3::ref& arg) { - __forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::bref& arg) - { - return get_fmt::text(fmt, len, arg.addr()); - } - }; + return unveil::get_value(arg.addr()); + } + }; - template - struct get_fmt, false> + template + struct unveil, false> + { + typedef typename unveil::result_type result_type; + + __forceinline static result_type get_value(const vm::ps3::bref& arg) { - __forceinline static std::string text(const char* fmt, size_t len, const vm::psv::ref& arg) - { - return get_fmt::text(fmt, len, arg.addr()); - } - }; - } + return unveil::get_value(arg.addr()); + } + }; + + template + struct unveil, false> + { + typedef typename unveil::result_type result_type; + + __forceinline static result_type get_value(const vm::psv::ref& arg) + { + return unveil::get_value(arg.addr()); + } + }; } diff --git a/rpcs3/Emu/SysCalls/CB_FUNC.h b/rpcs3/Emu/SysCalls/CB_FUNC.h index ac49cb90b5..e567225185 100644 --- a/rpcs3/Emu/SysCalls/CB_FUNC.h +++ b/rpcs3/Emu/SysCalls/CB_FUNC.h @@ -181,13 +181,13 @@ namespace vm } template -RT cb_call(PPUThread& CPU, u32 pc, u32 rtoc, T... args) +__forceinline RT cb_call(PPUThread& CPU, u32 pc, u32 rtoc, T... args) { return cb_detail::_func_caller::call(CPU, pc, rtoc, args...); } -template -void cb_call(PPUThread& CPU, u32 pc, u32 rtoc, T... args) -{ - cb_detail::_func_caller::call(CPU, pc, rtoc, args...); -} \ No newline at end of file +//template +//void cb_call(PPUThread& CPU, u32 pc, u32 rtoc, T... args) +//{ +// cb_detail::_func_caller::call(CPU, pc, rtoc, args...); +//} diff --git a/rpcs3/Emu/SysCalls/LogBase.cpp b/rpcs3/Emu/SysCalls/LogBase.cpp index 8842757919..f0ff6628fb 100644 --- a/rpcs3/Emu/SysCalls/LogBase.cpp +++ b/rpcs3/Emu/SysCalls/LogBase.cpp @@ -9,25 +9,15 @@ bool LogBase::CheckLogging() const return Ini.HLELogging.GetValue() || m_logging; } -void LogBase::LogOutput(LogType type, const char* info, const std::string& text) const +void LogBase::LogOutput(LogType type, const std::string& text) const { switch (type) { - case LogNotice: LOG_NOTICE(HLE, "%s%s%s", GetName().c_str(), info, text.c_str()); break; - case LogSuccess: LOG_SUCCESS(HLE, "%s%s%s", GetName().c_str(), info, text.c_str()); break; - case LogWarning: LOG_WARNING(HLE, "%s%s%s", GetName().c_str(), info, text.c_str()); break; - case LogError: LOG_ERROR(HLE, "%s%s%s", GetName().c_str(), info, text.c_str()); break; - } -} - -void LogBase::LogOutput(LogType type, const u32 id, const char* info, const std::string& text) const -{ - switch (type) - { - case LogNotice: LOG_NOTICE(HLE, "%s[%d]%s%s", GetName().c_str(), id, info, text.c_str()); break; - case LogSuccess: LOG_SUCCESS(HLE, "%s[%d]%s%s", GetName().c_str(), id, info, text.c_str()); break; - case LogWarning: LOG_WARNING(HLE, "%s[%d]%s%s", GetName().c_str(), id, info, text.c_str()); break; - case LogError: LOG_ERROR(HLE, "%s[%d]%s%s", GetName().c_str(), id, info, text.c_str()); break; + case LogNotice: LOG_NOTICE(HLE, GetName() + ": " + text); break; + case LogSuccess: LOG_SUCCESS(HLE, GetName() + ": " + text); break; + case LogWarning: LOG_WARNING(HLE, GetName() + ": " + text); break; + case LogError: LOG_ERROR(HLE, GetName() + " error: " + text); break; + case LogTodo: LOG_ERROR(HLE, GetName() + " TODO: " + text); break; } } diff --git a/rpcs3/Emu/SysCalls/LogBase.h b/rpcs3/Emu/SysCalls/LogBase.h index 9c87a27a5f..7f496d6c6e 100644 --- a/rpcs3/Emu/SysCalls/LogBase.h +++ b/rpcs3/Emu/SysCalls/LogBase.h @@ -11,10 +11,16 @@ class LogBase LogSuccess, LogWarning, LogError, + LogTodo, }; - void LogOutput(LogType type, const char* info, const std::string& text) const; - void LogOutput(LogType type, const u32 id, const char* info, const std::string& text) const; + void LogOutput(LogType type, const std::string& text) const; + + template + __noinline void LogPrepare(LogType type, const char* fmt, size_t len, Targs... args) const + { + LogOutput(type, fmt::detail::format(fmt, len, args...)); + } public: void SetLogging(bool value) @@ -29,17 +35,14 @@ public: virtual const std::string& GetName() const = 0; - template __noinline void Notice(const u32 id, const char* fmt, Targs... args) const + template + __forceinline void Notice(const char* fmt, Targs... args) const { - LogOutput(LogNotice, id, " : ", fmt::format(fmt, args...)); + LogPrepare(LogNotice, fmt, strlen(fmt), fmt::do_unveil(args)...); } - template __noinline void Notice(const char* fmt, Targs... args) const - { - LogOutput(LogNotice, ": ", fmt::format(fmt, args...)); - } - - template __forceinline void Log(const char* fmt, Targs... args) const + template + __forceinline void Log(const char* fmt, Targs... args) const { if (CheckLogging()) { @@ -47,52 +50,28 @@ public: } } - template __forceinline void Log(const u32 id, const char* fmt, Targs... args) const + template + __forceinline void Success(const char* fmt, Targs... args) const { - if (CheckLogging()) - { - Notice(id, fmt, args...); - } + LogPrepare(LogSuccess, fmt, strlen(fmt), fmt::do_unveil(args)...); } - template __noinline void Success(const u32 id, const char* fmt, Targs... args) const + template + __forceinline void Warning(const char* fmt, Targs... args) const { - LogOutput(LogSuccess, id, " : ", fmt::format(fmt, args...)); + LogPrepare(LogWarning, fmt, strlen(fmt), fmt::do_unveil(args)...); } - template __noinline void Success(const char* fmt, Targs... args) const + template + __forceinline void Error(const char* fmt, Targs... args) const { - LogOutput(LogSuccess, ": ", fmt::format(fmt, args...)); + LogPrepare(LogError, fmt, strlen(fmt), fmt::do_unveil(args)...); } - template __noinline void Warning(const u32 id, const char* fmt, Targs... args) const + template + __forceinline void Todo(const char* fmt, Targs... args) const { - LogOutput(LogWarning, id, " warning: ", fmt::format(fmt, args...)); - } - - template __noinline void Warning(const char* fmt, Targs... args) const - { - LogOutput(LogWarning, " warning: ", fmt::format(fmt, args...)); - } - - template __noinline void Error(const u32 id, const char* fmt, Targs... args) const - { - LogOutput(LogError, id, " error: ", fmt::format(fmt, args...)); - } - - template __noinline void Error(const char* fmt, Targs... args) const - { - LogOutput(LogError, " error: ", fmt::format(fmt, args...)); - } - - template __noinline void Todo(const u32 id, const char* fmt, Targs... args) const - { - LogOutput(LogError, id, " TODO: ", fmt::format(fmt, args...)); - } - - template __noinline void Todo(const char* fmt, Targs... args) const - { - LogOutput(LogError, " TODO: ", fmt::format(fmt, args...)); + LogPrepare(LogTodo, fmt, strlen(fmt), fmt::do_unveil(args)...); } }; diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp index a2a80f1719..cea8ba8569 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp @@ -995,7 +995,7 @@ int cellDmuxEnableEs(u32 demuxerHandle, vm::ptr esFil *esHandle = id; cellDmux->Warning("*** New ES(dmux=%d, addr=0x%x, size=0x%x, filter(0x%x, 0x%x, 0x%x, 0x%x), cb=0x%x(arg=0x%x), spec=0x%x): id = %d", - demuxerHandle, es->memAddr, es->memSize, es->fidMajor, es->fidMinor, es->sup1, es->sup2, esCb->cbEsMsgFunc, es->cbArg, es->spec, id); + demuxerHandle, es->memAddr, es->memSize, es->fidMajor, es->fidMinor, es->sup1, es->sup2, es->cbFunc, es->cbArg, es->spec, id); DemuxerTask task(dmuxEnableEs); task.es.es = id; diff --git a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp index 1b8351b1d3..6fb4df09ca 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp @@ -443,11 +443,11 @@ int cellGameContentErrorDialog(s32 type, s32 errNeedSizeKB, vm::ptr std::string errorMsg; if (type == CELL_GAME_ERRDIALOG_NOSPACE || type == CELL_GAME_ERRDIALOG_NOSPACE_EXIT) { - errorMsg = fmt::Format("ERROR: %s\nSpace needed: %d KB", errorName.c_str(), errNeedSizeKB, dirName); + errorMsg = fmt::format("ERROR: %s\nSpace needed: %d KB", errorName, errNeedSizeKB); } else { - errorMsg = fmt::Format("ERROR: %s", errorName.c_str()); + errorMsg = fmt::format("ERROR: %s", errorName); } if (dirName) diff --git a/rpcs3/Emu/SysCalls/SC_FUNC.h b/rpcs3/Emu/SysCalls/SC_FUNC.h index d3ad6739b5..ad405eac7a 100644 --- a/rpcs3/Emu/SysCalls/SC_FUNC.h +++ b/rpcs3/Emu/SysCalls/SC_FUNC.h @@ -122,21 +122,21 @@ namespace detail }; template - static __forceinline RT call(F f, Tuple && t) + __forceinline RT call(F f, Tuple && t) { typedef typename std::decay::type ttype; return detail::call_impl::value, std::tuple_size::value>::call(f, std::forward(t)); } template - static __forceinline std::tuple<> iterate(PPUThread& CPU) + __forceinline std::tuple<> iterate(PPUThread& CPU) { // terminator return std::tuple<>(); } template - static __forceinline std::tuple iterate(PPUThread& CPU) + __forceinline std::tuple iterate(PPUThread& CPU) { static_assert(!std::is_pointer::value, "Invalid function argument type (pointer)"); static_assert(!std::is_reference::value, "Invalid function argument type (reference)"); diff --git a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp b/rpcs3/Emu/SysCalls/lv2/cellFs.cpp index 4f83878a83..3aafb8b2c8 100644 --- a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/cellFs.cpp @@ -432,7 +432,7 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr> pos) case CELL_SEEK_CUR: seek_mode = vfsSeekCur; break; case CELL_SEEK_END: seek_mode = vfsSeekEnd; break; default: - sys_fs->Error(fd, "Unknown seek whence! (0x%x)", whence); + sys_fs->Error("cellFsLseek(fd=%d): Unknown seek whence! (0x%x)", fd, whence); return CELL_EINVAL; }