Previous: Function Specific Option Pragmas, Up: Pragmas [Contents][Index]

#### 6.64.16 Loop-Specific Pragmas

`#pragma GCC ivdep`

  With this pragma, the programmer asserts that there are no loop-carried dependencies which would prevent consecutive iterations of the following loop from executing concurrently with SIMD (single instruction multiple data) instructions.

  For example, the compiler can only unconditionally vectorize the following loop with the pragma:

      void foo (int n, int *a, int *b, int *c)
      {
        int i, j;
      #pragma GCC ivdep
        for (i = 0; i < n; ++i)
          a[i] = b[i] + c[i];
      }

  In this example, using the `restrict` qualifier had the same effect. In the following example, that would not be possible. Assume k < -m or k >= m. Only with the pragma, the compiler knows that it can unconditionally vectorize the following loop:

      void ignore_vec_dep (int *a, int k, int c, int m)
      {
      #pragma GCC ivdep
        for (int i = 0; i < m; i++)
          a[i] = a[i + k] * c;
      }

`#pragma GCC novector`

  With this pragma, the programmer asserts that the following loop should be prevented from executing concurrently with SIMD (single instruction multiple data) instructions.

  For example, the compiler cannot vectorize the following loop with the pragma:

      void foo (int n, int *a, int *b, int *c)
      {
        int i, j;
      #pragma GCC novector
        for (i = 0; i < n; ++i)
          a[i] = b[i] + c[i];
      }

`#pragma GCC unroll n`

  You can use this pragma to control how many times a loop should be unrolled. It must be placed immediately before a `for`, `while` or `do` loop or a `#pragma GCC ivdep`, and applies only to the loop that follows. n is an integer constant expression specifying the unrolling factor. The values of 0 and 1 block any unrolling of the loop.

Previous: Function Specific Option Pragmas, Up: Pragmas [Contents][Index]