Merge pull request #2 from debris/depsup

use byteorder for endian conversion, updated rustc_version version
This commit is contained in:
Nikolay Volf 2017-03-15 16:12:04 +03:00 committed by GitHub
commit 3ebff39cbe
4 changed files with 9 additions and 42 deletions

View File

@ -9,9 +9,10 @@ authors = ["Parity Technologies <admin@parity.io>"]
build = "build.rs"
[build-dependencies]
rustc_version = "0.1"
rustc_version = "0.2"
[dependencies]
rustc-serialize = "0.3"
heapsize = "0.3"
rand = "0.3.12"
byteorder = "1.0"

View File

@ -19,7 +19,7 @@ extern crate rustc_version;
use rustc_version::{version_meta, Channel};
fn main() {
if let Channel::Nightly = version_meta().channel {
if let Channel::Nightly = version_meta().unwrap().channel {
println!("cargo:rustc-cfg=asm_available");
}
}

View File

@ -18,6 +18,7 @@
#![cfg_attr(asm_available, feature(asm))]
extern crate byteorder;
extern crate rand;
extern crate rustc_serialize;
#[macro_use] extern crate heapsize;

View File

@ -42,6 +42,7 @@ use std::str::{FromStr};
use std::hash::Hash;
use std::ops::{Shr, Shl, BitAnd, BitOr, BitXor, Not, Div, Rem, Mul, Add, Sub};
use std::cmp::Ordering;
use byteorder::{ByteOrder, BigEndian, LittleEndian};
use rustc_serialize::hex::{ToHex, FromHex, FromHexError};
/// Conversion from decimal string error
@ -647,55 +648,19 @@ macro_rules! construct_uint {
(arr[index / 8] >> (((index % 8)) * 8)) as u8
}
#[cfg(any(
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "powerpc64"))]
#[inline]
fn to_big_endian(&self, bytes: &mut[u8]) {
debug_assert!($n_words * 8 == bytes.len());
let &$name(ref arr) = self;
unsafe {
let mut out: *mut u64 = mem::transmute(bytes.as_mut_ptr());
out = out.offset($n_words);
for i in 0..$n_words {
out = out.offset(-1);
*out = arr[i].swap_bytes();
}
}
}
#[cfg(not(any(
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "powerpc64")))]
#[inline]
fn to_big_endian(&self, bytes: &mut[u8]) {
debug_assert!($n_words * 8 == bytes.len());
let &$name(ref arr) = self;
for i in 0..bytes.len() {
let rev = bytes.len() - 1 - i;
let pos = rev / 8;
bytes[i] = (arr[pos] >> ((rev % 8) * 8)) as u8;
for i in 0..$n_words {
BigEndian::write_u64(&mut bytes[8 * i..], self.0[$n_words - i - 1]);
}
}
#[inline]
fn to_little_endian(&self, bytes: &mut [u8]) {
debug_assert!($n_words * 8 == bytes.len());
let &$name(ref arr) = self;
for i in 0..bytes.len() {
let pos = i / 8;
bytes[i] = (arr[pos] >> ((i % 8) * 8)) as u8;
for i in 0..$n_words {
LittleEndian::write_u64(&mut bytes[8 * i..], self.0[i]);
}
}