The reversal of a loop can be obtained with a scattering function as shown in this page.

CLooG input for a sample 2D loop is as follows:

c # language is C

1 4                   # 1 lines and 4 columns
# eq/in m  n  1
    1   0  0  0       # 0 >= 0, always true

1 # We want to set manually the parameter names
m n                   # parameter names

# --------------------- STATEMENTS --------------------
1 # Number of statements

1 # First statement
4 6                   # 3 lines and 5 columns
# eq/in i  j  m  n  1
    1   1  0  0  0 -1    # i >= 1
    1  -1  0  0  1  0    # i <= n
    1   0  1  0  0 -1    # j >= 1
    1   0 -1  1  0  0    # j <= m
0  0  0               # for future options


1 # We want to set manually the scattering dimension names
i j                 # scattering dimension names

# --------------------- SCATTERING --------------------
1 # Scattering functions
4 10    
# eq/in p1  p2  p3  p4  i  j  n  m  1 
    0    1   0  0   0   0  0  0  0  0    
    0    0   1  0   0  -1  0  0  0  0    
    0    0   0  1   0   0  0  0  0  0    
    0    0   0  0   1   0 -1  0  0  0    
0

The output of CLooG is

if (m >= 1) {
  for (c2=1;c2<=n;c2++) {
    for (c4=1;c4<=m;c4++) {
      S1(i = c2,j = c4) ;
    }
  }
}

To reverse the inner loop, scattering function has to be changed to

# --------------------- SCATTERING --------------------
1 # Scattering functions
4 10    
# eq/in p1  p2  p3  p4  i  j  n  m  1 
    0    1   0  0   0   0  0  0  0  0    
    0    0   1  0   0  -1  0  0  0  0    
    0    0   0  1   0   0  0  0  0  0    
    0    0   0  0   1   0  1  0  0  0    

Now the output of CLooG becomes:

if (m >= 1) {
  for (c2=1;c2<=n;c2++) {
    for (c4=-m;c4<=-1;c4++) {
      S1(i = c2,j = -c4) ;
    }
  }
}

None: Graphite/Reversal (last edited 2010-07-31 14:28:42 by 202)