fmt::format() optimization (fmt::unveil template)

This commit is contained in:
Nekotekina 2015-01-19 01:54:56 +03:00
parent 87f1a9d9dc
commit 0d28f378a7
20 changed files with 343 additions and 309 deletions

View File

@ -758,86 +758,86 @@ template<typename T, typename T1, T1 value> struct _se<be_t<T>, T1, value> : pub
#define se32(x) _se<u32, decltype(x), x>::value
#define se64(x) _se<u64, decltype(x), x>::value
template<typename T> __forceinline static u8 Read8(T& f)
template<typename T> __forceinline u8 Read8(T& f)
{
u8 ret;
f.Read(&ret, sizeof(ret));
return ret;
}
template<typename T> __forceinline static u16 Read16(T& f)
template<typename T> __forceinline u16 Read16(T& f)
{
be_t<u16> ret;
f.Read(&ret, sizeof(ret));
return ret;
}
template<typename T> __forceinline static u32 Read32(T& f)
template<typename T> __forceinline u32 Read32(T& f)
{
be_t<u32> ret;
f.Read(&ret, sizeof(ret));
return ret;
}
template<typename T> __forceinline static u64 Read64(T& f)
template<typename T> __forceinline u64 Read64(T& f)
{
be_t<u64> ret;
f.Read(&ret, sizeof(ret));
return ret;
}
template<typename T> __forceinline static u16 Read16LE(T& f)
template<typename T> __forceinline u16 Read16LE(T& f)
{
u16 ret;
f.Read(&ret, sizeof(ret));
return ret;
}
template<typename T> __forceinline static u32 Read32LE(T& f)
template<typename T> __forceinline u32 Read32LE(T& f)
{
u32 ret;
f.Read(&ret, sizeof(ret));
return ret;
}
template<typename T> __forceinline static u64 Read64LE(T& f)
template<typename T> __forceinline u64 Read64LE(T& f)
{
u64 ret;
f.Read(&ret, sizeof(ret));
return ret;
}
template<typename T> __forceinline static void Write8(T& f, const u8 data)
template<typename T> __forceinline void Write8(T& f, const u8 data)
{
f.Write(&data, sizeof(data));
}
template<typename T> __forceinline static void Write16LE(T& f, const u16 data)
template<typename T> __forceinline void Write16LE(T& f, const u16 data)
{
f.Write(&data, sizeof(data));
}
template<typename T> __forceinline static void Write32LE(T& f, const u32 data)
template<typename T> __forceinline void Write32LE(T& f, const u32 data)
{
f.Write(&data, sizeof(data));
}
template<typename T> __forceinline static void Write64LE(T& f, const u64 data)
template<typename T> __forceinline void Write64LE(T& f, const u64 data)
{
f.Write(&data, sizeof(data));
}
template<typename T> __forceinline static void Write16(T& f, const u16 data)
template<typename T> __forceinline void Write16(T& f, const u16 data)
{
Write16LE(f, re16(data));
}
template<typename T> __forceinline static void Write32(T& f, const u32 data)
template<typename T> __forceinline void Write32(T& f, const u32 data)
{
Write32LE(f, re32(data));
}
template<typename T> __forceinline static void Write64(T& f, const u64 data)
template<typename T> __forceinline void Write64(T& f, const u64 data)
{
Write64LE(f, re64(data));
}

View File

@ -235,3 +235,18 @@ LogChannel &LogManager::getChannel(LogType type)
{
return mChannels[static_cast<u32>(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);
}

View File

@ -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<typename... Targs>
__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<typename T, typename... Ts>
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);
}

View File

@ -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<u64>(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)

View File

@ -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<u64>(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<typename T, bool is_enum = std::is_enum<T>::value>
template<typename T>
struct get_fmt
{
static_assert(is_enum, "Unsupported fmt::format argument");
typedef typename std::underlying_type<T>::type underlying_type;
static std::string text(const char* fmt, size_t len, const T& arg)
{
return get_fmt<underlying_type>::text(fmt, len, (underlying_type)arg);
}
};
template<typename T, typename T2>
struct get_fmt<be_t<T, T2>, false>
{
static std::string text(const char* fmt, size_t len, const be_t<T, T2>& arg)
{
return get_fmt<T>::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<typename T, typename... Args>
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<typename T, bool is_enum = std::is_enum<T>::value>
struct unveil
{
typedef T result_type;
__forceinline static result_type get_value(const T& arg)
{
return arg;
}
};
template<size_t N>
struct unveil<const char[N], false>
{
typedef const char* result_type;
__forceinline static result_type get_value(const char(&arg)[N])
{
return arg;
}
};
template<>
struct unveil<std::string, false>
{
typedef const std::string& result_type;
__forceinline static result_type get_value(const std::string& arg)
{
return arg;
}
};
template<typename T>
struct unveil<T, true>
{
typedef typename std::underlying_type<T>::type result_type;
__forceinline static result_type get_value(const T& arg)
{
return static_cast<result_type>(arg);
}
};
template<typename T, typename T2>
struct unveil<be_t<T, T2>, false>
{
typedef typename unveil<T>::result_type result_type;
__forceinline static result_type get_value(const be_t<T, T2>& arg)
{
return unveil<T>::get_value(arg.value());
}
};
template<typename T>
__forceinline typename unveil<T>::result_type do_unveil(const T& arg)
{
return unveil<T>::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<typename... Args>
__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

View File

@ -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

View File

@ -519,21 +519,21 @@ namespace psv_func_detail
};
template <typename RT, typename F, typename Tuple>
static __forceinline RT call(F f, Tuple && t)
__forceinline RT call(F f, Tuple && t)
{
typedef typename std::decay<Tuple>::type ttype;
return psv_func_detail::call_impl<RT, F, Tuple, 0 == std::tuple_size<ttype>::value, std::tuple_size<ttype>::value>::call(f, std::forward<Tuple>(t));
}
template<int g_count, int f_count, int v_count>
static __forceinline std::tuple<> iterate(ARMv7Thread& CPU)
__forceinline std::tuple<> iterate(ARMv7Thread& CPU)
{
// terminator
return std::tuple<>();
}
template<int g_count, int f_count, int v_count, typename T, typename... A>
static __forceinline std::tuple<T, A...> iterate(ARMv7Thread& CPU)
__forceinline std::tuple<T, A...> iterate(ARMv7Thread& CPU)
{
static_assert(!std::is_pointer<T>::value, "Invalid function argument type (pointer)");
static_assert(!std::is_reference<T>::value, "Invalid function argument type (reference)");

View File

@ -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:

View File

@ -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; };

View File

@ -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());

View File

@ -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:

View File

@ -501,33 +501,37 @@ namespace vm
namespace fmt
{
// external specializations for fmt::format function
namespace detail
template<typename T, int lvl, typename AT>
struct unveil<vm::ps3::ptr<T, lvl, AT>, false>
{
template<typename T, int lvl, typename AT>
struct get_fmt<vm::ps3::ptr<T, lvl, AT>, false>
{
__forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::ptr<T, lvl, AT>& arg)
{
return get_fmt<AT>::text(fmt, len, arg.addr());
}
};
typedef typename unveil<AT>::result_type result_type;
template<typename T, int lvl, typename AT>
struct get_fmt<vm::ps3::bptr<T, lvl, AT>, false>
__forceinline static result_type get_value(const vm::ps3::ptr<T, lvl, AT>& arg)
{
__forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::bptr<T, lvl, AT>& arg)
{
return get_fmt<AT>::text(fmt, len, arg.addr());
}
};
return unveil<AT>::get_value(arg.addr());
}
};
template<typename T, int lvl, typename AT>
struct get_fmt<vm::psv::ptr<T, lvl, AT>, false>
template<typename T, int lvl, typename AT>
struct unveil<vm::ps3::bptr<T, lvl, AT>, false>
{
typedef typename unveil<AT>::result_type result_type;
__forceinline static result_type get_value(const vm::ps3::bptr<T, lvl, AT>& arg)
{
__forceinline static std::string text(const char* fmt, size_t len, const vm::psv::ptr<T, lvl, AT>& arg)
{
return get_fmt<AT>::text(fmt, len, arg.addr());
}
};
}
return unveil<AT>::get_value(arg.addr());
}
};
template<typename T, int lvl, typename AT>
struct unveil<vm::psv::ptr<T, lvl, AT>, false>
{
typedef typename unveil<AT>::result_type result_type;
__forceinline static result_type get_value(const vm::psv::ptr<T, lvl, AT>& arg)
{
return unveil<AT>::get_value(arg.addr());
}
};
}

View File

@ -113,33 +113,37 @@ namespace vm
namespace fmt
{
// external specializations for fmt::format function
namespace detail
template<typename T, typename AT>
struct unveil<vm::ps3::ref<T, AT>, false>
{
template<typename T, typename AT>
struct get_fmt<vm::ps3::ref<T, AT>, false>
{
__forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::ref<T, AT>& arg)
{
return get_fmt<AT>::text(fmt, len, arg.addr());
}
};
typedef typename unveil<AT>::result_type result_type;
template<typename T, typename AT>
struct get_fmt<vm::ps3::bref<T, AT>, false>
__forceinline static result_type get_value(const vm::ps3::ref<T, AT>& arg)
{
__forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::bref<T, AT>& arg)
{
return get_fmt<AT>::text(fmt, len, arg.addr());
}
};
return unveil<AT>::get_value(arg.addr());
}
};
template<typename T, typename AT>
struct get_fmt<vm::psv::ref<T, AT>, false>
template<typename T, typename AT>
struct unveil<vm::ps3::bref<T, AT>, false>
{
typedef typename unveil<AT>::result_type result_type;
__forceinline static result_type get_value(const vm::ps3::bref<T, AT>& arg)
{
__forceinline static std::string text(const char* fmt, size_t len, const vm::psv::ref<T, AT>& arg)
{
return get_fmt<AT>::text(fmt, len, arg.addr());
}
};
}
return unveil<AT>::get_value(arg.addr());
}
};
template<typename T, typename AT>
struct unveil<vm::psv::ref<T, AT>, false>
{
typedef typename unveil<AT>::result_type result_type;
__forceinline static result_type get_value(const vm::psv::ref<T, AT>& arg)
{
return unveil<AT>::get_value(arg.addr());
}
};
}

View File

@ -181,13 +181,13 @@ namespace vm
}
template<typename RT, typename... T>
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<RT, T...>::call(CPU, pc, rtoc, args...);
}
template<typename... T>
void cb_call(PPUThread& CPU, u32 pc, u32 rtoc, T... args)
{
cb_detail::_func_caller<void, T...>::call(CPU, pc, rtoc, args...);
}
//template<typename... T>
//void cb_call(PPUThread& CPU, u32 pc, u32 rtoc, T... args)
//{
// cb_detail::_func_caller<void, T...>::call(CPU, pc, rtoc, args...);
//}

View File

@ -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;
}
}

View File

@ -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<typename... Targs>
__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<typename... Targs> __noinline void Notice(const u32 id, const char* fmt, Targs... args) const
template<typename... Targs>
__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<typename... Targs> __noinline void Notice(const char* fmt, Targs... args) const
{
LogOutput(LogNotice, ": ", fmt::format(fmt, args...));
}
template<typename... Targs> __forceinline void Log(const char* fmt, Targs... args) const
template<typename... Targs>
__forceinline void Log(const char* fmt, Targs... args) const
{
if (CheckLogging())
{
@ -47,52 +50,28 @@ public:
}
}
template<typename... Targs> __forceinline void Log(const u32 id, const char* fmt, Targs... args) const
template<typename... Targs>
__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<typename... Targs> __noinline void Success(const u32 id, const char* fmt, Targs... args) const
template<typename... Targs>
__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<typename... Targs> __noinline void Success(const char* fmt, Targs... args) const
template<typename... Targs>
__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<typename... Targs> __noinline void Warning(const u32 id, const char* fmt, Targs... args) const
template<typename... Targs>
__forceinline void Todo(const char* fmt, Targs... args) const
{
LogOutput(LogWarning, id, " warning: ", fmt::format(fmt, args...));
}
template<typename... Targs> __noinline void Warning(const char* fmt, Targs... args) const
{
LogOutput(LogWarning, " warning: ", fmt::format(fmt, args...));
}
template<typename... Targs> __noinline void Error(const u32 id, const char* fmt, Targs... args) const
{
LogOutput(LogError, id, " error: ", fmt::format(fmt, args...));
}
template<typename... Targs> __noinline void Error(const char* fmt, Targs... args) const
{
LogOutput(LogError, " error: ", fmt::format(fmt, args...));
}
template<typename... Targs> __noinline void Todo(const u32 id, const char* fmt, Targs... args) const
{
LogOutput(LogError, id, " TODO: ", fmt::format(fmt, args...));
}
template<typename... Targs> __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)...);
}
};

View File

@ -995,7 +995,7 @@ int cellDmuxEnableEs(u32 demuxerHandle, vm::ptr<const CellCodecEsFilterId> 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;

View File

@ -443,11 +443,11 @@ int cellGameContentErrorDialog(s32 type, s32 errNeedSizeKB, vm::ptr<const char>
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)

View File

@ -122,21 +122,21 @@ namespace detail
};
template <typename RT, typename F, typename Tuple>
static __forceinline RT call(F f, Tuple && t)
__forceinline RT call(F f, Tuple && t)
{
typedef typename std::decay<Tuple>::type ttype;
return detail::call_impl<RT, F, Tuple, 0 == std::tuple_size<ttype>::value, std::tuple_size<ttype>::value>::call(f, std::forward<Tuple>(t));
}
template<int g_count, int f_count, int v_count>
static __forceinline std::tuple<> iterate(PPUThread& CPU)
__forceinline std::tuple<> iterate(PPUThread& CPU)
{
// terminator
return std::tuple<>();
}
template<int g_count, int f_count, int v_count, typename T, typename... A>
static __forceinline std::tuple<T, A...> iterate(PPUThread& CPU)
__forceinline std::tuple<T, A...> iterate(PPUThread& CPU)
{
static_assert(!std::is_pointer<T>::value, "Invalid function argument type (pointer)");
static_assert(!std::is_reference<T>::value, "Invalid function argument type (reference)");

View File

@ -432,7 +432,7 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr<be_t<u64>> 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;
}