110. Summing two arrays unrolled via the Vector API
In this problem, we take the example of summing two arrays from the previous problem and re-write the loop in an unrolled fashion.
Loop unrolling can be applied manually (as we will do here) or by the compiler, and it stands for an optimization technique meant to reduce the loop iteration count.
In our case, in order to reduce the loop iteration count, we use more vectors to repeat the sequence of loop body statements that are responsible for summing the items. If we know that our arrays are long enough to always require at least 4 loop iterations, then rewriting the code as follows will reduce the loop iterations by 4 times:
public static void sumUnrolled(int x[], int y[], int z[]) {
int width = VS256.length();
int i = 0;
for (; i <= (x.length - width * 4); i += width * 4) {
IntVector s1 = IntVector.fromArray(VS256, x, i)
.add(IntVector.fromArray(VS256, y, i));
IntVector s2 = IntVector.fromArray(VS256...