question on inline assembly and long long values
Gabriel Paubert
paubert at iram.es
Thu Apr 7 07:18:43 EST 2005
On Wed, Apr 06, 2005 at 02:01:20PM -0600, Chris Friesen wrote:
> Kumar Gala wrote:
> >I'm having a similar need (for a different purpose), this post might be
> >useful:
> >
> >http://gcc.gnu.org/ml/gcc/2005-04/msg00283.html
>
> Sweet! My new code is now shorter *and* more efficient:
>
> static inline unsigned long long getmsr()
> {
> unsigned long long val;
> asm volatile( \
> "mfmsr %L0 \n\t" \
> "rldicl %0,%L0,32,32 \n\t" \
> "rldicl %L0,%L0,0,32 \n\t" \
> : "=r" (val));
> return val;
> }
>
> This results in
>
> unsigned long long a = asdf3();
> unsigned long long b = asdf3();
>
> being compiled to
>
> mfmsr 6
> rldicl 5,6,32,32
> rldicl 6,6,0,32
>
> mfmsr 8
> rldicl 7,8,32,32
> rldicl 8,8,0,32
If you are running in 32 bit mode, you don't need
to clear the upper half of %L0. The architecture is
designed so that pure 32 bit code runs unmodified despite
the fact that you can access the upper 32 bits using
64 bit instructions.
Regards,
Gabriel
More information about the Linuxppc-dev
mailing list