Skip to content

olo_fix_inv

Back to Entity List

Status Information

VHDL Source: olo_fix_inv
Bit-true Model: olo_fix_inv

Description

This entity calculates the inverse of the input:

Out_Result = 1/In_Data

The absolute value of the input is normalized (blue) into the range [1, 2), inverted through a table based piecewise linear approximation (red) and the normalization is reverted on the result (green):

Formula

Compared to olo_fix_bin_div it requires less LUT logic and its latency does not grow with the output width, but it requires a ROM and a multiplier.

Because the normalization covers the full input range, the approximation only has to cover one octave. Hence 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.

Latency of this entity is constant, see Latency. 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

Inputs that are powers of two are inverted exactly (as far as the result is representable in OutFmt_g). Their normalized value is exactly 1.0, for which the approximation returns exactly 1.0.

An input of zero delivers the same result as the smallest non-zero input, which is the largest result the entity can produce. No error is flagged. With the default Saturate_g = "Sat_s" and an output format that cannot represent 2^InFmt_g.F, this result saturates to the maximum value of OutFmt_g.

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 21 clock cycles, independently of the input format.

Generics

Name Type Default Description
OutFmt_g string - Output format. Must be signed if InFmt_g is signed.
InFmt_g string - Input format. Any format that is at least two and at most 256 bits wide.
PrecisionBits_g positive 18 Number of fractional bits of the inversion approximation. Must be 10, 14, 18 or 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 Inverse 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.

Block Diagram

The normalization shift N is the number of leading zeros of the absolute value of the input. 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 shift count and the sign of the input are delayed to the point where they are needed by olo_base_latency_comp.

The leading one of the normalized value 1+m is known, hence it is dropped and only the mantissa fraction m in the range [0, 1) is passed on. The function approximated is 1/(1+m), which covers the range (0.5, 1.0]. As a result the whole range of the approximation is used.

The approximation is implemented by the internal entity olo_fix_private_lin_approx_inv. It contains the inversion tables (one per supported PrecisionBits_g value) and instantiates olo_fix_lin_approx_calc for the piecewise linear interpolation.

Reverting the normalization shifts the result left by N. 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 negated for negative inputs and rounded/saturated to OutFmt_g by olo_fix_resize.

Precision

PrecisionBits_g selects the number of fractional bits the inversion 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 22 bit
14 128 x 29 bit
18 512 x 36 bit
20 1024 x 35 bit

Because the normalization makes the accuracy independent of the magnitude of the input, the error is defined relative to the absolute value of the result:

Error