From 8a14926f6d313db3bc7d5701c24a12bb17385e65 Mon Sep 17 00:00:00 2001 From: snd Date: Tue, 5 Dec 2017 13:14:16 +0100 Subject: [PATCH] Issue 6 (#7) * add rustc_version to build deps of ether types (needed by build script) * ethereum-types: add build script that sets cargo:rustc-cfg=asm_available on nightly * ethereum-types: #![cfg_attr(asm_available, feature(asm))] * tests: add the whole feature asm build script to make it pass on nightly CI * add #![cfg_attr(asm_available, feature(asm))] directly where needed so users don't have to add it * remove tests/build.rs since it should not be needed anymore * move inner cfg_attr attributes to the right allowed position * remove check for asm_available in contexts that already have check for that --- ethereum-types/Cargo.toml | 3 +++ ethereum-types/build.rs | 17 +++++++++++++++++ ethereum-types/src/uint.rs | 1 + uint/src/lib.rs | 2 -- uint/src/uint.rs | 5 ++++- 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 ethereum-types/build.rs diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index f900f6e..1c52f96 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -3,6 +3,9 @@ name = "ethereum-types" version = "0.1.0" authors = ["debris "] +[build-dependencies] +rustc_version = "0.2" + [dependencies] uint = { path = "../uint", version = "0.1" } fixed-hash = { path = "../fixed-hash", version = "0.1" } diff --git a/ethereum-types/build.rs b/ethereum-types/build.rs new file mode 100644 index 0000000..432acc3 --- /dev/null +++ b/ethereum-types/build.rs @@ -0,0 +1,17 @@ +// Copyright 2015-2017 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. + +extern crate rustc_version; + +use rustc_version::{version_meta, Channel}; + +fn main() { + if let Channel::Nightly = version_meta().unwrap().channel { + println!("cargo:rustc-cfg=asm_available"); + } +} diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index 6b12c8a..f1595ad 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -7,6 +7,7 @@ impl U256 { /// No overflow possible #[cfg(all(asm_available, target_arch="x86_64"))] pub fn full_mul(self, other: U256) -> U512 { + #![feature(asm)] let self_t: &[u64; 4] = &self.0; let other_t: &[u64; 4] = &other.0; let mut result: [u64; 8] = unsafe { ::core::mem::uninitialized() }; diff --git a/uint/src/lib.rs b/uint/src/lib.rs index 4a3dc8a..01d41a7 100644 --- a/uint/src/lib.rs +++ b/uint/src/lib.rs @@ -8,8 +8,6 @@ //! Efficient large, fixed-size big integers and hashes. -#![cfg_attr(asm_available, feature(asm))] - #[doc(hidden)] pub extern crate byteorder; diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 39e7aca..11da94e 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -77,6 +77,7 @@ macro_rules! uint_overflowing_add_reg { #[macro_export] #[doc(hidden)] macro_rules! uint_overflowing_add { + #![feature(asm)] (U256, $n_words:tt, $self_expr: expr, $other: expr) => ({ let mut result: [u64; $n_words] = unsafe { ::core::mem::uninitialized() }; let self_t: &[u64; $n_words] = &$self_expr.0; @@ -223,6 +224,7 @@ macro_rules! uint_overflowing_sub_reg { #[macro_export] #[doc(hidden)] macro_rules! uint_overflowing_sub { + #![feature(asm)] (U256, $n_words:tt, $self_expr: expr, $other: expr) => ({ let mut result: [u64; $n_words] = unsafe { ::core::mem::uninitialized() }; let self_t: &[u64; $n_words] = &$self_expr.0; @@ -277,7 +279,7 @@ macro_rules! uint_overflowing_sub { "={al}"(overflow) /* $0 - $4 */ : "{rdi}"(&result[4] as *const u64) /* $5 */ - "{rsi}"(&self_t[4] as *const u64) /* $6 */ + "{rsi}"(&self_t[4] as *const u64) /* $6 */ "0"(self_t[0]), "1"(self_t[1]), "2"(self_t[2]), "3"(self_t[3]), "m"(self_t[4]), "m"(self_t[5]), "m"(self_t[6]), "m"(self_t[7]), /* $7 - $14 */ @@ -298,6 +300,7 @@ macro_rules! uint_overflowing_sub { #[cfg(all(asm_available, target_arch="x86_64"))] #[macro_export] macro_rules! uint_overflowing_mul { + #![feature(asm)] (U256, $n_words: expr, $self_expr: expr, $other: expr) => ({ let mut result: [u64; $n_words] = unsafe { ::core::mem::uninitialized() }; let self_t: &[u64; $n_words] = &$self_expr.0;