mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2025-12-27 17:55:21 +01:00
Squashed 'externals/xbyak/' content from commit d512551e
git-subtree-dir: externals/xbyak git-subtree-split: d512551e914737300ba35f3c049d1b40effbe76d
This commit is contained in:
commit
4ed09fda06
79 changed files with 22734 additions and 0 deletions
41
sample/static_buf.cpp
Normal file
41
sample/static_buf.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
sample to use static memory
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#define XBYAK_NO_OP_NAMES
|
||||
#include "xbyak/xbyak.h"
|
||||
|
||||
MIE_ALIGN(4096) char buf[4096];
|
||||
|
||||
struct Code : Xbyak::CodeGenerator {
|
||||
Code()
|
||||
: Xbyak::CodeGenerator(sizeof(buf), buf)
|
||||
{
|
||||
puts("generate");
|
||||
printf("ptr=%p, %p\n", getCode(), buf);
|
||||
Xbyak::CodeArray::protect(buf, sizeof(buf), true);
|
||||
#ifdef XBYAK32
|
||||
mov(eax, ptr [esp + 4]);
|
||||
add(eax, ptr [esp + 8]);
|
||||
#elif defined(XBYAK64_WIN)
|
||||
lea(rax, ptr [rcx + rdx]);
|
||||
#else
|
||||
lea(rax, ptr [rdi + rsi]);
|
||||
#endif
|
||||
ret();
|
||||
}
|
||||
} s_code;
|
||||
|
||||
inline int add(int a, int b)
|
||||
{
|
||||
return Xbyak::CastTo<int (*)(int,int)>(buf)(a, b);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sum += add(i, 5);
|
||||
}
|
||||
printf("sum=%d\n", sum);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue