restrict in practice

bearophile bearophileHUGS at lycos.com
Sun Jan 3 09:24:46 PST 2010


This is a paper by Markus Mock is about the usefulness of the "restrict" annotation in medium-sized C programs:
http://www.cs.pitt.edu/~mock/papers/clei2004.pdf

The author finds that restrict is not significantly useful in the bulk of programs, while it can be useful in computational kernels (small routines that perform heavy array operations).

I think what the paper says is not very useful now because:
- It uses the Sparc V9 and Itanium 2 CPUs. Itanium has hardware that greatly reduces the need of the restrict annotation. But I think Core2 and i7 CPUs don't have such feature.
- GCC 4.5 seens able to use restrict well, while older GCCs where not good (but this article doesn't use GCC).

A downside of the restrict of C is that the compiler is not able to spot if the annotation is used in the wrong place.

Compared to the inline annotation the situation is different because today compiler backends like LLVM/GCC are good enough at choosing what functions to inline, while for them finding what pointers aren't an alias of each other is not easy still.

The LLVM backend of LDC is able to use annotations that define pointers as unique.

So it can be useful to have ways for the D compiler to know what pointers in a computational kernel aren't alias of each other, but I'd like this to be safer, unlike C. Unique & lend for class references may be usable for pointers too.

Bye,
bearophile



More information about the Digitalmars-d mailing list