linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* question on inline assembly and long long values
@ 2005-04-06 18:26 Chris Friesen
  2005-04-06 19:16 ` Kumar Gala
  2005-04-06 23:19 ` Benjamin Herrenschmidt
  0 siblings, 2 replies; 11+ messages in thread
From: Chris Friesen @ 2005-04-06 18:26 UTC (permalink / raw)
  To: linuxppc-dev

I want to retrieve the msr (which is 64-bits) on a 970 when running in 
32-bit mode.  I have the following bit of code that seems to work, but 
when looking at the code it always seems to use a suboptimal register 
for the low word, and then it ends up having to copy it to the right 
register to create a long long register pair.

static inline unsigned long long get_msr()
{
	union {
		struct {
			unsigned long low;
			unsigned long high;
		} words;
		unsigned long long val;
	} val;
         asm volatile( \
                 "mfmsr  %0               \n\t" \
                 "rldicl %1,%0,32,32       \n\t" \
                 "rldicl %0,%0,0,32        \n\t" \
                 : "=r" (val.words.low), "=r" (val.words.high));
	return val.val;
}

Using this code, the optimised assembly output of

	unsigned long long a = asdf();
	unsigned long long b = asdf();

is

	mfmsr  5
	rldicl 0,5,32,32
	rldicl 5,5,0,32
	mr 6,0
	mfmsr  7
	rldicl 9,7,32,32
	rldicl 7,7,0,32
	mr 8,9

I figure it should have been able to use registers 6/8 in the first 
place, and save the extra moves.

Is there any way to help gcc optimise this?


Chris

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-04-07  0:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-06 18:26 question on inline assembly and long long values Chris Friesen
2005-04-06 19:16 ` Kumar Gala
2005-04-06 20:01   ` Chris Friesen
2005-04-06 21:18     ` Gabriel Paubert
2005-04-06 21:37       ` Chris Friesen
2005-04-06 23:19 ` Benjamin Herrenschmidt
2005-04-06 23:30   ` Chris Friesen
2005-04-06 23:49     ` Benjamin Herrenschmidt
2005-04-06 23:56       ` Chris Friesen
2005-04-06 23:57         ` Benjamin Herrenschmidt
2005-04-07  0:09           ` Chris Friesen

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 NNTP newsgroup(s).