Skip to content

Faster shiftOut function #7

Description

@knothed

Your optimized version of the shiftOut function uses 8 conditional branches.
It should be possible to write a faster version without if-branches. Something like this should work (not tested):

inline void shiftOut(uint8_t data) const
{
  // unrolled for loop
  // bit 0 (LSB)
  ShiftRegisterPWM_setDataPin(data & 0B00000001);
  ShiftRegisterPWM_toggleClockPinTwice();
  ...
}

where

// val must be 0 or 1
#define ShiftRegisterPWM_setDataPin(val)
  ShiftRegisterPWM_DATA_PORT = (ShiftRegisterPWM_DATA_PORT | ((-(val)) & ShiftRegisterPWM_DATA_MASK)) & ((-(val)) | ~ShiftRegisterPWM_DATA_MASK)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions