Skip to content

Commit 6217574

Browse files
authored
chacha20: Add full NEON backend. (#310)
Observed performance changes on an Apple M1 Air: ``` name chacha-soft ns/iter chacha-neon ns/iter diff ns/iter diff % speedup chacha12_bench1_16b 34 (470 MB/s) 28 (571 MB/s) -6 -17.65% x 1.21 chacha12_bench2_256b 477 (536 MB/s) 132 (1939 MB/s) -345 -72.33% x 3.61 chacha12_bench3_1kib 1,897 (539 MB/s) 503 (2035 MB/s) -1,394 -73.48% x 3.77 chacha12_bench4_16kib 30,811 (531 MB/s) 7,914 (2070 MB/s) -22,897 -74.31% x 3.89 chacha20_bench1_16b 51 (313 MB/s) 47 (340 MB/s) -4 -7.84% x 1.09 chacha20_bench2_256b 777 (329 MB/s) 212 (1207 MB/s) -565 -72.72% x 3.67 chacha20_bench3_1kib 3,088 (331 MB/s) 821 (1247 MB/s) -2,267 -73.41% x 3.76 chacha20_bench4_16kib 50,251 (326 MB/s) 13,001 (1260 MB/s) -37,250 -74.13% x 3.87 chacha8_bench1_16b 26 (615 MB/s) 19 (842 MB/s) -7 -26.92% x 1.37 chacha8_bench2_256b 335 (764 MB/s) 92 (2782 MB/s) -243 -72.54% x 3.64 chacha8_bench3_1kib 1,328 (771 MB/s) 344 (2976 MB/s) -984 -74.10% x 3.86 chacha8_bench4_16kib 21,184 (773 MB/s) 5,371 (3050 MB/s) -15,813 -74.65% x 3.94 ``` * chacha20: Gate NEON backend behind `neon` feature. * chacha20: Re-enable CI for NEON backend * chacha20: Update README to include `neon`
1 parent efa393e commit 6217574

File tree

6 files changed

+338
-597
lines changed

6 files changed

+338
-597
lines changed

.github/workflows/chacha20.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ jobs:
197197
rust: stable
198198

199199
# ARM64 with NEON backend
200-
#- target: aarch64-unknown-linux-gnu
201-
# rust: nightly
202-
# features: --features neon
200+
- target: aarch64-unknown-linux-gnu
201+
rust: stable
202+
features: --features neon
203203

204204
# PPC32
205205
- target: powerpc-unknown-linux-gnu

chacha20/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ hex-literal = "0.3.3"
3232
[features]
3333
std = ["cipher/std"]
3434
zeroize = ["cipher/zeroize"]
35+
neon = []
3536

3637
[package.metadata.docs.rs]
3738
all-features = true

chacha20/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ work on stable Rust with the following `RUSTFLAGS`:
3434
- `x86` / `x86_64`
3535
- `avx2`: (~1.4cpb) `-Ctarget-cpu=haswell -Ctarget-feature=+avx2`
3636
- `sse2`: (~2.5cpb) `-Ctarget-feature=+sse2` (on by default on x86 CPUs)
37+
- `aarch64`
38+
- `neon` (~2-3x faster than `soft`) requires Rust 1.61+ and the `neon` feature enabled
3739
- Portable
3840
- `soft`: (~5 cpb on x86/x86_64)
3941

@@ -76,8 +78,8 @@ done with a minor version bump.
7678

7779
Licensed under either of:
7880

79-
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
80-
* [MIT license](http://opensource.org/licenses/MIT)
81+
- [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
82+
- [MIT license](http://opensource.org/licenses/MIT)
8183

8284
at your option.
8385

chacha20/src/backends.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ cfg_if! {
1515
pub(crate) mod sse2;
1616
}
1717
}
18+
} else if #[cfg(all(feature = "neon", target_arch = "aarch64", target_feature = "neon"))] {
19+
pub(crate) mod neon;
1820
} else {
1921
pub(crate) mod soft;
2022
}

0 commit comments

Comments
 (0)