This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Inline assembly and ldm/stm
Bryce Schober writes:
> On 4/10/07, Andrew Haley <aph@gcc.gnu.org> wrote:
> > Sure, but there's nothing to stop him picking two named register
> > variables.
>
> Following Andrew's hint, the following works:
>
> typedef struct
> {
> int reg[2];
> } arm_2_registers_t;
>
> static inline
> arm_2_registers_t arm_2_registers_load(
> int *src_addr_ptr )
> {
> register int result_0 __asm__ ("r3");
> register int result_1 __asm__ ("r4");
> arm_2_registers_t result;
> __asm__ __volatile__ (
> "ldmia %0, {%1,%2} \n\t"
> : "+r" (src_addr_ptr), "=r" (result_0), "=r" (result_1)
> );
> result.reg[0] = result_0;
> result.reg[1] = result_1;
> return( result );
> }
> It's still pretty sub-optimal, though, since the registers have to be
> specified, which could lead to a bunch of register-to-register moving
> when using several functions like this. It'd be a bit better as a
> macro that could take the register names as arguments.
True.
> It's too bad that the assembler can't just make the right choice for
> us... It doesn't seem like *that* hard a problem...
Well, it would require at least a partial rewrite of gcc's register
allocator. It depends what you mean by "hard", I guess. ;-)
Andrew.