From 8a0bd797bfe33b7dd46fe24db4f50a8bf52361d0 Mon Sep 17 00:00:00 2001 From: tz12323 <2760686250@qq.com> Date: Tue, 20 Oct 2026 10:56:34 +0800 Subject: [PATCH] add xsimd --- .agents/docs/2026-10-20-add-xsimd-plan.md | 78 +++++++++++++++++++++++ mcpp.toml | 1 + pkgs/c/compat.xsimd.lua | 68 ++++++++++++++++++++ tests/examples/xsimd/mcpp.toml | 8 +++ tests/examples/xsimd/tests/xsimd.cpp | 55 ++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 .agents/docs/2026-10-20-add-xsimd-plan.md create mode 100644 pkgs/c/compat.xsimd.lua create mode 100644 tests/examples/xsimd/mcpp.toml create mode 100644 tests/examples/xsimd/tests/xsimd.cpp diff --git a/.agents/docs/2026-10-20-add-xsimd-plan.md b/.agents/docs/2026-10-20-add-xsimd-plan.md new file mode 100644 index 00000000..288873f0 --- /dev/null +++ b/.agents/docs/2026-10-20-add-xsimd-plan.md @@ -0,0 +1,78 @@ +# Add xsimd 14.3.0 as compat.xsimd + +## Source and shape + +- Upstream: . +- Version: `14.3.0`, the newest stable tag observed with + `git ls-remote --tags --refs`. +- License: BSD-3-Clause. +- Shape: Form B, header-only. Upstream's CMake INTERFACE target exposes + `include/`, where consumers find ``. The package therefore + uses `include_dirs = { "*/include" }` and a trivial anchor C TU to provide a + buildable `xsimd` lib target. +- No features: xsimd has no optional compilable library component. The + optional `xtl::xcomplex` integration is an external dependency plus the + consumer's `XSIMD_ENABLE_XTL_COMPLEX` define, which a sources-only feature + cannot express. + +Upstream requires C++14. The descriptor compiles its own anchor as C++; the +consumer test uses the workspace default C++23 mode and a direct smoke test +also verifies that the public header compiles in C++14 mode. + +## Download and mirror + +- GLOBAL: + `https://github.com/xtensor-stack/xsimd/archive/refs/tags/14.3.0.tar.gz` +- SHA-256: + `b3d50e7a73fbf4642ceef30131c93414901d69eee41c2a5302db650b03e2c792` +- The archive was downloaded twice and compared byte-for-byte; both copies had + the same digest. +- No verified `mcpp-res/xsimd` release is available, so the descriptor uses the + upstream plain-string URL fallback rather than inventing a CN resource. + +## Automatic updates + +The package meets the automatic-update criteria: it has GitHub numeric tags, +stable archive URLs, identical resources on all declared platforms, and future +versions do not require a build-recipe change. `extensions.autoupdate` uses the +unprefixed `${version}` tag spelling and the GitHub tag-archive URL template. +The initial URL and SHA-256 live once in the `versions` table and all three +platforms reference that entry. + +## Test member + +`tests/examples/xsimd/` is registered in the root workspace. It asserts: + +- the selected default architecture is supported and available; +- runtime architecture discovery contains the default architecture; +- unaligned load, batch addition and unaligned store preserve every lane; +- batch square root and horizontal reduction return the expected scalar. + +Every assertion affects the process exit status (`return ok ? 0 : 1`). + +## Verification + +- Pinned mcpp `2026.10.1.2`: + `mcpp xpkg parse --all-os pkgs/c/compat.xsimd.lua` reports `parse OK` for + linux, macosx, and windows. +- Pinned cold GCC run: + `mcpp test -p xsimd --cache off` reports + `test result ok. 1 passed; 0 failed`, running + `xsimd OK width=4 arch=sse2`. +- Pinned cold LLVM run: + `mcpp test -p xsimd --toolchain llvm@22.1.8 --cache off` reports the same + successful test with Clang. +- The public header and test compile and run directly under both C++14 and + C++23 (GCC 16.2.1), covering xsimd's documented language floor. +- Full relevant lint passed: Lua syntax, mirror URL policy, package identity, + reserved namespaces, cross-package references, platform parity, and + duplicate versions. All 255 descriptors parse with the pinned mcpp. +- The pinned updater's 11 repository tests pass. Its declaration coverage audit + reports `All 83 GitHub-direct descriptors declared; all existing versions + unchanged`, including `compat:xsimd`. +- `xpkgindex_update inspect --package compat:xsimd` accepts the declaration and + reports the three platform URLs plus the automatic-update template. +- `xpkgindex_update check --package compat:xsimd` reports + `status = "up-to-date"`, current version `14.3.0`, discovery by upstream + tags. An earlier attempt hit the unauthenticated GitHub API rate limit; the + check passed after the documented reset window. diff --git a/mcpp.toml b/mcpp.toml index a25889b3..b906489a 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -172,6 +172,7 @@ members = [ "tests/examples/websocket-features", "tests/examples/websocket-tls", "tests/examples/tray", + "tests/examples/xsimd", "tests/examples/xxhash", "tests/examples/yaml-cpp", "tests/examples/yaml-cpp-v080", diff --git a/pkgs/c/compat.xsimd.lua b/pkgs/c/compat.xsimd.lua new file mode 100644 index 00000000..0040efd9 --- /dev/null +++ b/pkgs/c/compat.xsimd.lua @@ -0,0 +1,68 @@ +local versions = { + ["14.3.0"] = { + url = "https://github.com/xtensor-stack/xsimd/archive/refs/tags/14.3.0.tar.gz", + sha256 = "b3d50e7a73fbf4642ceef30131c93414901d69eee41c2a5302db650b03e2c792", + }, +} + +-- Form B inline descriptor for xsimd — C++ wrappers over SIMD intrinsics. +-- +-- HEADER-ONLY: upstream's CMake target exposes exactly `include/`, where +-- consumers find ``. Tests, examples, benchmarks and docs +-- stay outside the include path. A trivial anchor TU gives mcpp a buildable +-- `xsimd` lib target, following compat.gtl / compat.safeint. +-- +-- LANGUAGE FLOOR: xsimd requires C++14 (`target_compile_features` says +-- `cxx_std_14`). The package's own anchor is compiled as C++; consumers may +-- use any C++14-or-newer language mode supported by their toolchain. +-- +-- No features: xsimd is header-only and has no optional compilable library +-- component. Its optional `xtl::xcomplex` integration is controlled by the +-- consumer's XSIMD_ENABLE_XTL_COMPLEX define and an external xtl dependency, +-- so a sources-only feature cannot represent it and is deliberately omitted. +-- +-- No verified mcpp-res mirror is available, so the upstream URL is a plain +-- string rather than a fabricated GLOBAL/CN resource table. +package = { + spec = "1", + namespace = "compat", + name = "xsimd", + description = "C++ wrappers for SIMD intrinsics with runtime architecture selection (header-only)", + licenses = {"BSD-3-Clause"}, + repo = "https://github.com/xtensor-stack/xsimd", + type = "package", + + extensions = { + autoupdate = { + tag = "${version}", + url = "https://github.com/xtensor-stack/xsimd/archive/refs/tags/${tag}.tar.gz", + }, + }, + + xpm = { + linux = { + ["14.3.0"] = versions["14.3.0"], + }, + macosx = { + ["14.3.0"] = versions["14.3.0"], + }, + windows = { + ["14.3.0"] = versions["14.3.0"], + }, + }, + + mcpp = { + language = "c++23", + import_std = false, + c_standard = "c11", + include_dirs = { "*/include" }, + generated_files = { + ["mcpp_generated/xsimd_anchor.c"] = [==[ +int mcpp_compat_xsimd_headers_anchor(void) { return 0; } +]==], + }, + sources = { "mcpp_generated/xsimd_anchor.c" }, + targets = { ["xsimd"] = { kind = "lib" } }, + deps = { }, + }, +} diff --git a/tests/examples/xsimd/mcpp.toml b/tests/examples/xsimd/mcpp.toml new file mode 100644 index 00000000..68eb2e66 --- /dev/null +++ b/tests/examples/xsimd/mcpp.toml @@ -0,0 +1,8 @@ +# xsimd test project: exercise the default architecture selected from the +# consumer's compiler flags, plus load/store and useful batch operations. +[package] +name = "xsimd-tests" +version = "0.1.0" + +[dependencies.compat] +xsimd = "14.3.0" diff --git a/tests/examples/xsimd/tests/xsimd.cpp b/tests/examples/xsimd/tests/xsimd.cpp new file mode 100644 index 00000000..ddc88a90 --- /dev/null +++ b/tests/examples/xsimd/tests/xsimd.cpp @@ -0,0 +1,55 @@ +// compat.xsimd — assert architecture discovery, unaligned load/store, batch +// arithmetic, math functions and horizontal reduction through the public API. +#include + +#include +#include +#include +#include + +int main() { + using batch_type = xsimd::batch; + constexpr std::size_t width = batch_type::size; + + std::array left{}; + std::array right{}; + std::array sum{}; + for (std::size_t i = 0; i < width; ++i) { + left[i] = static_cast(i + 1); + right[i] = static_cast(2 * i + 2); + } + + bool ok = true; + auto check = [&](bool condition, const char* what) { + if (!condition) { + std::printf("FAIL: %s\n", what); + ok = false; + } + }; + + check(xsimd::default_arch::supported(), + "default architecture is supported by the compiler"); + check(xsimd::default_arch::available(), + "default architecture is available on this CPU"); + check(xsimd::available_architectures().has(xsimd::default_arch{}), + "runtime discovery includes the default architecture"); + + auto lhs = xsimd::load_unaligned(left.data()); + auto rhs = xsimd::load_unaligned(right.data()); + xsimd::store_unaligned(sum.data(), lhs + rhs); + for (std::size_t i = 0; i < width; ++i) { + check(sum[i] == left[i] + right[i], + "unaligned load, batch addition and store"); + } + + auto square_roots = xsimd::sqrt(lhs * lhs); + const float expected = static_cast(width * (width + 1) / 2); + check(std::fabs(xsimd::reduce_add(square_roots) - expected) < 0.001f, + "batch math and horizontal reduction"); + + if (ok) { + std::printf("xsimd OK width=%zu arch=%s\n", + width, xsimd::default_arch::name()); + } + return ok ? 0 : 1; +}