Skip to content

Drop __ieee754_pow (2.7 KB) via fl::powf in Gamma8Impl + applyGamma_video (#2886) #2910

Closed

Description

@zackees

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::pow fixed-point template specializations in fl/math/fixed_point/*.h — different overload, doesn't pull __ieee754_pow.

Acceptance

  1. Gamma8Impl::Gamma8Impl(float) uses fl::powf and float math (no static_cast<double>).
  2. applyGamma_video(u8, float) uses fl::powf.
  3. bash lint --cpp passes.
  4. bash test --cpp passes — the host tests cover Gamma8 LUT correctness.
  5. 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.txt accordingly.

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

🤖 Generated with Claude Code

Activity

  1. added a commit that references this issue on Jun 7, 2026
    f090358
  2. added a commit that references this issue on Jun 7, 2026
  3. moved this from Triage to Done in FastLED Trackeron Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions