Repository navigation
fix(filters): accumulate on fxp and move to caller-owned storage - #6
Merged
Merged
Conversation
9 tasks done
FIR and biquad outputs are accumulated with fxp_acc_mac_chk and narrowed once through the fxp rounding policy, so INT32_MIN operands saturate and return FPC_STATUS_SATURATED instead of overflowing the int64 accumulator, and negative results round to nearest instead of flooring through a right shift. Filters become caller-owned structs, and the FIR borrows caller-sized coefficient and history arrays. fxp is pinned by commit (24315b4, which compiles where CHAR_BIT == 16) until it is tagged, and CI now builds the library with TI C2000 CGT 22.6.2 and 25.11.1 under COFF and EABI. Expected FIR outputs move by one LSB where the old floor shift truncated (999 to 1000, 1666 to 1667, 299 to 300). Refs #5
aajll
force-pushed
the
5-fix-filters-fxp
branch
from
October 14, 2026 16:56
7ca487c to
43e95a0
Compare
4 tasks
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.
Refs #5
Layer 1 of 4. Ports the FIR and biquad filters onto
fxpand moves them to caller-owned storage.Why
Both filters summed
int64_tproducts unchecked and narrowed withacc >> 16. TwoINT32_MINoperands overflow that sum (undefined behaviour), and the shift of a negative sum is implementation-defined and floors. Accumulating withfxp_acc_mac_chkand narrowing withfxp_acc_narrow_chkmakes overflow saturate and reportFPC_STATUS_SATURATED, and narrowing follows the build-wideFXP_ROUNDING.Caller-owned structs replace the pool so the filters keep no global state and need no capacity configuration; this matches
rampganddebounce.Changes
subprojects/fxp.wrappinsfxpat24315b4, which includes fix: take uint_least8_t in fxp_rescale for CHAR_BIT == 16 targets fxp#3 (fxp_rescaletakesuint_least8_t, sofxp.hcompiles whereCHAR_BIT == 16);fpc_depcarriesfxp_depbecausefxp_tis in the public API.c2000CI job builds the library and its subprojects with-Dwerror=trueon TI C2000 CGT 22.6.2 and 25.11.1, under--abi=coffabiand--abi=eabi. Installers are SHA-256 pinned and the toolchain cached.include/fpc_filters.h: publicstruct fpc_firandstruct fpc_biquad; FIR history is a caller-provided buffer oforderelements.init,reset,set_configandprocess; nodeinit.a1/a2 == FXP_MINis rejected so that their negation is exact. A zero biquad is a valid all-zero filter; a zero FIR is uninitialised.fxpwrap and suppresses findings insidesubprojects/.tests/test_filters.c: 11 cases with exact expectations.Acceptance criteria evidence
INT32_MINsaturates — FIR and biquad cases withFXP_MINcoefficients and samples returnFPC_STATUS_SATURATEDand the saturated output; clean under ASan+UBSan with-fno-sanitize-recover=all. An unchecked-sum mutant fails under UBSan.FXP_ROUNDING— no>>or<<remains insrc/filters.c; negative round-to-nearest-even cases (−5 → −2, −1 → 0) are asserted. A floor-shift mutant fails at the 1000 expectation.Checks
-Werror: pass. clang-Werror: pass.src/filters.ccoverage: 100% lines, 100% branches.-Dwerror=true(the CI step run locally on a clean export): 0 diagnostics.Stack
fxp, caller-owned, saturating; TI C2000 CI gatefxp: wide integral,dtper term, caller-ownedpool-allocator, its options and headers; coverage gate 100/100Review bottom first. Each layer builds and passes the full suite on its own. The whole-change narrative and limitations are in the top pull request (layer 4).