Specifying a target architecture, processor, and instruction set
When compiling code, the compiler must know which architecture or processor to target, which optional architectural features are available, and which instruction set to use.
Overview
If you only want to run code on one particular processor, you can target that specific processor. Performance is optimized, but code is only guaranteed to run on that processor.
If you want your code to run on a wide range of processors, you can target an architecture. The code runs on any processor implementation of the target architecture, but performance might be impacted.
The options for specifying a target are as follows:
-
Specify the execution state using the
--target
option.The execution state can be AArch64 or AArch32 depending on the processor.
-
Target one of the following:
- an architecture using the
-march
option. - a specific processor using the
-mcpu
option.
- an architecture using the
- (AArch32 targets only) Specify the floating-point hardware
available using the
-mfpu
option, or omit to use the default for the target. - (AArch32 targets only) For processors that support both A32 (formerly ARM)
and T32 (formerly Thumb) instruction sets, specify the instruction set using
-marm
or-mthumb
, or omit to default to-marm
.
Specifying the target execution state
To specify a target execution state with armclang
, use the --target
command-line option:
--target=
arch
-vendor
-os
-abi
Supported targets are as follows:
aarch64-arm-none-eabi
- Generates A64 instructions for AArch64 state. Implies
-march=armv8-a
unless-mcpu
is specified. arm-arm-none-eabi
- Generates A32/T32 instructions for AArch32 state. Must be used in
conjunction with
-march
(to target an architecture) or-mcpu
(to target a processor).
Note
The--target
option is an
armclang
option. For all of the other tools,
such as armasm
and armlink
, use the --cpu
and --fpu
options to specify target processors and
architectures.Note
The--target
option is mandatory. You
must always specify a target execution state.Specifying the target architecture
Targeting an architecture with --target
and
-march
generates generic code that runs on any
processor with that architecture.
Use the -march=list
option to see all supported architectures.
Note
The-march
option is an armclang
option. For all of the other tools, such as
armasm
and armlink
, use the --cpu
and --fpu
options to specify target processors and
architectures.Specifying a particular processor
Targeting a processor with --target
and -mcpu
optimizes code
for the specified processor.
Use the -mcpu=list
option to see all
supported processors.
You can specify feature modifiers with -mcpu
and -march
. For example
-mcpu=cortex-a57+nocrypto
.
Specifying the floating-point hardware available on the target
The -mfpu
option overrides the default FPU
option implied by the target architecture or processor.
Note
The-mfpu
option is ignored with Arm®v8‑A
AArch64 targets. Use the -mcpu
option to override
the default FPU for AArch64 targets. For example, to prevent the use of the
cryptographic extensions for AArch64 targets use the -mcpu=name
+nocrypto
option.Specifying the instruction set
Different architectures support different instruction sets:
- Armv8‑A processors in AArch64 state execute A64 instructions.
- Armv8‑A processors in AArch32 state, as well as Armv7 and earlier A- and R- profile processors execute A32 and T32 instructions.
- M-profile processors execute T32 instructions.
To specify the target instruction set, use the following command-line options:
-marm
targets the A32 instruction set. This is the default for all targets that support A32 instructions.-mthumb
targets the T32 instruction set. This is the default for all targets that only support T32 instructions.
Note
The-marm
and -mthumb
options are not valid with AArch64 targets.
The compiler ignores the -marm
and -mthumb
options and generates a warning with AArch64 targets.Command-line examples
The following examples show how to compile for different combinations of architecture, processor, and instruction set:
Table 3-1 Compiling for different combinations of architecture, processor, and instruction set
Architecture | Processor | Instruction set | armclang command |
---|---|---|---|
Armv8‑A AArch64 state | Generic | A64 |
|
Armv8‑A AArch64 state | Cortex®‑A57 | A64 |
|
Armv8‑A AArch32 state | Generic | A32 |
|
Armv8‑A AArch32 state | Cortex‑A53 | A32 |
|
Armv8‑A AArch32 state | Cortex‑A57 | T32 |
|
Armv7‑A | Generic | A32 |
|
Armv7‑A | Cortex‑A9 | A32 |
|
Armv7‑A | Cortex‑A15 | T32 |
|
Armv7‑R | Cortex‑R7 | A32 |
|
Armv7‑R | Cortex‑R7 | T32 |
|
Armv7‑M | Generic | T32 |
|
Armv6‑M | Cortex‑M0 | T32 |
|
Armv8.Mainline | Generic | T32 |
|
Armv8.Baseline | Generic | T32 |
|