When to use the early level constraint in the advanced GCC built-in assembly?

I understand when to use the list of shoemakers (for example, listing the register that was changed in the assembly so that it is not selected for use as an input register, etc.), but I can not wrap my head around the restriction of early clobber & . If you list your outputs, does this mean that the inputs cannot use the selected register (in addition to the corresponding value restrictions)?

For instance:

 asm( "movl $1, %0;" "addl $3, %0;" "addl $4, %1;" "addl %1, %0;" : "=g"(num_out) : "g"(num_in) : ); 

Is & required for output variables? The compiler must know the register that was selected for output, and therefore should not use it for input.

+4
source share
1 answer

By default, the compiler assumes that all inputs will be consumed before any output registers are written, to allow the use of the same registers for both. This leads to better code when possible, but if the assumption is wrong, everything will be catastrophically catastrophic. The β€œearly clober” marker is a way to tell the compiler that this output will be written before all input is consumed, so it cannot share the register with any input.

+10
source

All Articles