[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: About g++ optimization
From: |
address@hidden |
Subject: |
Re: About g++ optimization |
Date: |
1 Apr 2006 09:02:19 -0800 |
User-agent: |
G2/0.2 |
If you're doing more powerful optimizations, such as IPA based, its
likely you will be doing loop unrolling as well. And after loop
unrolling, they should generate code identical code.
> Saves usually a register and replaces a check against an 'arbitrary'
> number with a check for zero (which is faster/smaller on some
> architectures).
Say for a minute, that f(n) returned a constant and IPCP could replace
the f(n) with a constant, say 5.
For example:
for (int i = 5; i--; )
On x86, gcc would generate for your example:
movl $4, %ebx
L1:
decl %ebx
.... ; loop body
cmpl $-1, %ebx
jne L1
where mine would be:
xorl %ebx, %ebx
L1:
incl %ebx
.... ; loop body
cmpl $5, %ebx
jne L1
'Technically', my code would be faster because zeroing out ebx is
cheaper than a move. :)
Anyways, my point is that I avoid doing 'micro' optimizations because
it does not always make the code faster, and it usually makes the code
slightly harder to read.
Regards,
Ryan Mansfield