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

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

References LIB8STATIC_ALWAYS_INLINE, and scale.

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

+ Here is the caller graph for this function: