FastLED 3.10.8
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#include "fl/stl/noexcept.h"
12
13namespace fl {
14
16 static constexpr int HP_BITS = 16;
17 static constexpr fl::i32 HP_ONE = static_cast<fl::i32>(1) << HP_BITS;
18
19 // Build fade LUT - still i32 for API compatibility
20 static void init_fade_lut(fl::i32 *table) FL_NO_EXCEPT;
21
22 // Public API: accepts s16x16 raw values
24 const fl::i32 *fade_lut,
25 const fl::u8 *perm) FL_NO_EXCEPT;
26
27 // Hot path: uses i16 arithmetic for lerp/grad after extracting fractional part
28 static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw,
29 const fl::i32 *fade_lut,
30 const fl::u8 *perm) FL_NO_EXCEPT;
31
32 private:
33 static constexpr int FP_BITS = fl::s16x16::FRAC_BITS;
34 static constexpr fl::i32 FP_ONE = static_cast<fl::i32>(1) << FP_BITS;
35 // For i16 coordinates: use full 16-bit value (no room for 1.0 in i16)
36 // Coordinates are fractional parts only (0-65535), HP_ONE stays as i32
37 static constexpr fl::i32 HP_ONE_I16 = HP_ONE;
38
39 // Extract fractional part as i16 (range 0-65535)
40 static FASTLED_FORCE_INLINE void floor_frac_i16(fl::i32 fp16, int &ifloor, fl::i16 &frac16) FL_NO_EXCEPT;
41
42 // Fade optimized for i16 input (coordinates), returns i32 (can be 0-65536)
43 static FASTLED_FORCE_INLINE fl::i32 fade(fl::i16 t, const fl::i32 *table) FL_NO_EXCEPT;
44
45 // Standard lerp (i32), but benefits from smaller grad results
46 static FASTLED_FORCE_INLINE fl::i32 lerp(fl::i32 t, fl::i32 a, fl::i32 b) FL_NO_EXCEPT;
47
48 // i16 grad: Takes i16 coordinates (faster than i32), returns i32
49 static FASTLED_FORCE_INLINE fl::i32 grad_i16(int hash, fl::i16 x, fl::i16 y) FL_NO_EXCEPT;
50};
51
52} // namespace fl
static constexpr int FRAC_BITS
Definition s16x16.h:24
#define FASTLED_FORCE_INLINE
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
static FASTLED_FORCE_INLINE fl::i32 lerp(fl::i32 t, fl::i32 a, fl::i32 b) FL_NO_EXCEPT
static void init_fade_lut(fl::i32 *table) FL_NO_EXCEPT
static constexpr fl::i32 HP_ONE
static FASTLED_FORCE_INLINE void floor_frac_i16(fl::i32 fp16, int &ifloor, fl::i16 &frac16) FL_NO_EXCEPT
static constexpr int HP_BITS
static constexpr fl::i32 FP_ONE
static constexpr fl::i32 HP_ONE_I16
static FASTLED_FORCE_INLINE fl::i32 grad_i16(int hash, fl::i16 x, fl::i16 y) FL_NO_EXCEPT
static constexpr int FP_BITS
static FASTLED_FORCE_INLINE fl::i32 fade(fl::i16 t, const fl::i32 *table) FL_NO_EXCEPT
static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw, const fl::i32 *fade_lut, const fl::u8 *perm) FL_NO_EXCEPT
static fl::s16x16 pnoise2d(fl::s16x16 fx, fl::s16x16 fy, const fl::i32 *fade_lut, const fl::u8 *perm) FL_NO_EXCEPT