Skip to content

Commit 58a301e

Browse files
authored
Merge pull request #1126 from Amanieu/x87
Clarify behavior of x87 FP registers in inline assembly
2 parents cdb6520 + 153617b commit 58a301e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/inline-assembly.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ To avoid undefined behavior, these rules must be followed when using function-sc
460460
- Vector extension state (`vtype`, `vl`, `vcsr`).
461461
- On x86, the direction flag (DF in `EFLAGS`) is clear on entry to an asm block and must be clear on exit.
462462
- Behavior is undefined if the direction flag is set on exiting an asm block.
463+
- On x86, the x87 floating-point register stack must remain unchanged unless all of the `st([0-7])` registers have been marked as clobbered with `out("st(0)") _, out("st(1)") _, ...`.
464+
- If all x87 registers are clobbered then the x87 register stack is guaranteed to be empty upon entering an `asm` block. Assembly code must ensure that the x87 register stack is also empty when exiting the asm block.
463465
- The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting an `asm!` block.
464466
- This means that `asm!` blocks that never return (even if not marked `noreturn`) don't need to preserve these registers.
465467
- 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*.

0 commit comments

Comments
 (0)