Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from AVX to SSE in the example #1735

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/attributes/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,30 @@ The following restrictions apply unless otherwise specified by the platform rule
Implicitly enabled features are included in this rule. For example an `sse2` function can call ones marked with `sse`.

```rust
# #[cfg(target_feature = "avx2")] {
#[target_feature(enable = "avx")]
fn foo_avx() {}
# #[cfg(target_feature = "sse2")] {
#[target_feature(enable = "sse")]
fn foo_sse() {}

fn bar() {
// Calling `foo_avx` here is unsafe, as we must ensure that AVX is
// available first, even if `avx` is enabled by default on the target
// Calling `foo_sse` here is unsafe, as we must ensure that SSE is
// available first, even if `sse` is enabled by default on the target
// platform or manually enabled as compiler flags.
unsafe {
foo_avx();
foo_sse();
}
}

#[target_feature(enable = "avx")]
fn bar_avx() {
// Calling `foo_avx` here is safe.
foo_avx();
|| foo_avx();
#[target_feature(enable = "sse")]
fn bar_sse() {
// Calling `foo_sse` here is safe.
foo_sse();
|| foo_sse();
}

#[target_feature(enable = "avx2")]
fn bar_avx2() {
// Calling `foo_avx` here is safe because `avx2` implies `avx`.
foo_avx();
#[target_feature(enable = "sse2")]
fn bar_sse2() {
// Calling `foo_sse` here is safe because `sse2` implies `sse`.
foo_sse();
}
# }
```
Expand Down