1 2XEN_ROOT=$(CURDIR)/../../.. 3include $(XEN_ROOT)/tools/Rules.mk 4 5TARGET := test_x86_emulator 6 7.PHONY: all 8all: $(TARGET) 9 10.PHONY: run 11run: $(TARGET) 12 ./$(TARGET) 13 14SIMD := sse sse2 sse4 avx 15TESTCASES := blowfish $(SIMD) sse2-avx sse4-avx 16 17blowfish-cflags := "" 18blowfish-cflags-x86_32 := "-mno-accumulate-outgoing-args -Dstatic=" 19 20sse-vecs := 16 21sse-ints := 22sse-flts := 4 23sse2-vecs := $(sse-vecs) 24sse2-ints := 1 2 4 8 25sse2-flts := 4 8 26sse4-vecs := $(sse2-vecs) 27sse4-ints := $(sse2-ints) 28sse4-flts := $(sse2-flts) 29avx-vecs := 16 32 30avx-ints := 31avx-flts := 4 8 32 33# When converting SSE to AVX, have the compiler avoid XMM0 to widen 34# coverage of the VEX.vvvv checks in the emulator. We must not do this, 35# however, for SSE4.1 and later, as there are instructions with XMM0 as 36# an implicit operand. 37sse2avx-sse2 := -ffixed-xmm0 -Wa,-msse2avx 38sse2avx-sse4 := -Wa,-msse2avx 39 40# For AVX and later, have the compiler avoid XMM0 to widen coverage of 41# the VEX.vvvv checks in the emulator. 42non-sse = $(if $(filter sse%,$(1)),,-ffixed-xmm0) 43 44define simd-defs 45$(1)-cflags := \ 46 $(foreach vec,$($(1)-vecs), \ 47 $(foreach int,$($(1)-ints), \ 48 "-D_$(vec)i$(int) -m$(1) $(call non-sse,$(1)) -O2 -DVEC_SIZE=$(vec) -DINT_SIZE=$(int)" \ 49 "-D_$(vec)u$(int) -m$(1) $(call non-sse,$(1)) -O2 -DVEC_SIZE=$(vec) -DUINT_SIZE=$(int)") \ 50 $(foreach flt,$($(1)-flts), \ 51 "-D_$(vec)f$(flt) -m$(1) $(call non-sse,$(1)) -O2 -DVEC_SIZE=$(vec) -DFLOAT_SIZE=$(flt)")) \ 52 $(foreach flt,$($(1)-flts), \ 53 "-D_f$(flt) -m$(1) $(call non-sse,$(1)) -mfpmath=sse -O2 -DFLOAT_SIZE=$(flt)") 54$(1)-avx-cflags := \ 55 $(foreach vec,$($(1)-vecs), \ 56 $(foreach int,$($(1)-ints), \ 57 "-D_$(vec)i$(int) -m$(1) $(sse2avx-$(1)) -O2 -DVEC_SIZE=$(vec) -DINT_SIZE=$(int)" \ 58 "-D_$(vec)u$(int) -m$(1) $(sse2avx-$(1)) -O2 -DVEC_SIZE=$(vec) -DUINT_SIZE=$(int)")) 59endef 60 61$(foreach flavor,$(SIMD),$(eval $(call simd-defs,$(flavor)))) 62 63$(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile 64 rm -f $@.new $*.bin 65 $(foreach arch,$(filter-out $(XEN_COMPILE_ARCH),x86_32) $(XEN_COMPILE_ARCH), \ 66 for cflags in $($*-cflags) $($*-cflags-$(arch)); do \ 67 $(MAKE) -f testcase.mk TESTCASE=$* XEN_TARGET_ARCH=$(arch) $*-cflags="$$cflags" all; \ 68 flavor=$$(echo $${cflags} | sed -e 's, .*,,' -e 'y,-=,__,') ; \ 69 (echo "static const unsigned int $(subst -,_,$*)_$(arch)$${flavor}[] = {"; \ 70 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \ 71 echo "};") >>$@.new; \ 72 rm -f $*.bin; \ 73 done; \ 74 ) 75 mv $@.new $@ 76 77$(addsuffix .c,$(SIMD)) $(addsuffix -avx.c,$(filter sse%,$(SIMD))): 78 ln -sf simd.c $@ 79 80$(TARGET): x86-emulate.o test_x86_emulator.o 81 $(HOSTCC) $(HOSTCFLAGS) -o $@ $^ 82 83.PHONY: clean 84clean: 85 rm -rf $(TARGET) *.o *~ core $(addsuffix .h,$(TESTCASES)) *.bin x86_emulate asm 86 87.PHONY: distclean 88distclean: clean 89 90.PHONY: install 91install: 92 93x86_emulate: 94 [ -L $@ ] || ln -sf $(XEN_ROOT)/xen/arch/x86/$@ 95 96x86_emulate/%: x86_emulate ; 97 98asm: 99 [ -L $@ ] || ln -sf $(XEN_ROOT)/xen/include/asm-x86 $@ 100 101asm/%: asm ; 102 103HOSTCFLAGS-x86_64 := -fno-PIE 104$(call cc-option-add,HOSTCFLAGS-x86_64,HOSTCC,-no-pie) 105HOSTCFLAGS += $(CFLAGS_xeninclude) -I. $(HOSTCFLAGS-$(XEN_COMPILE_ARCH)) 106 107x86.h := asm/x86-vendors.h asm/x86-defns.h asm/msr-index.h 108x86_emulate.h := x86-emulate.h x86_emulate/x86_emulate.h $(x86.h) 109 110x86-emulate.o: x86-emulate.c x86_emulate/x86_emulate.c $(x86_emulate.h) 111 $(HOSTCC) $(HOSTCFLAGS) -D__XEN_TOOLS__ -c -g -o $@ $< 112 113test_x86_emulator.o: test_x86_emulator.c $(addsuffix .h,$(TESTCASES)) $(x86_emulate.h) 114 $(HOSTCC) $(HOSTCFLAGS) -c -g -o $@ $< 115