Re: volatile function

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

 



On 25/01/2011 10:37, Cedric Roux wrote:
On 01/25/2011 09:04 AM, kevin diggs wrote:
Hi,

The function in question is returning the value of the PLL config
register in a PowerPC 750GX. I wanted to make sure that the optimizer
does not move or eliminate the call. I thought that is one of the uses
of the volatile qualifier???

Thanks!

kevin

static inline volatile unsigned int get_PLL(void)
{
unsigned int ret;

__asm__ __volatile__ ("mfspr %0,%1":
"=r"(ret):
"i"(SPRN_HID1)
);

return ret;
}

I think that SPRN_HID1 has to be declared as volatile
(if that has a meaning at all in your case) for gcc
to force the load in all cases (my .02 euros, I don't
know your target asm, I don't know what SPRN_HID1 is).


It's a PowerPC, and SPRN_HID1 is a constant (the "mfspr" instruction reads from a specified "special purpose register").

Drop the "volatile" on the function declaration, and then code is then correct. It is the "__volatile__" in the assembly statement that ensures the read cannot be eliminated.




[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