Squashed 'external/xbyak/' content from commit 9d8ff37

git-subtree-dir: external/xbyak
git-subtree-split: 9d8ff37306f39c6a71cf998078cbe880ce5dc224
This commit is contained in:
Simone Coco
2025-12-23 16:51:03 +01:00
commit 0a097849af
148 changed files with 33794 additions and 0 deletions

44
sample/static_buf.cpp Normal file
View File

@@ -0,0 +1,44 @@
/*
sample to use static memory
*/
#include <stdio.h>
#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);
#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();
Xbyak::CodeArray::protect(buf, sizeof(buf), Xbyak::CodeArray::PROTECT_RE);
}
~Code()
{
Xbyak::CodeArray::protect(buf, sizeof(buf), Xbyak::CodeArray::PROTECT_RW);
}
} s_code;
inline int add(int a, int b)
{
return reinterpret_cast<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);
}