diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/gcc~13/loop-specific-pragmas.html | |
new repository
Diffstat (limited to 'devdocs/gcc~13/loop-specific-pragmas.html')
| -rw-r--r-- | devdocs/gcc~13/loop-specific-pragmas.html | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/devdocs/gcc~13/loop-specific-pragmas.html b/devdocs/gcc~13/loop-specific-pragmas.html new file mode 100644 index 00000000..285f8e81 --- /dev/null +++ b/devdocs/gcc~13/loop-specific-pragmas.html @@ -0,0 +1,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> |
