Skip to content
heliaDSP
User guide
HELIA HUB

Contracts

A function’s contract is everything a caller must satisfy and may rely on: its signature and types, the sizes of the buffers it reads and writes, coefficient order and padding, alignment, which buffers may overlap or are overwritten, and its numerical behaviour. heliaDSP keeps Arm’s CMSIS-DSP signatures, types and contracts unchanged. This page collects the parts of those contracts that the declarations in Arm’s headers have not always stated, and the parts that change with the build configuration, for the functions Ambiq has measured or tested.

Helium, or MVE, is the vector extension of the Cortex-M55 in Apollo510. In this page a Helium build is one in which ARM_MATH_MVEF is defined and ARM_MATH_AUTOVECTORIZE is not: CMSIS-DSP’s headers define ARM_MATH_MVEF when the compiler targets a CPU with floating-point Helium, and AUTOVECTORIZE=ON (Zephyr: CONFIG_CMSIS_DSP_AUTOVECTORIZE=y) selects the portable C kernels instead. Code that must be correct in both kinds of build tests the same condition:

#if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
/* Helium build */
#endif

Under Zephyr the application sees ARM_MATH_AUTOVECTORIZE only after its first CMSIS-DSP include; see Zephyr.

Most stateful CMSIS-DSP functions come as a pair:

arm_fir_instance_f32 S; /* caller-owned instance */
arm_fir_init_f32(&S, numTaps, coeffs, state, blockSize); /* fills S, clears state */
arm_fir_f32(&S, input, output, blockSize); /* processes one block */

The caller allocates the instance, the state buffer, the coefficients and the input and output buffers, and keeps them alive while the instance is used. The library allocates no memory. The initializer stores pointers and counts in the instance and does not learn the size of any buffer, so it cannot detect a buffer that is too small: a short state buffer is overrun without an error.

arm_biquad_cascade_df1_f32 filters with numStages second-order sections. The caller supplies 5 coefficients per stage in the order {b0, b1, b2, a1, a2}, where the feedback coefficients a1 and a2 have the opposite sign to SciPy’s sos convention, and a state buffer of 4 * numStages floats.

In a Helium build the process function reads coefficients in an expanded layout of 32 floats per stage. Initialize with arm_biquad_cascade_df1_mve_init_f32, which takes caller-owned storage for that layout, one arm_biquad_mod_coef_f32 per stage:

#define NUM_STAGES 2
static const float32_t coeffs[5 * NUM_STAGES] = { /* b0, b1, b2, a1, a2 per stage */ };
static float32_t state[4 * NUM_STAGES];
static arm_biquad_casd_df1_inst_f32 S;
#if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
static arm_biquad_mod_coef_f32 coeffsMod[NUM_STAGES]; /* 32 floats per stage */
arm_biquad_cascade_df1_mve_init_f32(&S, NUM_STAGES, coeffs, coeffsMod, state);
#else
arm_biquad_cascade_df1_init_f32(&S, NUM_STAGES, coeffs, state);
#endif
arm_biquad_cascade_df1_f32(&S, input, output, blockSize);

In a Helium build, an instance initialized with arm_biquad_cascade_df1_init_f32, or filled by hand with plain coefficients, produces incorrect output with no error; Inf and NaN outputs were observed on Apollo510. arm_biquad_cascade_df1_mve_init_f32 is declared only in Helium builds, so the #if is required in code built for both. helia/tests/qualification/biquad_df1_test.c uses this pattern and checks both builds against a double-precision reference. The f16 biquad has the same requirement.

heliaDSP v1.1.0 accepted the plain initializer in Helium builds by adding a field to the instance type and expanding coefficients on each call. 2.0.0 restores Arm’s type and Arm’s contract; code that relied on 1.1.0’s behaviour must change its initialization, and objects compiled against 1.1.0’s headers in a Helium build are not link-compatible with 2.0.0.

nsx-physiokit v0.1.0 initializes its biquad with arm_biquad_cascade_df1_init_f32, and is affected in Helium builds.

arm_fir_f32 filters with numTaps coefficients stored in time-reversed order relative to the usual definition of the impulse response.

In a scalar build the state buffer holds numTaps + blockSize - 1 floats. In a Helium build:

  • the state buffer is longer. The length at the current qualified CMSIS-DSP commit is stated under “Configuration and ABI” in COMPATIBILITY.md; and
  • the coefficient array must be zero-padded to a multiple of 4 elements, while numTaps keeps its true value. Arm’s documentation states the same padding rule for the f16, Q31, Q15 and Q7 FIR filters.

A caller who sizes the state buffer for a scalar build and then builds for Helium has the end of the buffer overwritten by the initializer.

Arm’s Helium FIR f32 kernel also reads past the documented state length for most block shapes, and for some shapes with four or fewer taps and a block size that is not a multiple of four it writes past it. Pull request #9 of the upstream-tracking fork records the measurements, made on the Corstone-300 simulator, and corrects the kernel so that it writes nothing past the state length and reads within 4*ceil(numTaps/4) + 2*blockSize - 1 elements, and its initializer clears that many elements; with #9 that is the state length a Helium caller provides. The qualified CMSIS-DSP commit of 2.0.0 carries #9 (the carried_patches list of PROVENANCE.toml).

arm_rfft_fast_f32(&S, in, out, ifftFlag) computes a real FFT of the length the instance was initialized for.

  • Initialize with the initializer for the length, arm_rfft_fast_init_<N>_f32 for N = 32, 64, 128, 256, 512, 1024, 2048 or 4096. The generic arm_rfft_fast_init_f32(&S, N) refers to the tables of every length, which the linker therefore keeps: 87.6 KB of flash for a 512-point transform against 9.3 KB with arm_rfft_fast_init_512_f32 (Cortex-M55, GCC 14.2.1, -O2, unused sections removed; see Measurements). The choice affects flash and not run time: arm_rfft_fast_init_2048_f32 took 67 cycles on Apollo510 (GCC 14.2.1). arm_mfcc_init_f32 calls the generic initializer, so a program that uses the f32 MFCC links every length’s tables.
  • The input buffer is overwritten.
  • The forward output is packed: out[0] is the DC bin, out[1] the Nyquist bin, then interleaved real and imaginary parts of bins 1 to N/2 - 1. The forward transform is unnormalized; the inverse (ifftFlag = 1) includes the factor 1/N and returns the original signal.

heliaDSP v1.1.0’s macro ARM_RFFT_FAST_INIT_F32(S, LEN) is removed in 2.0.0; call arm_rfft_fast_init_<LEN>_f32.

The per-length initializers arm_rfft_init_<N>_q15 and arm_rfft_init_<N>_q31 (N = 32 to 8192) link coefficient tables of the size that length needs. The generic arm_rfft_init_q15 and arm_rfft_init_q31 link the 8192-point tables. Both produce bit-identical output: the parity test compares them for every length, forward and inverse. The table sizes are in Measurements.

arm_mat_vec_mult_f32 computes pDst = M * pVec; the output must not overlap either input. The upstream-tracking fork’s patch masks the Helium kernel’s vector loads at the end of each row so that lanes past the row are not read (predicated loads), so the kernel reads nothing past the matrix (the same holds for the Q7, Q15 and Q31 kernels). For matrices larger than the data cache, cycles depend on where the matrix is stored: on Apollo510, a 160 by 160 matrix took 26,993 cycles from DTCM (data tightly coupled memory) and 53,671 from shared SRAM (GCC 14.2.1, -O2, 96 MHz; see Measurements).

Arm documents that its vectorized kernels may read up to 3 words past the end of a buffer, and asks callers to ensure that the end of each buffer plus that margin lies inside a readable memory region. The reads are harmless unless the margin crosses into memory that faults, such as a region protected by the memory protection unit (MPU). The upstream-tracking fork removes such reads from the matrix-vector kernels and from the Q15 and Q31 real-FFT coefficient tables, each checked with an MPU guard directly after the buffer. It also removes the read past the end of the in-place buffer in the last radix-4 stage of the Helium complex FFTs (fork pull request #19): at the qualified commit, arm_cfft_f32, arm_cfft_q31 and arm_cfft_q15 access nothing outside the buffer at every power-of-two length from 16 to 4096 in either direction, measured on the Corstone-300 model with an MPU guard at the end and at the start of the buffer. It also loads the final partial block of the f32/u32, fixed-point and f16 vector kernels under the tail predicate (fork pull requests #14, #15, #16), replaces the vld2q tails of three f16 kernels with predicated de-interleaving gathers and loads the f32 matrix addition and subtraction under the block predicate (#18), and predicates the state loads of the FIR decimators and the input-copy load of the Q15 decimator (#22, #23); the f32 FIR kernel is described above (#9). The remaining Helium kernels keep Arm’s requirement.

DISABLEFLOAT16 removes the f16 functions and their declarations. ARM_MATH_AUTOVECTORIZE, ARM_MATH_MVE_FLOAT16 and ARM_MATH_NEON change which declarations and instance layouts the headers present. heliaDSP’s CMake makes each of these a usage requirement (a compile setting that CMake applies to the library and to every target that links it) of CMSISDSP, so the library and every target that links it compile with the same set. Code that compiles a CMSIS-DSP header outside those targets, or links a library built elsewhere, must reproduce the same definitions; a mismatch changes structure layouts without a diagnostic.