diff --git a/recipes/xbyak/all/conandata.yml b/recipes/xbyak/all/conandata.yml new file mode 100644 index 00000000000000..d1133c5032998a --- /dev/null +++ b/recipes/xbyak/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "5.993": + url: "https://github.com/herumi/xbyak/archive/refs/tags/v5.993.tar.gz" + sha256: "97d596e7ca05208a0f64b225bff482ee5bcd44ebae07f1e3a50009d5e54b940b" diff --git a/recipes/xbyak/all/conanfile.py b/recipes/xbyak/all/conanfile.py new file mode 100644 index 00000000000000..7ec5fe1e56b218 --- /dev/null +++ b/recipes/xbyak/all/conanfile.py @@ -0,0 +1,34 @@ +from conans import ConanFile, tools +import os + +required_conan_version = ">=1.33.0" + + +class XbyakConan(ConanFile): + name = "xbyak" + description = "Xbyak is a C++ header library that enables dynamically to " \ + "assemble x86(IA32), x64(AMD64, x86-64) mnemonic." + license = "BSD-3-Clause" + topics = ("conan", "xbyak", "jit", "assembler") + homepage = "https://github.com/herumi/xbyak" + url = "https://github.com/conan-io/conan-center-index" + no_copy_source = True + + @property + def _source_subfolder(self): + return "source_subfolder" + + def package_id(self): + self.info.header_only() + + def source(self): + tools.get(**self.conan_data["sources"][self.version], + destination=self._source_subfolder, strip_root=True) + + def package(self): + self.copy("COPYRIGHT", dst="licenses", src=self._source_subfolder) + self.copy("*.h", dst=os.path.join("include", "xbyak"), src=os.path.join(self._source_subfolder, "xbyak")) + + def package_info(self): + self.cpp_info.names["cmake_find_package"] = "xbyak" + self.cpp_info.names["cmake_find_package_multi"] = "xbyak" diff --git a/recipes/xbyak/all/test_package/CMakeLists.txt b/recipes/xbyak/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..06cb5e8631ae14 --- /dev/null +++ b/recipes/xbyak/all/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(xbyak REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} xbyak::xbyak) diff --git a/recipes/xbyak/all/test_package/conanfile.py b/recipes/xbyak/all/test_package/conanfile.py new file mode 100644 index 00000000000000..a9f777f7680ff1 --- /dev/null +++ b/recipes/xbyak/all/test_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/xbyak/all/test_package/test_package.cpp b/recipes/xbyak/all/test_package/test_package.cpp new file mode 100644 index 00000000000000..f44f21153df9bd --- /dev/null +++ b/recipes/xbyak/all/test_package/test_package.cpp @@ -0,0 +1,126 @@ +#define XBYAK_NO_OP_NAMES +#include + +#include + +const int expectTbl[] = { + 5, 9, 12 +}; + +struct Code : Xbyak::CodeGenerator { + explicit Code(int mode, size_t size, void *p) + : Xbyak::CodeGenerator(size, p) + { + inLocalLabel(); +#ifdef XBYAK64 + const Xbyak::Reg64& a = rax; + const Xbyak::Reg64& c = rcx; +#ifdef XBYAK64_WIN + mov(rax, rcx); +#else + mov(rax, rdi); +#endif +#else + const Xbyak::Reg32& a = eax; + const Xbyak::Reg32& c = ecx; + mov(a, ptr [esp + 4]); +#endif + + switch (mode) { + case 0: + mov(c, ".jmp_table"); + lea(c, ptr [c + a * 8]); + jmp(c); + align(8); + L(".jmp_table"); + mov(a, expectTbl[0]); + ret(); + align(8); + mov(a, expectTbl[1]); + ret(); + align(8); + mov(a, expectTbl[2]); + ret(); + break; + + case 1: + /* + the label for putL is defined when called + */ + mov(c, ".jmp_table"); + jmp(ptr [c + a * (int)sizeof(size_t)]); + L(".label1"); + mov(a, expectTbl[0]); + jmp(".end"); + L(".label2"); + mov(a, expectTbl[1]); + jmp(".end"); + L(".label3"); + mov(a, expectTbl[2]); + jmp(".end"); + L(".end"); + ret(); + ud2(); + + align(8); + L(".jmp_table"); + putL(".label1"); + putL(".label2"); + putL(".label3"); + break; + + case 2: + /* + the label for putL is not defined when called + */ + jmp(".in"); + ud2(); + align(8); + L(".jmp_table"); + putL(".label1"); + putL(".label2"); + putL(".label3"); + L(".in"); + mov(c, ".jmp_table"); + jmp(ptr [c + a * (int)sizeof(size_t)]); + L(".label1"); + mov(a, expectTbl[0]); + jmp(".end"); + L(".label2"); + mov(a, expectTbl[1]); + jmp(".end"); + L(".label3"); + mov(a, expectTbl[2]); + jmp(".end"); + L(".end"); + ret(); + break; + } + outLocalLabel(); + } +}; + +int main() + try +{ + for (int mode = 0; mode < 3; mode++) { + printf("mode=%d\n", mode); + for (int grow = 0; grow < 2; grow++) { + printf("auto grow=%s\n", grow ? "on" : "off"); + Code c(mode, grow ? 30 : 4096, grow ? Xbyak::AutoGrow : 0); + int (*f)(int) = c.getCode(); + c.ready(); + for (int i = 0; i < 3; i++) { + const int a = expectTbl[i]; + const int b = f(i); + if (a != b) { + printf("ERR i=%d, a=%d, b=%d\n", i, a, b); + exit(1); + } + } + } + } + puts("ok"); +} catch (std::exception& e) { + printf("ERR %s\n", e.what()); +} diff --git a/recipes/xbyak/config.yml b/recipes/xbyak/config.yml new file mode 100644 index 00000000000000..6f5b1de9deadab --- /dev/null +++ b/recipes/xbyak/config.yml @@ -0,0 +1,3 @@ +versions: + "5.993": + folder: all