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

◆ nscale8_LEAVING_R1_DIRTY()

LIB8STATIC_ALWAYS_INLINE void nscale8_LEAVING_R1_DIRTY ( uint8_t & i,
fract8 scale )

In place modifying version of scale8() that does not clean up the R1 register on AVR.

If you are doing several "scale8()'s" in a row, use this, and then explicitly call cleanup_R1().

Warning
You MUST call cleanup_R1() after using this function!
Warning
This function always modifies its arguments in place!
Parameters
iinput value to scale
scalescale factor, in n/256 units
See also
scale8()

Definition at line 217 of file scale8.h.

218 {
219#if SCALE8_C == 1
220#if (FASTLED_SCALE8_FIXED == 1)
221 i = (((uint16_t)i) * ((uint16_t)(scale) + 1)) >> 8;
222#else
223 i = ((int)i * (int)(scale)) >> 8;
224#endif
225#elif SCALE8_AVRASM == 1
226 asm volatile(
227#if (FASTLED_SCALE8_FIXED == 1)
228 // Multiply 8-bit i * 8-bit scale, giving 16-bit r1,r0
229 "mul %0, %1 \n\t"
230 // Add i to r0, possibly setting the carry flag
231 "add r0, %0 \n\t"
232 // load the immediate 0 into i (note, this does _not_ touch any flags)
233 "ldi %0, 0x00 \n\t"
234 // walk and chew gum at the same time
235 "adc %0, r1 \n\t"
236#else
237 /* Multiply 8-bit i * 8-bit scale, giving 16-bit r1,r0 */
238 "mul %0, %1 \n\t"
239 /* Move the high 8-bits of the product (r1) back to i */
240 "mov %0, r1 \n\t"
241#endif
242 /* R1 IS LEFT DIRTY HERE; YOU MUST ZERO IT OUT YOURSELF */
243 /* "clr __zero_reg__ \n\t" */
244
245 : "+d"(i) /* writes to i; r16-r31, restricted by ldi */
246 : "r"(scale) /* uses scale */
247 : "r0", "r1" /* clobbers r0, r1 */
248 );
249#else
250#error "No implementation for nscale8_LEAVING_R1_DIRTY available."
251#endif
252}
UISlider scale("Scale", 4,.1, 4,.1)

References LIB8STATIC_ALWAYS_INLINE, and scale.