Repository navigation
Description
Goal
Drop __ieee754_pow (libm double-precision IEEE-754 power) from FastLED release builds. It's the 9th-largest symbol in the post-#2908 ESP32-S3 NEOPIXEL Blink audit at 2,723 B, and on a Blink it's pulled in solely by Gamma8Impl::Gamma8Impl(float) computing a 256-entry u16 LUT — single precision is more than sufficient precision for that LUT.
Mechanism, not algorithm. Switch the LUT-generator call site (and the applyGamma_video site on the same code path) from fl::pow(double, double) to fl::powf(float, float). The float branch resolves to ::powf → __ieee754_powf (typically 1.5-2 KB on xtensa-esp), so the net reduction is __ieee754_pow size minus __ieee754_powf size — projected at 0.5-1.5 KB measured on a NEOPIXEL Blink build.
Parent: #2886 — second algorithmic-bloat reduction (after #2908's fl::sort_small).
Why this works
Caller analysis
__ieee754_pow is pulled into a Blink build via this chain:
Channel::showPixels (src/fl/channels/channel.cpp.hpp:343)
→ Gamma8::getOrCreate(gamma)
→ Gamma8Impl::Gamma8Impl(float gamma) [src/fl/math/ease.cpp.hpp:355]
→ fl::pow(static_cast<double>(i) / 255.0, static_cast<double>(gamma)) [line 358]
→ fl::pow_impl_double [math.h:437]
→ ::pow(double, double) [math.cpp.hpp:138]
→ __ieee754_pow [libm/e_pow.o]
Other Gamma8::getOrCreate callers are inside the UCS7604 chipset path (ucs7604.h:247, chipsets/ucs7604.h:165). UCS7604 is not in a stock NEOPIXEL Blink. Other fl::pow references in src/ are either in fixed-point template specializations (different overload — does not pull ::pow(double, double)), or in third_party/cq_kernel/fft_precision.h and third_party/stb/truetype/... — neither in a Blink build.
applyGamma_video(u8, float) at src/fl/gfx/colorutils.cpp.hpp:1289 also calls bare pow(orig, gamma) (float args promoted to double). It's not in a Blink hot path but is the symmetric site that should also flip to powf so the double-precision pow chain dies cleanly in any sketch that uses applyGamma_video without an offsetting double call elsewhere.
Precision check
Gamma8Impl's LUT is u16-valued (0..65535). Single-precision float has ~7 decimal digits, vastly more than the 16 bits needed for static_cast<u16>(fl::round(v)). The double in the existing code is precision-waste — it never carries past the round-to-u16.
applyGamma_video is u8 → u8 (static_cast<u8>(adj)). Same conclusion: double precision is overkill.
Deliverable
1. src/fl/math/ease.cpp.hpp — Gamma8Impl::Gamma8Impl(float) ctor
explicit Gamma8Impl(float gamma) {
mLut[0] = 0;
for (int i = 1; i < 256; ++i) {
- double v = fl::pow(static_cast<double>(i) / 255.0, static_cast<double>(gamma)) * 65535.0;
+ float v = fl::powf(static_cast<float>(i) / 255.0f, gamma) * 65535.0f;
mLut[i] = static_cast<u16>(fl::round(v));
}
}2. src/fl/gfx/colorutils.cpp.hpp — applyGamma_video(u8, float)
fl::u8 applyGamma_video(fl::u8 brightness, float gamma) {
float orig;
float adj;
orig = (float)(brightness) / (255.0);
- adj = pow(orig, gamma) * (255.0);
+ adj = fl::powf(orig, gamma) * (255.0);
fl::u8 result = (fl::u8)(adj);
...
}That's it — 2 file edits, ~4 lines changed.
Out of scope
third_party/cq_kernel/fft_precision.h— third-party FFT. Macro-driven and explicit about precision; not for this PR.third_party/stb/truetype/stb_truetype.cpp.hpp— third-party font rasterizer. Same reason.fl::powfixed-point template specializations infl/math/fixed_point/*.h— different overload, doesn't pull__ieee754_pow.
Acceptance
Gamma8Impl::Gamma8Impl(float)usesfl::powfand float math (nostatic_cast<double>).applyGamma_video(u8, float)usesfl::powf.bash lint --cpppasses.bash test --cpppasses — the host tests cover Gamma8 LUT correctness.- Measured against the post-perf(esp32): add fl::sort_small for bounded containers; cut ClocklessIdf5 bloat #2908 ELF baseline (350,127 B), the new build should be lower; the same PR ratchets
tests/data/esp32s3_bloat_baseline.txtaccordingly.
Expected savings
- Eliminated:
__ieee754_pow(2,723 B). - Added:
__ieee754_powf(typically 1.5-2 KB on xtensa-esp; not currently linked, so it's a new pull). - Net: 0.5-1.5 KB projected on the ESP32-S3 NEOPIXEL Blink build.
Variance reflects that __ieee754_powf's exact size depends on the libm build flags. Will be measured precisely on the post-merge build.
Related
- Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886 — parent meta + Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886#issuecomment-4641413123 / Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886#issuecomment-4641488454 (audit + post-perf(esp32): add fl::sort_small for bounded containers; cut ClocklessIdf5 bloat #2908 measurement).
- perf(esp32): add fl::sort_small for bounded containers; cut ClocklessIdf5 bloat #2908 — fl::sort_small (first algorithmic-bloat reduction; same PR pattern).
- chore(bloat): ratchet baseline 350568 -> 350127 (post-#2908 fl::sort_small) #2909 — baseline ratchet to 350,127 (the number this PR lowers further).
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
perf(gamma): use fl::s16x16::pow for Gamma8 LUT + applyGamma_video; d…
chore(bloat): ratchet baseline 350127 -> 347004 (post-#2911 fl::s16x1…