Correct autoconfiguration of restrict keyword; add support for builtin_expect

Create issue
Issue #437 closed
Erik Schnetter created an issue

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)

  1. Ian Hinder
    • 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?

  2. Log in to comment