[Top][All Lists]

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

Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t

From: Alex Wenger
Subject: Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t
Date: Wed, 22 Apr 2009 14:51:29 +0200
User-agent: Thunderbird (Windows/20090302)


> There is every reason. The flags get updated in interrupt routines and
> in non-interrupt code.
>> Try the following version of set_status:
>> void set_status(uint32_t flag, uint8_t set) {
>>      if (set) *(uint32_t* &status) |= flag;
>>      else *(uint32_t* &status) &= ~flag;
>>      asm("" : : : "memory");
>> }
>> First, we remove the "volatile" from status so that the optimiser can  
>> give you a single byte access when the function is inlined.  Secondly,  
>> instead of using "volatile" to protect the access to "status", we use a  
>> memory clobber that forces writes to memory variables to be completed  
>> before going on.  This will ensure that the change is written out to  
>> status as soon as possible (otherwise changes could be cached for later  
>> storage).
> Which would be a problem, since the volatile nature of the variable is
> important in this usage.

Why? The memory clobber does exactly what you need for using it in an
interrupt and outside.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]