Skip to content

Commit fab2d46

Browse files
author
Timothée Delabrouille
committed
remove allow_fail and uncomment the [feature(asm)] on every example
1 parent 1ddddca commit fab2d46

File tree

1 file changed

+30
-30
lines changed
  • src/doc/unstable-book/src/library-features

1 file changed

+30
-30
lines changed

src/doc/unstable-book/src/library-features/asm.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Inline assembly is currently supported on the following architectures:
3434

3535
Let us start with the simplest possible example:
3636

37-
```rust,allow_fail
38-
# #![feature(asm)]
37+
```rust
38+
#![feature(asm)]
3939
unsafe {
4040
asm!("nop");
4141
}
@@ -51,8 +51,8 @@ in the first argument of the `asm!` macro as a string literal.
5151
Now inserting an instruction that does nothing is rather boring. Let us do something that
5252
actually acts on data:
5353

54-
```rust,allow_fail
55-
# #![feature(asm)]
54+
```rust
55+
#![feature(asm)]
5656
let x: u64;
5757
unsafe {
5858
asm!("mov {}, 5", out(reg) x);
@@ -73,8 +73,8 @@ the template and will read the variable from there after the inline assembly fin
7373

7474
Let us see another example that also uses an input:
7575

76-
```rust,allow_fail
77-
# #![feature(asm)]
76+
```rust
77+
#![feature(asm)]
7878
let i: u64 = 3;
7979
let o: u64;
8080
unsafe {
@@ -113,8 +113,8 @@ readability, and allows reordering instructions without changing the argument or
113113

114114
We can further refine the above example to avoid the `mov` instruction:
115115

116-
```rust,allow_fail
117-
# #![feature(asm)]
116+
```rust
117+
#![feature(asm)]
118118
let mut x: u64 = 3;
119119
unsafe {
120120
asm!("add {0}, {number}", inout(reg) x, number = const 5);
@@ -127,8 +127,8 @@ This is different from specifying an input and output separately in that it is g
127127

128128
It is also possible to specify different variables for the input and output parts of an `inout` operand:
129129

130-
```rust,allow_fail
131-
# #![feature(asm)]
130+
```rust
131+
#![feature(asm)]
132132
let x: u64 = 3;
133133
let y: u64;
134134
unsafe {
@@ -149,8 +149,8 @@ There is also a `inlateout` variant of this specifier.
149149

150150
Here is an example where `inlateout` *cannot* be used:
151151

152-
```rust,allow_fail
153-
# #![feature(asm)]
152+
```rust
153+
#![feature(asm)]
154154
let mut a: u64 = 4;
155155
let b: u64 = 4;
156156
let c: u64 = 4;
@@ -170,8 +170,8 @@ Here the compiler is free to allocate the same register for inputs `b` and `c` s
170170

171171
However the following example can use `inlateout` since the output is only modified after all input registers have been read:
172172

173-
```rust,allow_fail
174-
# #![feature(asm)]
173+
```rust
174+
#![feature(asm)]
175175
let mut a: u64 = 4;
176176
let b: u64 = 4;
177177
unsafe {
@@ -189,8 +189,8 @@ Therefore, Rust inline assembly provides some more specific constraint specifier
189189
While `reg` is generally available on any architecture, these are highly architecture specific. E.g. for x86 the general purpose registers `eax`, `ebx`, `ecx`, `edx`, `ebp`, `esi`, and `edi`
190190
among others can be addressed by their name.
191191

192-
```rust,allow_fail,no_run
193-
# #![feature(asm)]
192+
```rust,no_run
193+
#![feature(asm)]
194194
let cmd = 0xd1;
195195
unsafe {
196196
asm!("out 0x64, eax", in("eax") cmd);
@@ -205,8 +205,8 @@ Note that unlike other operand types, explicit register operands cannot be used
205205

206206
Consider this example which uses the x86 `mul` instruction:
207207

208-
```rust,allow_fail
209-
# #![feature(asm)]
208+
```rust
209+
#![feature(asm)]
210210
fn mul(a: u64, b: u64) -> u128 {
211211
let lo: u64;
212212
let hi: u64;
@@ -241,8 +241,8 @@ This state is generally referred to as being "clobbered".
241241
We need to tell the compiler about this since it may need to save and restore this state
242242
around the inline assembly block.
243243

244-
```rust,allow_fail
245-
# #![feature(asm)]
244+
```rust
245+
#![feature(asm)]
246246
let ebx: u32;
247247
let ecx: u32;
248248

@@ -271,8 +271,8 @@ However we still need to tell the compiler that `eax` and `edx` have been modifi
271271

272272
This can also be used with a general register class (e.g. `reg`) to obtain a scratch register for use inside the asm code:
273273

274-
```rust,allow_fail
275-
# #![feature(asm)]
274+
```rust
275+
#![feature(asm)]
276276
// Multiply x by 6 using shifts and adds
277277
let mut x: u64 = 4;
278278
unsafe {
@@ -293,8 +293,8 @@ assert_eq!(x, 4 * 6);
293293
A special operand type, `sym`, allows you to use the symbol name of a `fn` or `static` in inline assembly code.
294294
This allows you to call a function or access a global variable without needing to keep its address in a register.
295295

296-
```rust,allow_fail
297-
# #![feature(asm)]
296+
```rust
297+
#![feature(asm)]
298298
extern "C" fn foo(arg: i32) {
299299
println!("arg = {}", arg);
300300
}
@@ -335,8 +335,8 @@ By default the compiler will always choose the name that refers to the full regi
335335

336336
This default can be overriden by using modifiers on the template string operands, just like you would with format strings:
337337

338-
```rust,allow_fail
339-
# #![feature(asm)]
338+
```rust
339+
#![feature(asm)]
340340
let mut x: u16 = 0xab;
341341

342342
unsafe {
@@ -360,7 +360,7 @@ You have to manually use the memory address syntax specified by the respectively
360360
For example, in x86/x86_64 and intel assembly syntax, you should wrap inputs/outputs in `[]`
361361
to indicate they are memory operands:
362362

363-
```rust,allow_fail
363+
```rust
364364
# #![feature(asm, llvm_asm)]
365365
# fn load_fpu_control_word(control: u16) {
366366
unsafe {
@@ -378,7 +378,7 @@ The compiler is allowed to instantiate multiple copies an `asm!` block, for exam
378378

379379
Moreover, due to [an llvm bug], you shouldn't use labels exclusively make of `0` and `1` digits, e.g. `0`, `11` or `101010`, as they may end up being interpreted as binary values.
380380

381-
```rust,allow_fail
381+
```rust
382382
#![feature(asm)]
383383

384384
let mut a = 0;
@@ -415,8 +415,8 @@ By default, an inline assembly block is treated the same way as an external FFI
415415

416416
Let's take our previous example of an `add` instruction:
417417

418-
```rust,allow_fail
419-
# #![feature(asm)]
418+
```rust
419+
#![feature(asm)]
420420
let mut a: u64 = 4;
421421
let b: u64 = 4;
422422
unsafe {

0 commit comments

Comments
 (0)