Skip to content

Commit

Permalink
Merge pull request #1735 from ehuss/avx-example
Browse files Browse the repository at this point in the history
Switch from AVX to SSE in the example
  • Loading branch information
ehuss authored Feb 18, 2025
2 parents 708f07f + 639712d commit b4f049d
Showing 1 changed file with 15 additions and 15 deletions.
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

0 comments on commit b4f049d

Please sign in to comment.