Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
cvt_test.cpp
Go to the documentation of this file.
1#include <xbyak/xbyak.h>
2
3using namespace Xbyak;
4using namespace Xbyak::util;
5
6#ifdef XBYAK64
7const struct Ptn {
8 const Reg8 *reg8;
11 Reg64 reg64;
12} tbl[] = {
13 { &al, ax, eax, rax },
14 { &bl, bx, ebx, rbx },
15 { &cl, cx, ecx, rcx },
16 { &dl, dx, edx, rdx },
17 { &sil, si, esi, rsi },
18 { &dil, di, edi, rdi },
19 { &bpl, bp, ebp, rbp },
20 { &spl, sp, esp, rsp },
21 { &r8b, r8w, r8d, r8 },
22 { &r9b, r9w, r9d, r9 },
23 { &r10b, r10w, r10d, r10 },
24 { &r11b, r11w, r11d, r11 },
25 { &r12b, r12w, r12d, r12 },
26 { &r13b, r13w, r13d, r13 },
27 { &r14b, r14w, r14d, r14 },
28 { &r15b, r15w, r15d, r15 },
29};
30#else
31const struct Ptn {
32 const Reg8 *reg8;
35} tbl[] = {
36 { &al, ax, eax },
37 { &bl, bx, ebx },
38 { &cl, cx, ecx },
39 { &dl, dx, edx },
40 { 0, si, esi },
41 { 0, di, edi },
42 { 0, bp, ebp },
43 { 0, sp, esp },
44};
45#endif
46
47int errNum = 0;
48int testNum = 0;
49
50template<class T>
51void verify(const T& x, const T& y)
52{
53 if (x != y) {
54 printf("ERR %s %s\n", x.toString(), y.toString());
55 errNum++;
56 }
57 testNum++;
58}
59
60#define verifyExp(state) \
61{ \
62 bool isOK = false; \
63 try { \
64 state; \
65 } catch (const Xbyak::Error& e) { \
66 if ((int)e == ERR_CANT_CONVERT) { \
67 isOK = true; \
68 } \
69 } \
70 if (!isOK) { \
71 printf("ERR " #state "\n"); \
72 errNum++; \
73 } \
74 testNum++; \
75}
76
77int main()
78 try
79{
80 for (size_t i = 0; i < sizeof(tbl) / sizeof(tbl[0]); i++) {
81 if (tbl[i].reg8) {
82 verify(tbl[i].reg8->cvt8(), *tbl[i].reg8);
83 verify(tbl[i].reg8->cvt16(), tbl[i].reg16);
84 verify(tbl[i].reg8->cvt32(), tbl[i].reg32);
85 verify(tbl[i].reg16.cvt8(), *tbl[i].reg8);
86 verify(tbl[i].reg32.cvt8(), *tbl[i].reg8);
87 }
88 verify(tbl[i].reg16.cvt16(), tbl[i].reg16);
89 verify(tbl[i].reg16.cvt32(), tbl[i].reg32);
90 verify(tbl[i].reg32.cvt16(), tbl[i].reg16);
91 verify(tbl[i].reg32.cvt32(), tbl[i].reg32);
92#ifdef XBYAK64
93 if (tbl[i].reg8) {
94 verify(tbl[i].reg64.cvt8(), *tbl[i].reg8);
95 verify(tbl[i].reg8->cvt64(), tbl[i].reg64);
96 }
97 verify(tbl[i].reg64.cvt16(), tbl[i].reg16);
98 verify(tbl[i].reg64.cvt32(), tbl[i].reg32);
99 verify(tbl[i].reg64.cvt64(), tbl[i].reg64);
100 verify(tbl[i].reg16.cvt64(), tbl[i].reg64);
101 verify(tbl[i].reg32.cvt64(), tbl[i].reg64);
102#endif
103 }
104 {
105 const Reg8 errTbl[] = {
106 ah, bh, ch, dh
107 };
108 for (size_t i = 0; i < sizeof(errTbl) / sizeof(errTbl[0]); i++) {
109 verifyExp(errTbl[i].cvt16());
110 }
111 }
112#ifdef XBYAK32
113 {
114 const Reg16 errTbl[] = {
115 si, di, bp, sp
116 };
117 for (size_t i = 0; i < sizeof(errTbl) / sizeof(errTbl[0]); i++) {
118 verifyExp(errTbl[i].cvt8());
119 }
120 }
121#endif
122 printf("test=%d(err=%d)\n", testNum, errNum);
123} catch (std::exception& e) {
124 printf("ERR %s\n", e.what());
125}
int errNum
Definition cvt_test.cpp:47
#define verifyExp(state)
Definition cvt_test.cpp:60
void verify(const T &x, const T &y)
Definition cvt_test.cpp:51
int testNum
Definition cvt_test.cpp:48
int main()
Definition cvt_test.cpp:77
const struct Ptn tbl[]
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
static const Reg8 dl(Operand::DL)
static const Reg32 ebp(Operand::EBP)
static const Reg8 ch(Operand::CH)
static const Reg32 esp(Operand::ESP)
static const Reg16 dx(Operand::DX)
static const Reg8 ah(Operand::AH)
static const Reg32 ecx(Operand::ECX)
static const Reg32 edi(Operand::EDI)
static const Reg32 edx(Operand::EDX)
static const Reg16 di(Operand::DI)
static const Reg16 si(Operand::SI)
static const Reg8 dh(Operand::DH)
static const Reg16 sp(Operand::SP)
static const Reg8 bh(Operand::BH)
static const Reg16 bp(Operand::BP)
static const Reg16 cx(Operand::CX)
static const Reg32 ebx(Operand::EBX)
static const Reg8 bl(Operand::BL)
static const Reg8 cl(Operand::CL)
static const Reg16 bx(Operand::BX)
static const Reg32 esi(Operand::ESI)
Definition xbyak.h:104
#define T(meth, val, expected)
Reg32 reg32
Definition cvt_test.cpp:34
Reg16 reg16
Definition cvt_test.cpp:33
const Reg8 * reg8
Definition cvt_test.cpp:32
Xbyak ; JIT assembler for x86(IA32)/x64 by C++.