avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] poor optimisation


From: Rob Ward
Subject: [avr-libc-dev] poor optimisation
Date: Mon, 18 Nov 2002 10:31:03 +1300
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826

Hi. I think I have an example of some very poor avr-gcc optimisation. I have pasted my c code below, followed by a .lst listing. I have also included my makefile at the end.


c code ...

SIGNAL(SIG_OVERFLOW0) { // signal handler for tcnt0 overflow interrupt - SIGNAL disables interrupts u08 DataHigh, DataMid, DataLow; // 3 bytes to hold 19 bits to send to 3972

 outp(Timer0Interval, TCNT0);

if (InConfigMode == TRUE) { // At startup, we are InConfigMode so we can send the 19 config bits.
   InConfigMode = FALSE;               // Enter here only once at startup
   DataHigh = 0x80;
   DataMid  = 0x30;
   DataLow  = 0x01;
 }
 else {
   if (StepDirn == CCW) {
     DataHigh = PRG_RDB(&WordHighCCW[StepPos]);
     DataMid  = PRG_RDB(&WordMidCCW[StepPos]);
     DataLow  = PRG_RDB(&WordLowCCW[StepPos]);
   }
   else { // step direction is clockwise
     DataHigh = PRG_RDB(&WordHighCW[StepPos]);
     DataMid  = PRG_RDB(&WordMidCW[StepPos]);
     DataLow  = PRG_RDB(&WordLowCW[StepPos]);
   }
 }

SetStrobeLow(); // set strobe low to initiate data transfer

if (DataHigh & 0x80) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataHigh & 0x40) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataHigh & 0x20) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataHigh & 0x10) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataHigh & 0x08) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataHigh & 0x04) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataHigh & 0x02) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataHigh & 0x01) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow();

if (DataMid & 0x80) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataMid & 0x40) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataMid & 0x20) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataMid & 0x10) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataMid & 0x08) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataMid & 0x04) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataMid & 0x02) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataMid & 0x01) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow();

if (DataLow & 0x04) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataLow & 0x02) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow(); if (DataLow & 0x01) SetDataHigh(); else SetDataLow(); SetClockHigh(); SetClockLow();

SetStrobeHigh(); // reset strobe to high to terminate data transfer

 StepCompleted = TRUE;
}




and here is the .lst output

note all the (lots of) wasted rom space because of these...
14a:    c0 98           cbi     0x18, 0 ; 24
14c:    c3 cf           rjmp    .-122           ; 0xd4



///////////////////////////////////////////////////////////////////
SIGNAL(SIG_OVERFLOW0) {                 // signal handler for tcnt0 overflow 
interrupt - SIGNAL disables interrupts
  0:    1f 92           push    r1
  2:    0f 92           push    r0
  4:    0f b6           in      r0, 0x3f        ; 63
  6:    0f 92           push    r0
  8:    11 24           eor     r1, r1
  a:    2f 93           push    r18
  c:    3f 93           push    r19
  e:    8f 93           push    r24
 10:    9f 93           push    r25
 12:    ef 93           push    r30
 14:    ff 93           push    r31
 u08 DataHigh, DataMid, DataLow;       // 3 bytes to hold 19 bits to send to 
3972

 outp(Timer0Interval, TCNT0);
 16:    80 91 00 00     lds     r24, 0x0000
 1a:    82 bf           out     0x32, r24       ; 50

 if (InConfigMode == TRUE) {           // At startup, we are InConfigMode so we 
can send the 19 config bits.
 1c:    80 91 00 00     lds     r24, 0x0000
 20:    81 30           cpi     r24, 0x01       ; 1
 22:    09 f4           brne    .+2             ; 0x26
 24:    c1 c0           rjmp    .+386           ; 0x1a8
   InConfigMode = FALSE;               // Enter here only once at startup
   DataHigh = 0x80;
   DataMid  = 0x30;
   DataLow  = 0x01;
 }
 else {
   if (StepDirn == CCW) {
 26:    80 91 00 00     lds     r24, 0x0000
 2a:    81 30           cpi     r24, 0x01       ; 1
 2c:    09 f4           brne    .+2             ; 0x30
 2e:    a3 c0           rjmp    .+326           ; 0x176
     DataHigh = PRG_RDB(&WordHighCCW[StepPos]);
     DataMid  = PRG_RDB(&WordMidCCW[StepPos]);
     DataLow  = PRG_RDB(&WordLowCCW[StepPos]);
   }
   else { // step direction is clockwise
     DataHigh = PRG_RDB(&WordHighCW[StepPos]);
 30:    80 91 00 00     lds     r24, 0x0000
 34:    e8 2f           mov     r30, r24
 36:    ff 27           eor     r31, r31
 38:    e0 50           subi    r30, 0x00       ; 0
 3a:    f0 40           sbci    r31, 0x00       ; 0
 3c:    c8 95           lpm
 3e:    90 2d           mov     r25, r0
     DataMid  = PRG_RDB(&WordMidCW[StepPos]);
 40:    80 91 00 00     lds     r24, 0x0000
 44:    e8 2f           mov     r30, r24
 46:    ff 27           eor     r31, r31
 48:    e0 50           subi    r30, 0x00       ; 0
 4a:    f0 40           sbci    r31, 0x00       ; 0
 4c:    c8 95           lpm
 4e:    20 2d           mov     r18, r0
     DataLow  = PRG_RDB(&WordLowCW[StepPos]);
 50:    80 91 00 00     lds     r24, 0x0000
 54:    e8 2f           mov     r30, r24
 56:    ff 27           eor     r31, r31
 58:    e0 50           subi    r30, 0x00       ; 0
 5a:    f0 40           sbci    r31, 0x00       ; 0
 5c:    c8 95           lpm
 5e:    30 2d           mov     r19, r0
   }
 }

 SetStrobeLow();                       // set strobe low to initiate data 
transfer
 60:    96 98           cbi     0x12, 6 ; 18

 if (DataHigh & 0x80) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 62:    97 ff           sbrs    r25, 7
 64:    86 c0           rjmp    .+268           ; 0x172
 66:    c0 9a           sbi     0x18, 0 ; 24
 68:    97 9a           sbi     0x12, 7 ; 18
 6a:    97 98           cbi     0x12, 7 ; 18
 if (DataHigh & 0x40) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 6c:    89 2f           mov     r24, r25
 6e:    99 27           eor     r25, r25
 70:    86 ff           sbrs    r24, 6
 72:    7d c0           rjmp    .+250           ; 0x16e
 74:    c0 9a           sbi     0x18, 0 ; 24
 76:    97 9a           sbi     0x12, 7 ; 18
 78:    97 98           cbi     0x12, 7 ; 18
 if (DataHigh & 0x20) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 7a:    85 ff           sbrs    r24, 5
 7c:    76 c0           rjmp    .+236           ; 0x16a
 7e:    c0 9a           sbi     0x18, 0 ; 24
 80:    97 9a           sbi     0x12, 7 ; 18
 82:    97 98           cbi     0x12, 7 ; 18
 if (DataHigh & 0x10) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 84:    84 ff           sbrs    r24, 4
 86:    6f c0           rjmp    .+222           ; 0x166
 88:    c0 9a           sbi     0x18, 0 ; 24
 8a:    97 9a           sbi     0x12, 7 ; 18
 8c:    97 98           cbi     0x12, 7 ; 18
 if (DataHigh & 0x08) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 8e:    83 ff           sbrs    r24, 3
 90:    68 c0           rjmp    .+208           ; 0x162
 92:    c0 9a           sbi     0x18, 0 ; 24
 94:    97 9a           sbi     0x12, 7 ; 18
 96:    97 98           cbi     0x12, 7 ; 18
 if (DataHigh & 0x04) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 98:    82 ff           sbrs    r24, 2
 9a:    61 c0           rjmp    .+194           ; 0x15e
 9c:    c0 9a           sbi     0x18, 0 ; 24
 9e:    97 9a           sbi     0x12, 7 ; 18
 a0:    97 98           cbi     0x12, 7 ; 18
 if (DataHigh & 0x02) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 a2:    81 ff           sbrs    r24, 1
 a4:    5a c0           rjmp    .+180           ; 0x15a
 a6:    c0 9a           sbi     0x18, 0 ; 24
 a8:    97 9a           sbi     0x12, 7 ; 18
 aa:    97 98           cbi     0x12, 7 ; 18
 if (DataHigh & 0x01) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 ac:    80 ff           sbrs    r24, 0
 ae:    53 c0           rjmp    .+166           ; 0x156
 b0:    c0 9a           sbi     0x18, 0 ; 24
 b2:    97 9a           sbi     0x12, 7 ; 18
 b4:    97 98           cbi     0x12, 7 ; 18

 if (DataMid  & 0x80) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 b6:    27 ff           sbrs    r18, 7
 b8:    4c c0           rjmp    .+152           ; 0x152
 ba:    c0 9a           sbi     0x18, 0 ; 24
 bc:    97 9a           sbi     0x12, 7 ; 18
 be:    97 98           cbi     0x12, 7 ; 18
 if (DataMid  & 0x40) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 c0:    82 2f           mov     r24, r18
 c2:    99 27           eor     r25, r25
 c4:    86 ff           sbrs    r24, 6
 c6:    43 c0           rjmp    .+134           ; 0x14e
 c8:    c0 9a           sbi     0x18, 0 ; 24
 ca:    97 9a           sbi     0x12, 7 ; 18
 cc:    97 98           cbi     0x12, 7 ; 18
 if (DataMid  & 0x20) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 ce:    85 ff           sbrs    r24, 5
 d0:    3c c0           rjmp    .+120           ; 0x14a
 d2:    c0 9a           sbi     0x18, 0 ; 24
 d4:    97 9a           sbi     0x12, 7 ; 18
 d6:    97 98           cbi     0x12, 7 ; 18
 if (DataMid  & 0x10) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 d8:    84 ff           sbrs    r24, 4
 da:    35 c0           rjmp    .+106           ; 0x146
 dc:    c0 9a           sbi     0x18, 0 ; 24
 de:    97 9a           sbi     0x12, 7 ; 18
 e0:    97 98           cbi     0x12, 7 ; 18
 if (DataMid  & 0x08) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 e2:    83 ff           sbrs    r24, 3
 e4:    2e c0           rjmp    .+92            ; 0x142
 e6:    c0 9a           sbi     0x18, 0 ; 24
 e8:    97 9a           sbi     0x12, 7 ; 18
 ea:    97 98           cbi     0x12, 7 ; 18
 if (DataMid  & 0x04) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 ec:    82 ff           sbrs    r24, 2
 ee:    27 c0           rjmp    .+78            ; 0x13e
 f0:    c0 9a           sbi     0x18, 0 ; 24
 f2:    97 9a           sbi     0x12, 7 ; 18
 f4:    97 98           cbi     0x12, 7 ; 18
 if (DataMid  & 0x02) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
 f6:    81 ff           sbrs    r24, 1
 f8:    20 c0           rjmp    .+64            ; 0x13a
 fa:    c0 9a           sbi     0x18, 0 ; 24
 fc:    97 9a           sbi     0x12, 7 ; 18
 fe:    97 98           cbi     0x12, 7 ; 18
 if (DataMid  & 0x01) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
100:    80 ff           sbrs    r24, 0
102:    19 c0           rjmp    .+50            ; 0x136
104:    c0 9a           sbi     0x18, 0 ; 24
106:    97 9a           sbi     0x12, 7 ; 18
108:    97 98           cbi     0x12, 7 ; 18

 if (DataLow  & 0x04) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
10a:    83 2f           mov     r24, r19
10c:    99 27           eor     r25, r25
10e:    82 ff           sbrs    r24, 2
110:    10 c0           rjmp    .+32            ; 0x132
112:    c0 9a           sbi     0x18, 0 ; 24
114:    97 9a           sbi     0x12, 7 ; 18
116:    97 98           cbi     0x12, 7 ; 18
 if (DataLow  & 0x02) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
118:    81 ff           sbrs    r24, 1
11a:    09 c0           rjmp    .+18            ; 0x12e
11c:    c0 9a           sbi     0x18, 0 ; 24
11e:    97 9a           sbi     0x12, 7 ; 18
120:    97 98           cbi     0x12, 7 ; 18
 if (DataLow  & 0x01) SetDataHigh(); else SetDataLow();  SetClockHigh(); 
SetClockLow();
122:    80 ff           sbrs    r24, 0
124:    02 c0           rjmp    .+4             ; 0x12a
126:    c0 9a           sbi     0x18, 0 ; 24
128:    45 c0           rjmp    .+138           ; 0x1b4
12a:    c0 98           cbi     0x18, 0 ; 24
12c:    43 c0           rjmp    .+134           ; 0x1b4
12e:    c0 98           cbi     0x18, 0 ; 24
130:    f6 cf           rjmp    .-20            ; 0x11e
132:    c0 98           cbi     0x18, 0 ; 24
134:    ef cf           rjmp    .-34            ; 0x114
136:    c0 98           cbi     0x18, 0 ; 24
138:    e6 cf           rjmp    .-52            ; 0x106
13a:    c0 98           cbi     0x18, 0 ; 24
13c:    df cf           rjmp    .-66            ; 0xfc
13e:    c0 98           cbi     0x18, 0 ; 24
140:    d8 cf           rjmp    .-80            ; 0xf2
142:    c0 98           cbi     0x18, 0 ; 24
144:    d1 cf           rjmp    .-94            ; 0xe8
146:    c0 98           cbi     0x18, 0 ; 24
148:    ca cf           rjmp    .-108           ; 0xde
14a:    c0 98           cbi     0x18, 0 ; 24
14c:    c3 cf           rjmp    .-122           ; 0xd4
14e:    c0 98           cbi     0x18, 0 ; 24
150:    bc cf           rjmp    .-136           ; 0xca
152:    c0 98           cbi     0x18, 0 ; 24
154:    b3 cf           rjmp    .-154           ; 0xbc
156:    c0 98           cbi     0x18, 0 ; 24
158:    ac cf           rjmp    .-168           ; 0xb2
15a:    c0 98           cbi     0x18, 0 ; 24
15c:    a5 cf           rjmp    .-182           ; 0xa8
15e:    c0 98           cbi     0x18, 0 ; 24
160:    9e cf           rjmp    .-196           ; 0x9e
162:    c0 98           cbi     0x18, 0 ; 24
164:    97 cf           rjmp    .-210           ; 0x94
166:    c0 98           cbi     0x18, 0 ; 24
168:    90 cf           rjmp    .-224           ; 0x8a
16a:    c0 98           cbi     0x18, 0 ; 24
16c:    89 cf           rjmp    .-238           ; 0x80
16e:    c0 98           cbi     0x18, 0 ; 24
170:    82 cf           rjmp    .-252           ; 0x76
172:    c0 98           cbi     0x18, 0 ; 24
174:    79 cf           rjmp    .-270           ; 0x68
176:    80 91 00 00     lds     r24, 0x0000
17a:    e8 2f           mov     r30, r24
17c:    ff 27           eor     r31, r31
17e:    e0 50           subi    r30, 0x00       ; 0
180:    f0 40           sbci    r31, 0x00       ; 0
182:    c8 95           lpm
184:    90 2d           mov     r25, r0
186:    80 91 00 00     lds     r24, 0x0000
18a:    e8 2f           mov     r30, r24
18c:    ff 27           eor     r31, r31
18e:    e0 50           subi    r30, 0x00       ; 0
190:    f0 40           sbci    r31, 0x00       ; 0
192:    c8 95           lpm
194:    20 2d           mov     r18, r0
196:    80 91 00 00     lds     r24, 0x0000
19a:    e8 2f           mov     r30, r24
19c:    ff 27           eor     r31, r31
19e:    e0 50           subi    r30, 0x00       ; 0
1a0:    f0 40           sbci    r31, 0x00       ; 0
1a2:    c8 95           lpm
1a4:    30 2d           mov     r19, r0
1a6:    5c cf           rjmp    .-328           ; 0x60
1a8:    10 92 00 00     sts     0x0000, r1
1ac:    90 e8           ldi     r25, 0x80       ; 128
1ae:    20 e3           ldi     r18, 0x30       ; 48
1b0:    38 2f           mov     r19, r24
1b2:    56 cf           rjmp    .-340           ; 0x60
1b4:    97 9a           sbi     0x12, 7 ; 18
1b6:    97 98           cbi     0x12, 7 ; 18

 SetStrobeHigh();                      // reset strobe to high to terminate 
data transfer
1b8:    96 9a           sbi     0x12, 6 ; 18

 StepCompleted = TRUE;
1ba:    81 e0           ldi     r24, 0x01       ; 1
1bc:    80 93 00 00     sts     0x0000, r24
}
1c0:    ff 91           pop     r31
1c2:    ef 91           pop     r30
1c4:    9f 91           pop     r25
1c6:    8f 91           pop     r24
1c8:    3f 91           pop     r19
1ca:    2f 91           pop     r18
1cc:    0f 90           pop     r0
1ce:    0f be           out     0x3f, r0        ; 63
1d0:    0f 90           pop     r0
1d2:    1f 90           pop     r1
1d4:    18 95           reti

000001d6 <__vector_8>:








and here is my makefile ...

CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
CFLAGS=-g -mmcu=at90s4433
RM = rm
SOURCES = demo.c
OBJECTS = demo.o
TARGETS = rom.hex demo.out

all : rom.hex steppr01.lst

rom.hex : steppr01.out
        $(OBJCOPY) -j .text -O srec steppr01.out rom.hex

steppr01.out : steppr01.o
        $(CC) $(CFLAGS) -o steppr01.out -Wl,-Map,steppr01.map steppr01.o -lm
# -lm above links in the math library needed for sqrt() fn.

steppr01.o : steppr01.c
        $(CC) $(CFLAGS) -Os -c steppr01.c

steppr01.lst : steppr01.o
        $(OBJDUMP) -S steppr01.o > steppr01.lst

clean:
        -$(RM) $(OBJECTS)

realclean:
        -$(RM) $(OBJECTS)
        -$(RM) $(TARGETS)






Thanks in advance.

Rob Ward







reply via email to

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