FastLED 3.10.6
Loading...
Searching...
No Matches

◆ sincos32()

FASTLED_FORCE_INLINE SinCos32 fl::sincos32 ( u32 angle)

Definition at line 86 of file sin32.h.

86 {
87 u8 angle256 = static_cast<u8>(angle >> 16);
88 u32 t = angle & 0xFFFF;
89
90 u8 quadrant = angle256 >> 6;
91 u8 pos = angle256 & 0x3F;
92
93 // Quarter-wave mapping (same for both sin and cos)
94 u8 mirror_s = quadrant & 1;
95 u8 qi = static_cast<u8>(pos + mirror_s * (64 - 2 * pos));
96 u8 qi_next = static_cast<u8>(qi + 1 - 2 * mirror_s);
97
98 // Derivative masks: sin and cos have opposite mirror states
99 i32 sdmask = -static_cast<i32>(mirror_s);
100 i32 cdmask = ~sdmask; // opposite mirror
101
102 // Sin at offset 0, cos at offset 2 — same qi, same cache line
103 i32 s_raw = sin32_interp(qi, qi_next, sdmask, t, 0);
104 i32 c_raw = sin32_interp(qi, qi_next, cdmask, t, 2);
105
106 // Sin sign: negative in quadrants 2, 3
107 i32 svmask = -static_cast<i32>((quadrant >> 1) & 1);
108 // Cos sign: negative in quadrants 1, 2 (XOR of quadrant bits)
109 i32 cvmask = -static_cast<i32>((quadrant ^ (quadrant >> 1)) & 1);
110
111 SinCos32 out;
112 out.sin_val = (i32)(((i64)s_raw ^ svmask) - svmask);
113 out.cos_val = (i32)(((i64)c_raw ^ cvmask) - cvmask);
114 return out;
115}
uint8_t pos
Definition Blur.ino:11
unsigned char u8
Definition stdint.h:131
FASTLED_FORCE_INLINE i32 sin32_interp(u8 qi, u8 qi_next, i32 dmask, u32 t, u8 offset=0) FL_NO_EXCEPT
Definition sin32.h:38
i32 sin_val
Definition sin32.h:23
i32 cos_val
Definition sin32.h:24
fl::i64 i64
Definition stdint.h:221

References fl::SinCos32::cos_val, FASTLED_FORCE_INLINE, FL_NO_EXCEPT, pos, sin32_interp(), fl::SinCos32::sin_val, and t.

Referenced by fl::Chasing_Spirals_Q31_SIMD::draw(), render_value_fp(), fl::fixed_point_base< Derived, IntBits, FracBits >::sincos(), and fl::s16x16::sincos().

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