News for hackers. Stuff that matters.
Re:Depressing and faintly terrifying days for the C standard... by kazinator on Wednesday May 30, 2018 @10:04PM (#17193432)
Ah, but by using restrict I'm saying, "please screw my C program with C99 stuff that potentially introduces undefined behavior".

That's what restrict does: it makes some behaviors undefined and otherwise doesn't change the semantics of the program. It's completely against the grain of moving to a safer language.

Why would I do that, if I can instead beautify the source and machine code while sticking to what was available in C90.

I think restrict is mainly intended as a way of competing against Fortran. If you're processing arrays referenced by pointers, and can get the compiler to believe that they do not overlap, then the compiler can unroll the loops and rearrange the accesses and calculations in the unrolled body. Like it can load four elements from a source arrays, do four calculations, and then store four elements into a target, rather than interleaving. That can be done by vectorized instructions.

Here is where our technique falls short: if we write the loop body with our load-calculate-store style, it cannot be unrolled and vectorized. We have pinned down an exact behavior for all possible cases of aliasing, like self-overlap with a displacement. Vectorizing unrolls do not preserve that behavior.

Manual unrolling isn't attractive because it's a guessing game. A good amount of unrolling on one machine may give the instruction cache indigestion on another machine.

There are no comments on this comment yet.