This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Code size
- To: Jan Hubicka <jh at suse dot cz>
- Subject: Code size
- From: Frank Klemm <pfk at fuchs dot offl dot uni-jena dot de>
- Date: Sun, 9 Sep 2001 15:55:47 +0200
- >Received: (from pfk@localhost)by fuchs.offl.uni-jena.de (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id PAA02638;Sun, 9 Sep 2001 15:55:47 +0200
- Cc: gcc at gcc dot gnu dot org
- References: <20010901202854.A7713@fuchs.offl.uni-jena.de> <20010902000000.C27182@atrey.karlin.mff.cuni.cz> <20010902024104.F7713@fuchs.offl.uni-jena.de> <20010903154513.C13574@atrey.karlin.mff.cuni.cz> <20010904003127.C335@fuchs.offl.uni-jena.de> <20010905133458.D15564@atrey.karlin.mff.cuni.cz> <20010905185526.A559@fuchs.offl.uni-jena.de> <20010906174007.B1486@atrey.karlin.mff.cuni.cz> <20010906222524.A2578@fuchs.offl.uni-jena.de> <20010907111641.G9651@atrey.karlin.mff.cuni.cz>
long long x;
void main (void)
{
x &= 100;
}
------------------------------------------------
Code with -Os (31 bytes + 7.5 bytes for alignment = 38.5 bytes on average)
.align 16
.global main
.type main,@function
main:
pushl %ebp
xorl %edx, %edx
movl %esp, %ebp
pushl %eax
pushl %eax
movl x, %eax
andl $-16, %esp
movl %edx, x+4
andl $100, %eax
movl %eax, x
leave
ret
-------------------------------------------------
Code with -Os -fomit-frame-pointer (31 bytes + 7.5 bytes for alignment = 38.5 bytes on average)
.align 16
.global main
.type main,@function
main:
pushl %ebp <---- incomprehensible
xorl %edx, %edx <---- okay
movl %esp, %ebp <---- incomprehensible
pushl %eax <---- incomprehensible
pushl %eax <---- incomprehensible
movl x, %eax <---- okay
andl $-16, %esp <---- incomprehensible
movl %edx, x+4 <---- okay
andl $100, %eax <---- okay
movl %eax, x <---- okay
leave <---- incomprehensible
ret <---- okay
-------------------------------------------------
Optimized code (14 bytes):
.text
.global main
.type main,@function
<---- no .align, we want optimize for size
main:
xorl %eax, %eax <---- xor r,r; mov r,(mem) is shorter than mov $0,(mem)
movl $x, %ecx <---- we have a free reg and x is accessed more than once
andl $100, (%ecx) <---- operation can be done directly in memory
movl %eax, 4(%ecx) <---- wipe memory
ret
May be the last two statements must be switched to improve speed.
--
Frank Klemm