-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.common
170 lines (137 loc) · 4.49 KB
/
Makefile.common
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
163
164
165
166
167
168
169
CXXFLAGS+=-std=gnu++23 -Wall -Wextra -Wno-psabi -O2 -g0 -Wno-attributes
CXXFLAGS_clang := -Wno-unknown-pragmas
CXXFLAGS_gcc := -fconcepts-diagnostics-depth=3
ifneq ($(shell $(CXX) --version|grep -i clang),)
compiler:=clang
else ifneq ($(shell $(CXX) --version|grep 'g++'),)
compiler:=gcc
else
compiler:=unknown
endif
CXXFLAGS += $(CXXFLAGS_$(compiler))
#-D_GLIBCXX_DEBUG_UB=1
icerun := $(shell which icerun)
ifeq ($(icerun)$(shell which icecc),)
# without icecream (icerun and icecc) set DIRECT=1
DIRECT := 1
else ifeq ($(ICECC),no)
DIRECT := 1
else ifeq ($(ICECC),disable)
DIRECT := 1
else ifneq ($(notdir $(realpath $(CXX))),icecc)
# CXX isn't using icecream
DIRECT := 1
icerun :=
else ifneq ($(DIRECT),)
ifneq ($(ICECC_CXX),)
ifeq ($(notdir $(realpath $(CXX))),icecc)
# with icecream, DIRECT, and ICECC_CXX set, and CXX resolving to icecc, compile
# locally but allocate slots on the icecream scheduler
export ICECC=no
endif
endif
endif
testarchs ::= athlon64 \
nocona \
core2 \
westmere \
ivybridge \
bdver4 \
skylake \
znver4 \
skylake-avx512
tests ::= $(patsubst tests/%.cpp,%,$(wildcard tests/*.cpp))
testtypes ::= signed-char \
unsigned-char \
signed-short \
unsigned-short \
signed-int \
unsigned-int \
signed-long \
unsigned-long \
signed-long-long \
unsigned-long-long \
float \
double \
char \
char8_t \
wchar_t \
char16_t \
char32_t \
std::byte
ifneq ($(compiler),clang)
testtypes += std::float16_t \
std::float32_t \
std::float64_t
endif
testtypes ::= $(subst ::,--,$(testtypes))
testwidths ::= $(shell seq 1 67)
getwidth = $(subst .,,$(suffix $(1)))
gettype = $(subst -, ,$(subst --,::,$(subst .,,$(basename $(notdir $(1))))))
getarch = $(subst .,,$(suffix $(subst /,,$(dir $(1)))))
gettest = $(basename $(subst /,,$(dir $(1))))
define pch_template
obj/$(1).hpp: tests/unittest*.h tests/*.cpp
@echo "Generate $$@"
@grep -h '^ *# *include ' $$^|grep -v unittest.h|sort -u|sed 's,","../tests/,' > $$@
obj/$(1).depend: obj/$(1).hpp
@echo "Update $(1) dependencies"
@$$(CXX) $$(CXXFLAGS) -march=$(1) -MM -MT "obj/$(1).hpp.gch" $$< > $$@
include obj/$(1).depend
obj/$(1).hpp.gch: obj/$(1).hpp
@echo "Build pre-compiled header for $(1)"
@$$(CXX) $$(CXXFLAGS) -march=$(1) -c $$< -o $$@
endef
$(foreach arch,$(testarchs),\
$(eval $(call pch_template,$(arch))))
# arguments: test, arch
define exe_template
obj/$(1).$(2)/%.exe: tests/$(1).cpp obj/$(2).hpp.gch tests/unittest*.h
@echo "Build $(if $(DIRECT),and link )$$(@:obj/%.exe=check/%)"
@mkdir -p $$(dir $$@)
@$$(CXX) $$(CXXFLAGS) -march=$(2) -D UNITTEST_TYPE="$$(call gettype,$$*)" -D UNITTEST_WIDTH=$$(call getwidth,$$*) -include obj/$(2).hpp $(if $(DIRECT),-o $$@,-c -o $$(@:.exe=.o)) $$<
ifeq ($(DIRECT),)
@echo " Link $$(@:obj/%.exe=check/%)"
@$$(CXX) $$(CXXFLAGS) -march=$(2) -o $$@ $$(@:.exe=.o)
@rm $$(@:.exe=.o)
endif
endef
$(foreach arch,$(testarchs),\
$(foreach t,$(tests),\
$(eval $(call exe_template,$(t),$(arch)))))
constexpr_checks ::= $(foreach arch,$(testarchs),obj/constexpr.$(arch).s)
.PHONY: check-constexpr
check-constexpr: $(shell shuf -e -- $(constexpr_checks))
check_targets := obj/check.targets
codegen_files ::= $(wildcard codegen/*.c++)
codegen_names ::= $(patsubst codegen/%.c++,%,$(codegen_files))
codegen_targets ::= $(patsubst %,check-codegen-%,$(codegen_names))
obj/codegen.depend: $(codegen_files)
@echo "Update codegen dependencies"
@mkdir -p obj
$(file >$@)
$(foreach c,$(codegen_names),\
$(shell $(CXX) $(CXXFLAGS) -MM -MT obj/codegen.$c.s codegen/$c.c++ >> $@))
include obj/codegen.depend
$(shell $(CXX) $(CXXFLAGS) -MM -MT "obj/constexpr.%.s" constexpr_tests.c++|tr -d '\\') obj/%.hpp.gch
@echo "Build constexpr tests for $*"
@$(CXX) $(CXXFLAGS) -march=$* -include obj/$*.hpp -S -o $@ constexpr_tests.c++
check/%: obj/%.exe always-remake
@mkdir -p $(dir $@)
@{ \
echo "================================================================";\
echo " Run check/$*"; \
echo "================================================================";\
$(icerun) obj/$*.exe; \
} | tee $@
@tail -n1 $@ | grep -qv '^Failed tests: [^0]'
.PHONY: always-remake
always-remake: ;
check-codegen-%: obj/codegen.%.s codegen/check.sh
@echo "Testing for expected instructions in $<"
@codegen/check.sh "codegen/$*.c++" "$<"
obj/codegen.%.s: codegen/%.c++
@echo "Building $@"
@$(CXX) $(CXXFLAGS) -masm=intel -march=skylake -S -o $@ $<
@cat $@ | grep -v '^\s*\.' | c++filt > [email protected]
@mv [email protected] $@