FastLED 3.9.15
Loading...
Searching...
No Matches

◆ runPerlinBenchmark()

PerlinBenchResult autoresearch::animartrix_check::runPerlinBenchmark ( int iters)
inline

Definition at line 44 of file AutoResearchAnimartrixBench.h.

44 {
46 r.iterations = iters;
47
48 // Init the i16 implementation's fade lookup table once, off the
49 // benchmark clock. Function-local static so the linter's
50 // static-in-header rule stays happy and C++11's thread-safe init
51 // guarantees a single initialization across calls. The float path
52 // has no equivalent setup.
53 struct FadeLut {
54 int32_t table[257];
55 FadeLut() { fl::perlin_i16_optimized::init_fade_lut(table); }
56 };
57 static const FadeLut fade_lut_holder; // C++11 magic statics
58 const int32_t* fade_lut = fade_lut_holder.table;
59
60 constexpr int GRID = 16; // 16x16 pixel pass per iteration
61 constexpr float STEP_F = 0.05f; // Animartrix-typical pixel step in noise space
62 // Mirror in fixed-point: 0.05 in Q16.16 = 0.05 * 65536 ≈ 3277
63 constexpr int32_t STEP_I = static_cast<int32_t>(0.05f * 65536.0f);
64
65 // ── Float pnoise ──────────────────────────────────────────────
66 {
67 float ax = 0.0f, ay = 0.0f;
68 int32_t sink = 0;
69 uint32_t t0 = micros();
70 for (int it = 0; it < iters; it++) {
71 // Slowly drift the origin across the iter so the compiler
72 // can't pre-compute. Same pattern Animartrix uses (the
73 // origin advances with `time_speed * dt` each frame).
74 ax += 0.011f;
75 ay += 0.013f;
76 for (int row = 0; row < GRID; row++) {
77 float y = ay + row * STEP_F;
78 for (int col = 0; col < GRID; col++) {
79 float x = ax + col * STEP_F;
80 float n = fl::pnoise(x, y, 0.0f);
81 // Map [-1, 1] → int8 the way Animartrix's output
82 // stage does. Sink to defeat DCE.
83 sink += static_cast<int32_t>(n * 127.0f);
84 }
85 }
86 }
87 uint32_t t1 = micros();
89 r.pnoise_float_us = static_cast<int64_t>(t1 - t0);
90 }
91
92 // ── i16 fixed-point pnoise2d ──────────────────────────────────
93 {
94 int32_t ax_i = 0, ay_i = 0;
95 // Q16.16 increment for the slow drift (matches 0.011, 0.013 in float)
96 constexpr int32_t DRIFT_X = static_cast<int32_t>(0.011f * 65536.0f);
97 constexpr int32_t DRIFT_Y = static_cast<int32_t>(0.013f * 65536.0f);
98 int32_t sink = 0;
99 uint32_t t0 = micros();
100 for (int it = 0; it < iters; it++) {
101 ax_i += DRIFT_X;
102 ay_i += DRIFT_Y;
103 for (int row = 0; row < GRID; row++) {
104 int32_t y_i = ay_i + row * STEP_I;
105 for (int col = 0; col < GRID; col++) {
106 int32_t x_i = ax_i + col * STEP_I;
107 // pnoise2d_raw returns i32 Q16.16. Scale to int8
108 // the same way the float path does — divide by
109 // (HP_ONE / 127) so the magnitudes line up.
111 x_i, y_i, fade_lut, fl::PERLIN_NOISE);
112 sink += n >> 9; // crude scale; the actual op cost,
113 // not the value, is what we measure
114 }
115 }
116 }
117 uint32_t t1 = micros();
119 r.pnoise_i16_us = static_cast<int64_t>(t1 - t0);
120 }
121
122 return r;
123}
int y
Definition simple.h:93
int x
Definition simple.h:92
static volatile int32_t g_animartrix_bench_sink
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::u32 micros()
Universal microsecond timer - returns microseconds since system startup.
fl::i32 int32_t
Definition s16x16x4.h:220
FASTLED_FORCE_INLINE float pnoise(float x, float y, float z)
static void init_fade_lut(fl::i32 *table)
static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw, const fl::i32 *fade_lut, const fl::u8 *perm)

References g_animartrix_bench_sink, fl::perlin_i16_optimized::init_fade_lut(), autoresearch::animartrix_check::PerlinBenchResult::iterations, fl::pnoise(), fl::perlin_i16_optimized::pnoise2d_raw(), autoresearch::animartrix_check::PerlinBenchResult::pnoise_float_us, autoresearch::animartrix_check::PerlinBenchResult::pnoise_i16_us, x, and y.

Referenced by AutoResearchRemoteControl::registerFunctions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: