Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
memfunc.cpp
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <memory.h>
4#define XBYAK_NO_OP_NAMES
5#include <xbyak/xbyak.h>
6
7struct A {
8 int x_;
9 int y_;
10 A() : x_(3), y_(5) {}
11 int func(int a, int b, int c, int d, int e) const { return x_ + y_ + a + b + c + d + e; }
12};
13
14#ifdef _MSC_VER
15 #pragma warning(disable : 4510 4512 4610)
16#endif
17
18struct Code : public Xbyak::CodeGenerator {
20 {
21 using namespace Xbyak;
22
23 int RET_ADJ = 0;
24#ifdef XBYAK32
25 #ifdef _WIN32
26 const int PARA_ADJ = 0;
27 RET_ADJ = 5 * 4;
28 #else
29 const int PARA_ADJ = 4;
30 mov(ecx, ptr [esp + 4]);
31 #endif
32#endif
33 const struct {
34#ifdef XBYAK32
35 const Reg32& self;
36#else
37 const Reg64& self;
38#endif
39 const Operand& a;
40 const Operand& b;
41 const Operand& c;
42 const Operand& d;
43 const Operand& e;
44 } para = {
45#if defined(XBYAK64_WIN)
46 rcx,
47 edx,
48 r8d,
49 r9d,
50 ptr [rsp + 8 * 5],
51 ptr [rsp + 8 * 6],
52#elif defined(XBYAK64_GCC)
53 rdi,
54 esi,
55 edx,
56 ecx,
57 r8d,
58 r9d,
59#else
60 ecx,
61 ptr [esp + 4 + PARA_ADJ],
62 ptr [esp + 8 + PARA_ADJ],
63 ptr [esp + 12 + PARA_ADJ],
64 ptr [esp + 16 + PARA_ADJ],
65 ptr [esp + 20 + PARA_ADJ],
66#endif
67 };
68 mov(eax, ptr [para.self]);
69 add(eax, ptr [para.self + 4]);
70 add(eax, para.a);
71 add(eax, para.b);
72 add(eax, para.c);
73 add(eax, para.d);
74 add(eax, para.e);
75 ret(RET_ADJ);
76 }
77};
78
79int main()
80{
81#ifdef XBYAK64
82 printf("64bit");
83#else
84 printf("32bit");
85#endif
86#ifdef _WIN32
87 puts(" win");
88#else
89 puts(" linux");
90#endif
91 try {
92 Code code;
93 int (A::*p)(int, int, int, int, int) const = 0;
94 const void *addr = code.getCode<void*>();
95 memcpy(&p, &addr, sizeof(void*));
96 for (int i = 0; i < 10; i++) {
97 A a;
98 int t1, t2, t3, t4, t5, x, y;
99 a.x_ = rand(); a.y_ = rand();
100 t1 = rand(); t2 = rand(); t3 = rand();
101 t4 = rand(); t5 = rand();
102 x = a.func(t1, t2, t3, t4, t5);
103 y = (a.*p)(t1, t2, t3, t4, t5);
104 printf("%c %d, %d\n", x == y ? 'o' : 'x', x, y);
105 }
106 } catch (std::exception& e) {
107 printf("err=%s\n", e.what());
108 return 1;
109 }
110}
111
const mie::Vuint & p
Definition bn.cpp:27
Operand
Definition calc2.cpp:28
const uint8 * getCode() const
Definition xbyak.h:905
const Reg32 esp
Definition xbyak.h:2087
const Reg32 eax
Definition xbyak.h:2087
const Reg32 ecx
Definition xbyak.h:2087
void add(const Operand &op, uint32 imm)
Definition xbyak.h:6
const Reg32 edx
Definition xbyak.h:2087
void mov(const Operand &reg1, const Operand &reg2)
Definition xbyak.h:2210
const Reg32 esi
Definition xbyak.h:2087
const AddressFrame ptr
Definition xbyak.h:2090
int main()
Definition memfunc.cpp:79
Definition xbyak.h:104
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
A()
Definition memfunc.cpp:10
int func(int a, int b, int c, int d, int e) const
Definition memfunc.cpp:11
int x_
Definition memfunc.cpp:8
int y_
Definition memfunc.cpp:9
Definition bench.cpp:18
Code()
Definition memfunc.cpp:19
Xbyak ; JIT assembler for x86(IA32)/x64 by C++.
CK_ULONG d
CK_RV ret
memcpy((char *) pInfo->slotDescription, s, l)