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
-
i | input value to scale |
scale | scale 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
239 "mul %0, %1 \n\t"
240
241 "add r0, %0 \n\t"
242
243 "ldi %0, 0x00 \n\t"
244
245 "adc %0, r1 \n\t"
246#else
247
248 "mul %0, %1 \n\t"
249
250 "mov %0, r1 \n\t"
251#endif
252
253
254
255 : "+d"(i)
257 : "r0", "r1"
258 );
259#else
260#error "No implementation for nscale8_LEAVING_R1_DIRTY available."
261#endif
262}
References LIB8STATIC_ALWAYS_INLINE, and scale.