0

So,I have two loops that I would like to attempt to do a 10 x 10 unrolling on. I really have never done this. I have seen some simple examples that did not involve if/else statements or nested loops. So I am kind of at a loss how to do this for these loops.

All the variables are int.

The first loop is:

     for (j=0; j < WIDTH; ++j) {
         for (i = 0; i < HEIGHT; ++i) {
            n = Calculate(prv, i, j);
            if (prv[i][j] && (n == 3 || n == 2))
               nxt[i][j] = true;
            else if (!prv[i][j] && (n == 3)) 
               nxt[i][j] = true;
            else
               nxt[i][j] = false;
         }
      }

I believe the secret is doing some sort of multiple accumulators, I am just not quite sure how that would look.

The second loop:

    for (ii = i_left; ii < i_right; ++ii) {
         for (jj = j_left; jj < j_right; ++jj) {
            n += b[ii][jj];
         }
      }

Again, I believe this too would involve some sort of multiple accumulator approach as well.

Any help getting started on this would be greatly appreciated. Also, if there are any other ways to optimize the loops, I would appreciate those suggestions as well.

Thank you

terrylt1
  • 67
  • 7
  • For the first loop, you move the if/else if/else logic into a function returning a boolean. It doesn't help with the mechanics of unrolling the loops, but reduces the inner loop to a single statement: `nxt[i][j] = NextGen(prv, i, j);`. – Ian Abbott Mar 02 '21 at 12:56
  • The first loop looks a lot like Conway's Game Of Life. Whether or not that's actually what you're doing, you could try a search for "optimizing conway's game of life" some inspiration. – fearless_fool Mar 02 '21 at 13:56

0 Answers0