I've been trying to optimize some simple code and I try two kind of optimizations, loop enrolling and memory aliasing.
My original code:
int paint(char *dst, unsigned n, char *src, char bias)
{
unsigned i;
for (i=0;i<n;i++) {
*dst++ = bias + *src++;
}
return 0;
}
My optimizated code after loop enrolling:
int paint(char *dst, unsigned n, char *src, char bias)
{
unsigned i;
for (i=0;i<n;i+=2) {
*dst++ = bias + *src++;
*dst++ = bias + *src++;
}
return 0;
}
How after this I can optimize the code with memory aliasing? And there are another good optimizations for this code? (Like cast the pointers to long pointers to copy quickly)