-
Notifications
You must be signed in to change notification settings - Fork 62
Add LoongArch toolchain conventions. #23
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,161 @@ | ||||||||||||||||||
| = 龙芯架构编译器约定 | ||||||||||||||||||
| 龙芯中科技术股份有限公司 | ||||||||||||||||||
| v1.00 | ||||||||||||||||||
| :docinfodir: ../themes | ||||||||||||||||||
| :docinfo: shared | ||||||||||||||||||
| :doctype: book | ||||||||||||||||||
| :toc: left | ||||||||||||||||||
| :toc-title: 目录 | ||||||||||||||||||
| :scripts: cjk | ||||||||||||||||||
|
|
||||||||||||||||||
| == 编译器命令行选项界面 | ||||||||||||||||||
|
|
||||||||||||||||||
| 以下编译器选项的最终效应包括: | ||||||||||||||||||
|
|
||||||||||||||||||
| 1. 配置使用的 ABI 类型 | ||||||||||||||||||
|
|
||||||||||||||||||
| 2. 配置使用的 ISA 扩展 | ||||||||||||||||||
|
|
||||||||||||||||||
| 3. 配置处理器型号相关的调优参数 | ||||||||||||||||||
|
|
||||||||||||||||||
| .编译器选项列表: | ||||||||||||||||||
| [%header,cols="^1m,^2,^7"] | ||||||||||||||||||
| |=== | ||||||||||||||||||
| |选项 | ||||||||||||||||||
| |可用值 | ||||||||||||||||||
| |描述 | ||||||||||||||||||
|
|
||||||||||||||||||
| |-march= | ||||||||||||||||||
| |`native` `loongarch64` `la464` | ||||||||||||||||||
| |选择目标 CPU (隐含默认 ABI 类型、ISA 扩展和调优参数) | ||||||||||||||||||
|
|
||||||||||||||||||
| |-mtune= | ||||||||||||||||||
| |`native` `loongarch64` `la464` | ||||||||||||||||||
| |选择目标 CPU 的性能调优参数 | ||||||||||||||||||
|
|
||||||||||||||||||
| |-mabi= | ||||||||||||||||||
| |`lp64` `ilp32` | ||||||||||||||||||
| |选择整型 ABI 类型 | ||||||||||||||||||
|
|
||||||||||||||||||
| |-mfloat-abi= | ||||||||||||||||||
| |`double` `single` `soft` | ||||||||||||||||||
| |选择浮点 / 扩展 ABI 类型 | ||||||||||||||||||
|
Comment on lines
+36
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
尽管如此,个人仍然强烈倾向于、建议采用 RV 的做法:浮点 ABI 体现在 ABI 命名中,不单加选项。这是由于,讲话过程中只需要传递一个信息元素,理解起来很方便,且不会有歧义、生造表达方式等语言学问题。 举例说明,RV
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
目前文档描述的 / gcc 实现的标准 ABI 名称是 同样,在目前的 gcc 实现上 "-mabi=lp64" 也不隐含 "-mfloat-abi=double":若不给出 "-mfloat-abi" 选项,则只有 "-mfpu" 和 "-march" 可能隐含它的取值,如果这两者也没有给出,就采用 configure 时从 triplet 或 --with-float 选项获取的默认浮点 ABI 类型。
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 了解,我们再讨论一下应该怎么做。 |
||||||||||||||||||
|
|
||||||||||||||||||
| |-mfpu= | ||||||||||||||||||
| |`double` `single` `none` | ||||||||||||||||||
| |选择编译器可用的浮点 / 扩展指令集 | ||||||||||||||||||
|
|
||||||||||||||||||
| |-msoft-float | ||||||||||||||||||
| |`--` | ||||||||||||||||||
| |`-mfloat-abi=soft -mfpu=none` 的简写 | ||||||||||||||||||
|
|
||||||||||||||||||
| |-msingle-float | ||||||||||||||||||
| |`--` | ||||||||||||||||||
| |`-mfloat-abi=single -mfpu=single` 的简写 | ||||||||||||||||||
|
|
||||||||||||||||||
| |-mdouble-float | ||||||||||||||||||
| |`--` | ||||||||||||||||||
| |`-mfloat-abi=double -mfpu=double` 的简写 | ||||||||||||||||||
| |=== | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| == GNU 目标三元组和 Multiarch 架构标识符 | ||||||||||||||||||
|
|
||||||||||||||||||
| GNU 目标三元组是 GNU 构建系统用于描述目标平台的字符串, | ||||||||||||||||||
| 一般包含三个字段:处理器类型 (`machine`) ,系统厂商 (`vendor`),操作系统 (`os`)。 | ||||||||||||||||||
|
|
||||||||||||||||||
| .龙芯架构 `machine` 字符串列表: | ||||||||||||||||||
| [%header,cols="^1,^2"] | ||||||||||||||||||
| |=== | ||||||||||||||||||
| |`machine` 字符串 | ||||||||||||||||||
| |含义 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`loongarch64` | ||||||||||||||||||
| |默认使用 la64 指令集,双精度浮点单元,ABI 类型 `lp64/double` | ||||||||||||||||||
|
|
||||||||||||||||||
| |`loongarch64nf` | ||||||||||||||||||
| |默认使用 la64 指令集,无硬件浮点单元,ABI 类型 `lp64/soft` | ||||||||||||||||||
|
|
||||||||||||||||||
| |`loongarch64sf` | ||||||||||||||||||
| |默认使用 la64 指令集,单精度浮点单元,ABI 类型 `lp64/single` | ||||||||||||||||||
| |=== | ||||||||||||||||||
|
Comment on lines
+67
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 强烈不建议如此,建议采用符合一般熟悉 ARM、MIPS 开发人员习惯的
这样做的好处有:
如果出于某些原因,这个信息一定、必须、非得要体现在 machine 字段的话,请说明这些原因,读文档的人猜不到。这种情况下可以这么做:
由于这么搞一遍又要大动干戈去改几十上百个上游项目 vendor 的
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 上游的 这里 GNU triplet machine 字段希望反映的是处理器支持的最高指令集特性(参照 从实现看,这个 triplet 基本上只是一个用于让 GNU 构建系统判断是否进行交叉编译的符号。对于 GCC 来说,目前它的效果除了设定编译器类型,命令默认前缀和”-dumpmachine"选项的返回值之外,主要就是隐含 目前我们对 GNU 工具链和发行版的设想是:
感谢建议,如果有必要我会补充一下额外说明。
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果要“反映处理器支持的最高指令集特性”,那么应该学习 HPPA,取
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 另外,“处理器支持的指令集特性”这一点上 amd64/arm64 都做得很好,都有很多新功能迭代,但他们不动 machine 字段,也是龙芯当前的现状;其实可能基于现状结合 amd64/arm64 的实践,才是成本最低效益最高的。
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我比较偏向于 前者很可能违背人类的直觉,但后者又和 “ |
||||||||||||||||||
|
|
||||||||||||||||||
| Multiarch 架构标识符是用于 multiarch 库安装路径的目录名称, | ||||||||||||||||||
| 可以看作规范的 GNU 目标三元组,参见 https://wiki.debian.org/Multiarch/Tuples[Debian 文档] 。 | ||||||||||||||||||
|
|
||||||||||||||||||
| .龙芯架构 Mulitarch 架构标识符列表: | ||||||||||||||||||
| [%header,cols="^1,^2"] | ||||||||||||||||||
| |=== | ||||||||||||||||||
| |Multiarch 架构标识符 | ||||||||||||||||||
| |含义 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`<machine>-linux-gnu` | ||||||||||||||||||
| |GNU/Linux 系统,使用 GNU C Library (glibc) 作为标准 C 库,系统内核为 Linux | ||||||||||||||||||
| |=== | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| == C/C++ 预处理器内建宏定义 | ||||||||||||||||||
|
|
||||||||||||||||||
| .龙芯架构相关 C/C++ 预处理器内建宏列表: | ||||||||||||||||||
| [%header,cols="^1,^3,^3"] | ||||||||||||||||||
| |=== | ||||||||||||||||||
| |名称 | ||||||||||||||||||
| |值 | ||||||||||||||||||
| |描述 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`\\__loongarch__` | ||||||||||||||||||
| |(无) | ||||||||||||||||||
| |目标为龙芯架构 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`__loongarch_gpr` | ||||||||||||||||||
| |`64` | ||||||||||||||||||
| |通用寄存器位宽 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`__loongarch_fpr` | ||||||||||||||||||
| |`0` `32` `64` | ||||||||||||||||||
| |浮点寄存器位宽(无 fpu 则为 `0` ) | ||||||||||||||||||
|
Comment on lines
+110
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议改成手册提到的 |
||||||||||||||||||
|
|
||||||||||||||||||
| |`_LOONGARCH_ARCH` | ||||||||||||||||||
| |`loongarch64` `la464` | ||||||||||||||||||
scylaac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||
| |相当于 `--with-arch` / `-march` 指定的处理器型号 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`_LOONGARCH_TUNE` | ||||||||||||||||||
| |`loongarch64` `la464` | ||||||||||||||||||
| |相当于 `-mtune` 指定的处理器型号 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`__loongarch_lp64` | ||||||||||||||||||
| |(无) | ||||||||||||||||||
| |整型 ABI 类型为 `lp64` | ||||||||||||||||||
|
|
||||||||||||||||||
| |`__loongarch_hard_float` | ||||||||||||||||||
| |(无) | ||||||||||||||||||
| |浮点/扩展 ABI 类型为 `single` 或 `double` | ||||||||||||||||||
|
|
||||||||||||||||||
| |`__loongarch_soft_float` | ||||||||||||||||||
| |(无) | ||||||||||||||||||
| |浮点/扩展 ABI 类型为 `soft` | ||||||||||||||||||
|
|
||||||||||||||||||
| |`__loongarch_single_float` | ||||||||||||||||||
| |(无) | ||||||||||||||||||
| |浮点/扩展 ABI 类型为 `single` | ||||||||||||||||||
|
|
||||||||||||||||||
| |`__loongarch_double_float` | ||||||||||||||||||
| |(无) | ||||||||||||||||||
| |浮点/扩展 ABI 类型为 `double` | ||||||||||||||||||
|
|
||||||||||||||||||
| |`_LOONGARCH_SZINT` | ||||||||||||||||||
| |(略) | ||||||||||||||||||
| |C/C++ `int` 类型位宽 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`_LOONGARCH_SZINT` | ||||||||||||||||||
| |(略) | ||||||||||||||||||
| |C/C++ `int` 类型位宽 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`_LOONGARCH_SZLONG` | ||||||||||||||||||
| |(略) | ||||||||||||||||||
| |C/C++ `long int` 类型位宽 | ||||||||||||||||||
|
|
||||||||||||||||||
| |`_LOONGARCH_SZPTR` | ||||||||||||||||||
| |(略) | ||||||||||||||||||
| |C/C++ 指针类型位宽 | ||||||||||||||||||
| |=== | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| = LoongArch ELF ABI specification | ||
| Loongson Technology Corporation Limited | ||
| v1.00 | ||
| :docinfodir: ../themes | ||
| :docinfo: shared | ||
| :doctype: book | ||
| :toc: left | ||
|
|
||
| == Compiler Options | ||
|
|
||
| The command-line options listed below should denote a change | ||
| in the following compiler settings: | ||
|
|
||
| 1. ABI type of compiled subroutines | ||
|
|
||
| 2. Available ISA extensions | ||
|
|
||
| 3. Processor-model-specific tuning parameters | ||
|
|
||
| .Compiler Options: | ||
| [%header,cols="^1m,^2,^7"] | ||
| |=== | ||
| |Option | ||
| |Possible Values | ||
| |Description | ||
|
|
||
| |-march= | ||
| |`native` `loongarch64` `la464` | ||
| |Target CPU model (implies default ABI type, ISA extension and tuning parameters) | ||
|
|
||
| |-mtune= | ||
| |`native` `loongarch64` `la464` | ||
| |Target CPU model (tuning parameters) | ||
|
|
||
| |-mabi= | ||
| |`lp64` `ilp32` | ||
| |Integer ABI type | ||
|
|
||
| |-mfloat-abi= | ||
| |`double` `single` `soft` | ||
| |Floating-point / extended ABI type | ||
|
|
||
| |-mfpu= | ||
| |`double` `single` `none` | ||
| |Floating-point ISA / SIMD extensions | ||
|
|
||
| |-msoft-float | ||
| |`--` | ||
| |alias for `-mfloat-abi=soft -mfpu=none` | ||
|
|
||
| |-msingle-float | ||
| |`--` | ||
| |alias for `-mfloat-abi=single -mfpu=single` | ||
|
|
||
| |-mdouble-float | ||
| |`--` | ||
| |alias for `-mfloat-abi=double -mfpu=double` | ||
| |=== | ||
|
|
||
|
|
||
| == GNU Target Triplets and Multiarch Specifiers | ||
|
|
||
| Target triplet is a core concept in the GNU build system. | ||
| It describes a platform on which the code runs, primarily with three fields: | ||
| the CPU family/model (`machine`), the vendor (`vendor`), and the operating | ||
| system name (`os`)。 | ||
|
|
||
| .List of LoongArch `machine` strings: | ||
| [%header,cols="^1,^2"] | ||
| |=== | ||
| |`machine` | ||
| |Description | ||
|
|
||
| |`loongarch64` | ||
| |Processors that support la64 ISA and 64-bit FPU. (ABI: `lp64/double`) | ||
|
|
||
| |`loongarch64nf` | ||
| |Processors that support la64 ISA without FPU. (ABI: `lp64/soft`) | ||
|
|
||
| |`loongarch64sf` | ||
| |Processors that support la64 ISA and 32-bit FPU. (ABI: `lp64/single`) | ||
| |=== | ||
|
|
||
| Multiarch Architecture Specifiers are essentially standard directory names | ||
| where libraries are installed on a multiarch-flavored filesystem. | ||
| These strings are normalized GNU target triplets. See | ||
| https://wiki.debian.org/Multiarch/Tuples[debian documentation] for details. | ||
|
|
||
| .LoongArch Mulitarch Architecture Specifiers: | ||
| [%header,cols="^1,^2"] | ||
| |=== | ||
| |Multiarch Specifier | ||
| |Description | ||
|
|
||
| |`<machine>-linux-gnu` | ||
| |GNU/Linux on LoongArch (with Glibc as standard C library and Linux as OS kernel) | ||
| |=== | ||
|
|
||
|
|
||
| == C/C++ Preprocessor Definitions | ||
|
|
||
| .LoongArch-specific C/C++ Built-in Macros: | ||
| [%header,cols="^1,^3,^3"] | ||
| |=== | ||
| |Name | ||
| |Possible Values | ||
| |Description | ||
|
|
||
| |`\\__loongarch__` | ||
| |(none) | ||
| |Defined if the target is LoongArch. | ||
|
|
||
| |`__loongarch_gpr` | ||
| |`64` | ||
| |Bit-width of general purpose registers. | ||
|
|
||
| |`__loongarch_fpr` | ||
| |`0` `32` `64` | ||
| |Bit-width of floating-point registers (`0` if there is no FPU). | ||
|
|
||
| |`_LOONGARCH_ARCH` | ||
| |`loongarch64` `la464` | ||
| |Processor model as specified by `--with-arch` / `-march`. | ||
|
|
||
| |`_LOONGARCH_TUNE` | ||
| |`loongarch64` `la464` | ||
| |Processor model as specified by `-mtune`. | ||
|
|
||
| |`__loongarch_lp64` | ||
| |(none) | ||
| |Defined if integer ABI type is `lp64`. | ||
|
|
||
| |`__loongarch_hard_float` | ||
| |(none) | ||
| |Defined if floating-point/extended ABI type is `single` or `double`. | ||
|
|
||
| |`__loongarch_soft_float` | ||
| |(none) | ||
| |Defined if floating-point/extended ABI type is `soft`. | ||
|
|
||
| |`__loongarch_single_float` | ||
| |(none) | ||
| |Defined if floating-point/extended ABI type is `single`. | ||
|
|
||
| |`__loongarch_double_float` | ||
| |(none) | ||
| |Defined if floating-point/extended ABI type is `double`. | ||
|
|
||
| |`_LOONGARCH_SZINT` | ||
| |(omitted) | ||
| |Bit-width of C/C++ `int` type. | ||
|
|
||
| |`_LOONGARCH_SZLONG` | ||
| |(omitted) | ||
| |Bit-width of C/C++ `long int` type. | ||
|
|
||
| |`_LOONGARCH_SZPTR` | ||
| |(omitted) | ||
| |Bit-width of C/C++ pointer types. | ||
| |=== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照一般认知,
-march用于指定可用的最高指令集特性,-mtune用于指定为哪个微架构进行指令调度。因此-march最好体现版本,-mtune应当体现微架构型号。la464是修改译码器版 GS464V 的新名字,起个新名字我个人觉得没问题。但loongarch64我觉得比较有问题,因为不体现版本。如果不考虑 x32/n32 这类 ABI 的话,位数在 ABI 已经体现了,这里也没必要。我的建议是可以参考 HPPA 的做法,按照手册版本给此处意图所指的 generic LA 大版本起名;他们的做法是-march=1.0-march=1.1-march=2.0。我们可以用-march=1.00表示支持 v1.00 手册中描述为必须实现的指令。