1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<div class="subsection-level-extent" id="Loop-Specific-Pragmas"> <div class="nav-panel"> <p> Previous: <a href="function-specific-option-pragmas" accesskey="p" rel="prev">Function Specific Option Pragmas</a>, Up: <a href="pragmas" accesskey="u" rel="up">Pragmas Accepted by GCC</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="subsection" id="Loop-Specific-Pragmas-1"><span>6.62.16 Loop-Specific Pragmas<a class="copiable-link" href="#Loop-Specific-Pragmas-1"> ¶</a></span></h1> <dl class="table"> <dt>
<span><code class="code">#pragma GCC ivdep</code><a class="copiable-link" href="#index-pragma-GCC-ivdep"> ¶</a></span>
</dt> <dd> <p>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. </p> <p>For example, the compiler can only unconditionally vectorize the following loop with the pragma: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">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];
}</pre>
</div> <p>In this example, using the <code class="code">restrict</code> qualifier had the same effect. In the following example, that would not be possible. Assume <em class="math">k < -m</em> or <em class="math">k >= m</em>. Only with the pragma, the compiler knows that it can unconditionally vectorize the following loop: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">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;
}</pre>
</div> </dd> <dt>
<span><code class="code">#pragma GCC unroll <var class="var">n</var></code><a class="copiable-link" href="#index-pragma-GCC-unroll-n"> ¶</a></span>
</dt> <dd> <p>You can use this pragma to control how many times a loop should be unrolled. It must be placed immediately before a <code class="code">for</code>, <code class="code">while</code> or <code class="code">do</code> loop or a <code class="code">#pragma GCC ivdep</code>, and applies only to the loop that follows. <var class="var">n</var> is an integer constant expression specifying the unrolling factor. The values of <em class="math">0</em> and <em class="math">1</em> block any unrolling of the loop. </p> </dd> </dl> </div><div class="_attribution">
<p class="_attribution-p">
© Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
<a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Loop-Specific-Pragmas.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Loop-Specific-Pragmas.html</a>
</p>
</div>
|