diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2020-01-14 13:40:42 +0000 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2020-03-26 15:49:22 +0000 |
| commit | d162d096ddf7972819e5b700890726a2ea85f272 (patch) | |
| tree | 10aef78eb9fffb1aa127609e953204a62b18ecef /src/doc | |
| parent | 2fbb07525e2f07a815e780a4268b11916248b5a9 (diff) | |
Rename asm! to llvm_asm!
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/unstable-book/src/library-features/llvm-asm.md (renamed from src/doc/unstable-book/src/library-features/asm.md) | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/llvm-asm.md index 2a1b6397781..e07f716e567 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/llvm-asm.md @@ -1,17 +1,17 @@ -# `asm` +# `llvm_asm` -The tracking issue for this feature is: [#29722] +The tracking issue for this feature is: [#70173] -[#29722]: https://github.com/rust-lang/rust/issues/29722 +[#70173]: https://github.com/rust-lang/rust/issues/70173 ------------------------ For extremely low-level manipulations and performance reasons, one might wish to control the CPU directly. Rust supports using inline -assembly to do this via the `asm!` macro. +assembly to do this via the `llvm_asm!` macro. ```rust,ignore -asm!(assembly template +llvm_asm!(assembly template : output operands : input operands : clobbers @@ -19,7 +19,7 @@ asm!(assembly template ); ``` -Any use of `asm` is feature gated (requires `#![feature(asm)]` on the +Any use of `llvm_asm` is feature gated (requires `#![feature(llvm_asm)]` on the crate to allow) and of course requires an `unsafe` block. > **Note**: the examples here are given in x86/x86-64 assembly, but @@ -31,12 +31,12 @@ The `assembly template` is the only required parameter and must be a literal string (i.e. `""`) ```rust -#![feature(asm)] +#![feature(llvm_asm)] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn foo() { unsafe { - asm!("NOP"); + llvm_asm!("NOP"); } } @@ -51,16 +51,16 @@ fn main() { } ``` -(The `feature(asm)` and `#[cfg]`s are omitted from now on.) +(The `feature(llvm_asm)` and `#[cfg]`s are omitted from now on.) Output operands, input operands, clobbers and options are all optional but you must add the right number of `:` if you skip them: ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # fn main() { unsafe { -asm!("xor %eax, %eax" +llvm_asm!("xor %eax, %eax" : : : "eax" @@ -73,10 +73,10 @@ asm!("xor %eax, %eax" Whitespace also doesn't matter: ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # fn main() { unsafe { -asm!("xor %eax, %eax" ::: "eax"); +llvm_asm!("xor %eax, %eax" ::: "eax"); # } } # #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] # fn main() {} @@ -89,12 +89,12 @@ Input and output operands follow the same format: `: expressions must be mutable lvalues, or not yet assigned: ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn add(a: i32, b: i32) -> i32 { let c: i32; unsafe { - asm!("add $2, $0" + llvm_asm!("add $2, $0" : "=r"(c) : "0"(a), "r"(b) ); @@ -116,11 +116,11 @@ operand. This is useful for very low level programming, where which register you use is important: ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # unsafe fn read_byte_in(port: u16) -> u8 { let result: u8; -asm!("in %dx, %al" : "={al}"(result) : "{dx}"(port)); +llvm_asm!("in %dx, %al" : "={al}"(result) : "{dx}"(port)); result # } ``` @@ -133,11 +133,11 @@ compiler not to assume any values loaded into those registers will stay valid. ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # fn main() { unsafe { // Put the value 0x200 in eax: -asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax"); +llvm_asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax"); # } } # #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] # fn main() {} @@ -167,12 +167,12 @@ Current valid options are: 3. *intel* - use intel syntax instead of the default AT&T. ```rust -# #![feature(asm)] +# #![feature(llvm_asm)] # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] # fn main() { let result: i32; unsafe { - asm!("mov eax, 2" : "={eax}"(result) : : : "intel") + llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel") } println!("eax is currently {}", result); # } @@ -182,7 +182,7 @@ println!("eax is currently {}", result); ## More Information -The current implementation of the `asm!` macro is a direct binding to [LLVM's +The current implementation of the `llvm_asm!` macro is a direct binding to [LLVM's inline assembler expressions][llvm-docs], so be sure to check out [their documentation as well][llvm-docs] for more information about clobbers, constraints, etc. @@ -190,4 +190,4 @@ constraints, etc. [llvm-docs]: http://llvm.org/docs/LangRef.html#inline-assembler-expressions If you need more power and don't mind losing some of the niceties of -`asm!`, check out [global_asm](global-asm.md). +`llvm_asm!`, check out [global_asm](global-asm.md). |
