- removed comment
Correct autoconfiguration of restrict keyword; add support for builtin_expect
While experimenting with several different compilers on Hopper, I noticed that some compilers do not support all the ways in which the "restrict" keyword can be used. I updated our autoconf macro to test more cases.
I now also think it is not worthwhile to require the compiler to support the array syntax for function arguments, i.e. the syntax
void foo (double A[restrict]);
which (essentially) declares a pointer A using array syntax. One can instead use the syntax
void foo (double *restrict const A);
which is identical in almost all respects. The PGI compiler does not seem to support the array syntax, and disabling support for the restrict keyword does not seem to be worth the cost.
I also add support for the gcc built-in function "builtin_expect", which tells the compiler the value that an expression is most likely to have, allowing compile-time optimisations based on this heuristic, and maybe avoiding branch penalties at run time.
I also enabled the (currently commented out) definitions for attribute(hot) and attribute(cold), which tell the compiler that a function is either executed very often, or very rarely. This can also influence the optimiser.
I attach a patch.
Keyword:
Comments (7)
-
reporter -
reporter - changed status to open
- removed comment
-
- removed comment
I'm not sure I understand the array syntax issue. Is this only applicable to the restrict keyword, in which case it's probably fine, or does it also apply to declarations of the form
void foo (double A[]);
which I thought were standard C and should be supported by all compilers?
-
- removed comment
I also add support for the gcc built-in function "builtin_expect"
This sounds like potentially quite a nice addition. How difficult would it be to take this further and enable the use of profile guided optimization (eg. http://stackoverflow.com/questions/2738835/learning-sample-of-likely-and-unlikely-compiler-hints). Do you think it would be likely to help much?
-
reporter - removed comment
Ian Hinder reports having used this patch without problems.
-
reporter - changed status to resolved
- removed comment
Committed.
-
- edited description
- changed status to closed
- Log in to comment