aboutsummaryrefslogtreecommitdiffhomepage
path: root/sample
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <[email protected]>2023-12-26 13:38:18 +0900
committerMITSUNARI Shigeo <[email protected]>2023-12-26 13:38:18 +0900
commit5438fc69dbc0ee92a1536e4f8572c45070390df9 (patch)
treeda94073429e7aaae27fdaabab95b054b2a2f8a72 /sample
parentf17cb9d6b94c44e0c7f2b569b0e360c416e628d5 (diff)
parentee26c094ed0e2a20ca5514ea26587614d0d582ca (diff)
downloadxbyak-5438fc69dbc0ee92a1536e4f8572c45070390df9.tar.gz
xbyak-5438fc69dbc0ee92a1536e4f8572c45070390df9.zip
Merge branch 'dev'v7.03
Diffstat (limited to 'sample')
-rw-r--r--sample/Makefile10
-rw-r--r--sample/ccmp.cpp68
-rw-r--r--sample/zero_upper.cpp48
3 files changed, 125 insertions, 1 deletions
diff --git a/sample/Makefile b/sample/Makefile
index 62c7dcf..2010f69 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 ccmp
ifeq ($(BOOST_EXIST),1)
TARGET += calc64 #calc2_64
endif
@@ -103,6 +103,14 @@ 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
+ccmp: ccmp.cpp $(XBYAK_INC)
+ $(CXX) $(CFLAGS) ccmp.cpp -o $@
+test_ccmp: ccmp
+ sde -future -- ./ccmp
clean:
rm -rf $(TARGET) profiler profiler-vtune
diff --git a/sample/ccmp.cpp b/sample/ccmp.cpp
new file mode 100644
index 0000000..622d3d1
--- /dev/null
+++ b/sample/ccmp.cpp
@@ -0,0 +1,68 @@
+/*
+ An example of ccmp
+ > g++ ccmp.cpp -I ../xbyak
+ > sde -future -- ./a.out
+*/
+#include <stdio.h>
+#include <xbyak/xbyak.h>
+#include <xbyak/xbyak_util.h>
+
+using namespace Xbyak;
+
+struct Code1 : Xbyak::CodeGenerator {
+ Code1()
+ {
+ Xbyak::util::StackFrame sf(this, 2);
+ const auto& p1 = sf.p[0];
+ const auto& p2 = sf.p[1];
+ int dfv = 0;
+ cmp(p1, 3);
+ ctesta(p2, 1, dfv); // eflags = (p1 > 3) ? (p2 & 1) : dfv;
+ setz(al|T_zu);
+ }
+};
+
+struct Code2 : Xbyak::CodeGenerator {
+ Code2()
+ {
+ Xbyak::util::StackFrame sf(this, 3);
+ const auto& p1 = sf.p[0];
+ const auto& p2 = sf.p[1];
+ const auto& p3 = sf.p[2];
+ int dfv = 0;
+ cmp(p1, 1);
+ ccmpe(p2, 2, dfv); // eflags = p1==1 ? p2==2 : dfv;
+ ccmpe(p3, 3, dfv); // eflags = (p1==1 && p2==2) ? p3==3 : dfv;
+ setz(al|T_zu); // p1==1 && p2==2 && p3==3
+ }
+};
+
+
+int main()
+ try
+{
+ {
+ puts("(p1 > 3) && ((p2 & 1) == 0)");
+ Code1 c;
+ auto f = c.getCode<int (*)(int, int)>();
+ for (int p1 = 2; p1 < 5; p1++) {
+ for (int p2 = 0; p2 < 3; p2++) {
+ printf("p1=%d p2=%d ret=%d (%d)\n", p1, p2, f(p1, p2), p1 > 3 && ((p2&1) == 0));
+ }
+ }
+ }
+ {
+ puts("p1 == 1 && p2 == 2 && p3 == 3");
+ Code2 c;
+ auto f = c.getCode<int (*)(int, int, int)>();
+ for (int p1 = 0; p1 < 3; p1++) {
+ for (int p2 = 1; p2 < 4; p2++) {
+ for (int p3 = 2; p3 < 5; p3++) {
+ printf("p1=%d p2=%d p3=%d ret=%d (%d)\n", p1, p2, p3, f(p1, p2, p3), p1==1 && p2==2 && p3==3);
+ }
+ }
+ }
+ }
+} catch (std::exception& e) {
+ printf("ERR %s\n", e.what());
+}
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 <stdio.h>
+#include <xbyak/xbyak.h>
+
+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<int (*)()>();
+ printf("ret=%08x\n", f());
+ }
+} catch (std::exception& e) {
+ printf("ERR %s\n", e.what());
+}