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

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

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: