avoid non-standard predefined macros
[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 bmarks_host = \
34 median \
35 qsort \
36 towers \
37 vvadd \
38 multiply \
39 spmv \
40 vec-vvadd \
41 vec-cmplxmult \
42 vec-matmul \
43
44 #--------------------------------------------------------------------
45 # Build rules
46 #--------------------------------------------------------------------
47
48 HOST_OPTS = -std=gnu99 -DPREALLOCATE=0 -DHOST_DEBUG=1
49 HOST_COMP = gcc $(HOST_OPTS)
50
51 RISCV_PREFIX ?= riscv$(XLEN)-unknown-elf-
52 RISCV_GCC ?= $(RISCV_PREFIX)gcc
53 RISCV_GCC_OPTS ?= -mcmodel=medany -static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf
54 RISCV_LINK ?= $(RISCV_GCC) -T $(src_dir)/common/test.ld $(incs)
55 RISCV_LINK_MT ?= $(RISCV_GCC) -T $(src_dir)/common/test-mt.ld
56 RISCV_LINK_OPTS ?= -nostdlib -nostartfiles -ffast-math -lgcc
57 RISCV_OBJDUMP ?= $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data
58 RISCV_SIM ?= spike
59
60 VPATH += $(addprefix $(src_dir)/, $(bmarks))
61 VPATH += $(src_dir)/common
62
63 incs += -I$(src_dir)/../env -I$(src_dir)/common $(addprefix -I$(src_dir)/, $(bmarks))
64 objs :=
65
66 include $(patsubst %, $(src_dir)/%/bmark.mk, $(bmarks))
67
68 #------------------------------------------------------------
69 # Build and run benchmarks on riscv simulator
70
71 bmarks_riscv_bin = $(addsuffix .riscv, $(bmarks))
72 bmarks_riscv_dump = $(addsuffix .riscv.dump, $(bmarks))
73 bmarks_riscv_out = $(addsuffix .riscv.out, $(bmarks))
74
75 bmarks_defs = -DPREALLOCATE=1 -DHOST_DEBUG=0
76 bmarks_cycles = 80000
77
78 $(bmarks_riscv_dump): %.riscv.dump: %.riscv
79 $(RISCV_OBJDUMP) $< > $@
80
81 $(bmarks_riscv_out): %.riscv.out: %.riscv
82 $(RISCV_SIM) $< > $@
83
84 %.o: %.c
85 $(RISCV_GCC) $(RISCV_GCC_OPTS) $(bmarks_defs) \
86 -c $(incs) $< -o $@
87
88 %.o: %.S
89 $(RISCV_GCC) $(RISCV_GCC_OPTS) $(bmarks_defs) -D__ASSEMBLY__=1 \
90 -c $(incs) $< -o $@
91
92 riscv: $(bmarks_riscv_dump)
93 run-riscv: $(bmarks_riscv_out)
94 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
95 $(bmarks_riscv_out); echo;
96
97 junk += $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(bmarks_riscv_hex) $(bmarks_riscv_out)
98
99 #------------------------------------------------------------
100 # Build and run benchmarks on host machine
101
102 bmarks_host_bin = $(addsuffix .host, $(bmarks_host))
103 bmarks_host_out = $(addsuffix .host.out, $(bmarks_host))
104
105 $(bmarks_host_out): %.host.out: %.host
106 ./$< > $@
107
108 host: $(bmarks_host_bin)
109 run-host: $(bmarks_host_out)
110 echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
111 $(bmarks_host_out); echo;
112
113 junk += $(bmarks_host_bin) $(bmarks_host_out)
114
115 #------------------------------------------------------------
116 # Default
117
118 all: riscv
119
120 #------------------------------------------------------------
121 # Install
122
123 date_suffix = $(shell date +%Y-%m-%d_%H-%M)
124 install_dir = $(instbasedir)/$(instname)-$(date_suffix)
125 latest_install = $(shell ls -1 -d $(instbasedir)/$(instname)* | tail -n 1)
126
127 install:
128 mkdir $(install_dir)
129 cp -r $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(install_dir)
130
131 install-link:
132 rm -rf $(instbasedir)/$(instname)
133 ln -s $(latest_install) $(instbasedir)/$(instname)
134
135 #------------------------------------------------------------
136 # Clean up
137
138 clean:
139 rm -rf $(objs) $(junk)