# crypto.sha2: Use intrinsics for SHA-256 on x86-64 and AArch64 · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/10edb6d352173dfbc9962ce3db064384319e77f8)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 10edb6d352173dfbc9962ce3db064384319e77f8

Requested commit: 10edb6d352173dfbc9962ce3db064384319e77f8

Commit: 10edb6d352173dfbc9962ce3db064384319e77f8

Tree: 84b964d90c0488872a9ec56b856910aef82f3e2c

Author: Cody Tapscott

Committer: Cody Tapscott

## Message

```
crypto.sha2: Use intrinsics for SHA-256 on x86-64 and AArch64

There's probably plenty of room to optimize these further in the
future, but for the moment this gives ~3x improvement on Intel
x86-64 processors, ~5x on AMD, and ~10x on M1 Macs.

These extensions are very new - Most processors prior to 2020 do
not support them.

AVX-512 is a slightly older alternative that we could use on Intel
for a much bigger performance bump, but it's been fused off on
Intel's latest hybrid architectures and it relies on computing
independent SHA hashes in parallel. In contrast, these SHA intrinsics
provide the usual single-threaded, single-stream interface, and should
continue working on new processors.

AArch64 also has SHA-512 intrinsics that we could take advantage
of in the future

```

## Parents

- [c616141241047d6d6c811d43f644eb1b7d2b26ce](https://git.cafe/gitcafe/zig/commit/c616141241047d6d6c811d43f644eb1b7d2b26ce?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/10edb6d352173dfbc9962ce3db064384319e77f8?format=markdown)
