ShiftRegister-PWM-Library
ShiftRegister-PWM-Library copied to clipboard
Faster `shiftOut` function
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)