{"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,"milestone":null,"comments":16,"created_at":"2016-01-24T20:43:12Z","updated_at":"2016-02-25T00:29: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, but it doesn't actually work. This is a PR to give people an early look at what the API looks like and to offer suggestions/advice/commentary.\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.\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. Note that the load/store code isn't 100% complete yet.\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. This is not currently implemented, but a sample use of the API will likely look like is in SafeRead/SafeWrite.\r\n\r\nI plan on making all of the register locks and borrows 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. I don't expect this will happen often and this may overcomplicate the code.\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\nCaution: as part of this work I would like to replace uses of RSCRATCH/RSCRATCH2/RSCRATCH_EXTRA with calls to reg.gpr.Borrow() to potentially give us some extra breathing room by bringing these into the allocation order if they aren't used. This turns out to be fairly large on its own so I'm going to split that out into its own changeset for the future. Half of that work is contained in this patch, but will be out for the final PR.\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/188533312","html_url":"https://github.com/dolphin-emu/dolphin/pull/3565#issuecomment-188533312","issue_url":"https://api.github.com/repos/dolphin-emu/dolphin/issues/3565","id":188533312,"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},"created_at":"2016-02-25T00:29:07Z","updated_at":"2016-02-25T00:29:07Z","body":"\n\n\n\nReview status: 31 of 47 files reviewed at latest revision, 99 unresolved discussions.\n\n---\n\n*[Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp, line 89 \\[r6\\]](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565#-KBKp-dfbHWVYeZZSPCP:-KBKp-dg3ptrm6lLemvR:-1520941894) ([raw file](https://github.com/dolphin-emu/dolphin/blob/472ac199b684b1084c6375fcbe1de08715864412/Source/Core/Core/PowerPC/Jit64/Jit64_RegCache.cpp#L89)):*\nTODO: zero-initialize this\n\n---\n\n\n*Comments from the [review on Reviewable.io](https://reviewable.io:443/reviews/dolphin-emu/dolphin/3565)*\n<!-- Sent from Reviewable.io -->\n"}}