This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Code enlargement
- To: gcc at gcc dot gnu dot org
- Subject: Code enlargement
- From: Frank Klemm <pfk at fuchs dot offl dot uni-jena dot de>
- Date: Sat, 1 Sep 2001 14:18:17 +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 OAA01522for gcc@gcc.gnu.org; Sat, 1 Sep 2001 14:18:17 +0200
C-Code:
...1
if ( x == 0 ) {
...2
}
...3
return;
gcc2.95:
...1
cmpl $0,x
jne lbl
...2
lbl: ...3
ret
gcc3.0 tends to code this like (also with -Os):
...1
cmpl $0,x
je lbl1
lbl2: ...3
ret
lbl1: ...2 \ code
jmp lbl2 / junks
Problems:
- code is at least 2 byte longer (2 jumps instead of 1 jump)
- code often is 9 byte longer (distance becomes larger than
-128...+127 bytes, so a 'Jcc long' (6 byte) and 'JMP long'
(5 byte) is needed.
Solutions:
- avoid this trick with '-Os', may be also with '-O2', because speed
increase is very little, zero or below zero. Brnach prediction
seems to work very well.
- avoid trick especially if jump distance is too long compared with
the nontricky code.
- Insert the code junks as early as possible (after every jmp this
is possible, or before the function start). But be carefully to
avoid other code increases inside the function
- if code is small and target is Pentium Pro, II, III, 4, Duron, Athlon
often a conditional-mov works well (especially if the conditional
expression is highly inpredictable).
if ( expect (x>12,0) ) // condition is seldom true
if ( expect (x>12,1) ) // condition is very often true
The current expect() syntax don't allow to describe a condition
which is high unpredictable so that jumps should be avoided and cmov's
should be used if possible.
--
Frank Klemm