Re: ARM Inline Assembler and 64 bit variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> is it possible to use the inline assembler of GCC for arm elf target in
> conjunction with 64 bit variables?

> I tried the following example (arithmetic average), but with little
> success! 

> uint64_t        a,b,r; asm(
>         "adds   %A0,    %A1,    %A2"            "\n\t"
>         "adds   %B0,    %B1,    %B2"            "\n\t"
>         "mov    %B0,    %B0,    rrx"            "\n\t"
>         "mov    %A0,    %A0,    rrx"
>         : "=r" (r) : "r" (a), "r" (b) : "cc" );


Yes, it is, but you need to use the right operand modifiers (these vary by 
target).

On ARM the modifiers for accessing 64-bit types are

%<n> The lowest numbered register of a pair
%H<n> The highest numbered register of a pair
%Q<n> The register containing the least significant part of the 32-bit 
value
%R<n> The register containing the most significant part of the 32-bit value

Why so many?  Well it depends on whether you want your code to compile 
correctly for big-endian as well as little-endian systems.

So your test case above should probably read something like

int64_t        a,b,r;
asm(
        "adds   %Q0,    %Q1,    %Q2"            "\n\t"
        "adds   %R0,    %R1,    %R2"            "\n\t"
        "mov    %R0,    %R0,    rrx"            "\n\t"
        "mov    %Q0,    %Q0,    rrx"
        : "=&r" (r) : "r" (a), "r" (b) : "cc"
);

Note the use of =&r in the constraint for the variable 'r'.  This ensures 
that your input operands won't be corrupted before they have been fully 
read.

R.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux