GCC Advanced Asm - Understanding Clot and Scratch Use

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)?

+4
source share
1 answer

What is the added value of this code compared to the other?

""? , , , ( clobber memory).

: , . , , :

  • , . , r.
  • , asm , *x *y . m.

%3 %1, m . . %1 - %r0 %eax, %3 (%r0), (%eax) some_symbol. , .

+3

Source: https://habr.com/ru/post/1694347/


All Articles