This is the official documentation of the toolchain conventions of the LoongArch™ Architecture.
The latest releases of this document are available at https://github.com/loongson/la-toolchain-conventions and are licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
This specification is written in both English and Chinese. In the event of any inconsistency between the same document version in two languages, the Chinese version shall prevail.
Note
|
In this document, the terms "architecture", "instruction set architecture" and "ISA" are used synonymously to refer to a certain set of instructions and the set of registers they can operate upon. |
Version | Description |
---|---|
1.0 |
initial version, separated from the original LoongArch Documentation repo. |
1.1 |
update the ISA description to include LoongArch v1.1; introduce the ISA versioning scheme for binary distributions. |
Compiler options that are specific to LoongArch should denote a change in the following compiler settings:
-
Target architecture: the allowed set of instructions and registers to be used by the compiler.
-
Target ABI type: the data model and calling conventions.
-
Target microarchitecture: microarchitectural features that guide compiler optimizations.
-
Linking optimizations: code model selection and linker relaxation.
Below is the current list of all LoongArch-specific compiler options that are supported by a fully conforming compiler. The list will be updated as more LoongArch features are developed and implemented.
Option | Possible values | Description | Note |
---|---|---|---|
|
|
Select the target architecture, i.e. the basic collection of enabled ISA feature subsets. |
|
|
|
Select the target microarchitecture, default to the value of |
|
|
|
Select the base ABI type. |
|
|
|
Select the allowed set of basic floating-point instructions and registers.
This option should not change the FP calling convention unless it is necessary.
(The implementation of this option is not mandatory. It is recommended to use
|
|
|
|
Select the SIMD extension(s) to be enabled. |
|
|
|
Select the code model for computing global references. |
|
|
|
Generate assembly code for linker relaxation. |
|
|
|
Do not generate unaligned memory accesses. Useful for targets that do not support unaligned memory access. |
|
|
Prevent the compiler from generating hardware floating-point instructions,
and adjust the selected base ABI type to use soft-float calling convention.
(The adjusted base ABI identifier should have suffix |
||
|
Enable generation of 32-bit floating-point instructions,
and adjust the selected base ABI type to use 32-bit FP calling convention.
(The adjusted base ABI identifier should have suffix |
||
|
Enable generation of 32- and 64-bit floating-point instructions.
and adjust the selected base ABI type to use 64-bit FP calling convention.
(The adjusted base ABI identifier should have suffix |
||
|
|
Enable LSX (128-bit) SIMD instructions. |
|
|
|
Enable LASX (256-bit) SIMD instructions. |
|
|
|
Enable generating approximate reciprocal divide and square root instructions
( |
LoongArch V1.1 |
|
|
Assume |
LoongArch V1.1 |
|
|
Enable atomic operations |
LoongArch V1.1 |
|
|
Enable atomic compare-and-swap instructions |
LoongArch V1.1 |
|
|
Assume no hardware reordering between load operations at the same address.
In this case, do not generate load-load barrier instructions ( |
LoongArch V1.1 |
Note
|
Valid parameter values of -march= and -mtune= options should correspond to
actual LoongArch processor models, IP cores, product families or ISA versions.
|
For one compilation command, the effective order of all LoongArch-specific compiler options is computed with the following general rules:
-
Within each category in the above tables, only the last-seen option is effective (
-m*-float
falls into the same category). -
-march=
and-mabi=
always precede other options. -
On the basis of rule 1 and 2, any options with parameters (i.e. with
=
) precedes all options without parameters. -
If the above rule failed to determine the effective order between two options, unless specified by the following table, they should have independent meanings. (i.e. the effective order between them does not affect the compiler’s final configuration)
Option combination | Compiler behavior | Description |
---|---|---|
|
Abort |
The 64-bit FPU must be present with any SIMD extensions. |
|
||
|
In this particular order, the two options are cancelled out. |
If LSX was previously disabled by |
The compiler should reach the final target configuration by applying the options in their effective order. Options that appears later in the order can override existing configurations.
The following sections will cover the details of the target ISA / ABI configuration items.
Certain features of the LoongArch ISA may evolve independently and combine freely in processor implementations. To support the possible variations of a LoongArch target with a consistent model, we make a modular abstraction of the target ISA, where an ISA implementation can always be identified as a combination of feature subsets.
The feature subsets are divided into two categories: base architectures and ISA extensions. A base architecture is the core component of the target ISA, which defines the basic integer and floating-point operations, and an ISA extension may represent either the base of an extended ISA component or added features in an update.
The possible values of the -march=
parameters are some meaningful
combinations of the ISA feature subsets. It is recommended to specify -march=
first
when composing compiler options for a given target platform.
The compiler should at least implement one ISA configuration represented by an
-march=
parameter value, which includes a base architecture and a number of
ISA extensions. The compiler options that relates to the control of these
extensions should also be implemented. For unimplemented combinations of these
options, the compiler may abort.
Name | Symbol | Description |
---|---|---|
LoongArch64 base architecture |
|
ISA defined in LoongArch Reference Manual - Volume 1: Basic Architecture v1.00. |
The following table lists all ISA extensions that should be abstracted by the compiler and the options that enable/disable them.
Name | Symbol | Related option(s) | Description of the option(s) |
---|---|---|---|
Basic Floating-Point Processing Unit |
|
|
Selects the allowed set of basic floating-point instructions and floating-point registers. This is part of the base architecture, where it gets its default value, but may be adjusted independently. |
Loongson SIMD extension |
|
|
Allow or do not allow generating LSX 128-bit SIMD instructions.
Enabling |
Loongson Advanced SIMD extension |
|
|
Allow or do not allow generating LASX 256-bit SIMD instructions.
Enabling |
LoongArch V1.1 features |
|
|
Enable or disable features introduced by LoongArch V1.1.
The LSX / LASX part of the LoongArch v1.1 update should only be
enabled with |
The following table list the targets that represents specific
LoongArch hardware with microarchitectural features to optimize
for. These are valid parameters to either -march=
or -mtune=
.
Name (-march parameter) |
ISA feature subsets | Target of optimization |
---|---|---|
|
auto-detected |
auto-detected microarchitecture model / features |
|
|
Generic LoongArch 64-bit (LA64) processors |
|
|
LA464 processor core |
|
|
LA664 processor core |
Using the namespace of -march=
targets, we also define a versioning scheme
to promote binary compatibility between LoongArch programs and implementations.
In addition to the IP core / product model names, ISA versions can also be
the parameter of -march=
options, which are tags that identify sets of
commonly agreed ISA features to be implemented by the processors and used by
the software. It is advisable to use -march=<ISA version>
as the only
compiler option to describe the target ISA when building binary distributions
of software.
Name (-march= parameter) |
ISA feature subsets | Version number (major.minor) |
---|---|---|
|
|
|
|
|
|
Like configuring the target ISA, a complete ABI configuration of LoongArch consists of two parts, the base ABI and the ABI extension. The former describes the data model and calling convention in general, while the latter denotes an overall adjustment to the base ABI, which may require support from certain ISA extensions.
Please be noted that there is only ONE ABI extension slot in an ABI configuration. They do not combine with one another, and are, in principle, mutually incompatible.
A new ABI extension type will not be added to this document unless it implies certain significant performance / functional advantage that no compiler optimization techniques can provide without altering the ABI.
There are six base ABI types, whose standard names are the same as
the -mabi
values that select them. The compiler may choose to implement
one or more of these base ABI types, possibly according to the range of
implemented target ISA variants.
Standard name | Data model | Bit-width of argument / return value GPRs / FPRs |
---|---|---|
|
LP64 |
64 / 64 |
|
LP64 |
64 / 32 |
|
LP64 |
64 / (none) |
|
ILP32 |
32 / 64 |
|
ILP32 |
32 / 32 |
|
ILP32 |
32 / (none) |
The following table lists all ABI extension types and
related compiler options. A compiler may choose to implement
any subset of these extensions that contains base
.
The default ABI extension type is base
when referring to
an ABI type with only the "base" component.
Name | Compiler options | Description |
---|---|---|
|
(none) |
conforms to the LoongArch ELF psABI |
The compiler should know the default ABI to use during its build time.
If the ABI extension type is not explicitly configured,
base
should be used.
In principle, the target ISA configuration should not affect the decision of the target ABI. When certain ISA feature required by explicit (i.e. from the compiler’s command-line arguments) ABI configuration cannot be met due constraints imposed by ISA options, the compiler should abort with an error message to complain about the conflict.
When the ABI is not fully constrained by the compiler options, the default configuration of either the base ABI or the ABI extension, whichever is missing from the command line, should be attempted. If this default ABI setting cannot be implemented by the explicitly configured target ISA, the expected behavior is undefined since the user is encouraged to specify which ABI to use when choosing a smaller instruction set than the default.
In this case, it is suggested that the compiler should abort with
an error message, however, for user-friendliness, it may also choose
to ignore the default base ABI or ABI extension and select a viable
fallback ABI for the currently enabled ISA feature subsets with caution.
It is also recommended that the compiler should notify the user about the
ABI change, optionally with a compiler warning.
For example, passing -mfpu=none
as the only command-line argument
may cause a compiler configured with lp64d
/ base
default ABI
to automatically select lp64s
/ base
instead.
When the target ISA configuration cannot be uniquely decided from the given compiler options, the implementation-defined default values should be consulted first. If the default ISA setting is insufficient for implementing the ABI configuration, the compiler should try enabling the missing ISA feature subsets according to the following table, as long as they are not explicitly disabled or excluded from usage.
Base ABI type | ABI extension type | Minimal required ISA feature subsets |
---|---|---|
|
|
|
|
|
|
|
|
|
Target triplet is a core concept in the GNU build system.
It describes a platform on which the code runs and mostly consists of three fields:
the CPU family / model (machine
), the vendor (vendor
), and the operating
system name (os
).
Multiarch architecture apecifiers are essentially standard directory names where libraries are installed on a multiarch-flavored filesystem. These strings are normalized GNU target triplets. See debian documentation for details.
This document recognizes the following machine
strings
for the GNU triplets of LoongArch:
machine
strings
machine |
Description |
---|---|
|
LA64 base architecture (implies |
|
LA32 base architecture (implies |
As standard library directory names, the canonical multiarch architecture specifiers of LoongArch should contain information about the ABI type of the libraries that are meant to be released in the binary form and installed there.
While the integer base ABI is implied by the machine
field,
the floating-point base ABI and the ABI extension type are encoded
with two string suffices (<fabi-suffix><abiext-suffix>
) to the os
field of the
specifier, respectively.
<fabi-suffix>
<fabi-suffix> |
Description |
---|---|
(empty string) |
The base ABI uses 64-bit FPRs for parameter passing. ( |
|
The base ABI uses 32-bit FPRs for parameter passing. ( |
|
The base ABI uses no FPR for parameter passing. ( |
<abiext-suffix>
<abiext-suffix> |
ABI extension type |
---|---|
(empty string) |
|
ABI type (Base ABI / ABI extension) |
C Library | Kernel | Multiarch specifier |
---|---|---|---|
|
glibc |
Linux |
|
|
glibc |
Linux |
|
|
glibc |
Linux |
|
|
musl libc |
Linux |
|
|
musl libc |
Linux |
|
|
musl libc |
Linux |
|
Name | Possible Values | Description |
---|---|---|
|
|
Defined if the target is LoongArch. |
|
|
Bit-width of general purpose registers. |
|
|
Bit-width of floating-point registers ( |
|
|
Target ISA preset as specified by |
|
|
Processor model as specified by |
|
|
Defined if ABI uses the LP64 data model and 64-bit GPRs for parameter passing. |
|
|
Defined if floating-point/extended ABI type is |
|
|
Defined if floating-point/extended ABI type is |
|
|
Defined if floating-point/extended ABI type is |
|
|
Defined if floating-point/extended ABI type is |
|
|
Defined if the compiler enables the |
|
|
Defined if the compiler enables the |
|
|
The maximum SIMD bit-width enabled by the compiler.
( |
|
|
Defined if |
|
|
Defined if |
|
|
Defined if |
|
|
Defined if |
|
|
Defined if |
|
|
The minimally required LoongArch ISA version (major) to run the compiled program. Undefined if no such version is known to the compiler. |
|
|
The minimally required LoongArch ISA version (minor) to run the compiled program.
Undefined if and only if |
The non-loongarch-specific macros listed below may also be helpful when composing code that need to differentiate between ABIs in an architecture-agnostic manner.
Name | Description |
---|---|
|
Byte order |
|
Byte order for floating-point data |
|
Whether the ABI passes arguments in 64-bit GPRs and uses the |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ pointer types, in bytes |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ |
|
Width of C/C++ |
The following built-in macro definitions are listed for compatibility with legacy code. New programs should not assume existence of these macros, and a conforming compiler may choose to implement none or all them.
Name | Equivalent to | Description |
---|---|---|
|
|
Defined iff |
|
|
|
|
|
|
|
Data model of the current ABI. Possible values are |
|
|
|
Size of the |
|
|
Size of the |
|
|
Size of the pointers in bits. |