Main Content

rSqrt

Implement control-signal-based reciprocal square root function

Since R2020b

  • HDL Math rSqrt Block

Description

HDL Math rSqrt Block

The rSqrt block performs the reciprocal square-root operation on the input data signal. The block has control signals that indicate whether the input and output data are valid. You can also specify the number of iterations of the algorithm and the latency strategy.

To use this block in your Simulink® model, open the HDLMathLib library by entering this command in the MATLAB® Command Window:

open_system("HDLMathLib")

Latency Considerations

You can simulate the rSqrt block with latency. This block is a masked subsystem that contains the LumpLatencyMATLAB Function block. The subsystem uses this MATLAB Function block to compute the latency based on the Number of iterations. To view the function that computes the latency of the block, open the LumpLatency block in the masked subsystem. To view inside the mask, click the ⇩ icon on the block.

The block supports four latency modes, Min, Max, Custom and Zero. To learn more about latency values of rSqrt block, see Latency strategy.

Examples

Limitations

The rSqrt block has following HDL code generation limitations:

  • The block does not support floating-point data types, such as half, single, and double.

  • The block does not support bus inputs.

  • Cannot be used in Synchronous Subsystem.

  • Does not support resource sharing optimization.

Ports

Input

expand all

Input signal to calculate the reciprocal square root.

Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point

Input control signal that indicates whether the input signal is valid.

Data Types: Boolean

Output

expand all

Output signal that is the reciprocal square root of the input signal.

Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point

Output control signal that indicates whether output signal is valid.

Data Types: Boolean

Parameters

expand all

Select the architecture for rSqrt block.

Programmatic Use

Block Parameter: architecture
Type: character vector
Values: RecipSqrtNewtonSingleRate
Default: 'RecipSqrtNewtonSingleRate'

Specify the number of iterations for rSqrt algorithm.

Programmatic Use

Block Parameter: numOfIterations
Type: character vector
Values: Integer values
Default: '3'

Specify whether to map the blocks in your design to minimum, maximum, minimum, custom, or zero latency. For more information, see LatencyStrategy. The latency of the block is determined based on the Number of iterations.

Latency StrategyLatency Value (L)
Max

L = (N * 4) + 5

where N is the value of the Number of iterations parameter.

Min

L = 2 + ceil(((N * 4) - 1) / 3)

Custom

Using custom latency mode, you can specify the latency value for the block by entering the value between zero and maximum latency in Custom latency parameter.

ZeroThe latency of the block is 0.

Programmatic Use

Block Parameter: latencyMode
Type: character vector
Values: 'Max' | 'Min' | 'Custom' | 'Zero'
Default: 'Max'

When you set Latency strategy to Custom, use this parameter to specify the custom latency value. The latency must be a nonnegative integer in the range [0, L], where L is the maximum latency value of rSqrt block. For more information, see CustomLatency.

Dependency

To use this parameter, set Latency strategy to Custom.

Programmatic Use

Block Parameter: customLatencyValue
Type: Integer
Values: 0 to Max latency
Default: 0

Specify the output data type. The data type can be inherited or specified directly.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'Inherit: Inherit via back propagation' | 'Inherit: Same as first input' | 'int8' | 'uint8' | int16 | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | fixdt(1,16,0) | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

ActionReasons for Taking This ActionWhat Happens for OverflowsExample

Select this check box.

Your model has possible overflow, and you want explicit saturation protection in the generated code.

Overflows saturate to either the minimum or maximum value that the data type can represent.

The maximum value that the int8 (signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box selected, the block output saturates at 127. Similarly, the block output saturates at a minimum output value of -128.

Do not select this check box.

You want to optimize efficiency of your generated code.

You want to avoid overspecifying how a block handles out-of-range signals. For more information, see Troubleshoot Signal Range Errors.

Overflows wrap to the value that is representable by the data type.

The maximum value that the int8 (signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box cleared, the software interprets the overflow-causing value as int8, which can produce an unintended result. For example, a block result of 130 (binary 1000 0010) expressed as int8, is -126.

When you select this check box, saturation applies to every internal operation on the block, not just the output or result. Usually, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Programmatic Use

Block Parameter: SaturateOnIntegerOverflow
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Specify the rounding mode for fixed-point operations. For more information, see Rounding Modes.

Programmatic Use

Block Parameter: RndMeth
Type: character vector
Values: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'
Default: 'Floor'

Tips

The block supports HDL code generation using HDL Coder™. HDL Coder provides additional configuration options that affect HDL implementation and synthesized logic. For more information, see HDL Block Properties.

Version History

Introduced in R2020b