Search code examples
c++visual-c++c++-amp

Is the order of 'restrict's significant?


I was going through the MSDN restrict documentation and came across the line:
restrict description image
Here in, the 2 versions of restrict, namely, restrict(cpu, amp) and restrict(amp, cpu) are explicitly disctinctly mentioned. Falling back, we can infer that restrict(A, B) is restrict (A) restrct (B) and vice versa. My question is the order significant?
Namely, is restrict(A) restrict(B) same as restrict(B) restrict(A)?


Solution

  • No, order doesn't matter. There is an example that directly demonstrates that:

    void myFunction(int a) restrict(amp, cpu) //or restrict(cpu, amp)
    {
        // Code that can execute on the CPU
        // and
        // can execute on amp accelerators
    }
    

    - See restrict – a key new language feature introduced with C++ AMP

    All of the these forms should be equivalent:

    restrict(amp) restrict(cpu)
    restrict(cpu) restrict(amp)
    restrict(cpu, amp)
    restrict(amp, cpu)
    

    It wouldn't make any logical sense for order to matter here, because each restrict specifier adds more restrictions onto our function. This "logical and" between the restrictions is commutative.