FastLED 3.9.15
Loading...
Searching...
No Matches
SIMD.ino
Go to the documentation of this file.
1// @filter: (memory is large)
2//
3// examples/SIMD/SIMD.ino
4//
5// FastLED SIMD Operations Test Suite
6//
7// This sketch validates all SIMD operations provided by fl::simd namespace.
8// Tests are executed sequentially with pass/fail tracking and a summary report.
9//
10// DEMONSTRATES:
11// 1. SIMD load/store operations (u8x16, u32x4, f32x4)
12// 2. SIMD arithmetic operations (add, sub, scale, blend)
13// 3. SIMD comparison operations (min, max, avg)
14// 4. SIMD bitwise operations (and, or, xor, andnot)
15// 5. SIMD floating-point operations (add, sub, mul, div, sqrt, min, max)
16//
17// Platform Support:
18// - All platforms (uses platform-specific SIMD when available, scalar fallback otherwise)
19//
20// Expected Output:
21// Serial monitor will show:
22// - Individual test results (PASS/FAIL) for each SIMD operation
23// - Error details for any failed tests
24// - Final summary table with pass/fail counts
25// - Overall PASS/FAIL banner
26//
27// ============================================================================
28// AGENT INSTRUCTIONS
29// ============================================================================
30// This sketch is a validation test that uses the "ERROR" keyword in FL_ERROR
31// statements to signal test failures. The `bash debug` command monitors for
32// the "ERROR" keyword and fails the test when detected (exit code 1).
33//
34// 🚫 DO NOT "CHEAT" THE TEST:
35// - DO NOT change "ERROR" to "FAIL", "WARNING", "FAILURE", or any other
36// keyword to avoid test detection
37// - DO NOT modify FL_ERROR statements unless explicitly requested by the user
38// - The "ERROR" keyword is INTENTIONAL and part of the validation contract
39//
40// āœ… VALID MODIFICATIONS (only if explicitly requested):
41// - User asks: "Change the error message format"
42// - User asks: "Use a different warning macro"
43// - User asks: "Remove the ERROR prefix"
44//
45// āŒ INVALID MODIFICATIONS (considered "cheating"):
46// - Changing "ERROR" to avoid `bash debug --fail-on ERROR` detection
47// - Renaming to bypass automated test failure detection
48// - Any modification that circumvents the validation contract
49//
50// If the test is failing, investigate and FIX THE ACTUAL BUG that causes
51// the "ERROR" message to be printed. Do not hide the symptom by changing
52// the error message keyword.
53// ============================================================================
54
55#include <FastLED.h>
56#include "fl/math/simd.h"
57#include "fl/log/log.h"
58
59// Test framework headers
60#include "test_result.h"
61#include "test_helpers.h"
62#include "simd_tests.h"
63
64using namespace simd_test;
65
66// ============================================================================
67// Global Test State
68// ============================================================================
69
70// Test results storage
72
73// Test statistics
77
78// ============================================================================
79// Main Setup and Loop
80// ============================================================================
81
82void setup() {
83 Serial.begin(115200);
84 delay(2000);
85
86 fl::sstream ss;
87 ss << "\n╔════════════════════════════════════════════════════════════════╗\n";
88 ss << "ā•‘ FastLED SIMD Operations Test Suite ā•‘\n";
89 ss << "ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•\n";
90 FL_PRINT(ss.str());
91
92 FL_PRINT("\nStarting SIMD operation tests...\n");
93
94 // ========================================================================
95 // Load/Store Tests
96 // ========================================================================
97 FL_PRINT("\n[CATEGORY] Load/Store Operations");
98 FL_PRINT("────────────────────────────────────────────────────────────────");
99
103
104 // ========================================================================
105 // Arithmetic Tests
106 // ========================================================================
107 FL_PRINT("\n[CATEGORY] Arithmetic Operations");
108 FL_PRINT("────────────────────────────────────────────────────────────────");
109
114
115 // ========================================================================
116 // Comparison Tests
117 // ========================================================================
118 FL_PRINT("\n[CATEGORY] Comparison Operations");
119 FL_PRINT("────────────────────────────────────────────────────────────────");
120
125
126 // ========================================================================
127 // Bitwise Tests
128 // ========================================================================
129 FL_PRINT("\n[CATEGORY] Bitwise Operations");
130 FL_PRINT("────────────────────────────────────────────────────────────────");
131
136
137 // ========================================================================
138 // Broadcast Tests
139 // ========================================================================
140 FL_PRINT("\n[CATEGORY] Broadcast Operations");
141 FL_PRINT("────────────────────────────────────────────────────────────────");
142
145
146 // ========================================================================
147 // Float Tests
148 // ========================================================================
149 FL_PRINT("\n[CATEGORY] Floating Point Operations");
150 FL_PRINT("────────────────────────────────────────────────────────────────");
151
159
160 // ========================================================================
161 // Print Summary
162 // ========================================================================
165
166 // Signal completion
167 if (failed_tests == 0) {
168 FL_PRINT("\nSIMD_TEST_SUITE_COMPLETE");
169 } else {
170 fl::sstream err;
171 err << "\nSIMD test suite failed with " << failed_tests << " error(s)";
172 FL_ERROR(err.str().c_str());
173 }
174}
175
176// Test runs once flag
177static bool tests_run = false;
178
179void loop() {
180 // Run tests only once
181 if (tests_run) {
182 delay(1000);
183 return;
184 }
185
186 tests_run = true;
187 FL_PRINT("SIMD test suite complete");
188}
static bool tests_run
Definition SIMD.ino:177
void setup()
Definition SIMD.ino:82
int passed_tests
Definition SIMD.ino:75
int failed_tests
Definition SIMD.ino:76
int total_tests
Definition SIMD.ino:74
fl::vector< TestResult > test_results
Definition SIMD.ino:71
void loop()
Definition SIMD.ino:179
const char * c_str() const FL_NOEXCEPT
string str() const FL_NOEXCEPT
Definition strstream.h:43
#define FL_ERROR(X)
Definition log.h:219
#define FL_PRINT(X)
Print without prefix (like FL_WARN but without "WARN: " prefix) Uses sstream for dynamic formatting (...
Definition log.h:457
Centralized logging categories for FastLED hardware interfaces and subsystems.
void test_load_store_f32_4(TestResult &result)
void test_load_store_u8_16(TestResult &result)
void test_or_u8_16(TestResult &result)
void test_set1_u32_4(TestResult &result)
void test_add_sat_u8_16(TestResult &result)
void test_avg_u8_16(TestResult &result)
void test_load_store_u32_4(TestResult &result)
void test_min_f32_4(TestResult &result)
void test_and_u8_16(TestResult &result)
void run_test(const char *test_name, TestFunc test_func, fl::vector< TestResult > &results, int &total_tests, int &passed_tests, int &failed_tests)
Run a single test and record result.
void test_max_f32_4(TestResult &result)
void test_set1_f32_4(TestResult &result)
void test_min_u8_16(TestResult &result)
void test_mul_f32_4(TestResult &result)
void print_final_banner(int failed_tests)
Print final result banner (PASS/FAIL)
void test_sub_sat_u8_16(TestResult &result)
void test_add_f32_4(TestResult &result)
void test_div_f32_4(TestResult &result)
void test_xor_u8_16(TestResult &result)
void test_sub_f32_4(TestResult &result)
void test_scale_u8_16(TestResult &result)
void test_max_u8_16(TestResult &result)
void test_avg_round_u8_16(TestResult &result)
void test_blend_u8_16(TestResult &result)
void print_summary(const fl::vector< TestResult > &test_results, int total_tests, int passed_tests, int failed_tests)
Print summary table of all test results.
void test_andnot_u8_16(TestResult &result)
void test_sqrt_f32_4(TestResult &result)
Umbrella header for SIMD subsystem.
#define Serial
Definition serial.h:304