This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Inline assembly - how to get gcc to clear the full rcx register in x86-64 mode


I have ported an SSE4 strcmp function from
to GCC inline assembly:

long __res;
__asm__ __volatile__(
"sub $16, %4 \n"
"add $16, %4 \n"
"movdqu (%4), %%xmm0 \n" // Could use any XMM, using register constraint "x"
// ".byte 0x48 \n" // REX prefix with REX.w=1, to get result in RCX
"pcmpistri $0x18, (%4,%0), %%xmm0 \n" // EQUAL_EACH(0x08) + NEGATIVE_POLARITY(0x10)
"ja 1b \n"
"jc 2f \n"
"xor %0, %0 \n"
"jmp 3f \n" // XXX Extra jump could be avoided in pure asm
"add %4, %0 \n"
"movzxb (%0,%1), %0 \n"
"movzxb (%4,%1), %4 \n"
"sub %4, %0 \n"
: "=a"(__res), "=c"(cs) : "0"(cs-ct), "1"(0L), "r"(ct) : "xmm0" );

return (int) __res;

The problem with this code is that "pcmpistri" returns its result in ECX (i.e. the lower 32 bits of RCX), while the "movzxb" instructions use the full RCX register.
One solution is to insert a REX prefix with REX.w bit set ( any gas directive for this? )

However, I'd prefer to have gcc clear RCX at the beginning of the function. The above code loads the "c" register with 0, but the resulting asm code is
"xorl ecx, ecx"

Is this a bug in GCC? Or how do I get it to clear the full RCX, without doing it 'manually' in the asm block?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]