This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: problem in extended asm
- From: "Dave Korn" <dk at artimi dot com>
- To: "'Ankit Jain'" <ankitjain1580 at yahoo dot com>
- Cc: "'gcc'" <gcc at gcc dot gnu dot org>
- Date: Thu, 12 Aug 2004 12:31:38 +0100
- Subject: RE: problem in extended asm
> -----Original Message-----
> From: Ankit Jain
> Sent: 11 August 2004 17:11
> To: Dave Korn
> Subject: RE: problem in extended asm
>
> :) well i also know it gives error
But not once in this entire conversation did you ever tell anyone what the
error message actually says! :-O
> but what i was asking is cant we use that variable
> there in some way?
Right, now we're getting down to it! Well, of course you can use that
variable _some_ way... it's just a matter of doing it the right way.
> > > for(i=0;i<8;i++)
> > > {
> > > asm("movq i(%1),%%mm0 \n"/my question lies in this line
> > > "movq %%mm0,(%0)
> > > :"=r"(x) //x is a pointer to another array
> > > :"r"(m)); //m is a pointer to array a
> > > }
Now, my question to you is, what ever made you think that using 'i' like
that was possible in the first place? You seem to have realised that the
assembly language can't access the other two variables, 'm' and 'x' without
passing them in to the asm as input or output operands and using
%-substitution. Why did you think it would be any different for 'i'?
>like if i use $_i or something like
> that...because when i tried that then it is also not
> working
Well, because you didn't give us a whole working code example, it isn't
obvious, but I'd guess that 'i' is a local variable rather than a global
one, and therefore it isn't stored in a constant memory location but in a
stack slot or register. So no symbol exists for it. Gcc would have put it
somewhere that your assembly code could get at it - but only if you told gcc
that you it wanted to do that by naming 'i' as an input operand to your asm.
Also, given that 'i' is a variable, not a constant, you can't use the
syntax you've written there. "movq <something>(%<reg>),<src>" is only
valid when <something> is a numeric integer constant; that's indexed
addressing. You want to add a variable, 'i', which is going to have to be
in a register, so you want to use the base plus index form "movq
(%<basereg>,%<indexreg>),<src>".
So, given all the above, how does this version work for you ?
for(i=0;i<8;i++)
{
asm("movq (%2,%1),%%mm0 \n"
"movq %%mm0,(%0) \n"
: "=r"(x)
: "r"(m), "r"(i));
}
I haven't tested it, but it does what you *think* that you wanted the
other one to do. Your other bug, the one where you're going to get
misaligned quadword access exceptions because you haven't taken account of
the fact that in order to access an array you have to multiply the element
index by the sizeof the array members, I leave as an exercise for the
reader.
cheers,
DaveK
--
Can't think of a witty .sigline today....