Embedding assembly in C with compiler search registers for you

When embedding assembler code in a C / C ++ program, you can avoid scrambling registers by saving them using the push command (or specifying a compiler compiler list).

If you turn on the inline assembly and want to avoid the overhead of pushing and popping scrambled registers, is there a way to let gcc select the registers for you (for example, those that it knows do not have any useful information in them).

+3
source share
3 answers

. , ( ) , . . . , :

asm("your assembly instructions"
      : output1("=a"),  // I want output1 in the eax register
        output2("=r"),  // output2 can be in any general-purpose register
        output3("=q"),  // output3 can be in eax, ebx, ecx, or edx
        output4("=A")   // output4 can be in eax or edx
      : /* inputs */
      : /* clobbered registers */
   );
+9

intrinsics - C/++. , , ( ). , .

, C , . ,

struct TwoVectors
{
   __m128 a; __m128b;
}

// adds two vectors A += B using the native SSE opcode
inline void SimdADD( TwoVectors *v ) 
{
   v->a = _mm_add_ps( v->a , v->b ); // compiles directly to ADDSS opcode
}
0

, , , ( ):

asm ( "your assembly instructions"
    : "=a"(output1),
      "=r"(output2),
      "=q"(output3),
      "=A"(output4)
    : /* inputs */
    : /* clobbered registers */
);

, , / (.. , ). clobber (, "% xmm1", "% rcx" ), , , . , .

0
source

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


All Articles