* ARM Inline Assembler and 64 bit variables @ 2006-05-23 9:36 Wolfgang Haidinger 2006-06-01 7:57 ` Richard Earnshaw 0 siblings, 1 reply; 3+ messages in thread From: Wolfgang Haidinger @ 2006-05-23 9:36 UTC (permalink / raw) To: gcc-help Hi all, 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" ); Grüße Wolfgang Haidinger --- Wolfgang Haidinger B&R Industrie-Elektronik GmbH BU Controls, Safety Tel: +43 (0)7748 6586 1121 eMail: wolfgang.haidinger@br-automation.com ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ARM Inline Assembler and 64 bit variables 2006-05-23 9:36 ARM Inline Assembler and 64 bit variables Wolfgang Haidinger @ 2006-06-01 7:57 ` Richard Earnshaw 2006-06-01 7:59 ` Richard Earnshaw 0 siblings, 1 reply; 3+ messages in thread From: Richard Earnshaw @ 2006-06-01 7:57 UTC (permalink / raw) To: Wolfgang Haidinger; +Cc: Richard.Earnshaw, gcc-help > 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. ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ARM Inline Assembler and 64 bit variables 2006-06-01 7:57 ` Richard Earnshaw @ 2006-06-01 7:59 ` Richard Earnshaw 0 siblings, 0 replies; 3+ messages in thread From: Richard Earnshaw @ 2006-06-01 7:59 UTC (permalink / raw) To: Wolfgang Haidinger; +Cc: Richard.Earnshaw, gcc-help On Thu, 01 Jun 2006 08:56:59 BST, Richard Earnshaw wrote: > > > 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. > Incidentally, if you want the arithmetic average, the code you want is int64_t a,b,r; asm( "adds %Q0, %Q1, %Q2" "\n\t" "adcs %R0, %R1, %R2" "\n\t" "movs %R0, %R0, rrx" "\n\t" "mov %Q0, %Q0, rrx" : "=&r" (r) : "r" (a), "r" (b) : "cc" ); R. ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-06-01 7:59 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-05-23 9:36 ARM Inline Assembler and 64 bit variables Wolfgang Haidinger 2006-06-01 7:57 ` Richard Earnshaw 2006-06-01 7:59 ` Richard Earnshaw
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).