-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Circular buffer should use conditional statement instead of modulo #7890
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AStyle CI review (fix needed)
9f3b838
to
4e263b1
Compare
@SenRamakri @geky - Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
...huh. Kinda surprised to find that we're using modulo, since I would expect masking arythmetic to be used for this kind of rollover. Still, an /morph build |
Build : SUCCESSBuild number : 3158 Triggering tests/morph test |
Exporter Build : FAILUREBuild number : 2762 |
Test : SUCCESSBuild number : 2969 |
In this case BufferSize is a compile-time constant (template). So the compiler can trivially turn it into a mask when it's a power of 2. |
Wow. It's been a while since we last saw something like this. /morph export |
Gotcha. Is the compiler still able to do the optimization with this PR change? |
Nope: https://godbolt.org/z/aYf-MO Though note how much worse it gets when you change SIZE to a non-power of two. Note that is we really wanted to, we could have a template specialization for powers of two, and a template specialization for non-powers of two. But this may take much much more effort than it's really worth. |
@cmonr No the compiler doesn't apply the optimisation: https://godbolt.org/z/yEKolO . Edit: As @geky pointed out there's performance salvation with partial specialisation however it'll be maintenance hell for uninitiated programmers. |
/morph export-build |
Exporter Build : SUCCESSBuild number : 2776 |
Description
platform
folderPull request type