28ba2b785c28f7ccfd19f33cd1af261fefb6e483
[riscv-tests.git] / benchmarks / Makefile
1 #=======================================================================
2 # UCB VLSI FLOW: Makefile for riscv-bmarks
3 #-----------------------------------------------------------------------
4 # Yunsup Lee (yunsup@cs.berkeley.edu)
5 #
6
7 XLEN ?= 64
8
9 default: all
10
11 src_dir = .
12
13 instname = riscv-bmarks
14 instbasedir = $(UCB_VLSI_HOME)/install
15
16 #--------------------------------------------------------------------
17 # Sources
18 #--------------------------------------------------------------------
19
20 bmarks = \
21 median \
22 qsort \
23 rsort \
24 towers \
25 vvadd \
26 multiply \
27 mm \
28 dhrystone \
29 spmv \
30 mt-vvadd \
31 mt-matmul \
32
33 #--------------------------------------------------------------------
34 # Build rules
35 #--------------------------------------------------------------------
36
37 RISCV_PREFIX ?= riscv$(XLEN)-unknown-elf-
38 RISCV_GCC ?= $(RISCV_PREFIX)gcc
39 RISCV_GCC_OPTS ?= -DPREALLOCATE=1 -mcmodel=medany -static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf
40 RISCV_LINK ?= $(RISCV_GCC) -T $(src_dir)/common/test.ld $(incs)
41 RISCV_LINK_OPTS ?= -static -nostdlib -nostartfiles -lgcc -T $(src_dir)/common/test.ld
42 RISCV_OBJDUMP ?= $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data
43 RISCV_SIM ?= spike --isa=rv$(XLEN)gc
44
45 incs += -I$(src_dir)/../env -I$(src_dir)/common $(addprefix -I$(src_dir)/, $(bmarks))
46 objs :=
47
48 define compile_template
49 $(1).riscv: $(wildcard $(src_dir)/$(1)/*) $(wildcard $(src_dir)/common/*)
50 $$(RISCV_GCC) $$(incs) $$(RISCV_GCC_OPTS) $$(RISCV_LINK_OPTS) -o $$@ $(wildcard $(src_dir)/$(1)/*.c) $(wildcard $(src_dir)/common/*.c) $(wildcard $(src_dir)/common/*.S)
51 endef
52
53 $(foreach bmark,$(bmarks),$(eval $(call compile_template,$(bmark))))
54
55 #------------------------------------------------------------
56 # Build and run benchmarks on riscv simulator
57
58 bmarks_riscv_bin = $(addsuffix .riscv, $(bmarks))
59 bmarks_riscv_dump = $(addsuffix .riscv.dump, $(bmarks))
60 bmarks_riscv_out = $(addsuffix .riscv.out, $(bmarks))
61
62 $(bmarks_riscv_dump): %.riscv.dump: %.riscv
63 $(RISCV_OBJDUMP) $< > $@
64
65 $(bmarks_riscv_out): %.riscv.out: %.riscv
66 $(RISCV_SIM) $< > $@
67
68 riscv: $(bmarks_riscv_dump)
69 run: $(bmarks_riscv_out)
70 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
71 $(bmarks_riscv_out); echo;
72
73 junk += $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(bmarks_riscv_hex) $(bmarks_riscv_out)
74
75 #------------------------------------------------------------
76 # Default
77
78 all: riscv
79
80 #------------------------------------------------------------
81 # Install
82
83 date_suffix = $(shell date +%Y-%m-%d_%H-%M)
84 install_dir = $(instbasedir)/$(instname)-$(date_suffix)
85 latest_install = $(shell ls -1 -d $(instbasedir)/$(instname)* | tail -n 1)
86
87 install:
88 mkdir $(install_dir)
89 cp -r $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(install_dir)
90
91 install-link:
92 rm -rf $(instbasedir)/$(instname)
93 ln -s $(latest_install) $(instbasedir)/$(instname)
94
95 #------------------------------------------------------------
96 # Clean up
97
98 clean:
99 rm -rf $(objs) $(junk)