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 223 of file scale8.h.

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

References LIB8STATIC_ALWAYS_INLINE, and scale.