feat(radio): eliminate double-precision math from firmware#7257
Open
raphaelcoeffic wants to merge 2 commits into
Open
feat(radio): eliminate double-precision math from firmware#7257raphaelcoeffic wants to merge 2 commits into
raphaelcoeffic wants to merge 2 commits into
Conversation
Replace newlib's double-precision float conversion chain (strtod, _dtoa_r, mprec Bignum) and printf float formatting with lightweight float-only alternatives. Lua is configured with LUA_32BITS (single-precision float) and STM32 MCUs only have single-precision FPU, so double was purely parasitic overhead. Changes: - Add eyalroz/printf v6.3.0 with PRINTF_USE_DOUBLE_INTERNALLY=0 - Add custom float-only strtof (replaces newlib's strtod-based strtof) - Remove -u _printf_float / -u _scanf_float linker flags - Remove luaconf.h strtod override (restore strtof for LUA_32BITS) - Use Lua's native hex float formatter instead of snprintf %a - Rewrite math.random: bit-manipulation float for [0,1), integer scaling with rejection sampling for [low,up] - Fix double-promotion warnings: f-suffix literals, sinf/powf/fmodf/ fabsf/sqrtf, explicit casts for variadic functions - Add -Wdouble-promotion to catch future regressions - Add 6 Lua float behavior regression tests X7 (Cortex-M3): 507112 -> 492708 bytes text (-14404 bytes) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…chain theme_manager.cpp was the sole sscanf user in firmware. On non-nano targets (color LCD), sscanf pulls in full svfscanf → _strtod_r → strtod.o → mprec, dragging ~47KB of double-precision code even though only %i (integer) format was used. Replace with strtol-based parsing for "RGB(%i,%i,%i)" format. X10: 1599084 -> 1551804 bytes text (-47280 bytes) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
strtod,_dtoa_r, mprec Bignum) and printf float formatting with lightweight float-only alternativesLUA_32BITS(single-precisionfloat) and STM32 MCUs only have single-precision FPU — double was purely parasitic overheadsscanfintheme_manager.cppwithstrtolparsing — on non-nano (color) targets,sscanfpulled in the fullsvfscanf→_strtod_rchain even for integer-only formatsFlash savings (text section)
Changes
PRINTF_USE_DOUBLE_INTERNALLY=0replaces newlib'ssnprintf/sprintf/vsnprintfvia strong symbol overridestrtofreplaces newlib'sstrtof(which internally calledstrtod+d2f) via--wraplinker optionluaconf.h: removed unconditionalstrtodoverride (restorestrtofforLUA_FLOAT_FLOAT), disabledlua_number2strxmacro so Lua's native hex float formatter is used instead ofsnprintf %amath.random: rewritten with bit-manipulation float for[0,1)and integer-only scaling with rejection sampling for[low,up]— eliminates last double-precision ops from Lua-Wdouble-promotionadded to catch future regressionsf-suffix literals,sinf/powf/fmodf/fabsf/sqrtfvariants, explicit casts for variadic functionstonumber,tostring,string.format,math.random,string.pack, arithmetic round-tripsTest plan
string.formatoutput matches expectations for common patterns (%f,%g,%e,%a)math.random()distribution on radio