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

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

References LIB8STATIC_ALWAYS_INLINE, and scale.