3.1 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:

  1. Specify the execution state using the --target option.

    The execution state can be AArch64 or AArch32 depending on the processor.

  2. Target one of the following:

    • an architecture using the -march option.
    • a specific processor using the -mcpu option.
  3. (AArch32 targets only) Specify the floating-point hardware available using the -mfpu option, or omit to use the default for the target.
  4. (AArch32 targets only) For processors that support both ARM and Thumb, 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 ARMv8-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 (formerly ARM) and T32 (formerly Thumb) instructions.
  • M-profile processors execute T32 (formerly Thumb) instructions.

To specify the target instruction set, use the following command-line options:

  • -marm targets the A32 (formerly ARM) instruction set. This is the default for all targets that support ARM or A32 instructions.
  • -mthumb targets the T32 (formerly Thumb) instruction set. This is the default for all targets that only support Thumb or 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

armclang --target=aarch64-arm-none-eabi test.c

ARMv8-A AArch64 state Cortex®‑A57 A64

armclang --target=aarch64-arm-none-eabi -mcpu=cortex-a57 test.c

ARMv8-A AArch32 state Generic A32

armclang --target=arm-arm-none-eabi -march=armv8-a test.c

ARMv8-A AArch32 state Cortex‑A53 A32

armclang --target=arm-arm-none-eabi -mcpu=cortex-a53 test.c

ARMv8-A AArch32 state Cortex‑A57 T32

armclang --target=arm-arm-none-eabi -mcpu=cortex-a57 -mthumb test.c

ARMv7-A Generic A32

armclang --target=arm-arm-none-eabi -march=armv7-a test.c

ARMv7-A Cortex‑A9 A32

armclang --target=arm-arm-none-eabi -mcpu=cortex-r7 test.c

ARMv7-A Cortex‑A15 T32

armclang --target=arm-arm-none-eabi -mcpu=cortex-r7 -mthumb test.c

ARMv7-R Cortex‑R7 A32

armclang --target=arm-arm-none-eabi -mcpu=cortex-r7 test.c

ARMv7-R Cortex‑R7 T32

armclang --target=arm-arm-none-eabi -mcpu=cortex-r7 -mthumb test.c

ARMv7-M Generic T32

armclang --target=arm-arm-none-eabi -march=armv7-m test.c

ARMv6-M Cortex‑M0 T32

armclang --target=arm-arm-none-eabi -mcpu=cortex-m0 test.c

ARMv8-M.Mainline Generic T32

armclang --target=arm-arm-none-eabi -march=armv8-m.main test.c

ARMv8-M.Baseline Generic T32

armclang --target=arm-arm-none-eabi -march=armv8-m.base test.c

Non-ConfidentialPDF file icon PDF versionARM 100066_0608_00_en
Copyright © 2014–2017 ARM Limited or its affiliates. All rights reserved.