FPGA開発日記

FPGAというより、コンピュータアーキテクチャかもね! カテゴリ別記事インデックス https://sites.google.com/site/fpgadevelopindex/

Coremark-ProをRISC-Vのgccを使ってコンパイルする

github.com

Coremark-ProをRISC-Vの環境でコンパイルするためにいろいろ修正したまとめ。

まず、util/make/ にRISC-V向けの環境ファイルを追加した。 基本は、fakeio.mak と linux.mak を使ってそれを変更することで対応している。

$ diff -w fakeio.mak gcc-riscv.mak
26c26,27
< TOOLS = /usr
---
> TOOLS = /home/vagrant/riscv-ver1.7/
> GNU_TARGET=riscv64-unknown-elf-
39c40
< CC            = $(TOOLS)/bin/gcc
---
> CC            = $(TOOLS)/bin/$(GNU_TARGET)gcc
50c51
< AS            = $(TOOLS)/bin/as
---
> AS            = $(TOOLS)/bin/$(GNU_TARGET)as
54c55
< LD            = $(TOOLS)/bin/gcc
---
> LD            = $(TOOLS)/bin/$(GNU_TARGET)gcc
60c61
< AR            = $(TOOLS)/bin/ar
---
> AR            = $(TOOLS)/bin/$(GNU_TARGET)ar
83,84c84,85
< COMPILER_FLAGS        = -O2 $(CDEFN)NDEBUG $(CDEFN)HOST_EXAMPLE_CODE=1 -std=gnu99 -mpc64
< COMPILER_NOOPT        = -g -O0 $(CDEFN)NDEBUG $(CDEFN)HOST_EXAMPLE_CODE=1 -mpc64
---
> COMPILER_FLAGS        = -O2 $(CDEFN)NDEBUG $(CDEFN)HOST_EXAMPLE_CODE=1 -std=gnu99
> COMPILER_NOOPT        = -g -O0 $(CDEFN)NDEBUG $(CDEFN)HOST_EXAMPLE_CODE=1
119c120
< COMPILER_DEFINES += HAVE_SYS_STAT_H=1 USE_NATIVE_PTHREAD=1 GCC_INLINE_MACRO=1 NO_RESTRICT_QUALIFIER=1 FAKE_FILEIO=1
---
> COMPILER_DEFINES += HAVE_SYS_STAT_H=1 USE_NATIVE_PTHREAD=0 USE_SINGLE_CONTEXT=1 GCC_INLINE_MACRO=1 NO_RESTRICT_QUALIFIER=1 FAKE_FILEIO=1 NO_ALIGNED_ALLOC=1
143c144
<  LINKER_LAST  += -lm -lpthread
---
>  LINKER_LAST  += -lm
147c148
<   LINKER_LAST         += -lrt
---
>   LINKER_LAST         +=
203,204d203
<
<
$ diff -w linux.mak linux-riscv.mak
6c6
< TOOLCHAIN=gcc
---
> TOOLCHAIN=gcc-riscv

また、何故かpthreadの定義がコンパイル時に足りないと言われたの、th_al.cに以下を追加した。

$ git show 30c5806
commit 30c580639c643adf6b0773e9e2d04bae5af6e07c
Author: Masayuki Kimura <masayuki.kimura.1986@gmail.com>
Date:   Sun Jun 7 06:00:40 2015 +0000

    Func: add timespec and clock_gettime in th_al.c for compiling

diff --git a/coremark-pro_1.1.2446/mith/al/src/th_al.c b/coremark-pro_1.1.2446/mith/al/src/th_al.c
index 6f1bc2c..069a72e 100644
--- a/coremark-pro_1.1.2446/mith/al/src/th_al.c
+++ b/coremark-pro_1.1.2446/mith/al/src/th_al.c
@@ -65,6 +65,16 @@ Please refer to http://www.eembc.org/license.php for the specific license agreem
 #include <valgrind/callgrind.h>
 #endif

+struct timespec {
+       long  tv_sec;
+       long  tv_nsec;
+};
+long clock_gettime(int X, struct timespec *t) {
+       t->tv_sec=0;
+       t->tv_nsec=0;
+       return 0;
+}
+
 /** Define Host specific (POSIX), or target specific global time variables. */
 /* Define: TIMER_RES_DIVIDER
        Divider to trade off timer resolution and total time that can be measured.
@@ -77,7 +87,7 @@ Please refer to http://www.eembc.org/license.php for the specific license agreem
                #include <time.h>
                #define NSECS_PER_SEC CLOCKS_PER_SEC
                #define EE_TIMER_TICKER_RATE 1000
-               #define ALTIMETYPE clock_t
+               #define ALTIMETYPE clock_t
                #define GETMYTIME(_t) (*_t=clock())
                #define MYTIMEDIFF(fin,ini) ((fin)-(ini))
                #define TIMER_RES_DIVIDER 1

最後の方に、余分なdiffが入ってしまっているな... whitespaceを最後に追加してるのを消しちゃったのが原因かな。

これで一通りコンパイルできるようになったが、まだstartupのルーチンとかを入れていないため、ちゃんと動作しないと思う。それはまた修正していく。

ちなみに、x86で動作させるときの実行オプションは、

$ make TARGET=linux TOOLCHAIN=gcc64 | ag exe
make[3]: /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/benchmarks/fp/linpack/SP/../Makefile: No such file or directory
make[3]: *** No rule to make target '/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/benchmarks/fp/linpack/SP/../Makefile'.  Stop.
make[2]: *** [/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/obj/bench/fp/linpack/SP/done.build] Error 2
make[3]: /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/benchmarks/fp/loops/SP/../Makefile: No such file or directory
make[3]: *** No rule to make target '/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/benchmarks/fp/loops/SP/../Makefile'.  Stop.
make[2]: *** [/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/obj/bench/fp/loops/SP/done.build] Error 2
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/cjpeg-rose7-preset.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/cjpeg-rose7-preset.run.log 2>&1
/usr/bin/size  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/cjpeg-rose7-preset.exe >  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/cjpeg-rose7-preset.size.log
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/sha-test.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/sha-test.run.log 2>&1
/usr/bin/size  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/sha-test.exe >  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/sha-test.size.log
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/core.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/core.run.log 2>&1
/usr/bin/size  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/core.exe >  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/core.size.log
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/nnet_test.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/nnet_test.run.log 2>&1
/usr/bin/size  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/nnet_test.exe >  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/nnet_test.size.log
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/linear_alg-mid-100x100-sp.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/linear_alg-mid-100x100-sp.run.log 2>&1
make[2]: *** [run] Error 127
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/parser-125k.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/parser-125k.run.log 2>&1
/usr/bin/size  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/parser-125k.exe >  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/parser-125k.size.log
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/loops-all-mid-10k-sp.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/loops-all-mid-10k-sp.run.log 2>&1
make[2]: *** [run] Error 127
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/radix2-big-64k.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/radix2-big-64k.run.log 2>&1
/usr/bin/size  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/radix2-big-64k.exe >  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/radix2-big-64k.size.log
/home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/zip-test.exe     > /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/zip-test.run.log 2>&1
/usr/bin/size  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/bin/zip-test.exe >  /home/vagrant/benchmarks_x86/coremark-pro_1.1.2446/builds/linux/gcc64/logs/zip-test.size.log

基本的に引数は付けていないから、main時のargc,argvについて調整を考える必要はないかな。