FastLED 3.10.8
Loading...
Searching...
No Matches

◆ FASTLED_DEFINE_POD_COMPARISON_OPERATOR

#define FASTLED_DEFINE_POD_COMPARISON_OPERATOR ( CLASS,
OP )
Value:
template <typename T, typename U> \
typename enable_if< \
is_same<U, CLASS>::value && is_pod<T>::value, bool>::type \
operator OP(const T &pod, const CLASS &obj) FL_NO_EXCEPT { \
return pod OP obj; \
} \
template <typename T> \
typename enable_if<is_pod<T>::value, bool>::type operator OP( \
const CLASS &obj, const T &pod) FL_NO_EXCEPT { \
return obj OP pod; \
}
#define FL_NO_EXCEPT

Definition at line 1033 of file s16x16x4.h.

1033#pragma once
1034
1037
1038#include "fl/math/simd.h"
1040#include "fl/math/sin32_simd.h"
1042#include "fl/stl/align.h"
1043// Pulled in at file scope, not through simd_ops.h below: that include sits
1044// inside `namespace fl`, so reaching s0x32x4.h through it nests the whole
1045// header -- and everything it includes -- one namespace too deep.
1047
1048namespace fl {
1049
1050// Forward declaration for cross-type operations
1051struct s0x32x4;
1052
1055struct s16x16x4 {
1056 simd::simd_u32x4 raw; // 4× i32 values in Q16 format
1057
1058 // ---- Construction ------------------------------------------------------
1059
1061 s16x16x4 result;
1062 result.raw = r;
1063 return result;
1064 }
1065
1066 // Load 4 s16x16 values from memory (unaligned access supported)
1067 static FASTLED_FORCE_INLINE s16x16x4 load(const s16x16* ptr) {
1068 return from_raw(simd::platforms::load_u32_4(reinterpret_cast<const u32*>(ptr))); // ok reinterpret cast
1069 }
1070
1071 // Store 4 s16x16 values to memory (unaligned access supported)
1072 FASTLED_FORCE_INLINE void store(s16x16* ptr) const {
1073 simd::platforms::store_u32_4(reinterpret_cast<u32*>(ptr), raw); // ok reinterpret cast
1074 }
1075
1076 // Broadcast single s16x16 value to all 4 lanes
1077 static FASTLED_FORCE_INLINE s16x16x4 set1(s16x16 value) {
1078 return from_raw(simd::platforms::set1_u32_4(static_cast<u32>(value.raw())));
1079 }
1080
1081 // ---- SIMD arithmetic (s16x16x4 OP s16x16x4 → s16x16x4) -----------------
1082
1083 FASTLED_FORCE_INLINE s16x16x4 operator+(s16x16x4 b) const {
1084 return from_raw(simd::add_i32_4(raw, b.raw));
1085 }
1086
1087 FASTLED_FORCE_INLINE s16x16x4 operator-(s16x16x4 b) const {
1088 return from_raw(simd::sub_i32_4(raw, b.raw));
1089 }
1090
1091 FASTLED_FORCE_INLINE s16x16x4 operator*(s16x16x4 b) const {
1092 // Q16 × Q16 = Q32 → shift right 16 → Q16
1093 return from_raw(simd::mulhi_i32_4(raw, b.raw));
1094 }
1095
1096 FASTLED_FORCE_INLINE s16x16x4 operator-() const {
1097 // Unary negation: -x = 0 - x
1098 auto zero = simd::set1_u32_4(0);
1099 return from_raw(simd::sub_i32_4(zero, raw));
1100 }
1101
1102 FASTLED_FORCE_INLINE s16x16x4 operator>>(int shift) const {
1103 return from_raw(simd::sra_i32_4(raw, shift));
1104 }
1105
1106 FASTLED_FORCE_INLINE s16x16x4 operator<<(int shift) const {
1107 return from_raw(simd::sll_u32_4(raw, shift));
1108 }
1109
1110 // Cross-type multiply: s16x16x4 × s0x32x4 → s16x16x4 (commutative)
1111 // Implemented after s0x32x4 is defined
1112 FASTLED_FORCE_INLINE s16x16x4 operator*(s0x32x4 b) const;
1113
1114 // ---- Math functions -------------------------------------------------------
1115
1117 FASTLED_FORCE_INLINE s16x16x4 abs() const {
1118 // mask = -1 if negative (sign extended), 0 if positive
1119 auto mask = simd::sra_i32_4(raw, 31);
1120 // flip bits if negative, then add 1 (two's complement)
1121 auto flipped = simd::xor_u32_4(raw, mask);
1122 return from_raw(simd::sub_i32_4(flipped, mask));
1123 }
1124
1126 FASTLED_FORCE_INLINE s16x16x4 min(s16x16x4 b) const {
1127 return from_raw(simd::min_i32_4(raw, b.raw));
1128 }
1129
1131 FASTLED_FORCE_INLINE s16x16x4 max(s16x16x4 b) const {
1132 return from_raw(simd::max_i32_4(raw, b.raw));
1133 }
1134
1136 FASTLED_FORCE_INLINE s16x16x4 clamp(s16x16x4 lo, s16x16x4 hi) const {
1137 return max(lo).min(hi);
1138 }
1139
1142 FASTLED_FORCE_INLINE s16x16x4 lerp(s16x16x4 b, s16x16 t) const {
1143 auto t_vec = s16x16x4::set1(t);
1144 auto diff = b - (*this);
1145 return (*this) + (diff * t_vec);
1146 }
1147
1150 FASTLED_FORCE_INLINE void sincos(s16x16x4& out_sin, s16x16x4& out_cos) const {
1151 // Convert radians to 24-bit angle units (same as scalar s16x16)
1152 // RAD_TO_24 = 2^24 / (2π) in Q16
1153 static constexpr i32 RAD_TO_24 = 2670177; // from s16x16.h
1154
1155 // Convert 4 angles: mulhi_i32_4 does (i64*i64) >> 16
1156 auto angles_u32 = simd::mulhi_su32_4(raw, simd::set1_u32_4(static_cast<u32>(RAD_TO_24)));
1157
1158 // Call vectorized sincos
1159 auto sc = sincos32_simd(angles_u32);
1160
1161 // Shift results right by 15 to convert from raw sin32 output to Q16.16
1162 out_sin = from_raw(simd::sra_i32_4(sc.sin_vals, 15));
1163 out_cos = from_raw(simd::sra_i32_4(sc.cos_vals, 15));
1164 }
1165
1167 FASTLED_FORCE_INLINE s16x16x4 sin() const {
1168 s16x16x4 sin_out, cos_out;
1169 sincos(sin_out, cos_out);
1170 return sin_out;
1171 }
1172
1174 FASTLED_FORCE_INLINE s16x16x4 cos() const {
1175 s16x16x4 sin_out, cos_out;
1176 sincos(sin_out, cos_out);
1177 return cos_out;
1178 }
1179};
1180
1181// Include simd_ops.h to implement cross-type operations
1182// Must come after all types are defined
1183#include "fl/math/fixed_point/simd_ops.h" // allow-include-after-namespace
1184
1185} // namespace fl
Alignment macros and utilities for FastLED.
platforms::simd_u32x4 simd_u32x4
Definition types.h:26
constexpr int type_rank< T >::value
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
FASTLED_FORCE_INLINE SinCos32_simd sincos32_simd(simd::simd_u32x4 angles) FL_NO_EXCEPT
Process 4 angles simultaneously, returning vectorized sin/cos values SIMD-optimized: vectorized angle...
Definition sin32_simd.h:32
Base definition for an LED controller.
SIMD 4-wide s0x32 fixed-point vector type.
#define FASTLED_FORCE_INLINE
Umbrella header for SIMD subsystem.
Cross-type SIMD fixed-point operations (implemented after all types are defined)
Four-lane SIMD batch of fl::sincos32.
4-wide s0x32 vector (normalized values [-1, 1]) Backed by 128-bit SIMD register (4× i32 in Q31 format...
Definition s0x32x4.h:17
FASTLED_FORCE_INLINE s16x16x4 min(s16x16x4 b) const
Element-wise minimum.
Definition s16x16x4.h:94
FASTLED_FORCE_INLINE s16x16x4 clamp(s16x16x4 lo, s16x16x4 hi) const
Clamp to [lo, hi].
Definition s16x16x4.h:104
FASTLED_FORCE_INLINE s16x16x4 cos() const
Compute cosine of 4 angles (in radians)
Definition s16x16x4.h:142
FASTLED_FORCE_INLINE s16x16x4 operator-() const
Definition s16x16x4.h:64
FASTLED_FORCE_INLINE s16x16x4 operator*(s16x16x4 b) const
Definition s16x16x4.h:59
FASTLED_FORCE_INLINE void store(s16x16 *ptr) const
Definition s16x16x4.h:40
FASTLED_FORCE_INLINE void sincos(s16x16x4 &out_sin, s16x16x4 &out_cos) const
Compute sin and cos of 4 angles (in radians) Results written to out_sin and out_cos.
Definition s16x16x4.h:118
FASTLED_FORCE_INLINE s16x16x4 sin() const
Compute sine of 4 angles (in radians)
Definition s16x16x4.h:135
FASTLED_FORCE_INLINE s16x16x4 abs() const
Absolute value: branchless via mask and xor.
Definition s16x16x4.h:85
FASTLED_FORCE_INLINE s16x16x4 operator>>(int shift) const
Definition s16x16x4.h:70
static FASTLED_FORCE_INLINE s16x16x4 from_raw(simd::simd_u32x4 r)
Definition s16x16x4.h:28
FASTLED_FORCE_INLINE s16x16x4 operator<<(int shift) const
Definition s16x16x4.h:74
simd::simd_u32x4 raw
Definition s16x16x4.h:24
FASTLED_FORCE_INLINE s16x16x4 max(s16x16x4 b) const
Element-wise maximum.
Definition s16x16x4.h:99
static FASTLED_FORCE_INLINE s16x16x4 load(const s16x16 *ptr)
Definition s16x16x4.h:35
static FASTLED_FORCE_INLINE s16x16x4 set1(s16x16 value)
Definition s16x16x4.h:45
FASTLED_FORCE_INLINE s16x16x4 lerp(s16x16x4 b, s16x16 t) const
Linear interpolation: a + (b - a) * t (using Q16 multiply) t: s16x16 interpolation factor in [0,...
Definition s16x16x4.h:110
FASTLED_FORCE_INLINE s16x16x4 operator+(s16x16x4 b) const
Definition s16x16x4.h:51
4-wide s16x16 vector (general fixed-point) Backed by 128-bit SIMD register (4× i32 in Q16 format)
Definition s16x16x4.h:23