FastLED 3.9.15
Loading...
Searching...
No Matches
perlin_i16_optimized.h
Go to the documentation of this file.
1#pragma once
2
3// 2D Perlin noise i16-optimized implementation
4// Extracted from animartrix_detail.hpp
5//
6// i16-optimized Perlin: Uses i16 for lerp/grad hot path (2x faster multiplies)
7// Coordinates stay as i32 (s16x16) externally but convert to i16 for interpolation
8
11
12namespace fl {
13
15 static constexpr int HP_BITS = 16;
16 static constexpr fl::i32 HP_ONE = static_cast<fl::i32>(1) << HP_BITS;
17
18 // Build fade LUT - still i32 for API compatibility
19 static void init_fade_lut(fl::i32 *table);
20
21 // Public API: accepts s16x16 raw values
23 const fl::i32 *fade_lut,
24 const fl::u8 *perm);
25
26 // Hot path: uses i16 arithmetic for lerp/grad after extracting fractional part
27 static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw,
28 const fl::i32 *fade_lut,
29 const fl::u8 *perm);
30
31 private:
32 static constexpr int FP_BITS = fl::s16x16::FRAC_BITS;
33 static constexpr fl::i32 FP_ONE = static_cast<fl::i32>(1) << FP_BITS;
34 // For i16 coordinates: use full 16-bit value (no room for 1.0 in i16)
35 // Coordinates are fractional parts only (0-65535), HP_ONE stays as i32
36 static constexpr fl::i32 HP_ONE_I16 = HP_ONE;
37
38 // Extract fractional part as i16 (range 0-65535)
39 static FASTLED_FORCE_INLINE void floor_frac_i16(fl::i32 fp16, int &ifloor, fl::i16 &frac16);
40
41 // Fade optimized for i16 input (coordinates), returns i32 (can be 0-65536)
42 static FASTLED_FORCE_INLINE fl::i32 fade(fl::i16 t, const fl::i32 *table);
43
44 // Standard lerp (i32), but benefits from smaller grad results
45 static FASTLED_FORCE_INLINE fl::i32 lerp(fl::i32 t, fl::i32 a, fl::i32 b);
46
47 // i16 grad: Takes i16 coordinates (faster than i32), returns i32
48 static FASTLED_FORCE_INLINE fl::i32 grad_i16(int hash, fl::i16 x, fl::i16 y);
49};
50
51} // namespace fl
static constexpr int FRAC_BITS
Definition s16x16.h:22
unsigned char u8
Definition s16x16x4.h:132
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_FORCE_INLINE
static FASTLED_FORCE_INLINE void floor_frac_i16(fl::i32 fp16, int &ifloor, fl::i16 &frac16)
static constexpr fl::i32 HP_ONE
static constexpr int HP_BITS
static constexpr fl::i32 FP_ONE
static constexpr fl::i32 HP_ONE_I16
static void init_fade_lut(fl::i32 *table)
static FASTLED_FORCE_INLINE fl::i32 grad_i16(int hash, fl::i16 x, fl::i16 y)
static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw, const fl::i32 *fade_lut, const fl::u8 *perm)
static constexpr int FP_BITS
static fl::s16x16 pnoise2d(fl::s16x16 fx, fl::s16x16 fy, const fl::i32 *fade_lut, const fl::u8 *perm)
static FASTLED_FORCE_INLINE fl::i32 lerp(fl::i32 t, fl::i32 a, fl::i32 b)
static FASTLED_FORCE_INLINE fl::i32 fade(fl::i16 t, const fl::i32 *table)