-
Notifications
You must be signed in to change notification settings - Fork 223
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
Port over relevant changes from bigint #25
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9609d2e
Remove asm and port over performance improvements from `bigint`
dvdplm 16012b3
Add benchmark
dvdplm ae247ae
Port over no_std formatting and use rustc_hex 2.0 to make tests pass …
dvdplm 13d7356
Run uint no_std tests
dvdplm 3356726
Use rustc-hex without default features
dvdplm 4336907
move display/debug funtionality back to `std`-gated macro
dvdplm 2af9e11
don't run tests with --no-default-features
dvdplm 1262de4
Try `travis_wait` to fix timeouts
dvdplm 78cf6e7
Debug travis
dvdplm b49e0ed
debug travis (attempt 3)
dvdplm 85ba498
Try with absurdly long wait time: 400min (attempt 4)
dvdplm 97ecf17
Export U256 and U512
dvdplm d3c335e
Add impl to converto from U256 to [u8; 32]
dvdplm 1906259
Put original travis config back
dvdplm b4b5c6f
Fix repo meta-data key
dvdplm 9261b85
Move conversion inside macro
dvdplm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Big unsigned integer types | ||
|
||
Implementation of a various large-but-fixed sized unsigned integer types. | ||
The functions here are designed to be fast. There are optional `x86_64` | ||
implementations for even more speed, hidden behind the `x64_arithmetic` | ||
feature flag. | ||
The functions here are designed to be fast. | ||
|
||
The crate exports two commonly used types: `U256` and `U512`. Other sizes can be constructed with `construct_uint!(NAME, SIZE_IN_WORDS)`, e.g. `construct_uint!(U128, 2);`. | ||
|
||
Run tests with `cargo test --features=std,impl_quickcheck_arbitrary`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
// Copyright 2015-2017 Parity Technologies | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! benchmarking for bigint | ||
//! should be started with: | ||
//! ```bash | ||
//! rustup run nightly cargo bench | ||
//! ``` | ||
|
||
#![feature(test)] | ||
|
||
extern crate core; | ||
extern crate test; | ||
#[macro_use] | ||
extern crate crunchy; | ||
#[macro_use] | ||
extern crate uint; | ||
construct_uint!(U128, 2); | ||
construct_uint!(U256, 4); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the exported types here? Apparently, creating the types here influences the benchmark results. |
||
construct_uint!(U512, 8); | ||
|
||
use test::{Bencher, black_box}; | ||
|
||
impl U256 { | ||
/// Multiplies two 256-bit integers to produce full 512-bit integer | ||
/// No overflow possible | ||
#[inline(always)] | ||
pub fn full_mul(self, other: U256) -> U512 { | ||
U512(uint_full_mul_reg!(U256, 4, self, other)) | ||
} | ||
} | ||
|
||
#[bench] | ||
fn u256_add(b: &mut Bencher) { | ||
b.iter(|| { | ||
let n = black_box(10000); | ||
let zero = black_box(U256::zero()); | ||
(0..n).fold(zero, |old, new| { | ||
old.overflowing_add(U256::from(black_box(new))).0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u256_sub(b: &mut Bencher) { | ||
b.iter(|| { | ||
let n = black_box(10000); | ||
let max = black_box(U256::max_value()); | ||
(0..n).fold(max, |old, new| { | ||
old.overflowing_sub(U256::from(black_box(new))).0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u512_sub(b: &mut Bencher) { | ||
b.iter(|| { | ||
let n = black_box(10000); | ||
let max = black_box(U512::max_value()); | ||
(0..n).fold(max, |old, new| { | ||
let new = black_box(new); | ||
let p = new % 2; | ||
old.overflowing_sub(U512([p, p, p, p, p, p, p, new])).0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u512_add(b: &mut Bencher) { | ||
b.iter(|| { | ||
let n = black_box(10000); | ||
let zero = black_box(U512::zero()); | ||
(0..n).fold(zero, |old, new| { | ||
let new = black_box(new); | ||
old.overflowing_add(U512([new, new, new, new, new, new, new, new])) | ||
.0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u512_mul(b: &mut Bencher) { | ||
b.iter(|| { | ||
(1..10000).fold(black_box(U512::one()), |old, new| { | ||
old.overflowing_mul(U512::from(black_box(new | 1))).0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u512_mul_small(b: &mut Bencher) { | ||
b.iter(|| { | ||
(1..153).fold(black_box(U512::one()), |old, _| { | ||
old.overflowing_mul(U512::from(black_box(10))).0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u256_mul(b: &mut Bencher) { | ||
b.iter(|| { | ||
(1..10000).fold(black_box(U256::one()), |old, new| { | ||
old.overflowing_mul(U256::from(black_box(new | 1))).0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u256_mul_small(b: &mut Bencher) { | ||
b.iter(|| { | ||
(1..77).fold(black_box(U256::one()), |old, _| { | ||
old.overflowing_mul(U256::from(black_box(10))).0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u256_full_mul(b: &mut Bencher) { | ||
b.iter(|| { | ||
let n = black_box(10000); | ||
let one = black_box(U256::one()); | ||
(1..n).map(|n| n | 1).fold(one, |old, new| { | ||
let new = black_box(new); | ||
let U512(ref u512words) = old.full_mul(U256([new, new, new, new])); | ||
U256([u512words[0], u512words[2], u512words[2], u512words[3]]) | ||
}) | ||
}); | ||
} | ||
|
||
|
||
#[bench] | ||
fn u128_mul(b: &mut Bencher) { | ||
b.iter(|| { | ||
let n = black_box(10000); | ||
(1..n).fold(U128([12345u64, 0u64]), |old, new| { | ||
old.overflowing_mul(U128::from(new | 1)).0 | ||
}) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u256_from_le(b: &mut Bencher) { | ||
b.iter(|| { | ||
let raw = black_box( | ||
[ | ||
1u8, | ||
2, | ||
3, | ||
5, | ||
7, | ||
11, | ||
13, | ||
17, | ||
19, | ||
23, | ||
29, | ||
31, | ||
37, | ||
41, | ||
43, | ||
47, | ||
53, | ||
59, | ||
61, | ||
67, | ||
71, | ||
73, | ||
79, | ||
83, | ||
89, | ||
97, | ||
101, | ||
103, | ||
107, | ||
109, | ||
113, | ||
127, | ||
], | ||
); | ||
let _ = U256::from_little_endian(&raw[..]); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn u256_from_be(b: &mut Bencher) { | ||
b.iter(|| { | ||
let raw = black_box( | ||
[ | ||
1u8, | ||
2, | ||
3, | ||
5, | ||
7, | ||
11, | ||
13, | ||
17, | ||
19, | ||
23, | ||
29, | ||
31, | ||
37, | ||
41, | ||
43, | ||
47, | ||
53, | ||
59, | ||
61, | ||
67, | ||
71, | ||
73, | ||
79, | ||
83, | ||
89, | ||
97, | ||
101, | ||
103, | ||
107, | ||
109, | ||
113, | ||
127, | ||
], | ||
); | ||
let _ = U256::from_big_endian(&raw[..]); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline before macro invocation?