This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Compiler optimization?
- From: Chirag Wighe <chirag dot wighe at windriver dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 10 Jun 2003 17:41:13 -0700
- Subject: Compiler optimization?
Hi
I am an embedded developer and I am trying to understand the endian issues
with respect to compilers and how they access structure fields.
Consider a structure defined as follows
typedef struct _s1
{
UINT32 f;
UINT16 f1;
UINT16 f2;
} S1
;
and code something like this:
S1 s;
void foo (void)
{
s.f1 = 0x0123;
s.f2 = 0x4567;
}
Is it possible for an optimizing compiler to combine the two half word
writes into a single word write. The compiler will form a single 32 bit
immediate value and do a word write thus saving one write cycle. This would
however cause problems if the memory where the code is data is being stored
is defined with an endian attribute other than that of the CPU as it will
lead to a reversal of the order of the structure fields. In the code
compiled using GNU that I am using I have not seen this happen. I would
like to know if there are compilers doing this, if not whether it is
prohibited and how likely it is that such an optimization may be introduced
in the future.
I am not on the email list so I would appreciate it if you could copy my
email in any replies.
Thanks
Chirag Wighe
Software Development Engineer
Wind River Systems