This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: volatile function
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
On Tue, Jan 25, 2011 at 12:06 AM, Ian Lance Taylor <iant@google.com> wrote:
> kevin diggs <diggskevin38@gmail.com> writes:
>
>> I may be wearing out my welcome, but:
>>
>> I tried to use (in a header file):
>>
>> /**
>> * get_PLL: - return current value of PLL register (HID1)
>> *
>> * This returns the current value of the PLL configuration register (HID1).
>> */
>> static inline volatile unsigned int get_PLL(void)
>> {
>> unsigned int ret;
>>
>> __asm__ __volatile__ ("mfspr %0,%1":
>> "=r"(ret):
>> "i"(SPRN_HID1)
>> );
>>
>> return ret;
>> }
>>
>> to make sure that this function did not get moved or optimized away.
>> 4.1.2 generated a warning (Linux kernel compile: warning -> error).
>>
>> cc1: warnings being treated as errors
>> In file included from arch/powerpc/kernel/cpu/cpufreq/cf750gx.c:37:
>> /mnt/mnt3/linux-2.6.36/arch/powerpc/include/asm/pll.h:84: warning:
>> type qualifiers ignored on function return type
>
> The warning is correct: volatile is ignored on a function return type.
> To avoid the warning, write
> static inline unsigned int get_PLL(void)
>
> If that does not answer your question, what are you trying to do?
>
> Ian
>