source: public/doc/gnu-c/Optimization-Pragmas.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 6.2 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
4
5(The work of Trevis Rothwell and Nelson Beebe has been assigned or
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing GNU and promoting software freedom." -->
19<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
20<head>
21<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22<title>Optimization Pragmas (GNU C Language Manual)</title>
23
24<meta name="description" content="Optimization Pragmas (GNU C Language Manual)">
25<meta name="keywords" content="Optimization Pragmas (GNU C Language Manual)">
26<meta name="resource-type" content="document">
27<meta name="distribution" content="global">
28<meta name="Generator" content="makeinfo">
29<link href="index.html" rel="start" title="Top">
30<link href="Symbol-Index.html" rel="index" title="Symbol Index">
31<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
32<link href="Pragmas.html" rel="up" title="Pragmas">
33<link href="Static-Assertions.html" rel="next" title="Static Assertions">
34<link href="Severity-Pragmas.html" rel="prev" title="Severity Pragmas">
35<style type="text/css">
36<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.no-bullet {list-style: none}
51-->
52</style>
53
54
55</head>
56
57<body lang="en">
58<span id="Optimization-Pragmas"></span><div class="header">
59<p>
60Previous: <a href="Severity-Pragmas.html" accesskey="p" rel="prev">Severity Pragmas</a>, Up: <a href="Pragmas.html" accesskey="u" rel="up">Pragmas</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
61</div>
62<hr>
63<span id="Optimization-Pragmas-1"></span><h4 class="subsection">30.1.3 Optimization Pragmas</h4>
64
65<p>These pragmas enable a particular optimization for specific function
66definitions. The settings take effect at the end of a function
67definition, so the clean place to use these pragmas is between
68function definitions.
69</p>
70<dl compact="compact">
71<dt><code>#pragma GCC optimize <var>optimization</var></code></dt>
72<dt><code>_Pragma (&quot;GCC optimize <var>optimization</var>&quot;)</code></dt>
73<dd><p>These pragmas enable the optimization <var>optimization</var> for the
74following functions. For example,
75</p>
76<div class="example">
77<pre class="example">_Pragma (&quot;GCC optimize -fforward-propagate&quot;)
78</pre></div>
79
80<p>says to apply the &lsquo;<samp>forward-propagate</samp>&rsquo; optimization to all
81following function definitions. Specifying optimizations for
82individual functions, rather than for the entire program, is rare but
83can be useful for getting around a bug in the compiler.
84</p>
85<p>If <var>optimization</var> does not correspond to a defined optimization
86option, the pragma is erroneous. To turn off an optimization, use the
87corresponding &lsquo;<samp>-fno-</samp>&rsquo; option, such as
88&lsquo;<samp>-fno-forward-propagate</samp>&rsquo;.
89</p>
90</dd>
91<dt><code>#pragma GCC target <var>optimizations</var></code></dt>
92<dt><code>_Pragma (&quot;GCC target <var>optimizations</var>&quot;)</code></dt>
93<dd><p>The pragma &lsquo;<samp>GCC target</samp>&rsquo; is similar to &lsquo;<samp>GCC optimize</samp>&rsquo; but is
94used for platform-specific optimizations. Thus,
95</p>
96<div class="example">
97<pre class="example">_Pragma (&quot;GCC target popcnt&quot;)
98</pre></div>
99
100<p>activates the optimization &lsquo;<samp>popcnt</samp>&rsquo; for all
101following function definitions. This optimization is supported
102on a few common targets but not on others.
103</p>
104</dd>
105<dt><code>#pragma GCC push_options</code></dt>
106<dt><code>_Pragma (&quot;GCC push_options&quot;)</code></dt>
107<dd><p>The &lsquo;<samp>push_options</samp>&rsquo; pragma saves on a stack the current settings
108specified with the &lsquo;<samp>target</samp>&rsquo; and &lsquo;<samp>optimize</samp>&rsquo; pragmas.
109</p>
110</dd>
111<dt><code>#pragma GCC pop_options</code></dt>
112<dt><code>_Pragma (&quot;GCC pop_options&quot;)</code></dt>
113<dd><p>The &lsquo;<samp>pop_options</samp>&rsquo; pragma pops saved settings from that stack.
114</p>
115<p>Here&rsquo;s an example of using this stack.
116</p>
117<div class="example">
118<pre class="example">_Pragma (&quot;GCC push_options&quot;)
119_Pragma (&quot;GCC optimize forward-propagate&quot;)
120
121/* <span class="roman">Functions to compile</span>
122 <span class="roman">with the <code>forward-propagate</code> optimization.</span> */
123
124_Pragma (&quot;GCC pop_options&quot;)
125/* <span class="roman">Ends enablement of <code>forward-propagate</code>.</span> */
126</pre></div>
127
128</dd>
129<dt><code>#pragma GCC reset_options</code></dt>
130<dt><code>_Pragma (&quot;GCC reset_options&quot;)</code></dt>
131<dd><p>Clears all pragma-defined &lsquo;<samp>target</samp>&rsquo; and &lsquo;<samp>optimize</samp>&rsquo;
132optimization settings.
133</p></dd>
134</dl>
135
136<hr>
137<div class="header">
138<p>
139Previous: <a href="Severity-Pragmas.html" accesskey="p" rel="prev">Severity Pragmas</a>, Up: <a href="Pragmas.html" accesskey="u" rel="up">Pragmas</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
140</div>
141
142
143
144</body>
145</html>
Note: See TracBrowser for help on using the repository browser.