From the GCC documentation regarding Extended ASM - Clobbers and Scratch Registers, I find it difficult to understand the following explanation and example:
Here is a dummy sum of squared instructions that takes two pointers to floating point values in memory and creates floating output. Note that x and y both appear twice in asm, once to indicate access to memory, and once to indicate the base register used by asm.
Well, the first part understood, now the proposal continues:
Usually you don’t spend registering by doing this, since GCC can use the same register for both purposes. However, it would be foolish to use both% 1 and% 3 for x in this asm and expect them to be the same. In fact,% 3 may well not be case sensitive. This may be a symbolic memory reference to the object pointed to by x.
Lost me.
Example:
asm ("sumsq %0, %1, %2"
: "+f" (result)
: "r" (x), "r" (y), "m" (*x), "m" (*y));
What does the example and the second part of the sentence tell us? What is the added value of this code compared to the other? will this code lead to a more efficient memory dump (as explained earlier in this chapter)?
source
share