c - How restrictive is the restrict keyword? -
i have following simple function
static inline void minvec(const double *restrict v, double *restrict vmin, unsigned length){ (unsigned = 0; < length; ++i) vmin[i] = -v[i]; return; }
which compiles , runs fine when use way
double v[] = {1, 2, 3}; minvec(v, v, 3);
i've been led believe using restrict
in case informs compiler each iteration of loop independent of others, loop can aggressively optimized. correct way of doing or poking implementation-defined behaviour here?
the restrict
keyword purely optimization hint: allows compiler reorder reads/writes from/to restricted pointers other memory accesses. cannot done if compiler cannot prove memory behind pointer can accessed via pointer.
so, if restrict
, tell compiler: "i assure pointer 1 points memory, please feel free reorder. aware blue elephants may appear if wrong, i'm human, can't wrong, bow before me."
this keyword sake of compiler, not sake!
Comments
Post a Comment