Skip to content

Commit dbcd0a6

Browse files
authored
add xsimd (#549)
1 parent 0694bbf commit dbcd0a6

5 files changed

Lines changed: 210 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Add xsimd 14.3.0 as compat.xsimd
2+
3+
## Source and shape
4+
5+
- Upstream: <https://github.com/xtensor-stack/xsimd>.
6+
- Version: `14.3.0`, the newest stable tag observed with
7+
`git ls-remote --tags --refs`.
8+
- License: BSD-3-Clause.
9+
- Shape: Form B, header-only. Upstream's CMake INTERFACE target exposes
10+
`include/`, where consumers find `<xsimd/xsimd.hpp>`. The package therefore
11+
uses `include_dirs = { "*/include" }` and a trivial anchor C TU to provide a
12+
buildable `xsimd` lib target.
13+
- No features: xsimd has no optional compilable library component. The
14+
optional `xtl::xcomplex` integration is an external dependency plus the
15+
consumer's `XSIMD_ENABLE_XTL_COMPLEX` define, which a sources-only feature
16+
cannot express.
17+
18+
Upstream requires C++14. The descriptor compiles its own anchor as C++; the
19+
consumer test uses the workspace default C++23 mode and a direct smoke test
20+
also verifies that the public header compiles in C++14 mode.
21+
22+
## Download and mirror
23+
24+
- GLOBAL:
25+
`https://github.com/xtensor-stack/xsimd/archive/refs/tags/14.3.0.tar.gz`
26+
- SHA-256:
27+
`b3d50e7a73fbf4642ceef30131c93414901d69eee41c2a5302db650b03e2c792`
28+
- The archive was downloaded twice and compared byte-for-byte; both copies had
29+
the same digest.
30+
- No verified `mcpp-res/xsimd` release is available, so the descriptor uses the
31+
upstream plain-string URL fallback rather than inventing a CN resource.
32+
33+
## Automatic updates
34+
35+
The package meets the automatic-update criteria: it has GitHub numeric tags,
36+
stable archive URLs, identical resources on all declared platforms, and future
37+
versions do not require a build-recipe change. `extensions.autoupdate` uses the
38+
unprefixed `${version}` tag spelling and the GitHub tag-archive URL template.
39+
The initial URL and SHA-256 live once in the `versions` table and all three
40+
platforms reference that entry.
41+
42+
## Test member
43+
44+
`tests/examples/xsimd/` is registered in the root workspace. It asserts:
45+
46+
- the selected default architecture is supported and available;
47+
- runtime architecture discovery contains the default architecture;
48+
- unaligned load, batch addition and unaligned store preserve every lane;
49+
- batch square root and horizontal reduction return the expected scalar.
50+
51+
Every assertion affects the process exit status (`return ok ? 0 : 1`).
52+
53+
## Verification
54+
55+
- Pinned mcpp `2026.10.1.2`:
56+
`mcpp xpkg parse --all-os pkgs/c/compat.xsimd.lua` reports `parse OK` for
57+
linux, macosx, and windows.
58+
- Pinned cold GCC run:
59+
`mcpp test -p xsimd --cache off` reports
60+
`test result ok. 1 passed; 0 failed`, running
61+
`xsimd OK width=4 arch=sse2`.
62+
- Pinned cold LLVM run:
63+
`mcpp test -p xsimd --toolchain llvm@22.1.8 --cache off` reports the same
64+
successful test with Clang.
65+
- The public header and test compile and run directly under both C++14 and
66+
C++23 (GCC 16.2.1), covering xsimd's documented language floor.
67+
- Full relevant lint passed: Lua syntax, mirror URL policy, package identity,
68+
reserved namespaces, cross-package references, platform parity, and
69+
duplicate versions. All 255 descriptors parse with the pinned mcpp.
70+
- The pinned updater's 11 repository tests pass. Its declaration coverage audit
71+
reports `All 83 GitHub-direct descriptors declared; all existing versions
72+
unchanged`, including `compat:xsimd`.
73+
- `xpkgindex_update inspect --package compat:xsimd` accepts the declaration and
74+
reports the three platform URLs plus the automatic-update template.
75+
- `xpkgindex_update check --package compat:xsimd` reports
76+
`status = "up-to-date"`, current version `14.3.0`, discovery by upstream
77+
tags. An earlier attempt hit the unauthenticated GitHub API rate limit; the
78+
check passed after the documented reset window.

‎mcpp.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ members = [
172172
"tests/examples/websocket-features",
173173
"tests/examples/websocket-tls",
174174
"tests/examples/tray",
175+
"tests/examples/xsimd",
175176
"tests/examples/xxhash",
176177
"tests/examples/yaml-cpp",
177178
"tests/examples/yaml-cpp-v080",

‎pkgs/c/compat.xsimd.lua‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
local versions = {
2+
["14.3.0"] = {
3+
url = "https://github.com/xtensor-stack/xsimd/archive/refs/tags/14.3.0.tar.gz",
4+
sha256 = "b3d50e7a73fbf4642ceef30131c93414901d69eee41c2a5302db650b03e2c792",
5+
},
6+
}
7+
8+
-- Form B inline descriptor for xsimd — C++ wrappers over SIMD intrinsics.
9+
--
10+
-- HEADER-ONLY: upstream's CMake target exposes exactly `include/`, where
11+
-- consumers find `<xsimd/xsimd.hpp>`. Tests, examples, benchmarks and docs
12+
-- stay outside the include path. A trivial anchor TU gives mcpp a buildable
13+
-- `xsimd` lib target, following compat.gtl / compat.safeint.
14+
--
15+
-- LANGUAGE FLOOR: xsimd requires C++14 (`target_compile_features` says
16+
-- `cxx_std_14`). The package's own anchor is compiled as C++; consumers may
17+
-- use any C++14-or-newer language mode supported by their toolchain.
18+
--
19+
-- No features: xsimd is header-only and has no optional compilable library
20+
-- component. Its optional `xtl::xcomplex` integration is controlled by the
21+
-- consumer's XSIMD_ENABLE_XTL_COMPLEX define and an external xtl dependency,
22+
-- so a sources-only feature cannot represent it and is deliberately omitted.
23+
--
24+
-- No verified mcpp-res mirror is available, so the upstream URL is a plain
25+
-- string rather than a fabricated GLOBAL/CN resource table.
26+
package = {
27+
spec = "1",
28+
namespace = "compat",
29+
name = "xsimd",
30+
description = "C++ wrappers for SIMD intrinsics with runtime architecture selection (header-only)",
31+
licenses = {"BSD-3-Clause"},
32+
repo = "https://github.com/xtensor-stack/xsimd",
33+
type = "package",
34+
35+
extensions = {
36+
autoupdate = {
37+
tag = "${version}",
38+
url = "https://github.com/xtensor-stack/xsimd/archive/refs/tags/${tag}.tar.gz",
39+
},
40+
},
41+
42+
xpm = {
43+
linux = {
44+
["14.3.0"] = versions["14.3.0"],
45+
},
46+
macosx = {
47+
["14.3.0"] = versions["14.3.0"],
48+
},
49+
windows = {
50+
["14.3.0"] = versions["14.3.0"],
51+
},
52+
},
53+
54+
mcpp = {
55+
language = "c++23",
56+
import_std = false,
57+
c_standard = "c11",
58+
include_dirs = { "*/include" },
59+
generated_files = {
60+
["mcpp_generated/xsimd_anchor.c"] = [==[
61+
int mcpp_compat_xsimd_headers_anchor(void) { return 0; }
62+
]==],
63+
},
64+
sources = { "mcpp_generated/xsimd_anchor.c" },
65+
targets = { ["xsimd"] = { kind = "lib" } },
66+
deps = { },
67+
},
68+
}

‎tests/examples/xsimd/mcpp.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# xsimd test project: exercise the default architecture selected from the
2+
# consumer's compiler flags, plus load/store and useful batch operations.
3+
[package]
4+
name = "xsimd-tests"
5+
version = "0.1.0"
6+
7+
[dependencies.compat]
8+
xsimd = "14.3.0"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// compat.xsimd — assert architecture discovery, unaligned load/store, batch
2+
// arithmetic, math functions and horizontal reduction through the public API.
3+
#include <xsimd/xsimd.hpp>
4+
5+
#include <array>
6+
#include <cmath>
7+
#include <cstddef>
8+
#include <cstdio>
9+
10+
int main() {
11+
using batch_type = xsimd::batch<float>;
12+
constexpr std::size_t width = batch_type::size;
13+
14+
std::array<float, width> left{};
15+
std::array<float, width> right{};
16+
std::array<float, width> sum{};
17+
for (std::size_t i = 0; i < width; ++i) {
18+
left[i] = static_cast<float>(i + 1);
19+
right[i] = static_cast<float>(2 * i + 2);
20+
}
21+
22+
bool ok = true;
23+
auto check = [&](bool condition, const char* what) {
24+
if (!condition) {
25+
std::printf("FAIL: %s\n", what);
26+
ok = false;
27+
}
28+
};
29+
30+
check(xsimd::default_arch::supported(),
31+
"default architecture is supported by the compiler");
32+
check(xsimd::default_arch::available(),
33+
"default architecture is available on this CPU");
34+
check(xsimd::available_architectures().has(xsimd::default_arch{}),
35+
"runtime discovery includes the default architecture");
36+
37+
auto lhs = xsimd::load_unaligned(left.data());
38+
auto rhs = xsimd::load_unaligned(right.data());
39+
xsimd::store_unaligned(sum.data(), lhs + rhs);
40+
for (std::size_t i = 0; i < width; ++i) {
41+
check(sum[i] == left[i] + right[i],
42+
"unaligned load, batch addition and store");
43+
}
44+
45+
auto square_roots = xsimd::sqrt(lhs * lhs);
46+
const float expected = static_cast<float>(width * (width + 1) / 2);
47+
check(std::fabs(xsimd::reduce_add(square_roots) - expected) < 0.001f,
48+
"batch math and horizontal reduction");
49+
50+
if (ok) {
51+
std::printf("xsimd OK width=%zu arch=%s\n",
52+
width, xsimd::default_arch::name());
53+
}
54+
return ok ? 0 : 1;
55+
}

0 commit comments

Comments
 (0)