* inline assembly & r0 SOS
@ 2008-08-06 0:20 Kevin Diggs
2008-08-06 0:35 ` Benjamin Herrenschmidt
2008-08-06 0:41 ` Jeremy Kerr
0 siblings, 2 replies; 6+ messages in thread
From: Kevin Diggs @ 2008-08-06 0:20 UTC (permalink / raw)
To: linuxppc-dev
Hi,
If I have:
inline unsigned int get_PLL_range(unsigned int range, unsigned int
config)
{
unsigned int ret;
/*
* Turn r3 (range) into a rotate count for the selected range.
* 0 -> 23, 1 -> 31
*/
__asm__ __volatile__ ( "slwi %0,%0,3\n"
"addi %0,%0,23\n"
"rlwnm %0,%1,%0,30,31\n":
"=r"(ret):
"r"(config),"0"(range)
);
return ret;
}
in a header and the resultant code generated is:
.L58:
li 0,1 # ratio,
mr 29,0 # ret, ratio
#APP
slwi 29,29,3 # ret
addi 29,29,21 # ret
rlwnm 29,28,29,27,31 # ret, ret
slwi 0,0,3 # ret
addi 0,0,23 # ret
rlwnm 0,28,0,30,31 # ret, ret
#NO_APP
thats bad right? Because the "addi 0, 0, 23" will not work as expected
because of the "special property" of r0. FYI: The first three lines
after the "#APP" are from a similar function get_PLL_ratio().
Is there a way to blacklist r0?
kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline assembly & r0 SOS
2008-08-06 0:20 inline assembly & r0 SOS Kevin Diggs
@ 2008-08-06 0:35 ` Benjamin Herrenschmidt
2008-08-06 0:41 ` Jeremy Kerr
1 sibling, 0 replies; 6+ messages in thread
From: Benjamin Herrenschmidt @ 2008-08-06 0:35 UTC (permalink / raw)
To: Kevin Diggs; +Cc: linuxppc-dev
On Tue, 2008-08-05 at 17:20 -0700, Kevin Diggs wrote:
> Hi,
>
> thats bad right? Because the "addi 0, 0, 23" will not work as expected
> because of the "special property" of r0. FYI: The first three lines
> after the "#APP" are from a similar function get_PLL_ratio().
>
> Is there a way to blacklist r0?
Yes. Use "b" instead of "r" in the constraints to force the compiler
to avoid r0 when assigning a register.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline assembly & r0 SOS
2008-08-06 0:20 inline assembly & r0 SOS Kevin Diggs
2008-08-06 0:35 ` Benjamin Herrenschmidt
@ 2008-08-06 0:41 ` Jeremy Kerr
2008-08-06 2:31 ` Kevin Diggs
1 sibling, 1 reply; 6+ messages in thread
From: Jeremy Kerr @ 2008-08-06 0:41 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Kevin Diggs
Hi Kevin,
> /*
> * Turn r3 (range) into a rotate count for the selected
> range. * 0 -> 23, 1 -> 31
> */
> __asm__ __volatile__ ( "slwi %0,%0,3\n"
> "addi %0,%0,23\n"
> "rlwnm %0,%1,%0,30,31\n":
> "=r"(ret):
> "r"(config),"0"(range)
> );
Wouldn't this be much simpler in plain C?
However, if you really do need to do this in inline asm, you can use
the "b" modifier rather than "r" to avoid using r0.
Cheers,
Jeremy
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline assembly & r0 SOS
2008-08-06 0:41 ` Jeremy Kerr
@ 2008-08-06 2:31 ` Kevin Diggs
2008-08-06 8:49 ` Andreas Schwab
0 siblings, 1 reply; 6+ messages in thread
From: Kevin Diggs @ 2008-08-06 2:31 UTC (permalink / raw)
To: Jeremy Kerr; +Cc: linuxppc-dev
Jeremy Kerr wrote:
> Hi Kevin,
>
>
>> /*
>> * Turn r3 (range) into a rotate count for the selected
>>range. * 0 -> 23, 1 -> 31
>> */
>> __asm__ __volatile__ ( "slwi %0,%0,3\n"
>> "addi %0,%0,23\n"
>> "rlwnm %0,%1,%0,30,31\n":
>> "=r"(ret):
>> "r"(config),"0"(range)
>> );
>
>
> Wouldn't this be much simpler in plain C?
>
I just knew someone was gonna try to rain on my rlwnm'in fun parade!
Wonder if the C code can be made to compile down to 3 instructions?
> However, if you really do need to do this in inline asm, you can use
> the "b" modifier rather than "r" to avoid using r0.
>
Oh cool! Thanks! You to Ben!
> Cheers,
>
>
> Jeremy
>
kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline assembly & r0 SOS
2008-08-06 2:31 ` Kevin Diggs
@ 2008-08-06 8:49 ` Andreas Schwab
2008-08-06 14:39 ` Segher Boessenkool
0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2008-08-06 8:49 UTC (permalink / raw)
To: Kevin Diggs; +Cc: linuxppc-dev, Jeremy Kerr
Kevin Diggs <kevdig@hypersurf.com> writes:
> Jeremy Kerr wrote:
>> Hi Kevin,
>>
>>
>>> /*
>>> * Turn r3 (range) into a rotate count for the selected
>>>range. * 0 -> 23, 1 -> 31
>>> */
>>> __asm__ __volatile__ ( "slwi %0,%0,3\n"
>>> "addi %0,%0,23\n"
>>> "rlwnm %0,%1,%0,30,31\n":
>>> "=r"(ret):
>>> "r"(config),"0"(range)
>>> );
>>
>>
>> Wouldn't this be much simpler in plain C?
>>
> I just knew someone was gonna try to rain on my rlwnm'in fun parade!
> Wonder if the C code can be made to compile down to 3 instructions?
This will do:
unsigned int get_PLL_range(unsigned int range, unsigned int config)
{
range = range * 8 + 23;
return ((config << range) | (config >> (32 - range))) & 3;
}
The special pattern ((a << n) | (a >> (32 - n))) is recognized by gcc as
a rotate operation.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: inline assembly & r0 SOS
2008-08-06 8:49 ` Andreas Schwab
@ 2008-08-06 14:39 ` Segher Boessenkool
0 siblings, 0 replies; 6+ messages in thread
From: Segher Boessenkool @ 2008-08-06 14:39 UTC (permalink / raw)
To: Andreas Schwab; +Cc: linuxppc-dev, Kevin Diggs, Jeremy Kerr
>>>> unsigned int get_PLL_range(unsigned int range, unsigned int config)
> {
> range = range * 8 + 23;
> return ((config << range) | (config >> (32 - range))) & 3;
> }
>
> The special pattern ((a << n) | (a >> (32 - n))) is recognized by
> gcc as
> a rotate operation.
It's only valid for 1 <= n <= 31 though, so for input "range" 0 or 1.
(*)
If that's the whole range needed, much simpler code is possible...
Segher
(*) or 0xffffffff or 0xfffffffe, but somehow I doubt that was intended.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-08-06 14:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-06 0:20 inline assembly & r0 SOS Kevin Diggs
2008-08-06 0:35 ` Benjamin Herrenschmidt
2008-08-06 0:41 ` Jeremy Kerr
2008-08-06 2:31 ` Kevin Diggs
2008-08-06 8:49 ` Andreas Schwab
2008-08-06 14:39 ` Segher Boessenkool
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).