首页 > 其他分享 >riscv gnu编译器

riscv gnu编译器

时间:2023-12-10 10:11:40浏览次数:43  
标签:point riscv ABI gnu -- 编译器 registers bit floating

官网

https://github.com/riscv-collab/riscv-gnu-toolchain

编译器

基于RISC-V交叉编译器包括32bit和64bit两种类型,其中每种类型又包括裸机版本(newlib)和动态链接库版本(linux glibc)

  • newlib
./configure --prefix=/opt/riscv
make
  • glibc
#默认仅支持64位target
./configure --prefix=/opt/riscv
make linux
#仅支持32位target
./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d
make linux
  • musl
./configure --prefix=/opt/riscv
make musl
  • Newlib/glibc/musl multilib
./configure --prefix=/opt/riscv --enable-multilib
# newlib
make
# glibc
make linux
# musl
make musl
  • The multilib compiler will have the prefix riscv64-unknown-elf- or riscv64-unknown-linux-gnu- but will be able to target both 32-bit and 64-bit systems. It will support the most common -march/-mabi options, which can be seen by using the --print-multi-lib flag on either cross-compiler.
# 查看支持的编译架构
 riscv64-unknown-elf-gcc --print-multi-lib
  • The musl compiler (riscv64-unknown-linux-musl-) will only be able to target 64-bit systems due to limitations in the upstream musl architecture support. The --enable-multilib flag therefore does not actually enable multilib support for musl libc.

-march and -mabi参数

https://xpack.github.io/dev-tools/riscv-none-elf-gcc/

ISA基础功能

RISC-V ISA strings begin with either RV32I, RV32E, RV64I, or RV128I indicating the supported address space size in bits for the base integer ISA.

  • RV32I: A load-store ISA with 32, 32-bit general-purpose integer registers.
  • RV32E: An embedded flavour of RV32I with only 16 integer registers.
  • RV64I: A 64-bit flavour of RV32I where the general-purpose integer registers are 64-bit wide.

ISA扩展功能

In addition to these base ISAs, a handful of extensions have been specified. The extensions that have both been specified and are supported by the toolchain are:

M - Integer Multiplication and Division
A - Atomics
F - Single-Precision Floating-Point
D - Double-Precision Floating-Point
C - 16-bit Compressed Instructions
G - General, a shortcut to IMAFD

For more details, please see The RISC-V ISA Specification, Volume I: Unprivileged Spec

march

RISC-V ISA strings are defined by appending the supported extensions to the base ISA in the order listed above. For example, the RISC-V ISA with 32, 32-bit integer registers and the instructions to for multiplication would be denoted as “RV32IM”. Users can control the set of instructions that GCC uses when generating assembly code by passing the lower-case ISA string to the -march GCC option: for example -march=rv32im

mabi

除了指定GCC的指令,还可以指定ABI类型,也就是函数调用方式、内存布局

In addition to controlling the instructions available to GCC during code generating (which defines the set of implementations the generated code will run on), users can select from various ABIs to target (which defines the calling convention and layout of objects in memory). Objects and libraries may only be linked together if they follow the same ABI.

RISC-V defines two integer ABIs and three floating-point ABIs, which together are treated as a single ABI string. The integer ABIs follow the standard ABI naming scheme:

  • ilp32: “int”, “long”, and pointers are all 32-bit long. “long long” is a 64-bit type, “char” is 8-bit, and “short” is 16-bit.
  • lp64: “long” and pointers are 64-bit long, while “int” is a 32-bit type. The other types remain the same as ilp32.

while the floating-point ABIs are a RISC-V specific addition:

  • ”” (the empty string): No floating-point arguments are passed in registers.
  • f: 32-bit and smaller floating-point arguments are passed in registers. This ABI requires the F extension, as without F there are no floating-point registers.
  • d: 64-bit and smaller floating-point arguments are passed in registers. This ABI requires the D extension.

examples

ABI strings are concatenated together and passed via the -mabi argument to GCC. For example:

  • -march=rv32imafdc -mabi=ilp32d: Hardware floating-point instructions can be generated and floating-point arguments are passed in registers. This is like the -mfloat-abi=hard option to Arm’s GCC. 架构支持浮点,可生成浮点指令。ABI规定可通过寄存器传参浮点。
  • -march=rv32imac -mabi=ilp32: No floating-point instructions can be generated and no floating-point arguments are passed in registers. This is like the -mfloat-abi=soft argument to Arm’s GCC. 架构不支持浮点,不可生成浮点指令。ABI规定不可通过寄存器传参浮点。
  • -march=rv32imafdc -mabi=ilp32: Hardware floating-point instructions can be generated, but no floating-point arguments will be passed in registers. This is like the -mfloat-abi=softfp argument to Arm’s GCC, and is usually used when interfacing with soft-float binaries on a hard-float system. 架构支持浮点,可生成浮点指令。但是ABI规定不可通过寄存器传参浮点。也就是硬件支持,但是软件主动不使用硬件浮点功能
  • -march=rv32imac -mabi=ilp32d: Illegal, as the ABI requires floating-point arguments are passed in registers but the ISA defines no floating-point registers to pass them in. 非法选项

标签:point,riscv,ABI,gnu,--,编译器,registers,bit,floating
From: https://www.cnblogs.com/lvzh/p/17892179.html

相关文章

  • Termux安装GCC编译器
    cctoolspkgupdatepkginstall-ycoreutilsgnupgcurl-sLo$PREFIX/etc/apt/trusted.gpg.d/cctools.asc--create-dirshttps://cctools.info/public.keyecho"deb[trusted=yes]https://cctools.infotermuxcctools"|tee$PREFIX/etc/apt/sources.list......
  • 学习riscv(1)安装tinyriscv的工具链
    因为毕设是CPU的低功耗设计,所以开始看cpu,打算还是先从这个tinyriscv学起,昨天把环境下好了,第一步是用git去clone代码,这个首先要下载git,然后在目标文件夹鼠标右键,选择“opengitbushhere”,再输入项目的url,就可以了。方法不难。b站有详细教程接下来是安装工具,我用的是wind......
  • 交叉编译工具 arm-none-linux-gnueabihf-gcc安装及思考
    1安装步骤A创建目录:/usr/local/armB将交叉编译器(压缩包)复制到该目录,在该目录下进行解压得到“gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf”的文件C打开/etc/profile文件添加环境变量       sudovi/etc/profile  exportPATH=......
  • 编译器上手指南,算子开发及开源项目指导手册,直播课程报名通道限时开启!
    「MegEngine开发者说」直播课程第二期火爆来袭!本期既有技术大佬带来深度学习编译器MegCC的详细教程,又有实习经历丰富的在校同学分享MegEngine算子开发流程及开源经历,手把手带你学习,精彩不容错过!更有直播间有奖答疑,现在报名,即有机会获得MegEngine周边大礼包!关于「MegEngi......
  • go的编译器安装
    中文网:https://studygolang.com/dl 点击下载 next-next后安装路径:D:\Go\  next-next-install gobuild生成可执行文件.exe./可执行文件.exe执行 ......
  • 最佳 C++ 编译器
    最佳C++编译器Incredibuild​已认证账号​关注 134人赞同了该文章 C++是一个“开放”的编程语言,任何人都可以使用自己喜欢的编译器。当然,C++编译器的种类也很多。同样, C++IDE 也不少,我在之前的一个博客中讨论过这个话题。编译和运行C++......
  • vim编译器
    一、vim是什么?vim是从vi发展出来的一个文本编辑器。代码补全、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。简单的来说,vi是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方。vim则可以说是程序开发者的一项很好用的工具。 二、vim的使用......
  • C\C++ 设置Visual Studio编译器使用C++17标准
    文章作者:里海简介:        使用ISOC++17标准可以为开发人员带来许多好处,包括更简洁的代码、更高的运行效率、更好的硬件支持、更好的兼容性和可移植性,以及更好的多线程编程支持等。那么如何设置vs使用c++标准呢?下面是方法。注意需要vs2017及以上版本。方法:打开VisualStud......
  • Linux学习记录:Vim编译器和文件一些简单属性
    1.Vi编辑器是Linux上最基本的文本编辑器,工作在字符模式下,效率非常高。Vim是Vi的增强版,这个编译器的功能广泛。 Vim编译器主要有三种模式:编辑模式、命令模式、末行模式(拓展命令模式)。命令模式:控制光标,对文件进行复制、粘贴、删除、查询等操作。编辑模式:进行文本录入和更改。......
  • vim编译器的学习了解
    首先,我学会了如何在Linux系统中安装Vim。虽然大多数Linux发行版都预装了Vim,但我还是决定亲手编译安装,以便更好地理解这个编辑器。通过源代码编译的方式,我深入了解了Vim的组成结构和依赖关系,这为我后续的学习打下了坚实的基础。Vim的编辑模式是初学者常常感到困扰的地方,但也是它独......