ZCC 4.x 使用手册
ZCC 是兆松科技基于 LLVM 开源框架开发的 RISC-V 高性能 C/C++ 编译器,支持最新的 C 和 C++ 语言标准,包括 C17、C99、C11、C++17、C++14 和 C++11 等,此外,ZCC 编译器还具有以下优势:
-
支持 RVV 自动向量化及多项优化
-
支持 RISC-V 基本指令集、标准扩展以及 XuanTie、Nuclei、Andes 厂商自定义扩展指令集
下载安装
高性能 RISC-V 工具链 ZCC 提供 Windows 和 Linux 版本。
系统要求
请查看系统要求以确认您的计算机是否符合工具链支持的运行环境。
-
Windows : Windows 10 (32-bit and 64-bit) 及以上
-
Linux :
-
Ubuntu 18, Ubuntu 20, Ubuntu 22.04 and Ubuntu 24.04
-
Centos 6, CentOS 7 and Centos8
-
Fedora 42
-
openSUSE Leap 15.5
-
使用 Terapines Installer 安装
推荐使用 Terapines Installer 便捷地安装兆松科技的产品。对于无图形界面的用户,请使用命令行安装器(CLI Installer)。
- Windows
- Linux (GUI)
- Linux (CLI)
-
从 ZCC 下载页面选择
Windows平台的安装器可执行文件.exe。 -
使用管理员权限运行 Installer 并选择需要安装的 ZCC 版本。
-
ZCC 工具链默认包含 LibZCC,如需要额外的扩展功能,请选择合适的软件库进行安装。所有安装的 ZCC 软件包都将直接安装进工具链中并应用于全局。
-
LibDSP: 专门设计用于数字信号处理(DSP)的函数和工具。
-
LibNN: 专门用于实现和运行神经网络(NN)算法的库。
-
安装完成后可以打开 Product Manager 进行多版本管理。社区版用户无需登录即可使用,商业版用户在 Product Manager 中登录 Terapines 账号即可激活授权许可。


-
从 ZCC 下载页面选择
Linux平台的安装器可执行文件。 -
为所有用户添加执行权限。
chmod a+x ZCC-Installer-<version>-Linux -
运行安装器可执行文件并选择需要安装的 ZCC 版本。
./ZCC-Installer-<version>-Linux -
ZCC 工具链默认包含 LibZCC,如需要额外的扩展功能,请选择合适的软件库进行安装。所有安装的 ZCC 软件包都将直接安装进工具链中并应用于全局。
-
LibDSP: 专门设计用于数字信号处理(DSP)的函数和工具。
-
LibNN: 专门用于实现和运行神经网络(NN)算法的库。
-
安装完成可以打开 Product Manager 进行多版本管理。社区版用户无需登录即可使用,商业版用户在 Product Manager 中登录 Terapines 账号即可激活授权许可。


-
从 ZCC 下载页面选择
Linux (CLI)平台的安装器可执行文件。 -
为所有用户添加 执行权限。
chmod a+x ZCC-Installer-<version>-Linux-CLI -
使用管理员权限运行安装器,选择需要安装的 ZCC 版本并跟随提示完成安装。
./ZCC-Installer-<version>-Linux-CLI -
ZCC 工具链默认包含 LibZCC,如需要额外的扩展功能,请选择合适的软件库进行安装。所有安装的 ZCC 软件包都将直接安装进工具链中并应用于全局。
-
LibDSP: 专门设计用于数字信号处理(DSP)的函数和工具。
-
LibNN: 专门用于实现和运行神经网络(NN)算法的库。
-
安装完成后可以打开 Product Manager 进行多版本管理。社区版用户无需登录即可使用,商业版用户在 Product Manager 中登录 Terapines 账号即可激活授权许可。
./home/tptuser/Terapines/Product-Manager-CLI
更新 ZCC
用户可以通过 Terapines Product Manager(产品管理器)更新 ZCC 并进行多版本管理。保持 ZCC 版本更新,可以确保获得最新的功能和性能优化。
- 打开电脑上的 Terapines 产品管理器,在左侧导航栏展开可用版本(Available)。
- 找到列表中的最新 ZCC 版本,选择该版本并点击安装(Install)。
开启邮件通知
推荐开启自动邮件提醒,及时获取最新 ZCC 更新信息。点击产品管理器右上角的设置图标。进入个人资料(Profile)页面,打开邮件通知开关。


开启后,每当有新版本发布时将收到邮件通知。前往 Terapines Product Manager(产品管理器)即可及时更新 ZCC。
语言标准支持
ZCC 编译器支持最新的 C 和 C++ 语言标准。
-
-x <language>用于将输入文件看待为 C 文件或者 C++ 文件。
<language>可选项是 C 和 C++。 -
-std=<standard>选择用来编译的语言标准,目前 ZCC 支持的语言标准如下表所示。ZCC 支持的所有语言标准规则及细则与上游保持一致。请参考 C++ Support in Clang 和 C Support in Clang。
-
-ansi等同于 "-std=c89",用于将语言标准设置为 c89。
| Standards | Versions |
|---|---|
| C Standard | c18; c17; c11; c99; c90; c89 |
| C++ Standard | c++17; c++14; c++11; c++03; c++98 |
| GNU C | gnu18; gnu17; gnu11; gnu89; gnu++17; gnu++14; gnu++11; gnu++98 |
| ISO C | iso9899:2018; iso9899:2017; iso9899:2011; iso9899:1999; iso9899:199409; iso9899:1990 |
- C17 & C18:C18 也被称为 C17。它于 2017 年编写并于 2018 年发布。
- C89 & C90:C89 和 C90 通常指同一种语言。C89 在 1989 年完成,1990 年被国际标准化组织采用并带有一些小改动。
目标平台支持
使用 -print-supported-extensions 打印 ZCC 所支持的所有扩展指令集选项。
RISC-V 基础 ISAs
ZCC 支持了三种基础指令集 RV32I,RV64I,RV32E。
支持的 target triple:
- riscv32 XLEN=32 的 RISC-V(即 RV32I 或 RV32E)
- riscv64 XLEN=64 的 RISC-V(即 RV64I)
要选择 E 扩展 ISA(例如 RV32E 而不是 RV32I),请使用基本架构字符串(例如 riscv32)与扩展名 e。
RISC-V 扩展
下表提供了 ZCC 中保证了兼容性的扩展,其中包括官方标准扩展以及部分旧版本的实验性扩展。
例如,Zp052b 扩展是 P 扩展的 0.52 版本,是一个旧版本的实验性扩展。ZCC 将该版本提取成一个标准版本,并且给予命名 Zp052b。使用此扩展时,不需要添加版本号,直接使用 zp052b 即可。
zcc -march=rv32imaczp052b -c hello.c
zcc -march=rv32imafdc -c hello.c
| Extension | Version | Feature | Description |
|---|---|---|---|
| I | 2.1 | i | Base Integer Instruction Set |
| E | 2.0 | e | Implements RV64E (provides 16 rather than 32 GPRs) |
| M | 2.0 | m | Integer Multiplication and Division |
| A | 2.1 | a | Atomic Instructions |
| F | 2.2 | f | Single-Precision Floating-Point |
| D | 2.2 | d | Double-Precision Floating-Point |
| C | 2.0 | c | Compressed Instructions |
| B | 1.0 | b | The collection of the Zba, Zbb, Zbs extensions |
| V | 1.0 | v | Vector Extension for Application Processors |
| H | 1.0 | h | Hypervisor |
| Zic64b | 1.0 | zic64b | Cache Block Size Is 64 Bytes |
| Zicbom | 1.0 | zicbom | Cache-Block Management Instructions |
| Zicbop | 1.0 | zicbop | Cache-Block Prefetch Instructions |
| Zicboz | 1.0 | zicboz | Cache-Block Zero Instructions |
| Ziccamoa | 1.0 | ziccamoa | Main Memory Supports All Atomics in A |
| Ziccif | 1.0 | ziccif | Main Memory Supports Instruction Fetch with Atomicity Requirement |
| Zicclsm | 1.0 | zicclsm | Main Memory Supports Misaligned Loads/Stores |
| Ziccrse | 1.0 | ziccrse | Main Memory Supports Forward Progress on LR/SC Sequences |
| Zicntr | 2.0 | zicntr | Base Counters and Timers |
| Zicond | 1.0 | zicond | Integer Conditional Operations |
| Zicsr | 2.0 | zicsr | Control and Status Register (CSR) Instructions |
| Zifencei | 2.0 | zifencei | fence.i |
| Zihintntl | 1.0 | zihintntl | Non-Temporal Locality Hints |
| Zihintpause | 2.0 | zihintpause | Pause Hint |
| Zihpm | 2.0 | zihpm | Hardware Performance Counters |
| Zilsd | 1.0 | zilsd | Load/Store Pair Instructions |
| Zimop | 1.0 | zimop | May-Be-Operations |
| Zmmul | 1.0 | zmmul | Integer Multiplication |
| Za128rs | 1.0 | za128rs | Reservation Set Size of at Most 128 Bytes |
| Za64rs | 1.0 | za64rs | Reservation Set Size of at Most 64 Bytes |
| Zaamo | 1.0 | zaamo | Atomic Memory Operations |
| Zabha | 1.0 | zabha | Byte and Halfword Atomic Memory Operations |
| Zacas | 1.0 | zacas | Atomic Compare-And-Swap Instructions |
| Zalrsc | 1.0 | zalrsc | Load-Reserved/Store-Conditional |
| Zama16b | 1.0 | zama16b | Atomic 16-byte misaligned loads, stores and AMOs |
| Zawrs | 1.0 | zawrs | Wait on Reservation Set |
| Zfa | 1.0 | zfa | Additional Floating-Point |
| Zfbfmin | 1.0 | zfbfmin | Scalar BF16 Converts |
| Zfh | 1.0 | zfh | Half-Precision Floating-Point |
| Zfhmin | 1.0 | zfhmin | Half-Precision Floating-Point Minimal |
| Zfinx | 1.0 | zfinx | Float in Integer |
| Zdinx | 1.0 | zdinx | Double in Integer |
| Zca | 1.0 | zca | Part of the C extension, excluding compressed floating point loads/stores |
| Zcb | 1.0 | zcb | Compressed basic bit manipulation instructions |
| Zcd | 1.0 | zcd | Compressed Double-Precision Floating-Point Instructions |
| Zce | 1.0 | zce | Compressed extensions for microcontrollers |
| Zcf | 1.0 | zcf | Compressed Single-Precision Floating-Point Instructions |
| Zclsd | 1.0 | zclsd | Compressed Load/Store Pair Instructions |
| Zcmop | 1.0 | zcmop | Compressed May-Be-Operations |
| Zcmp | 1.0 | zcmp | Sequenced instructions for code-size reduction |
| Zcmt | 1.0 | zcmt | Table jump instructions for code-size reduction |
| Zba | 1.0 | zba | Address Generation Instructions |
| Zbb | 1.0 | zbb | Basic Bit-Manipulation |
| Zbc | 1.0 | zbc | Carry-Less Multiplication |
| Zbkb | 1.0 | zbkb | Bitmanip instructions for Cryptography |
| Zbkc | 1.0 | zbkc | Carry-less multiply instructions for Cryptography |
| Zbkx | 1.0 | zbkx | Crossbar permutation instructions |
| Zbs | 1.0 | zbs | Single-Bit Instructions |
| Zk | 1.0 | zk | Standard scalar cryptography extension |
| Zkn | 1.0 | zkn | NIST Algorithm Suite |
| Zknd | 1.0 | zknd | NIST Suite: AES Decryption |
| Zkne | 1.0 | zkne | NIST Suite: AES Encryption |
| Zknh | 1.0 | zknh | NIST Suite: Hash Function Instructions |
| Zkr | 1.0 | zkr | Entropy Source Extension |
| Zks | 1.0 | zks | ShangMi Algorithm Suite |
| Zksed | 1.0 | zksed | ShangMi Suite: SM4 Block Cipher Instructions |
| Zksh | 1.0 | zksh | ShangMi Suite: SM3 Hash Function Instructions |
| Zkt | 1.0 | zkt | Data Independent Execution Latency |
| Ztso | 1.0 | ztso | Memory Model - Total Store Order |
| Zp052b | 0.5 | zp052b | Packed-SIMD Instructions |
| Zp053b | 0.5 | zp053b | Packed-SIMD Instructions |
| Zp054b | 0.5 | zp054b | Packed-SIMD Instructions |
| Zp095b | 1.0 | zp095b | RV32 only 'P' Instructions |
| Zp64054b | 0.5 | zp64054b | Packed-SIMD Instructions |
| Zpn095b | 1.0 | zpn095b | Normal 'P' Instructions |
| Zprvsfextra095b | 1.0 | zprvsfextra095b | RV64 only 'P' Instructions |
| Zpsfoperand095b | 1.0 | zpsfoperand095b | Paired-register operand 'P' Instructions |
| Zvbb | 1.0 | zvbb | Vector basic bit-manipulation instructions |
| Zvbc | 1.0 | zvbc | Vector Carryless Multiplication |
| Zve32f | 1.0 | zve32f | Vector Extensions for Embedded Processors with maximal 32 EEW and F ex |
| Zve32x | 1.0 | zve32x | Vector Extensions for Embedded Processors with maximal 32 EEW |
| Zve64d | 1.0 | zve64d | Vector Extensions for Embedded Processors with maximal 64 EEW, F and D |
| Zve64f | 1.0 | zve64f | Vector Extensions for Embedded Processors with maximal 64 EEW and F ex |
| Zve64x | 1.0 | zve64x | Vector Extensions for Embedded Processors with maximal 64 EEW |
| Zvbfmin | 1.0 | zvfbfmin | Vector BF16 Converts |
| Zvfbfwma | 1.0 | zvfbfwma | Vector BF16 widening mul-add |
| Zvfh | 1.0 | zvfh | Vector Half-Precision Floating-Point |
| Zvfhmin | 1.0 | zvfhmin | Vector Half-Precision Floating-Point Minimal |
| Zvkb | 1.0 | zvkb | Vector Bit-manipulation used in Cryptography |
| Zvkg | 1.0 | zvkg | Vector GCM instructions for Cryptography |
| Zvkn | 1.0 | zvkn | Shorthand for 'Zvkned', 'Zvknhb', 'Zvkb', and 'Zvkt' |
| Zvknc | 1.0 | zvknc | Shorthand for 'Zvknc' and 'Zvbc' |
| Zvkned | 1.0 | zvkned | Vector AES Encryption & Decryption (Single Round) |
| Zvkng | 1.0 | zvkng | Shorthand for 'Zvkn' and 'Zvkg' |
| Zvknha | 1.0 | zvknha | Vector SHA-2 (SHA-256 only) |
| Zvknhb | 1.0 | zvknhb | Vector SHA-2 (SHA-256 and SHA-512) |
| Zvks | 1.0 | zvks | Shorthand for 'Zvksed', 'Zvksh', 'Zvkb', and 'Zvkt' |
| Zvksc | 1.0 | zvksc | Shorthand for 'Zvks' and 'Zvbc' |
| Zvksed | 1.0 | zvksed | SM4 Block Cipher Instructions |
| Zvksg | 1.0 | zvksg | Shorthand for 'Zvks' and 'Zvkg' |
| Zvksh | 1.0 | zvksh | SM3 Hash Function Instructions |
| Zvkt | 1.0 | zvkt | Vector Data-Independent Execution Latency |
| Zvl | 1.0 | zvl1024b | Zvl (Minimum Vector Length) 1024 |
| Zvl | 1.0 | zvl128b | Zvl (Minimum Vector Length) 128 |
| Zvl | 1.0 | zvl16384b | Zvl (Minimum Vector Length) 16384 |
| Zvl | 1.0 | zvl2048b | Zvl (Minimum Vector Length) 2048 |
| Zvl | 1.0 | zvl256b | Zvl (Minimum Vector Length) 256 |
| Zvl | 1.0 | zvl32768b | Zvl (Minimum Vector Length) 32768 |
| Zvl | 1.0 | zvl32b | Zvl (Minimum Vector Length) 32 |
| Zvl | 1.0 | zvl4096b | Zvl (Minimum Vector Length) 4096 |
| Zvl | 1.0 | zvl512b | Zvl (Minimum Vector Length) 512 |
| Zvl | 1.0 | zvl64b | Zvl (Minimum Vector Length) 64 |
| Zvl | 1.0 | zvl65536b | Zvl (Minimum Vector Length) 65536 |
| Zvl | 1.0 | zvl8192b | Zvl (Minimum Vector Length) 8192 |
| Zhinx | 1.0 | zhinx | Zhinx (Half Float in Integer) |
| Zhinxmin | 1.0 | zhinxmin | Zhinxmin (Half Float in Integer Minimal) |
| Shcounterenw | 1.0 | shcounterenw | Support writeable hcounteren enable bit for any hpmcounter that is not read-only zero |
| Sgatpa | 1.0 | shgatpa | SvNNx4 mode supported for all modes supported by satp, as well as Bare |
| Shtvala | 1.0 | shtvala | htval provides all needed values |
| Svsatpa | 1.0 | shvsatpa | vsatp supports all modes supported by satp |
| Shvstvala | 1.0 | shvstvala | vstval provides all needed values |
| Shvstvecd | 1.0 | shvstvecd | vstvec supports Direct mode |
| Smaia | 1.0 | smaia | Advanced Interrupt Architecture Machine Level |
| Smcdeleg | 1.0 | smcdeleg | Counter Delegation Machine Level |
| Smcsrind | 1.0 | smcsrind | Indirect CSR Access Machine Level |
| Smepmp | 1.0 | smepmp | Enhanced Physical Memory Protection |
| Smrnmi | 1.0 | smrnmi | Resumable Non-Maskable Interrupts |
| Smstateen | 1.0 | smstateen | Machine-mode view of the state-enable extension |
| Ssaia | 1.0 | ssaia | Advanced Interrupt Architecture Supervisor Level |
| Ssccfg | 1.0 | ssccfg | Counter Configuration Supervisor Level |
| Ssccptr | 1.0 | ssccptr | Main memory supports page table reads |
| Sscofpmf | 1.0 | sscofpmf | Count Overflow and Mode-Based Filtering |
| Sscounterenw | 1.0 | sscounterenw | Support writeable scounteren enable bit for any hpmcounter that is not read-only zero |
| Sscsrind | 1.0 | sscsrind | Indirect CSR Access Supervisor Level |
| Ssqosid | 1.0 | ssqosid | Quality-of-Service (QoS) Identifiers |
| Ssstateen | 1.0 | ssstateen | Supervisor-mode view of the state-enable extension |
| Ssstrict | 1.0 | ssstrict | No non-conforming extensions are present |
| Sstc | 1.0 | sstc | Supervisor-mode timer interrupts |
| Sstvala | 1.0 | sstvala | stval provides all needed values |
| Sstvecd | 1.0 | sstvecd | stvec supports Direct mode |
| Ssu64xl | 1.0 | ssu64xl | UXLEN=64 supported |
| Svade | 1.0 | svade | Raise exceptions on improper A/D bits |
| Svadu | 1.0 | svadu | Hardware A/D updates |
| Svbare | 1.0 | svbare | $(satp mode Bare supported) |
| Svinval | 1.0 | svinval | Fine-Grained Address-Translation Cache Invalidation |
| Svnapot | 1.0 | svnapot | NAPOT Translation Contiguity |
| Svpbmt | 1.0 | svpbmt | Page-Based Memory Types |
| Svvptc | 1.0 | svvptc | Obviating Memory-Management Instructions after Marking PTEs Valid |
RISC-V 实验性扩展
包含还未批准的实验性指令扩展,工具链版本之间不保证兼容性。使用这些扩展时需要添加版本号。
例如,在使用 Zalasr 扩展时,需要添加版本号,即使用 zalasr0p1 而不是 zalasr。
zcc -march=rv32imaczalasr0p1 -c hello.c
zcc -march=rv32imaczicfiss1p0 -c hello.c
| Extension | Version | Feature | Description |
|---|---|---|---|
| Zicfiss | 1.0 | zicfiss | Shadow stack |
| Zalasr | 0.1 | zalasr | Load-Acquire and Store-Release Instructions |
| Smmpm | 1.0 | smmpm | Machine-level Pointer Masking for M-mode |
| Smnpm | 1.0 | smnpm | Machine-level Pointer Masking for next lower privilege mode |
| Ssnpm | 1.0 | ssnpm | Supervisor-level Pointer Masking for next lower privilege mode |
| Sspm | 1.0 | sspm | Indicates Supervisor-mode Pointer Masking |
RISC-V 供应商扩展
下表列举了硬件厂商定义的非标准的自定义扩展在 ZCC 中的支持情况。
| Extension | Version | Feature | Description |
|---|---|---|---|
| Xandes | 5.0 | xandes | AndeStar V5 Extension Specification |
| XCValu | 1.0 | xcvalu | CORE-V ALU Operations |
| XCVbi | 1.0 | xcvbi | CORE-V Immediate Branching |
| XCVbitmanip | 1.0 | xcvbitmanip | CORE-V Bit Manipulation |
| XCVelw | 1.0 | xcvelw | CORE-V Event Load Word |
| XCVmac | 1.0 | xcvmac | CORE-V Multiply-Accumulate |
| XCVmem | 1.0 | xcvmem | CORE-V Post-incrementing Load & Store |
| XCVsimd | 1.0 | xcvsimd | CORE-V SIMD ALU |
| Xp | 4.0 | xgap8dsp | GAP8 DSP extension |
| Xm | 4.0 | xgap8m | GAP8 Integer Multiplication |
| Xv | 4.0 | xgap8v | GAP8 Vector extension |
| XSfcease | 1.0 | xsfcease | SiFive sf.cease Instruction |
| XSfvcp | 1.0 | xsfvcp | SiFive Custom Vector Coprocessor Interface Instructions |
| XSfvfnrclipxfqf | 1.0 | xsfvfnrclipxfqf | SiFive FP32-to-int8 Ranged Clip Instructions |
| XSfvfwmaccqqq | 1.0 | xsfvfwmaccqqq | SiFive Matrix Multiply Accumulate Instruction and 4-by-4 |
| XSfvqmaccdod | 1.0 | xsfvqmaccdod | SiFive Int8 Matrix Multiplication Instructions 2-by-8 and 8-by-2 |
| XSfvqmaccqoq | 1.0 | xsfvqmaccqoq | SiFive Int8 Matrix Multiplication Instructions 4-by-8 and 8-by-4 |
| XSiFivecdiscarddlone | 1.0 | xsifivecdiscarddlone | SiFive sf.cdiscard.d.l1 Instruction |
| XSiFivecflushdlone | 1.0 | xsifivecflushdlone | SiFive sf.cflush.d.l1 Instruction |
| XTHeadBa | 1.0 | xtheadba | T-Head address calculation instructions |
| XTHeadBb | 1.0 | xtheadbb | T-Head basic bit-manipulation instructions |
| XTHeadBs | 1.0 | xtheadbs | T-Head single-bit instructions |
| XTHeadC | 2.0 | xtheadc | T-Head C series performance-enhanced instruction set |
| XTHeadCBI | 1.0 | xtheadcbi | Xuantie coprocessor basic integer intruction |
| XTHeadCEI | 1.0 | xtheadcei | Xuantie coprocessor enhanced integer intruction |
| XTHeadCF | 1.0 | xtheadcf | Xuantie coprocessor float intruction |
| XTHeadCmo | 1.0 | xtheadcmo | T-Head cache management instructions |
| XTHeadCondMov | 1.0 | xtheadcondmov | T-Head conditional move instructions |
| XTHeadCV | 1.0 | xtheadcv | Xuantie coprocessor vector intruction |
| XTHeadE | 2.0 | xtheade | T-Head E series performance-enhanced instruction set |
| XTHeadFMemIdx | 1.0 | xtheadfmemidx | T-Head FP Indexed Memory Operations |
| XTHeadFMv | 1.0 | xtheadfmv | T-Head FP Move Instructions |
| XTHeadInt | 1.0 | xtheadint | T-Head Acceleration Interruption Instructions |
| XTHeadLPW | 1.0 | xtheadlpw | T-Head Low Power Wait Instructions |
| XTHeadMac | 1.0 | xtheadmac | T-Head Multiply-Accumulate Instructions |
| XTHeadMemIdx | 1.0 | xtheadmemidx | T-Head Indexed Memory Operations |
| XTHeadMemPair | 1.0 | xtheadmempair | T-Head two-GPR Memory Operations |
| XTHeadSE | 2.0 | xtheadse | T-Head Small E series performance-enhanced instruction set |
| XTHeadSync | 1.0 | xtheadsync | T-Head multicore synchronization instructions |
| XTHeadVdot | 1.0 | xtheadvdot | T-Head Vector Extensions for Dot |
| XVentanaCondOps | 1.0 | xventanacondops | Ventana Conditional Ops |
| Xwchc | 2.2 | xwchc | WCH/QingKe additional compressed opcodes |
| Xxlcz | 1.0 | xxlcz | Nuclei Additional Xlcz Instruction for Codesize |
| Xxldsp | 1.0 | xxldsp | Nuclei customized DSP instructions for both RV32 and RV64 |
| Xxldspn1x | 1.0 | xxldspn1x | Nuclei customized DSP N1 instructions only for RV32 |
| Xxldspn2x | 1.0 | xxldspn2x | Nuclei customized DSP N2 instructions only for RV32 |
| Xxldspn3x | 1.0 | xxldspn3x | Nuclei customized DSP N3 instructions only for RV32 |
| Xxlvqmacc | 1.0 | xxlvqmacc | Nuclei Int8 Matrix Multiplication Instructions |
RISC-V 预设组合
可以使用 -march 指定支持的 RISC-V 设定扩展组合,目前支持的扩展组合如下表:
| Supported Profiles | Experimental Profiles |
|---|---|
| rva20s64 | rva23s64 |
| rva20u64 | rva23u64 |
| rva22s64 | rvb23s64 |
| rva22u64 | rvb23u64 |
| rvi20u32 | rvm23u32 |
| rvi20u64 |
用户也可以在设定扩展组合之后附加其他扩展,例如 rva20u64_zicond 将启用 zicond 扩展以及 rva20u64 设定扩展组合中的功能。
编译选项和参数
ZCC 4.x 基于 LLVM 19.1.6 版本进行开发,所以大部分 LLVM 的编译器选项都适用于 ZCC。
-target 参数
使用 -target <architecture> 选择需要将源代码编译到可以在 <architecture> 平台运行的二进制文件,可用参数如下:
- riscv64-unknown-elf
- riscv32-unknown-elf
- riscv64-unknown-linux-gnu
-march 参数
使用 -march=<architecture> 指定生成代码的目标处理器架构。
对于 march 的检测规则采用 -march=rv[32|64][i|e][extensions],使用时不限定先后顺序,同时最后链接时将会按照指定 march 进行指令生成。举例:使用 -march=rv32imafc 找的是 rv32ifa 的库,但是最终依旧可以成功生成 M 扩展的指令。
Multilib
ZCC 将根据用户所指定的 arch/abi 组合,选择兼容的函数库添加到应用程序中。例如:
| 指定的 arch/abi 组合 | 应用的函数库 |
|---|---|
-march=rv32imafc -mabi=ilp32f | rv32ifa/ilp32f |
-march=rv32imafc_zba_zbb_zbc_zbs_zp052b -mabi=ilp32f | rv32iafzp/ilp32f |
对于应用程序使用到函数库中不存在的 Arch,如 M 和 C 扩展,其优化将在 IR 翻译到汇编的阶段进行,因此优化不会缺失。对于某些 Arch,如 P 和 V 扩展,因为其优化在 C 源码翻译到 IR 时进行,必须为其单独做库。
-mtune 参数
添加 -mtune= 参数后,编译器会将代码优化为在目标系列 CPU 上性能更优的版本。 -mtune= 参数的可用选项如下:
- THead
- thead-c908-series
- Andes
- andes-kavalan
- andes-vicuna
- andes-23-series
- andes-25-series
- andes-45-series
- andes-d25-series
- andes-d45-series
- Tenstorrent
- ascalon
- Nuclei
- nuclei-100-series
- nuclei-200-series
- nuclei-300-series
- nuclei-310-series
- nuclei-600-series
- nuclei-900-series
- nuclei-1000-series
- Rocket
- rocket
- Imagination
- rtxm2200
- Sifive
- sifive-7-series
- Syntacore
- syntacore-scr1-series
优化选项
-
-O0, -O1, -O2, -O3, -Os用于控制优化等级。
-
-O0: 无优化。生成可读性最好的代码,编译速度最快,用于调试目的。
-
-O1: 基本优化。执行一些常见的优化,如删除未引用的函数和数据、复制传递、简单的常数传播等。
-
-O2: 常用优化。执行更多的优化,包括内联函数、循环展开、常量折叠等,可能会增加编译时间。
-
-O3: 高级优化。执行更激进的优化,可能会增加编译时间,但生成的代码通常更快。
-
-Os: 优化代码大小,以减小生成的可执行文件的大小。
-