Manual optimization of main loop.

The C18 compiler does not unroll loops. For loops
over indexed arrays are very expensive, so manually
unrolling these loops gives us a big performance
boost.