Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (115 loc) · 3.27 KB
/
Copy pathMakefile
File metadata and controls
135 lines (115 loc) · 3.27 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
# Tiny arbitrary precision floating point library
#
# Copyright (c) 2017-2018 Fabrice Bellard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Enable Windows compilation
#CONFIG_WIN32=y
# build AVX2 version
#CONFIG_AVX2=y
# Enable profiling with gprof
#CONFIG_PROFILE=y
# compile the bftest utility to do regression tests and benchmarks. Must have
# the MPFR and MPDecimal libraries
#CONFIG_BFTEST=y
# 32 bit compilation
#CONFIG_M32=y
#CONFIG_ASAN=y
ifdef CONFIG_WIN32
CROSS_PREFIX=x86_64-w64-mingw32-
EXE:=.exe
else
EXE:=
endif
CC=$(CROSS_PREFIX)gcc
CFLAGS=-Wall -g $(PROFILE) -MMD
CFLAGS+=-O2
#CFLAGS+=-flto
#CFLAGS+=-Os
LDFLAGS=
ifdef CONFIG_M32
CFLAGS+=-m32
LDFLAGS+=-m32
endif
ifdef CONFIG_PROFILE
CFLAGS+=-p
LDFLAGS+=-p
else
#LDFLAGS+=-s # strip output
endif
ifdef CONFIG_ASAN
CFLAGS+=-fsanitize=address
LDFLAGS+=-fsanitize=address
endif
LIBS=-lm
PROGS+=bfbench$(EXE) bfpi$(EXE)
PROGS+=bfcalc$(EXE)
ifdef CONFIG_BFTEST
PROGS+=bftest$(EXE)
endif
ifdef CONFIG_AVX2
ifndef CONFIG_M32
PROGS+=bfbench-avx2$(EXE) bfpi-avx2$(EXE)
endif
endif
all: $(PROGS)
bfpi$(EXE): bfpi.o libbf.o cutils.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
bfpi-avx2$(EXE): bfpi.avx2.o libbf.avx2.o cutils.avx2.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
bfcalc$(EXE): bfcalc.o readline_tty.o readline.o libbf.o cutils.o
$(CC) $(LDFLAGS) -o $@ $^ -lm
BFTEST_LIBS:=$(LIBS)
ifdef CONFIG_BFTEST
BFTEST_LIBS:=-lmpfr -lgmp $(BFTEST_LIBS)
bfbench.o bfbench.avx2.o: CFLAGS+=-DCONFIG_MPFR
bftest$(EXE): bftest.o libbf.o cutils.o softfp.o
$(CC) $(LDFLAGS) -o $@ $^ -lmpdec $(BFTEST_LIBS)
endif
bfbench$(EXE): bfbench.o libbf.o cutils.o
$(CC) $(LDFLAGS) -o $@ $^ $(BFTEST_LIBS)
bfbench-avx2$(EXE): bfbench.avx2.o libbf.avx2.o cutils.avx2.o
$(CC) $(LDFLAGS) -o $@ $^ $(BFTEST_LIBS)
test: all
time ./bfpi 1e5 pi_1e5.txt
sha1sum -c pi_1e5.sha1sum
ifdef CONFIG_AVX2
time ./bfpi-avx2 1e5 pi_1e5.txt
sha1sum -c pi_1e5.sha1sum
endif
#
time ./bfpi 1e6 pi_1e6.txt
sha1sum -c pi_1e6.sha1sum
ifdef CONFIG_AVX2
time ./bfpi-avx2 1e6 pi_1e6.txt
sha1sum -c pi_1e6.sha1sum
#
time ./bfpi-avx2 1e7 pi_1e7.txt
sha1sum -c pi_1e7.sha1sum
#
# time ./bfpi-avx2 1e8 pi_1e8.txt
# sha1sum -c pi_1e8.sha1sum
endif
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.avx2.o: %.c
$(CC) $(CFLAGS) -mavx -mavx2 -mfma -mbmi2 -c -o $@ $<
clean:
rm -f $(PROGS) *.o *.d *~
-include $(wildcard *.d)