aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/rules.mk
blob: cab957c0dcc4f624834071eaf69c9951862039c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# This Makefile does not depend on ../rules.mk
SHELL=bash

# You can modify ALL_CFILES to include the files that should be linked
ALL_CFILES?=$(wildcard *.c)

# Name of the target
TARGET?=toto

# Arguments of execution
EXECUTE_ARGS?=

# Name of the clock object
CLOCK=../clock

# Maximum amount of time measures (see cycles.h)
MAX_MEASURES=10
MEASURES?=time

# Flags common to both compilers, then to gcc, then to ccomp
ALL_CFLAGS+=-Wall -D__KVX_COS__ -DMAX_MEASURES=$(MAX_MEASURES)
#ALL_CFLAGS+=-g
ALL_GCCFLAGS+=$(ALL_CFLAGS) -std=c99 -Wextra -Werror=implicit
ALL_CCOMPFLAGS+=$(ALL_CFLAGS) # -fprofile-use= ../compcert_profiling.dat

# The compilers
KVX_CC?=kvx-elf-gcc
KVX_CCOMP?=ccomp

# Command to execute
#EXECUTE_CYCLES?=timeout --signal=SIGTERM 3m kvx-cluster --syscall=libstd_scalls.so --cycle-based --
EXECUTE_CYCLES?=kvx-cluster --enable-cache --syscall=libstd_scalls.so --cycle-based --

# You can define up to GCC4FLAGS and CCOMP4FLAGS
GCC0FLAGS?=$(ALL_GCCFLAGS) -O0
GCC1FLAGS?=$(ALL_GCCFLAGS) -O1
GCC2FLAGS?=$(ALL_GCCFLAGS) -O2
GCC3FLAGS?=$(ALL_GCCFLAGS) -O3
GCC4FLAGS?=
CCOMP0FLAGS?=$(ALL_CCOMPFLAGS) -O2 
CCOMP1FLAGS?=$(ALL_CCOMPFLAGS) -O2 -fprepass= list
CCOMP2FLAGS?=$(ALL_CCOMPFLAGS) -O2 -funrollsingle 30
CCOMP3FLAGS?=$(ALL_CCOMPFLAGS) -O2 -fprepass= list -funrollsingle 30
CCOMP4FLAGS?=$(ALL_CCOMPFLAGS) -O2 -fprepass= zigzag

# Prefix names
GCC0PREFIX?=.gcc.o0
GCC1PREFIX?=.gcc.o1
GCC2PREFIX?=.gcc.o2
GCC3PREFIX?=.gcc.o3
GCC4PREFIX?=
CCOMP0PREFIX?=.ccomp
CCOMP1PREFIX?=.ccomp.prepass_list
CCOMP2PREFIX?=.ccomp.unrollsingle_30
CCOMP3PREFIX?=.ccomp.prepass_list-unrollsingle_30
CCOMP4PREFIX?=.ccomp.prepass_zigzag

# List of outfiles, updated by gen_rules
OUTFILES:=
BINFILES:=

# First line of the CSV file, completed later
FIRSTLINE:=benches

firstrule: all

# $1: compiler
# $2: compilation flags
# $3: extension prefix
define gen_rules

.SECONDARY:
asm/%$(3).s: %.c
	@mkdir -p $$(@D)
	$(1) $(2) -S $$< -o $$@

.SECONDARY:
bin/$(TARGET)$(3).bin: $(addprefix obj/,$(ALL_CFILES:.c=$(3).o)) $(CLOCK).gcc.kvx.o
	@mkdir -p $$(@D)
	$(1) $$+ -lm -o $$@

BINFILES:=$(BINFILES) bin/$(TARGET)$(3).bin
OUTFILES:=$(OUTFILES) out/$(TARGET)$(3).out
FIRSTLINE:=$(FIRSTLINE), $(3)

endef

# Clock generation
$(CLOCK).gcc.kvx.o: $(CLOCK).c
	$(KVX_CC) $(ALL_GCCFLAGS) -O3 $< -c -o $@

# Generic rules
obj/%.o: asm/%.s
	@mkdir -p $(@D)
	$(KVX_CC) $< -c -o $@

out/%.out: bin/%.bin
	@mkdir -p $(@D)
	@rm -f $@
	$(EXECUTE_CYCLES) $< $(subst __BASE__,$(patsubst %.out,%,$@),$(EXECUTE_ARGS)) | tee -a $@

##
# Generating the rules for all the compiler/flags..
##

ifneq ($(GCC0FLAGS),)
$(eval $(call gen_rules,$(KVX_CC),$(GCC0FLAGS),$(GCC0PREFIX)))
endif
ifneq ($(GCC1FLAGS),)
$(eval $(call gen_rules,$(KVX_CC),$(GCC1FLAGS),$(GCC1PREFIX)))
endif
ifneq ($(GCC2FLAGS),)
$(eval $(call gen_rules,$(KVX_CC),$(GCC2FLAGS),$(GCC2PREFIX)))
endif
ifneq ($(GCC3FLAGS),)
$(eval $(call gen_rules,$(KVX_CC),$(GCC3FLAGS),$(GCC3PREFIX)))
endif
ifneq ($(GCC4FLAGS),)
$(eval $(call gen_rules,$(KVX_CC),$(GCC4FLAGS),$(GCC4PREFIX)))
endif

ifneq ($(CCOMP0FLAGS),)
$(eval $(call gen_rules,$(KVX_CCOMP),$(CCOMP0FLAGS),$(CCOMP0PREFIX)))
endif
ifneq ($(CCOMP1FLAGS),)
$(eval $(call gen_rules,$(KVX_CCOMP),$(CCOMP1FLAGS),$(CCOMP1PREFIX)))
endif
ifneq ($(CCOMP2FLAGS),)
$(eval $(call gen_rules,$(KVX_CCOMP),$(CCOMP2FLAGS),$(CCOMP2PREFIX)))
endif
ifneq ($(CCOMP3FLAGS),)
$(eval $(call gen_rules,$(KVX_CCOMP),$(CCOMP3FLAGS),$(CCOMP3PREFIX)))
endif
ifneq ($(CCOMP4FLAGS),)
$(eval $(call gen_rules,$(KVX_CCOMP),$(CCOMP4FLAGS),$(CCOMP4PREFIX)))
endif

measures.csv: $(OUTFILES)
	@echo $(FIRSTLINE) > $@
	@for i in "$(MEASURES)"; do\
		first=$$(grep "$$i cycles" $(firstword $(OUTFILES)));\
		if test ! -z "$$first"; then\
			if [ "$$i" != "time" ]; then\
				line="$(TARGET) $$i";\
			else\
				line="$(TARGET)";\
			fi;\
			$(foreach outfile,$(OUTFILES),line="$$line, $$(grep "$$i cycles" $(outfile) | cut -d':' -f2)"; ):;\
			echo "$$line" >> $@;\
		fi;\
	done;\
	echo "$@ created!"

.PHONY: all clean run
all: $(BINFILES)

run: measures.csv

clean:
	rm -f *.o *.s *.bin *.out
	rm -rf asm/ bin/ obj/ out/