Signal-processing algorithms are often developed in floating point and then implemented on FPGAs in fixed point [1]. Floating-point operators cost significant resources and many cycles of latency on an FPGA, and Kastner, Matai and Neuendorffer recommend avoiding them unless the accuracy requirement demands it [1]. The standard flow is to get a floating-point model correct first and then convert it, a step they describe as non-trivial and best left to the designer because it trades accuracy for cost [1].
This article covers the decisions in that conversion: the format of each signal, the noise each rounding step adds, what happens on overflow, and how wide each stage must be. It ends with a 32-tap FIR filter sized by hand and mapped onto an AMD DSP48E2 slice.
Formats and notation
A fixed-point number is an integer with an implied binary point. In two’s complement, the most significant bit carries a negative weight, and widening a signed number copies the sign bit into the new upper bits, which is called sign extension [1]. The format must be documented, because after a multiplication the result has to be renormalized to the right binary point [1].
The common shorthand is Q notation, which gives the number of fractional bits. Q15 has 15 fractional bits, usually in a 16-bit signed word, and covers the interval [-1, 1) [1]. HLS libraries describe the same thing by total width and integer bits. Vivado HLS’s ap_fixed<W,I> takes the overall width W and the number of integer bits I [1], and hls4ml writes the same pair as <X,Y> [2].
Two arithmetic rules drive every word-length decision. Adding two N-bit numbers needs N+1 bits to avoid overflow, and multiplying two N-bit signed numbers needs 2N bits [1]. For unequal widths the product width is the sum of the two widths, which is why the DSP48E2’s 27-bit by 18-bit multiplier produces a 45-bit result [3].
Quantization noise
Each time a signal is rounded to a step size q, it picks up an error. For an ideal N-bit converter, Kester models that error as uniformly distributed over ±q/2 and uncorrelated with the signal [4]. Under that model the mean-square error is q²/12 and the RMS error is q/√12 [4]. For a full-scale sine wave this gives the familiar ideal signal-to-noise ratio:
SNR = 6.02N + 1.76 dB, measured over the band from DC to fs/2 [4].
Two details from the same tutorial matter in FPGA work. The noise is spread over the whole Nyquist band, so filtering to a narrower bandwidth BW adds a process gain of 10 log10(fs / 2BW) [4]. And the model assumes the error is uncorrelated with the input. When the sampling clock and signal are harmonically related, the energy concentrates in harmonics, although the RMS value stays near q/√12 [4].
Kester derives the model for analog-to-digital converters [4]. He notes that the approximation is adequate for signals that span more than a few LSBs [4]. We apply the same model to rounding steps inside the datapath, under the same condition.
Overflow: wrap or saturate
Overflow happens when a result is larger than the format can hold. The simplest hardware response is to drop the upper bits, called wrapping [1]. In two’s complement, wrapping can turn a large positive value into a negative one [1]. In a filter or control loop we consider that sign flip a worse failure than a clipped value.
Saturation clamps the result to the largest or smallest representable value instead. It needs extra logic to detect the out-of-range case, and we treat it as the safer default wherever a signal leaves a wide accumulator for a narrow output. The DSP48E2 supports this directly: its pattern detector can flag overflow and underflow in a sequential accumulator, using a redundant sign bit that reduces the usable output to 47 bits [3].
Rounding: truncation is biased
Dropping fractional bits rounds toward negative infinity, so every result moves slightly in the same direction [1]. In an accumulator or a long filter chain that bias adds up. Rounding to nearest, with ties going to the even value, always picks the nearest representable number, and its errors tend to cancel in sums [1]. This is called convergent rounding. The DSP48E2 supports symmetric rounding of a product through its C input, and convergent rounding through the C input together with its pattern detector [3].
Word-length growth in FIR filters and MACs
An N-tap FIR filter computes each output as the sum of N products of input samples and coefficients [5]. Applying the two width rules:
- Each product of a B_x-bit sample and a B_h-bit coefficient needs B_x + B_h bits.
- Summing N such products adds up to ceil(log2 N) bits in the worst case, one bit for each doubling of the number of terms.
The worst-case bound assumes every product reaches full scale with the same sign. If the coefficients are known, the tighter bound is |y| ≤ max|x| · Σ|h_k|, and the growth is ceil(log2 Σ|h_k|) bits beyond the product’s range. When Σ|h_k| is much smaller than N, the actual growth is far below the worst case. This bound is our own reasoning from the triangle inequality, so check it against the real coefficient set before trimming bits.
A worked example
Take a 32-tap FIR filter with 16-bit Q15 input samples and 18-bit coefficients with 17 fractional bits (Q17), both covering [-1, 1). All numbers below are our own arithmetic.
Quantizing one sample and one coefficient.
- Sample x = 0.3: round(0.3 × 2^15) = round(9830.4) = 9830. Stored value 9830 / 32768 = 0.29998779. Error −1.22 × 10^-5, inside the ±q/2 = ±1.53 × 10^-5 bound.
- Coefficient h = 0.7: round(0.7 × 2^17) = round(91750.4) = 91750. Stored value 91750 / 131072 = 0.69999695. Error −3.05 × 10^-6.
The product. 9830 × 91750 = 901,902,500. The product has 16 + 18 = 34 bits and 15 + 17 = 32 fractional bits, so its value is 901,902,500 / 2^32 = 0.20999054. Two integer bits remain, and they are needed: (−1) × (−1) = +1 does not fit in one sign bit.
The accumulator. Thirty-two products of magnitude up to 1 can sum to 32. Growth is log2(32) = 5 bits, so the accumulator needs 34 + 5 = 39 bits, with 7 integer bits and 32 fractional bits.
Mapping to the DSP48E2. The slice’s multiplier takes a 27-bit operand from the A port and an 18-bit operand from the B port [3]. We put the 16-bit samples on A, sign-extended to 27 bits, and the 18-bit coefficients on B. The accumulator is 48 bits wide [3]. With a 34-bit product, that leaves 48 − 34 = 14 guard bits, enough for 2^14 = 16,384 full-scale products before overflow is possible. This matches the pattern in the user guide, which gives 3 guard bits for a full 27 × 18 product and 12 guard bits when A is limited to 18 bits [3]. Our 32 taps need 5 of the 14. If a design ever needs more than the guard bits allow, two slices can form a 96-bit accumulator with the MACC_EXTEND feature [3].
Back to 16 bits. The output must return to Q15. That drops 32 − 15 = 17 fractional bits and 7 − 1 = 6 integer bits. Taking our single product as the output value for illustration, 901,902,500 / 2^17 = 6880.97:
- Truncation gives 6880, or 0.20996094, an error of 2.96 × 10^-5 against the exact product, close to one full output LSB (3.05 × 10^-5).
- Rounding to nearest gives 6881, or 0.20999146, an error of 9.2 × 10^-7.
The six integer bits are dropped with saturation: any accumulator value at or above 1 becomes 32767 / 32768, and any value below −1 becomes −1.
Noise budget. At the Q15 output, q = 2^-15 = 3.05 × 10^-5, so the RMS rounding noise under the uniform model is q/√12 = 8.81 × 10^-6. For a full-scale sine, the formula gives 6.02 × 16 + 1.76 = 98.08 dB [4]. If the samples came from an ideal 12-bit ADC, its own limit is 6.02 × 12 + 1.76 = 74.0 dB [4]. Adding the two noise powers gives a combined 73.98 dB, so the 16-bit output costs about 0.02 dB. A 14-bit output (86.04 dB on its own) would bring the combined figure down to 73.74 dB, a loss of about 0.26 dB. A 20-bit output would recover less than 0.02 dB.
Using the DSP slice well
Cascade, do not tree. In a direct-form FIR with an adder tree, the tree depth scales with log2 of the tap count, and the fabric adders are usually the performance bottleneck [3]. The DSP48E2 instead passes partial sums up a column on its dedicated 48-bit cascade, which the user guide states improves both power and speed [3]. The cascade length is limited by the number of DSP slices in a column [3], and the coefficients and samples must be delayed to line up with the staggered partial sums [3].
Use the pre-adder for symmetric filters. Symmetric coefficients let the filter add the two samples that share a coefficient before multiplying, roughly halving the multipliers [5]. The DSP48E2’s 27-bit pre-adder exists for this case [3]. On a Stratix IV device, a 51-tap symmetric filter in DSP blocks used 3.0 times less area than the same filter in soft logic with fixed coefficients, and ran at 510 MHz against 248 MHz [5].
Check whether the tools used the features. Vendor tools map a multiplication onto a DSP block automatically, but generally do not use accumulation or the systolic FIR registers unless the designer instantiates the block in the right mode [5].
Watch the precision steps. In the hls4ml study, DSP usage rose in steps as fixed-point precision increased, which the authors attribute to the precision of the DSP blocks [2]. A multiplication wider than the DSP ports has to be split across more than one slice, and the DSP48E2 provides a 17-bit shift on its cascade for building such wider multipliers [3].
Narrow additions can use SIMD. With the multiplier unused, the DSP48E2’s 48-bit adder can run as two 24-bit or four 12-bit adders or accumulators [3].
A checklist for each signal
- Write down the Q format of every signal, including intermediate products.
- Bound the growth of every sum, with the worst case and with the real coefficients.
- Choose rounding or truncation at each narrowing step, and know which one the tool applied.
- Saturate where a wide value enters a narrow port, unless the wrap behavior is intended.
- Budget the noise added by each rounding step against the input’s own noise floor.
- Compare the final widths with the DSP port widths of the target device.
Where Takumetra can help
We can convert a floating-point model to a bit-true fixed-point model, size each stage from a noise budget, and map the result onto the target device’s DSP slices. We can also review an existing DSP pipeline for overflow risk, rounding bias and DSP use. See our FPGA services for the engagement types.