Skip to content

rational: recursive (IIR) half-band stages by 2 and their cascades (IIR-b) - #113

Merged
tap merged 12 commits into
mainfrom
claude/sample-rate-solutions-comparison-mqc190
Nov 22, 2026
Merged

tap merged 12 commits into
mainfrom
claude/sample-rate-solutions-comparison-mqc190

Conversation

@tap

@tap tap commented Nov 22, 2026

Copy link
Copy Markdown
Owner

What this changes

IIR-b of docs/IIR_PLAN.md: rational gains recursive (IIR) half-band stages by 2 and their cascades, a stage type of their own beside the FIR stages (D20, R21–R25). The FIR stages, chains, matrix and C ABI are unchanged.

  • iir_stage.h: basic_iir_stage<S, Ch, R, P> over iir_stage_base<S, R, P> (K12). R is up2 / down2. P is iir_phase::nonlinear (the elliptic two-path allpass half-band) or iir_phase::near_linear (one path a pure delay, with an exact delay path).
    • Profiles: the family's four, at the FIR stages' numbers (I3).
    • Call shapes: the family's (process, pull, flush, reset, validate, outputs_for, frames_needed, window_frames).
    • Latency: nominal (nominal_latency_output_frames, latency_deviation_output_frames, group_delay_output_frames(f)), and delay_path_output_frames() for the near-linear variant (I5).
    • Aliases: iir_converter<Ch, R>, iir_converter_near_linear<Ch, R>, and their _q15 / _q31 siblings.
    • By 3 and by 4 are static_asserts whose messages say why.
  • iir_chain.h: iir_down_by / iir_up_by<S, Ch, P, D>, D = 2, 4, 8 or 16, each stage at profile::relaxed(d) (I13). The cascade deletes the inherited exact latency and gives its own composed delay path and window.
  • DspTap pinned at v0.3.0 (bd9617a, IIR-a: the recursive substrate (designs, tables, kernels per format, FTZ, chain nominal latency), 0.3.0 DspTap#68: IIR-a's substrate). TAP_SR_DSPTAP_MINIMUM is 0.3.0 in the three umbrella headers, and the root README's tested pairs gain the row for the unreleased 0.9.0. TAP_SR_VERSION stays 0.8.0; 0.9.0 is IIR-d's.
  • Tests:
    • the golden leg (tools/reference/make_iir_reference_vectors.py: 64 stages through scipy.signal.lfilter, committed vectors) and the battery tests/test_iir_stage.cpp;
    • the no-flush image tests/test_iir_subnormals.cpp (TAP_DSP_ALLOW_SUBNORMALS, an executable of its own);
    • four compile-fail cases (rational.IirStage.RefusedShapesFailToCompileWithTheMessage);
    • the rational header count pinned at 8.
  • Docs: the charter (PLAN.md 2 and D20), rational/PLAN.md R21–R25 and its verification record, the roadmap's section 10, the book's new chapter book/src/part7/iir.md, the READMEs' profile table, and docs/IIR_PLAN.md v10 (the decisions recorded, I12's verdict, question 19).
  • The four-path stage does not ship (I12). Its measurement record is rational/tools/spikes/iir/iirb_fourpath/: probes, the draft header they measured, and counts per target.

Why

The IIR plan's second step (section 5). These are the stages the plan's remaining steps build on: IIR-c's guard band filter, and IIR-d's C ABI, notebooks, ratchet workloads and 0.9.0.

I12 only lets the four-path ↓4/↑4 ship where it measures more than 10 % fewer instructions than the two half-bands it replaces. On the shipping machine over DspTap's kernels, streaming at economy (the other two 70 dB profiles are within 0.01 %):

target float ↓ Q15 ↓ float ↑ Q15 ↑
M33 +10.7 % +14.6 % +2.1 % −14.7 %
M55 +9.2 % −10.1 % −1.2 % −5.0 %
Hexagon −19.5 % −24.1 % −7.7 % −10.7 %

No format and direction clears 10 % on all three targets. IIR-0's kernels unrolled their fixed section counts; DspTap's are generic, which costs the in-order Arm cores. So R is up2 / down2 only, and every cascade is half-bands.

Verification

Each number is measured by the named test (asserted there against its bound or stated tolerance):

What Measured Test
Golden leg, max error (of full scale) double 9.6e-14, float 3.8e-7, Q15 1.5e-5, Q31 5.2e-9 iir_stage_test.MatchesTheDirectFormGoldenLeg
Q15 / Q31 outputs bit-pinned, 4 FNV-1a hashes each iir_fixed_test.OutputsAreBitPinned
Group delay vs scipy within 8.5e-11 frames GroupDelayMatchesTheGoldenLeg
Stopbands −71.3 to −145.6 dB, each at least A + 1 EveryStageMeetsItsSpecAtEveryProfileAndDivisor
Nonlinear power complementarity to 5e-15 same
Aliasing / imaging at 0.95 of the passband edge ≤ −71.8 dB (70 dB profiles), ≤ −123.9 dB (transparent) AliasingAndImagingMeasuredBySineFits
Round trip ×2 to ×16 through tap::dsp::subband_delta −64.5 / −70.0 / −68.6 dB at the three 70 dB profiles, −114.8 dB at transparent; one frame off T stays above −40 dB RoundTripCancelsToTheProfilesThreshold
Latency at economy, ↓2 nonlinear 1.20 frames at DC, 2.48 at the passband edge; near-linear exactly 7 frames within 0.0088 NominalLatencyAndGroupDelayMatchTheImpulseResponse
Cascade cost at economy, MACs per output by 2 / 4 / 8 / 16 nonlinear 4 / 8 / 16 / 24, near-linear 7 / 13 / 21 / 29 (FIR down_by4 … down_by16: 43 / 71 / 143) IirChain.CascadesCostTheRelaxedRow
Fixed point largest state 1.99 of full scale (limit 4); outputs within 2 LSB (Q15) and 1e-8 (Q31) of double; saturation, never wrap; Q15 floor −100.8 dB RMS; every state exactly zero inside its window FullScaleDriveNeverWrapsInside, Q15FloorIsTheOutputsOwnRounding, FixedPointSilenceIsExactlyZeroAfterTheWindow
Without flush-to-zero residue at most 7× the smallest subnormal (bound 16) iir_subnormals.WithoutFlushToZeroTheResidueIsBounded

Where it ran:

  • Hosted: GCC 13 with -Werror on all three engines, 407 of 407 (my rebuild of the pushed head); Clang 18 with -Werror and -Wshadow-all, and GCC without exceptions or RTTI, all passing; a Debug build of rational's battery, 209 of 209, the precondition's death test included.
  • QEMU, both builds: M33 and M55 169 of 169 in the main battery plus 4 of 4 in the subnormal image; Hexagon 194 of 194. The spec sweep joins the Hexagon exclusions in ci.yml (in soft double it ran past the job's 20 minutes); the Arm one-shot filter excludes it too.
  • The pin move, A/B'd against the parent commit: all 312 workload counts and checksums are identical on M33, M55, Hexagon and host in both builds, and so are the size and stack ceilings. With the stages added, the tree measures the same again. No baseline or ceiling file is touched.
  • Style and docs: clang-tidy is clean on the new files, clang-format 18 passes, the vocabulary gate passes, and the book builds with mdBook 0.4.40 and no warnings.
  • Not run locally: MSVC and AppleClang. CI is the first gate for both.

Notes for the reviewer

  • Submodule pin moved: submodules/dsptap 084f2f6 (v0.2.0) → bd9617a (v0.3.0). Besides the new headers, DspTap 0.3.0 changes only comments in kaiser.h and nyquist.h, and adds chain.h members that no FIR workload instantiates.
  • An honest limit, open as question 19. The floating near-linear stage at transparent, divisor 1 (order 19), holds a zero-input limit cycle under flush-to-zero at 3.7–4.1× the smallest normal, in float and double, from 12–20 of 39 noise starts. It is the mechanism IIR-a found in the Chebyshev II.
    • That stage's flush ends in that residue, not silence.
    • A chain with that stage before other stages flushes to within the residue of zero padding rather than bit for bit (iir_up_by<…, near_linear, 8> at transparent).
    • It is pinned (residue ≤ 8× the smallest normal) and stated in iir_stage.h.
    • The choices are in docs/IIR_PLAN.md question 19: keep the limit, commit a draining design in DspTap, or don't offer that stage in floating point.
    • DspTap's comment that its allpass sections "reach an exactly zero state" under flush-to-zero is wrong for this design. Correcting it is DspTap's change, for whichever answer question 19 gets.
  • Decisions the plan left open, taken here:
    • The near-linear variant refuses a custom profile or a named one at another divisor; the nonlinear variant designs those at run time.
    • A profile counts as a named design point when its (A, p/d) matches bit for bit.
    • The fixed-point window for the near-linear second-order sections is twice the summed per-section pole-radius decay.
    • An interpolator's pull() banks the second output of a pair when a call asks for an odd count.
    • A read-only states() accessor exists for the tests.
  • The four-path record commit (9529030) can be dropped without touching anything else, if you'd rather not keep the draft header in the tree.

Generated by Claude Code

… A9)

Moves submodules/dsptap from 084f2f6 (v0.2.0) to bd9617a, the commit the
maintainer tags v0.3.0 (tap/DspTap#68: IIR-a's recursive substrate,
iir_design.h, iir_tables.h, iir_kernels.h, subnormals.h, chain.h's nominal
latency members, and X-c's subband.h). TAP_SR_DSPTAP_MINIMUM is 0.3.0 in
the three umbrella headers, family.VersionMacrosAgree re-pinned, and the
root README's tested pairs gain the row for the unreleased 0.9.0.
TAP_SR_VERSION stays 0.8.0 (0.9.0 is IIR-d's).

Outside the new headers DspTap 0.3.0 changes only comments in kaiser.h
and nyquist.h and adds members to chain.h that no FIR workload
instantiates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
…e variants, and the cascades (IIR-b)

The recursive stages of docs/IIR_PLAN.md (I2-I6, I8, I9, I13, I14), a
stage type of their own beside basic_stage (the family's D20):

- iir_stage.h: basic_iir_stage<S, Ch, R, P> over iir_stage_base<S, R, P>
  (K12), R up2 / down2, P iir_phase::nonlinear (the elliptic two-path
  allpass half-band) or iir_phase::near_linear (one path a pure delay);
  the aliases iir_converter<Ch, R> and iir_converter_near_linear<Ch, R>
  with their _q15 / _q31 siblings. The stage machine around DspTap's step
  kernels: the commutator and its latch, the near-linear delay path's
  ring, pull()'s banked output, outputs_for / frames_needed, flush and
  window_frames(), validate() (D17), process / pull / flush out of line
  against a cursor (A12). Every named profile reaches both variants (I3),
  at compile-time designs (nonlinear) or DspTap's committed tables
  (near-linear) at the divisors 1, 2, 4 and 8; a custom nonlinear profile
  designs at run time, a custom near-linear one is refused. Latency is the
  nominal triple chain.h composes (I5), plus the near-linear delay path
  subband.h takes as T; flush-to-zero is the host's job, checked as a
  debug-build precondition (I9).
- iir_chain.h: iir_down_by / iir_up_by<S, Ch, P, D>, D = 2, 4, 8, 16: a
  cascade of half-bands, each at profile::relaxed of its divisor (I13).
  Its exact latency is deleted, its delay path composed, so the round-trip
  scaffold takes the near-linear cascades and refuses the nonlinear ones.
- The golden leg: tools/reference/make_iir_reference_vectors.py writes
  tests/reference/iir_reference_vectors.h, every offered stage's transfer
  function in one direct form through scipy.signal.lfilter around down-
  sampling or zero-stuffing (64 cases).
- tests/test_iir_stage.cpp (typed over float / double / Q15 / Q31) and
  tests/test_iir_subnormals.cpp (its own image, TAP_DSP_ALLOW_SUBNORMALS),
  the compile-fail "iir" set, the bare-metal runner for the second image,
  the header count re-pinned at 8.

The four-path stage by 4 does not ship: measured on this machine it does
not beat the two half-bands it would replace by R3's 10 % on the M33, the
M55 and Hexagon (I12; the record is rational/tools/spikes/iir/
iirb_fourpath/). The floating near-linear stage at transparent and
divisor 1 holds a zero-input limit cycle at about four times the smallest
normal under flush-to-zero, so I6's exactly zero state does not hold
there: pinned as an honest limit pending the maintainer's decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
rational/tools/spikes/iir/iirb_fourpath/: the probes, the draft of
iir_stage.h they measured (with the four-path stage by 4 that the
measurement kept out of the release), and the counts on the M33, the M55
and Hexagon. Against the two half-bands it replaces (economy, streaming
instructions), going down: float +10.7 / +9.2 / -19.5 %, Q15 +14.6 /
-10.1 / -24.1 %; going up: float +2.1 / -1.2 / -7.7 %, Q15 -14.7 / -5.0 /
-10.7 %. No format, direction and placement clears R3's 10 % on every
target, so it does not ship. Not part of any build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
…IR-b)

clang-tidy's readability-identifier-naming: the typed tests' `using S =
TypeParam;` and the helpers' sample aliases are `sample`, the golden
runner's ratio alias `direction`. No test changes what it checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
…ook (IIR-b)

- docs/IIR_PLAN.md v10: IIR-a recorded as landed (tap/DspTap#68) with its
  findings; I3, I6, I8, I13, I14 and the names decided with the
  maintainer's answers; IIR-b's results, the four-path measurement (2.4,
  I12: it does not ship) and the near-linear transparent stage's limit
  cycle under flush-to-zero as open question 19.
- PLAN.md: D20 (IIR stages are a stage type of their own, not a profile
  and not an engine), cited by section 2's line.
- rational/PLAN.md: the charter (section 1) and R2 amended, R21-R25, the
  layout, the v0.21 row and the IIR-b record in section 6.
- rational/CLAUDE.md: the charter constraints (R1-R25, the _by aliases,
  the recursive stages); the root CLAUDE.md's rational sentence.
- README.md: rational's row with each variant's profiles, the profile
  section's note that the variant is in the type; rational/README.md: the
  recursive stages, their numbers, the per-target flush-to-zero table and
  the honest limits.
- docs/ROADMAP.md: section 8's deferral of the IIR pre-filter lifted, and
  section 10, Block IIR (IIR-0 to IIR-d).
- book: Part VII's chapter on iir_stage.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
…he saturation counted, the padding streamed (IIR-b)

- make_iir_reference_vectors.py also writes each stage's direct-form
  group delay (scipy.signal.group_delay) at 0, half and all of its
  passband edge; iir_double.GroupDelayMatchesTheGoldenLeg holds
  group_delay_output_frames(f) to it (8.5e-11 frames at worst) and the
  stated deviation to bound it. The expected outputs are unchanged.
- FullScaleDriveNeverWrapsInside checks that every output the double
  stage takes past full scale is the rail of its sign (69128 in Q15,
  71343 in Q31), so saturation is at the output and never a wrap.
- The flush tests stream the zero padding in blocks: whole, the double
  windows outgrew the M55 image's heap (std::bad_alloc on the leg).
- The plans' Q31 headroom figure: 1.99 of full scale, as Q15's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
The near-linear fixed-point window's rule as implemented (twice the sections' pole-radius decay), the limit cycle of the floating near-linear transparent stage at divisor 1 among the honest limits (the IIR plan's question 19), the measured headroom, Q15 floor and subnormal residue, and the tests' names as gtest reports them. Comments only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
…IIR-b, A4)

The recursive stages take the same four profile names at the same numbers; the table says so where the README's profile section already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
…R-b)

Double on the M33 and float and double on Hexagon have no flush-to-zero control (tap/dsp/subnormals.h), so the fixture's bits reach nothing there and a floating state sticks at the subnormal residue. FlushEqualsZeroPaddingBitForBit, its chains and SilenceDecaysToExactZero hold those types to the residue (64 times the smallest subnormal through a chain) on those legs, and to an exactly zero state everywhere a bit governs the type, as DspTap's battery does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
…t is summarized (IIR-b, I12)

iir_chain.h, R21, the README, the book and the spike's README said the stage passed only on Hexagon or cost more on both Arm targets; it also passed in Q15 going up on the M33 and going down on the M55. What fails the bar is that no format and direction passes on all three targets. Comments and prose only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
…(IIR-b)

iir_double.EveryStageMeetsItsSpecAtEveryProfileAndDivisor runs 32 impulse responses through a 2049-point DTFT per band in double, which is software on Hexagon: it was still running after 20 minutes under qemu-hexagon, the job's budget. A host measurement, as the Arm legs' one-shot filter already treats it (bare_metal_main.cpp); every other recursive test runs on Hexagon.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
Hosted GCC 13 and Clang 18 with -Werror, both builds, Debug; clang-tidy, clang-format, the vocabulary gate and the book; the M33, M55 and Hexagon batteries in both builds; the ratchet and the ceilings unchanged on every key. MSVC and AppleClang not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GKzq1VSdcMYCRMhddiMaf
@tap
tap merged commit f9e0c2b into main Nov 22, 2026
41 checks passed
@tap
tap deleted the claude/sample-rate-solutions-comparison-mqc190 branch November 22, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants