Skip to content

Commit 4369be9

Browse files
authored
Add x86_64 asm codegen for PrimeField mul and square (#176)
2 parents 11c02ed + a52841d commit 4369be9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1898
-3851
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Informally, the library provides the ability to create transactions that run arb
3131

3232
This repository contains several Rust crates that implement the different building blocks of ZEXE. The high-level structure of the repository is as follows.
3333

34-
* [`algebra`](algebra): Rust crate that provides finite fields and elliptic curves
34+
* [`algebra-core`](algebra-core): Rust crate that provides generic arithmetic for finite fields and elliptic curves
35+
* [`algebra`](algebra): Rust crate that provides concrete instantiations of some finite fields and elliptic curves
3536
* [`crypto-primitives`](crypto-primitives): Rust crate that implements some useful cryptographic primitives (and constraints for them)
3637
* [`dpc`](dpc): Rust crate that implements DPC schemes (the main cryptographic primitive in this repository)
3738
* [`ff-fft`](ff-fft): Rust crate that provides efficient finite field polynomial arithmetic based on finite field FFTs
@@ -64,9 +65,9 @@ cargo build --release
6465
This library comes with unit tests for each of the provided crates. Run the tests with:
6566
```bash
6667
cargo test
67-
```
68+
```
6869

69-
Lastly, this library comes with benchmarks for the following crates:
70+
This library comes with benchmarks for the following crates:
7071

7172
- [`algebra`](algebra)
7273
- [`dpc`](dpc)
@@ -76,6 +77,18 @@ These benchmarks require the nightly Rust toolchain; to install this, run `rustu
7677
cargo +nightly bench
7778
```
7879

80+
Compiling with `adcxq`, `adoxq` and `mulxq` instructions can lead to a 30-70% speedup. These are available on most `x86_64` platforms (Broadwell onwards for Intel and Ryzen onwards for AMD). Run the following command:
81+
```bash
82+
RUSTFLAGS="-C target-feature=+bmi2,+adx" cargo +nightly test/build/bench --features asm
83+
```
84+
Tip: If optimising for performance, your mileage may vary with passing `--emit=asm` to `RUSTFLAGS`.
85+
86+
To bench `algebra-benches` with greater accuracy, especially for functions with execution times on the order of nanoseconds, use the `n_fold` feature to run selected functions 1000x per iteration. To run with multiple features, make sure to double quote the features.
87+
```bash
88+
cargo +nightly bench --features "n_fold bls12_381"
89+
```
90+
91+
7992
## License
8093

8194
ZEXE is licensed under either of the following licenses, at your discretion.

algebra-benches/Cargo.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,27 @@ include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
1919
license = "MIT/Apache-2.0"
2020
edition = "2018"
2121
publish = false
22+
build = "build.rs"
2223

2324
################################# Dependencies ################################
2425

2526
[dev-dependencies]
26-
algebra = { path = "../algebra", features = [ "full" ] }
27+
algebra = { path = "../algebra" }
2728
blake2 = "0.8.1"
2829
rand = "0.7"
2930
rand_xorshift = { version = "0.2" }
31+
paste = "0.1"
32+
33+
[features]
34+
asm = [ "algebra/asm"]
35+
n_fold = []
36+
mnt4_298 = [ "algebra/mnt4_298"]
37+
mnt6_298 = [ "algebra/mnt6_298"]
38+
mnt4_753 = [ "algebra/mnt4_753"]
39+
mnt6_753 = [ "algebra/mnt6_753"]
40+
bls12_381 = [ "algebra/bls12_381"]
41+
bls12_377 = [ "algebra/bls12_377"]
42+
sw6 = [ "algebra/sw6" ]
43+
44+
[build-dependencies]
45+
rustc_version = "0.1.*"

algebra-benches/benches/bls12_377/ec.rs

Lines changed: 0 additions & 183 deletions
This file was deleted.

0 commit comments

Comments
 (0)