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

◆ qmul8()

LIB8STATIC_ALWAYS_INLINE uint8_t qmul8 ( uint8_t i,
uint8_t j )

8x8 bit multiplication with 8-bit result, saturating at 0xFF.

Parameters
ifirst byte to multiply
jsecond byte to multiply
Returns
the product of i * j, capping at 0xFF

Definition at line 486 of file math8.h.

486 {
487#if QMUL8_C == 1
488 unsigned p = (unsigned)i * (unsigned)j;
489 if (p > 255)
490 p = 255;
491 return p;
492#elif QMUL8_AVRASM == 1
493 asm volatile(
494 /* Multiply 8-bit i * 8-bit j, giving 16-bit r1,r0 */
495 " mul %0, %1 \n\t"
496 /* Extract the LOW 8-bits (r0) */
497 " mov %0, r0 \n\t"
498 /* If high byte of result is zero, all is well. */
499 " tst r1 \n\t"
500 " breq Lnospill_%= \n\t"
501 /* If high byte of result > 0, saturate to 0xFF */
502 " ldi %0, 0xFF \n\t"
503 "Lnospill_%=: \n\t"
504 /* Restore r1 to "0"; it's expected to always be that */
505 " clr __zero_reg__ \n\t"
506 : "+d"(i) // r16-r31, restricted by ldi
507 : "r"(j)
508 : "r0", "r1");
509 return i;
510#else
511#error "No implementation for qmul8 available."
512#endif
513}

References LIB8STATIC_ALWAYS_INLINE.

Referenced by operator*().

+ Here is the caller graph for this function: