Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kriegsman <kriegsman@tr.org>2016-01-07 23:23:03 +0300
committerMark Kriegsman <kriegsman@tr.org>2016-01-07 23:23:03 +0300
commit3a8bb4c09bac0bbfb13cbc749e83396d417d0ccc (patch)
tree731c9f3b4b517ba351657f310c82174091a0b166
parent2e48c08b24bf56e969145318c1bf7b04333d1953 (diff)
3% speedup in noise on AVR by eliminating a shift-loop. Math is identical, output results tested and found identical in every case tested.
-rw-r--r--noise.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/noise.cpp b/noise.cpp
index 49aa6e7c..72b0211f 100644
--- a/noise.cpp
+++ b/noise.cpp
@@ -297,7 +297,13 @@ uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z) {
int32_t ans = inoise16_raw(x,y,z);
ans = ans + 19052L;
uint32_t pan = ans;
- return (pan*220L)>>7;
+ // pan = (ans * 220L) >> 7. That's the same as:
+ // pan = (ans * 440L) >> 8. And this way avoids a 7X four-byte shift-loop on AVR.
+ // Identical math, except for the highest bit, which we don't care about anyway,
+ // since we're returning the 'middle' 16 out of a 32-bit value anyway.
+ pan *= 440L;
+ return (pan>>8);
+
// // return scale16by8(pan,220)<<1;
// return ((inoise16_raw(x,y,z)+19052)*220)>>7;
// return scale16by8(inoise16_raw(x,y,z)+19052,220)<<1;
@@ -340,7 +346,13 @@ uint16_t inoise16(uint32_t x, uint32_t y) {
int32_t ans = inoise16_raw(x,y);
ans = ans + 17308L;
uint32_t pan = ans;
- return (pan*242L)>>7;
+ // pan = (ans * 242L) >> 7. That's the same as:
+ // pan = (ans * 484L) >> 8. And this way avoids a 7X four-byte shift-loop on AVR.
+ // Identical math, except for the highest bit, which we don't care about anyway,
+ // since we're returning the 'middle' 16 out of a 32-bit value anyway.
+ pan *= 484L;
+ return (pan>>8);
+
// return (uint32_t)(((int32_t)inoise16_raw(x,y)+(uint32_t)17308)*242)>>7;
// return scale16by8(inoise16_raw(x,y)+17308,242)<<1;
}