[Bug c/61939] warn when __attribute__((aligned(x))) is ignored
daniel.santos at pobox dot com
gcc-bugzilla@gcc.gnu.org
Thu Oct 20 04:02:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61939
--- Comment #2 from Daniel Santos <daniel.santos at pobox dot com> ---
(In reply to Vedran Miletic from comment #1)
> #include <numeric>
> #include <vector>
> float f(std::vector<float>& A, std::vector<float>& B)
> {
> __builtin_assume_aligned(A.data(), 64);
> __builtin_assume_aligned(B.data(), 64);
> return std::inner_product(A.begin(), A.end(), B.begin(), 0.f);
> }
You are doing it wrong. __builtin_assume_aligned() returns void* and you must
use it's return value for it to be effective. So your code should be something
like this:
float f(std::vector<float>& A, std::vector<float>& B)
{
float *a_data = __builtin_assume_aligned(A.data(), 64);
float *b_data = __builtin_assume_aligned(B.data(), 64);
return std::inner_product(a_data, b_data, B.begin(), 0.f);
}
Of course, this assumes that the buffer that your vector<> implementation
supplies is 64 byte aligned.
More information about the Gcc-bugs
mailing list