-
-
Notifications
You must be signed in to change notification settings - Fork 172
Encapsulate the Cache's write mask functions as members #2990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The delete and grow functions only operate on the cache write map, so moving them into the cache struct now lets them operate directly on the members.
The type addition code only operates on the cache write map members, so moving it into the cache's struct now lets it operate directly on the members avoiding multiple levels of deferencing. The type addition function is split at the type level for bytes, words, and dwords, to make it clearer what it's doing. (previously, the function took in a generic 'size' value, implying arbitrary scalars could be handled, when really it's just meant to handle the three type sizes).
Can't test right now, but in the meantime here's a demo pack that should give the dynarec stuff a good workout. Especially Will test with the demos this evening. |
Nice; thanks for the test pack, @johnnovak -- will give it a try and report back. |
Also suggest to test for performance regressions with Screamer, Tomb Raider and System Shock in 640x480 software rendering mode in addition to Quake. |
I've tested it with a few demos on macOS and it's fine. Haven't tried Windows and I'm a bit busy right now, so feel free to merge @kcgen once you've gained enough confidence about this. |
Thanks for those tests on your side @johnnovak. I tested all of demos w/ the branch versus (will post some measurements in a bit) |
From your commit message:
Unless I'm very wrong in my understanding of how C++ works (which is always possible), this is not true. Whenever you have a member function, it gets called with a hidden I would expect this PR to have no significant difference in performance one way or the other. However, if you think this improves readability, then go for it. I'm not familiar enough with this part of the code to have a strong opinion. |
I'm using
Tested with [cpu]
cputype = pentium_slow
cycles = 250000
|
Thanks for the very detailed performance testing @kcgen. 🎖️ @weirddan455 I think you're right in principle; there is an implicit this pointer when dealing with method calls. The objective here was to fix the bug while not causing performance regressions, so this is fit for purpose plus it improves readability while keeping the same performance, which is another win 🚀 |
Yes, that's right; all members are accessed through Ideally the optimizer will hoist the repeating dereferences up to a temporary, but that only happens when the compiler can be confident that no side effects alter those dereferenced variables (like active_cb and cache). So yeah.. this is likely just a wash, but I didn't want to thow away the code given it baked out a lot of ugly hops in the code :-) |
Description
This PR is a small refactoring that encapsulates the
Cache
's write-map mask functionality as member functions, which simplifies their code but also reduces pointer dereferences (as they're not drilling into two levels of structs).Additionally, this eliminates the duplicate
decode_increase_wmapmask
functions.Suggest reviewing commit-by-commit.
@weirddan455 , this re-purposes the de-referencing cleanup done in the
std::vector
write map branch, but now on top of the currentmain
code. I've tossed that vector branch :-)Manual testing
Tested release and sanitizer builds of the benchmarks, Alone in the Dark, Windows 3.1 applications, as well as builds with the dynamic-core disabled (
-Ddynamic_core=none
) and-Ddynamic_core=dynrec
.Performance is unaffected and the branch's release-build dynrec ASM files are just a bit smaller (
693064
bytes for main,692828
for the branch; that said.. the PR's goal is just to de-dupe and move a bit of this mask functionality closer to the variables they operates on).Checklist
Please tick the items as you have addressed them. Don't remove items; leave the ones that are not applicable unchecked.
I have: