avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] Optimiser bloats code


From: Wouter van Gulik
Subject: [avr-gcc-list] Optimiser bloats code
Date: Tue, 31 Jul 2007 22:07:18 +0200

Hello list,

After some testing on bit inversion etc if thought I found the most optimal
code.
But the optimiser came in to play and start doing things I don't understand.

I attached the files. I use WinAVR-20070525 and default MFile makefile
(except I build for a mega644)
Most shocking is the example in the bottom. The optimiser decides to init
with PINB&(1<<5) instead of 0.
Ok, but it makes a mess of getting the that bit on bit 0...

I also noted that on all functions r25 is cleared, but the value is returned
in r24, right? I am returning an 8 bit value, not a 16 bit? What's going on?

Hope you can help,

Wouter van Gulik

====================== Generated ASM Code =====================

//Not bit inverted, optimiser goes bloating BIG TIME
//Ofcourse something like "temp = (PINB >> 5)&0x7;" would be better
//But this is a test case
uint8_t foo2(void) { //worst
  c4:   83 b1           in      r24, 0x03       ; 3
  c6:   99 27           eor     r25, r25
  c8:   25 e0           ldi     r18, 0x05       ; 5
  ca:   96 95           lsr     r25
  cc:   87 95           ror     r24
  ce:   2a 95           dec     r18
  d0:   e1 f7           brne    .-8             ; 0xca <foo2+0x6>
  d2:   81 70           andi    r24, 0x01       ; 1
  
  uint8_t temp = 0;  
  if(PINB & (1<<5)) temp |= (1<<0);
  if(PINB & (1<<6)) temp |= (1<<1);
  d4:   1e 99           sbic    0x03, 6 ; 3
  d6:   82 60           ori     r24, 0x02       ; 2
  if(PINB & (1<<7)) temp |= (1<<2);
  d8:   1f 99           sbic    0x03, 7 ; 3
  da:   84 60           ori     r24, 0x04       ; 4

  return temp;
}
  dc:   99 27           eor     r25, r25
<<===============  WHY??? ====================
  de:   08 95           ret

Attachment: main.lss
Description: Binary data

Attachment: test.c
Description: Binary data


reply via email to

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