[ILUG] a quick gcc microoptimisation question

Justin Mason jm at jmason.org
Thu Dec 16 18:32:48 GMT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


HiLUG,

quickie: when using gcc's -O switches, what is more efficient:

    if (condition) {
      /* more common case */
    } else {
      /* less common case */
    }

or 

    if (condition) {
      /* less common case */
    } else {
      /* more common case */
    }

??

I know there is/was a tool that using coverage/profile data to optimise
branching and cache locality of code, but is there a technique to do this
efficiently without requiring that and the profiling runs it'd require?
In other words, with gcc optimisation, is the branch instruction used for
the "if" case or the "else" case by default?

- --j.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Exmh CVS

iD8DBQFBwdTPMJF5cimLx9ARAsohAKCC2+vKsZjd97sSCCxQSRfUj40DWwCfZpI/
aLxsAxjjL4Yahxbn1PDcm6g=
=KERp
-----END PGP SIGNATURE-----




More information about the ILUG mailing list