Name magic numbers + minor cache performance#5
Open
AmityWilder wants to merge 1 commit into
Open
Conversation
Multiple magic numbers were present in array sizes, so I've given them constants for clarity. Additionally, the inverse square root of 2 was being calculated at runtime when it could easily be a constant itself. I've also made one of the if-statements branchless, making it hopefully easier for the optimizer to speed up that loop. Ideally it could use a call to `popcount`, but I'm not certain what version of C++ this is designed for and the bits header doesn't have portable support for that feature in older versions. I've also swapped the X and Y loops in `dct8x8` to improve cache performance, since the `input` is row-major. Doing this gives the loops better locality since it's just sprinting through the elements in order rather than jumping row by row and then back to start the next column. This will hopefully improve the cache hit-rate. Note that this is simply a speed improvement. The cache I'm referring to is the CPU's cache of the RAM, not the browser's cache of media.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Multiple magic numbers were present in array sizes, so I've given them constants for clarity.
Additionally, the inverse square root of 2 was being calculated at runtime when it could easily be a constant itself. I've also made one of the if-statements branchless, making it hopefully easier for the optimizer to speed up that loop. Ideally it could use a call to
popcount, but I'm not certain what version of C++ this is designed for and the bits header doesn't have portable support for that feature in older versions.I've also swapped the X and Y loops in
dct8x8to improve cache performance, since theinputis row-major. Doing this gives the loops better locality since it's just sprinting through the elements in order rather than jumping row by row and then back to start the next column. This will hopefully improve the cache hit-rate. Note that this is simply a speed improvement. The cache I'm referring to is the CPU's cache of the RAM, not the browser's cache of media.