Skip to content

Commit 09efea5

Browse files
committed
Update unstable book documentation with the latest RFC text
1 parent 32471f4 commit 09efea5

File tree

1 file changed

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

1 file changed

+10
-3
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ Several types of operands are supported:
427427
- The substituted string does not include any modifiers (e.g. GOT, PLT, relocations, etc).
428428
- `<path>` is allowed to point to a `#[thread_local]` static, in which case the asm code can combine the symbol with relocations (e.g. `@plt`, `@TPOFF`) to read from thread-local data.
429429

430+
Operand expressions are evaluated from left to right, just like function call arguments. After the `asm!` has executed, outputs are written to in left to right order. This is significant if two outputs point to the same place: that place will contain the value of the rightmost output.
431+
430432
## Register operands
431433

432434
Input and output operands can be specified either as an explicit register or as a register class from which the register allocator can select a register. Explicit registers are specified as string literals (e.g. `"eax"`) while register classes are specified as identifiers (e.g. `reg`). Using string literals for register names enables support for architectures that use special characters in register names, such as MIPS (`$0`, `$1`, etc).
@@ -438,7 +440,7 @@ Only the following types are allowed as operands for inline assembly:
438440
- Floating-point numbers
439441
- Pointers (thin only)
440442
- Function pointers
441-
- SIMD vectors (structs defined with `#[repr(simd)]` and which implement `Copy`)
443+
- SIMD vectors (structs defined with `#[repr(simd)]` and which implement `Copy`). This includes architecture-specific vector types defined in `std::arch` such as `__m128` (x86) or `int8x16_t` (ARM).
442444

443445
Here is the list of currently supported register classes:
444446

@@ -667,7 +669,6 @@ The compiler performs some additional checks on options:
667669
- These flags registers must be restored upon exiting the asm block if the `preserves_flags` option is set:
668670
- x86
669671
- Status flags in `EFLAGS` (CF, PF, AF, ZF, SF, OF).
670-
- Direction flag in `EFLAGS` (DF).
671672
- Floating-point status word (all).
672673
- Floating-point exception flags in `MXCSR` (PE, UE, OE, ZE, DE, IE).
673674
- ARM
@@ -682,11 +683,17 @@ The compiler performs some additional checks on options:
682683
- Floating-point status (`FPSR` register).
683684
- RISC-V
684685
- Floating-point exception flags in `fcsr` (`fflags`).
686+
- On x86, the direction flag (DF in `EFLAGS`) is clear on entry to an asm block and must be clear on exit.
687+
- Behavior is undefined if the direction flag is set on exiting an asm block.
685688
- The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting an `asm!` block.
686689
- This means that `asm!` blocks that never return (even if not marked `noreturn`) don't need to preserve these registers.
687690
- 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*.
688691
- You cannot exit an `asm!` block that has not been entered. Neither can you exit an `asm!` block that has already been exited.
689692
- You are responsible for switching any target-specific state (e.g. thread-local storage, stack bounds).
690693
- The set of memory locations that you may access is the intersection of those allowed by the `asm!` blocks you entered and exited.
694+
- You cannot assume that an `asm!` block will appear exactly once in the output binary. The compiler is allowed to instantiate multiple copies of the `asm!` block, for example when the function containing it is inlined in multiple places.
695+
- As a consequence, you should only use [local labels] inside inline assembly code. Defining symbols in assembly code may lead to assembler and/or linker errors due to duplicate symbol definitions.
696+
697+
> **Note**: As a general rule, the flags covered by `preserves_flags` are those which are *not* preserved when performing a function call.
691698
692-
> **Note**: As a general rule, these are the flags which are *not* preserved when performing a function call.
699+
[local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels

0 commit comments

Comments
 (0)