-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.share
367 lines (351 loc) · 13.3 KB
/
Makefile.share
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#
# NOT USED
#
VEJIT_ROOT:=../..
COMPILE_TYPE:=$(word 1,$(shell $(CC) --version 2>&1))
$(if $(COMPILE_TYPE),,$(error could not determine C compiler type for CC=$(CC))) # VE(ncc) vs x86(gcc or ...)
ifneq ($(COMPILE_TYPE),ncc)
.PRECIOUS: jitpp_loadreg
#
# only a few things can compile for x86...
#
#TARGETS:=test_strMconst asmfmt-x86 jitpp_loadreg veliFoo.o
#TARGETS+=veliFoo.o veli_loadreg-x86
TARGETS:=veli_loadReg
VE_EXEC:=time
OBJDUMP:=objdump
OBJDUMP:=objdump
OBJCOPY:=objcopy
SHELL:=/bin/bash
CFLAGS:=-O2 -g2
CXXFLAGS:=$(CFLAGS) -std=c++11
LIBVELI_TARGETS:=libveli-x86.a
LIBJIT1_TARGETS:=libjit1-x86.a
else
#
# we may want to generate jit code on host OR ve
# Ex. 1: Simple tests, libraries of complex kernels precompiled for VE:
# Host precompiles a jit kernel to a PERSISTENT .bin file,
# which is mmaped and executed on the VE.
# Host program invokes 'ncc' or 'nas' or ... main output-->file
# Ex. 2: Repetitive testing (avoiding zillions of .bin files):
# test program runs on VE already and generates a string of
# code and (somehow) converts the string to machine code that
# it puts in a JIT page. Only TEMPORARY files are used on the
# host filesystem.
# VE program invokes 'ncc' or 'nas' or ... main output-->memory
# (but originally I kept around the .bin files)
#
# Originally, I ran JIT testing code entirely on VE, keeping the .bin files.
# A big speedup would be to run a simplified 'nas' entirely on the VE, avoiding
# all temporary files. Unfortunately 'ncc' and 'nas' and tools run on host only,
# and some steps require real files on the host filesystem :(
#
#TARGETS=asmkern0.asm libjit1.a libjit1-x86.a asmfmt-ve\
# asmkern.bin asmkern1.bin msk \
# syscall_hello \
# jitve0 jitve_hello test_strMconst jitve_math \
# jitpp_hello test_naspipe-x86 test_vejitpage_sh-x86 \
# jitpp_loadreg \
# asmfmt-x86 veli_loadreg-x86 veli_loadreg
# slow!
#TARGETS+=test_naspipe test_vejitpage_sh
CC?=ncc-1.5.1
CXX?=nc++-1.5.1
CC:=ncc-1.5.1
CXX:=nc++-1.5.1
CC:=ncc-1.2.4
CXX:=nc++-1.2.4
CC:=ncc-1.5.2
CXX:=nc++-1.5.2
CC:=ncc
CXX:=nc++
CFLAGS:=-O2 -g2
CXXFLAGS:=$(CFLAGS) -std=c++11
VE_EXEC:=ve_exec
OBJDUMP:=nobjdump
OBJCOPY:=nobjcopy
LIBVELI_TARGETS:=libveli.a libveli-x86.a
LIBJIT1_TARGETS:=libjit1.a libjit1-x86.a
endif
#TARGETS+=$(LIBJIT1_TARGETS) $(LIBVELI_TARGETS)
TARGETS+=cblock dltest1.log veli_loadreg-x86
CFLAGS+=-I$(VEJIT_ROOT)/include
CXXFLAGS+=-I$(VEJIT_ROOT)/include
LDFLAGS+=-L$(VEJIT_ROOT)/lib -Wl,-rpath=$(VEJIT_ROOT)/lib
all: $(TARGETS) liblist
SHELL:=LC_ALL=C /bin/bash
cblock: cblock.cpp
g++ $(CXXFLAGS) -DMAIN_CBLOCK -E $< -o cblock.i
g++ $(CXXFLAGS) -DMAIN_CBLOCK -c $< -o cblock.o
g++ $(CXXFLAGS) cblock.o -o $@
#
# see vl-run.sh for running veli_loadreg tests
# many tests only need veli_loadreg-x86
# only veli_loadreg -R needs VE (because it runs several
# thousand optimized VE assembler test cases).
WORKING?=6
veli_loadreg: veli_loadreg.cpp
$(CXX) $(CXXFLAGS) -DWORKING=${WORKING} -o $@ $^ $(LDFLAGS) $(VEJIT_ROOT)/lib/libveli.a $(VEJIT_ROOT)/lib/libjit1.a
@echo "veli_loadreg runs VE Logic for Instructions tests on VE"
veli_loadreg-x86: veli_loadreg.cpp
g++ $(CXXFLAGS) -Wall -DWORKING=${WORKING} $(LDFLAGS) -g -O2 -o $@ $^ -lveli-x86 -ljit1-x86
@echo "veli_loadreg-x86 will do VE logic tests on x86"
.PHONY: dltest1.log
dltest1.log:
# recreate and run dltest1 versions x86+gcc and VE+ncc
rm -f dltest1 dltest1-x86 tmp_*.c lib*_lucky.so
@# '13' has been hard-wired to produce incorrect std::string ccode
-{ $(MAKE) VERBOSE=1 dltest1-x86 \
&& /usr/bin/time ./dltest1-x86 13 \
&& echo YAY; } >& $@
ifeq ($(COMPILE_TYPE),ncc)
@# '7' should return the correct value from the JIT function.
-{ echo ""; echo ""; \
$(MAKE) VERBOSE=1 dltest1 \
&& /usr/bin/time ve_exec ./dltest1 7 \
&& echo YAY; } &>> $@
endif
# Attempting JIT-via-clang (compile and cross-compile),
# even though you might not have them installed...
-{ $(MAKE) VERBOSE=1 dltest1-clang \
&& /usr/bin/time ./dltest1-clang 123 \
&& echo YAY; } &>> $@
-{ $(MAKE) VERBOSE=1 dltest1-nclang \
&& /usr/bin/time ./dltest1-nclang -1 \
&& echo YAY; } &>> $@
-ls -l tmp_*.c lib*lucky.so
-ls -l tmp_*.c lib*lucky.so &>> $@
#libgcc_lucky.so this code and jit code runs on host
#libncc_lucky.so this code and jit code runs on VE
#libclang_lucky.so this code(can be gcc) and jit code from clang run on host
#libnclang_lucky.so this code(can be ncc) and jist code from clang -target ve-linux on VE
dltest1: dltest1.cpp Makefile
$(CXX) $(CXXFLAGS) -o $@ -Wall -Werror $<
dltest1-x86: dltest1.cpp Makefile
g++ $(CXXFLAGS) -o $@ -Wall -Werror $< -ldl
dltest1-clang: dltest1.cpp Makefile
g++ $(CXXFLAGS) -DJIT_CLANG -o $@ -Wall -Werror $< -ldl
dltest1-nclang: dltest1.cpp Makefile
nc++ $(CXXFLAGS) -DJIT_NCLANG -o $@ -Wall -Werror $<
.PHONY: liblist force
liblist:
-@ls -l lib*.a lib*.so
force: # force libs to be recompiled
rm -f libjit1*.a asmfmt*.o jitpage*.o jit_data*.o
rm -f libveli*.a prgiFoo.o wrpiFoo.o
rm -f $(patsubst %.cpp,%*.o,$(LIBVELI_SRC)) $(LIBVELI_TARGETS)
$(MAKE) $(LIBJIT1_TARGETS)
$(MAKE) $(LIBVELI_TARGETS)
VEJIT_SHARE:=cblock.cpp dltest1.cpp veli_loadreg.cpp
vejit.tar.gz: jitpage.h jit_data.h \
throw.hpp asmfmt_fwd.hpp asmfmt.hpp codegenasm.hpp velogic.hpp \
jitpipe_fwd.hpp jitpipe.hpp cblock.hpp pstreams-1.0.1 \
libjit1.a libjit1-x86.a libveli.a libveli-x86.a \
${VEJIT_SHARE}
rm -rf vejit
mkdir vejit
mkdir vejit/include
mkdir vejit/lib
mkdir vejit/share
mkdir vejit/share/vejit
cp -av $(filter %.hpp,$^) $(filter %.h,$^) vejit/include/
cp -av pstreams-1.0.1 vejit/include/
cp -av $(filter %.a,$^) vejit/lib/
cp -av ${VEJIT_SHARE} vejit/share/vejit/
cp -av Makefile.share vejit/share/vejit/Makefile
tar czf $@ vejit
#
# Aurora assembler.S: cpp->.asm, $(CC)->.o, nobjcopy->.bin, .bin-->.dump
# Actually, jitpage.h (newer version of ve_util.h) will use 'bin.mk' makefile
#
%.bin: %.S
@# .S files can run through *just* the C preprocessor.
$(CC) -o $*.asm -E $< && sed -i '/^[[:space:]]*$$/d' $*.asm
@# .bin needs even more than -fPIC (no GOT, PLT, external symbols!)
$(CC) -o $*.o -c $<
@# we can get symbols + code + data disassembled
$(OBJDUMP) -D $*.o > $*.dis
@# create a relocatable machine-language blob as follows
$(OBJCOPY) -O binary $*.o $*.bin
@# we can dump or disassemble the raw machine code
hexdump -C $*.bin > $*.dump
@echo "===========================" >> $*.dump
@echo "$(OBJDUMP) -b binary -mve -D %*.bin" >> $*.dump
$(OBJDUMP) -b binary -mve -D $*.bin >> $*.dump
# short demo of creating a binary blob from some hand-written assembler (no C ABI)
asmkern.bin: asmkern.S
$(CC) -o asmkern.o -c asmkern.S
@# if we have a relocatable (PIC) binary blob, we can create it as follows
$(OBJCOPY) -O binary asmkern.o asmkern.bin
@# we can dump or disassemble the raw machine code
hexdump -C asmkern.bin
$(OBJDUMP) -b binary -mve -D asmkern.bin
#
# a small demo of inline assembler, from Japan
#
asmkern0.asm: asmkern0.c
$(CC) $(CFLAGS) -c $< -DOPT=1 -o asmkern0.o
$(CC) $(CFLAGS) -Wa,adhln -S $< -o asmkern0.asm
$(OBJDUMP) -d asmkern0.o > asmkern0.dis
#
# pstreams demo piping a std::string of VE asm code
# into a shell script (naspipe.sh) that returns
# a disassembled dump on stdout
# and errors on stderr.
#
# The script stdout and stderr are captured into C++ strings using pstream.h
# (More interesting is to use vejitpage.sh and capture the binary blob
# output into a std::string that can be used to define a jit code page)
#
# This can run on VE or [much faster] on host
test_naspipe: test_naspipe.cpp naspipe.sh
$(CXX) -O2 $< -o $@
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
test_naspipe-x86: test_naspipe.cpp naspipe.sh
g++ -O2 $< -o $@
./$@ 2>&1 | tee [email protected]
# this also can run on host, in seconds rather than minutes,
# because we do not execute the jit page
# [we create the jit page string, and then hexdump and disassemble it]
test_vejitpage_sh: test_vejitpage_sh.cpp vejitpage.sh
$(CXX) -O2 $< -o $@
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
test_vejitpage_sh-x86: test_vejitpage_sh.cpp vejitpage.sh
g++ -std=c++11 -O2 $< -o $@
./$@ 2>&1 | tee [email protected]
#
# low-level C-api, using jitve_util.h
#
jitve0: jitve0.c bin.mk
$(CC) -O2 $< -o $@
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
jitve_util.o: jitve_util.c jitve_util.h
$(CC) -O2 -c $< -o $@
test_strMconst: test_strMconst.c jitve_util.o
$(CC) $(CFLAGS) -O2 $^ -o $@
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
jitve_hello: jitve_hello.c jitve_util.o
$(CC) $(CFLAGS) -O2 -E -dD $< >& $(patsubst %.c,%.i,$<)
$(CC) $(CFLAGS) -O2 $^ -o $@
$(CC) $(CFLAGS) -Wa,-adhln -c $< >& $(patsubst %.c,%.asm,$<)
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
jitve_math: jitve_math.c jitve_util.o
$(CC) $(CFLAGS) -O2 -E -dD $< >& $(patsubst %.c,%.i,$<)
$(CC) $(CFLAGS) -O2 $^ -o $@
$(CC) $(CFLAGS) -Wa,-adhln -c $< >& $(patsubst %.c,%.asm,$<)
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
#
# newer api uses jitpage.h (instead of jitve_util.h)
# and supports C++ (asmfmt_fwd.hpp)
#
# Note that libjit1.a could be running x86 code or VE code
#
.PRECIOUS: asmfmt.o jit_data.o jitpage.o
libjit1.a: asmfmt.o jitpage.o jit_data.o
$(AR) cqsv $@ $^
asmfmt.o: asmfmt.cpp asmfmt.hpp asmfmt_fwd.hpp
$(CXX) ${CXXFLAGS} -O2 -c asmfmt.cpp -o $@
jit_data.o: jit_data.c jit_data.h
$(CC) ${CFLAGS} -O2 -c $< -o $@
jitpage.o: jitpage.c jitpage.h
$(CXX) $(CXXFLAGS) -O2 -c $< -o $@
libjit1-x86.a: asmfmt-x86.o jitpage-x86.o jit_data-x86.o
ar cq $@ $^
asmfmt-x86.o: asmfmt.cpp asmfmt.hpp asmfmt_fwd.hpp
g++ ${CXXFLAGS} -O2 -c asmfmt.cpp -o $@
jit_data-x86.o: jit_data.c jit_data.h
g++ ${CFLAGS} -O2 -c $< -o $@
jitpage-x86.o: jitpage.c jitpage.h
g++ $(CXXFLAGS) -O2 -c $< -o $@
LIBVELI_SRC:=veliFoo.cpp wrpiFoo.cpp
libveli.a: $(patsubst %.cpp,%.o, $(LIBVELI_SRC))
#$(AR) cq $@ $^
rm -f $@; $(AR) cqsv $@ $^
libveli-x86.a: $(patsubst %.cpp,%-x86.o,$(LIBVELI_SRC))
$(AR) cq $@ $^
$(patsubst $(LIBVELI_SRC),%.cpp,%-x86.o) %-x86.o: %.cpp
g++ ${CXXFLAGS} -Wall -O2 -c $< -o $@
#$(patsubst $(LIBVELI_SRC),%.cpp,%.o) %.o: %.cpp
# @# inline asm is incompatible with nc++ -std=c++11
# $(CXX) -Wall -O2 -c $< -o $@
wrpiFoo.o: wrpiFoo.cpp velogic.hpp
@# inline asm is incompatible with nc++ -std=c++11
$(CXX) -Wall -O2 -c $< -o $@
veliFoo.o: veliFoo.cpp velogic.hpp
@# inline asm is incompatible with nc++ -std=c++11
$(CXX) ${CXXFLAGS} -Wall -O2 -c $< -o $@
#asmfmt.cpp has a standalone demo program with -D_MAIN compiler
asmfmt-x86: asmfmt.cpp asmfmt.hpp asmfmt_fwd.hpp jitpage.o
g++ $(CXXFLAGS) -O2 -E -dD $< >& $(patsubst %,%.i,$@)
g++ ${CXXFLAGS} -Wall -D_MAIN asmfmt.cpp jitpage.c -o $@
asmfmt-ve: asmfmt.cpp asmfmt.hpp asmfmt_fwd.hpp jitpage.o
$(CXX) $(CXXFLAGS) -O2 -E -dD $< >& $(patsubst %,%.i,$@)
#$(CXX) $(CXXFLAGS) -O2 -D_MAIN $(filter-out %.hpp,$^) -o $@
$(CXX) ${CXXFLAGS} -D_MAIN -Wall asmfmt.cpp jitpage.c -o $@
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
#
# C++ version of jitve_hello.
# This one is more complicated. Besides printing hello world,
# it also returns a very lucky value (7).
#
jitpp_hello: jitpp_hello.cpp asmfmt.o jitpage.o
$(CXX) $(CFLAGS) -O2 -E -dD $< >& $(patsubst %.cpp,%.i,$<)
$(CXX) $(CFLAGS) -O2 $^ -o $@
$(CXX) $(CFLAGS) -Wa,-adhln -c $^ >& $(patsubst %.cpp,%.asm,$<)
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
ifeq (0,1)
# ccom: ./phase3_src/cg/schedule_vn_sx4.cpp:3372: void VN_TAG::confirm(int, int): Assertion `false' failed.
# nc++: /opt/nec/ve/ncc/1.5.2/libexec/ccom is abnormally terminated by SIGABRT
msk: msk.cpp
$(CXX) $(CFLAGS) -E msk.cpp > msk.i
$(CXX) $(CFLAGS) -Wa,adhln -S msk.cpp -o msk.S
$(CXX) $(CFLAGS) -g2 msk.cpp -o $@
$(OBJDUMP) -d $@ >& msk.dis
$(VE_EXEC) ./$@ 2>&1 | tee msk.log
else
msk: msk.cpp
$(CXX) -O0 -E msk.cpp > msk.i
$(CXX) -O0 -Wa,adhln -S msk.cpp -o msk.S
$(CXX) -O0 -g2 msk.cpp -o $@
$(OBJDUMP) -d $@ >& msk.dis
$(VE_EXEC) ./$@ 2>&1 | tee msk.log
endif
jitpp_loadreg: jitpp_loadreg.cpp asmfmt.o jitpage.o jit_data.o
-$(CXX) $(CXXFLAGS) -O2 -E -dD $< >& $(patsubst %.cpp,%.i,$<) && echo YAY || echo OHOH for jitpp_loadreg.i
$(CXX) $(CXXFLAGS) -O2 $^ -o $@
$(CXX) $(CXXFLAGS) -Wa,-adhln -c $^ >& $(patsubst %.cpp,%.asm,$<)
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
%.asm: %.c
$(CC) $(CFLAGS) -g2 -Wa,-adhln -S $< >& $*.s
$(CC) $(CFLAGS) -Wa,-adhln -c $< >& $*.asm
$(CC) $(CFLAGS) -c $< -o $*.o
$(OBJDUMP) -d $*.o > $*.dis
syscall_hello: syscall_hello.c
$(CC) $(CFLAGS) -S $< -o syscall_hello.s
$(MAKE) syscall_hello.asm
$(CC) $(CFLAGS) $< -o $@ && $(VE_EXEC) $@
$(VE_EXEC) ./$@ 2>&1 | tee [email protected]
dltest0: dltest0.c
$(CC) $(CFLAGS) -o $@ -Wall -Werror $< -ldl
dltest0-x86: dltest0.c
g++ $(CFLAGS) -o $@ -Wall -Werror $< -ldl
# next test show how to dynamically *compile* and load a dll given
# a std::string containing 'C' code.
clean:
rm -f *.o *.i *.ii *.out *.gch
rm -f msk*.i msk*.S msk*.dis msk*.out
rm -f syscall_hello.o syscall_hello.asm syscall_hello.dis
rm -f asmkern0.asm asmkern0.dis
for f in *.bin; do b=`basename $$f .bin`; rm -f $$b.asm $$b.o $$b.dis $$b.dump; done
for f in tmp_*.S; do b=`basename $$f .S`; rm -f $$b.asm $$b.dis $$b.dump; done
rm -f jitve_math.asm jitve_hello.asm jitve_hello.s jitve_hello.dis jitve*.dis \
jitpp_hello.asm
realclean: clean
rm -f $(TARGETS) dltest1 dltest1-x86 dltest1-clang dltest1-nclang veli_loadreg veli_loadreg-x86
rm -f libclang_lucky.so libgcc_lucky.so libncc_lucky.so libnclang_lucky.so
rm -f msk msk0 msk1 msk2 msk3 msk4 syscall_hello smir jitve0
rm -f bld.log asmfmt.log jitpp_hello.log mk*.log bld*.log
rm -f tmp_*.S *.bin *.log
rm -rf CMakeCache.txt CMakeFiles asmfmt asmfmt-x86 asmfmt.txt jitve_hello.s
#