Add #[simd] macro - #347
Conversation
|
I think let's wait until linebender/vello#1853 has been merged and then we can try the ergonomics of using it there? |
…jects exactly one function boundary
…h the documented use case for vectorize(). Does not affect usage in dispatch!() which dispatches from non-target-feature context. The function itself was already trivial and under -O3 the optimizer would recognize it as trivial and inline it anyway, so adding a function boundary there didn't really work as intended, except under -Os.
…at it injects exactly one function boundary" This reverts commit ff8ee04.
|
Woudln't mind the #[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
if simd.level().as_neon().is_some() {
return inner_code(a, b, c);
}
simd.vectorize(
#[inline(always)]
move || inner_code(a, b, c);
}I believe it's somewhat exaggerated by taking enough arguments, in: #[target_feature(enable = "neon")]
fn vectorize_neon<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
unsafe { vectorize_neon(f) }
Wonder if there's some macro magic we could do in the |
|
And/or, maybe just special casing a few arguments, and doing an annoying |
…at it opens up an opportunity to spoof fearless_simd types, which would be unsound, move the unsafe blocks into a declarative macro inside fearless_simd so that the proc macro emits no unsafe code itself.
|
Ugh, turns out closure-captured arguments get put into a struct that then gets spilled to the stack. I've rewritten the macro to avoid that with Astra's assistance. The proc macro now also needs to refer to fearless_simd crate explicitly, and to avoid making it unsound by spoofing fearless_simd crate I had to move all the I think it's a reasonable split going forward, especially since all the level matching is now happening inside fearless_simd where it can all be updated in lockstep if/when we add new levels. Alternatively we can make renaming fearless_simd harder by using |
|
tests fail because There is no fuzzy matching functionality in |
…tput that changes between compiler versions
|
I've fixed the issues around The README.md is quite poor and needs to be rewritten, but I'll deal with that once the code settles down |
|
I feel a lot more confident in this code now that I've moved all the safety-critical bits into a straightforward and comprehensible declarative macro. Well, comprehensible by macro standards, anyway. |
My attempt at #338
I am not well-versed in proc macros. While the design of what the macro should expand into is mine, the implementation of the macro and thinking through various edge cases and handling them was largely delegated to Codex (GPT-5.6 Sol Ultra).
Codex summary of the changes
Implemented the standalone
#[simd]proc macro.Key pieces:
fearless_simd_macros0.1.0 with Syn 3.0.4 and no core dependency: implementation, documentation.token.vectorize(#[inline(always)] || { ... }), with no generated outer inline attribute.vectorizehelpers and removed the stale outlined-boundary documentation.Verification passed:
-D warnings.x86_64-unknown-noneno-std build.cargo-rdmeconsistency.git diff --check.Existing unrelated untracked workspace files were left untouched.
Before implementing the macro I investigated
vectorize()and found that it already gets inlined most of the time anyway. It doesn't work well as an inlining barrier, since the function that isn't annotated#[inline]is trival enough for the optimizer to always inline it anyway, even with a large closure body. So I reverted a separatevectorize_inline()which is recorded in commit history, and inlining can instead be controlled with annotation on the function callingvectorize(); the docs on it already show that usage in the example, the doc comment on vectorize() can probably be improved.The proc macro crate is separate from fearless_simd so it doesn't fall under the v1.0 guarantees. I expect to publish it in lockstep with v1.0, although we might ship pre-releases just to make sure it all works. The README points to git but should work with most versions no problem, just wouldn't have as much inlining annotations in
vectorize().