From f45c6d8fc7097b5186ece9c43c3237d1c58e8dd4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 7 Apr 2017 01:05:03 -0500 Subject: [PATCH 1/6] document some existing unstable features "msp430-interrupt", "ptx-kernel" and #![compiler_builtins_lib] --- .../unstable-book/src/abi-msp430-interrupt.md | 35 ++++++++++++ src/doc/unstable-book/src/abi-ptx.md | 56 ++++++++++++++++++- .../src/compiler-builtins-lib.md | 32 ++++++++++- .../unstable-book/src/compiler-builtins.md | 3 +- 4 files changed, 122 insertions(+), 4 deletions(-) diff --git a/src/doc/unstable-book/src/abi-msp430-interrupt.md b/src/doc/unstable-book/src/abi-msp430-interrupt.md index 9b2c7f29897..b10bc41cb14 100644 --- a/src/doc/unstable-book/src/abi-msp430-interrupt.md +++ b/src/doc/unstable-book/src/abi-msp430-interrupt.md @@ -5,3 +5,38 @@ The tracking issue for this feature is: [#38487] [#38487]: https://github.com/rust-lang/rust/issues/38487 ------------------------ + +In the MSP430 architecture, interrupt handlers have a special calling +convention. You can use the `"msp430-interrupt"` ABI to make the compiler apply +the right calling convention to the interrupt handlers you define. + + + +``` rust,ignore +#![feature(abi_msp430_interrupt)] +#![no_std] + +// Place the interrupt handler at the appropriate memory address +// (Alternatively, you can use `#[used]` and remove `pub` and `#[no_mangle]`) +#[link_section = "__interrupt_vector_10"] +#[no_mangle] +pub static TIM0_VECTOR: extern "msp430-interrupt" fn() = tim0; + +// The interrupt handler +extern "msp430-interrupt" fn tim0() { + // .. +} +``` + +``` text +$ msp430-elf-objdump -CD ./target/msp430/release/app +Disassembly of section __interrupt_vector_10: + +0000fff2 : + fff2: 00 c0 interrupt service routine at 0xc000 + +Disassembly of section .text: + +0000c000 : + c000: 00 13 reti +``` diff --git a/src/doc/unstable-book/src/abi-ptx.md b/src/doc/unstable-book/src/abi-ptx.md index 9c1b8868ace..89b2a199279 100644 --- a/src/doc/unstable-book/src/abi-ptx.md +++ b/src/doc/unstable-book/src/abi-ptx.md @@ -1,5 +1,59 @@ # `abi_ptx` -The tracking issue for this feature is: None. +The tracking issue for this feature +is: [38788](https://github.com/rust-lang/rust/issues/38788) ------------------------ + +When emitting PTX code, all vanilla Rust functions (`fn`) get translated to +"device" functions. These functions are *not* callable from the host via the +CUDA API so a crate with only device functions is not too useful! + +OTOH, "global" functions *can* be called by the host; you can think of them +as the real public API of your crate. To produce a global function use the +`"ptx-kernel"` ABI. + + + +``` rust,ignore +#![feature(abi_ptx)] +#![no_std] + +pub unsafe extern "ptx-kernel" fn global_function() { + device_function(); +} + +pub fn device_function() { + // .. +} +``` + +``` text +$ xargo rustc --target nvptx64-nvidia-cuda --release -- --emit=asm + +$ cat $(find -name '*.s') +// +// Generated by LLVM NVPTX Back-End +// + +.version 3.2 +.target sm_20 +.address_size 64 + + // .globl _ZN6kernel15global_function17h46111ebe6516b382E + +.visible .entry _ZN6kernel15global_function17h46111ebe6516b382E() +{ + + + ret; +} + + // .globl _ZN6kernel15device_function17hd6a0e4993bbf3f78E +.visible .func _ZN6kernel15device_function17hd6a0e4993bbf3f78E() +{ + + + ret; +} +``` diff --git a/src/doc/unstable-book/src/compiler-builtins-lib.md b/src/doc/unstable-book/src/compiler-builtins-lib.md index 8986b968ca6..5da8968fd0c 100644 --- a/src/doc/unstable-book/src/compiler-builtins-lib.md +++ b/src/doc/unstable-book/src/compiler-builtins-lib.md @@ -1,5 +1,35 @@ # `compiler_builtins_lib` -This feature is internal to the Rust compiler and is not intended for general use. +The tracking issue for this feature is: None. ------------------------ + +This feature is required to link to the `compiler_builtins` crate which contains +"compiler intrinsics". Compiler intrinsics are software implementations of basic +operations like multiplication of `u64`s. These intrinsics are only required on +platforms where these operations don't directly map to a hardware instruction. + +You should never need to explicitly link to the `compiler_builtins` crate when +building "std" programs as `compiler_builtins` is already in the dependency +graph of `std`. But you may need it when building `no_std` **binary** crates. If +you get a *linker* error like: + +``` text +$PWD/src/main.rs:11: undefined reference to `__aeabi_lmul' +$PWD/src/main.rs:11: undefined reference to `__aeabi_uldivmod' +``` + +That means that you need to link to this crate. + +When you link to this crate, make sure it only appears once in your crate +dependency graph. Also, it doesn't matter where in the dependency graph, you +place the `compiler_builtins` crate. + + + +``` rust,ignore +#![feature(compiler_builtins_lib)] +#![no_std] + +extern crate compiler_builtins; +``` diff --git a/src/doc/unstable-book/src/compiler-builtins.md b/src/doc/unstable-book/src/compiler-builtins.md index 3ec3cba257a..52fac575b6e 100644 --- a/src/doc/unstable-book/src/compiler-builtins.md +++ b/src/doc/unstable-book/src/compiler-builtins.md @@ -1,6 +1,5 @@ # `compiler_builtins` -The tracking issue for this feature is: None. +This feature is internal to the Rust compiler and is not intended for general use. ------------------------ - From 15fa301b7aa903235e70f8b5a4c2ef7ae31268f3 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 7 Apr 2017 09:46:55 -0500 Subject: [PATCH 2/6] change the format of the linked issue number --- src/doc/unstable-book/src/abi-ptx.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/doc/unstable-book/src/abi-ptx.md b/src/doc/unstable-book/src/abi-ptx.md index 89b2a199279..0ded3ceeaef 100644 --- a/src/doc/unstable-book/src/abi-ptx.md +++ b/src/doc/unstable-book/src/abi-ptx.md @@ -1,7 +1,8 @@ # `abi_ptx` -The tracking issue for this feature -is: [38788](https://github.com/rust-lang/rust/issues/38788) +The tracking issue for this feature is: [#38788] + +[#38788]: https://github.com/rust-lang/rust/issues/38788 ------------------------ From 5c5a5182c94d07409fac8cb40b2cdab488c140ff Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Fri, 7 Apr 2017 17:28:55 +0200 Subject: [PATCH 3/6] Optimize AtomicBool::fetch_nand --- src/libcore/sync/atomic.rs | 22 +++++++++++++--------- src/libcore/tests/atomic.rs | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 2e1058bfc34..dd0069502de 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -539,17 +539,21 @@ impl AtomicBool { // We can't use atomic_nand here because it can result in a bool with // an invalid value. This happens because the atomic operation is done // with an 8-bit integer internally, which would set the upper 7 bits. - // So we just use a compare-exchange loop instead, which is what the - // intrinsic actually expands to anyways on many platforms. - let mut old = self.load(Relaxed); - loop { - let new = !(old && val); - match self.compare_exchange_weak(old, new, order, Relaxed) { - Ok(_) => break, - Err(x) => old = x, + // So we just use fetch_xor or compare_exchange instead. + if val { + // !(x & true) == !x + // We must invert the bool. + self.fetch_xor(true, order) + } else { + // !(x & false) == true + // We must set the bool to true. Instead of delegating to swap or fetch_or, use + // compare_exchange instead in order to avoid unnecessary writes to memory, which + // might minimize cache-coherence traffic. + match self.compare_exchange(false, true, order, Ordering::Relaxed) { + Ok(_) => false, + Err(_) => true, } } - old } /// Logical "or" with a boolean value. diff --git a/src/libcore/tests/atomic.rs b/src/libcore/tests/atomic.rs index b6bb5fddf4a..9babe24a985 100644 --- a/src/libcore/tests/atomic.rs +++ b/src/libcore/tests/atomic.rs @@ -24,10 +24,23 @@ fn bool_() { #[test] fn bool_and() { let a = AtomicBool::new(true); - assert_eq!(a.fetch_and(false, SeqCst),true); + assert_eq!(a.fetch_and(false, SeqCst), true); assert_eq!(a.load(SeqCst),false); } +#[test] +fn bool_nand() { + let a = AtomicBool::new(false); + assert_eq!(a.fetch_nand(false, SeqCst), false); + assert_eq!(a.load(SeqCst), true); + assert_eq!(a.fetch_nand(false, SeqCst), true); + assert_eq!(a.load(SeqCst), true); + assert_eq!(a.fetch_nand(true, SeqCst), true); + assert_eq!(a.load(SeqCst), false); + assert_eq!(a.fetch_nand(true, SeqCst), false); + assert_eq!(a.load(SeqCst), true); +} + #[test] fn uint_and() { let x = AtomicUsize::new(0xf731); From f7ffe5bd2499663026787f91f60e3e3ecf946a03 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Fri, 7 Apr 2017 18:04:15 +0200 Subject: [PATCH 4/6] Replace compare_exchange with swap --- src/libcore/sync/atomic.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index dd0069502de..a4050f271eb 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -539,20 +539,15 @@ impl AtomicBool { // We can't use atomic_nand here because it can result in a bool with // an invalid value. This happens because the atomic operation is done // with an 8-bit integer internally, which would set the upper 7 bits. - // So we just use fetch_xor or compare_exchange instead. + // So we just use fetch_xor or swap instead. if val { // !(x & true) == !x // We must invert the bool. self.fetch_xor(true, order) } else { // !(x & false) == true - // We must set the bool to true. Instead of delegating to swap or fetch_or, use - // compare_exchange instead in order to avoid unnecessary writes to memory, which - // might minimize cache-coherence traffic. - match self.compare_exchange(false, true, order, Ordering::Relaxed) { - Ok(_) => false, - Err(_) => true, - } + // We must set the bool to true. + self.swap(true, order) } } From bfc08c13ccf9a88159a634bf0a19bf271d341c48 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 7 Apr 2017 20:47:22 +0200 Subject: [PATCH 5/6] pub(restricted) didn't make it into 1.17 Gets shipped in 1.18 instead. --- src/libsyntax/feature_gate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 550f1160bed..c68e2ae3468 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -408,7 +408,7 @@ declare_features! ( // Allows the definition recursive static items. (accepted, static_recursion, "1.17.0", Some(29719)), // pub(restricted) visibilities (RFC 1422) - (accepted, pub_restricted, "1.17.0", Some(32409)), + (accepted, pub_restricted, "1.18.0", Some(32409)), // The #![windows_subsystem] attribute (accepted, windows_subsystem, "1.18.0", Some(37499)), ); From 5c0c3e803d6070cc4d1ce0362e0ae3bae4962720 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 7 Apr 2017 17:16:52 -0700 Subject: [PATCH 6/6] bootstrap.py: fix armv7 detection This matches the logic that was in `./configure` before f8ca805422db8. --- src/bootstrap/bootstrap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index d5bc6127a1e..4b0491f8bd0 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -463,10 +463,10 @@ class RustBuild(object): cputype = 'i686' elif cputype in {'xscale', 'arm'}: cputype = 'arm' - elif cputype in {'armv6l', 'armv7l', 'armv8l'}: + elif cputype == 'armv6l': cputype = 'arm' ostype += 'eabihf' - elif cputype == 'armv7l': + elif cputype in {'armv7l', 'armv8l'}: cputype = 'armv7' ostype += 'eabihf' elif cputype == 'aarch64':