Skip to content

Allow safely creating SIMD level tokens from #[target_feature] functions - #293

Merged
Shnatsel merged 7 commits into
linebender:mainfrom
Shnatsel:safe-token-from-target-feature-functions
Aug 2, 2026
Merged

Allow safely creating SIMD level tokens from #[target_feature] functions#293
Shnatsel merged 7 commits into
linebender:mainfrom
Shnatsel:safe-token-from-target-feature-functions

Conversation

@Shnatsel

Copy link
Copy Markdown
Contributor

An updated version of #223

Also adds tests that verify that tokens can be safely made inside kernel! macros to verify that the target_feature annotations match.

@Shnatsel
Shnatsel requested a review from DJMcNab July 29, 2026 15:52

@DJMcNab DJMcNab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! It's good to see it taken over with better results - the tests are a fantastic idea. I don't think its possible to test the other way around though, right?

I'm not overly happy with the name new_unchecked for the methods, but it doesn't block.

Comment thread fearless_simd/src/generated/avx2.rs Outdated
#[inline]
pub const unsafe fn new_unchecked() -> Self {
#[target_feature(enable = "avx2,bmi1,bmi2,cmpxchg16b,f16c,fma,fxsr,lzcnt,movbe,popcnt,xsave")]
pub const fn new_unchecked() -> Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the name still need to be new_unchecked?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not thrilled about new_unchecked() either. Simply new() feels too low-hanging, doesn't communicate it's not very commonly used, but we have the docs pointing to Level::new() so it should be fine? We could also call it assume_supported().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed the function to assume_supported() after sleeping on it for a few days.

@Shnatsel
Shnatsel enabled auto-merge August 2, 2026 21:46
@Shnatsel
Shnatsel added this pull request to the merge queue Aug 2, 2026
Merged via the queue into linebender:main with commit b053706 Aug 2, 2026
22 checks passed
@Shnatsel
Shnatsel deleted the safe-token-from-target-feature-functions branch August 2, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants