From bacd8d34b6d1b0dd76e616ad8050b8acc7b44c6b Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 26 Dec 2023 11:37:49 +0900 Subject: [PATCH] add sample/zero_upper.cpp --- sample/Makefile | 6 +++++- sample/zero_upper.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 sample/zero_upper.cpp diff --git a/sample/Makefile b/sample/Makefile index 62c7dcf..5a84bcd 100644 --- a/sample/Makefile +++ b/sample/Makefile @@ -30,7 +30,7 @@ else endif ifeq ($(BIT),64) -TARGET += test64 bf64 memfunc64 test_util64 jmp_table64 +TARGET += test64 bf64 memfunc64 test_util64 jmp_table64 zero_upper ifeq ($(BOOST_EXIST),1) TARGET += calc64 #calc2_64 endif @@ -103,6 +103,10 @@ profiler: profiler.cpp ../xbyak/xbyak_util.h $(CXX) $(CFLAGS) profiler.cpp -o $@ profiler-vtune: profiler.cpp ../xbyak/xbyak_util.h $(CXX) $(CFLAGS) profiler.cpp -o $@ -DXBYAK_USE_VTUNE -I /opt/intel/vtune_amplifier/include/ -L /opt/intel/vtune_amplifier/lib64 -ljitprofiling -ldl +zero_upper: zero_upper.cpp $(XBYAK_INC) + $(CXX) $(CFLAGS) zero_upper.cpp -o $@ +test_zero_upper: zero_upper + sde -future -- ./zero_upper clean: rm -rf $(TARGET) profiler profiler-vtune diff --git a/sample/zero_upper.cpp b/sample/zero_upper.cpp new file mode 100644 index 0000000..46dcca9 --- /dev/null +++ b/sample/zero_upper.cpp @@ -0,0 +1,48 @@ +/* + An example of T_zu (zero upper) flag + > g++ zero_upper.cpp -I ../xbyak + > sde -future -- ./a.out +*/ +#include +#include + +using namespace Xbyak; + +struct Code : Xbyak::CodeGenerator { + Code(int mode) + { + mov(eax, 0x12345678); + cmp(eax, eax); // ZF=1 + switch (mode) { + case 0: // imul + puts("imul"); + imul(ax,ax, 0x1234); + break; + case 1: // imul+zu + puts("imul+zu"); + imul(ax|T_zu, ax, 0x1234); + break; + case 2: // setz + puts("setz"); + setz(al); + break; + case 3: // setz+zu + puts("setz+zu"); + setz(al|T_zu); + break; + } + ret(); + } +}; + +int main() + try +{ + for (int mode = 0; mode < 4; mode++) { + Code c(mode); + auto f = c.getCode(); + printf("ret=%08x\n", f()); + } +} catch (std::exception& e) { + printf("ERR %s\n", e.what()); +}