| 1 |
|
| 2 |
XEN_ROOT ?= $(CURDIR)/../../.. |
| 3 |
include $(XEN_ROOT)/tools/Rules.mk |
| 4 |
|
| 5 |
TARGET := test_x86_emulator |
| 6 |
|
| 7 |
.PHONY: all |
| 8 |
all: |
| 9 |
|
| 10 |
.PHONY: run |
| 11 |
run: $(TARGET) |
| 12 |
./$(TARGET) |
| 13 |
|
| 14 |
|
| 15 |
vpath %.c $(XEN_ROOT)/xen/lib/x86 |
| 16 |
|
| 17 |
CFLAGS += $(CFLAGS_xeninclude) |
| 18 |
|
| 19 |
SIMD := 3dnow sse sse2 sse4 avx avx2 xop avx512f avx512bw avx512dq avx512vbmi avx512fp16 |
| 20 |
FMA := fma4 fma |
| 21 |
SG := avx2-sg avx512f-sg |
| 22 |
AES := ssse3-aes avx-aes avx2-vaes avx512bw-vaes |
| 23 |
CLMUL := ssse3-pclmul avx-pclmul avx2-vpclmulqdq avx512bw-vpclmulqdq avx512vbmi2-vpclmulqdq |
| 24 |
SHA := sse4-sha avx-sha avx512f-sha |
| 25 |
GF := sse2-gf avx2-gf avx512bw-gf |
| 26 |
TESTCASES := blowfish $(SIMD) $(FMA) $(SG) $(AES) $(CLMUL) $(SHA) $(GF) |
| 27 |
|
| 28 |
OPMASK := avx512f avx512dq avx512bw |
| 29 |
|
| 30 |
ifeq ($(origin XEN_COMPILE_ARCH),override) |
| 31 |
|
| 32 |
HOSTCFLAGS += -m32 -I.. |
| 33 |
|
| 34 |
else |
| 35 |
|
| 36 |
blowfish-cflags := "" |
| 37 |
blowfish-cflags-x86_32 := "-mno-accumulate-outgoing-args -Dstatic=" |
| 38 |
|
| 39 |
3dnow-vecs := 8 |
| 40 |
3dnow-ints := |
| 41 |
3dnow-flts := 4 |
| 42 |
sse-vecs := 16 |
| 43 |
sse-ints := |
| 44 |
sse-flts := 4 |
| 45 |
sse2-vecs := $(sse-vecs) |
| 46 |
sse2-ints := 1 2 4 8 |
| 47 |
sse2-flts := 4 8 |
| 48 |
sse4-vecs := $(sse2-vecs) |
| 49 |
sse4-ints := $(sse2-ints) |
| 50 |
sse4-flts := $(sse2-flts) |
| 51 |
avx-vecs := 16 32 |
| 52 |
avx-ints := |
| 53 |
avx-flts := 4 8 |
| 54 |
fma4-vecs := $(avx-vecs) |
| 55 |
fma4-ints := |
| 56 |
fma4-flts := $(avx-flts) |
| 57 |
fma-vecs := $(avx-vecs) |
| 58 |
fma-ints := |
| 59 |
fma-flts := $(avx-flts) |
| 60 |
avx2-vecs := $(avx-vecs) |
| 61 |
avx2-ints := 1 2 4 8 |
| 62 |
avx2-flts := 4 8 |
| 63 |
avx2-sg-vecs := $(avx2-vecs) |
| 64 |
avx2-sg-idxs := 4 8 |
| 65 |
avx2-sg-ints := 4 8 |
| 66 |
avx2-sg-flts := 4 8 |
| 67 |
xop-vecs := $(avx-vecs) |
| 68 |
xop-ints := 1 2 4 8 |
| 69 |
xop-flts := $(avx-flts) |
| 70 |
avx512f-vecs := 64 16 32 |
| 71 |
avx512f-ints := 4 8 |
| 72 |
avx512f-flts := 4 8 |
| 73 |
avx512f-sg-vecs := $(avx512f-vecs) |
| 74 |
avx512f-sg-idxs := 4 8 |
| 75 |
avx512f-sg-ints := $(avx512f-ints) |
| 76 |
avx512f-sg-flts := $(avx512f-flts) |
| 77 |
avx512bw-vecs := $(avx512f-vecs) |
| 78 |
avx512bw-ints := 1 2 |
| 79 |
avx512bw-flts := |
| 80 |
avx512dq-vecs := $(avx512f-vecs) |
| 81 |
avx512dq-ints := $(avx512f-ints) |
| 82 |
avx512dq-flts := $(avx512f-flts) |
| 83 |
avx512vbmi-vecs := $(avx512bw-vecs) |
| 84 |
avx512vbmi-ints := $(avx512bw-ints) |
| 85 |
avx512vbmi-flts := $(avx512bw-flts) |
| 86 |
avx512vbmi2-vecs := $(avx512bw-vecs) |
| 87 |
avx512fp16-vecs := $(avx512bw-vecs) |
| 88 |
avx512fp16-ints := |
| 89 |
avx512fp16-flts := 2 |
| 90 |
|
| 91 |
avx512f-opmask-vecs := 2 |
| 92 |
avx512dq-opmask-vecs := 1 2 |
| 93 |
avx512bw-opmask-vecs := 4 8 |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
TARGET-y := $(TARGET) |
| 100 |
|
| 101 |
ifneq ($(filter-out run% clean% distclean,$(MAKECMDGOALS)),) |
| 102 |
|
| 103 |
define isa-check-cc |
| 104 |
TARGET-$(shell echo 'int i;' | $(CC) -x c -c -o /dev/null -m$(1) - || echo y) := |
| 105 |
endef |
| 106 |
|
| 107 |
ISA := bmi bmi2 tbm sse4.1 sse4.2 sse4a avx avx2 f16c |
| 108 |
ISA += $(addprefix avx512,f bw dq) |
| 109 |
$(foreach isa,$(ISA),$(eval $(call isa-check-cc,$(isa)))) |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
TARGET-$(shell echo 'asm("{evex} vmovaps %xmm0$(comma)%xmm0");' | $(CC) -x c -c -o /dev/null - || echo y) := |
| 114 |
|
| 115 |
ifeq ($(TARGET-y),) |
| 116 |
$(warning Test harness not built, use newer compiler than "$(CC)" (version $(shell $(CC) -dumpversion)) and an "{evex}" capable assembler) |
| 117 |
endif |
| 118 |
|
| 119 |
endif |
| 120 |
|
| 121 |
all: $(TARGET-y) |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
3dnowa := $(call cc-option,$(CC),-m3dnowa,-march=k8) |
| 130 |
non-sse = $(if $(filter sse%,$(1)),,$(if $(filter 3dnow%,$(1)),-msse -mfpmath=sse $(3dnowa),-ffixed-xmm0)) |
| 131 |
|
| 132 |
define simd-defs |
| 133 |
$(1)-cflags := \ |
| 134 |
$(foreach vec,$($(1)-vecs), \ |
| 135 |
$(foreach int,$($(1)-ints), \ |
| 136 |
"-D_$(vec)i$(int) -m$(1) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec) -DINT_SIZE=$(int)" \ |
| 137 |
"-D_$(vec)u$(int) -m$(1) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec) -DUINT_SIZE=$(int)") \ |
| 138 |
$(foreach flt,$($(1)-flts), \ |
| 139 |
"-D_$(vec)f$(flt) -m$(1) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec) -DFLOAT_SIZE=$(flt)")) \ |
| 140 |
$(foreach flt,$($(1)-flts), \ |
| 141 |
"-D_f$(flt) -m$(1) $(call non-sse,$(1)) -mfpmath=sse -Os -DFLOAT_SIZE=$(flt)") |
| 142 |
endef |
| 143 |
define simd-sg-defs |
| 144 |
$(1)-cflags := \ |
| 145 |
$(foreach vec,$($(1)-vecs), \ |
| 146 |
$(foreach idx,$($(1)-idxs), \ |
| 147 |
$(foreach int,$($(1)-ints), \ |
| 148 |
"-D_$(vec)x$(idx)i$(int) -m$(1:-sg=) $(call non-sse,$(1)) -Os -DVEC_MAX=$(vec) -DIDX_SIZE=$(idx) -DINT_SIZE=$(int)") \ |
| 149 |
$(foreach flt,$($(1)-flts), \ |
| 150 |
"-D_$(vec)x$(idx)f$(flt) -m$(1:-sg=) $(call non-sse,$(1)) -Os -DVEC_MAX=$(vec) -DIDX_SIZE=$(idx) -DFLOAT_SIZE=$(flt)"))) |
| 151 |
endef |
| 152 |
define simd-aes-defs |
| 153 |
$(1)-cflags := $(foreach vec,$($(patsubst %-aes,sse,$(1))-vecs) $($(patsubst %-vaes,%,$(1))-vecs), \ |
| 154 |
"-D_$(vec) -maes $(addprefix -m,$(subst -,$(space),$(1))) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec)") |
| 155 |
endef |
| 156 |
define simd-clmul-defs |
| 157 |
$(1)-cflags := $(foreach vec,$($(patsubst %-pclmul,sse,$(1))-vecs) $($(patsubst %-vpclmulqdq,%,$(1))-vecs), \ |
| 158 |
"-D_$(vec) -mpclmul $(addprefix -m,$(subst -,$(space),$(1))) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec)") |
| 159 |
endef |
| 160 |
define simd-sha-defs |
| 161 |
$(1)-cflags := $(foreach vec,$(sse-vecs), \ |
| 162 |
"-D_$(vec) $(addprefix -m,$(subst -,$(space),$(1))) -Os -DVEC_SIZE=$(vec)") |
| 163 |
endef |
| 164 |
define simd-gf-defs |
| 165 |
$(1)-cflags := $(foreach vec,$($(1:-gf=)-vecs), \ |
| 166 |
"-D_$(vec) -mgfni -m$(1:-gf=) $(call non-sse,$(1)) -Os -DVEC_SIZE=$(vec)") |
| 167 |
endef |
| 168 |
define opmask-defs |
| 169 |
$(1)-opmask-cflags := $(foreach vec,$($(1)-opmask-vecs), "-D_$(vec) -m$(1) -Os -DSIZE=$(vec)") |
| 170 |
endef |
| 171 |
|
| 172 |
$(foreach flavor,$(SIMD) $(FMA),$(eval $(call simd-defs,$(flavor)))) |
| 173 |
$(foreach flavor,$(SG),$(eval $(call simd-sg-defs,$(flavor)))) |
| 174 |
$(foreach flavor,$(AES),$(eval $(call simd-aes-defs,$(flavor)))) |
| 175 |
$(foreach flavor,$(CLMUL),$(eval $(call simd-clmul-defs,$(flavor)))) |
| 176 |
$(foreach flavor,$(SHA),$(eval $(call simd-sha-defs,$(flavor)))) |
| 177 |
$(foreach flavor,$(GF),$(eval $(call simd-gf-defs,$(flavor)))) |
| 178 |
$(foreach flavor,$(OPMASK),$(eval $(call opmask-defs,$(flavor)))) |
| 179 |
|
| 180 |
first-string = $(shell for s in $(1); do echo "$$s"; break; done) |
| 181 |
|
| 182 |
avx2-sg-cflags-x86_64 := "-D_high $(foreach n,7 6 5 4 3 2 1,-ffixed-ymm$(n)) $(call first-string,$(avx2-sg-cflags))" |
| 183 |
avx512f-sg-cflags-x86_64 := "-D_higher $(foreach n,7 6 5 4 3 2 1,-ffixed-zmm$(n)) $(call first-string,$(avx512f-sg-cflags))" |
| 184 |
avx512f-sg-cflags-x86_64 += "-D_highest $(foreach n,15 14 13 12 11 10 9 8,-ffixed-zmm$(n)) $(call first-string,$(avx512f-sg-cflags-x86_64))" |
| 185 |
|
| 186 |
$(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile |
| 187 |
rm -f [email protected] $*.bin |
| 188 |
$(foreach arch,$(filter-out $(XEN_COMPILE_ARCH),x86_32) $(XEN_COMPILE_ARCH), \ |
| 189 |
for cflags in $($*-cflags) $($*-cflags-$(arch)); do \ |
| 190 |
$(MAKE) -f testcase.mk TESTCASE=$* XEN_TARGET_ARCH=$(arch) $*-cflags="$$cflags" all; \ |
| 191 |
prefix=$(shell echo $(subst -,_,$*) | sed -e 's,^\([0-9]\),_\1,'); \ |
| 192 |
flavor=$$(echo $${cflags} | sed -e 's, .*,,' -e 'y,-=,__,') ; \ |
| 193 |
(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \ |
| 194 |
"$${prefix}_$(arch)$${flavor}[] = {"; \ |
| 195 |
od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \ |
| 196 |
echo "};"; \ |
| 197 |
echo "asm(\".type $${prefix}_$(arch)$${flavor}, STT_NOTYPE;\");"; \ |
| 198 |
echo "asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");"; \ |
| 199 |
) >>[email protected]; \ |
| 200 |
rm -f $*.bin; \ |
| 201 |
done; \ |
| 202 |
) |
| 203 |
mv [email protected] $@ |
| 204 |
|
| 205 |
$(addsuffix -opmask.h,$(OPMASK)): %.h: opmask.S testcase.mk Makefile |
| 206 |
rm -f [email protected] $*.bin |
| 207 |
$(foreach arch,$(filter-out $(XEN_COMPILE_ARCH),x86_32) $(XEN_COMPILE_ARCH), \ |
| 208 |
for cflags in $($*-cflags) $($*-cflags-$(arch)); do \ |
| 209 |
$(MAKE) -f testcase.mk TESTCASE=$* XEN_TARGET_ARCH=$(arch) $*-cflags="$$cflags" all; \ |
| 210 |
prefix=$(shell echo $(subst -,_,$*) | sed -e 's,^\([0-9]\),_\1,'); \ |
| 211 |
flavor=$$(echo $${cflags} | sed -e 's, .*,,' -e 'y,-=,__,') ; \ |
| 212 |
(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \ |
| 213 |
"$${prefix}_$(arch)$${flavor}[] = {"; \ |
| 214 |
od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \ |
| 215 |
echo "};"; \ |
| 216 |
echo "asm(\".type $${prefix}_$(arch)$${flavor}, STT_NOTYPE;\");"; \ |
| 217 |
echo "asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");"; \ |
| 218 |
) >>[email protected]; \ |
| 219 |
rm -f $*.bin; \ |
| 220 |
done; \ |
| 221 |
) |
| 222 |
mv [email protected] $@ |
| 223 |
|
| 224 |
$(addsuffix .c,$(SIMD)): |
| 225 |
ln -sf simd.c $@ |
| 226 |
|
| 227 |
$(addsuffix .c,$(FMA)): |
| 228 |
ln -sf simd-fma.c $@ |
| 229 |
|
| 230 |
$(addsuffix .c,$(SG)): |
| 231 |
ln -sf simd-sg.c $@ |
| 232 |
|
| 233 |
$(addsuffix .c,$(AES)): |
| 234 |
ln -sf simd-aes.c $@ |
| 235 |
|
| 236 |
$(addsuffix .c,$(CLMUL)): |
| 237 |
ln -sf simd-clmul.c $@ |
| 238 |
|
| 239 |
$(addsuffix .c,$(SHA)): |
| 240 |
ln -sf simd-sha.c $@ |
| 241 |
|
| 242 |
$(addsuffix .c,$(GF)): |
| 243 |
ln -sf simd-gf.c $@ |
| 244 |
|
| 245 |
$(addsuffix .h,$(SIMD) $(FMA) $(SG) $(AES) $(CLMUL) $(SHA) $(GF)): simd.h |
| 246 |
|
| 247 |
xop.h avx512f.h avx512fp16.h: simd-fma.c |
| 248 |
|
| 249 |
endif |
| 250 |
|
| 251 |
OBJS := x86-emulate.o cpuid.o test_x86_emulator.o evex-disp8.o predicates.o wrappers.o |
| 252 |
OBJS += x86_emulate/0f01.o x86_emulate/0fae.o x86_emulate/0fc7.o |
| 253 |
OBJS += x86_emulate/blk.o x86_emulate/decode.o x86_emulate/fpu.o x86_emulate/util.o |
| 254 |
|
| 255 |
WRAPPED := $(shell sed -n 's,^ *WRAP(\([[:alnum:]_]*\));,\1,p' \ |
| 256 |
$(firstword $(wildcard ../x86-emulate.h) x86-emulate.h)) |
| 257 |
|
| 258 |
$(TARGET): $(OBJS) |
| 259 |
$(HOSTCC) $(HOSTCFLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) -o $@ $^ |
| 260 |
|
| 261 |
.PHONY: clean |
| 262 |
clean: |
| 263 |
rm -rf $(TARGET) *.o *~ core *.bin x86_emulate |
| 264 |
rm -rf $(addsuffix .h,$(TESTCASES)) $(addsuffix -opmask.h,$(OPMASK)) |
| 265 |
rm -rf $(addsuffix .c,$(filter-out blowfish,$(TESTCASES))) |
| 266 |
|
| 267 |
.PHONY: distclean |
| 268 |
distclean: clean |
| 269 |
|
| 270 |
.PHONY: install uninstall |
| 271 |
install uninstall: |
| 272 |
|
| 273 |
.PHONY: run32 clean32 |
| 274 |
ifeq ($(XEN_COMPILE_ARCH),x86_64) |
| 275 |
run32: $(addsuffix .h,$(TESTCASES)) $(addsuffix -opmask.h,$(OPMASK)) |
| 276 |
run32 clean32: %32: |
| 277 |
$(MAKE) -C 32 HOSTCC=$(HOSTCC) $* |
| 278 |
clean: clean32 |
| 279 |
else |
| 280 |
run32 clean32: %32: % |
| 281 |
endif |
| 282 |
|
| 283 |
.PHONY: x86_emulate |
| 284 |
x86_emulate: |
| 285 |
mkdir -p $@ |
| 286 |
ln -sf $(XEN_ROOT)/xen/arch/x86/$@/*.[ch] $@/ |
| 287 |
|
| 288 |
x86_emulate/%: x86_emulate ; |
| 289 |
|
| 290 |
HOSTCFLAGS-x86_64 := -fno-PIE |
| 291 |
$(call cc-option-add,HOSTCFLAGS-x86_64,HOSTCC,-no-pie) |
| 292 |
HOSTCFLAGS += $(CFLAGS_xeninclude) -I. $(HOSTCFLAGS-$(XEN_COMPILE_ARCH)) |
| 293 |
|
| 294 |
x86.h := $(addprefix $(XEN_ROOT)/tools/include/xen/asm/,\ |
| 295 |
x86-vendors.h x86-defns.h msr-index.h) \ |
| 296 |
$(addprefix $(XEN_ROOT)/tools/include/xen/lib/x86/, \ |
| 297 |
cpu-policy.h cpuid-autogen.h) |
| 298 |
x86_emulate.h := x86-emulate.h x86_emulate/x86_emulate.h x86_emulate/private.h $(x86.h) |
| 299 |
|
| 300 |
$(OBJS): %.o: %.c $(x86_emulate.h) |
| 301 |
$(HOSTCC) $(HOSTCFLAGS) -c -g -o $@ $< |
| 302 |
|
| 303 |
x86-emulate.o: x86_emulate/x86_emulate.c |
| 304 |
x86-emulate.o x86_emulate/%.o: HOSTCFLAGS += -D__XEN_TOOLS__ |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
$(call cc-option-add,HOSTCFLAGS-toplevel,HOSTCC,-fno-toplevel-reorder) |
| 309 |
test_x86_emulator.o: HOSTCFLAGS += $(HOSTCFLAGS-toplevel) |
| 310 |
|
| 311 |
test_x86_emulator.o: $(addsuffix .h,$(TESTCASES)) $(addsuffix -opmask.h,$(OPMASK)) |