News for hackers. Stuff that matters.
Re:Duke Nukem 3D Code Review by chris_wot on Friday February 15, 2013 @06:24AM (#5225625)
I'm curious - and excuse me for my ignorance - but what is "unrolling code"?

http://fabiensanglard.net/duke3d/duke3d_code_review_unrolled...

Re:Duke Nukem 3D Code Review by pavlov on Friday February 15, 2013 @10:37AM (#5226629)
Usually it simply means repeating the loop body N times so that the amount of loop iterations can be reduced to 1/N.

For example, if you know that the iteration count is divisible by 4, you could do something like:

  int unrolledN = n / 4;
  for (int unrolledI = 0; unrolledI < unrolledN; unrolledI++) {
    int i = unrolledI * 4;
    // loop body...
    i++;
    // loop body...
    i++;
    // loop body...
    i++;
    // loop body...
  }
This wouldn't really offer any advantage over the plain loop, though. Next you'd need to reorganize the loop body so that e.g. memory reads for all iterations would occur at the start of the unrolled loop. This kind of optimizations can offer significant performance increases because you get more control over what the CPU is doing within the loop, but they also depend greatly on the target platform. Even different x86 processors can be very different in this respect, so unrolling can become a disoptimization easily.
Re:Duke Nukem 3D Code Review by zapu on Friday February 15, 2013 @09:19AM (#5226236)
In this case he sort of replaces some function calls with bodies of these functions, so the actual program flow would be clearer to read.
Re:Duke Nukem 3D Code Review by lotharbot on Friday February 15, 2013 @11:33AM (#5226958)
Broadly speaking, it's removing flow control from the code in order to make it easier to read or faster to execute.

In this case, I think he's replaced function calls with the body of those functions. For example, "displayrooms" is immediately followed by { } surrounding the contents of what "displayrooms" actually does: interpolate, animate, and so on. This means you can read just the one source file and know what's being executed, instead of having to read the source of displayrooms.c and various other source files separately.

Another common form of "unrolling" is repeating the body of a loop some number of times. See, for example, http://en.wikipedia.org/wiki/Duff%27s_device . Basically, by reducing the number of branches (and therefore potential pipeline flushes) you can decrease computation time.

Re:Duke Nukem 3D Code Review by Hurdy on Friday February 15, 2013 @06:44AM (#5225683)
I think what he means here is that all the code that is abstracted into functions etc. is "unrolled" (at some sensible level) into one main function so you can see the complete flow of the program without searching around.
Re:Duke Nukem 3D Code Review by paines on Friday February 15, 2013 @06:30AM (#5225642)
Not sure, but it could be something like Duff's Device. Look it up, it can be used for various things, like drawing and stuff.