{"action":"created","issue":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3565","repository_url":"https://api.github.com/repos/dolphin-emu/dolphin","labels_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3565/labels{/name}","comments_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3565/comments","events_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3565/events","html_url":"https://github.com/dolphin-emu/dolphin/pull/3565","id":128423868,"number":3565,"title":"[WIP/RFC] Refactor the register cache to use C++ idioms for locking/binding/unlocking","user":{"login":"mmastrac","id":512240,"avatar_url":"https://avatars.githubusercontent.com/u/512240?v=3","gravatar_id":"","url":"https://api.github.com/users/mmastrac","html_url":"https://github.com/mmastrac","followers_url":"https://api.github.com/users/mmastrac/followers","following_url":"https://api.github.com/users/mmastrac/following{/other_user}","gists_url":"https://api.github.com/users/mmastrac/gists{/gist_id}","starred_url":"https://api.github.com/users/mmastrac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmastrac/subscriptions","organizations_url":"https://api.github.com/users/mmastrac/orgs","repos_url":"https://api.github.com/users/mmastrac/repos","events_url":"https://api.github.com/users/mmastrac/events{/privacy}","received_events_url":"https://api.github.com/users/mmastrac/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dolphin-emu/dolphin/labels/RFC","name":"RFC","color":"fad8c7"},{"url":"https://api.github.com/repos/dolphin-emu/dolphin/labels/WIP","name":"WIP","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":44,"created_at":"2016-01-24T20:43:12Z","updated_at":"2016-06-30T17:12:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/pulls/3565","html_url":"https://github.com/dolphin-emu/dolphin/pull/3565","diff_url":"https://github.com/dolphin-emu/dolphin/pull/3565.diff","patch_url":"https://github.com/dolphin-emu/dolphin/pull/3565.patch"},"body":"Preface: this code compiles and works, but there are likely a few small bugs that will be shaken out via testing.\r\n\r\nThis work builds on my two other inflight PRs that are waiting for the freeze to end (the first three of four commits are from there). The changeset with all the magic is https://github.com/dolphin-emu/dolphin/commit/494f3027056cc157ab6fce89cc0dd14f38561623. Also note that Github won't show the diff for Jit_Integer.cpp due to size.\r\n\r\nThe goals of this PR are 1) to replace manual locking/binding/unlocking/transaction patterns with automated management of locks and binds with C++ constructors and destructors and 2) to keep the structure and function of the code as close to before as possible, and 3) fix a number of small bugs that are revealed using a stricter register cache.\r\n\r\nBecause a significant amount of the complexity in the register cache and the required complexity for us to port that code to the new API happens around the 'update' phase of stores and loads, I decided that I'd tackle that as part of the patch.\r\n\r\nTo handle register rollback in the case of memory exceptions, I've introduced the concept of a transactional binding. A register with a transactional binding will be bound to an X64 register until the point at which `Rollback()` or `Commit()` is called.\r\n\r\nAll of the register locks and borrows are lazy -- they won't be computed until the first time we access their location. This allows the regcache to avoid allocating a register that will be flushed immediately, or binding a PPC register to an x64 register that we're going to need shortly.\r\n\r\nThe register cache also adds the concept of an \"immediate\" register. This is a register with an immutable immediate value that can be used in the same way as a PPC register. It allows us to unify the code paths for registers that happened to have an immediate value and opcodes that pull operands from the constants embedded in their encoding. There are still a few places where I haven't refactored the code to take advantage of these. To avoid increasing the size of this patch more than necessary, I'll do that at a later date.\r\n\r\nI've used the \"auto\" keyword heavily in the changeset to allow me to change the underlying types as I tweak the API. I'm not attached to that, but if we switch to concrete types I'd want to do that as a final pass once everything is ready to commit.\r\n\r\n<!-- Reviewable:start -->\r\n[<img src=\"https://reviewable.io/review_button.png\" height=40 alt=\"Review on Reviewable\"/>](https://reviewable.io/reviews/dolphin-emu/dolphin/3565)\r\n<!-- Reviewable:end -->\r\n"},"comment":{"url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/comments/229725006","html_url":"https://github.com/dolphin-emu/dolphin/pull/3565#issuecomment-229725006","issue_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3565","id":229725006,"user":{"login":"lioncash","id":712067,"avatar_url":"https://avatars.githubusercontent.com/u/712067?v=3","gravatar_id":"","url":"https://api.github.com/users/lioncash","html_url":"https://github.com/lioncash","followers_url":"https://api.github.com/users/lioncash/followers","following_url":"https://api.github.com/users/lioncash/following{/other_user}","gists_url":"https://api.github.com/users/lioncash/gists{/gist_id}","starred_url":"https://api.github.com/users/lioncash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lioncash/subscriptions","organizations_url":"https://api.github.com/users/lioncash/orgs","repos_url":"https://api.github.com/users/lioncash/repos","events_url":"https://api.github.com/users/lioncash/events{/privacy}","received_events_url":"https://api.github.com/users/lioncash/received_events","type":"User","site_admin":false},"created_at":"2016-06-30T17:12:06Z","updated_at":"2016-06-30T17:12:06Z","body":"\n\n\n\nReview status: 11 of 40 files reviewed at latest revision, 91 unresolved discussions.\n\n---\n\n*[Source/Core/Common/x64Emitter.h, line 304 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXH9SYpAgx-kAeNU03:-KLXH9SYpAgx-kAeNU04:1361422236) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Common/x64Emitter.h#L304)):*\n> ```objc\n>     return OpArg((u8)offset, SCALE_IMM8);\n>   }\n>   OpArg AsImm(u8 asScale)\n> ```\n\nThis can likely be const qualified as:\n\n```cpp\nOpArg AsImm(u8 asScale) const\n```\n\nYou may want to make `asScale` be an `int` or `unsigned int`/`u32`  or something. This'll likely lead to unnecessary truncations otherwise.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit.h, line 31 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLWwcapWTGVpBM0VL1C:-KLWwcaqTpnE8zShxyoo:1851390681) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit.h#L31)):*\n> ```objc\n> \n> // Selective import from Jit64Reg\n> using GPRNative = Jit64Reg::GPRNative;\n> ```\n\nthese can likely just be\n\n```cpp\nusing Jit64Reg::GPRNative;\nusing Jit64Reg::GPRRegister;\nusing Jit64Reg::FPUNative;\nusing Jit64Reg::FPURegister;\nusing Jit64Reg::BindMode;\n```\n\nto import them through a namespace.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 37 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLWy05mji5rLvSUPTf_:-KLWy05nYxXY6wtdN2bL:-1550604652) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L37)):*\n> ```cpp\n>                                                   XMM13, XMM14, XMM15, XMM2, XMM3,  XMM4,  XMM5};\n> \n> const std::vector<X64Reg> FPU_SCRATCH_ALLOCATION_ORDER = {XMM0, XMM1};\n> ```\n\nIf any of the above can reasonably be made into `std::array` (i.e. if doing so wouldn't complicate API), it'll likely avoid doing some easy-to-avoid heap allocations.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 221 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLWynY1wJ_gv39bN4Tp:-KLWynY2uqcBTzj94JL8:-1372435124) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L221)):*\n> ```cpp\n> \n> template <Type T>\n> void Any<T>::LockAdvisory(RegisterData& data)\n> ```\n\nThis can be a const reference, since it's only read from (as far as I can tell).\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 282 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLWz2ngKj-89jP4FvOl:-KLWz2ngKj-89jP4FvOm:1662569705) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L282)):*\n> ```cpp\n> \n> template <Type T>\n> void Any<T>::Unlock(RegisterData& data)\n> ```\n\nSame here.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 330 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLWz6Q-CTkLhYKlpm8L:-KLWz6Q-CTkLhYKlpm8M:1854746597) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L330)):*\n> ```cpp\n> \n> template <Type T>\n> void Any<T>::UnlockAdvisory(RegisterData& data)\n> ```\n\nSame here\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 484 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX-mW6JvBBzKTS5D2b:-KLX-mW7Irhn2mSf2n0Z:-305512373) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L484)):*\n> ```cpp\n>   for (auto& xreg : m_xregs)\n>   {\n>     ReleaseXReg((X64Reg)(&xreg - &m_xregs[0]));\n> ```\n\nstatic_cast\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 533 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX04c-WBLM9fZs5LMa:-KLX04c0X2YXHS9Ns9Y1:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L533)):*\n> ```cpp\n> \n>     // Don't bind immediates\n>     auto& ppc = m_regs[reg];\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 547 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX09x08lVCkOf8mll0:-KLX09x08lVCkOf8mll1:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L547)):*\n> ```cpp\n>   for (int i : regs)\n>   {\n>     auto& reg = m_regs[i];\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 644 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX0nUy2QTpqGjKfUXw:-KLX0nUy2QTpqGjKfUXx:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L644)):*\n> ```cpp\n> {\n>   // Flushing will automatically release bound registers, but not borrowed ones\n>   ForEachX64([&](auto i, auto& xreg) {\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 648 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX0kg3Mm_rgedlMfgV:-KLX0kg4f4JeQDH-mDNN:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L648)):*\n> ```cpp\n>   });\n> \n>   ForEachPPC([&](auto i, auto& reg) {\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 663 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX0XDii_mmUwhEt8nu:-KLX0XDii_mmUwhEt8nv:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L663)):*\n> ```cpp\n> {\n>   // Flushing will automatically release bound registers, but not borrowed ones\n>   ForEachX64([&](auto i, auto& xreg) {\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 667 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX0UcOTdTppLVU_OB9:-KLX0UcOTdTppLVU_OBA:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L667)):*\n> ```cpp\n>   });\n> \n>   ForEachPPC([&](auto i, auto& reg) {\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 722 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX0djBrAgEXE1pLjeD:-KLX0djCcEZH5Jhvg5Q2:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L722)):*\n> ```cpp\n>     // If this is attached to a locked bound PPC register, it isn't available\n>     size_t preg = m_xregs[xr].ppcReg;\n>     auto& reg = m_regs[preg];\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 801 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX0zJzXPjfnb4cBobb:-KLX0zJzXPjfnb4cBobc:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L801)):*\n> ```cpp\n>     _assert_msg_(REGCACHE, !xreg.dirty, \"Xreg already dirty\");\n>     _assert_msg_(REGCACHE, xreg.locked == 0, \"GetFreeXReg returned borrowed register\");\n>     ForEachPPC([&](auto i, auto& reg) {\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 824 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX14wU5QJpCiYAbyN8:-KLX14wU5QJpCiYAbyN9:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L824)):*\n> ```cpp\n> \n>   X64Reg xr = ppc.location.GetSimpleReg();\n>   auto& xreg = m_xregs[xr];\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 861 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX1ArOSHtFGcK8sAMX:-KLX1ArOSHtFGcK8sAMY:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L861)):*\n> ```cpp\n>     {\n>       X64Reg xr = ppc.location.GetSimpleReg();\n>       auto& xreg = m_xregs[xr];\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 885 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX1EVb990DMLXV0dnk:-KLX1EVb990DMLXV0dnl:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L885)):*\n> ```cpp\n> void RegisterClassBase<T>::CheckUnlocked() const\n> {\n>   ForEachPPC([&](auto i, auto& reg) {\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 895 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX1KLYGTOwvSNgtbPw:-KLX1KLZyv6E-VUScsbK:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L895)):*\n> ```cpp\n>   CheckUnlocked();\n> \n>   ForEachPPC([&](auto i, auto& reg) {\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 920 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX1Pw4Dvic7xoo9kbN:-KLX1Pw4Dvic7xoo9kbO:-2111354431) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L920)):*\n> ```cpp\n>   CheckUnlocked();\n> \n>   ForEachPPC([&](auto i, auto& reg) {\n> ```\n\n`const auto&`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 941 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX1eXiDNfANRTOrSs3:-KLX1eXjcg2mV87wKZ_Z:1172493747) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L941)):*\n> ```cpp\n>                      \"Lock count for the rollback register should have been %u (was %u)\",\n>                      ROLLBACK_LOCK_MAGIC, xreg.locked);\n>         m_xregs[xrRollback].locked = 0;\n> ```\n\n`xreg.locked = 0;`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h, line 437 \\[r2\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KBGOuk3Cb8JzY2bGdJX:-KLX2nBoa48x-7h1cDrZ:-543950346) ([raw file](https://github.com/dolphin-emu/dolphin/blob/389f150a68d06ccdc3359b33f6c5ce687fa34d93/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h#L437)):*\n<details><summary><i>Previously, mmastrac (Matt Mastracci) wrote…</i></summary>\n> Not sure what you mean here\n</details>\nI forget what I was pointing out here, so I'll just mark this as satisfied.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h, line 451 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX2y8i6_qriHj50dpj:-KLX2y8oWIRqZyKg-1x_:647752994) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h#L451)):*\n> ```objc\n>     // A native register is locked if it is either explictly bound to a\n>     // PPC register or borrowed.\n>     int locked;\n> ```\n\nYou may want to indicate in a comment why this isn't a boolean (or perhaps use an `enum` or `enum class`) if it uses more than just `true` or `false` \n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h, line 506 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX48RaVcYA0BkcSqFG:-KLX48RbauvYnPdkhTZN:490282733) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h#L506)):*\n> ```objc\n>   void CheckUnlocked() const;\n>   BitSet32 CountRegsIn(reg_t preg, u32 lookahead) const;\n>   template <typename Func>\n> ```\n\n`Func` should probably be `FunctionObject`, since it satisfies that [concept](http://en.cppreference.com/w/cpp/concept/FunctionObject). The plus side is that whenever C++ Concepts get standardized ([really wordy standardese proposal document](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4377.pdf)), these can just be changed over to it.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h, line 555 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX6f-7zX45eEq3LtAL:-KLX6f-887z_vXL9lkXr:-1523855657) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h#L555)):*\n> ```objc\n>       reg.locked = 0;\n>   }\n>   void CopyFrom(RegisterClassBase<T>& other)\n> ```\n\n`other` can be a const reference.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h, line 589 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX793c74aJFWZZSS-M:-KLX793c74aJFWZZSS-N:647725875) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h#L589)):*\n> ```objc\n> \n> protected:\n>   virtual const std::vector<X64Reg>& GetAllocationOrder() const { return FPU_ALLOCATION_ORDER; }\n> ```\n\nThe `virtual` keyword can be swapped out with the C++11 [override](http://en.cppreference.com/w/cpp/language/override) keyword.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h, line 637 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX7fC0hhkQLCYa3d8I:-KLX7fC1PpU3qfljcnR3:-1697877165) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.h#L637)):*\n> ```objc\n>   CarryLock LockCarry() { return CarryLock(m_carryLock); }\n> protected:\n>   virtual const std::vector<X64Reg>& GetAllocationOrder() const { return GPR_ALLOCATION_ORDER; }\n> ```\n\nSame here with regards to [override](http://en.cppreference.com/w/cpp/language/override)\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp, line 82 \\[r1\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-K8pauZ87lYUqYlGV2EF:-KLXBDiN28fWjxounq3p:-126380488) ([raw file](https://github.com/dolphin-emu/dolphin/blob/494f3027056cc157ab6fce89cc0dd14f38561623/Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp#L82)):*\n<details><summary><i>Previously, mmastrac (Matt Mastracci) wrote…</i></summary>\n> Uncertain about this one - test above is `if (update)`\n</details>\nThis is likely out of sync, now, so I wouldn't worry about this.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp, line 17 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXC0GuPbVCKV1LSnXu:-KLXC0GvJevLMKiGsnih:-1755578941) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp#L17)):*\n> ```cpp\n> // we create a register transaction that will restore the register value.\n> \n> void Jit64::SafeWrite(GPRRegister& reg_value, GPRRegister& reg_addr, GPRRegister& offset,\n> ```\n\nI think `offset` can be a const reference.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp, line 202 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX8q2fI7OLRrefAPQI:-KLX8q2fI7OLRrefAPQJ:-766681487) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp#L202)):*\n> ```cpp\n> }\n> \n> void Jit64::UnsafeWriteToMemory(int accessSize, GPRRegister& value, OpArg target, bool swap)\n> ```\n\n`value` can likely be a const reference (this also allows a few other functions to take const references, as pointed out below)\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp, line 221 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX9CdInv5wr309tJqa:-KLX9CdInv5wr309tJqb:178841096) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp#L221)):*\n> ```cpp\n> }\n> \n> void Jit64::UnsafeWriteGatherPipe(int accessSize, GPRRegister& value, bool swap)\n> ```\n\n`value` can likely be a const reference\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp, line 235 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX9UrmrgVJIlGQ8ZOD:-KLX9UrmrgVJIlGQ8ZOE:1249106726) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp#L235)):*\n> ```cpp\n> }\n> \n> void Jit64::UnsafeWriteToConstRamAddress(int accessSize, GPRRegister& value, u32 address, bool swap)\n> ```\n\n`value` can likely be a const reference.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp, line 380 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX9d3SpPiS9GkonCnM:-KLX9d3SpPiS9GkonCnN:178841096) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp#L380)):*\n> ```cpp\n> }\n> \n> bool Jit64::UnsafeReadFromConstAddress(int accessSize, GPRNative& value, u32 address,\n> ```\n\n`value` can likely be a const reference\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp, line 393 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX9gWEi0snKirrXmEF:-KLX9gWFLRDT0s5qmHu8:1249106726) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp#L393)):*\n> ```cpp\n> }\n> \n> void Jit64::UnsafeReadFromConstRamAddress(int accessSize, GPRNative& value, u32 address,\n> ```\n\n`value` can likely be a const reference.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp, line 409 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLX9jyJFF4qFzzdwtrh:-KLX9jyJFF4qFzzdwtri:722885127) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit64_Util.cpp#L409)):*\n> ```cpp\n> }\n> \n> void Jit64::UnsafeReadFromMemory(int accessSize, GPRNative& value, Gen::OpArg target,\n> ```\n\n`value` can likely be a const reference. `Gen::` can also be removed from `target`\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp, line 55 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXCkDkchgJxusCAL0e:-KLXCkDkchgJxusCAL0f:-305512373) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp#L55)):*\n> ```cpp\n>   if (!SConfig::GetInstance().bAccurateNaNs)\n>   {\n>     if ((X64Reg)out != xmm)\n> ```\n\nstatic_cast\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp, line 63 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXDnVoKOVxCWt8PFso:-KLXDnVoKOVxCWt8PFsp:-240076293) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp#L63)):*\n> ```cpp\n>   std::vector<OpArg> inputs;\n>   std::set<Jit64Reg::reg_t> foundRegs;\n>   for (auto& reg : allInputs)\n> ```\n\n`reg` can be a const reference\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp, line 146 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXCrcMrlIRevbbLAnH:-KLXCrcMrlIRevbbLAnI:-305512373) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp#L146)):*\n> ```cpp\n>     }\n>   }\n>   if ((X64Reg)out != xmm)\n> ```\n\nstatic_cast\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp, line 659 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXDFNvF2IEuqxLhWGG:-KLXDFNwpF14U7C2iwF9:-305512373) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp#L659)):*\n> ```cpp\n>   auto scratch_extra = regs.gpr.Borrow(RSCRATCH_EXTRA);\n>   auto xmm0 = regs.fpu.Borrow(XMM0);\n>   MOVAPD((X64Reg)xmm0, rb);\n> ```\n\nstatic_cast\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp, line 677 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXDDfE212NV-UdTg0d:-KLXDDfFf1KtODqmRBJk:-305512373) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp#L677)):*\n> ```cpp\n>   auto scratch_extra = regs.gpr.Borrow(RSCRATCH_EXTRA);\n>   auto xmm0 = regs.fpu.Borrow(XMM0);\n>   MOVAPD((X64Reg)xmm0, rb);\n> ```\n\nstatic_cast\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp, line 594 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXEf8NxJZXRzx2KE-P:-KLXEf8NxJZXRzx2KE-Q:1821712844) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit_Integer.cpp#L594)):*\n> ```cpp\n> }\n> \n> void Jit64::Compare(int crf, bool merge_branch, GPRNative& input, GPRRegister& comparand)\n> ```\n\n`input` and `comparand` can both be const references.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit_Paired.cpp, line 67 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXFG1fwB2ifcyrkqeB:-KLXFG1goRJLFJaVocYH:-305512373) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit_Paired.cpp#L67)):*\n> ```cpp\n>       {\n>         auto tmp2 = regs.fpu.Borrow();\n>         MOVAPD((X64Reg)tmp2, xc);\n> ```\n\nstatic_cast\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp, line 45 \\[r17\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KLXFUKhQ-51mfA8MqzY:-KLXFUKjnba3GBVd9Qjm:-1537635761) ([raw file](https://github.com/dolphin-emu/dolphin/blob/e7fefe436d22fb1cba66099c1b285776570c7631/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp#L45)):*\n> ```cpp\n> }\n> \n> void Jit64::SetCRFieldBit(int field, int bit, GPRNative& in)\n> ```\n\n`in` can probably be a const reference.\n\n---\n\n\n*Comments from [Reviewable](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565)*\n<!-- Sent from Reviewable.io -->\n"}}
{"actor":{"display_login":"lioncash"}}