Use new uint version
BREAKING CHANGE: Remove U1024 and H1024 Remove conversion facilities that moved to uint Remove asm Cleanup
This commit is contained in:
parent
cb6e423501
commit
334020970e
|
@ -11,14 +11,13 @@ repository = "https://github.com/paritytech/primitives"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tiny-keccak = "1.4"
|
tiny-keccak = "1.4"
|
||||||
crunchy = { version = "0.1.6", features = ["limit_256"] }
|
crunchy = { version = "0.1.6", features = ["limit_256"] }
|
||||||
# TODO: remove `branch` when https://github.com/paritytech/parity-common/pull/12 lands
|
fixed-hash = { git = "https://github.com/paritytech/parity-common", default_features = false }
|
||||||
fixed-hash = { git = "https://github.com/paritytech/parity-common", branch = "add-fixed-hash", default_features = false }
|
|
||||||
ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true }
|
ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true }
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = { version = "0.4" }
|
rand = { version = "0.4" }
|
||||||
rustc-hex = "1.0"
|
rustc-hex = "2.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std", "heapsizeof", "serialize", "fixed-hash/libc"]
|
default = ["std", "heapsizeof", "serialize", "fixed-hash/libc"]
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ethereum-types"
|
name = "ethereum-types"
|
||||||
version = "0.3.3"
|
version = "0.4.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
homepage = "https://github.com/paritytech/primitives"
|
homepage = "https://github.com/paritytech/primitives"
|
||||||
description = "Ethereum types"
|
description = "Ethereum types"
|
||||||
build = "build.rs"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
rustc_version = "0.2"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crunchy = "0.1.5"
|
crunchy = "0.1"
|
||||||
ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false }
|
ethbloom = { path = "../ethbloom", version = "0.5.0", default-features = false }
|
||||||
ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true }
|
ethereum-types-serialize = { version = "0.2.1", path = "../serialize", optional = true }
|
||||||
fixed-hash = { git = "https://github.com/paritytech/parity-common", default_features = false }
|
fixed-hash = { git = "https://github.com/paritytech/parity-common", default_features = false }
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
uint = { git = "https://github.com/paritytech/parity-common", default_features = false }
|
# TODO: remove `branch` when https://github.com/paritytech/parity-common/pull/30 lands
|
||||||
|
uint = { version = "0.3", git = "https://github.com/paritytech/parity-common", default_features = false, branch = "dp/refactor/add-conversions" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
@ -26,5 +23,3 @@ default = ["std", "heapsizeof", "serialize"]
|
||||||
std = ["uint/std", "fixed-hash/std", "ethbloom/std"]
|
std = ["uint/std", "fixed-hash/std", "ethbloom/std"]
|
||||||
heapsizeof = ["uint/heapsizeof", "fixed-hash/heapsizeof", "ethbloom/heapsizeof"]
|
heapsizeof = ["uint/heapsizeof", "fixed-hash/heapsizeof", "ethbloom/heapsizeof"]
|
||||||
serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"]
|
serialize = ["std", "ethereum-types-serialize", "serde", "ethbloom/serialize"]
|
||||||
use_asm = ["uint/use_asm"]
|
|
||||||
impl_quickcheck_arbitrary = ["uint/impl_quickcheck_arbitrary", "fixed-hash/impl_quickcheck_arbitrary"]
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
extern crate rustc_version;
|
|
||||||
|
|
||||||
use rustc_version::{version_meta, Channel};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
if cfg!(feature = "use_asm") {
|
|
||||||
if let Channel::Nightly = version_meta().unwrap().channel {
|
|
||||||
println!("cargo:rustc-cfg=asm_available");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
use {U64, U128, U256, U512, U1024};
|
use {U64, U128, U256, U512};
|
||||||
|
|
||||||
#[cfg(feature="serialize")]
|
#[cfg(feature="serialize")]
|
||||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||||
|
@ -67,7 +67,6 @@ impl_serde!(H256, 32);
|
||||||
impl_serde!(H264, 33);
|
impl_serde!(H264, 33);
|
||||||
impl_serde!(H512, 64);
|
impl_serde!(H512, 64);
|
||||||
impl_serde!(H520, 65);
|
impl_serde!(H520, 65);
|
||||||
impl_serde!(H1024, 128);
|
|
||||||
|
|
||||||
construct_hash!(H32, 4);
|
construct_hash!(H32, 4);
|
||||||
construct_hash!(H64, 8);
|
construct_hash!(H64, 8);
|
||||||
|
@ -77,13 +76,11 @@ construct_hash!(H256, 32);
|
||||||
construct_hash!(H264, 33);
|
construct_hash!(H264, 33);
|
||||||
construct_hash!(H512, 64);
|
construct_hash!(H512, 64);
|
||||||
construct_hash!(H520, 65);
|
construct_hash!(H520, 65);
|
||||||
construct_hash!(H1024, 128);
|
|
||||||
|
|
||||||
impl_uint_conversions!(H64, U64);
|
impl_uint_conversions!(H64, U64);
|
||||||
impl_uint_conversions!(H128, U128);
|
impl_uint_conversions!(H128, U128);
|
||||||
impl_uint_conversions!(H256, U256);
|
impl_uint_conversions!(H256, U256);
|
||||||
impl_uint_conversions!(H512, U512);
|
impl_uint_conversions!(H512, U512);
|
||||||
impl_uint_conversions!(H1024, U1024);
|
|
||||||
|
|
||||||
#[deprecated]
|
#[deprecated]
|
||||||
impl From<H256> for H160 {
|
impl From<H256> for H160 {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#![cfg_attr(not(feature="std"), no_std)]
|
#![cfg_attr(not(feature="std"), no_std)]
|
||||||
|
|
||||||
#![cfg_attr(asm_available, feature(asm))]
|
|
||||||
|
|
||||||
#[cfg(feature="std")]
|
#[cfg(feature="std")]
|
||||||
extern crate core;
|
extern crate core;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -23,8 +21,8 @@ extern crate serde_json;
|
||||||
mod hash;
|
mod hash;
|
||||||
mod uint;
|
mod uint;
|
||||||
|
|
||||||
pub use uint::{U64, U128, U256, U512, U1024};
|
pub use uint::{U64, U128, U256, U512};
|
||||||
pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520, H1024};
|
pub use hash::{H32, H64, H128, H160, H256, H264, H512, H520};
|
||||||
pub use ethbloom::{Bloom, BloomRef, Input as BloomInput};
|
pub use ethbloom::{Bloom, BloomRef, Input as BloomInput};
|
||||||
pub use fixed_hash::clean_0x;
|
pub use fixed_hash::clean_0x;
|
||||||
|
|
||||||
|
|
|
@ -31,158 +31,16 @@ construct_uint!(U64, 1);
|
||||||
construct_uint!(U128, 2);
|
construct_uint!(U128, 2);
|
||||||
construct_uint!(U256, 4);
|
construct_uint!(U256, 4);
|
||||||
construct_uint!(U512, 8);
|
construct_uint!(U512, 8);
|
||||||
construct_uint!(U1024, 16);
|
|
||||||
|
|
||||||
impl_serde!(U64, 1);
|
impl_serde!(U64, 1);
|
||||||
impl_serde!(U128, 2);
|
impl_serde!(U128, 2);
|
||||||
impl_serde!(U256, 4);
|
impl_serde!(U256, 4);
|
||||||
impl_serde!(U512, 8);
|
impl_serde!(U512, 8);
|
||||||
impl_serde!(U1024, 16);
|
|
||||||
|
|
||||||
impl U256 {
|
impl U256 {
|
||||||
/// Multiplies two 256-bit integers to produce full 512-bit integer
|
|
||||||
/// No overflow possible
|
|
||||||
#[cfg(all(asm_available, target_arch="x86_64"))]
|
|
||||||
pub fn full_mul(self, other: U256) -> U512 {
|
|
||||||
let self_t: &[u64; 4] = &self.0;
|
|
||||||
let other_t: &[u64; 4] = &other.0;
|
|
||||||
let mut result: [u64; 8] = unsafe { ::core::mem::uninitialized() };
|
|
||||||
unsafe {
|
|
||||||
asm!("
|
|
||||||
mov $8, %rax
|
|
||||||
mulq $12
|
|
||||||
mov %rax, $0
|
|
||||||
mov %rdx, $1
|
|
||||||
|
|
||||||
mov $8, %rax
|
|
||||||
mulq $13
|
|
||||||
add %rax, $1
|
|
||||||
adc $$0, %rdx
|
|
||||||
mov %rdx, $2
|
|
||||||
|
|
||||||
mov $8, %rax
|
|
||||||
mulq $14
|
|
||||||
add %rax, $2
|
|
||||||
adc $$0, %rdx
|
|
||||||
mov %rdx, $3
|
|
||||||
|
|
||||||
mov $8, %rax
|
|
||||||
mulq $15
|
|
||||||
add %rax, $3
|
|
||||||
adc $$0, %rdx
|
|
||||||
mov %rdx, $4
|
|
||||||
|
|
||||||
mov $9, %rax
|
|
||||||
mulq $12
|
|
||||||
add %rax, $1
|
|
||||||
adc %rdx, $2
|
|
||||||
adc $$0, $3
|
|
||||||
adc $$0, $4
|
|
||||||
xor $5, $5
|
|
||||||
adc $$0, $5
|
|
||||||
xor $6, $6
|
|
||||||
adc $$0, $6
|
|
||||||
xor $7, $7
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $9, %rax
|
|
||||||
mulq $13
|
|
||||||
add %rax, $2
|
|
||||||
adc %rdx, $3
|
|
||||||
adc $$0, $4
|
|
||||||
adc $$0, $5
|
|
||||||
adc $$0, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $9, %rax
|
|
||||||
mulq $14
|
|
||||||
add %rax, $3
|
|
||||||
adc %rdx, $4
|
|
||||||
adc $$0, $5
|
|
||||||
adc $$0, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $9, %rax
|
|
||||||
mulq $15
|
|
||||||
add %rax, $4
|
|
||||||
adc %rdx, $5
|
|
||||||
adc $$0, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $10, %rax
|
|
||||||
mulq $12
|
|
||||||
add %rax, $2
|
|
||||||
adc %rdx, $3
|
|
||||||
adc $$0, $4
|
|
||||||
adc $$0, $5
|
|
||||||
adc $$0, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $10, %rax
|
|
||||||
mulq $13
|
|
||||||
add %rax, $3
|
|
||||||
adc %rdx, $4
|
|
||||||
adc $$0, $5
|
|
||||||
adc $$0, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $10, %rax
|
|
||||||
mulq $14
|
|
||||||
add %rax, $4
|
|
||||||
adc %rdx, $5
|
|
||||||
adc $$0, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $10, %rax
|
|
||||||
mulq $15
|
|
||||||
add %rax, $5
|
|
||||||
adc %rdx, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $11, %rax
|
|
||||||
mulq $12
|
|
||||||
add %rax, $3
|
|
||||||
adc %rdx, $4
|
|
||||||
adc $$0, $5
|
|
||||||
adc $$0, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $11, %rax
|
|
||||||
mulq $13
|
|
||||||
add %rax, $4
|
|
||||||
adc %rdx, $5
|
|
||||||
adc $$0, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $11, %rax
|
|
||||||
mulq $14
|
|
||||||
add %rax, $5
|
|
||||||
adc %rdx, $6
|
|
||||||
adc $$0, $7
|
|
||||||
|
|
||||||
mov $11, %rax
|
|
||||||
mulq $15
|
|
||||||
add %rax, $6
|
|
||||||
adc %rdx, $7
|
|
||||||
"
|
|
||||||
: /* $0 */ "={r8}"(result[0]), /* $1 */ "={r9}"(result[1]), /* $2 */ "={r10}"(result[2]),
|
|
||||||
/* $3 */ "={r11}"(result[3]), /* $4 */ "={r12}"(result[4]), /* $5 */ "={r13}"(result[5]),
|
|
||||||
/* $6 */ "={r14}"(result[6]), /* $7 */ "={r15}"(result[7])
|
|
||||||
|
|
||||||
: /* $8 */ "m"(self_t[0]), /* $9 */ "m"(self_t[1]), /* $10 */ "m"(self_t[2]),
|
|
||||||
/* $11 */ "m"(self_t[3]), /* $12 */ "m"(other_t[0]), /* $13 */ "m"(other_t[1]),
|
|
||||||
/* $14 */ "m"(other_t[2]), /* $15 */ "m"(other_t[3])
|
|
||||||
: "rax", "rdx"
|
|
||||||
:
|
|
||||||
);
|
|
||||||
}
|
|
||||||
U512(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Multiplies two 256-bit integers to produce full 512-bit integer
|
/// Multiplies two 256-bit integers to produce full 512-bit integer
|
||||||
/// No overflow possible
|
/// No overflow possible
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg(not(all(asm_available, target_arch="x86_64")))]
|
|
||||||
pub fn full_mul(self, other: U256) -> U512 {
|
pub fn full_mul(self, other: U256) -> U512 {
|
||||||
U512(uint_full_mul_reg!(U256, 4, self, other))
|
U512(uint_full_mul_reg!(U256, 4, self, other))
|
||||||
}
|
}
|
||||||
|
@ -300,66 +158,6 @@ impl From<U256> for u32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a [u8; 32]> for U256 {
|
|
||||||
fn from(bytes: &[u8; 32]) -> Self {
|
|
||||||
bytes[..].into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<[u8; 32]> for U256 {
|
|
||||||
fn from(bytes: [u8; 32]) -> Self {
|
|
||||||
bytes[..].as_ref().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<U256> for [u8; 32] {
|
|
||||||
fn from(number: U256) -> Self {
|
|
||||||
let mut arr = [0u8; 32];
|
|
||||||
number.to_big_endian(&mut arr);
|
|
||||||
arr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a [u8; 16]> for U128 {
|
|
||||||
fn from(bytes: &[u8; 16]) -> Self {
|
|
||||||
bytes[..].into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<[u8; 16]> for U128 {
|
|
||||||
fn from(bytes: [u8; 16]) -> Self {
|
|
||||||
bytes[..].as_ref().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<U128> for [u8; 16] {
|
|
||||||
fn from(number: U128) -> Self {
|
|
||||||
let mut arr = [0u8; 16];
|
|
||||||
number.to_big_endian(&mut arr);
|
|
||||||
arr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a [u8; 64]> for U512 {
|
|
||||||
fn from(bytes: &[u8; 64]) -> Self {
|
|
||||||
bytes[..].into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<[u8; 64]> for U512 {
|
|
||||||
fn from(bytes: [u8; 64]) -> Self {
|
|
||||||
bytes[..].as_ref().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<U512> for [u8; 64] {
|
|
||||||
fn from(number: U512) -> Self {
|
|
||||||
let mut arr = [0u8; 64];
|
|
||||||
number.to_big_endian(&mut arr);
|
|
||||||
arr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{U256, U512};
|
use super::{U256, U512};
|
||||||
|
|
Loading…
Reference in New Issue