directives for optimised code (M.M._van_der_Laan)
Wed, 28 Jun 1995 11:23:16 GMT

          From comp.compilers

Related articles
directives for optimised code (1995-06-28)
Re: directives for optimised code (1995-07-05)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (M.M._van_der_Laan)
Keywords: design, question, comment
Organization: Compilers Central
Date: Wed, 28 Jun 1995 11:23:16 GMT

Maybe it is a good idea to tell the compiler if a portion of code
is likely to be executed or not. Look at the following code and
it's translation:

      --- source --- --- intermediate code ---
      if a < b if a < b, jump lab1
              error("A is less than B") call error(...)
      else jump lab2
            normal processing lab1: normal processing
      next statement lab2: next statement

This translation will execute a jump in every case. Jumps are
very slow on modern processors.

In the next fragment I added a directive {NO}, which instructs
the compiler to assume that the 'then'-part will be executed
less often than the 'else'-part:

      if a < b {no} if a < b, jump lab1
              error("A is less than B") normal processing
      else lab2: next statement
            normal processing ...
      next statement lab1: call error(...)
                                                                                      jump lab2

The compiler can now move code that will be executed less often
to the end of the function. There are several improvements here:

- jumps are removed, so code is dramatically faster.
- There is better use of the cache, because unneeded instructions
    are not loaded.

Questions to you all:

Is this a good idea? Are there any implementations allready using
this? What is the speed improvement?

Mauk van der Laan
[The original version of Fortran had a FREQUENCY statement that let
you give the relative frequency of the three branches of the IF
statement and how many times a DO loop was likely to run. It turned
out to be useless, they even implemented it backwards for a while and
nobody noticed. These days it's far more common to collect
statistics from executing a program and feed those back to the
compiler, since they're a lot more accurate than the programmer's
expectations. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.