Explanation for clobber list in extended GCC inline assembly executing the x87 FPATAN operation
assembly, c, gcc, inline-assembly, x86
Solution
This is explained in the GCC documentation on inline asm (see section 6.41.2 about i386 floating point):
Given a set of input registers that die in an asm, it is necessary to know which are implicitly popped by the asm, and which must be explicitly popped by GCC.
An input register that is implicitly popped by the asm must be explicitly clobbered, unless it is constrained to match an output operand.
In this case, the `fpatan` operation pops both inputs and pushes the output, so we clobber `st(1)` to indicate this. We need to clobber only `st(1)` and not `st(0)` because `st(0)` is constrained to an output operand.
Problem
The following code is in the MinGW x86inline.h file: ``` /* ** in-line atan2(y,x) function. ** Computes arctan(y/x). */ #define atan2(y,x) atan2_x87_inline(y,x) double atan2_x87_inline(double y,double x); extern __inline__ double atan2_x87_inline(double y,double x) { double result; __asm__ ("fpatan" : "=t" (result) : "0" (x), "u" (y) : "st(1)"); return(result); } ``` As I understand, the x87 `fpatan` operation uses the `st(0)` and `st(1)` registers, overwrites the contents of the `st(1)` register, and then pops the top register. So why is only `st(1)` included in the clobber list, as opposed to `st(0)` as well? EDIT: In fact, why would it need a clobber list at all since `st(0)` and `st(1)` should be known to the compiler via the `"t"` and `"u"` constraints. Is that right?