>>>>> "quick" == quick  <qu...@sparq.org> writes:

 quick> I have two questions regarding the use on __restrict__
 quick> qualifiers for function arguments in C++:

 quick> 1) How does it interact with volatile?

 quick> Example, given:

 quick> void foo(volatile int* __restrict__ p1, volatile int*
 quick> __restrict__ p2) { *p1 = 3; if (*p1 == 5) ...; *p2 = 4; }

 quick> The most desireable for me would be that restrict would
 quick> indicate that *p1 and *p2 were disjoint and allow reordering
 quick> statement 3 to execute before either preceeding statement, but
 quick> that volatile would indicate that the if expression would need
 quick> to re-fetch *p1 and not assume the results of the first
 quick> statement.

 quick> However, an alternative (less useful) interpretation is that
 quick> volatile completely overrides restrict: where restrict would
 quick> allow the compiler to cache *p1 in a local register and
 quick> therefore volatile would prevent this.

Volatile means more than "you need to refetch *p1 each time".  It also
means "accesses may have side effects" -- which is why "volatile" is
used for I/O device registers.  Given that, even though p1 and p2 are
distinct addresses, reordering *p1 with *p2 may produce a different
answer.

My conclusion is that the "alternative" interpretation is the only
correct one, which means that restrict applied to pointers to volatile
has no effect.  I wonder if this deserves a warning ("restrict
attribute ignored" or something like that).

          paul

Reply via email to