diff options
author | Mark Kriegsman <kriegsman@tr.org> | 2017-05-29 16:09:06 +0300 |
---|---|---|
committer | Mark Kriegsman <kriegsman@tr.org> | 2017-05-29 16:09:06 +0300 |
commit | a4304e2cb817c1574ce98877a65cc24f923bb259 (patch) | |
tree | 9dea6dfe82f329ec71e34b80c3fb63bb5babd8ca | |
parent | b8f2e356de1c8bc8b28858917c401079dfbeb1d4 (diff) |
Added AVR asm version of ease8InOutQuad which is a little faster, and a little smaller than the C version; it also preserves one additional low-order bit of precision so while it may not give exactly the same numeric results as the C in all cases, it presumably gives 'better' (smoother) ones.
-rw-r--r-- | lib8tion.h | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -576,6 +576,7 @@ LIB8STATIC uint8_t map8( uint8_t in, uint8_t rangeStart, uint8_t rangeEnd) /// ease8InOutQuad: 8-bit quadratic ease-in / ease-out function /// Takes around 13 cycles on AVR +#if EASE8_C == 1 LIB8STATIC uint8_t ease8InOutQuad( uint8_t i) { uint8_t j = i; @@ -590,6 +591,35 @@ LIB8STATIC uint8_t ease8InOutQuad( uint8_t i) return jj2; } +#elif EASE8_AVRASM == 1 +// This AVR asm version of ease8InOutQuad preserves one more +// low-bit of precision than the C version, and is also slightly +// smaller and faster. +LIB8STATIC uint8_t ease8InOutQuad(uint8_t val) { + uint8_t j=val; + asm volatile ( + "sbrc %[val], 7 \n" + "com %[j] \n" + "mul %[j], %[j] \n" + "add r0, %[j] \n" + "ldi %[j], 0 \n" + "adc %[j], r1 \n" + "lsl r0 \n" // carry = high bit of low byte of mul product + "rol %[j] \n" // j = (j * 2) + carry // preserve add'l bit of precision + "sbrc %[val], 7 \n" + "com %[j] \n" + "clr __zero_reg__ \n" + : [j] "+a" (j) + : [val] "a" (val) + : "r0", "r1" + ); + return j; +} + +#else +#error "No implementation for ease8InOutQuad available." +#endif + /// ease8InOutCubic: 8-bit cubic ease-in / ease-out function /// Takes around 18 cycles on AVR |