Main Content

Guidelines for WritingMATLABCode to Generate Efficient HDL and SystemC Code

MATLABDesign Requirements for HDL and SystemC Code Generation

When you generate HDL or SystemC code from your MATLAB®design, you are converting an algorithm into an architecture that must meet hardware area and speed requirements.

Your MATLAB design has these requirements:

  • MATLAB code within the design must be supported by HDL or SystemC code generation.

  • Inputs and outputs must not be matrices or structures.

If you are generating code at the command line, verify your code readiness for code generation by using this command:

coder.screener('design_function_name')
If you use the HDL Workflow Advisor to generate code, this check runs automatically.

For a MATLAB language support reference, including supported functions from Fixed-Point Designer™, seeFunctions Supported for HDL and SystemC Code Generation.

Guidelines for WritingMATLABCode

For more efficient HDL code and faster code generation, design your MATLAB code by using these best practices:

  • Serialize your input and output data. Parallel data processing structures require more hardware resources and a higher pin count.

  • Use add and subtract algorithms instead of algorithms that use functions, such as sine, divide, and modulo. Add and subtract operations use fewer hardware resources.

  • Avoid large arrays and matrices. Large arrays and matrices require more registers and more RAM for storage.

  • Convert your code from floating-point to fixed-point. Floating-point data types are inefficient for hardware realization. HDL Coder™ provides an automated workflow for floating-point to fixed-point conversion.

  • Unroll loops to increase speed at the cost of higher area. Unroll fewer loops and enable the loop streaming optimization to conserve area at the cost of lower throughput.

For more efficient SystemC code and faster code generation, design your MATLAB code according to these best practices:

  • Serialize your input and output data. Parallel data processing structures require more hardware resources and a higher pin count.

  • Use add and subtract algorithms instead of algorithms that use functions, such as sine, divide, and modulo. Add and subtract operations use fewer hardware resources.

  • Avoid large arrays and matrices. Large arrays and matrices require more registers and RAM for storage. Whenever you need to use large arrays for memory, consider using the RAM mapping optimization to map these memories to RAM.

  • Convert your code from floating-point to fixed-point. Floating-point data types are inefficient for hardware realization. HDL Coder provides an automated workflow for floating-point to fixed-point conversion.

  • Unroll loops to increase speed at the cost of higher area.

  • Modularize the design into subfunctions as much as possible. Doing so improves the readability of the code and makes it easier to specify constraints, such ascoder.hdl.constrainlatency, on a particular region of code.

  • 使用一个从零开始的索引方案其次是数组access with the addition of 1 as MATLAB uses 1-based indexing: for example, usearrayVar(index+1)instead ofarrayVar(index). The extra indexing logic does not need to be inserted by the code generator, thereby reducing overall area.

See Also

Apps

Objects

Functions

Related Topics