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

◆ scale8_LEAVING_R1_DIRTY()

LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY ( uint8_t i,
fract8 scale )

This version of scale8() 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!
Parameters
iinput value to scale
scalescale factor, in n/256 units
Returns
scaled value
See also
scale8()

Definition at line 176 of file scale8.h.

177 {
178#if SCALE8_C == 1
179#if (FASTLED_SCALE8_FIXED == 1)
180 return (((uint16_t)i) * ((uint16_t)(scale) + 1)) >> 8;
181#else
182 return ((int)i * (int)(scale)) >> 8;
183#endif
184#elif SCALE8_AVRASM == 1
185 asm volatile(
186#if (FASTLED_SCALE8_FIXED == 1)
187 // Multiply 8-bit i * 8-bit scale, giving 16-bit r1,r0
188 "mul %0, %1 \n\t"
189 // Add i to r0, possibly setting the carry flag
190 "add r0, %0 \n\t"
191 // load the immediate 0 into i (note, this does _not_ touch any flags)
192 "ldi %0, 0x00 \n\t"
193 // walk and chew gum at the same time
194 "adc %0, r1 \n\t"
195#else
196 /* Multiply 8-bit i * 8-bit scale, giving 16-bit r1,r0 */
197 "mul %0, %1 \n\t"
198 /* Move the high 8-bits of the product (r1) back to i */
199 "mov %0, r1 \n\t"
200#endif
201 /* R1 IS LEFT DIRTY HERE; YOU MUST ZERO IT OUT YOURSELF */
202 /* "clr __zero_reg__ \n\t" */
203 : "+d"(i) /* writes to i; r16-r31, restricted by ldi */
204 : "r"(scale) /* uses scale */
205 : "r0", "r1" /* clobbers r0, r1 */
206 );
207 // Return the result
208 return i;
209#else
210#error "No implementation for scale8_LEAVING_R1_DIRTY available."
211#endif
212}
UISlider scale("Scale", 1.0f, 0.0f, 1.0f, 0.01f)

References LIB8STATIC_ALWAYS_INLINE, and scale.

Referenced by blend8(), fl::ColorFromPalette(), fl::ColorFromPalette(), fl::ColorFromPalette(), fl::ColorFromPalette(), fl::ColorFromPalette(), fl::ColorFromPalette(), fl::ColorFromPaletteExtended(), fl::ColorFromPaletteExtended(), fl::ColorFromPaletteExtended(), ease8InOutCubic(), fl::fadeUsingColor(), CRGB::getAverageLight(), CRGB::getLuma(), hsv2rgb_rainbow(), MyColorFromPaletteExtended(), fl::nblend(), fl::nblend(), nscale8x2(), and nscale8x3().

+ Here is the caller graph for this function: