Inline assembly constraints question
Jeroen Demeyer
jdemeyer@cage.ugent.be
Wed Aug 20 13:47:00 GMT 2008
Ian Lance Taylor wrote:
> Jeroen Demeyer <jdemeyer@cage.ugent.be> writes:
>
>> I have a C++ program (i386 target) which has a piece of inline
>> assembly with the following constraints:
>>
>> asm(/* Some asm code */
>> : "=&rm" (n0), "=&r" (n1), "=&r" (n2)
>> : "2" (n0), "1" (n1), "g" (n2), "cI" (s)
>> );
>>
>> When compiled with g++ 4.1.2 (CXXFLAGS=-O2 -march=pentium4) the
>> operands %0 and %5 get the same memory address, even though they refer
>> to distinct variables (n0 and n2).
>
> It would help to see the types of the variables. Is n2 a pointer?
> Also it would help to see the actual values that wind up getting
> passed in.
n0, n1, n2 are unsigned long (members of the same C++ class, the asm
statement is in a member function), s is unsigned char.
> I think more details would help. For example, run gcc with the -dg
> option, look at FILENAME.xxx.greg, and show us the insn corresponding
> to the asm statement.
This is the full asm statement:
asm("# number_t& number_t::operator>>=(unsigned char s)\n"
" shrdl %6, %4, %3\n"
" movl %3, %0\n"
" movl %5, %2\n"
" shrdl %6, %2, %1\n"
" shrl %6, %2\n"
: "=&rm" (n0), "=&r" (n1), "=&r" (n2)
: "2" (n0), "1" (n1), "g" (n2), "cI" (s)
);
The code generated is the following:
shrdl %cl, %esi, %eax
movl %eax, -4384(%ebp)
movl -4384(%ebp), %eax
shrdl %cl, %eax, %esi
shrl %cl, %eax
As you can see, %0 and %5 both become -4384(%ebp).
See attachment for the output from -dg.
I hope this clarifies the problem.
Thank you!
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.cpp.37.greg
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20080820/2558a342/attachment.ksh>
More information about the Gcc-help
mailing list