This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Major deficiency in optimising memset calls
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: Daniel Egger <degger at fhm dot edu>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 14 Oct 2004 19:50:37 +0200
- Subject: Re: Major deficiency in optimising memset calls
- References: <0CCB3484-1DE5-11D9-AE4A-000A958E35DC@fhm.edu>
> Hija,
> Next try:
> char a[8]
>
> int main (void)
> {
> __builtin_memset (a, 1, 8);
> }
>
> will result in:
> pushl %ebp
> movl $16843009, %eax
> movl %esp, %ebp
> subl $8, %esp
> movl $16843009, %edx
> andl $-16, %esp
> movl %eax, a+4
> subl $16, %esp
> movl %edx, a
> leave
> ret
>
> on linux-i686 compiled with gcc-3.4 -c -march=i686 -mtune=i686 -O2.
> Let's call that in interesting result.
GCC can inline only memset of 0 at the moment. Fixing this would involve
adding new named pattern instead of current clrstr and would ineed be
nice thing to do ;)
> aforementioned gcc call on i686 will result in:
> main:
> pushl %ebp
> xorl %eax, %eax
> movl %esp, %ebp
> pushl %edi
> cld
> subl $4, %esp
> movl $a, %edi
> movl $3, %ecx
> andl $-16, %esp
> subl $16, %esp
> rep
> stosl
> movl -4(%ebp), %edi
> leave
> ret
>
> The rep;stosl sequence seems somewhat okay to me for a simply
> inline sequence to clear a larger or only at runtime known
> amount of memory, however for under 16 bytes this seems like a
> clear loss in performance and code size to me.
This is because GCC won't align the array to neccesary boundary by
default at the moment (I believe).
I think this has been changed quite recently to allow sharing across
string constants...
Perhaps even for missaligned stores the sequence is better (at least for
athlon based chips) so having some knob for this would be nice.
I am not sure whether GCC will do that, but if you force the alignment
to be higher, it should be possible to track it down via MEM_ATTRs.
Honza