FastLED 3.9.15
Loading...
Searching...
No Matches

◆ mod8()

LIB8STATIC_ALWAYS_INLINE uint8_t mod8 ( uint8_t a,
uint8_t m )

Calculate the remainder of one unsigned 8-bit value divided by anoter, aka A % M.

Implemented by repeated subtraction, which is very compact, and very fast if A is "probably" less than M. If A is a large multiple of M, the loop has to execute multiple times. However, even in that case, the loop is only two instructions long on AVR, i.e., quick.

Parameters
adividend byte
mdivisor byte
Returns
remainder of a / m (i.e. a % m)

Definition at line 361 of file math8.h.

361 {
362#if defined(__AVR__)
363 asm volatile("L_%=: sub %[a],%[m] \n\t"
364 " brcc L_%= \n\t"
365 " add %[a],%[m] \n\t"
366 : [a] "+r"(a)
367 : [m] "r"(m));
368#else
369 while (a >= m)
370 a -= m;
371#endif
372 return a;
373}

References LIB8STATIC_ALWAYS_INLINE.