-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
251 lines (203 loc) · 8.13 KB
/
Makefile
File metadata and controls
251 lines (203 loc) · 8.13 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright © 2025–2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
# Matthias Kretz <m.kretz@gsi.de>
all: obj/libsimd.so obj/libsimd.a
include Makefile.common
prefix = /usr
includedir = $(prefix)/include
install:
@echo "Installing to $(prefix)/include"
install -d $(includedir)/bits
install -m 644 -t $(includedir) simd
install -m 644 -t $(includedir)/bits bits/*.h
deploy:
./deploy.sh
sysincludedir = $(dir $(shell echo "#include <vector>"|"$(CXX)" -std=c++17 -x c++ -E -o- -|grep '^# 1 "/.*/vector"'|cut -d'"' -f2))
install-system:
@echo "Installing to $(sysincludedir)"
@result=0; for i in bits/*.h; do \
test -f $(sysincludedir)$$i || continue; \
echo "Error: would overwrite $$i"; \
result=1; \
done; exit $$result
install -m 644 -t $(sysincludedir) simd
install -m 644 -t $(sysincludedir)/bits bits/*.h
uninstall-system:
@echo "Uninstalling from $(sysincludedir)"
@rm $(sysincludedir)simd
@for i in bits/*.h; do rm $(sysincludedir)$$i; done
info: $(check_targets)
@echo "This library is header-only and doesn't need to be built."
@echo
@echo "Installation"
@echo "============"
@echo "> make prefix=~/.local install"
@echo
@echo "Alternatively, install into the compiler's standard library directory:"
@echo "> make install-system"
@echo
@echo "To uninstall from the system:"
@echo "> make uninstall-system"
@echo
@echo "Testing"
@echo "======="
@echo "Compile and run tests via 'make check'."
@echo "For all possible check targets call 'make help'."
checkpoint:
@if [ -z "$(filename)" ]; \
then echo "ERROR: Pass 'filename=<path to tarball>' to 'make checkpoint'.";\
exit 1;\
fi
@tar -cz -f $(filename) check/* obj/*.hpp obj/*.depend
lib_srcs ::= $(patsubst lib/%.cpp,%,$(wildcard lib/*.cpp))
libarchs ::= v1 v2 v3a v3b v4
archv1 := -march=x86-64 -mtune=generic
archv2 := -msse4.1 -mtune=generic
archv3a := -mavx -mtune=ivybridge
archv3b := -march=x86-64-v3 -mtune=znver3
archv4 := -march=x86-64-v4 -mtune=znver5 -mavx512fp16
define lib_template
$(objdir)/$(1)/%.o: lib/%.cpp include/bits/*.h lib/*.h
@printf -- '$$(msg_build) $$@\n'
@mkdir -p $$(dir $$@)
@$$(call call_compiler,$$(CXXFLAGS) -U_GLIBCXX_ASSERTIONS $(arch$(1)) -I include -c -o $$@ $$<)
$(objdir)/$(1)/finite-%.o: lib/%.cpp include/bits/*.h lib/*.h
@printf -- '$$(msg_build) $$@\n'
@mkdir -p $$(dir $$@)
@$$(call call_compiler,$$(CXXFLAGS) -U_GLIBCXX_ASSERTIONS $(arch$(1)) -ffinite-math-only -I include -c -o $$@ $$<)
endef
$(foreach arch,$(libarchs),$(eval $(call lib_template,$(arch))))
$(objdir)/libsimd.so $(objdir)/libsimd.a: \
$(foreach src,$(lib_srcs),$(foreach arch,$(libarchs),$(objdir)/$(arch)/$(src).o)) \
$(foreach src,$(lib_srcs),$(foreach arch,$(libarchs),$(objdir)/$(arch)/finite-$(src).o))
@printf -- '$(msg_link) $@\n'
@$(if $(patsubst %.so,,$@),\
$(AR) rcs $@ $^,\
$(LINK_CXX) $(CXXFLAGS) -fno-lto -shared -o $@ $^)
fortestarchs := for a in $(testarchs); do
fortestwidths := for w in $(testwidths); do
clang_flags = $(CXXFLAGS)
ifneq ($(compiler),clang)
clang_flags := $(filter-out $(CXXFLAGS_$(compiler)),$(clang_flags)) $(CXXFLAGS_clang)
endif
clang_flags := $(filter-out -Werror -ferror-limit=%,$(clang_flags))
define ccjson
{ "directory": "$(PWD)",
"arguments": ["$(CXX)", $(clang_flags:%="%",) "-march=$1", "-include", "$(objdir)/$1.hpp", "-S", "$2"],
"file": "$2" }
endef
$(objdir)/compile_commands.json: $(objdir) Makefile Makefile.common
$(file >$@,[)
$(file >>$@,$(call ccjson,$(firstword $(testarchs)),constexpr_tests.cpp)$(foreach arch,$(wordlist 2,$(words $(testarchs)),$(testarchs)),,$(call ccjson,$(arch),constexpr_tests.cpp)))
$(file >>$@,])
.PHONY: metrics
metrics:
@sloccount *.h tests/*.h Makefile*
.PHONY: tidy
tidy: $(objdir)/compile_commands.json
@clang-tidy --config-file=.clang-tidy -p $(objdir) constexpr_tests.cpp
.PHONY: debug
debug:
@echo "obj dir rule: $(make_obj_dir_rule)"
@echo "obj dir: $(objdir)"
@echo "compiler: $(compiler)"
@echo "DIRECT: $(DIRECT)"
@echo "CXXFLAGS: $(CXXFLAGS)"
@echo "testarchs: $(testarchs)"
@echo "tests: $(tests)"
@echo "testwidths: $(testwidths)"
@for i in $(testtypes); do echo "- $$i"; done
@echo "int_tests: $(int_tests)"
@echo "float_tests: $(float_tests)"
@echo "complex_tests: $(complex_tests)"
@echo "width=$(call getwidth,shift_left.core2/signed-char.34)"
@echo "type=$(call gettype,shift_left.core2/signed-char.34)"
@echo "arch=$(call getarch,shift_left.core2/signed-char.34)"
@echo "test=$(call gettest,shift_left.core2/signed-char.34)"
@echo "type=$(call gettype,shift_left.core2/std--float32_t.34)"
@echo "prefix: $(prefix)"
@$(MAKE) -f Makefile.more $@
more_checks := ci check check10 check1 check-failed check-passed check-untested check-fast-math rerun
.PHONY: $(more_checks)
$(more_checks): $(check_targets) $(objdir)/libsimd.a
@$(MAKE) -f Makefile.more --no-print-directory $@
helptargets := $(more_checks) $(codegen_targets) check-constexpr
define simple_check_template
check-$(1): $(2)
helptargets+=check-$(1)
endef
define check_template
check-$(1):
@$$(MAKE) --no-print-directory $$(shell $(2) | shuf)
helptargets+=check-$(1)
endef
$(foreach t,$(tests),\
$(eval $(call check_template,$(t), $(fortestarchs) $(fortestwidths) for type in $(call testtypes_for_test,$(t)); do \
echo "check/$(t).$$$$a/$$$$type.$$$$w"; \
done;done;done)) \
)
tests_for_type = $(if $(filter $(1),$(complex_testtypes)),$(complex_tests),\
$(if $(filter $(1),$(float_testtypes)),$(float_tests),\
$(int_tests)))
$(foreach type,$(testtypes),\
$(eval $(call check_template,$(type),\
for t in $(call tests_for_type,$(type)); do $(fortestarchs) $(fortestwidths) \
echo "check/$$$$t.$$$$a/$(type).$$$$w";done;done;done))\
)
$(foreach type,$(testtypes),\
$(foreach w,$(testwidths),\
$(eval $(call check_template,$(type).$(w),for t in $(call tests_for_type,$(type)); do $(fortestarchs) \
echo "check/$$$$t.$$$$a/$(type).$(w)";done;done))) \
)
$(foreach t,$(tests),\
$(foreach type,$(call testtypes_for_test,$(t)),\
$(eval $(call check_template,$(t).$(type),$(fortestarchs) $(fortestwidths) \
echo "check/$(t).$$$$a/$(type).$$$$w";done;done))) \
$(foreach type,$(call testtypes_for_test,$(t)),\
$(foreach w,$(testwidths),\
$(eval $(call check_template,$(t).$(type).$(w),$(fortestarchs) \
echo "check/$(t).$$$$a/$(type).$(w)";done)))) \
$(foreach arch,$(testarchs),\
$(foreach type,$(call testtypes_for_test,$(t)),\
$(eval $(call check_template,$(t).$(arch).$(type),$(fortestwidths) \
echo "check/$(t).$(arch)/$(type).$$$$w";done))) \
$(foreach w,1 4 8 16,\
$(eval $(call check_template,$t.$(arch).$w,for type in $(call testtypes_for_test,$(t)); do \
echo "check/$t.$(arch)/$$$$type.$w";done)))) \
)
fortesttypes := for type in $(testtypes); do
$(foreach arch,$(testarchs),\
$(eval $(call simple_check_template,constexpr-$(arch),$(objdir)/constexpr.$(arch).s))\
$(eval $(call simple_check_template,math-traits-$(arch),$(objdir)/math-traits.$(arch).s))\
$(eval $(call check_template,$(arch),$(fortesttypes) for t in $(call tests_for_type,$(type)); do \
echo "check-$$$$t.$(arch).$$$$type";done;done;\
echo "check-math-traits-$(arch)";\
echo "check-constexpr-$(arch)")) \
)
$(check_targets): $(objdir)/compile_commands.json $(wildcard tests/*.cpp) Makefile Makefile.common
$(file >$@)
$(foreach t,$(tests),$(foreach w,$(testwidths),$(foreach y,$(call testtypes_for_test,$(t)),$(foreach a,$(testarchs),\
$(file >>$@,check/$t.$a/$y.$w)\
))))
# $(file >>$@,check/fast-math/$t.$a/$y.$w)\
REPORTFLAGS=-fmem-report -ftime-report -Q
$(objdir)/%.report:
@echo "Build time reports for $*"
@$(CXX) $(CXXFLAGS) $(REPORTFLAGS) -march=$(call getarch,$*) \
-D UNITTEST_TYPE="$(call gettype,$*)" \
-D UNITTEST_WIDTH=$(call getwidth,$*) \
-c -o $(objdir)/$*.o tests/$(call gettest,$*).cpp
@echo "Build time reports for $* done"
helptxt := $(objdir)/help.txt
$(helptxt): Makefile $(check_targets)
$(file >$@)
$(foreach t,$(helptargets),$(file >>$@,... $(t)))
@sed 's/^/... /' $(check_targets) >>$@
.PHONY: help
help: $(helptxt)
@echo "Define `DIRECT` to anything non-empty to compile and link in one step"
@cat $(helptxt)
.PHONY: clean
clean:
rm -rf check/*
rm -rf obj/*