This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How to make asm constraints for member variables?
sorry a correction
it's taking the address of a member variable which gcc complains about. So
"m" (this->member) //OK
"m" (&this->member) //Error
"m" (this->member.somearray) //Error
I really wanted to do #3. The class has an aggregate member, containing
arrays. I wand to load the beginning of the array in the member.
This situation is compatible with an offsettable operand (constant
offset to the this pointer), and gcc generates correct code for its own
code, but doesn't let me do it by hand.
no luck either with the "c" constraint:
"can't find register in class CREG while reloading asm"
"asm operand has impossible constraints"
Ian Lance Taylor - iant@google.com wrote:
Christian SchÃler <gcchelp.5.adept@0sg.net> writes:
I'd like to make an asm statement emit offset-register addressing like this:
movl 0x80(eax), ebx
where eax contains the pointer to a class (this) and 0x80 is the offset to a
member variable.
I get an error when assigning the member variable to a memory reference.
asm( "mov %[source], %[dest]"
: [dest] "=r" (...)
: [souce] "m" (this->member) ); // ERROR "memory input is not directly
addressable"
Try using
"p" (&this->member)
That might work.
Also, decomposing by hand always put a "$" in front of the offset rendering it
unusable, eg.
asm( "mov %[offset](%[base]), %[dest]"
: [dest] "=r" (...)
: [base] "r" (this), [offset] "p" (offsetof(member)) );
generates
movl $0x80(eax), ebx // ERROR "Junk..."
where assembler complains about the dollar sign.
For this sort of approach you want "c", not "p".
Ian