Main Content

Generate SIMD Code using Helium Instruction Set for ARM Cortex-M Processors

You can generate single instruction multiple data (SIMD) code from certain MATLAB® functions or Simulink® blocks using ARM® Helium instruction set for ARM Cortex®-M processors.

SIMD is a computing technique in which a single instruction processes multiple data simultaneously. Many modern processors have SIMD instructions that performs several operations such as addition or multiplication at once. For computationally intensive operations on supported functions, SIMD intrinsics can significantly improve the performance of the generated code on ARM Cortex-M processors.

ARM Helium instruction set is a vector extension for ARM v8.1-M architecture. The ARM Helium instruction set is based on SIMD operations. Processors with Cortex-M 55 and the latest processors after that support the ARM Helium instruction set.

Generate SIMD Code for MATLAB Functions

You can generate the SIMD code for MATLAB functions using MATLAB Coder app or MATLAB command line.

Using MATLAB Coder App

  1. On the MATLAB toolstrip Apps tab, under Code Generation, click the MATLAB Coder app icon. The app opens the Select Source Files page.

  2. In the Select Source Files page, enter or select the name of the entry-point function An entry-point function is a top-level MATLAB function from which you generate code. The app creates a project with the default name function_name.prj in the current folder.

  3. Click Next to go to the Define Input Types step. To generate code, you must define the input type for every entry-point. To automatically define input types, select a script that uses your entry-points.

  4. Instruct the app to automatically determine input properties by providing a script that calls the entry-point functions with sample inputs or specify the properties in the command window.

  5. Click Settings > Hardware. Set the Hardware board to None - Select device below.

  6. Set the Device vendor to ARM Compatible and Device type to ARM Cortex-M.

  7. Click Speed > Target Specific Optimization. Set Leverage target hardware instruction set extensions to Helium Integer Vector Extension (MVE-I) or Helium Vector Extension (MVE).

  8. Close the settings window.

  9. Click Generate Code.

To generate C code using MATLAB Coder app, see Generate C Code by Using the MATLAB Coder App.

Using MATLAB Command Line

  1. Create a code generation configuration object.

    cfg = coder.config('lib', 'ecoder', true);

  2. Set the verification mode to PIL and the target language to C.

    cfg.VerificationMode = 'PIL';
    cfg.TargetLang = 'C';

  3. Set the hardware board to ARM Cortex-M55 (MPS3).

    hw = coder.hardware("ARM Cortex-M55 (MPS3)");
    cfg.Hardware = hw;

  4. Set the instruction set extension to Helium Integer Vector Extension (MVE-I) or Helium Vector Extension (MVE).

    cfg.InstructionSetExtensions="Helium Vector Extension (MVE)";
    

  5. Optionally, set the OptimizeReductions property to 'on' to generate SIMD code for reduction operations such as sum and product functions.

    cfg.OptimizeReductions=true;

  6. Optionally, set the FMA property to 'on' to generate SIMD code for fused multiply-add operations.

    cfg.InstructionSetExtensionsConfig.FMA = true;

  7. To generate the code, use the codegen function.

    codegen('-config', cfg, 'function_name');

Generate SIMD Code for Simulink Blocks

You can generate SIMD code for Simulink blocks using the Simulink Coder app.

  1. Open the Simulink Coder app or the Embedded Coder app.

  2. Click Settings > Hardware Implementation.

  3. Set the Device vendor to ARM Compatible and Device type to ARM Cortex-M.

  4. Click Code Generation > Optimization. Under Target specific optimizations, set Leverage target hardware instruction set extensions to Helium Integer Vector Extension (MVE-I) or Helium Vector Extension (MVE).

  5. Optionally, enable the Optimize reductions parameter to generate SIMD code for reduction operations.

  6. Generate code from the model.

To generate c code using the Simulink Coder app, see Generate C Code by Using Simulink Coder Quick Start Tool.

See Also

|