Ahah!

I believe I might have a possible hacky workaround!

Instead of doing:

static void mul(int[] accum, int accumOffset, int[] src, int srcOffset, int 
n) {
    for (int ii = 0; ii < n; ++ii) {
        accum[ii + accumOffset] *= src[ii + srcOffset];
    }
}

do

static void mul(int[] accum, int accumOffset, int[] src, int srcOffset, int 
n) {
    var diff = srcOffset - accumOffset;
    rotate(accum, diff);
    for (int ii = 0; ii < n; ++ii) {
        accum[ii + accumOffset] *= src[ii + srcOffset];
    }
    rotate(accum, -diff);
}


where rotate rotates the array in place and so avoids expensive allocations 
(and does the same amounts of copies as allocating temporaries would.)

I can see how rotating once can be done in place (and using 
System.arraycopy so it could be fast.)

static void shiftOnce(int[] array) {
    var len = array.length;
    var start = array[0];
    System.arraycopy(array, 0, array, 1, len - 1);
    array[0] = start;
}

But I can't really see a good way of rotating an array in place for higher 
counts (I doubt repeated iteration would be good.)

I'll still need to benchmark but this might be good.

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to