[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Use of variables and programming in avr-gcc
From: |
Robert Rozman |
Subject: |
Re: [avr-gcc-list] Use of variables and programming in avr-gcc |
Date: |
Mon, 19 Mar 2001 09:55:18 +0100 |
Hello,
thanks Jorg for explanation. Carried by those advices I got an idea to keep
all global variables in struct, hoping that Z will point to them with
displacement and I'll save quite some bytes cause global variables are
accessed frequently.
But then I discovered that Z register is loaded again and again prior each
access through Z with displacement. This behaviour makes this approach non
oseful, but I still think that maybe somehow different I can get compiler to
optimize away those redundant loading of Z register.
I've used following program:
typedef struct {
char day;
char hour;
char min;
char sec;
} time_struct;
time_struct global ;
time_struct *time = &global;
char day;
char hour;
char min;
char sec;
int main(void)
{
day = 5;
hour= 9;
min = 10;
sec =10;
time->day = 5;
time->hour= 9;
time->min = 10;
time->sec =10;
for (;;) {} /* loop forever */
-----------------------------------------------
and I got:
44:test1.c **** day = 5;
75 .stabn 68,0,44,.LM2-main
76 .LM2:
77 0008 95E0 ldi r25,lo8(5)
78 000a 9093 0000 sts day,r25
45:test1.c **** hour= 9;
79 .stabn 68,0,45,.LM3-main
80 .LM3:
81 000e 29E0 ldi r18,lo8(9)
82 0010 2093 0000 sts hour,r18
46:test1.c **** min = 10;
83 .stabn 68,0,46,.LM4-main
84 .LM4:
85 0014 8AE0 ldi r24,lo8(10)
86 0016 8093 0000 sts min,r24
47:test1.c **** sec =10;
87 .stabn 68,0,47,.LM5-main
88 .LM5:
89 001a 8093 0000 sts sec,r24
48:test1.c ****
49:test1.c **** time->day = 5;
90 .stabn 68,0,49,.LM6-main
91 .LM6:
92 001e E091 0000 lds r30,time
93 0022 F091 0000 lds r31,(time)+1
94 0026 9083 st Z,r25
50:test1.c **** time->hour= 9;
95 .stabn 68,0,50,.LM7-main
96 .LM7:
97 0028 E091 0000 lds r30,time
98 002c F091 0000 lds r31,(time)+1
99 0030 2183 std Z+1,r18
51:test1.c **** time->min = 10;
100 .stabn 68,0,51,.LM8-main
101 .LM8:
102 0032 E091 0000 lds r30,time
103 0036 F091 0000 lds r31,(time)+1
104 003a 8283 std Z+2,r24
52:test1.c **** time->sec =10;
105 .stabn 68,0,52,.LM9-main
106 .LM9:
107 003c E091 0000 lds r30,time
108 0040 F091 0000 lds r31,(time)+1
109 0044 8383 std Z+3,r24
--------------------------------------
It can be seen that all but first loading register Z are redundant. If
compiler would optimize them away one could save a lot of bytes of coding
space when globals are frequently accessed.
So I kindly ask for advice, what I'm doing wrong in definition of struct or
pointer. I surely don't believe that avr-gcc is not capable of optimizing
such redundants away (in example I used -Os, but also -O3 doesn't change
things).
Thanks in advance,
Robert Rozman
}
-----Izvorno sporočilo-----
Od: Robert Rozman <address@hidden>
Za: address@hidden <address@hidden>
Datum: 1. marec 2001 12:06
Zadeva: [avr-gcc-list] Use of variables and programming in avr-gcc
>Hello,
>
>I'm relatively newbie to avr-gcc. I've not found any reference/advice on
>how to declare variables and how to use them in avr-gcc. Ther is only
>one Application note on atmel site about efficient programming in C, but
>it is for one of commercial compilers.
>
>I've several question and I'd kindly ask if someone from more
>experienced guys is willing to organize his experience in few sentences
>of advice to novice users. Among other I have few specific questions:
>- do recomendations from mentioned application note apply also for
>avr-gcc ? if not, what should be done differently ?
>- what declaration keywords are really implemented and what is their
>effect (const, register, volatile, ...) and how exactly to use them ?
>- is it better to keep SRAM variables in structures - as APP note
>recomends) or not ?
>
>I'd kindly ask for answers in code space and also from speed point of
>view.
>
>Thanks in advance and special thanks to all guys working on avr-gcc,
>
>Robert Rozman
>
>
>
>_______________________________________________
>avr-gcc-list mailing list
>address@hidden
>http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list