{"action":"created","comment":{"url":"https://api.github.com/repos/citra-emu/citra/pulls/comments/61382144","id":61382144,"diff_hunk":"@@ -0,0 +1,292 @@\n+// Copyright 2016 Citra Emulator Project\n+// Licensed under GPLv2 or any later version\n+// Refer to the license.txt file included.\n+\n+#pragma once\n+\n+#include <algorithm>\n+#include <array>\n+#include <functional>\n+#include <list>\n+#include <vector>\n+\n+#include \"common/assert.h\"\n+#include \"common/common_types.h\"\n+\n+#include \"core/memory.h\"\n+\n+namespace Cache {\n+\n+/// Loaders call these when mapping/unmapping code\n+void RegisterCode(u32 address, u32 size);\n+void UnregisterCode(u32 address, u32 size = 1);\n+\n+/// Clear every cache\n+void ClearCache();\n+\n+\n+using OnClearCb = std::function<void()>;\n+\n+constexpr u32 MAX_BLOCKS = 0x40000;\n+constexpr u32 INVALID_BLOCK = 0xFFFFFFFF;\n+\n+template <typename T>\n+struct BlockPtrCache {\n+    u32 addr;\n+    u32 addr_end;\n+    std::vector<T> data;\n+};\n+\n+class CacheBase {\n+public:\n+    struct functions {\n+        std::function<void(u32, u32)> code_load;\n+        std::function<void(u32, u32)> code_unload;\n+        std::function<void()> clear;\n+    } const cache_fns;\n+\n+protected:\n+    explicit CacheBase(functions fns);\n+    ~CacheBase();\n+};\n+\n+template <typename T>\n+class CacheCommon : CacheBase {\n+protected:\n+    explicit CacheCommon(bool index_mode, OnClearCb clearcb) : index_mode(index_mode), CacheBase({\n+            [this](u32 start, u32 size) { this->OnCodeLoad(start, size); },\n+            [this](u32 start, u32 size) { this->OnCodeUnload(start, size); },\n+            [this]() { this->Clear(); }}) {\n+        static_assert(std::is_pointer<T>::value, \"T must be a pointer\");","path":"src/core/arm/cache/cache.h","position":60,"original_position":60,"commit_id":"c14627ddcf62968d226f23ff6c16ce0487088a71","original_commit_id":"c14627ddcf62968d226f23ff6c16ce0487088a71","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},"body":"`std::is_pointer<T>()`","created_at":"2016-04-28T07:13:46Z","updated_at":"2016-04-28T07:13:46Z","html_url":"https://github.com/citra-emu/citra/pull/1719#discussion_r61382144","pull_request_url":"https://api.github.com/repos/citra-emu/citra/pulls/1719","_links":{"self":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/comments/61382144"},"html":{"href":"https://github.com/citra-emu/citra/pull/1719#discussion_r61382144"},"pull_request":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/1719"}}},"pull_request":{"url":"https://api.github.com/repos/citra-emu/citra/pulls/1719","id":67821126,"html_url":"https://github.com/citra-emu/citra/pull/1719","diff_url":"https://github.com/citra-emu/citra/pull/1719.diff","patch_url":"https://github.com/citra-emu/citra/pull/1719.patch","issue_url":"https://api.github.com/repos/citra-emu/citra/issues/1719","number":1719,"state":"open","locked":false,"title":"Interpreter instruction cache","user":{"login":"Bonta0","id":18446333,"avatar_url":"https://avatars.githubusercontent.com/u/18446333?v=3","gravatar_id":"","url":"https://api.github.com/users/Bonta0","html_url":"https://github.com/Bonta0","followers_url":"https://api.github.com/users/Bonta0/followers","following_url":"https://api.github.com/users/Bonta0/following{/other_user}","gists_url":"https://api.github.com/users/Bonta0/gists{/gist_id}","starred_url":"https://api.github.com/users/Bonta0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bonta0/subscriptions","organizations_url":"https://api.github.com/users/Bonta0/orgs","repos_url":"https://api.github.com/users/Bonta0/repos","events_url":"https://api.github.com/users/Bonta0/events{/privacy}","received_events_url":"https://api.github.com/users/Bonta0/received_events","type":"User","site_admin":false},"body":"Profiling showed that the interpreter spent around 10% time doing std::unordered_map lookups for the instruction cache . This PR reduces it to ~2% by caching into vectors instead, in a similar way to Memory::Read (look into page table, check for nullptr then get the data)\r\nIt provides a global that allows to clear the cache(s) and un/register codesets that can be useful for CRO\r\nIt also fixes MerryMage's jit that suffers the same issue, i have made a separate branch that would support this change","created_at":"2016-04-26T03:19:31Z","updated_at":"2016-04-28T07:13:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"98812cb97ef82e7774d9592c73660aea3d092f58","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/citra-emu/citra/pulls/1719/commits","review_comments_url":"https://api.github.com/repos/citra-emu/citra/pulls/1719/comments","review_comment_url":"https://api.github.com/repos/citra-emu/citra/pulls/comments{/number}","comments_url":"https://api.github.com/repos/citra-emu/citra/issues/1719/comments","statuses_url":"https://api.github.com/repos/citra-emu/citra/statuses/c14627ddcf62968d226f23ff6c16ce0487088a71","head":{"label":"Bonta0:interpreter_cache","ref":"interpreter_cache","sha":"c14627ddcf62968d226f23ff6c16ce0487088a71","user":{"login":"Bonta0","id":18446333,"avatar_url":"https://avatars.githubusercontent.com/u/18446333?v=3","gravatar_id":"","url":"https://api.github.com/users/Bonta0","html_url":"https://github.com/Bonta0","followers_url":"https://api.github.com/users/Bonta0/followers","following_url":"https://api.github.com/users/Bonta0/following{/other_user}","gists_url":"https://api.github.com/users/Bonta0/gists{/gist_id}","starred_url":"https://api.github.com/users/Bonta0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bonta0/subscriptions","organizations_url":"https://api.github.com/users/Bonta0/orgs","repos_url":"https://api.github.com/users/Bonta0/repos","events_url":"https://api.github.com/users/Bonta0/events{/privacy}","received_events_url":"https://api.github.com/users/Bonta0/received_events","type":"User","site_admin":false},"repo":{"id":56437480,"name":"citra","full_name":"Bonta0/citra","owner":{"login":"Bonta0","id":18446333,"avatar_url":"https://avatars.githubusercontent.com/u/18446333?v=3","gravatar_id":"","url":"https://api.github.com/users/Bonta0","html_url":"https://github.com/Bonta0","followers_url":"https://api.github.com/users/Bonta0/followers","following_url":"https://api.github.com/users/Bonta0/following{/other_user}","gists_url":"https://api.github.com/users/Bonta0/gists{/gist_id}","starred_url":"https://api.github.com/users/Bonta0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bonta0/subscriptions","organizations_url":"https://api.github.com/users/Bonta0/orgs","repos_url":"https://api.github.com/users/Bonta0/repos","events_url":"https://api.github.com/users/Bonta0/events{/privacy}","received_events_url":"https://api.github.com/users/Bonta0/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Bonta0/citra","description":"Nintendo 3DS Emulator","fork":true,"url":"https://api.github.com/repos/Bonta0/citra","forks_url":"https://api.github.com/repos/Bonta0/citra/forks","keys_url":"https://api.github.com/repos/Bonta0/citra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bonta0/citra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bonta0/citra/teams","hooks_url":"https://api.github.com/repos/Bonta0/citra/hooks","issue_events_url":"https://api.github.com/repos/Bonta0/citra/issues/events{/number}","events_url":"https://api.github.com/repos/Bonta0/citra/events","assignees_url":"https://api.github.com/repos/Bonta0/citra/assignees{/user}","branches_url":"https://api.github.com/repos/Bonta0/citra/branches{/branch}","tags_url":"https://api.github.com/repos/Bonta0/citra/tags","blobs_url":"https://api.github.com/repos/Bonta0/citra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bonta0/citra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bonta0/citra/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bonta0/citra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bonta0/citra/statuses/{sha}","languages_url":"https://api.github.com/repos/Bonta0/citra/languages","stargazers_url":"https://api.github.com/repos/Bonta0/citra/stargazers","contributors_url":"https://api.github.com/repos/Bonta0/citra/contributors","subscribers_url":"https://api.github.com/repos/Bonta0/citra/subscribers","subscription_url":"https://api.github.com/repos/Bonta0/citra/subscription","commits_url":"https://api.github.com/repos/Bonta0/citra/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bonta0/citra/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bonta0/citra/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bonta0/citra/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bonta0/citra/contents/{+path}","compare_url":"https://api.github.com/repos/Bonta0/citra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bonta0/citra/merges","archive_url":"https://api.github.com/repos/Bonta0/citra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bonta0/citra/downloads","issues_url":"https://api.github.com/repos/Bonta0/citra/issues{/number}","pulls_url":"https://api.github.com/repos/Bonta0/citra/pulls{/number}","milestones_url":"https://api.github.com/repos/Bonta0/citra/milestones{/number}","notifications_url":"https://api.github.com/repos/Bonta0/citra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bonta0/citra/labels{/name}","releases_url":"https://api.github.com/repos/Bonta0/citra/releases{/id}","deployments_url":"https://api.github.com/repos/Bonta0/citra/deployments","created_at":"2016-04-17T13:20:46Z","updated_at":"2016-04-17T14:00:25Z","pushed_at":"2016-04-28T05:07:19Z","git_url":"git://github.com/Bonta0/citra.git","ssh_url":"git@github.com:Bonta0/citra.git","clone_url":"https://github.com/Bonta0/citra.git","svn_url":"https://github.com/Bonta0/citra","homepage":"https://citra-emu.org","size":12512,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"citra-emu:master","ref":"master","sha":"1ecee38468f08445681e52f67dc9cf6b8302cffa","user":{"login":"citra-emu","id":7605670,"avatar_url":"https://avatars.githubusercontent.com/u/7605670?v=3","gravatar_id":"","url":"https://api.github.com/users/citra-emu","html_url":"https://github.com/citra-emu","followers_url":"https://api.github.com/users/citra-emu/followers","following_url":"https://api.github.com/users/citra-emu/following{/other_user}","gists_url":"https://api.github.com/users/citra-emu/gists{/gist_id}","starred_url":"https://api.github.com/users/citra-emu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citra-emu/subscriptions","organizations_url":"https://api.github.com/users/citra-emu/orgs","repos_url":"https://api.github.com/users/citra-emu/repos","events_url":"https://api.github.com/users/citra-emu/events{/privacy}","received_events_url":"https://api.github.com/users/citra-emu/received_events","type":"Organization","site_admin":false},"repo":{"id":19866730,"name":"citra","full_name":"citra-emu/citra","owner":{"login":"citra-emu","id":7605670,"avatar_url":"https://avatars.githubusercontent.com/u/7605670?v=3","gravatar_id":"","url":"https://api.github.com/users/citra-emu","html_url":"https://github.com/citra-emu","followers_url":"https://api.github.com/users/citra-emu/followers","following_url":"https://api.github.com/users/citra-emu/following{/other_user}","gists_url":"https://api.github.com/users/citra-emu/gists{/gist_id}","starred_url":"https://api.github.com/users/citra-emu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citra-emu/subscriptions","organizations_url":"https://api.github.com/users/citra-emu/orgs","repos_url":"https://api.github.com/users/citra-emu/repos","events_url":"https://api.github.com/users/citra-emu/events{/privacy}","received_events_url":"https://api.github.com/users/citra-emu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/citra-emu/citra","description":"Nintendo 3DS Emulator","fork":false,"url":"https://api.github.com/repos/citra-emu/citra","forks_url":"https://api.github.com/repos/citra-emu/citra/forks","keys_url":"https://api.github.com/repos/citra-emu/citra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/citra-emu/citra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/citra-emu/citra/teams","hooks_url":"https://api.github.com/repos/citra-emu/citra/hooks","issue_events_url":"https://api.github.com/repos/citra-emu/citra/issues/events{/number}","events_url":"https://api.github.com/repos/citra-emu/citra/events","assignees_url":"https://api.github.com/repos/citra-emu/citra/assignees{/user}","branches_url":"https://api.github.com/repos/citra-emu/citra/branches{/branch}","tags_url":"https://api.github.com/repos/citra-emu/citra/tags","blobs_url":"https://api.github.com/repos/citra-emu/citra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/citra-emu/citra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/citra-emu/citra/git/refs{/sha}","trees_url":"https://api.github.com/repos/citra-emu/citra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/citra-emu/citra/statuses/{sha}","languages_url":"https://api.github.com/repos/citra-emu/citra/languages","stargazers_url":"https://api.github.com/repos/citra-emu/citra/stargazers","contributors_url":"https://api.github.com/repos/citra-emu/citra/contributors","subscribers_url":"https://api.github.com/repos/citra-emu/citra/subscribers","subscription_url":"https://api.github.com/repos/citra-emu/citra/subscription","commits_url":"https://api.github.com/repos/citra-emu/citra/commits{/sha}","git_commits_url":"https://api.github.com/repos/citra-emu/citra/git/commits{/sha}","comments_url":"https://api.github.com/repos/citra-emu/citra/comments{/number}","issue_comment_url":"https://api.github.com/repos/citra-emu/citra/issues/comments{/number}","contents_url":"https://api.github.com/repos/citra-emu/citra/contents/{+path}","compare_url":"https://api.github.com/repos/citra-emu/citra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/citra-emu/citra/merges","archive_url":"https://api.github.com/repos/citra-emu/citra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/citra-emu/citra/downloads","issues_url":"https://api.github.com/repos/citra-emu/citra/issues{/number}","pulls_url":"https://api.github.com/repos/citra-emu/citra/pulls{/number}","milestones_url":"https://api.github.com/repos/citra-emu/citra/milestones{/number}","notifications_url":"https://api.github.com/repos/citra-emu/citra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/citra-emu/citra/labels{/name}","releases_url":"https://api.github.com/repos/citra-emu/citra/releases{/id}","deployments_url":"https://api.github.com/repos/citra-emu/citra/deployments","created_at":"2014-05-16T18:33:15Z","updated_at":"2016-04-28T07:07:03Z","pushed_at":"2016-04-28T05:07:19Z","git_url":"git://github.com/citra-emu/citra.git","ssh_url":"git@github.com:citra-emu/citra.git","clone_url":"https://github.com/citra-emu/citra.git","svn_url":"https://github.com/citra-emu/citra","homepage":"https://citra-emu.org","size":19782,"stargazers_count":1749,"watchers_count":1749,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":418,"mirror_url":null,"open_issues_count":208,"forks":418,"open_issues":208,"watchers":1749,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/1719"},"html":{"href":"https://github.com/citra-emu/citra/pull/1719"},"issue":{"href":"https://api.github.com/repos/citra-emu/citra/issues/1719"},"comments":{"href":"https://api.github.com/repos/citra-emu/citra/issues/1719/comments"},"review_comments":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/1719/comments"},"review_comment":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/citra-emu/citra/pulls/1719/commits"},"statuses":{"href":"https://api.github.com/repos/citra-emu/citra/statuses/c14627ddcf62968d226f23ff6c16ce0487088a71"}}}}