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

feat(sha2): use latest sha2-asm and enable M1 #261

Merged
merged 5 commits into from
May 5, 2021

Conversation

dignifiedquire
Copy link
Member

@dignifiedquire dignifiedquire commented May 4, 2021

Depends on RustCrypto/asm-hashes#35

Benchmarks on Mac Mini M1:

Soft

test bench1_10    ... bench:          40 ns/iter (+/- 0) = 250 MB/s
test bench2_100   ... bench:         390 ns/iter (+/- 1) = 256 MB/s
test bench3_1000  ... bench:       3,869 ns/iter (+/- 8) = 258 MB/s
test bench4_10000 ... bench:      38,662 ns/iter (+/- 175) = 258 MB/s

ASM

test bench1_10    ... bench:           6 ns/iter (+/- 0) = 1666 MB/s
test bench2_100   ... bench:          46 ns/iter (+/- 0) = 2173 MB/s
test bench3_1000  ... bench:         463 ns/iter (+/- 2) = 2159 MB/s
test bench4_10000 ... bench:       4,636 ns/iter (+/- 12) = 2157 MB/s

Cargo.toml Outdated Show resolved Hide resolved
#[cfg(target_os = "macos")]
#[inline(always)]
pub fn sha2_supported() -> bool {
// TODO: Verify this is true for all available chips.
Copy link
Member

@tarcieri tarcieri May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. See the discussion here:

RustCrypto/utils#378 (comment)

Perhaps leave a TODO to use the cpufeatures crate for this detection, once ARM support lands?

@tarcieri
Copy link
Member

tarcieri commented May 4, 2021

Confirm the tests pass on my M1 Mac Mini:

% cargo test --features asm
    Updating git repository `https://github.com/dignifiedquire/asm-hashes`
    Updating crates.io index
  Downloaded hex-literal v0.2.1
  Downloaded version_check v0.9.3
  Downloaded opaque-debug v0.3.0
  Downloaded cc v1.0.67
  Downloaded proc-macro-hack v0.5.19
  Downloaded digest v0.9.0
  Downloaded cfg-if v1.0.0
  Downloaded block-buffer v0.9.0
  Downloaded blobby v0.1.2
  Downloaded byteorder v1.4.3
  Downloaded generic-array v0.14.4
  Downloaded typenum v1.13.0
  Downloaded hex-literal-impl v0.2.2
  Downloaded 13 crates (227.5 KB) in 0.44s
   Compiling version_check v0.9.3
   Compiling typenum v1.13.0
   Compiling proc-macro-hack v0.5.19
   Compiling cc v1.0.67
   Compiling byteorder v1.4.3
   Compiling opaque-debug v0.3.0
   Compiling cfg-if v1.0.0
   Compiling blobby v0.1.2
   Compiling generic-array v0.14.4
   Compiling sha2-asm v0.6.0 (https://github.com/dignifiedquire/asm-hashes?branch=arm-m1#8f5a9eb1)
   Compiling hex-literal-impl v0.2.2
   Compiling block-buffer v0.9.0
   Compiling digest v0.9.0
   Compiling sha2 v0.9.3 (/Users/tony/src/hashes/sha2)
   Compiling hex-literal v0.2.1
    Finished test [optimized + debuginfo] target(s) in 1m 39s
     Running /Users/tony/src/hashes/target/debug/deps/sha2-be3e015d4c750ddb

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running /Users/tony/src/hashes/target/debug/deps/lib-208bf8ba67780be5

running 8 tests
test sha224_main ... ok
test sha512_224_main ... ok
test sha256_main ... ok
test sha512_256_main ... ok
test sha384_main ... ok
test sha512_main ... ok
test sha256_1million_a ... ok
test sha512_1million_a ... ok

test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

   Doc-tests sha2

running 1 test
test src/lib.rs - (line 22) ... ok

Edit: looks like they aren't passing on macOS/x86-64 in CI, though

@dignifiedquire
Copy link
Member Author

Benchmarks on Mac Mini M1:

Soft

test bench1_10    ... bench:          40 ns/iter (+/- 0) = 250 MB/s
test bench2_100   ... bench:         390 ns/iter (+/- 1) = 256 MB/s
test bench3_1000  ... bench:       3,869 ns/iter (+/- 8) = 258 MB/s
test bench4_10000 ... bench:      38,662 ns/iter (+/- 175) = 258 MB/s

ASM

test bench1_10    ... bench:           6 ns/iter (+/- 0) = 1666 MB/s
test bench2_100   ... bench:          46 ns/iter (+/- 0) = 2173 MB/s
test bench3_1000  ... bench:         463 ns/iter (+/- 2) = 2159 MB/s
test bench4_10000 ... bench:       4,636 ns/iter (+/- 12) = 2157 MB/s

Co-authored-by: Tony Arcieri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants