Is C++ pointer aliasing a threat if the pointers are exactly the same? -
consider function intended vectorization:
void addsqr(float* restrict dst, float* restrict src, int cnt) { (int i=0; i<cnt; i++) dst[i] = src[i] * src[i]; };
this work if src & dst not aliased of course. if src == dst? extreme cases such src == dst+1 not allowed of course. if pointers same, there shouldn't problem, or missing something?
edit: restrict intel c++ compiler keyword, msvc has __restrict.
my point question don't see way how kind of vectorization go wrong: since every dst value dependent on single src value @ either different (without aliasing) or same address, when dst changed, src value never needed anymore, because fact has been written means output has been calculated. case if compiler used dst temporary buffer, don't think correct.
in c, code causes undefined behaviour violating restrict
definition because writes 1 object through dst
reads same object through src
.
it doesn't matter whether or not there offset between dst
, src
; condition there exists float
object written through 1 pointer , read through other.
Comments
Post a Comment