-
Notifications
You must be signed in to change notification settings - Fork 4
/
makefile
175 lines (153 loc) · 6.58 KB
/
makefile
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
BASE2_RAISED_BY=32
CXX:=g++
TESTFLAGS:=-g -Og -D_APA_TESTING_PHASE -D_HIDE_WARNING -D_BASE2_$(BASE2_RAISED_BY)
CXXFLAGS:=-std=c++11 -Wall -Wextra
OS:=$(shell uname)
.PHONY: test all_test benchmark karatsuba arithmetic initandtostring style compare
ifeq ($(OS), Linux)
TESTFLAGS += -fsanitize=address
# TESTFLAGS += -fsanitize=memory -fsanitize-memory-track-origins
endif
all_test:
@echo ===============================
@echo Base 2^16 Test
@$(MAKE) test BASE2_RAISED_BY=16
@$(MAKE) clean
@echo ===============================
@echo Base 2^32 Test
@$(MAKE) test BASE2_RAISED_BY=32
@$(MAKE) clean
@echo ===============================
@echo Base 2^64 Test
@$(MAKE) test BASE2_RAISED_BY=64
@$(MAKE) clean
@echo ===============================
@echo APA ALL TESTS PASSED
@echo ===============================
SRC := tests
SRC_FILES := $(wildcard $(SRC)/*.cpp)
OBJ := $(patsubst $(SRC)/%.cpp,$(SRC)/%.out,$(SRC_FILES))
# -------------------------- run test programs ---------------------------
test: $(OBJ)
@echo OS : $(OS)
@echo LIMB : Base2_$(BASE2_RAISED_BY)
@echo CPP_COMPILER : $(CXX)
@echo "----------------------------------------------------"
@echo "Running Initial Tests..."
@./$(SRC)/integer_constructor.out
@./$(SRC)/integer_swap.out
@./$(SRC)/integer_add.out
@./$(SRC)/integer_add_assign.out
@./$(SRC)/integer_sub.out
@./$(SRC)/integer_sub_assign.out
@./$(SRC)/integer_mul.out
@./$(SRC)/integer_bitwise_logic.out
@./$(SRC)/integer_relational.out
@./$(SRC)/integer_logical.out
@./$(SRC)/integer_shifts.out
@./$(SRC)/integer_div.out
@./$(SRC)/integer_div_assign.out
@./$(SRC)/integer_base_print.out
@./$(SRC)/integer_bases.out
@./$(SRC)/integer_access.out
@./$(SRC)/bint_construct.out
@./$(SRC)/bint_logical.out
@./$(SRC)/bint_add.out
@./$(SRC)/bint_add_assign.out
@./$(SRC)/bint_sub.out
@./$(SRC)/bint_sub_assign.out
@./$(SRC)/bint_mul.out
@./$(SRC)/bint_div.out
@./$(SRC)/bint_div_assign.out
@./$(SRC)/bint_bitwise_logic.out
@./$(SRC)/bint_shifts.out
@./$(SRC)/bint_methods.out
@./$(SRC)/bint_karatsuba.out
@./$(SRC)/bint_error_handling.out
@./$(SRC)/bint_literal_assign.out
# -------------------------- test program compilation ---------------------------
$(SRC)/%.out: $(SRC)/%.cpp
@echo "compiling test program - compiler : $(CXX)"
@$(CXX) $(TESTFLAGS) $(CXXFLAGS) -o $@ $<
clean:
ifeq ($(OS), Linux)
@echo "deleting compiled test programs"
@rm ./$(SRC)/*.out
else
@echo "deleting compiled test programs"
del tests\*.out
endif
style:
@clang-format -i -style=file *.cpp *.hpp tests/*.hpp tests/*.cpp benchmark/*.cpp
benchmark: karatsuba arithmetic initandtostring
karatsuba:
@echo "# Karatsuba Multiplication" > benchmark/karatsuba.md
@echo "" >> benchmark/karatsuba.md
@echo "Compiler : $(CXX)" >> benchmark/karatsuba.md
@echo "" >> benchmark/karatsuba.md
@echo "Average performance of APA's karatsuba implementation (microseconds)" >> benchmark/karatsuba.md
@echo "" >> benchmark/karatsuba.md
@$(CXX) benchmark/karatsuba.cpp -O3 -o benchmark/karatsuba.out -D_FORCE_BASE2_16
@./benchmark/karatsuba.out >> benchmark/karatsuba.md
@$(CXX) benchmark/karatsuba.cpp -O3 -o benchmark/karatsuba.out -D_FORCE_BASE2_32
@./benchmark/karatsuba.out >> benchmark/karatsuba.md
@$(CXX) benchmark/karatsuba.cpp -O3 -o benchmark/karatsuba.out -D_FORCE_BASE2_64
@./benchmark/karatsuba.out >> benchmark/karatsuba.md
@rm benchmark/karatsuba.out
@echo "" >> benchmark/karatsuba.md
@echo "### System Runner" >> benchmark/karatsuba.md
@echo "" >> benchmark/karatsuba.md
@echo "\`\`\`" >> benchmark/karatsuba.md
@lscpu >> benchmark/karatsuba.md
@echo "\`\`\`" >> benchmark/karatsuba.md
arithmetic:
@echo "# Basic Arithmetic" > benchmark/basic-arithmetic.md
@echo "" >> benchmark/basic-arithmetic.md
@echo "Compiler : $(CXX)" >> benchmark/basic-arithmetic.md
@echo "" >> benchmark/basic-arithmetic.md
@echo "Average performance (nanoseconds)" >> benchmark/basic-arithmetic.md
@echo "" >> benchmark/basic-arithmetic.md
@$(CXX) benchmark/basic-arithmetic.cpp -O3 -o benchmark/basic-arithmetic.out -D_FORCE_BASE2_16
@./benchmark/basic-arithmetic.out >> benchmark/basic-arithmetic.md
@$(CXX) benchmark/basic-arithmetic.cpp -O3 -o benchmark/basic-arithmetic.out -D_FORCE_BASE2_32
@./benchmark/basic-arithmetic.out >> benchmark/basic-arithmetic.md
@$(CXX) benchmark/basic-arithmetic.cpp -O3 -o benchmark/basic-arithmetic.out -D_FORCE_BASE2_64
@./benchmark/basic-arithmetic.out >> benchmark/basic-arithmetic.md
@rm benchmark/basic-arithmetic.out
@echo "" >> benchmark/basic-arithmetic.md
@echo "### System Runner" >> benchmark/basic-arithmetic.md
@echo "" >> benchmark/basic-arithmetic.md
@echo "\`\`\`" >> benchmark/basic-arithmetic.md
@lscpu >> benchmark/basic-arithmetic.md
@echo "\`\`\`" >> benchmark/basic-arithmetic.md
initandtostring:
@echo "# String Initialization and To Base 10 String" > benchmark/init-and-to-string.md
@echo "" >> benchmark/init-and-to-string.md
@echo "Compiler : $(CXX)" >> benchmark/init-and-to-string.md
@echo "" >> benchmark/init-and-to-string.md
@echo "Accumulated performance (nanoseconds)" >> benchmark/init-and-to-string.md
@echo "" >> benchmark/init-and-to-string.md
@$(CXX) benchmark/init-and-to-string.cpp -O3 -o benchmark/init-and-to-string.out -D_FORCE_BASE2_16
@./benchmark/init-and-to-string.out >> benchmark/init-and-to-string.md
@$(CXX) benchmark/init-and-to-string.cpp -O3 -o benchmark/init-and-to-string.out -D_FORCE_BASE2_32
@./benchmark/init-and-to-string.out >> benchmark/init-and-to-string.md
@$(CXX) benchmark/init-and-to-string.cpp -O3 -o benchmark/init-and-to-string.out -D_FORCE_BASE2_64
@./benchmark/init-and-to-string.out >> benchmark/init-and-to-string.md
@rm benchmark/init-and-to-string.out
@echo "" >> benchmark/init-and-to-string.md
@echo "### System Runner" >> benchmark/init-and-to-string.md
@echo "" >> benchmark/init-and-to-string.md
@echo "\`\`\`" >> benchmark/init-and-to-string.md
@lscpu >> benchmark/init-and-to-string.md
@echo "\`\`\`" >> benchmark/init-and-to-string.md
FTSRC:=test
focustest:
@echo compiling $(FTSRC).cpp file base2_16...
@$(CXX) $(SRC)/$(FTSRC).cpp -o $(SRC)/$(FTSRC)_base16.out -D_APA_TESTING_PHASE -D_HIDE_WARNING -D_BASE2_16 -g -fsanitize=address -Wall -Wextra
$(SRC)/$(FTSRC)_base16.out
@echo compiling $(FTSRC).cpp file base2_32...
@$(CXX) $(SRC)/$(FTSRC).cpp -o $(SRC)/$(FTSRC)_base32.out -D_APA_TESTING_PHASE -D_HIDE_WARNING -D_BASE2_32 -g -fsanitize=address -Wall -Wextra
$(SRC)/$(FTSRC)_base32.out
@echo compiling $(FTSRC).cpp file base2_64...
@$(CXX) $(SRC)/$(FTSRC).cpp -o $(SRC)/$(FTSRC)_base64.out -D_APA_TESTING_PHASE -D_HIDE_WARNING -D_BASE2_64 -g -fsanitize=address -Wall -Wextra
$(SRC)/$(FTSRC)_base64.out