Multi_002dAlternative.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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: Multi-Alternative</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Multi-Alternative">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Multi-Alternative">
  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="Constraints.html#Constraints" rel="up" title="Constraints">
  30. <link href="Class-Preferences.html#Class-Preferences" rel="next" title="Class Preferences">
  31. <link href="Simple-Constraints.html#Simple-Constraints" rel="prev" title="Simple Constraints">
  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="Multi_002dAlternative"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Class-Preferences.html#Class-Preferences" accesskey="n" rel="next">Class Preferences</a>, Previous: <a href="Simple-Constraints.html#Simple-Constraints" accesskey="p" rel="prev">Simple Constraints</a>, Up: <a href="Constraints.html#Constraints" accesskey="u" rel="up">Constraints</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="Multiple-Alternative-Constraints"></a>
  69. <h4 class="subsection">16.8.2 Multiple Alternative Constraints</h4>
  70. <a name="index-multiple-alternative-constraints"></a>
  71. <p>Sometimes a single instruction has multiple alternative sets of possible
  72. operands. For example, on the 68000, a logical-or instruction can combine
  73. register or an immediate value into memory, or it can combine any kind of
  74. operand into a register; but it cannot combine one memory location into
  75. another.
  76. </p>
  77. <p>These constraints are represented as multiple alternatives. An alternative
  78. can be described by a series of letters for each operand. The overall
  79. constraint for an operand is made from the letters for this operand
  80. from the first alternative, a comma, the letters for this operand from
  81. the second alternative, a comma, and so on until the last alternative.
  82. All operands for a single instruction must have the same number of
  83. alternatives.
  84. Here is how it is done for fullword logical-or on the 68000:
  85. </p>
  86. <div class="smallexample">
  87. <pre class="smallexample">(define_insn &quot;iorsi3&quot;
  88. [(set (match_operand:SI 0 &quot;general_operand&quot; &quot;=m,d&quot;)
  89. (ior:SI (match_operand:SI 1 &quot;general_operand&quot; &quot;%0,0&quot;)
  90. (match_operand:SI 2 &quot;general_operand&quot; &quot;dKs,dmKs&quot;)))]
  91. &hellip;)
  92. </pre></div>
  93. <p>The first alternative has &lsquo;<samp>m</samp>&rsquo; (memory) for operand 0, &lsquo;<samp>0</samp>&rsquo; for
  94. operand 1 (meaning it must match operand 0), and &lsquo;<samp>dKs</samp>&rsquo; for operand
  95. 2. The second alternative has &lsquo;<samp>d</samp>&rsquo; (data register) for operand 0,
  96. &lsquo;<samp>0</samp>&rsquo; for operand 1, and &lsquo;<samp>dmKs</samp>&rsquo; for operand 2. The &lsquo;<samp>=</samp>&rsquo; and
  97. &lsquo;<samp>%</samp>&rsquo; in the constraints apply to all the alternatives; their
  98. meaning is explained in the next section (see <a href="Class-Preferences.html#Class-Preferences">Class Preferences</a>).
  99. </p>
  100. <p>If all the operands fit any one alternative, the instruction is valid.
  101. Otherwise, for each alternative, the compiler counts how many instructions
  102. must be added to copy the operands so that that alternative applies.
  103. The alternative requiring the least copying is chosen. If two alternatives
  104. need the same amount of copying, the one that comes first is chosen.
  105. These choices can be altered with the &lsquo;<samp>?</samp>&rsquo; and &lsquo;<samp>!</samp>&rsquo; characters:
  106. </p>
  107. <dl compact="compact">
  108. <dd><a name="index-_003f-in-constraint"></a>
  109. <a name="index-question-mark"></a>
  110. </dd>
  111. <dt><code>?</code></dt>
  112. <dd><p>Disparage slightly the alternative that the &lsquo;<samp>?</samp>&rsquo; appears in,
  113. as a choice when no alternative applies exactly. The compiler regards
  114. this alternative as one unit more costly for each &lsquo;<samp>?</samp>&rsquo; that appears
  115. in it.
  116. </p>
  117. <a name="index-_0021-in-constraint"></a>
  118. <a name="index-exclamation-point"></a>
  119. </dd>
  120. <dt><code>!</code></dt>
  121. <dd><p>Disparage severely the alternative that the &lsquo;<samp>!</samp>&rsquo; appears in.
  122. This alternative can still be used if it fits without reloading,
  123. but if reloading is needed, some other alternative will be used.
  124. </p>
  125. <a name="index-_005e-in-constraint"></a>
  126. <a name="index-caret"></a>
  127. </dd>
  128. <dt><code>^</code></dt>
  129. <dd><p>This constraint is analogous to &lsquo;<samp>?</samp>&rsquo; but it disparages slightly
  130. the alternative only if the operand with the &lsquo;<samp>^</samp>&rsquo; needs a reload.
  131. </p>
  132. <a name="index-_0024-in-constraint"></a>
  133. <a name="index-dollar-sign"></a>
  134. </dd>
  135. <dt><code>$</code></dt>
  136. <dd><p>This constraint is analogous to &lsquo;<samp>!</samp>&rsquo; but it disparages severely
  137. the alternative only if the operand with the &lsquo;<samp>$</samp>&rsquo; needs a reload.
  138. </p></dd>
  139. </dl>
  140. <p>When an insn pattern has multiple alternatives in its constraints, often
  141. the appearance of the assembler code is determined mostly by which
  142. alternative was matched. When this is so, the C code for writing the
  143. assembler code can use the variable <code>which_alternative</code>, which is
  144. the ordinal number of the alternative that was actually satisfied (0 for
  145. the first, 1 for the second alternative, etc.). See <a href="Output-Statement.html#Output-Statement">Output Statement</a>.
  146. </p>
  147. <hr>
  148. <div class="header">
  149. <p>
  150. Next: <a href="Class-Preferences.html#Class-Preferences" accesskey="n" rel="next">Class Preferences</a>, Previous: <a href="Simple-Constraints.html#Simple-Constraints" accesskey="p" rel="prev">Simple Constraints</a>, Up: <a href="Constraints.html#Constraints" accesskey="u" rel="up">Constraints</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>
  151. </div>
  152. </body>
  153. </html>