Register Usage

A large program usually has more data that would benefit from being held in registers than there are registers to hold the data. In such cases, Visual Fortran typically tries to use the registers according to the following descending priority list:

  1. For temporary operation results, including array indexes
  2. For variables
  3. For addresses of arrays (base address)
  4. All other usages

Visual Fortran uses heuristic algorithms and a modest amount of computation to attempt to determine an effective usage for the registers.

Holding Variables in Registers

Because operations using registers are much faster than using memory, Visual Fortran generates code that uses the integer and floating-point registers instead of memory locations. Knowing when Visual Fortran uses registers may be helpful when doing certain forms of debugging.

Visual Fortran uses registers to hold the values of variables whenever the Fortran language does not require them to be held in memory, such as holding the values of temporary results of subexpressions, even if /optimize:0 (no optimization) was specified.

Visual Fortran may hold the same variable in different registers at different points in the program:

  V = 3.0*Q
    .
    .
    .
  X = SIN(Y)*V
    .
    .
    .
  V = PI*X
    .
    .
    .
  Y = COS(Y)*V

Visual Fortran may choose one register to hold the first use of V and another register to hold the second. Both registers can be used for other purposes at points in between. There may be times when the value of the variable does not exist anywhere in the registers. If the value of V is never needed in memory, it might not ever be assigned.

Visual Fortran uses registers to hold the values of I, J, and K (so long as there are no other optimization effects, such as loops involving the variables):

  A(I) = B(J) + C(K)

More typically, an expression uses the same index variable:

  A(K) = B(K) + C(K)

In this case, K is loaded into only one register, which is used to index all three arrays at the same time.