I want to copy an image on an ARMv7 core. The naive implementation is to call memcpy per line.
for(i = 0; i < h; i++) {
memcpy(d, s, w);
s += sp;
d += dp;
}
I know that the following
d, dp, s, sp, w
are all 32-byte aligned, so my next (still quite naive) implementation was along the lines of
for (int i = 0; i < h; i++) {
uint8_t* dst = d;
const uint8_t* src = s;
int remaining = w;
asm volatile (
"1: \n"
"subs %[rem], %[rem], #32 \n"
"vld1.u8 {d0, d1, d2, d3}, [%[src],:256]! \n"
"vst1.u8 {d0, d1, d2, d3}, [%[dst],:256]! \n"
"bgt 1b \n"
: [dst]"+r"(dst), [src]"+r"(src), [rem]"+r"(remaining)
:
: "d0", "d1", "d2", "d3", "cc", "memory"
);
d += dp;
s += sp;
}
Which was ~150% faster than memcpy over a large number of iterations (on different images, so not taking advantage of caching). I feel like this should be nowhere near the optimum because I am yet to use preloading, but when I do I only seem to be able to make performance substantially worse. Does anyone have any insight here?