Skip to content

Commit 30ad736

Browse files
SpaceImmadebr
authored andcommitted
(conan-io#5784) add xbyak/5.993
1 parent 11b9784 commit 30ad736

File tree

6 files changed

+194
-0
lines changed

6 files changed

+194
-0
lines changed

recipes/xbyak/all/conandata.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sources:
2+
"5.993":
3+
url: "https://github.com/herumi/xbyak/archive/refs/tags/v5.993.tar.gz"
4+
sha256: "97d596e7ca05208a0f64b225bff482ee5bcd44ebae07f1e3a50009d5e54b940b"

recipes/xbyak/all/conanfile.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from conans import ConanFile, tools
2+
import os
3+
4+
required_conan_version = ">=1.33.0"
5+
6+
7+
class XbyakConan(ConanFile):
8+
name = "xbyak"
9+
description = "Xbyak is a C++ header library that enables dynamically to " \
10+
"assemble x86(IA32), x64(AMD64, x86-64) mnemonic."
11+
license = "BSD-3-Clause"
12+
topics = ("conan", "xbyak", "jit", "assembler")
13+
homepage = "https://github.com/herumi/xbyak"
14+
url = "https://github.com/conan-io/conan-center-index"
15+
no_copy_source = True
16+
17+
@property
18+
def _source_subfolder(self):
19+
return "source_subfolder"
20+
21+
def package_id(self):
22+
self.info.header_only()
23+
24+
def source(self):
25+
tools.get(**self.conan_data["sources"][self.version],
26+
destination=self._source_subfolder, strip_root=True)
27+
28+
def package(self):
29+
self.copy("COPYRIGHT", dst="licenses", src=self._source_subfolder)
30+
self.copy("*.h", dst=os.path.join("include", "xbyak"), src=os.path.join(self._source_subfolder, "xbyak"))
31+
32+
def package_info(self):
33+
self.cpp_info.names["cmake_find_package"] = "xbyak"
34+
self.cpp_info.names["cmake_find_package_multi"] = "xbyak"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
find_package(xbyak REQUIRED CONFIG)
8+
9+
add_executable(${PROJECT_NAME} test_package.cpp)
10+
target_link_libraries(${PROJECT_NAME} xbyak::xbyak)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self.settings):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#define XBYAK_NO_OP_NAMES
2+
#include <xbyak/xbyak.h>
3+
4+
#include <stdio.h>
5+
6+
const int expectTbl[] = {
7+
5, 9, 12
8+
};
9+
10+
struct Code : Xbyak::CodeGenerator {
11+
explicit Code(int mode, size_t size, void *p)
12+
: Xbyak::CodeGenerator(size, p)
13+
{
14+
inLocalLabel();
15+
#ifdef XBYAK64
16+
const Xbyak::Reg64& a = rax;
17+
const Xbyak::Reg64& c = rcx;
18+
#ifdef XBYAK64_WIN
19+
mov(rax, rcx);
20+
#else
21+
mov(rax, rdi);
22+
#endif
23+
#else
24+
const Xbyak::Reg32& a = eax;
25+
const Xbyak::Reg32& c = ecx;
26+
mov(a, ptr [esp + 4]);
27+
#endif
28+
29+
switch (mode) {
30+
case 0:
31+
mov(c, ".jmp_table");
32+
lea(c, ptr [c + a * 8]);
33+
jmp(c);
34+
align(8);
35+
L(".jmp_table");
36+
mov(a, expectTbl[0]);
37+
ret();
38+
align(8);
39+
mov(a, expectTbl[1]);
40+
ret();
41+
align(8);
42+
mov(a, expectTbl[2]);
43+
ret();
44+
break;
45+
46+
case 1:
47+
/*
48+
the label for putL is defined when called
49+
*/
50+
mov(c, ".jmp_table");
51+
jmp(ptr [c + a * (int)sizeof(size_t)]);
52+
L(".label1");
53+
mov(a, expectTbl[0]);
54+
jmp(".end");
55+
L(".label2");
56+
mov(a, expectTbl[1]);
57+
jmp(".end");
58+
L(".label3");
59+
mov(a, expectTbl[2]);
60+
jmp(".end");
61+
L(".end");
62+
ret();
63+
ud2();
64+
65+
align(8);
66+
L(".jmp_table");
67+
putL(".label1");
68+
putL(".label2");
69+
putL(".label3");
70+
break;
71+
72+
case 2:
73+
/*
74+
the label for putL is not defined when called
75+
*/
76+
jmp(".in");
77+
ud2();
78+
align(8);
79+
L(".jmp_table");
80+
putL(".label1");
81+
putL(".label2");
82+
putL(".label3");
83+
L(".in");
84+
mov(c, ".jmp_table");
85+
jmp(ptr [c + a * (int)sizeof(size_t)]);
86+
L(".label1");
87+
mov(a, expectTbl[0]);
88+
jmp(".end");
89+
L(".label2");
90+
mov(a, expectTbl[1]);
91+
jmp(".end");
92+
L(".label3");
93+
mov(a, expectTbl[2]);
94+
jmp(".end");
95+
L(".end");
96+
ret();
97+
break;
98+
}
99+
outLocalLabel();
100+
}
101+
};
102+
103+
int main()
104+
try
105+
{
106+
for (int mode = 0; mode < 3; mode++) {
107+
printf("mode=%d\n", mode);
108+
for (int grow = 0; grow < 2; grow++) {
109+
printf("auto grow=%s\n", grow ? "on" : "off");
110+
Code c(mode, grow ? 30 : 4096, grow ? Xbyak::AutoGrow : 0);
111+
int (*f)(int) = c.getCode<int (*)(int)>();
112+
c.ready();
113+
for (int i = 0; i < 3; i++) {
114+
const int a = expectTbl[i];
115+
const int b = f(i);
116+
if (a != b) {
117+
printf("ERR i=%d, a=%d, b=%d\n", i, a, b);
118+
exit(1);
119+
}
120+
}
121+
}
122+
}
123+
puts("ok");
124+
} catch (std::exception& e) {
125+
printf("ERR %s\n", e.what());
126+
}

recipes/xbyak/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"5.993":
3+
folder: all

0 commit comments

Comments
 (0)