Re:Optimizing Big Number Arithmetic Without SSE
by cliffbean on Monday February 10, 2014 @12:52PM
(#7212466)
Few people actually know Fortran anymore, but in reality, C99's restrict covers only a narrow subset of what Fortran's aliasing rules covered. restrict's numerous limitations substantially reduce its usefulness, which is one reason it's not as common knowledge as one might guess.
Re:Optimizing Big Number Arithmetic Without SSE
by sharpneli on Monday February 10, 2014 @01:09PM
(#7212575)
Can you elaborate on what the limitations are?
I have been under the impression that restrict makes it pretty much equivalent to fortran (restrict means that nothing aliases the pointer)
Re:Optimizing Big Number Arithmetic Without SSE
by cliffbean on Monday February 10, 2014 @11:02PM
(#7215716)
On some pointers, for example function return types, restrict is defined to be meaningless. Also, restrict pointers can be copies of other pointers, and copies can be made of restrict pointers, subject to certain rules. So it's more involved than just "nothing aliases the pointer".
Here's another example:
// C has pretty paltry array support, so it's common for
// people to build their own stuff like this:
struct Array {
float *data;
size_t len;
};
// But then you use it:
void foo(Array *a, Array *b) {
for (i = ...)
for (j = ...)
a->data[i] = b->data[j];
}
and there's nowhere you can put restrict to declare that the two array references here are independent. The data pointer is one of the contexts where restrict is defined to be meaningless.If you're a hyperactive squirrel, you might try rewriting all your code everywhere to do stuff like this:
void foo(Array *a, Array *b) {
for (i = ...)
for (j = ...) {
float *restrict x = a->data;
float *restrict y = b->data;
x[i] = y[i];
}
but then you'll just discover that most compilers ignore restrict in block scopes like this, because the semantics for that are tricky for compilers to deal with, so you still won't win.
Re:Optimizing Big Number Arithmetic Without SSE
by willvarfar on Monday February 10, 2014 @12:30PM
(#7212278)
As an aside, its worth looking at the new Mill CPU architecture; its immune to aliasing bugs :) http://ootbcomp.com/topic/introduction-to-the-mill-cpu-progr...
It's such an important addition that I'm bit surprised why it's still not common knowledge.