Skip to content

Commit 6990cdc

Browse files
authored
chore(mp3): make minimp3 the sole backend and delete libhelix (#4056) (#4112)
Phase 5 / G5 of FastLED/license#14. `src/third_party/libhelix_mp3/` is deleted -- 10,566 deletions -- and with it the RPSL/RCSL licence obligations that were the reason for the tracker. FastLED's MP3 support is now entirely CC0. minimp3.h now decodes in fixed point unless a translation unit asks for `MINIMP3_FLOAT_POINT`. Float remains as the reference build the fixed-vs-float gates compare against, not a production configuration. Because the default changed, every audit and probe TU pins its variant explicitly rather than inheriting it -- an unpinned TU would silently measure one decoder against the other's baselines. `MINIMP3_FIXED_POINT` together with `MINIMP3_FLOAT_POINT` is a hard #error, and the header releases the default it sets for itself at the end of every inclusion so the pin cannot be defeated by include order. The three tests that compared two backends were rewritten around the property each protected: per-frame metadata checked against the ISO 11172-3 / 13818-3 samples-per-frame rule; resync proven by sample-identical output against the clean decode; the limited-accuracy floor kept against its ISO reference vector. Validation: 287/287 unit tests and 84/84 host examples, quick and --debug; memory ledger PASS with every figure byte-identical after the row swap; CPU audit operation counts identical to baseline across 892 frames; 1,098 Python tests. Also fixes three pre-existing CI defects found on the way: `Board.__post_init__` ignored `add_board_to_all`, so every `create_board` call permanently grew `ci.boards.ALL`; `MultipleEsp32SpiBuses.ino` had no `@filter`; and the watermark rig leaked its allocations on an error path that feeds a Massif measurement. `FASTLED.patch` was stale and is regenerated against upstream ea99364, with a verified regeneration procedure recorded in PROVENANCE. Carve-out: #4110 re-baselines the CPU trend onto the fixed-point build. Closes #4056 Refs FastLED/license#14, #4054, #4055, #4110
1 parent 37c401a commit 6990cdc

64 files changed

Lines changed: 614 additions & 10583 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/CODEOWNERS‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Ownership for the MP3 decoder and the evidence that gates it.
2+
#
3+
# FastLED/FastLED#4056 (Phase 5 of FastLED/license#14) made minimp3 the sole MP3
4+
# backend and deleted the RPSL/RCSL-licensed Helix tree. The decoder's
5+
# correctness, memory and CPU claims now rest entirely on the audits and ledgers
6+
# listed here, so a change to any of them is a change to the licensing and
7+
# quality argument -- not just to code.
8+
9+
/src/third_party/minimp3/ @zackees
10+
/src/fl/codec/mp3.h @zackees
11+
/src/fl/codec/mp3.cpp.hpp @zackees
12+
/src/fl/codec/mp3_memory.h @zackees
13+
/tests/fl/codec/mp3.hpp @zackees
14+
/tests/fl/codec/mp3_fixed_point.hpp @zackees
15+
/tests/fl/codec/minimp3_variants.hpp @zackees
16+
/tests/profile/mp3_memory_audit.cpp @zackees
17+
/ci/codec_memory/ @zackees
18+
/ci/codec_cpu/ @zackees
19+
/ci/codec_tables/ @zackees
20+
/codec_memory_ledger.md @zackees
21+
/codec_cpu_trend.json @zackees
22+
/.github/workflows/mp3_memory_audit.yml @zackees
23+
/.github/workflows/mp3_cpu_audit.yml @zackees

‎.github/workflows/mp3_cpu_audit.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
branches: [master]
1010
paths:
1111
- 'src/fl/codec/mp3*'
12-
- 'src/third_party/libhelix_mp3/**'
1312
- 'src/third_party/minimp3/**'
1413
- 'ci/codec_tables/**'
1514
- 'tests/fl/codec/mp3*'
@@ -25,7 +24,6 @@ on:
2524
branches: [master]
2625
paths:
2726
- 'src/fl/codec/mp3*'
28-
- 'src/third_party/libhelix_mp3/**'
2927
- 'src/third_party/minimp3/**'
3028
- 'ci/codec_tables/**'
3129
- 'tests/fl/codec/mp3*'

‎.github/workflows/mp3_memory_audit.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
branches: [master]
1010
paths:
1111
- 'src/fl/codec/mp3*'
12-
- 'src/third_party/libhelix_mp3/**'
1312
- 'src/third_party/minimp3/**'
1413
- 'ci/codec_tables/**'
1514
- 'tests/fl/codec/mp3*'
@@ -22,7 +21,6 @@ on:
2221
branches: [master]
2322
paths:
2423
- 'src/fl/codec/mp3*'
25-
- 'src/third_party/libhelix_mp3/**'
2624
- 'src/third_party/minimp3/**'
2725
- 'ci/codec_tables/**'
2826
- 'tests/fl/codec/mp3*'

‎ci/boards.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
# Old fork that we were using
4040
# ESP32_IDF_5_1_PIOARDUINO = "https://github.com/zackees/platform-espressif32#Arduino/IDF5"
4141

42-
# ALL will be auto populated in the Board constructor whenever a
43-
# board is defined.
42+
# ALL is auto-populated by Board.__post_init__ for every board declared with
43+
# add_board_to_all left at its default. Clones, create_board()'s unknown-board
44+
# fallbacks and test fixtures pass False and stay out.
4445
ALL: list["Board"] = []
4546

4647

@@ -125,7 +126,17 @@ def __post_init__(self) -> None:
125126
# Auto-detect and exclude problematic libraries based on environmental signals
126127
self._auto_detect_library_exclusions()
127128

128-
ALL.append(self)
129+
# Honour the flag. This used to append unconditionally, which made
130+
# `add_board_to_all=False` mean nothing: `clone()` sets it, and
131+
# `create_board()` returns `board.clone()`, so every create_board call
132+
# anywhere in CI permanently appended one more entry to ALL. The
133+
# unknown-board fallback in create_board sets it too, so those ad-hoc
134+
# placeholders accumulated as well -- and the reverse-lookup loops in
135+
# create_board scan ALL, so a later lookup could match a placeholder
136+
# left behind by an earlier one. Registration is for boards declared in
137+
# this module.
138+
if self.add_board_to_all:
139+
ALL.append(self)
129140

130141
def _is_native_or_stub_platform(self) -> bool:
131142
"""Check if this is a native or stub platform that doesn't need a framework"""

‎ci/codec_cpu/audit.py‎

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
BUILD = Path(os.environ.get("CODEC_CPU_BUILD", ROOT / ".build" / "codec-cpu-audit"))
2626
REGRESSION_TOLERANCE = 0.05
2727
PROFILE_RUNS = 30
28-
BACKENDS = ("helix", "minimp3-float")
28+
# minimp3's float build. It stays the CPU-audited variant after Helix's
29+
# deletion: the host baselines in codec_cpu_trend.json are keyed by its symbols,
30+
# and re-baselining onto the fixed build is separate work (FastLED#4110). The
31+
# fixed path's speed is gated by the SIMD perf test in
32+
# tests/fl/codec/mp3_fixed_point.hpp.
33+
BACKENDS = ("minimp3-float",)
2934
STAGES = (
3035
"scalefactors",
3136
"huffman",
@@ -100,7 +105,6 @@ class InstrumentedDriver:
100105
)
101106

102107
_FUSED_STAGES = {
103-
"helix": {"reorder": "dequant"},
104108
"minimp3-float": {"dequant": "huffman"},
105109
}
106110

@@ -264,20 +268,9 @@ def instrument_llvm_ir(
264268
if re.search(r"\bfmul\b", line)
265269
if (match := _LLVM_VALUE_RE.match(line))
266270
}
267-
mulshift_values = {
268-
match.group(1)
269-
for line in body
270-
if "MULSHIFT32" in line and re.search(r"\bcall\b", line)
271-
if (match := _LLVM_VALUE_RE.match(line))
272-
}
273271
float_accumulates = _tainted_accumulate_lines(
274272
body, fmul_values, r"\bf(?:add|sub)\b"
275273
)
276-
helix_accumulates = _tainted_accumulate_lines(
277-
body,
278-
mulshift_values,
279-
r"\b(?:add|sub)(?:\s+nsw|\s+nuw)*\s+i(?:32|64)\b",
280-
)
281274
for relative, line in enumerate(body, start=start + 1):
282275
if (
283276
operations
@@ -303,27 +296,6 @@ def instrument_llvm_ir(
303296
f"i32 {operation_stage_index}, i32 0, i32 {lanes})"
304297
)
305298
operation_sites += 1
306-
elif (
307-
operations
308-
and backend == "helix"
309-
and ("MULSHIFT32" in symbol or "MADD64" in symbol)
310-
and re.search(r"\bmul(?:\s+nsw|\s+nuw)*\s+i64\b", line)
311-
):
312-
inserts.setdefault(relative, []).append(
313-
" call void @fastled_mp3_cpu_operation("
314-
f"i32 -1, i32 1, i32 {1 if 'MADD64' in symbol else 0})"
315-
)
316-
operation_sites += 1
317-
elif (
318-
operations
319-
and backend == "helix"
320-
and relative - (start + 1) in helix_accumulates
321-
):
322-
inserts.setdefault(relative, []).append(
323-
" call void @fastled_mp3_cpu_operation("
324-
f"i32 {operation_stage_index}, i32 0, i32 1)"
325-
)
326-
operation_sites += 1
327299
if operations and operation_sites == 0:
328300
raise RuntimeError(f"no arithmetic sites found in {backend} LLVM IR")
329301
declarations = [
@@ -374,7 +346,6 @@ def build_instrumented_driver(*, operations: bool = True) -> InstrumentedDriver:
374346
BUILD.mkdir(parents=True, exist_ok=True)
375347
compiler = compiler_path()
376348
sources = {
377-
"helix": ROOT / "ci" / "codec_memory" / "helix_audit.cpp",
378349
"minimp3-float": ROOT / "ci" / "codec_memory" / "minimp3_audit.cpp",
379350
}
380351
objects: list[Path] = []
@@ -456,7 +427,7 @@ def build_plain_driver() -> Path:
456427
BUILD.mkdir(parents=True, exist_ok=True)
457428
compiler = compiler_path()
458429
objects: list[Path] = []
459-
for backend in ("helix", "minimp3"):
430+
for backend in ("minimp3",):
460431
source = ROOT / "ci" / "codec_memory" / f"{backend}_audit.cpp"
461432
obj = BUILD / f"{backend}.plain.o"
462433
RunningProcess.run(
@@ -1132,14 +1103,9 @@ def _target_tools(target: str) -> TargetTools:
11321103
def run_codegen_audit() -> dict[str, dict[str, dict[str, dict[str, int]]]]:
11331104
BUILD.mkdir(parents=True, exist_ok=True)
11341105
sources = {
1135-
"helix": Path(__file__).with_name("helix_codegen.cpp"),
11361106
"minimp3-float": Path(__file__).with_name("minimp3_codegen.cpp"),
11371107
}
11381108
kernel_needles = {
1139-
"helix": {
1140-
"dct32": ("FDCT32",),
1141-
"polyphase": ("PolyphaseMono", "PolyphaseStereo"),
1142-
},
11431109
"minimp3-float": {
11441110
"dct32": ("mp3d_DCT_II",),
11451111
"polyphase": ("mp3d_synth_pair",),

‎ci/codec_cpu/driver.cpp‎

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
#include <string.h>
66

77
#include "fl/codec/mp3_memory.h"
8-
#include "third_party/libhelix_mp3/pub/mp3dec.h"
8+
9+
// Pinned to the float variant: this driver links minimp3_audit.o, which pins it
10+
// the same way, and the audit's host baselines are keyed by that build's
11+
// symbols. minimp3.h now defaults to fixed point, so relying on the default
12+
// would silently swap the measured decoder.
13+
#define MINIMP3_FLOAT_POINT 1
914
#include "third_party/minimp3/minimp3.h"
15+
#undef MINIMP3_FLOAT_POINT
1016

1117
#if __has_include(<valgrind/callgrind.h>)
1218
#include <valgrind/callgrind.h>
@@ -107,49 +113,6 @@ uint64_t checksumPcm(const int16_t* pcm, int samples, int channels) {
107113
return value;
108114
}
109115

110-
bool decodeHelix(const unsigned char* data, size_t size, uint64_t* checksum,
111-
int* frames) {
112-
const int frames_before = *frames;
113-
HMP3Decoder decoder = fl::third_party::MP3InitDecoder();
114-
if (!decoder) {
115-
return false;
116-
}
117-
int16_t* pcm = static_cast<int16_t*>(::malloc(2304 * sizeof(int16_t)));
118-
if (!pcm) {
119-
fl::third_party::MP3FreeDecoder(decoder);
120-
return false;
121-
}
122-
const unsigned char* input = data;
123-
size_t remaining = size;
124-
while (remaining > 4) {
125-
const int offset = fl::third_party::MP3FindSyncWord(
126-
input, static_cast<int>(remaining));
127-
if (offset < 0) {
128-
break;
129-
}
130-
input += offset;
131-
remaining -= static_cast<size_t>(offset);
132-
const size_t before = remaining;
133-
const int result = fl::third_party::MP3Decode(
134-
decoder, &input, &remaining, pcm, 0);
135-
if (result == 0) {
136-
MP3FrameInfo info = {};
137-
fl::third_party::MP3GetLastFrameInfo(decoder, &info);
138-
if (info.outputSamps > 0 && info.nChans > 0) {
139-
*checksum ^= checksumPcm(
140-
pcm, info.outputSamps / info.nChans, info.nChans);
141-
++*frames;
142-
}
143-
}
144-
if (remaining >= before) {
145-
break;
146-
}
147-
}
148-
::free(pcm);
149-
fl::third_party::MP3FreeDecoder(decoder);
150-
return *frames > frames_before;
151-
}
152-
153116
bool decodeMinimp3(const unsigned char* data, size_t size, uint64_t* checksum,
154117
int* frames) {
155118
const int frames_before = *frames;
@@ -268,10 +231,8 @@ void Mp3MemoryFree(void* ptr, fl::size bytes, Mp3MemoryTag tag) FL_NO_EXCEPT {
268231
} // namespace fl
269232

270233
int main(int argc, char** argv) {
271-
if (argc != 2 ||
272-
(::strcmp(argv[1], "helix") != 0 &&
273-
::strcmp(argv[1], "minimp3-float") != 0)) {
274-
::fprintf(stderr, "usage: codec_cpu_driver helix|minimp3-float\n");
234+
if (argc != 2 || ::strcmp(argv[1], "minimp3-float") != 0) {
235+
::fprintf(stderr, "usage: codec_cpu_driver minimp3-float\n");
275236
return 2;
276237
}
277238
uint64_t checksum = 0;
@@ -294,9 +255,7 @@ int main(int argc, char** argv) {
294255
}
295256
callgrindStart();
296257
const uint64_t cycle_start = cycleCounter();
297-
const bool decoded = ::strcmp(argv[1], "helix") == 0
298-
? decodeHelix(data, size, &checksum, &frames)
299-
: decodeMinimp3(data, size, &checksum, &frames);
258+
const bool decoded = decodeMinimp3(data, size, &checksum, &frames);
300259
cycles += cycleCounter() - cycle_start;
301260
callgrindStop();
302261
::free(data);

‎ci/codec_cpu/helix_codegen.cpp‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎ci/codec_cpu/minimp3_codegen.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
// Standalone minimp3 translation unit for target-ISA code generation auditing.
2+
//
3+
// The float variant, pinned. The wrappers below take `float*`, the kernel
4+
// needles in ci/codec_cpu/audit.py name the float kernels, and the codegen
5+
// baselines in codec_cpu_trend.json are keyed to them -- so this TU must not
6+
// follow minimp3.h's default, which is fixed point since FastLED#4056.
7+
// FastLED#4110 covers adding the fixed build's cross-target codegen row, which
8+
// needs its own int32_t-typed wrappers rather than a flipped define here.
29

310
#include "fl/stl/compiler_control.h"
411

@@ -12,7 +19,9 @@
1219

1320
typedef fl::u64 uint64_t;
1421

22+
#define MINIMP3_FLOAT_POINT 1
1523
#include "third_party/minimp3/_build.cpp.hpp"
24+
#undef MINIMP3_FLOAT_POINT
1625

1726
extern "C" FL_NO_INLINE void
1827
fl_codec_cpu_minimp3_dct32(float* grbuf, int bands) FL_NO_EXCEPT {

0 commit comments

Comments
 (0)