Skip to content

Commit 230d8ff

Browse files
joshtriplettnbdd0121
authored andcommitted
More distinctions between asm blocks and assembly code
Update more cases where the phrasing could potentially have been interpreted as affecting a `label` block.
1 parent c8aa67d commit 230d8ff

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/inline-assembly.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ r[asm.options.supported-options.nomem]
10071007
# #[cfg(target_arch = "x86_64")] {
10081008
let mut x = 0i32;
10091009
let z: i32;
1010-
// Accessing memory from a nomem asm block is disallowed
1010+
// Accessing memory from assembly in a nomem asm block is disallowed
10111011
unsafe {
10121012
core::arch::asm!("mov {val:e}, dword ptr [{ptr}]",
10131013
ptr = in(reg) &mut x,
@@ -1016,7 +1016,7 @@ unsafe {
10161016
)
10171017
}
10181018
1019-
// Writing to memory is also undefined behaviour
1019+
// Writing to memory from assembly in a nomem asm block is also undefined behaviour
10201020
unsafe {
10211021
core::arch::asm!("mov dword ptr [{ptr}], {val:e}",
10221022
ptr = in(reg) &mut x,
@@ -1243,7 +1243,7 @@ r[asm.rules.black-box]
12431243
- The compiler cannot assume that the instructions in the asm are the ones that will actually end up executed.
12441244
- This effectively means that the compiler must treat the `asm!` as a black box and only take the interface specification into account, not the instructions themselves.
12451245
- Runtime code patching is allowed, via target-specific mechanisms.
1246-
- However there is no guarantee that each `asm!` directly corresponds to a single instance of instructions in the object file: the compiler is free to duplicate or deduplicate `asm!` blocks.
1246+
- However there is no guarantee that each `asm!` directly corresponds to a single instance of instructions in the object file: the compiler is free to duplicate or deduplicate the assembly code in `asm!` blocks.
12471247

12481248
r[asm.rules.stack-below-sp]
12491249
- Unless the `nostack` option is set, asm code is allowed to use stack space below the stack pointer.
@@ -1332,9 +1332,9 @@ r[asm.rules.arm64ec]
13321332
r[asm.rules.only-on-exit]
13331333
- The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting the assembly code.
13341334
- This means that assembly code that never returns (even if not marked `noreturn`) doesn't need to preserve these registers.
1335-
- When returning to a different `asm!` block than you entered (e.g. for context switching), these registers must contain the value they had upon entering the `asm!` block that you are *exiting*.
1336-
- You cannot exit an `asm!` block that has not been entered.
1337-
Neither can you exit an `asm!` block that has already been exited (without first entering it again).
1335+
- When returning to the assembly code of a different `asm!` block than you entered (e.g. for context switching), these registers must contain the value they had upon entering the `asm!` block that you are *exiting*.
1336+
- You cannot exit the assembly code of an `asm!` block that has not been entered.
1337+
Neither can you exit the assembly code of an `asm!` block whose assembly code has already been exited (without first entering it again).
13381338
- You are responsible for switching any target-specific state (e.g. thread-local storage, stack bounds).
13391339
- You cannot jump from an address in one `asm!` block to an address in another, even within the same function or block, without treating their contexts as potentially different and requiring context switching. You cannot assume that any particular value in those contexts (e.g. current stack pointer or temporary values below the stack pointer) will remain unchanged between the two `asm!` blocks.
13401340
- The set of memory locations that you may access is the intersection of those allowed by the `asm!` blocks you entered and exited.
@@ -1361,7 +1361,7 @@ In addition to all of the previous rules, the string argument to `asm!` must ult
13611361
after all other arguments are evaluated, formatting is performed, and operands are translated---
13621362
assembly that is both syntactically correct and semantically valid for the target architecture.
13631363
The formatting rules allow the compiler to generate assembly with correct syntax.
1364-
Rules concerning operands permit valid translation of Rust operands into and out of `asm!`.
1364+
Rules concerning operands permit valid translation of Rust operands into and out of the assembly code.
13651365
Adherence to these rules is necessary, but not sufficient, for the final expanded assembly to be
13661366
both correct and valid. For instance:
13671367

0 commit comments

Comments
 (0)