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

Support SIMD on Rust stable #520

Merged
merged 24 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9312a13
Remove dependency on `packed_simd`
koute Mar 21, 2023
bd32f0b
Support SIMD on stable Rust
koute Mar 21, 2023
7343254
Move `packed_simd.rs` to `vector` module
koute Mar 21, 2023
1761028
Add comment header to `packed_simd.rs`
koute Mar 21, 2023
94035c5
Initialize SIMD registers using intrinsics instead of `transmute`
koute Mar 21, 2023
bccad56
Use a splat inside of `unpack_pair`
koute Mar 21, 2023
0db286b
Add `#[allow(dead_code)]`s
koute Mar 21, 2023
d0a3709
Replace `unwrap` with `expect` in build.rs to make Clippy happy
koute Mar 21, 2023
a448528
Allow missing docs for the `packed_simd` module
koute Mar 21, 2023
94aee21
Document the `PartialEq` impl for the SIMD wrapper types
koute Mar 28, 2023
7393812
Remove the `IntoBits` trait
koute Mar 28, 2023
5f1f887
Remove the `i32x8` wrapper type
koute Mar 28, 2023
590f20e
Add a wrapper method for `_mm256_mul_epu32`
koute Mar 28, 2023
70f6b69
Add extra doc comments
koute Mar 28, 2023
69dbacf
Added docs on why signed/unsigned arithmetic conversion is OK
rozbb Mar 29, 2023
ad56e1f
Update README: the AVX2 backend now works on stable Rust
koute Mar 29, 2023
6288388
Add a CI job to also build the AVX2 SIMD backend on Rust stable
koute Mar 29, 2023
f5e2d2e
Actually run the tests for the AVX2 SIMD backend on CI
koute Mar 29, 2023
4bfe9ce
Added SIMD MSRV test; docs
rozbb Mar 30, 2023
cada35f
Fixed yaml
rozbb Mar 30, 2023
fa52eaf
Fixed yaml again
rozbb Mar 30, 2023
07e5b8d
CI wibble
rozbb Mar 30, 2023
60ce89a
Put AVX2 build in MSRV test
rozbb Mar 30, 2023
6b676d4
Added comment
rozbb Mar 30, 2023
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
16 changes: 15 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- run: cargo build --target thumbv7em-none-eabi --release
- run: cargo build --target thumbv7em-none-eabi --release --features serde

build-simd:
build-simd-nightly:
name: Build simd backend (nightly)
runs-on: ubuntu-latest
steps:
Expand All @@ -69,6 +69,16 @@ jobs:
RUSTFLAGS: '--cfg curve25519_dalek_backend="simd" -C target_feature=+avx512ifma'
run: cargo build --target x86_64-unknown-linux-gnu

test-simd-avx2:
name: Test simd backend (avx2)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- env:
RUSTFLAGS: '--cfg curve25519_dalek_backend="simd" -C target_feature=+avx2'
run: cargo test --target x86_64-unknown-linux-gnu

build-docs:
name: Build docs
runs-on: ubuntu-latest
Expand Down Expand Up @@ -151,6 +161,10 @@ jobs:
# deps and the stated MSRV
- uses: dtolnay/rust-toolchain@1.60.0
- run: cargo build --no-default-features --features serde
# Also make sure the AVX2 build works
- env:
RUSTFLAGS: '--cfg curve25519_dalek_backend="simd" -C target_feature=+avx2'
run: cargo build --target x86_64-unknown-linux-gnu

bench:
name: Check that benchmarks compile
Expand Down
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ rand_core = { version = "0.6", default-features = false, features = ["getrandom"

[build-dependencies]
platforms = "3.0.2"
rustc_version = "0.4.0"

[[bench]]
name = "dalek_benchmarks"
Expand All @@ -57,11 +58,6 @@ zeroize = { version = "1", default-features = false, optional = true }
[target.'cfg(curve25519_dalek_backend = "fiat")'.dependencies]
fiat-crypto = "0.1.19"

# The original packed_simd package was orphaned, see
# https://github.com/rust-lang/packed_simd/issues/303#issuecomment-701361161
[target.'cfg(curve25519_dalek_backend = "simd")'.dependencies]
packed_simd = { version = "0.3.8", package = "packed_simd_2", features = ["into_bits"] }

[features]
default = ["alloc", "precomputed-tables", "zeroize"]
alloc = ["zeroize?/alloc"]
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ $ cargo build --target i686-unknown-linux-gnu
Target backend selection within `simd` must be done manually by setting the
`RUSTFLAGS` environment variable to one of the below options:

| CPU feature | `RUSTFLAGS` |
| :--- | :--- |
| avx2 | `-C target_feature=+avx2` |
| avx512ifma | `-C target_feature=+avx512ifma` |
| CPU feature | `RUSTFLAGS` | Requires nightly? |
| :--- | :--- | :--- |
| avx2 | `-C target_feature=+avx2` | no |
| avx512ifma | `-C target_feature=+avx512ifma` | yes |

Or you can use `-C target_cpu=native` if you don't know what to set.

The `simd` backend also requires using nightly, e.g. by running `cargo
+nightly build`, to build.
The AVX512 backend requires Rust nightly. If enabled and when compiled on a non-nightly
compiler it will fall back to using the AVX2 backend.

# Documentation

Expand Down
8 changes: 8 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ fn main() {
DalekBits::Dalek64 => println!("cargo:rustc-cfg=curve25519_dalek_bits=\"64\""),
DalekBits::Dalek32 => println!("cargo:rustc-cfg=curve25519_dalek_bits=\"32\""),
}

if rustc_version::version_meta()
.expect("failed to detect rustc version")
.channel
== rustc_version::Channel::Nightly
{
println!("cargo:rustc-cfg=nightly");
}
}

// Deterministic cfg(curve25519_dalek_bits) when this is not explicitly set.
Expand Down
Loading