-
Notifications
You must be signed in to change notification settings - Fork 145
Rewrite cache management functions #758
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
base: master
Are you sure you want to change the base?
Conversation
f500950
to
c3f3cfd
Compare
Nice improvement in code readability! I see you've made a few changes after making the PR. Take your time and let me know when it's ready to merge. |
The previous implementation looped over and read both ways of every cache line, doing a manual comparison of the address and then doing index invalidate on match. This replaces that with a simple loop over each cache line using the Hit invalidate cache ops, which will tell the hardware to check for a cache hit and invalidate.
sceSifWriteBackDCache used Hit writeback invalidate ops, this makes it a good match to use SyncDCache now that it also does. This misses some loop unrolling that was there for large invalidations, not sure that particularly matters.
This should be safe now that we use Hit invalidate cache ops. sceSifWriteBackDCache left them and has been fine.
SyncDCache/InvalidDCache are annoying to use because of their provided range being inclusive at both ends, it's too easy to accidentally affect an extra cache line at the end. This provides a new cache API and implements the older ones using it.
It kept bugging me how easy it is to accidentally affect one more line than you intended with SyncDCache/InvalidDCache, since the range end is inclusive SyncDCache(0, 64) is syncing two cache lines and I see most code using it just add a size without subtracting 1. That's not so bad for writeback, but could be bad for invalidate. So I added a |
Looks good |
The existing cache functionality is designed and documented by Sony and so the limitation of writing back in units of 64 is known. If you have nice macros for improving its behaviour, I suppose that would be a nice addition. Personally, I used to make use the uncached or even uncached+accelerated memory region where its characteristics fit better better than writing back/invalidating the data cache lines, since there is no need to write in blocks of 64. However, we are cautioned against mixing access modes within a cache line. I am retired, but I hope to share my 2-cents. But feel free to carry on if we can manage this. |
My main problem is that I see it misused all over PS2SDK when it does something like
I agree, using UCAB memory for writing DMA lists is great.
In this case |
First of all, I totally understand if people think it's best to leave this well enough alone.
The previous implementation looped over and read both ways of every cache line, doing a manual comparison of the address and then doing index invalidate on match.
This replaces that with a simple loop over each cache line using the Hit invalidate cache ops, which will tell the hardware to check for a cache hit and invalidate.
Doing things this way should mean it's safe to do without disabling interrupts, which is how sceSifWriteBackDCache worked. Because of that I've made it use the same shared implementation, this does miss some loop unrolling from that function because I don't imagine it matters much?