Rustで作るBinary Translation型のエミュレータ、基本的な機能はかなり備わってきて、システムコールも一部サポートしたので次はベンチマークテストを動かそう。まずはDhrystoneだろう。printf()
が動くようになったのでDhrystoneは問題なく動くはずだ。
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/dhrystone.riscv
0000000080002c6c:0000000080002c6c Hostcode 00098513 : mv a0, s3 0000000080002c70:0000000080002c70 Hostcode cb9ff0ef : jal pc + 0xffcb8 0000000080002928:0000000080002928 Hostcode 00151793 : slli a5, a0, 1 000000008000292c:000000008000292c Hostcode 0017e793 : ori a5, a5, 1 0000000080002930:0000000080002930 Hostcode ffffe717 : auipc a4, 0xffffe 0000000080002934:0000000080002934 Hostcode 6cf73823 : sd a5, 1744(a4) 1.989 finished Result: MEM[0x1000] = 00000001
テストパタン自体は完走したようだ。後はstep実行とログ生成をやめてみよう。
$ cargo run -- --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/dhrystone.riscv
sys_write() = 80006580 ,tohost = 80026140 Microseconds for one run through Dhrystone: 0 sys_write() = 80006580 ,tohost = 80026140 Dhrystones per Second: -1 0.066 finished Result: MEM[0x1000] = 00000001
いいね、かなり高速に実行できているようだ。とりあえず用意されているテストベンチをすべて実行してみよう。
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/median.riscv
... 00000000800025d8:00000000800025d8 Hostcode fffff717 : auipc a4, 0xfffff 00000000800025dc:00000000800025dc Hostcode a2f73423 : sd a5, -1496(a4) 0.429 finished Result: MEM[0x1000] = 00000001
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/mm.riscvs
0000000080004f34:0000000080004f34 Hostcode 01b77637 : lui a2, 0x1b77 0000000080004f38:0000000080004f38 Hostcode 40060613 : addi a2, a2, 1024 0000000080004f3c:0000000080004f3c Hostcode 03965633 : divu a2, a2, s9 zsh: floating point exception (core dumped) cargo run -- --step --dump-guest --elf-file
あ、やべゼロ割の例外起こしてしまった。
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/mt-matmul.riscv
000000008000203c:000000008000203c Hostcode 00072783 : lw a5, 0(a4) 0000000080002040:0000000080002040 Hostcode fef69ee3 : bne a3, a5, pc + 4092 000000008000203c:000000008000203c Hostcode 00072783 : lw a5, 0(a4) 0000000080002040:0000000080002040 Hostcode fef69ee3 : bne a3, a5, pc + 4092
うーん、無限ループに陥った?
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/multiply.riscv
00000000800028d0:00000000800028d0 Hostcode cbdff0ef : jal pc + 0xffcbc 000000008000258c:000000008000258c Hostcode 00151793 : slli a5, a0, 1 0000000080002590:0000000080002590 Hostcode 0017e793 : ori a5, a5, 1 0000000080002594:0000000080002594 Hostcode fffff717 : auipc a4, 0xfffff 0000000080002598:0000000080002598 Hostcode a6f73623 : sd a5, -1428(a4) 0.404 finished Result: MEM[0x1000] = 00000001
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/qsort.riscv
0000000080002740:0000000080002740 Hostcode 00151793 : slli a5, a0, 1 0000000080002744:0000000080002744 Hostcode 0017e793 : ori a5, a5, 1 0000000080002748:0000000080002748 Hostcode fffff717 : auipc a4, 0xfffff 000000008000274c:000000008000274c Hostcode 8af73c23 : sd a5, -1864(a4) 0.644 finished Result: MEM[0x1000] = 00000001
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/rsort.riscv
00000000800028e8:00000000800028e8 Hostcode 0017e793 : ori a5, a5, 1 00000000800028ec:00000000800028ec Hostcode ffffe717 : auipc a4, 0xffffe 00000000800028f0:00000000800028f0 Hostcode 70f73a23 : sd a5, 1812(a4) 0.862 finished Result: MEM[0x1000] = 00000001
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/spmv.riscv
0000000080002c14:0000000080002c14 Hostcode d5058593 : addi a1, a1, 3408 0000000080002c18:0000000080002c18 Hostcode 1f400513 : li a0, 500 0000000080002c1c:0000000080002c1c Hostcode be4ff0ef : jal pc + 0xff3e4 fmadd(emu, 15, 5, 4, 15) is called! fmadd(emu, 14, 3, 2, 14) is called! fmadd(emu, 12, 1, 0, 12) is called! fmadd(emu, 13, 10, 11, 13) is called! zsh: segmentation fault (core dumped) cargo run -- --step --dump-guest --elf-file
あ、Segmentation Faultで落ちてしまった。
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/towers.riscv
0000000080002930:0000000080002930 Hostcode 0017e793 : ori a5, a5, 1 0000000080002934:0000000080002934 Hostcode ffffe717 : auipc a4, 0xffffe 0000000080002938:0000000080002938 Hostcode 6cf73623 : sd a5, 1740(a4) 0.598 finished Result: MEM[0x1000] = 00000001
$ cargo run -- --step --dump-guest --elf-file /home/msyksphinz/work/riscv/riscv-tools/riscv-tests/benchmarks/vvadd.riscv
0000000080002598:0000000080002598 Hostcode 00151793 : slli a5, a0, 1 000000008000259c:000000008000259c Hostcode 0017e793 : ori a5, a5, 1 00000000800025a0:00000000800025a0 Hostcode fffff717 : auipc a4, 0xfffff 00000000800025a4:00000000800025a4 Hostcode a6f73023 : sd a5, -1440(a4) 0.397 finished Result: MEM[0x1000] = 00000001