Strip fixed-point scaling into a hw-supported integer type

Hw-aware version of the Data Type Conversion and Scaling Strip blocks.
26 Downloads
Updated 1 Feb 2018

View License

How to extract the stored integer inside a fixed-point signal and put it in a “hardware” type, such as int32? The attached example shows a way to get this done.
The Data Type Conversion block promises to do the job. In “SI” (Stored Integer) mode it will extract the desired value, but will place it in a data type with the same word length as the input. As a result, an input of ufix23_En5 will produce an output of ufix23, and an input of uint63_En10 will produce an output of uint63.

How to map the output to a hardware-supported integer? The Data Type Scaling Strip block promises to do something close. Its description says: “It maps the input data type to the smallest built-in data type that has sufficient bits to hold the input.” This is progress! It successfully turns ufix23_En5 into uint32. Alas, uint63_En10 produces 128!

This is happening because the block only maps input types to Simulink built-in sizes, of which there are 3: 8-bits, 16-bits, and 32-bits. All bigger types map to 128-bits, and hardware sizes are not an option.

The attached example shows how to put together a hardware-aware scaling strip. Let’s assume the example is designed to run on either an FPGA, or a CPU with 8-bit char, 16-bit short, 32-bit int, 32-bit long, and maybe a 64-bit long long. This block bases its decision on the production target as configured in the model’s hardware configuration, and offers the following functionality:
• If the production hardware is ASIC/FPGA, any word length from 1 to the (maximum supported) 128 is valid for use. This will mimic the behavior of the Data Type Conversion block.
• For CPUs, only data types available by the hardware can be used.
• If the input data type has more bits than the hardware supports, a multiple of the biggest type (multiword) will be used, not exceeding a maximum of 128 bits.
• If the hardware/compiler supports a long long type, make sure to check the “Support long long” checkbox to make this data type available to Simulink.
• If you have a non-traditional CPU, for example SHARC where all data types are 32-bit, the block will honor this and map all small types (such as 5-bit or 13-bit types) to int32 or unit32. If your DSP has a 40-bit long, int40 and uint40 will become valid output data types.
• The FPGA mode is also available for CPUs.

This block successfully produces a 64-bit output for our uint63_En10 case above. If long long is enabled, it will use this native type. If it is not enabled, the output will still be uint64, and the code generator will produce multiword operations (for two 32-bit words) to implement it.

To review and modify the model’s production target, click Ctrl-E to open the Model Parameters dialog, and select the Hardware Implementation pane on the left.

Cite As

Alexander Carmeli (2024). Strip fixed-point scaling into a hw-supported integer type (https://www.mathworks.com/matlabcentral/fileexchange/65918-strip-fixed-point-scaling-into-a-hw-supported-integer-type), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0