Skip to content

Commit

Permalink
add no_flags sample
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Dec 27, 2023
1 parent 523cf1e commit 8c44467
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions sample/no_flags.cpp
Original file line number Diff line number Diff line change
@@ -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(*)()>()());
}
}

0 comments on commit 8c44467

Please sign in to comment.