Convolution function
all I wanted was a circular buffer

Consider using an array accessed with mod.
That is, assign size s = k.length - 1,
allocate a &quot;previous&quot; array p,
and then access p[i % s].
If you're lucky, the compiler may notice that
a portion of the code is just copying,
and it will issue memcpy instructions.