Who is this for?

This is an advanced topic for developers interested in optimizing their C/C++ applications across Arm64 targets.

What will you learn?

Upon completion of this Learning Path, you will be able to:

  • Use hardware features to tune your applications at function level.
  • Create multiple versions of C/C++ functions for the targets that you intend to run applications on.
  • Assist the compiler in generating optimal code for the targets, or provide your own optimized versions at source level.
  • Automatically select the most appropriate function version at runtime.
  • Reuse your optimized application binaries across various targets.

Prerequisites

Before starting, you will need the following:

  • Basic knowledge of GNU function attributes.
  • Familiarity with indirect functions (ifuncs).
  • Basic knowledge of loop vectorization.
  • Familiarity with Arm assembly.
  • A LLVM 20 compiler with runtime library support or GCC 16.

Summary

AI-assisted

This summary was drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.

Close
?
You’ll implement function multiversioning for arm64 in C/C++ using the target_version and target_clones attributes, so a single binary contains feature-specific implementations. You’ll create versions keyed to architectural features such as default, sve, sve2, simd, mops, and sme2 to enable runtime selection of the most suitable function. Through hands-on examples, you’ll compare code generation for a vectorized loop, write an SVE-based dot product with Arm C Language Extensions (ACLE), and mix SVE2 inline assembly with library calls where the compiler can emit FEAT_MOPS for memcpy. You’ll also cover streaming mode compatibility by keeping calling conventions consistent across function versions.

Frequently asked questions

AI-assisted

These FAQs were drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.

Close
?
How do I know which function version executed at runtime?
In the dot product example, the SVE-specialized function prints a message when it runs. If that message doesn’t appear, the default version executed.
Which option should I use in `target_version` or `target_clones`?
Use architectural feature names shown in the examples, such as default, sve, sve2, simd, mops, or sme2. You can also combine multiple features using a + separator in the attribute string.
Does the order of entries in `target_clones` affect selection?
No. The order of versions listed in target_clones doesn’t affect which version is chosen at runtime.
How should I organize code that uses ACLE intrinsics or inline assembly?
Place SVE or SVE2-specific code in functions annotated with the corresponding target_version (for example, sve or sve2). Keep a generic default version so the binary runs on Armv8 targets without those features.
What should I check if I use streaming mode with multiversioning?
Ensure every version of the function uses the same calling convention. The examples show combining __arm_streaming (and related attributes) with target_version or target_clones to keep versions compatible.
Next