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 64 of file math8.h.

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

References LIB8STATIC_ALWAYS_INLINE.