olo_fix_sqrt¶
Status Information¶
VHDL Source: olo_fix_sqrt
Bit-true Model: olo_fix_sqrt
Description¶
This entity calculates the square root. It does so based on piecewise linear approximation (olo_fix_lin_approx_calc). It can process one sample per clock cycle but has a fixed latency. It is optimal for pipelined processing chains with high throughput.
The input is normalized (blue) into the range [0.25, 1), the square root is taken through a table based piecewise
linear approximation (red) and the normalization is reverted on the result (green):

Because the square root halves the exponent, the normalization shift N must be even - which is why the
approximation covers the two octaves [0.25, 1) and not just one.
Because the normalization maps the full input range to a relatively small range for approximation, a relatively small table delivers accurate results over the full range of any input format. The precision of the approximation is selected through PrecisionBits_g, see Precision.
The entity is fully pipelined, hence it accepts one input sample per clock cycle. As a result, back-pressure is not supported.
For details about the fixed-point number format used in Open Logic, refer to the fixed point principles.
Corner Cases¶
An input of zero delivers exactly zero.
Powers of four are not inverted exactly. The relative error stays within the bounds given under Precision for all inputs.
Latency¶
Latency is not guaranteed to be constant across different versions. It's therefore best to design user logic to be independent of the latency of this block (e.g. through olo_base_latency_comp).
In the current version the latency is 19 clock cycles, independently of the input format.
Generics¶
| Name | Type | Default | Description |
|---|---|---|---|
| OutFmt_g | string | - | Output format |
| InFmt_g | string | - | Input format. Must be unsigned and at least 5 and at most 256 bits wide. |
| PrecisionBits_g | positive | 18 | Number of fractional bits of the square root approximation. Allowed values: 10, 14, 18, 20 |
| MemStyle_g | string | "auto" | Resource control for the table (auto, block or distributed) |
| Round_g | string | "NonSymPos_s" | Rounding mode of the output stage |
| Saturate_g | string | "Sat_s" | Saturation mode of the output stage |
Interfaces¶
Control¶
| Name | In/Out | Length | Default | Description |
|---|---|---|---|---|
| Clk | in | 1 | - | Clock |
| Rst | in | 1 | - | Reset input (high-active, synchronous to Clk) |
Input Data¶
| Name | In/Out | Length | Default | Description |
|---|---|---|---|---|
| In_Valid | in | 1 | '1' | AXI4-Stream handshaking signal for In_Data |
| In_Data | in | width(InFmt_g) | - | Input data Format: InFmt_g |
Output Data¶
| Name | In/Out | Length | Default | Description |
|---|---|---|---|---|
| Out_Valid | out | 1 | N/A | AXI4-Stream handshaking signal for Out_Result |
| Out_Result | out | width(OutFmt_g) | N/A | Square root of In_Data Format: OutFmt_g |
Details¶
Architecture¶
The figure below shows the architecture of the entity. The colors of the signal labels match the formula given in the Description.

The normalization shift N is derived from the number of leading zeros of the input. Because the compensation shift
is half of the normalization shift, normalization shift must be even, which is automatically enforced by the logic
itself. The input value is always normalized into the range [0.25, 1) after the shift.
Normalization and its reversal are both implemented by olo_base_dyn_sft, which spreads the barrel shifter over two pipeline stages to achieve good timing. The output shift is N/2, because the square root halves the exponent. It is delayed to the point where it is needed by olo_base_latency_comp.
The approximation is implemented by the internal entity olo_fix_private_lin_approx_sqrt. It contains the square
root tables (one per supported PrecisionBits_g value) and instantiates
olo_fix_lin_approx_calc for the piecewise linear interpolation. Below 0.25 the
tables contain zeros, which makes the square root of a zero input exactly zero without any extra logic.
Reverting the normalization shifts the result right by N/2. The remaining constant factor (which depends only on the number of integer bits of the input format) is applied by reinterpreting the number format of the shifted result, hence it is pure wiring and does not cost any logic. Finally the result is rounded/saturated to OutFmt_g by olo_fix_resize.
Precision¶
PrecisionBits_g selects the number of fractional bits the square root approximation delivers. One table exists per supported value, hence only the values listed below are allowed - any other value leads to an error:
| PrecisionBits_g | Table size |
|---|---|
| 10 | 32 x 16 bit |
| 14 | 128 x 23 bit |
| 18 | 512 x 29 bit |
| 20 | 1024 x 33 bit |
Because the normalization makes the accuracy independent of the magnitude of the input, the error is defined relative to the result:

For very small outputs that are represented by less than PrecisionBits_g, the relative error can be larger, but the absolute error remains below 1 LSB.