RISC-Vのベクトル拡張命令であるRISC-V Vector Extensionは仕様の策定されており、徐々に実装が進んでいる。
- riscv-toolsのSpike命令セットシミュレータ
- riscv-gnu-toolchainの対応
現在の実装の状況を見てみることにした。
riscv-toolsのインストール
riscv-toolsには、RVV(RISC-V Vector Extension)をサポートするためのブランチが切ってある。
git clone https://github.com/riscv/riscv-tools.git
新たにRVVのツールセットをインストールするディレクトリを決めて、インストールする。
- riscv-isa-sim (Spike)
export RISCV=${HOME}/riscv_rvv cd riscv-isa-sim git checkout b1bde2b ./configure --prefix=${HOME}/riscv_rvv make -j4 make install
バージョンの確認。
Spike RISC-V ISA Simulator 1.0.1-dev
usage: spike [host options] <target program> [target options]
Host Options:
-p<n> Simulate <n> processors [default 1]
-m<n> Provide <n> MiB of target memory [default 2048]
-m<a:m,b:n,...> Provide memory regions of size m and n bytes
at base addresses a and b (with 4 KiB alignment)
-d Interactive debug mode
-g Track histogram of PCs
-l Generate a log of execution
-h, --help Print this help message
-H Start halted, allowing a debugger to connect
--isa=<name> RISC-V ISA string [default RV64IMAFDC]
--varch=<name> RISC-V Vector uArch string [default v128:e32:s128]
--pc=<address> Override ELF entry point
--hartids=<a,b,...> Explicitly specify hartids, default is 0,1,...
--ic=<S>:<W>:<B> Instantiate a cache model with S sets,
--dc=<S>:<W>:<B> W ways, and B-byte blocks (with S and
--l2=<S>:<W>:<B> B both powers of 2).
...
git clone https://github.com/riscv/riscv-gnu-toolchain.git cd riscv-gnu-toolchain git checkout rvv-0.7.x mkdir build cd build ../configure --prefix=${RISCV} make -j4
バージョン確認
$ riscv64-unknown-elf-gcc --version riscv64-unknown-elf-gcc (GCC) 8.3.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
簡単なプログラムをコンパイルしてみる。
まだauto-vectorizationは効かないようなので、サンプルでテスト用についているプログラムをコンパイルしてみる。
riscv64-unknown-elf-gcc -O3 -march=rv64gcv /home/msyksphinz/work/riscv/riscv-tools/riscv-gnu-toolchain/riscv-binutils/gas/testsuite/gas/riscv/vector-insns.s -c
riscv64-unknown-elf-objdump -d vector-insns.o | less
...
vector-insns.o: file format elf64-littleriscv
Disassembly of section .text:
0000000000000000 <.text>:
0: 80c5f557 vsetvl a0,a1,a2
4: 0005f557 vsetvli a0,a1,e8,m1,d1
8: 7ff5f557 vsetvli a0,a1,2047
c: 0455f557 vsetvli a0,a1,e16,m2,d4
10: 12050207 vlb.v v4,(a0)
14: 12050207 vlb.v v4,(a0)
18: 10050207 vlb.v v4,(a0),v0.t
1c: 12055207 vlh.v v4,(a0)
20: 12055207 vlh.v v4,(a0)