diff --git a/ethbloom/CHANGELOG.md b/ethbloom/CHANGELOG.md index f1da71a00..1edf138b9 100644 --- a/ethbloom/CHANGELOG.md +++ b/ethbloom/CHANGELOG.md @@ -1,10 +1,11 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) ## [0.8.1] - 2019-10-24 ### Dependencies diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 952f043c3..f9f9960fb 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -22,10 +22,9 @@ rand = "0.7.2" hex-literal = "0.2.1" [features] -default = ["std", "serialize", "libc", "rustc-hex"] +default = ["std", "serialize", "rustc-hex"] std = ["fixed-hash/std", "crunchy/std"] serialize = ["std", "impl-serde"] -libc = ["fixed-hash/libc"] rustc-hex = ["fixed-hash/rustc-hex"] [[bench]] diff --git a/fixed-hash/CHANGELOG.md b/fixed-hash/CHANGELOG.md index ae22eee7f..adf179a5e 100644 --- a/fixed-hash/CHANGELOG.md +++ b/fixed-hash/CHANGELOG.md @@ -1,14 +1,15 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) ## [0.5.2] - 2019-12-19 ### Fixed -- re-export `alloc` for both std and no-std to fix compilation (See [PR #268](https://github.com/paritytech/parity-common/pull/268)) +- re-export `alloc` for both std and no-std to fix compilation (See [PR #268](https://github.com/paritytech/parity-common/pull/268)) ## [0.5.1] - 2019-10-24 ### Dependencies diff --git a/fixed-hash/Cargo.toml b/fixed-hash/Cargo.toml index cc3d3f3a8..c12d35c57 100644 --- a/fixed-hash/Cargo.toml +++ b/fixed-hash/Cargo.toml @@ -22,12 +22,14 @@ static_assertions = "1.0.0" [dev-dependencies] rand_xorshift = "0.2.0" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] -libc = { version = "0.2.65", optional = true, default-features = false } +criterion = "0.3.0" [features] -default = ["std", "libc", "rand", "rustc-hex", "byteorder"] +default = ["std", "rand", "rustc-hex", "byteorder"] std = ["rustc-hex/std", "rand/std", "byteorder/std"] api-dummy = [] # Feature used by docs.rs to display documentation of hash types + +[[bench]] +name = "cmp" +harness = false diff --git a/fixed-hash/benches/cmp.rs b/fixed-hash/benches/cmp.rs new file mode 100644 index 000000000..fd8918006 --- /dev/null +++ b/fixed-hash/benches/cmp.rs @@ -0,0 +1,98 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Benchmarks for fixed-hash cmp implementation. + +use criterion::{black_box, Criterion, ParameterizedBenchmark}; +use criterion::{criterion_group, criterion_main}; + +use fixed_hash::construct_fixed_hash; + +construct_fixed_hash! { pub struct H256(32); } + +criterion_group!(cmp, eq_equal, eq_nonequal, compare,); +criterion_main!(cmp); + +fn eq_equal(c: &mut Criterion) { + c.bench( + "eq_equal", + ParameterizedBenchmark::new( + "", + |b, x| b.iter(|| black_box(x.eq(black_box(x)))), + vec![ + H256::zero(), + H256::repeat_byte(0xAA), + H256::from([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + H256([u8::max_value(); 32]), + ], + ), + ); +} + +fn eq_nonequal(c: &mut Criterion) { + c.bench( + "eq_nonequal", + ParameterizedBenchmark::new( + "", + |b, (x, y)| b.iter(|| black_box(x.eq(black_box(y)))), + vec![ + ( + H256::zero(), + H256::from([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + ]), + ), + (H256::repeat_byte(0xAA), H256::repeat_byte(0xA1)), + ( + H256::from([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + H256::from([ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + ), + ], + ), + ); +} + +fn compare(c: &mut Criterion) { + c.bench( + "compare", + ParameterizedBenchmark::new( + "", + |b, (x, y)| b.iter(|| black_box(x.cmp(black_box(y)))), + vec![ + ( + H256::zero(), + H256::from([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + ]), + ), + (H256::zero(), H256::zero()), + (H256::repeat_byte(0xAA), H256::repeat_byte(0xAA)), + (H256::repeat_byte(0xAA), H256::repeat_byte(0xA1)), + ( + H256::from([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDF, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + H256::from([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + ), + ], + ), + ); +} diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index ea2210076..adfb8a065 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -313,7 +313,7 @@ macro_rules! construct_fixed_hash { impl_byteorder_for_fixed_hash!($name); impl_rand_for_fixed_hash!($name); - impl_libc_for_fixed_hash!($name); + impl_cmp_for_fixed_hash!($name); impl_rustc_hex_for_fixed_hash!($name); impl_quickcheck_for_fixed_hash!($name); } @@ -527,17 +527,9 @@ macro_rules! impl_rand_for_fixed_hash { }; } -// Implementation for disabled libc crate support. -// -// # Note -// -// Feature guarded macro definitions instead of feature guarded impl blocks -// to work around the problems of introducing `libc` crate feature in -// a user crate. -#[cfg(not(all(feature = "libc", not(target_os = "unknown"))))] #[macro_export] #[doc(hidden)] -macro_rules! impl_libc_for_fixed_hash { +macro_rules! impl_cmp_for_fixed_hash { ( $name:ident ) => { impl $crate::core_::cmp::PartialEq for $name { #[inline] @@ -555,52 +547,6 @@ macro_rules! impl_libc_for_fixed_hash { }; } -// Implementation for enabled libc crate support. -// -// # Note -// -// Feature guarded macro definitions instead of feature guarded impl blocks -// to work around the problems of introducing `libc` crate feature in -// a user crate. -#[cfg(all(feature = "libc", not(target_os = "unknown")))] -#[macro_export] -#[doc(hidden)] -macro_rules! impl_libc_for_fixed_hash { - ( $name:ident ) => { - impl $crate::core_::cmp::PartialEq for $name { - #[inline] - fn eq(&self, other: &Self) -> bool { - unsafe { - $crate::libc::memcmp( - self.as_ptr() as *const $crate::libc::c_void, - other.as_ptr() as *const $crate::libc::c_void, - Self::len_bytes(), - ) == 0 - } - } - } - - impl $crate::core_::cmp::Ord for $name { - fn cmp(&self, other: &Self) -> $crate::core_::cmp::Ordering { - let r = unsafe { - $crate::libc::memcmp( - self.as_ptr() as *const $crate::libc::c_void, - other.as_ptr() as *const $crate::libc::c_void, - Self::len_bytes(), - ) - }; - if r < 0 { - return $crate::core_::cmp::Ordering::Less; - } - if r > 0 { - return $crate::core_::cmp::Ordering::Greater; - } - $crate::core_::cmp::Ordering::Equal - } - } - }; -} - // Implementation for disabled rustc-hex crate support. // // # Note diff --git a/primitive-types/CHANGELOG.md b/primitive-types/CHANGELOG.md index 12b958c30..87ee03e6f 100644 --- a/primitive-types/CHANGELOG.md +++ b/primitive-types/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) ## [0.6.2] - 2019-01-03 - Expose to_hex and from_hex from impl-serde. [#302](https://github.com/paritytech/parity-common/pull/302) diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index 31ef6235c..3131a001f 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -18,7 +18,6 @@ impl-rlp = { version = "0.2", path = "impls/rlp", default-features = false, opti default = ["std"] std = ["uint/std", "fixed-hash/std", "impl-codec/std"] byteorder = ["fixed-hash/byteorder"] -libc = ["fixed-hash/libc"] rustc-hex = ["fixed-hash/rustc-hex"] serde = ["std", "impl-serde"] codec = ["impl-codec"]