In my C code I have
complex float M[n][n];
complex float *delta = malloc(n * sizeof *delta);
complex float *v = malloc(n * sizeof *v);
for (i = 0; i < n; i++) {
v[i] -= 2.*delta[j]*M[j][i];
}
where i and n are ints.
It was suggested I use __builtin_assume_aligned to make sure these are aligned in order to help auto-vectorization. However, having looked at the docs I don't understand how to do that.
How would you use it for this code?
The code in this question is extracted from How to help gcc vectorize C code . This is also why I want to try to align things.
__builtin_assume_aligned is just a hint for gcc that the pointer is already aligned, so that it can typically vectorize the following code; it's not a directive to either malloc or any other memory allocation mechanism, so you might be lying to gcc.
To ensure that you have actually aligned pointers, it's your responsibility to use appropriate mechanisms. So you have to:
malloc and then roundup to the next multiple of your granularity (if not already there)__attribute__((aligned(N))) in your declarations (working for sure for heap-allocated, and possibly for stack-allocated variables)posix_memalign
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With