Conditional-Execution.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>GNU Compiler Collection (GCC) Internals: Conditional Execution</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Conditional Execution">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Conditional Execution">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Machine-Desc.html#Machine-Desc" rel="up" title="Machine Desc">
  30. <link href="Define-Subst.html#Define-Subst" rel="next" title="Define Subst">
  31. <link href="Processor-pipeline-description.html#Processor-pipeline-description" rel="prev" title="Processor pipeline description">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Conditional-Execution"></a>
  63. <div class="header">
  64. <p>
  65. 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>
  66. </div>
  67. <hr>
  68. <a name="Conditional-Execution-1"></a>
  69. <h3 class="section">16.20 Conditional Execution</h3>
  70. <a name="index-conditional-execution"></a>
  71. <a name="index-predication"></a>
  72. <p>A number of architectures provide for some form of conditional
  73. execution, or predication. The hallmark of this feature is the
  74. ability to nullify most of the instructions in the instruction set.
  75. When the instruction set is large and not entirely symmetric, it
  76. can be quite tedious to describe these forms directly in the
  77. <samp>.md</samp> file. An alternative is the <code>define_cond_exec</code> template.
  78. </p>
  79. <a name="index-define_005fcond_005fexec"></a>
  80. <div class="smallexample">
  81. <pre class="smallexample">(define_cond_exec
  82. [<var>predicate-pattern</var>]
  83. &quot;<var>condition</var>&quot;
  84. &quot;<var>output-template</var>&quot;
  85. &quot;<var>optional-insn-attribues</var>&quot;)
  86. </pre></div>
  87. <p><var>predicate-pattern</var> is the condition that must be true for the
  88. insn to be executed at runtime and should match a relational operator.
  89. One can use <code>match_operator</code> to match several relational operators
  90. at once. Any <code>match_operand</code> operands must have no more than one
  91. alternative.
  92. </p>
  93. <p><var>condition</var> is a C expression that must be true for the generated
  94. pattern to match.
  95. </p>
  96. <a name="index-current_005finsn_005fpredicate"></a>
  97. <p><var>output-template</var> is a string similar to the <code>define_insn</code>
  98. output template (see <a href="Output-Template.html#Output-Template">Output Template</a>), except that the &lsquo;<samp>*</samp>&rsquo;
  99. and &lsquo;<samp>@</samp>&rsquo; special cases do not apply. This is only useful if the
  100. assembly text for the predicate is a simple prefix to the main insn.
  101. In order to handle the general case, there is a global variable
  102. <code>current_insn_predicate</code> that will contain the entire predicate
  103. if the current insn is predicated, and will otherwise be <code>NULL</code>.
  104. </p>
  105. <p><var>optional-insn-attributes</var> is an optional vector of attributes that gets
  106. appended to the insn attributes of the produced cond_exec rtx. It can
  107. be used to add some distinguishing attribute to cond_exec rtxs produced
  108. that way. An example usage would be to use this attribute in conjunction
  109. with attributes on the main pattern to disable particular alternatives under
  110. certain conditions.
  111. </p>
  112. <p>When <code>define_cond_exec</code> is used, an implicit reference to
  113. the <code>predicable</code> instruction attribute is made.
  114. See <a href="Insn-Attributes.html#Insn-Attributes">Insn Attributes</a>. This attribute must be a boolean (i.e. have
  115. exactly two elements in its <var>list-of-values</var>), with the possible
  116. values being <code>no</code> and <code>yes</code>. The default and all uses in
  117. the insns must be a simple constant, not a complex expressions. It
  118. may, however, depend on the alternative, by using a comma-separated
  119. list of values. If that is the case, the port should also define an
  120. <code>enabled</code> attribute (see <a href="Disable-Insn-Alternatives.html#Disable-Insn-Alternatives">Disable Insn Alternatives</a>), which
  121. should also allow only <code>no</code> and <code>yes</code> as its values.
  122. </p>
  123. <p>For each <code>define_insn</code> for which the <code>predicable</code>
  124. attribute is true, a new <code>define_insn</code> pattern will be
  125. generated that matches a predicated version of the instruction.
  126. For example,
  127. </p>
  128. <div class="smallexample">
  129. <pre class="smallexample">(define_insn &quot;addsi&quot;
  130. [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;r&quot;)
  131. (plus:SI (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
  132. (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
  133. &quot;<var>test1</var>&quot;
  134. &quot;add %2,%1,%0&quot;)
  135. (define_cond_exec
  136. [(ne (match_operand:CC 0 &quot;register_operand&quot; &quot;c&quot;)
  137. (const_int 0))]
  138. &quot;<var>test2</var>&quot;
  139. &quot;(%0)&quot;)
  140. </pre></div>
  141. <p>generates a new pattern
  142. </p>
  143. <div class="smallexample">
  144. <pre class="smallexample">(define_insn &quot;&quot;
  145. [(cond_exec
  146. (ne (match_operand:CC 3 &quot;register_operand&quot; &quot;c&quot;) (const_int 0))
  147. (set (match_operand:SI 0 &quot;register_operand&quot; &quot;r&quot;)
  148. (plus:SI (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
  149. (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;))))]
  150. &quot;(<var>test2</var>) &amp;&amp; (<var>test1</var>)&quot;
  151. &quot;(%3) add %2,%1,%0&quot;)
  152. </pre></div>
  153. <hr>
  154. <div class="header">
  155. <p>
  156. 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>
  157. </div>
  158. </body>
  159. </html>