From cb411c1ff34a72bedaa53bf571936de7f379b2b1 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sat, 1 Jan 2022 22:40:30 +0100 Subject: [PATCH 1/2] Clarify behavior of x87 FP registers in inline assembly --- src/inline-assembly.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/inline-assembly.md b/src/inline-assembly.md index b95f5e003..2570df0fd 100644 --- a/src/inline-assembly.md +++ b/src/inline-assembly.md @@ -460,6 +460,8 @@ To avoid undefined behavior, these rules must be followed when using function-sc - Vector extension state (`vtype`, `vl`, `vcsr`). - On x86, the direction flag (DF in `EFLAGS`) is clear on entry to an asm block and must be clear on exit. - Behavior is undefined if the direction flag is set on exiting an asm block. +- On x86, the x87 floating-point register stack must remain unchanged unless all of the `st(*)` registers have been marked as clobbered. + - 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. - The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting an `asm!` block. - This means that `asm!` blocks that never return (even if not marked `noreturn`) don't need to preserve these registers. - 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*. From 153617b13ef52b88ab7671a2bae4776507325f4f Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sun, 2 Jan 2022 20:57:43 +0100 Subject: [PATCH 2/2] Address review feedback --- src/inline-assembly.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inline-assembly.md b/src/inline-assembly.md index 2570df0fd..9846c1561 100644 --- a/src/inline-assembly.md +++ b/src/inline-assembly.md @@ -460,7 +460,7 @@ To avoid undefined behavior, these rules must be followed when using function-sc - Vector extension state (`vtype`, `vl`, `vcsr`). - On x86, the direction flag (DF in `EFLAGS`) is clear on entry to an asm block and must be clear on exit. - Behavior is undefined if the direction flag is set on exiting an asm block. -- On x86, the x87 floating-point register stack must remain unchanged unless all of the `st(*)` registers have been marked as clobbered. +- 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)") _, ...`. - 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. - The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting an `asm!` block. - This means that `asm!` blocks that never return (even if not marked `noreturn`) don't need to preserve these registers.