Skip to content
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

Missed bitshift optimization #39

Open
BoannWasHere opened this issue Dec 19, 2021 · 0 comments
Open

Missed bitshift optimization #39

BoannWasHere opened this issue Dec 19, 2021 · 0 comments

Comments

@BoannWasHere
Copy link

Hello! I really love how tidy and efficient FAB LED is, but I found a missed optimization in the core loops, where it loops over the individual bits of each color byte.

For example, here, in onePortSoftwareSendBytes:

const uint8_t val = array[c];
for(int8_t b=7; b>=0; b--) {
    const bool bit = (val>>b) & 0x1;

The problem is that AVR has no instruction to shift by more than 1 bit at a time, so val >> b compiles to an additional loop that executes for every bit to be sent.

The extra loop can be eliminated by changing to:

uint8_t val = array[c];
for(uint8_t b=0; b<8; b++, val <<= 1) {
    const bool bit = val & 0x80;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant