avr-chat
[Top][All Lists]
Advanced

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

[avr-chat] Missed Optimisation ?


From: bob
Subject: [avr-chat] Missed Optimisation ?
Date: Tue, 01 Mar 2011 12:48:20 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4

Hi,

I have a very time-critcal routine where a 32-bit value is read serially
(bit-shift).
The code is very simple (runs in Port Change interrupt):

    if ((PINA & _BV(A2DDATA)) != 0)
        result |= 0x80000000;

    result >>= 1;

The disassembly of the OR  however is:


    if ((PINA & _BV(A2DDATA)) != 0)
 622:   01 9b           sbis    0x00, 1 ; 0
 624:   11 c0           rjmp    .+34            ; 0x648 <__vector_4+0x42>

        result |= 0x80000000;
 626:   80 91 5a 02     lds     r24, 0x025A
 62a:   90 91 5b 02     lds     r25, 0x025B
 62e:   a0 91 5c 02     lds     r26, 0x025C
 632:   b0 91 5d 02     lds     r27, 0x025D
 636:   b0 68           ori     r27, 0x80       ; 128
 638:   80 93 5a 02     sts     0x025A, r24
 63c:   90 93 5b 02     sts     0x025B, r25
 640:   a0 93 5c 02     sts     0x025C, r26
 644:   b0 93 5d 02     sts     0x025D, r27

The compiler has loaded all 4 bytes of the uint32_t, but only operated
on one of them, so it seems 'clever' enough to see that the immediate
value is full of '0' and not bother to OR the lower bytes but still
loads and saves them.

I have:

OPTIMIZE       = -Os -fno-inline

override CFLAGS        = -g -Wall -Wno-main $(OPTIMIZE)
-mmcu=$(MCU_TARGET) $(DEFS)

in my Makefile.

Am I missing something?

Regards,

Bob



reply via email to

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