主要内容

Use Target Hardware Instruction Set Extensions to Generate SIMD Code from MATLAB System Objects for Apple silicon and ARM Cortex-A Processors

Note

This workflow requires Embedded Coder® license.

This topic shows how to generate SIMD code from MATLAB® System objects for Apple silicon and ARM® Cortex®-A processors using the InstructionSetExtensions (Simulink Coder) configuration parameter. For a list of System objects in DSP System Toolbox™ that support this workflow, see System objects in DSP System Toolbox that Support SIMD Code Generation.

To generate SIMD code from MATLAB System objects:

  • Create a coder.config (MATLAB Coder) object.

    Set ecoder_flag to true to create a coder.EmbeddedCodeConfig object. build_type is 'lib', 'dll', or 'exe'.

    config_obj = coder.config(build_type,'ecoder',true)

  • Select the hardware device by setting HardwareImplementation.ProdHWDeviceType to one of these options:

    • "Apple->ARM64"

    • "ARM Compatible->ARM Cortex-A (32-bit)"

    • "ARM Compatible->ARM Cortex-A (64-bit)"

    config_obj.HardwareImplementation.ProdHWDeviceType = "Apple->ARM64"
  • Select the instruction set extensions by setting InstructionSetExtensions to Neon v7.

    config_obj.InstructionSetExtensions = "Neon v7"

  • Set OptimizeReductions to true to generate SIMD code for reduction operations.

    config_obj.OptimizeReductions = true

  • Set InstructionSetExtensionsConfig.FMA to true to generate SIMD code for fused multiply-add operations.

    config_obj.InstructionSetExtensionsConfig.FMA = true

  • Set CodeReplacementLibrary to "None".

    config_obj.CodeReplacementLibrary = "None"

  • In addition, you must satisfy the conditions under which the System objects support SIMD code generation. For more information, see the Extended Capabilities > C/C++ Code Generation section in the respective System object reference page.

  • Generate code using the codegen (MATLAB Coder) command.

    codegen MATLABfunctionName -config config_obj

    MATLABfunctionName is the MATLAB function that calls the System object™ you are trying to generate SIMD code from. For a list of System objects that support SIMD code generation, see System objects in DSP System Toolbox that Support SIMD Code Generation.

The SIMD instructions are the intrinsic functions that start with the identifier v in the generated code. These functions process multiple data in a single iteration of the loop because the loop increments by four for single data types and by two for double data types. For models that process more data and are computationally more intensive, the SIMD instructions can significantly speed up the code execution time.

See Also

Topics