blob: c23b9f01feaccb3b6a1b906a66ea96c9df207a04 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2015 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below). A copy of the license is included in the section entitled
"GNU Free Documentation License".
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development. -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Compiler Collection (GCC) Internals: Conditional Execution</title>
<meta name="description" content="GNU Compiler Collection (GCC) Internals: Conditional Execution">
<meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Conditional Execution">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Machine-Desc.html#Machine-Desc" rel="up" title="Machine Desc">
<link href="Define-Subst.html#Define-Subst" rel="next" title="Define Subst">
<link href="Processor-pipeline-description.html#Processor-pipeline-description" rel="prev" title="Processor pipeline description">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Conditional-Execution"></a>
<div class="header">
<p>
Next: <a href="Define-Subst.html#Define-Subst" accesskey="n" rel="next">Define Subst</a>, Previous: <a href="Insn-Attributes.html#Insn-Attributes" accesskey="p" rel="prev">Insn Attributes</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Conditional-Execution-1"></a>
<h3 class="section">16.20 Conditional Execution</h3>
<a name="index-conditional-execution"></a>
<a name="index-predication"></a>
<p>A number of architectures provide for some form of conditional
execution, or predication. The hallmark of this feature is the
ability to nullify most of the instructions in the instruction set.
When the instruction set is large and not entirely symmetric, it
can be quite tedious to describe these forms directly in the
<samp>.md</samp> file. An alternative is the <code>define_cond_exec</code> template.
</p>
<a name="index-define_005fcond_005fexec"></a>
<div class="smallexample">
<pre class="smallexample">(define_cond_exec
[<var>predicate-pattern</var>]
&quot;<var>condition</var>&quot;
&quot;<var>output-template</var>&quot;
&quot;<var>optional-insn-attribues</var>&quot;)
</pre></div>
<p><var>predicate-pattern</var> is the condition that must be true for the
insn to be executed at runtime and should match a relational operator.
One can use <code>match_operator</code> to match several relational operators
at once. Any <code>match_operand</code> operands must have no more than one
alternative.
</p>
<p><var>condition</var> is a C expression that must be true for the generated
pattern to match.
</p>
<a name="index-current_005finsn_005fpredicate"></a>
<p><var>output-template</var> is a string similar to the <code>define_insn</code>
output template (see <a href="Output-Template.html#Output-Template">Output Template</a>), except that the &lsquo;<samp>*</samp>&rsquo;
and &lsquo;<samp>@</samp>&rsquo; special cases do not apply. This is only useful if the
assembly text for the predicate is a simple prefix to the main insn.
In order to handle the general case, there is a global variable
<code>current_insn_predicate</code> that will contain the entire predicate
if the current insn is predicated, and will otherwise be <code>NULL</code>.
</p>
<p><var>optional-insn-attributes</var> is an optional vector of attributes that gets
appended to the insn attributes of the produced cond_exec rtx. It can
be used to add some distinguishing attribute to cond_exec rtxs produced
that way. An example usage would be to use this attribute in conjunction
with attributes on the main pattern to disable particular alternatives under
certain conditions.
</p>
<p>When <code>define_cond_exec</code> is used, an implicit reference to
the <code>predicable</code> instruction attribute is made.
See <a href="Insn-Attributes.html#Insn-Attributes">Insn Attributes</a>. This attribute must be a boolean (i.e. have
exactly two elements in its <var>list-of-values</var>), with the possible
values being <code>no</code> and <code>yes</code>. The default and all uses in
the insns must be a simple constant, not a complex expressions. It
may, however, depend on the alternative, by using a comma-separated
list of values. If that is the case, the port should also define an
<code>enabled</code> attribute (see <a href="Disable-Insn-Alternatives.html#Disable-Insn-Alternatives">Disable Insn Alternatives</a>), which
should also allow only <code>no</code> and <code>yes</code> as its values.
</p>
<p>For each <code>define_insn</code> for which the <code>predicable</code>
attribute is true, a new <code>define_insn</code> pattern will be
generated that matches a predicated version of the instruction.
For example,
</p>
<div class="smallexample">
<pre class="smallexample">(define_insn &quot;addsi&quot;
[(set (match_operand:SI 0 &quot;register_operand&quot; &quot;r&quot;)
(plus:SI (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
(match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
&quot;<var>test1</var>&quot;
&quot;add %2,%1,%0&quot;)
(define_cond_exec
[(ne (match_operand:CC 0 &quot;register_operand&quot; &quot;c&quot;)
(const_int 0))]
&quot;<var>test2</var>&quot;
&quot;(%0)&quot;)
</pre></div>
<p>generates a new pattern
</p>
<div class="smallexample">
<pre class="smallexample">(define_insn &quot;&quot;
[(cond_exec
(ne (match_operand:CC 3 &quot;register_operand&quot; &quot;c&quot;) (const_int 0))
(set (match_operand:SI 0 &quot;register_operand&quot; &quot;r&quot;)
(plus:SI (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
(match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;))))]
&quot;(<var>test2</var>) &amp;&amp; (<var>test1</var>)&quot;
&quot;(%3) add %2,%1,%0&quot;)
</pre></div>
<hr>
<div class="header">
<p>
Next: <a href="Define-Subst.html#Define-Subst" accesskey="n" rel="next">Define Subst</a>, Previous: <a href="Insn-Attributes.html#Insn-Attributes" accesskey="p" rel="prev">Insn Attributes</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>