A DSP algorithm starts as a formula tested in floating point. There, a square root or a division costs one line of code. On an FPGA the algorithm must become fixed-point logic that runs at one sample per clock, and the same square root has to be designed. The work in between has three parts: choosing word lengths, replacing operations the fabric does not have, and verifying that the hardware computes exactly what the model computes. This article follows one small block through that flow and measures what each choice costs.
The workflow
Fig. 1 shows a typical flow for implementing a DSP block on an FPGA. The algorithm is first developed in floating point, typically double precision in Python or MATLAB, where word lengths, rounding and overflow can still be ignored. The fixed-point model comes next. It fixes the format of every signal and every rounding and saturation step, and it defines the performance of the final design. It becomes the golden reference model.
The implementation follows either in HLS or as hand-written RTL. In HLS, the C++ code is checked in C simulation (C-sim), turned into RTL by C synthesis, and checked again in C/RTL co-simulation. In both cases, RTL verification requires the outputs to be bit-accurate to the golden model. Synthesis and implementation then report the resources and the timing, and the hardware test closes the loop on the board. Two feedback paths run through the flow: the error against the float model sets the word lengths, and resources and timing can send the design back to other word lengths or another architecture.
The block: z/|z|
The block scales a complex sample to unit magnitude and keeps its phase:
It is used as a limiter ahead of phase and frequency detectors and in clipping for peak-to-average power reduction. It also computes the phase-only weights of beamformers and equal-gain combiners.
The specification here is typical. and are signed 16-bit samples in Q1.15, and so is the output. Q1.15 means a sign bit and 15 fractional bits, covering ; one LSB is . One sample enters every clock. The worst-case error in either output component must stay below one LSB over all inputs. An input of maps to zero.
On a CPU the block is the formula:
std::complex<float> normalize_cpu(std::complex<float> z) {
const float p = std::norm(z); // re^2 + im^2
return p > 0.0f ? z * (1.0f / std::sqrt(p)) : std::complex<float>{};
}
On the test vectors, single precision is within 0.005 LSB of the exact result. The processor has a multiplier, a square-root unit and a divider. An FPGA has adders, look-up tables (LUTs), small hardware multipliers (DSP slices) and block RAM. The square root and the division must be built from these. Each additional bit of accuracy widens registers, adders and multipliers, and so costs logic.
From float to fixed point
The float model defines the intended behaviour. The fixed-point model defines the behaviour the hardware will have. Writing it means making every implicit choice explicit: the format of each intermediate value, where rounding happens, and what happens at the edges.
Here the output is rounded once, half up, and then saturated. Saturation is needed because +1.0 is not representable in Q1.15 and must become 32767. Rounding half up is not symmetric, and neither is the floor of an arithmetic shift. For roughly one sample in ten, the result for therefore differs from the negated result for by one LSB. This stays within the error bound.
The fixed-point model is written in Python with integer arithmetic. It is the golden reference model: the HLS code and the RTL must be bit-accurate to it, not to the float model.
One property of the block shapes both designs below: does not depend on the scale of . Shifting and left by the same number of bits leaves the result unchanged. The precision available to the arithmetic improves. Architecture A normalises the power before its table lookup. Architecture B normalises and before its first micro-rotation.
The two operations that the fabric lacks can also be merged. Instead of a square root followed by a division,
so one reciprocal square root replaces both. The CPU version above already computes it this way. Tables with interpolation and Newton–Raphson iteration compute it directly [3]. Architecture A uses a leading-zero normalisation and an interpolated table. Architecture B uses CORDIC [1], [2]. It avoids the reciprocal square root and rotates onto the unit circle instead.
Architecture A: normalise, look up, interpolate
The first design computes the reciprocal square root with a table, in four steps:
- The power , exact in 32 bits.
- An even shift : the leading-zero count of , rounded down to an even number. Then lies in , and lies in . The shift is even so that the square root of is again a shift, by .
- from a table. The top nine bits of address it, and the next twelve bits interpolate linearly. Since , the top two bits are never 00, so only 384 of the 512 addresses occur. The result has 17 fractional bits.
- The products and , shifted right by with a single rounding. The 18 collects the fixed scalings of , and the Q1.15 output (); the undoes the normalisation.
Steps 2 and 4 are the normalisation and its undo; only step 3 approximates the function.
Because of the normalisation, the table only has to cover between 1/4 and 1, whatever the input. Accuracy then comes from interpolation. The entry below the address alone is off by up to 1,018 LSB of . Interpolating to the next entry brings the error down to 2.4 LSB, at the cost of one small multiplier (Fig. 2). Without interpolation, the same accuracy would take more than 100,000 entries. Each of the 384 entries stores a 19-bit base value and a 10-bit slope.
The table size follows from the error budget. Fig. 3 (left) sweeps it, with the worst case taken over all inputs. Nine address bits (384 entries) is the smallest table tested that keeps the complete block below one output LSB.
In HLS C++ the four steps follow the description closely. The types carry explicit widths, and the
rounding is written out. The pragmas request distributed ROM (LUTRAM) for the tables and an initiation
interval (II) of one, so a new sample enters every clock. The rounding helper round_sat and the
generated tables are not shown:
void normalize_hls(sample_t i, sample_t q, sample_t &x, sample_t &y) {
#pragma HLS PIPELINE II=1
#pragma HLS BIND_STORAGE variable=RSQRT_BASE type=rom_1p impl=lutram
#pragma HLS BIND_STORAGE variable=RSQRT_SLOPE type=rom_1p impl=lutram
// 1. power, exact: |I|, |Q| <= 2^15, so P <= 2^31
ap_uint<32> p = ap_uint<32>(i * i) + ap_uint<32>(q * q);
if (p == 0) { x = 0; y = 0; return; }
// 2. normalise by an even shift: m = P << s lies in [2^30, 2^32)
ap_uint<5> s = p.countLeadingZeros() & 0x1E;
ap_uint<32> m = p << s;
// 3. table lookup with linear interpolation: r ~ 2^17 / sqrt(m / 2^32)
ap_uint<9> k = m(31, 23);
ap_uint<12> f = m(22, 11);
ap_uint<19> r = RSQRT_BASE[k - 128] - ((RSQRT_SLOPE[k - 128] * f + 2048) >> 12);
// 4. undo the normalisation: x = i * r / 2^(18 - s/2)
ap_uint<5> sh = 18 - (s >> 1);
x = round_sat(i * r, sh);
y = round_sat(q * r, sh);
}
Unlike the CPU version, this code describes hardware. Each declared width sets the size of a register or
an adder, and each operator is implemented as logic. The approximation is written out instead of being
called from a library. HLS accepts i / hls::sqrt(p) directly and synthesises it [4]. It becomes a generic
square-root implementation followed by a full-width divider, whose size, latency and error the library
decides. The table version replaces both with a 384-entry table, one small multiplier for the
interpolation, and shifts.
Architecture B: CORDIC without the angle
CORDIC computes rotations with additions and shifts only [1], [2]. In vectoring mode it rotates onto the real axis through micro-rotations by . Each step rotates towards the real axis: upwards when the imaginary part is negative, downwards otherwise. The signs encode the angle of . A common next step accumulates that angle and feeds it to a second CORDIC in rotation mode, which turns it into and .
The angle itself is not needed. Apply the same sequence of micro-rotations in the opposite direction to the vector . Each micro-rotation also stretches the vector slightly. is the product of these stretches, and starting from cancels it. The result is , with no angle register and no arctangent table. CORDIC arrays for QR decomposition pass direction bits between stages in the same way. Here each pipeline stage applies one micro-rotation to both vectors with a shared sign. That takes four adder/subtractors; the shifts are by constants and cost only wiring.
wire neg = yj[W-1]; // d_j = +1 when y < 0
// shift first, as signed wires: inside an unsigned expression >>> would be a logical shift
wire signed [W-1:0] xsh = xj >>> j, ysh = yj >>> j, ush = uj >>> j, vsh = vj >>> j;
// a - b written as a + ~b + 1, so each output needs one carry chain
wire [W-1:0] sub = {W{neg}}, add = {W{~neg}};
wire [W-1:0] c_sub = {{(W-1){1'b0}}, neg}, c_add = {{(W-1){1'b0}}, ~neg};
always @(posedge clk) begin
xs[(j+1)*W +: W] <= xj + (ysh ^ sub) + c_sub; // neg ? x - y' : x + y'
ys[(j+1)*W +: W] <= yj + (xsh ^ add) + c_add; // neg ? y + x' : y - x'
us[(j+1)*W +: W] <= uj + (vsh ^ add) + c_add; // same signs, reversed,
vs[(j+1)*W +: W] <= vj + (ush ^ sub) + c_sub; // on (1/K, 0)
end
The fixed-point model required two extra steps. CORDIC converges only for angles within about ±99.9°. A rotation by ±90° therefore first brings into the right half-plane, and the output undoes it.
The second step matters more, because without it small inputs lose their angle. A small input, for example , holds too few bits for the shifts to act on. After a few stages its components shift to zero, and the remaining signs no longer depend on the angle. The fix is the scale invariance again. and are shifted left together until the larger of the two reaches the top of its range. This keeps the error below one LSB at every magnitude (Fig. 4).
With 18 micro-rotations and 8 guard bits, CORDIC meets the same error budget as the table design (Fig. 3, right). Its datapath is 28 bits wide: 16 bits of input, one bit of sign growth, 8 guard bits and 3 bits for the CORDIC gain. Both fixed-point models were checked exhaustively over all inputs. The check uses C++ ports of the models, which match the Python models on every test vector. The worst-case error in either component is 0.795 LSB for architecture A and 0.797 LSB for architecture B. The RMS error is 0.296 and 0.306 LSB, against 0.289 LSB for ideal rounding. The saturation of +1.0 to 32767 is not counted as error, since no 16-bit design can avoid it.
HLS or RTL?
Both architectures are also written by hand in Verilog. Design A becomes a six-stage pipeline: squares, normalisation, table read, interpolation, multiplication and rounding. Design B becomes twenty stages: normalisation and pre-rotation, eighteen identical micro-rotations, and the output rounding.
In HLS, the scheduler decides how many pipeline stages to insert for a given clock target. In RTL, each stage is written explicitly. For this block, HLS shortened the exploration of word lengths and table sizes, with verification at C-simulation speed. Hand-written RTL gave exact control over the pipeline stages and over which operations map to DSP slices. The HLS C simulation of A and the RTL of A are both bit-accurate to the golden model.
RTL verification
RTL verification requires the RTL outputs to be bit-accurate to the golden reference model: equal on every bit, not within a tolerance. The error analysis already lives in the fixed-point model. Any difference in the RTL is therefore a bug. The testbench, written in cocotb [5], streams one vector into the pipeline every clock and checks every output sample:
if str(dut.out_valid.value) == "1":
i, q, ex, ey = pending.popleft()
gx, gy = dut.x.value.to_signed(), dut.y.value.to_signed()
if (gx, gy) != (ex, ey):
mismatches += 1
The stimulus covers every octave of magnitude equally, from one LSB to full scale, with uniform angles. Corner cases are added: full-scale negative values, single-LSB inputs and zero. On 100,015 vectors, both RTL designs and the HLS C simulation are bit-accurate to the golden model.
The testbench catches small changes. Each change below was injected alone into a copy of the RTL:
- A one-LSB change in the interpolation rounding constant of design A: 921 of 100,015 samples flagged.
- The output rounding removed: 71,739 samples flagged in design A and 70,323 in design B.
- The sign of the last micro-rotation of design B inverted: 57,762 samples flagged.
It also detected an actual design error during this work. The first add/subtract version of the CORDIC stage mixed
signed and unsigned operands in one Verilog expression. This turned the arithmetic shift >>> into a
logical shift, and 100,014 of the 100,015 samples failed.
What it costs
| Latency (cycles) | LUT | Flip-flops | DSP48 | Block RAM | |
|---|---|---|---|---|---|
| A: table | 6 | 796 | 139 | 5 | 0 |
| B: CORDIC | 20 | 2,514 | 1,926 | 0 | 0 |
LUT counts include inverter cells (7 and 123) and exclude shift-register LUTs (6 and 4).
At one sample per clock, the multiplier-free CORDIC uses 3.2 times the LUTs and 14 times the flip-flops of the table design. Each of its eighteen stages holds four 28-bit adder/subtractors and their registers. Eighteen stages, each registering four 28-bit values, give about 2,000 flip-flops, close to the 1,926 reported. The 72 adder/subtractors account for most of the LUTs. The flip-flop ratio overstates the difference. Part of design A’s pipeline sits in the internal registers of its five DSP slices. These serve the two squares, the interpolation and the two final products.
CORDIC is the better choice when DSP slices are the scarce resource, as on small devices or in designs with many filters. An iterative CORDIC, one stage reused eighteen times, would be much smaller at an eighteenth of the throughput. The comparison also says nothing about the clock rate. Each CORDIC stage is a single 28-bit carry chain and will likely reach a higher Fmax than the multiply-add stages of design A.
Limitations
The resource figures come from Yosys, not from Vivado, and include no timing. Vivado may also place the 384-entry table in block RAM rather than LUTs. In design A, the clock rate is most likely limited by the single-cycle multiply-add, the leading-zero count with its barrel shift, or the rounding shift. In design B, the likely limits are the normalisation and pre-rotation stage and the output stage. The HLS code was not synthesised, and the RTL was verified in simulation on test vectors rather than exhaustively.
Summary
The FPGA version needed an error budget and two approximations of a reciprocal square root. It needed a normalisation that both architectures depend on. The fixed-point golden models were checked exhaustively, and both RTL designs were verified bit-accurate to them. Both designs keep the worst-case error below 0.8 LSB over all inputs. The table design does it with a third of the LUTs, at the cost of five DSP slices. “Multiplier-free” is not the same as cheap: the right architecture depends on which resource the rest of the design runs out of first. The code, models and testbenches are on GitHub.
References
[1] J. E. Volder, “The CORDIC trigonometric computing technique,” IRE Transactions on Electronic Computers, vol. EC-8, no. 3, pp. 330–334, 1959.
[2] R. Andraka, “A survey of CORDIC algorithms for FPGA based computers,” in Proc. ACM/SIGDA International Symposium on FPGAs, 1998, pp. 191–200.
[3] J.-M. Muller, Elementary Functions: Algorithms and Implementation, 3rd ed. Boston, MA, USA: Birkhäuser, 2016.
[4] AMD, Vitis High-Level Synthesis User Guide, UG1399, accessed October 2026.
[5] cocotb, a coroutine-based cosimulation library for writing testbenches in Python, https://www.cocotb.org.
[6] C. Wolf, Yosys Open SYnthesis Suite, https://yosyshq.net/yosys/.