diff --git a/Source/Core/Common/ArmCPUDetect.cpp b/Source/Core/Common/ArmCPUDetect.cpp index 466a0a0741..7ad619581c 100644 --- a/Source/Core/Common/ArmCPUDetect.cpp +++ b/Source/Core/Common/ArmCPUDetect.cpp @@ -10,10 +10,11 @@ #include #include +#include + #include "Common/CPUDetect.h" #include "Common/CommonTypes.h" #include "Common/FileUtil.h" -#include "Common/StringUtil.h" const char procfile[] = "/proc/cpuinfo"; @@ -77,9 +78,9 @@ std::string CPUInfo::Summarize() { std::string sum; if (num_cores == 1) - sum = StringFromFormat("%s, %i core", cpu_string, num_cores); + sum = fmt::format("{}, 1 core", cpu_string); else - sum = StringFromFormat("%s, %i cores", cpu_string, num_cores); + sum = fmt::format("{}, {} cores", cpu_string, num_cores); if (bAES) sum += ", AES"; diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 297934ba7c..fb67d076c6 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -9,6 +9,8 @@ #include #include +#include + #include "Common/CDUtils.h" #include "Common/Common.h" #include "Common/CommonTypes.h" @@ -134,20 +136,23 @@ std::vector GetCDDevices() } #else // checklist: /dev/cdrom, /dev/dvd /dev/hd?, /dev/scd? /dev/sr? -static struct +struct CheckListEntry { const char* format; unsigned int num_min; unsigned int num_max; -} checklist[] = { +}; + +constexpr CheckListEntry checklist[] = { #ifdef __linux__ - {"/dev/cdrom", 0, 0}, {"/dev/dvd", 0, 0}, {"/dev/hd%c", 'a', 'z'}, - {"/dev/scd%d", 0, 27}, {"/dev/sr%d", 0, 27}, + {"/dev/cdrom", 0, 0}, {"/dev/dvd", 0, 0}, {"/dev/hd{}", 'a', 'z'}, + {"/dev/scd{}", 0, 27}, {"/dev/sr{}", 0, 27}, #else - {"/dev/acd%d", 0, 27}, - {"/dev/cd%d", 0, 27}, + {"/dev/acd{}", 0, 27}, + {"/dev/cd{}", 0, 27}, #endif - {nullptr, 0, 0}}; + {nullptr, 0, 0}, +}; // Returns true if a device is a block or char device and not a symbolic link static bool IsDevice(const std::string& source_name) @@ -189,7 +194,7 @@ std::vector GetCDDevices() { for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j) { - std::string drive = StringFromFormat(checklist[i].format, j); + std::string drive = fmt::format(checklist[i].format, j); if (IsCDROM(drive)) { drives.push_back(std::move(drive)); diff --git a/Source/Core/Common/CompatPatches.cpp b/Source/Core/Common/CompatPatches.cpp index b2bc839be3..03963ccdee 100644 --- a/Source/Core/Common/CompatPatches.cpp +++ b/Source/Core/Common/CompatPatches.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include "Common/CommonTypes.h" #include "Common/LdrWatcher.h" #include "Common/StringUtil.h" @@ -213,41 +215,41 @@ void CompatPatchesInstall(LdrWatcher* watcher) auto patcher = ImportPatcher(event.base_address); patcher.PatchIAT("kernel32.dll", "HeapCreate", HeapCreateLow4GB); }}); - watcher->Install({{L"ucrtbase.dll"}, [](const LdrDllLoadEvent& event) { - // ucrtbase implements caching between fseek/fread, old versions have a bug - // such that some reads return incorrect data. This causes noticable bugs - // in dolphin since we use these APIs for reading game images. - Version version; - if (!GetModuleVersion(event.name.c_str(), &version)) - return; - const u16 fixed_build = 10548; - if (version.build >= fixed_build) - return; - const UcrtPatchInfo patches[] = { - // 10.0.10240.16384 (th1.150709-1700) - {0xF61ED, 0x6AE7B, 5}, - // 10.0.10240.16390 (th1_st1.150714-1601) - {0xF5ED9, 0x6AE7B, 5}, - // 10.0.10137.0 (th1.150602-2238) - {0xF8B5E, 0x63ED6, 2}, - }; - for (const auto& patch : patches) - { - if (ApplyUcrtPatch(event.name.c_str(), patch)) - return; - } - // If we reach here, the version is buggy (afaik) and patching failed - auto msg = StringFromFormat( - "You are running %S version %d.%d.%d.%d.\n" - "An important fix affecting Dolphin was introduced in build %d.\n" - "You can use Dolphin, but there will be known bugs.\n" - "Please update this file by installing the latest Universal C Runtime.\n", - event.name.c_str(), version.major, version.minor, version.build, - version.qfe, fixed_build); - // Use MessageBox for maximal user annoyance - MessageBoxA(nullptr, msg.c_str(), "WARNING: BUGGY UCRT VERSION", - MB_ICONEXCLAMATION); - }}); + watcher->Install( + {{L"ucrtbase.dll"}, [](const LdrDllLoadEvent& event) { + // ucrtbase implements caching between fseek/fread, old versions have a bug + // such that some reads return incorrect data. This causes noticable bugs + // in dolphin since we use these APIs for reading game images. + Version version; + if (!GetModuleVersion(event.name.c_str(), &version)) + return; + const u16 fixed_build = 10548; + if (version.build >= fixed_build) + return; + const UcrtPatchInfo patches[] = { + // 10.0.10240.16384 (th1.150709-1700) + {0xF61ED, 0x6AE7B, 5}, + // 10.0.10240.16390 (th1_st1.150714-1601) + {0xF5ED9, 0x6AE7B, 5}, + // 10.0.10137.0 (th1.150602-2238) + {0xF8B5E, 0x63ED6, 2}, + }; + for (const auto& patch : patches) + { + if (ApplyUcrtPatch(event.name.c_str(), patch)) + return; + } + // If we reach here, the version is buggy (afaik) and patching failed + const auto msg = + fmt::format("You are running {} version {}.{}.{}.{}.\n" + "An important fix affecting Dolphin was introduced in build {}.\n" + "You can use Dolphin, but there will be known bugs.\n" + "Please update this file by installing the latest Universal C Runtime.\n", + UTF16ToUTF8(event.name), version.major, version.minor, version.build, + version.qfe, fixed_build); + // Use MessageBox for maximal user annoyance + MessageBoxA(nullptr, msg.c_str(), "WARNING: BUGGY UCRT VERSION", MB_ICONEXCLAMATION); + }}); } int __cdecl EnableCompatPatches() diff --git a/Source/Core/Common/DynamicLibrary.cpp b/Source/Core/Common/DynamicLibrary.cpp index 1c32cc6708..6bfdb482c8 100644 --- a/Source/Core/Common/DynamicLibrary.cpp +++ b/Source/Core/Common/DynamicLibrary.cpp @@ -3,9 +3,12 @@ // Refer to the license.txt file included. #include "Common/DynamicLibrary.h" + #include + +#include + #include "Common/Assert.h" -#include "Common/StringUtil.h" #ifdef _WIN32 #include @@ -42,27 +45,27 @@ std::string DynamicLibrary::GetVersionedFilename(const char* libname, int major, { #if defined(_WIN32) if (major >= 0 && minor >= 0) - return StringFromFormat("%s-%d-%d.dll", libname, major, minor); + return fmt::format("{}-{}-{}.dll", libname, major, minor); else if (major >= 0) - return StringFromFormat("%s-%d.dll", libname, major); + return fmt::format("{}-{}.dll", libname, major); else - return StringFromFormat("%s.dll", libname); + return fmt::format("{}.dll", libname); #elif defined(__APPLE__) const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : ""; if (major >= 0 && minor >= 0) - return StringFromFormat("%s%s.%d.%d.dylib", prefix, libname, major, minor); + return fmt::format("{}{}.{}.{}.dylib", prefix, libname, major, minor); else if (major >= 0) - return StringFromFormat("%s%s.%d.dylib", prefix, libname, major); + return fmt::format("{}{}.{}.dylib", prefix, libname, major); else - return StringFromFormat("%s%s.dylib", prefix, libname); + return fmt::format("{}{}.dylib", prefix, libname); #else const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : ""; if (major >= 0 && minor >= 0) - return StringFromFormat("%s%s.so.%d.%d", prefix, libname, major, minor); + return fmt::format("{}{}.so.{}.{}", prefix, libname, major, minor); else if (major >= 0) - return StringFromFormat("%s%s.so.%d", prefix, libname, major); + return fmt::format("{}{}.so.{}", prefix, libname, major); else - return StringFromFormat("%s%s.so", prefix, libname); + return fmt::format("{}{}.so", prefix, libname); #endif } diff --git a/Source/Core/Common/GekkoDisassembler.cpp b/Source/Core/Common/GekkoDisassembler.cpp index f9f1a701ae..0fedea6652 100644 --- a/Source/Core/Common/GekkoDisassembler.cpp +++ b/Source/Core/Common/GekkoDisassembler.cpp @@ -32,10 +32,13 @@ // Modified for use with Dolphin +#include "Common/GekkoDisassembler.h" + #include +#include + #include "Common/CommonTypes.h" -#include "Common/GekkoDisassembler.h" #include "Common/StringUtil.h" namespace Common @@ -125,6 +128,45 @@ unsigned char GekkoDisassembler::m_flags = PPCF_ILLEGAL; unsigned short GekkoDisassembler::m_sreg = 0; u32 GekkoDisassembler::m_displacement = 0; +static u32 HelperRotateMask(int r, int mb, int me) +{ + // first make 001111111111111 part + unsigned int begin = 0xFFFFFFFF >> mb; + // then make 000000000001111 part, which is used to flip the bits of the first one + unsigned int end = me < 31 ? (0xFFFFFFFF >> (me + 1)) : 0; + // do the bitflip + unsigned int mask = begin ^ end; + // and invert if backwards + if (me < mb) + mask = ~mask; + // rotate the mask so it can be applied to source reg + // return _rotl(mask, 32 - r); + return (mask << (32 - r)) | (mask >> r); +} + +static std::string ldst_offs(u32 val) +{ + if (val == 0) + { + return "0"; + } + + if (val & 0x8000) + { + return fmt::format("-0x{:.4X}", ((~val) & 0xffff) + 1); + } + + return fmt::format("0x{:.4X}", val); +} + +static int SEX12(u32 x) +{ + if ((x & 0x800) != 0) + return static_cast(x | 0xFFFFF000); + + return static_cast(x); +} + static std::string spr_name(int i) { switch (i) @@ -275,7 +317,7 @@ static std::string spr_name(int i) return "THRM3"; } - return StringFromFormat("%d", i); + return std::to_string(i); } static u32 swapda(u32 w) @@ -298,7 +340,7 @@ void GekkoDisassembler::ill(u32 in) else { m_opcode = "(ill)"; - m_operands = StringFromFormat("%08x", in); + m_operands = fmt::format("{:08x}", in); } m_flags |= PPCF_ILLEGAL; @@ -330,34 +372,31 @@ std::string GekkoDisassembler::imm(u32 in, int uimm, int type, bool hex) switch (type) { case 0: - return StringFromFormat("%s, %s, %d", regnames[(int)PPCGETD(in)], regnames[(int)PPCGETA(in)], - i); + return fmt::format("{}, {}, {}", regnames[PPCGETD(in)], regnames[PPCGETA(in)], i); case 1: if (hex) - return StringFromFormat("%s, %s, 0x%.4X", regnames[(int)PPCGETA(in)], - regnames[(int)PPCGETD(in)], i); + return fmt::format("{}, {}, 0x{:.4X}", regnames[PPCGETA(in)], regnames[PPCGETD(in)], i); else - return StringFromFormat("%s, %s, %d", regnames[(int)PPCGETA(in)], regnames[(int)PPCGETD(in)], - i); + return fmt::format("{}, {}, {}", regnames[PPCGETA(in)], regnames[PPCGETD(in)], i); case 2: - return StringFromFormat("%s, %d", regnames[(int)PPCGETA(in)], i); + return fmt::format("{}, {}", regnames[PPCGETA(in)], i); case 3: if (hex) - return StringFromFormat("%s, 0x%.4X", regnames[(int)PPCGETD(in)], i); + return fmt::format("{}, 0x{:.4X}", regnames[PPCGETD(in)], i); else - return StringFromFormat("%s, %d", regnames[(int)PPCGETD(in)], i); + return fmt::format("{}, {}", regnames[PPCGETD(in)], i); default: - return StringFromFormat("%s", "imm(): Wrong type"); + return "imm(): Wrong type"; } } std::string GekkoDisassembler::ra_rb(u32 in) { - return StringFromFormat("%s, %s", regnames[(int)PPCGETA(in)], regnames[(int)PPCGETB(in)]); + return fmt::format("{}, {}", regnames[PPCGETA(in)], regnames[PPCGETB(in)]); } std::string GekkoDisassembler::rd_ra_rb(u32 in, int mask) @@ -367,11 +406,11 @@ std::string GekkoDisassembler::rd_ra_rb(u32 in, int mask) if (mask) { if (mask & 4) - result += StringFromFormat("%s, ", regnames[(int)PPCGETD(in)]); + result += fmt::format("{}, ", regnames[PPCGETD(in)]); if (mask & 2) - result += StringFromFormat("%s, ", regnames[(int)PPCGETA(in)]); + result += fmt::format("{}, ", regnames[PPCGETA(in)]); if (mask & 1) - result += StringFromFormat("%s, ", regnames[(int)PPCGETB(in)]); + result += fmt::format("{}, ", regnames[PPCGETB(in)]); size_t pos = result.rfind(", "); if (pos != std::string::npos) @@ -390,11 +429,11 @@ std::string GekkoDisassembler::fd_ra_rb(u32 in, int mask) if (mask) { if (mask & 4) - result += StringFromFormat("f%d,", (int)PPCGETD(in)); + result += fmt::format("f{},", PPCGETD(in)); if (mask & 2) - result += StringFromFormat("%s,", regnames[(int)PPCGETA(in)]); + result += fmt::format("{},", regnames[PPCGETA(in)]); if (mask & 1) - result += StringFromFormat("%s,", regnames[(int)PPCGETB(in)]); + result += fmt::format("{},", regnames[PPCGETB(in)]); // Drop the trailing comma result.pop_back(); @@ -410,12 +449,12 @@ void GekkoDisassembler::trapi(u32 in, unsigned char dmode) m_flags |= dmode; if (cnd != nullptr) { - m_opcode = StringFromFormat("t%c%s", dmode ? 'd' : 'w', cnd); + m_opcode = fmt::format("t{}{}", dmode ? 'd' : 'w', cnd); } else { - m_opcode = StringFromFormat("t%ci", dmode ? 'd' : 'w'); - m_operands = StringFromFormat("%d, ", PPCGETD(in)); + m_opcode = fmt::format("t{}i", dmode ? 'd' : 'w'); + m_operands = fmt::format("{}, ", PPCGETD(in)); } m_operands += imm(in, 0, 2, false); } @@ -429,12 +468,12 @@ void GekkoDisassembler::cmpi(u32 in, int uimm) if (i != 0) m_flags |= PPCF_64; - m_opcode = StringFromFormat("%si", cmpname[uimm * 2 + i]); + m_opcode = fmt::format("{}i", cmpname[uimm * 2 + i]); i = (int)PPCGETCRD(in); if (i != 0) { - m_operands += StringFromFormat("cr%c, ", '0' + i); + m_operands += fmt::format("cr{}, ", '0' + i); } m_operands += imm(in, uimm, 2, false); @@ -449,7 +488,8 @@ void GekkoDisassembler::addi(u32 in, const std::string& ext) { if ((in & 0x08000000) && !PPCGETA(in)) { - m_opcode = StringFromFormat("l%s", ext.c_str()); // li, lis + // li, lis + m_opcode = fmt::format("l{}", ext); if (ext == "i") m_operands = imm(in, 0, 3, false); @@ -458,7 +498,7 @@ void GekkoDisassembler::addi(u32 in, const std::string& ext) } else { - m_opcode = StringFromFormat("%s%s", (in & 0x8000) ? "sub" : "add", ext.c_str()); + m_opcode = fmt::format("{}{}", (in & 0x8000) ? "sub" : "add", ext); if (in & 0x8000) in = (in ^ 0xffff) + 1; @@ -487,33 +527,32 @@ size_t GekkoDisassembler::branch(u32 in, const char* bname, int aform, int bdisp // branch always if (PPCGETIDX(in) != 16) { - m_opcode = StringFromFormat("b%s%s", bname, ext); + m_opcode = fmt::format("b{}{}", bname, ext); } else { - m_opcode = StringFromFormat("bc%s", ext); - m_operands = StringFromFormat("%d, %d", bo, bi); + m_opcode = fmt::format("bc{}", ext); + m_operands = fmt::format("{}, {}", bo, bi); } } else // Branch conditional { - m_opcode = - StringFromFormat("b%s%s%s%c", b_condition[((bo & 8) >> 1) + (bi & 3)], bname, ext, y); + m_opcode = fmt::format("b{}{}{}{}", b_condition[((bo & 8) >> 1) + (bi & 3)], bname, ext, y); if (bi >= 4) { - m_operands = StringFromFormat("cr%d", bi >> 2); + m_operands = fmt::format("cr{}", bi >> 2); } } } else { // CTR is decremented and checked - m_opcode = StringFromFormat("bd%s%s%s%c", b_decr[bo >> 1], bname, ext, y); + m_opcode = fmt::format("bd{}{}{}{}", b_decr[bo >> 1], bname, ext, y); if ((bo & 16) == 0) { - m_operands = StringFromFormat("%d", bi); + m_operands = std::to_string(bi); } } @@ -530,9 +569,9 @@ void GekkoDisassembler::bc(u32 in) branch(in, "", (in & 2) ? 1 : 0, d); if (in & 2) // AA ? - m_operands = StringFromFormat("%s ->0x%.8X", m_operands.c_str(), d); + m_operands = fmt::format("{} ->0x{:.8X}", m_operands, d); else - m_operands = StringFromFormat("%s ->0x%.8X", m_operands.c_str(), *m_iaddr + d); + m_operands = fmt::format("{} ->0x{:.8X}", m_operands, *m_iaddr + d); m_type = PPCINSTR_BRANCH; m_displacement = d; @@ -545,12 +584,12 @@ void GekkoDisassembler::bli(u32 in) if (d & 0x02000000) d |= 0xfc000000; - m_opcode = StringFromFormat("b%s", b_ext[in & 3]); + m_opcode = fmt::format("b{}", b_ext[in & 3]); if (in & 2) // AA ? - m_operands = StringFromFormat("->0x%.8X", d); + m_operands = fmt::format("->0x{:.8X}", d); else - m_operands = StringFromFormat("->0x%.8X", *m_iaddr + d); + m_operands = fmt::format("->0x{:.8X}", *m_iaddr + d); m_type = PPCINSTR_BRANCH; m_displacement = d; @@ -560,8 +599,8 @@ void GekkoDisassembler::mcrf(u32 in, char c) { if ((in & 0x0063f801) == 0) { - m_opcode = StringFromFormat("mcrf%c", c); - m_operands = StringFromFormat("cr%d, cr%d", (int)PPCGETCRD(in), (int)PPCGETCRA(in)); + m_opcode = fmt::format("mcrf{}", c); + m_operands = fmt::format("cr{}, cr{}", PPCGETCRD(in), PPCGETCRA(in)); } else { @@ -577,11 +616,11 @@ void GekkoDisassembler::crop(u32 in, const char* n1, const char* n2) if ((in & 1) == 0) { - m_opcode = StringFromFormat("cr%s", (cra == crb && n2) ? n2 : n1); + m_opcode = fmt::format("cr{}", (cra == crb && n2) ? n2 : n1); if (cra == crb && n2) - m_operands = StringFromFormat("%d, %d", crd, cra); + m_operands = fmt::format("{}, {}", crd, cra); else - m_operands = StringFromFormat("%d, %d, %d", crd, cra, crb); + m_operands = fmt::format("{}, {}, {}", crd, cra, crb); } else { @@ -610,9 +649,9 @@ void GekkoDisassembler::rlw(u32 in, const char* name, int i) int mb = (int)PPCGETC(in); int me = (int)PPCGETM(in); - m_opcode = StringFromFormat("rlw%s%c", name, in & 1 ? '.' : '\0'); - m_operands = StringFromFormat("%s, %s, %s%d, %d, %d (%08x)", regnames[a], regnames[s], regsel[i], - bsh, mb, me, HelperRotateMask(bsh, mb, me)); + m_opcode = fmt::format("rlw{}{}", name, (in & 1) ? '.' : '\0'); + m_operands = fmt::format("{}, {}, {}{}, {}, {} ({:08x})", regnames[a], regnames[s], regsel[i], + bsh, mb, me, HelperRotateMask(bsh, mb, me)); } void GekkoDisassembler::ori(u32 in, const char* name) @@ -629,8 +668,8 @@ void GekkoDisassembler::rld(u32 in, const char* name, int i) int m = (int)(in & 0x7e0) >> 5; m_flags |= PPCF_64; - m_opcode = StringFromFormat("rld%s%c", name, in & 1 ? '.' : '\0'); - m_operands = StringFromFormat("%s, %s, %s%d, %d", regnames[a], regnames[s], regsel[i], bsh, m); + m_opcode = fmt::format("rld{}{}", name, (in & 1) ? '.' : '\0'); + m_operands = fmt::format("{}, {}, {}{}, {}", regnames[a], regnames[s], regsel[i], bsh, m); } void GekkoDisassembler::cmp(u32 in) @@ -646,7 +685,7 @@ void GekkoDisassembler::cmp(u32 in) i = (int)PPCGETCRD(in); if (i != 0) - m_operands += StringFromFormat("cr%c,", '0' + i); + m_operands += fmt::format("cr{},", static_cast('0' + i)); m_operands += ra_rb(in); } @@ -664,7 +703,7 @@ void GekkoDisassembler::trap(u32 in, unsigned char dmode) if (cnd != nullptr) { m_flags |= dmode; - m_opcode = StringFromFormat("t%c%s", dmode ? 'd' : 'w', cnd); + m_opcode = fmt::format("t{}{}", dmode ? 'd' : 'w', cnd); m_operands = ra_rb(in); } else @@ -705,8 +744,8 @@ void GekkoDisassembler::dab(u32 in, const char* name, int mask, int smode, int c if (smode) in = swapda(in); - m_opcode = StringFromFormat("%s%s%s", name, oesel[chkoe && (in & PPCOE)], - rcsel[(chkrc < 0) && (in & 1)]); + m_opcode = + fmt::format("{}{}{}", name, oesel[chkoe && (in & PPCOE)], rcsel[(chkrc < 0) && (in & 1)]); m_operands = rd_ra_rb(in, mask); } } @@ -727,11 +766,10 @@ void GekkoDisassembler::rrn(u32 in, const char* name, int smode, int chkoe, int if (smode) in = swapda(in); - m_opcode = StringFromFormat("%s%s%s", name, oesel[chkoe && (in & PPCOE)], - rcsel[(chkrc < 0) && (in & 1)]); - + m_opcode = + fmt::format("{}{}{}", name, oesel[chkoe && (in & PPCOE)], rcsel[(chkrc < 0) && (in & 1)]); m_operands = rd_ra_rb(in, 6); - m_operands += StringFromFormat(",%d", (int)PPCGETB(in)); + m_operands += fmt::format(",{}", PPCGETB(in)); } } @@ -746,10 +784,10 @@ void GekkoDisassembler::mtcr(u32 in) } else { - m_opcode = StringFromFormat("mtcr%c", crm == 0xff ? '\0' : 'f'); + m_opcode = fmt::format("mtcr{}", crm == 0xff ? '\0' : 'f'); if (crm != 0xff) - m_operands += StringFromFormat("0x%02x,", crm); + m_operands += fmt::format("0x{:02x},", crm); m_operands += regnames[s]; } @@ -767,12 +805,12 @@ void GekkoDisassembler::msr(u32 in, int smode) else { m_flags |= PPCF_SUPER; - m_opcode = StringFromFormat("m%csr", smode ? 't' : 'f'); + m_opcode = fmt::format("m{}sr", smode ? 't' : 'f'); if (smode) - m_operands = StringFromFormat("%d, %s", sr, regnames[s]); + m_operands = fmt::format("{}, {}", sr, regnames[s]); else - m_operands = StringFromFormat("%s, %d", regnames[s], sr); + m_operands = fmt::format("{}, {}", regnames[s], sr); } } @@ -812,14 +850,14 @@ void GekkoDisassembler::mspr(u32 in, int smode) break; } - m_opcode = StringFromFormat("m%c%s", smode ? 't' : 'f', x); + m_opcode = fmt::format("m{}{}", smode ? 't' : 'f', x); if (fmt) { if (smode) - m_operands = StringFromFormat("%s, %s", spr_name(spr).c_str(), regnames[d]); + m_operands = fmt::format("{}, {}", spr_name(spr), regnames[d]); else - m_operands = StringFromFormat("%s, %s", regnames[d], spr_name(spr).c_str()); + m_operands = fmt::format("{}, {}", regnames[d], spr_name(spr)); } else { @@ -855,11 +893,11 @@ void GekkoDisassembler::mtb(u32 in) default: x = '\0'; m_flags |= PPCF_SUPER; - m_operands += StringFromFormat(",%d", tbr); + m_operands += fmt::format(",{}", tbr); break; } - m_opcode = StringFromFormat("mftb%c", x); + m_opcode = fmt::format("mftb{}", x); } } @@ -870,8 +908,8 @@ void GekkoDisassembler::sradi(u32 in) int bsh = (int)(((in & 2) << 4) + PPCGETB(in)); m_flags |= PPCF_64; - m_opcode = StringFromFormat("sradi%c", in & 1 ? '.' : '\0'); - m_operands = StringFromFormat("%s, %s, %d", regnames[a], regnames[s], bsh); + m_opcode = fmt::format("sradi{}", (in & 1) ? '.' : '\0'); + m_operands = fmt::format("{}, {}, {}", regnames[a], regnames[s], bsh); } void GekkoDisassembler::ldst(u32 in, const char* name, char reg, unsigned char dmode) @@ -890,11 +928,11 @@ void GekkoDisassembler::ldst(u32 in, const char* name, char reg, unsigned char d if (reg == 'r') { - m_operands = StringFromFormat("%s, %s (%s)", regnames[s], ldst_offs(d).c_str(), regnames[a]); + m_operands = fmt::format("{}, {} ({})", regnames[s], ldst_offs(d), regnames[a]); } else { - m_operands = StringFromFormat("%c%d, %s (%s)", reg, s, ldst_offs(d).c_str(), regnames[a]); + m_operands = fmt::format("{}{}, {} ({})", reg, s, ldst_offs(d), regnames[a]); } } @@ -904,21 +942,21 @@ void GekkoDisassembler::fdabc(u32 in, const char* name, int mask, unsigned char int err = 0; m_flags |= dmode; - m_opcode = StringFromFormat("f%s%s", name, rcsel[in & 1]); - m_operands += StringFromFormat("f%d,", (int)PPCGETD(in)); + m_opcode = fmt::format("f{}{}", name, rcsel[in & 1]); + m_operands += fmt::format("f{},", PPCGETD(in)); if (mask & 4) - m_operands += StringFromFormat("f%d,", (int)PPCGETA(in)); + m_operands += fmt::format("f{},", PPCGETA(in)); else if ((mask & 8) == 0) err |= (int)PPCGETA(in); if (mask & 2) - m_operands += StringFromFormat("f%d,", (int)PPCGETC(in)); + m_operands += fmt::format("f{},", PPCGETC(in)); else if (PPCGETC(in) && (mask & 8) == 0) err |= (int)PPCGETC(in); if (mask & 1) - m_operands += StringFromFormat("f%d,", (int)PPCGETB(in)); + m_operands += fmt::format("f{},", PPCGETB(in)); else if (!(mask & 8)) err |= (int)PPCGETB(in); @@ -931,8 +969,8 @@ void GekkoDisassembler::fdabc(u32 in, const char* name, int mask, unsigned char void GekkoDisassembler::fmr(u32 in) { - m_opcode = StringFromFormat("fmr%s", rcsel[in & 1]); - m_operands = StringFromFormat("f%d, f%d", (int)PPCGETD(in), (int)PPCGETB(in)); + m_opcode = fmt::format("fmr{}", rcsel[in & 1]); + m_operands = fmt::format("f{}, f{}", PPCGETD(in), PPCGETB(in)); } // Indexed float instruction: xxxx fD,rA,rB @@ -950,9 +988,8 @@ void GekkoDisassembler::fcmp(u32 in, char c) } else { - m_opcode = StringFromFormat("fcmp%c", c); - m_operands = - StringFromFormat("cr%d,f%d,f%d", (int)PPCGETCRD(in), (int)PPCGETA(in), (int)PPCGETB(in)); + m_opcode = fmt::format("fcmp{}", c); + m_operands = fmt::format("cr{},f{},f{}", PPCGETCRD(in), PPCGETA(in), PPCGETB(in)); } } @@ -964,8 +1001,8 @@ void GekkoDisassembler::mtfsb(u32 in, int n) } else { - m_opcode = StringFromFormat("mtfsb%d%s", n, rcsel[in & 1]); - m_operands = StringFromFormat("%d", (int)PPCGETD(in)); + m_opcode = fmt::format("mtfsb{}{}", n, rcsel[in & 1]); + m_operands = std::to_string(PPCGETD(in)); } } @@ -1026,97 +1063,97 @@ void GekkoDisassembler::ps(u32 inst) { case 6: m_opcode = inst & 0x40 ? "psq_lux" : "psq_lx"; - m_operands = StringFromFormat("p%u, (r%u + r%u), %d, qr%d", FD, RA, RB, WX, IX); + m_operands = fmt::format("p{}, (r{} + r{}), {}, qr{}", FD, RA, RB, WX, IX); return; case 7: m_opcode = inst & 0x40 ? "psq_stux" : "psq_stx"; - m_operands = StringFromFormat("p%u, r%u, r%u, %d, qr%d", FS, RA, RB, WX, IX); + m_operands = fmt::format("p{}, r{}, r{}, {}, qr{}", FS, RA, RB, WX, IX); return; case 18: m_opcode = "ps_div"; - m_operands = StringFromFormat("p%u, p%u/p%u", FD, FA, FB); + m_operands = fmt::format("p{}, p{}/p{}", FD, FA, FB); return; case 20: m_opcode = "ps_sub"; - m_operands = StringFromFormat("p%u, p%u-p%u", FD, FA, FB); + m_operands = fmt::format("p{}, p{}-p{}", FD, FA, FB); return; case 21: m_opcode = "ps_add"; - m_operands = StringFromFormat("p%u, p%u+p%u", FD, FA, FB); + m_operands = fmt::format("p{}, p{}+p{}", FD, FA, FB); return; case 23: m_opcode = "ps_sel"; - m_operands = StringFromFormat("p%u>=0?p%u:p%u", FD, FA, FC); + m_operands = fmt::format("p{}>=0?p{}:p{}", FD, FA, FC); return; case 24: m_opcode = "ps_res"; - m_operands = StringFromFormat("p%u, (1/p%u)", FD, FB); + m_operands = fmt::format("p{}, (1/p{})", FD, FB); return; case 25: m_opcode = "ps_mul"; - m_operands = StringFromFormat("p%u, p%u*p%u", FD, FA, FC); + m_operands = fmt::format("p{}, p{}*p{}", FD, FA, FC); return; case 26: // rsqrte m_opcode = "ps_rsqrte"; - m_operands = StringFromFormat("p%u, p%u", FD, FB); + m_operands = fmt::format("p{}, p{}", FD, FB); return; case 28: // msub m_opcode = "ps_msub"; - m_operands = StringFromFormat("p%u, p%u*p%u-p%u", FD, FA, FC, FB); + m_operands = fmt::format("p{}, p{}*p{}-p{}", FD, FA, FC, FB); return; case 29: // madd m_opcode = "ps_madd"; - m_operands = StringFromFormat("p%u, p%u*p%u+p%u", FD, FA, FC, FB); + m_operands = fmt::format("p{}, p{}*p{}+p{}", FD, FA, FC, FB); return; case 30: // nmsub m_opcode = "ps_nmsub"; - m_operands = StringFromFormat("p%u, -(p%u*p%u-p%u)", FD, FA, FC, FB); + m_operands = fmt::format("p{}, -(p{}*p{}-p{})", FD, FA, FC, FB); return; case 31: // nmadd m_opcode = "ps_nmadd"; - m_operands = StringFromFormat("p%u, -(p%u*p%u+p%u)", FD, FA, FC, FB); + m_operands = fmt::format("p{}, -(p{}*p{}+p{})", FD, FA, FC, FB); return; case 10: m_opcode = "ps_sum0"; - m_operands = StringFromFormat("p%u, 0=p%u+p%u, 1=p%u", FD, FA, FB, FC); + m_operands = fmt::format("p{}, 0=p{}+p{}, 1=p{}", FD, FA, FB, FC); return; case 11: m_opcode = "ps_sum1"; - m_operands = StringFromFormat("p%u, 0=p%u, 1=p%u+p%u", FD, FC, FA, FB); + m_operands = fmt::format("p{}, 0=p{}, 1=p{}+p{}", FD, FC, FA, FB); return; case 12: m_opcode = "ps_muls0"; - m_operands = StringFromFormat("p%u, p%u*p%u[0]", FD, FA, FC); + m_operands = fmt::format("p{}, p{}*p{}[0]", FD, FA, FC); return; case 13: m_opcode = "ps_muls1"; - m_operands = StringFromFormat("p%u, p%u*p%u[1]", FD, FA, FC); + m_operands = fmt::format("p{}, p{}*p{}[1]", FD, FA, FC); return; case 14: m_opcode = "ps_madds0"; - m_operands = StringFromFormat("p%u, p%u*p%u[0]+p%u", FD, FA, FC, FB); + m_operands = fmt::format("p{}, p{}*p{}[0]+p{}", FD, FA, FC, FB); return; case 15: m_opcode = "ps_madds1"; - m_operands = StringFromFormat("p%u, p%u*p%u[1]+p%u", FD, FA, FC, FB); + m_operands = fmt::format("p{}, p{}*p{}[1]+p{}", FD, FA, FC, FB); return; } @@ -1125,22 +1162,22 @@ void GekkoDisassembler::ps(u32 inst) // 10-bit suckers (?) case 40: // nmadd m_opcode = "ps_neg"; - m_operands = StringFromFormat("p%u, -p%u", FD, FB); + m_operands = fmt::format("p{}, -p{}", FD, FB); return; case 72: // nmadd m_opcode = "ps_mr"; - m_operands = StringFromFormat("p%u, p%u", FD, FB); + m_operands = fmt::format("p{}, p{}", FD, FB); return; case 136: m_opcode = "ps_nabs"; - m_operands = StringFromFormat("p%u, -|p%u|", FD, FB); + m_operands = fmt::format("p{}, -|p{}|", FD, FB); return; case 264: m_opcode = "ps_abs"; - m_operands = StringFromFormat("p%u, |p%u|", FD, FB); + m_operands = fmt::format("p{}, |p{}|", FD, FB); return; case 0: @@ -1152,28 +1189,28 @@ void GekkoDisassembler::ps(u32 inst) int i = (int)PPCGETCRD(inst); if (i != 0) - m_operands += StringFromFormat("cr%c, ", '0' + i); - m_operands += StringFromFormat("p%u, p%u", FA, FB); + m_operands += fmt::format("cr{}, ", '0' + i); + m_operands += fmt::format("p{}, p{}", FA, FB); return; } case 528: m_opcode = "ps_merge00"; - m_operands = StringFromFormat("p%u, p%u[0],p%u[0]", FD, FA, FB); + m_operands = fmt::format("p{}, p{}[0],p{}[0]", FD, FA, FB); return; case 560: m_opcode = "ps_merge01"; - m_operands = StringFromFormat("p%u, p%u[0],p%u[1]", FD, FA, FB); + m_operands = fmt::format("p{}, p{}[0],p{}[1]", FD, FA, FB); return; case 592: m_opcode = "ps_merge10"; - m_operands = StringFromFormat("p%u, p%u[1],p%u[0]", FD, FA, FB); + m_operands = fmt::format("p{}, p{}[1],p{}[0]", FD, FA, FB); return; case 624: m_opcode = "ps_merge11"; - m_operands = StringFromFormat("p%u, p%u[1],p%u[1]", FD, FA, FB); + m_operands = fmt::format("p{}, p{}[1],p{}[1]", FD, FA, FB); return; case 1014: @@ -1185,7 +1222,7 @@ void GekkoDisassembler::ps(u32 inst) } // default: - m_opcode = StringFromFormat("ps_%i", ((inst >> 1) & 0x1f)); + m_opcode = fmt::format("ps_{}", ((inst >> 1) & 0x1f)); m_operands = "---"; } @@ -1195,23 +1232,23 @@ void GekkoDisassembler::ps_mem(u32 inst) { case 56: m_opcode = "psq_l"; - m_operands = StringFromFormat("p%u, %i(r%u), %d, qr%d", RS, SEX12(inst & 0xFFF), RA, W, I); + m_operands = fmt::format("p{}, {}(r{}), {}, qr{}", RS, SEX12(inst & 0xFFF), RA, W, I); break; case 57: m_opcode = "psq_lu"; - m_operands = StringFromFormat("p%u, %i(r%u), %d, qr%d", RS, SEX12(inst & 0xFFF), RA, W, I); + m_operands = fmt::format("p{}, {}(r{}), {}, qr{}", RS, SEX12(inst & 0xFFF), RA, W, I); ; break; case 60: m_opcode = "psq_st"; - m_operands = StringFromFormat("p%u, %i(r%u), %d, qr%d", RS, SEX12(inst & 0xFFF), RA, W, I); + m_operands = fmt::format("p{}, {}(r{}), {}, qr{}", RS, SEX12(inst & 0xFFF), RA, W, I); break; case 61: m_opcode = "psq_stu"; - m_operands = StringFromFormat("p%u, %i(r%u), %d, qr%d", RS, SEX12(inst & 0xFFF), RA, W, I); + m_operands = fmt::format("p{}, {}(r{}), {}, qr{}", RS, SEX12(inst & 0xFFF), RA, W, I); break; } } @@ -1845,7 +1882,7 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian) else { m_opcode = "mcrxr"; - m_operands = StringFromFormat("cr%d", (int)PPCGETCRD(in)); + m_operands = fmt::format("cr{}", PPCGETCRD(in)); } break; @@ -2214,8 +2251,8 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian) case 134: if ((in & 0x006f0800) == 0) { - m_opcode = StringFromFormat("mtfsfi%s", rcsel[in & 1]); - m_operands = StringFromFormat("cr%d,%d", (int)PPCGETCRD(in), (int)(in & 0xf000) >> 12); + m_opcode = fmt::format("mtfsfi{}", rcsel[in & 1]); + m_operands = fmt::format("cr{},{}", PPCGETCRD(in), (in & 0xf000) >> 12); } else { @@ -2241,8 +2278,8 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian) case 711: if ((in & 0x02010000) == 0) { - m_opcode = StringFromFormat("mtfsf%s", rcsel[in & 1]); - m_operands = StringFromFormat("0x%x, f%u", (in >> 17) & 0xff, PPCGETB(in)); + m_opcode = fmt::format("mtfsf{}", rcsel[in & 1]); + m_operands = fmt::format("0x{:x}, f{}", (in >> 17) & 0xff, PPCGETB(in)); } else { diff --git a/Source/Core/Common/GekkoDisassembler.h b/Source/Core/Common/GekkoDisassembler.h index f3e3ef0859..a77f1c6989 100644 --- a/Source/Core/Common/GekkoDisassembler.h +++ b/Source/Core/Common/GekkoDisassembler.h @@ -93,42 +93,6 @@ private: static u32* DoDisassembly(bool big_endian); - static u32 HelperRotateMask(int r, int mb, int me) - { - // first make 001111111111111 part - unsigned int begin = 0xFFFFFFFF >> mb; - // then make 000000000001111 part, which is used to flip the bits of the first one - unsigned int end = me < 31 ? (0xFFFFFFFF >> (me + 1)) : 0; - // do the bitflip - unsigned int mask = begin ^ end; - // and invert if backwards - if (me < mb) - mask = ~mask; - // rotate the mask so it can be applied to source reg - // return _rotl(mask, 32 - r); - return (mask << (32 - r)) | (mask >> r); - } - - static std::string ldst_offs(u32 val) - { - if (val == 0) - { - return "0"; - } - else - { - if (val & 0x8000) - { - return StringFromFormat("-0x%.4X", ((~val) & 0xffff) + 1); - } - else - { - return StringFromFormat("0x%.4X", val); - } - } - } - - static int SEX12(u32 x) { return x & 0x800 ? (x | 0xFFFFF000) : x; } enum InstructionType { PPCINSTR_OTHER = 0, // No additional info for other instr. diff --git a/Source/Core/Common/JitRegister.cpp b/Source/Core/Common/JitRegister.cpp index 089eb1cd08..1dcf999f3a 100644 --- a/Source/Core/Common/JitRegister.cpp +++ b/Source/Core/Common/JitRegister.cpp @@ -2,16 +2,18 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include +#include "Common/JitRegister.h" + #include #include #include #include #include +#include + #include "Common/CommonTypes.h" #include "Common/File.h" -#include "Common/JitRegister.h" #include "Common/StringUtil.h" #ifdef _WIN32 @@ -48,8 +50,8 @@ void Init(const std::string& perf_dir) if (!perf_dir.empty() || getenv("PERF_BUILDID_DIR")) { - std::string dir = perf_dir.empty() ? "/tmp" : perf_dir; - std::string filename = StringFromFormat("%s/perf-%d.map", dir.data(), getpid()); + const std::string dir = perf_dir.empty() ? "/tmp" : perf_dir; + const std::string filename = fmt::format("{}/perf-{}.map", dir, getpid()); s_perf_map_file.Open(filename, "w"); // Disable buffering in order to avoid missing some mappings // if the event of a crash: @@ -90,7 +92,7 @@ void RegisterV(const void* base_address, u32 code_size, const char* format, va_l std::string symbol_name = StringFromFormatV(format, args); #if defined USE_OPROFILE && USE_OPROFILE - op_write_native_code(s_agent, symbol_name.data(), (u64)base_address, base_address, code_size); + op_write_native_code(s_agent, symbol_name.c_str(), (u64)base_address, base_address, code_size); #endif #ifdef USE_VTUNE @@ -98,16 +100,15 @@ void RegisterV(const void* base_address, u32 code_size, const char* format, va_l jmethod.method_id = iJIT_GetNewMethodID(); jmethod.method_load_address = const_cast(base_address); jmethod.method_size = code_size; - jmethod.method_name = const_cast(symbol_name.data()); + jmethod.method_name = const_cast(symbol_name.c_str()); iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&jmethod); #endif // Linux perf /tmp/perf-$pid.map: - if (s_perf_map_file.IsOpen()) - { - std::string entry = - StringFromFormat("%" PRIx64 " %x %s\n", (u64)base_address, code_size, symbol_name.data()); - s_perf_map_file.WriteBytes(entry.data(), entry.size()); - } + if (!s_perf_map_file.IsOpen()) + return; + + const auto entry = fmt::format("{} {:x} {}\n", fmt::ptr(base_address), code_size, symbol_name); + s_perf_map_file.WriteBytes(entry.data(), entry.size()); } } // namespace JitRegister diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 4e946e8fd2..5a23cc7945 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Common/Logging/LogManager.h" + #include #include #include @@ -10,12 +12,13 @@ #include #include +#include + #include "Common/CommonPaths.h" #include "Common/Config/Config.h" #include "Common/FileUtil.h" #include "Common/Logging/ConsoleListener.h" #include "Common/Logging/Log.h" -#include "Common/Logging/LogManager.h" #include "Common/StringUtil.h" #include "Common/Timer.h" @@ -207,9 +210,9 @@ void LogManager::LogWithFullPath(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE char temp[MAX_MSGLEN]; CharArrayFromFormatV(temp, MAX_MSGLEN, format, args); - std::string msg = - StringFromFormat("%s %s:%u %c[%s]: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, - line, LogTypes::LOG_LEVEL_TO_CHAR[(int)level], GetShortName(type), temp); + const std::string msg = + fmt::format("{} {}:{} {}[{}]: {}\n", Common::Timer::GetTimeFormatted(), file, line, + LogTypes::LOG_LEVEL_TO_CHAR[(int)level], GetShortName(type), temp); for (auto listener_id : m_listener_ids) if (m_listeners[listener_id]) diff --git a/Source/Core/Common/MD5.cpp b/Source/Core/Common/MD5.cpp index 1020b51e57..5c2265e2a2 100644 --- a/Source/Core/Common/MD5.cpp +++ b/Source/Core/Common/MD5.cpp @@ -2,12 +2,15 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Common/MD5.h" + #include #include #include #include -#include "Common/MD5.h" +#include + #include "Common/StringUtil.h" #include "DiscIO/Blob.h" @@ -45,7 +48,7 @@ std::string MD5Sum(const std::string& file_path, std::function report // Convert to hex for (u8 n : output) - output_string += StringFromFormat("%02x", n); + output_string += fmt::format("{:02x}", n); return output_string; } diff --git a/Source/Core/Common/NandPaths.cpp b/Source/Core/Common/NandPaths.cpp index 390d95033c..ac57ccdcdc 100644 --- a/Source/Core/Common/NandPaths.cpp +++ b/Source/Core/Common/NandPaths.cpp @@ -9,6 +9,8 @@ #include #include +#include + #include "Common/CommonTypes.h" #include "Common/FileUtil.h" #include "Common/StringUtil.h" @@ -28,21 +30,20 @@ static std::string RootUserPath(std::optional from) std::string GetImportTitlePath(u64 title_id, std::optional from) { - return RootUserPath(from) + StringFromFormat("/import/%08x/%08x", - static_cast(title_id >> 32), - static_cast(title_id)); + return RootUserPath(from) + fmt::format("/import/{:08x}/{:08x}", static_cast(title_id >> 32), + static_cast(title_id)); } std::string GetTicketFileName(u64 title_id, std::optional from) { - return StringFromFormat("%s/ticket/%08x/%08x.tik", RootUserPath(from).c_str(), - static_cast(title_id >> 32), static_cast(title_id)); + return fmt::format("{}/ticket/{:08x}/{:08x}.tik", RootUserPath(from), + static_cast(title_id >> 32), static_cast(title_id)); } std::string GetTitlePath(u64 title_id, std::optional from) { - return StringFromFormat("%s/title/%08x/%08x", RootUserPath(from).c_str(), - static_cast(title_id >> 32), static_cast(title_id)); + return fmt::format("{}/title/{:08x}/{:08x}", RootUserPath(from), static_cast(title_id >> 32), + static_cast(title_id)); } std::string GetTitleDataPath(u64 title_id, std::optional from) @@ -62,7 +63,7 @@ std::string GetTMDFileName(u64 title_id, std::optional from) std::string GetMiiDatabasePath(std::optional from) { - return StringFromFormat("%s/shared2/menu/FaceLib/RFL_DB.dat", RootUserPath(from).c_str()); + return fmt::format("{}/shared2/menu/FaceLib/RFL_DB.dat", RootUserPath(from)); } bool IsTitlePath(const std::string& path, std::optional from, u64* title_id) @@ -111,7 +112,7 @@ std::string EscapeFileName(const std::string& filename) for (char c : filename_with_escaped_double_underscores) { if ((c >= 0 && c <= 0x1F) || chars_to_replace.find(c) != chars_to_replace.end()) - result.append(StringFromFormat("__%02x__", c)); + result.append(fmt::format("__{:02x}__", c)); else result.push_back(c); } diff --git a/Source/Core/Common/Network.cpp b/Source/Core/Common/Network.cpp index acfb60e55c..77d835a126 100644 --- a/Source/Core/Common/Network.cpp +++ b/Source/Core/Common/Network.cpp @@ -9,8 +9,9 @@ #include #include +#include + #include "Common/Random.h" -#include "Common/StringUtil.h" namespace Common { @@ -38,8 +39,8 @@ MACAddress GenerateMacAddress(const MACConsumer type) std::string MacAddressToString(const MACAddress& mac) { - return StringFromFormat("%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], - mac[5]); + return fmt::format("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", mac[0], mac[1], mac[2], mac[3], + mac[4], mac[5]); } std::optional StringToMacAddress(const std::string& mac_string) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index b946cfd450..0df4b595cd 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -2,8 +2,9 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Common/StringUtil.h" + #include -#include #include #include #include @@ -18,11 +19,12 @@ #include #include +#include + #include "Common/CommonFuncs.h" #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" -#include "Common/StringUtil.h" #include "Common/Swap.h" #ifdef _WIN32 @@ -51,12 +53,12 @@ std::string HexDump(const u8* data, size_t size) std::string out; for (size_t row_start = 0; row_start < size; row_start += BYTES_PER_LINE) { - out += StringFromFormat("%06zx: ", row_start); + out += fmt::format("{:06x}: ", row_start); for (size_t i = 0; i < BYTES_PER_LINE; ++i) { if (row_start + i < size) { - out += StringFromFormat("%02hhx ", data[row_start + i]); + out += fmt::format("{:02x} ", data[row_start + i]); } else { @@ -294,27 +296,27 @@ bool TryParse(const std::string& str, bool* const output) std::string ValueToString(u16 value) { - return StringFromFormat("0x%04x", value); + return fmt::format("0x{:04x}", value); } std::string ValueToString(u32 value) { - return StringFromFormat("0x%08x", value); + return fmt::format("0x{:08x}", value); } std::string ValueToString(u64 value) { - return StringFromFormat("0x%016" PRIx64, value); + return fmt::format("0x{:016x}", value); } std::string ValueToString(float value) { - return StringFromFormat("%#.9g", value); + return fmt::format("{:#.9g}", value); } std::string ValueToString(double value) { - return StringFromFormat("%#.17g", value); + return fmt::format("{:#.17g}", value); } std::string ValueToString(int value) @@ -324,7 +326,7 @@ std::string ValueToString(int value) std::string ValueToString(s64 value) { - return StringFromFormat("%" PRId64, value); + return std::to_string(value); } std::string ValueToString(bool value) diff --git a/Source/Core/Common/Timer.cpp b/Source/Core/Common/Timer.cpp index 1d25cc0f71..794f2dfd49 100644 --- a/Source/Core/Common/Timer.cpp +++ b/Source/Core/Common/Timer.cpp @@ -2,7 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include +#include "Common/Timer.h" + #include #include @@ -16,9 +17,10 @@ #include #endif +#include + #include "Common/CommonTypes.h" #include "Common/StringUtil.h" -#include "Common/Timer.h" namespace Common { @@ -149,9 +151,8 @@ std::string Timer::GetTimeElapsedFormatted() const // Hours u32 Hours = Minutes / 60; - std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03" PRIu64, Hours, Minutes % 60, - Seconds % 60, Milliseconds % 1000); - return TmpStr; + return fmt::format("{:02}:{:02}:{:02}:{:03}", Hours, Minutes % 60, Seconds % 60, + Milliseconds % 1000); } // Get current time @@ -217,15 +218,15 @@ std::string Timer::GetTimeFormatted() #ifdef _WIN32 struct timeb tp; (void)::ftime(&tp); - return UTF16ToUTF8(tmp) + StringFromFormat(":%03i", tp.millitm); + return UTF16ToUTF8(tmp) + fmt::format(":{:03}", tp.millitm); #elif defined __APPLE__ struct timeval t; (void)gettimeofday(&t, nullptr); - return StringFromFormat("%s:%03d", tmp, (int)(t.tv_usec / 1000)); + return fmt::format("{}:{:03}", tmp, t.tv_usec / 1000); #else struct timespec t; (void)clock_gettime(CLOCK_MONOTONIC, &t); - return StringFromFormat("%s:%03d", tmp, (int)(t.tv_nsec / 1000000)); + return fmt::format("{}:{:03}", tmp, t.tv_nsec / 1000000); #endif }