You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/doc/unstable-book/src/library-features/asm.md
+10-3
Original file line number
Diff line number
Diff line change
@@ -427,6 +427,8 @@ Several types of operands are supported:
427
427
- The substituted string does not include any modifiers (e.g. GOT, PLT, relocations, etc).
428
428
-`<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.
429
429
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
+
430
432
## Register operands
431
433
432
434
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:
438
440
- Floating-point numbers
439
441
- Pointers (thin only)
440
442
- 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).
442
444
443
445
Here is the list of currently supported register classes:
444
446
@@ -667,7 +669,6 @@ The compiler performs some additional checks on options:
667
669
- These flags registers must be restored upon exiting the asm block if the `preserves_flags` option is set:
668
670
- x86
669
671
- Status flags in `EFLAGS` (CF, PF, AF, ZF, SF, OF).
670
-
- Direction flag in `EFLAGS` (DF).
671
672
- Floating-point status word (all).
672
673
- Floating-point exception flags in `MXCSR` (PE, UE, OE, ZE, DE, IE).
673
674
- ARM
@@ -682,11 +683,17 @@ The compiler performs some additional checks on options:
682
683
- Floating-point status (`FPSR` register).
683
684
- RISC-V
684
685
- 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.
685
688
- The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting an `asm!` block.
686
689
- This means that `asm!` blocks that never return (even if not marked `noreturn`) don't need to preserve these registers.
687
690
- 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*.
688
691
- You cannot exit an `asm!` block that has not been entered. Neither can you exit an `asm!` block that has already been exited.
689
692
- You are responsible for switching any target-specific state (e.g. thread-local storage, stack bounds).
690
693
- 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.
691
698
692
-
> **Note**: As a general rule, these are the flags which are *not* preserved when performing a function call.
0 commit comments