add no_flags sample

This commit is contained in:
MITSUNARI Shigeo 2023-12-27 09:06:48 +09:00
parent 523cf1ed04
commit 8c44467afb
2 changed files with 33 additions and 1 deletions

View file

@ -30,7 +30,7 @@ else
endif
ifeq ($(BIT),64)
TARGET += test64 bf64 memfunc64 test_util64 jmp_table64 zero_upper ccmp
TARGET += test64 bf64 memfunc64 test_util64 jmp_table64 zero_upper ccmp no_flags
ifeq ($(BOOST_EXIST),1)
TARGET += calc64 #calc2_64
endif
@ -111,6 +111,10 @@ ccmp: ccmp.cpp $(XBYAK_INC)
$(CXX) $(CFLAGS) ccmp.cpp -o $@
test_ccmp: ccmp
sde -future -- ./ccmp
no_flags: no_flags.cpp $(XBYAK_INC)
$(CXX) $(CFLAGS) no_flags.cpp -o $@
test_no_flags: no_flags
sde -future -- ./no_flags
clean:
rm -rf $(TARGET) profiler profiler-vtune

28
sample/no_flags.cpp Normal file
View file

@ -0,0 +1,28 @@
#include <stdio.h>
#include <xbyak/xbyak.h>
struct Code : Xbyak::CodeGenerator {
Code(bool nf) {
if (nf) {
puts("no flags (with T_nf)");
} else {
puts("change flags (without T_nf)");
}
xor_(eax, eax); // CF = 0
mov(eax, -1);
if (nf) {
add(eax|T_nf, eax, 1); // does not change CF
} else {
add(eax, eax, 1); // CF = 1
}
adc(eax, 0); // eax = CF ? 1 : 0
ret();
}
};
int main() {
for (int i = 0; i < 2; i++) {
Code c(i);
printf("i=%d ret=%d\n", i, c.getCode<int(*)()>()());
}
}