File: zero_upper.cpp

package info (click to toggle)
xbyak 7.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,068 kB
  • sloc: cpp: 21,493; ansic: 2,981; python: 372; makefile: 306; sh: 204
file content (48 lines) | stat: -rw-r--r-- 797 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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());
}