Skip to content

Commit

Permalink
add cfg statements to only build doctest on x86 (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
nategraf committed Oct 3, 2023
1 parent 0cd099a commit e6675c6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions curve25519-dalek-derive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ to build out more elaborate abstractions it starts to become painful to use.
}

struct AVX;
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
impl Backend for AVX {
#[target_feature(enable = "avx")]
unsafe fn sum(xs: &[u32]) -> u32 {
Expand All @@ -53,6 +54,7 @@ to build out more elaborate abstractions it starts to become painful to use.
}

struct AVX2;
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
impl Backend for AVX2 {
#[target_feature(enable = "avx2")]
unsafe fn sum(xs: &[u32]) -> u32 {
Expand Down Expand Up @@ -87,6 +89,7 @@ fn func() {}

```rust
// It works, but must be `unsafe`
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[target_feature(enable = "avx2")]
unsafe fn func() {}
```
Expand All @@ -95,6 +98,7 @@ unsafe fn func() {}
use curve25519_dalek_derive::unsafe_target_feature;

// No `unsafe` on the function itself!
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[unsafe_target_feature("avx2")]
fn func() {}
```
Expand All @@ -119,6 +123,7 @@ use curve25519_dalek_derive::unsafe_target_feature;

struct S;

# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[unsafe_target_feature("avx2")]
impl core::ops::Add for S {
type Output = S;
Expand All @@ -135,6 +140,7 @@ impl core::ops::Add for S {
```rust
use curve25519_dalek_derive::unsafe_target_feature_specialize;

# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[unsafe_target_feature_specialize("sse2", "avx2", conditional("avx512ifma", nightly))]
mod simd {
#[for_target_feature("sse2")]
Expand All @@ -149,6 +155,7 @@ mod simd {
pub fn func() { /* ... */ }
}

# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn entry_point() {
#[cfg(nightly)]
if std::is_x86_feature_detected!("avx512ifma") {
Expand Down

0 comments on commit e6675c6

Please sign in to comment.