Skip to content

Commit

Permalink
Auto merge of #82 - str4d:read-write-le, r=ebfull
Browse files Browse the repository at this point in the history
Add read_le and write_le to PrimeFieldRepr
  • Loading branch information
bmerge committed May 17, 2018
2 parents dbe897d + da5f1d3 commit 09b6e6f
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 182 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "pairing"

# Remember to change version string in README.md.
version = "0.14.1"
version = "0.14.2"
authors = ["Sean Bowe <[email protected]>"]
license = "MIT/Apache-2.0"

Expand All @@ -14,7 +14,7 @@ repository = "https://github.com/ebfull/pairing"
[dependencies]
rand = "0.4"
byteorder = "1"
clippy = { version = "0.0.190", optional = true }
clippy = { version = "0.0.200", optional = true }

[features]
unstable-features = ["expose-arith"]
Expand Down
28 changes: 20 additions & 8 deletions benches/bls12_381/ec.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
mod g1 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::CurveProjective;
use pairing::bls12_381::*;
use pairing::CurveProjective;

#[bench]
fn bench_g1_mul_assign(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(G1, Fr)> = (0..SAMPLES).map(|_| (G1::rand(&mut rng), Fr::rand(&mut rng))).collect();
let v: Vec<(G1, Fr)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), Fr::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -27,7 +29,9 @@ mod g1 {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(G1, G1)> = (0..SAMPLES).map(|_| (G1::rand(&mut rng), G1::rand(&mut rng))).collect();
let v: Vec<(G1, G1)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), G1::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -44,7 +48,9 @@ mod g1 {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(G1, G1Affine)> = (0..SAMPLES).map(|_| (G1::rand(&mut rng), G1::rand(&mut rng).into())).collect();
let v: Vec<(G1, G1Affine)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), G1::rand(&mut rng).into()))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -59,16 +65,18 @@ mod g1 {
mod g2 {
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::CurveProjective;
use pairing::bls12_381::*;
use pairing::CurveProjective;

#[bench]
fn bench_g2_mul_assign(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(G2, Fr)> = (0..SAMPLES).map(|_| (G2::rand(&mut rng), Fr::rand(&mut rng))).collect();
let v: Vec<(G2, Fr)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), Fr::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -85,7 +93,9 @@ mod g2 {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(G2, G2)> = (0..SAMPLES).map(|_| (G2::rand(&mut rng), G2::rand(&mut rng))).collect();
let v: Vec<(G2, G2)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), G2::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -102,7 +112,9 @@ mod g2 {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(G2, G2Affine)> = (0..SAMPLES).map(|_| (G2::rand(&mut rng), G2::rand(&mut rng).into())).collect();
let v: Vec<(G2, G2Affine)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), G2::rand(&mut rng).into()))
.collect();

let mut count = 0;
b.iter(|| {
Expand Down
80 changes: 45 additions & 35 deletions benches/bls12_381/fq.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::{Field, PrimeField, PrimeFieldRepr, SqrtField};
use pairing::bls12_381::*;
use pairing::{Field, PrimeField, PrimeFieldRepr, SqrtField};

#[bench]
fn bench_fq_repr_add_nocarry(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(FqRepr, FqRepr)> = (0..SAMPLES).map(|_| {
let mut tmp1 = FqRepr::rand(&mut rng);
let mut tmp2 = FqRepr::rand(&mut rng);
// Shave a few bits off to avoid overflow.
for _ in 0..3 {
tmp1.div2();
tmp2.div2();
}
(tmp1, tmp2)
}).collect();
let v: Vec<(FqRepr, FqRepr)> = (0..SAMPLES)
.map(|_| {
let mut tmp1 = FqRepr::rand(&mut rng);
let mut tmp2 = FqRepr::rand(&mut rng);
// Shave a few bits off to avoid overflow.
for _ in 0..3 {
tmp1.div2();
tmp2.div2();
}
(tmp1, tmp2)
})
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -35,15 +37,17 @@ fn bench_fq_repr_sub_noborrow(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(FqRepr, FqRepr)> = (0..SAMPLES).map(|_| {
let tmp1 = FqRepr::rand(&mut rng);
let mut tmp2 = tmp1;
// Ensure tmp2 is smaller than tmp1.
for _ in 0..10 {
tmp2.div2();
}
(tmp1, tmp2)
}).collect();
let v: Vec<(FqRepr, FqRepr)> = (0..SAMPLES)
.map(|_| {
let tmp1 = FqRepr::rand(&mut rng);
let mut tmp2 = tmp1;
// Ensure tmp2 is smaller than tmp1.
for _ in 0..10 {
tmp2.div2();
}
(tmp1, tmp2)
})
.collect();

let mut count = 0;
b.iter(|| {
Expand Down Expand Up @@ -110,7 +114,9 @@ fn bench_fq_add_assign(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(Fq, Fq)> = (0..SAMPLES).map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng))).collect();
let v: Vec<(Fq, Fq)> = (0..SAMPLES)
.map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -127,7 +133,9 @@ fn bench_fq_sub_assign(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(Fq, Fq)> = (0..SAMPLES).map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng))).collect();
let v: Vec<(Fq, Fq)> = (0..SAMPLES)
.map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -144,7 +152,9 @@ fn bench_fq_mul_assign(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(Fq, Fq)> = (0..SAMPLES).map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng))).collect();
let v: Vec<(Fq, Fq)> = (0..SAMPLES)
.map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand Down Expand Up @@ -206,15 +216,17 @@ fn bench_fq_negate(b: &mut ::test::Bencher) {

#[bench]
fn bench_fq_sqrt(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;
const SAMPLES: usize = 1000;

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<Fq> = (0..SAMPLES).map(|_| {
let mut tmp = Fq::rand(&mut rng);
tmp.square();
tmp
}).collect();
let v: Vec<Fq> = (0..SAMPLES)
.map(|_| {
let mut tmp = Fq::rand(&mut rng);
tmp.square();
tmp
})
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -229,9 +241,7 @@ fn bench_fq_into_repr(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<Fq> = (0..SAMPLES).map(|_| {
Fq::rand(&mut rng)
}).collect();
let v: Vec<Fq> = (0..SAMPLES).map(|_| Fq::rand(&mut rng)).collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -246,9 +256,9 @@ fn bench_fq_from_repr(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<FqRepr> = (0..SAMPLES).map(|_| {
Fq::rand(&mut rng).into_repr()
}).collect();
let v: Vec<FqRepr> = (0..SAMPLES)
.map(|_| Fq::rand(&mut rng).into_repr())
.collect();

let mut count = 0;
b.iter(|| {
Expand Down
28 changes: 12 additions & 16 deletions benches/bls12_381/fq12.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use rand::{Rand, SeedableRng, XorShiftRng};

use pairing::Field;
use pairing::bls12_381::*;
use pairing::Field;

#[bench]
fn bench_fq12_add_assign(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(Fq12, Fq12)> = (0..SAMPLES).map(|_| {
(Fq12::rand(&mut rng), Fq12::rand(&mut rng))
}).collect();
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
.map(|_| (Fq12::rand(&mut rng), Fq12::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -28,9 +28,9 @@ fn bench_fq12_sub_assign(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(Fq12, Fq12)> = (0..SAMPLES).map(|_| {
(Fq12::rand(&mut rng), Fq12::rand(&mut rng))
}).collect();
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
.map(|_| (Fq12::rand(&mut rng), Fq12::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -47,9 +47,9 @@ fn bench_fq12_mul_assign(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<(Fq12, Fq12)> = (0..SAMPLES).map(|_| {
(Fq12::rand(&mut rng), Fq12::rand(&mut rng))
}).collect();
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
.map(|_| (Fq12::rand(&mut rng), Fq12::rand(&mut rng)))
.collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -66,9 +66,7 @@ fn bench_fq12_squaring(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<Fq12> = (0..SAMPLES).map(|_| {
Fq12::rand(&mut rng)
}).collect();
let v: Vec<Fq12> = (0..SAMPLES).map(|_| Fq12::rand(&mut rng)).collect();

let mut count = 0;
b.iter(|| {
Expand All @@ -85,9 +83,7 @@ fn bench_fq12_inverse(b: &mut ::test::Bencher) {

let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

let v: Vec<Fq12> = (0..SAMPLES).map(|_| {
Fq12::rand(&mut rng)
}).collect();
let v: Vec<Fq12> = (0..SAMPLES).map(|_| Fq12::rand(&mut rng)).collect();

let mut count = 0;
b.iter(|| {
Expand Down
Loading

0 comments on commit 09b6e6f

Please sign in to comment.