[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 2.0.0.21 (Windows/20090302) |
Hi,
> 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.
-Alex
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, (continued)
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, Paulo Marques, 2009/04/22
- [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, David Brown, 2009/04/22
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, Dale Whitfield, 2009/04/22
- [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, David Brown, 2009/04/22
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, Dale Whitfield, 2009/04/22
- [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, David Brown, 2009/04/22
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, Graham Davies, 2009/04/22
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, Dale Whitfield, 2009/04/22
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, Graham Davies, 2009/04/22
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, Paulo Marques, 2009/04/22
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t,
Alex Wenger <=
- Re: [avr-gcc-list] Re: Optimisation of bit set/clear in uint32_t, Dave Hylands, 2009/04/22