[Top][All Lists]

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

Re: [avr-chat] Missed Optimisation ?

From: Alex Eremeenkov
Subject: Re: [avr-chat] Missed Optimisation ?
Date: Tue, 01 Mar 2011 14:35:21 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; uk; rv: Gecko/20101207 Thunderbird/3.1.7

Hello Bob,

Did you sure that compiler *must* determine that for OR operation only one byte changing and load only part of value instead of all 32 bits? It's a simple optimization stuff according assemble set, but according initial logical operation with 32bit value it's a correct code. Compiler save at least 3 other 'ori' commands. BTW, you simply could optimize your routie by doing OR command on MSB byte only by itself.

01.03.2011 13:48, bob writes:

I have a very time-critcal routine where a 32-bit value is read serially
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?



AVR-chat mailing list

reply via email to

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