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

◆ qadd7()

LIB8STATIC_ALWAYS_INLINE int8_t qadd7 ( int8_t i,
int8_t j )

Add one byte to another, saturating at 0x7F and -0x80.

Parameters
ifirst byte to add
jsecond byte to add
Returns
the sum of i + j, capped at 0x7F and -0x80

Definition at line 73 of file math8.h.

73 {
74#if QADD7_C == 1
75 int16_t t = i + j;
76 if (t > 127)
77 t = 127;
78 else if (t < -128)
79 t = -128;
80 return static_cast<int8_t>(t);
81#elif QADD7_AVRASM == 1
82 asm volatile(
83 /* First, add j to i, conditioning the V and C flags */
84 "add %0, %1 \n\t"
85
86 /* Now test the V flag.
87 If V is clear, we branch to end.
88 If V is set, we go ahead and load 0x7F into i.
89 */
90 "brvc L_%= \n\t"
91 "ldi %0, 0x7F \n\t"
92
93 /* When both numbers are negative, C is set.
94 Adding it to make result negative. */
95 "adc %0, __zero_reg__\n\t"
96 "L_%=: "
97 : "+d"(i) // r16-r31, restricted by ldi
98 : "r"(j));
99 return i;
100#elif QADD7_ARM_DSP_ASM == 1
101 asm volatile("qadd8 %0, %0, %1" : "+r"(i) : "r"(j));
102 return i;
103#else
104#error "No implementation for qadd7 available."
105#endif
106}
static uint32_t t
Definition Luminova.h:54

References LIB8STATIC_ALWAYS_INLINE, and t.