Alignment of strings, EGCS all versions, gcc 2.95.*, i386
Etienne LORRAIN
etienne_lorrain@yahoo.fr
Fri Nov 26 06:38:00 GMT 1999
Hello,
>> A very usefull soft:
bash-2.02$ cat alstr.c
void fct (char *param)
{
strcpy (param, "A very long string: 31 chars !");
}
>> let's optimise the size:
bash-2.02$ gcc -Os -S alstr.c
bash-2.02$ cat alstr.s
.file "alstr.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 32
LC0:
.ascii "A very long string: 31 chars !\0"
.align 4
.globl _fct
.def _fct; .scl 2; .type 32; .endef
_fct:
pushl %ebp
movl %esp,%ebp
pushl %edi
pushl %esi
movl 8(%ebp),%edi
movl $LC0,%esi
leal -8(%ebp),%esp
cld
movl $7,%ecx
rep
movsl
movsw
movsb
popl %esi
popl %edi
movl %ebp,%esp
popl %ebp
ret
bash-2.02$
>> my main concern is with this line:
.align 32
Wasting, lets say an average of 16 bytes, for each
string bigger than 31 chars (and some software have
*a lot of* them) for saving very few cycles is boring.
Most of those strings are a parameter of "printf" anyway...
There is no way (no switch) to remove such alignment.
In fact, this is more or less related to the message:
http://egcs.cygnus.com/ml/gcc-bugs/1999-11/msg00294.html
where there was no answer.
the alignment is done by macros "CONSTANT_ALIGNMENT"
and "DATA_ALIGNMENT" in gcc-2.95.1/gcc/varasm.c
IHMO those two macros should be removed from the
default configuration of GCC and a *sensible* default
value for the aligment of structures/arrays should
be calculated. Then, if the user wants to, he can
still set a very big, or very small, alignment of types
with "attribute((align()))". That would remove the need
of "attribute((packed))" for variables, which is
documented but does not work anyway.
Just hoping to be read,
Etienne.
___________________________________________________________
Do You Yahoo!?
Achetez, vendez! ÃÂ votre prix! Sur http://encheres.yahoo.fr
More information about the Gcc-bugs
mailing list