You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
9.2KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Output Statement (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Output Statement (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Output Statement (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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="Predicates.html#Predicates" rel="next" title="Predicates">
  31. <link href="Output-Template.html#Output-Template" rel="prev" title="Output Template">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Output-Statement"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Predicates.html#Predicates" accesskey="n" rel="next">Predicates</a>, Previous: <a href="Output-Template.html#Output-Template" accesskey="p" rel="prev">Output Template</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>
  65. </div>
  66. <hr>
  67. <a name="C-Statements-for-Assembler-Output"></a>
  68. <h3 class="section">17.6 C Statements for Assembler Output</h3>
  69. <a name="index-output-statements"></a>
  70. <a name="index-C-statements-for-assembler-output"></a>
  71. <a name="index-generating-assembler-output"></a>
  72. <p>Often a single fixed template string cannot produce correct and efficient
  73. assembler code for all the cases that are recognized by a single
  74. instruction pattern. For example, the opcodes may depend on the kinds of
  75. operands; or some unfortunate combinations of operands may require extra
  76. machine instructions.
  77. </p>
  78. <p>If the output control string starts with a &lsquo;<samp>@</samp>&rsquo;, then it is actually
  79. a series of templates, each on a separate line. (Blank lines and
  80. leading spaces and tabs are ignored.) The templates correspond to the
  81. pattern&rsquo;s constraint alternatives (see <a href="Multi_002dAlternative.html#Multi_002dAlternative">Multi-Alternative</a>). For example,
  82. if a target machine has a two-address add instruction &lsquo;<samp>addr</samp>&rsquo; to add
  83. into a register and another &lsquo;<samp>addm</samp>&rsquo; to add a register to memory, you
  84. might write this pattern:
  85. </p>
  86. <div class="smallexample">
  87. <pre class="smallexample">(define_insn &quot;addsi3&quot;
  88. [(set (match_operand:SI 0 &quot;general_operand&quot; &quot;=r,m&quot;)
  89. (plus:SI (match_operand:SI 1 &quot;general_operand&quot; &quot;0,0&quot;)
  90. (match_operand:SI 2 &quot;general_operand&quot; &quot;g,r&quot;)))]
  91. &quot;&quot;
  92. &quot;@
  93. addr %2,%0
  94. addm %2,%0&quot;)
  95. </pre></div>
  96. <a name="index-_002a-in-template"></a>
  97. <a name="index-asterisk-in-template"></a>
  98. <p>If the output control string starts with a &lsquo;<samp>*</samp>&rsquo;, then it is not an
  99. output template but rather a piece of C program that should compute a
  100. template. It should execute a <code>return</code> statement to return the
  101. template-string you want. Most such templates use C string literals, which
  102. require doublequote characters to delimit them. To include these
  103. doublequote characters in the string, prefix each one with &lsquo;<samp>\</samp>&rsquo;.
  104. </p>
  105. <p>If the output control string is written as a brace block instead of a
  106. double-quoted string, it is automatically assumed to be C code. In that
  107. case, it is not necessary to put in a leading asterisk, or to escape the
  108. doublequotes surrounding C string literals.
  109. </p>
  110. <p>The operands may be found in the array <code>operands</code>, whose C data type
  111. is <code>rtx []</code>.
  112. </p>
  113. <p>It is very common to select different ways of generating assembler code
  114. based on whether an immediate operand is within a certain range. Be
  115. careful when doing this, because the result of <code>INTVAL</code> is an
  116. integer on the host machine. If the host machine has more bits in an
  117. <code>int</code> than the target machine has in the mode in which the constant
  118. will be used, then some of the bits you get from <code>INTVAL</code> will be
  119. superfluous. For proper results, you must carefully disregard the
  120. values of those bits.
  121. </p>
  122. <a name="index-output_005fasm_005finsn"></a>
  123. <p>It is possible to output an assembler instruction and then go on to output
  124. or compute more of them, using the subroutine <code>output_asm_insn</code>. This
  125. receives two arguments: a template-string and a vector of operands. The
  126. vector may be <code>operands</code>, or it may be another array of <code>rtx</code>
  127. that you declare locally and initialize yourself.
  128. </p>
  129. <a name="index-which_005falternative"></a>
  130. <p>When an insn pattern has multiple alternatives in its constraints, often
  131. the appearance of the assembler code is determined mostly by which alternative
  132. was matched. When this is so, the C code can test the variable
  133. <code>which_alternative</code>, which is the ordinal number of the alternative
  134. that was actually satisfied (0 for the first, 1 for the second alternative,
  135. etc.).
  136. </p>
  137. <p>For example, suppose there are two opcodes for storing zero, &lsquo;<samp>clrreg</samp>&rsquo;
  138. for registers and &lsquo;<samp>clrmem</samp>&rsquo; for memory locations. Here is how
  139. a pattern could use <code>which_alternative</code> to choose between them:
  140. </p>
  141. <div class="smallexample">
  142. <pre class="smallexample">(define_insn &quot;&quot;
  143. [(set (match_operand:SI 0 &quot;general_operand&quot; &quot;=r,m&quot;)
  144. (const_int 0))]
  145. &quot;&quot;
  146. {
  147. return (which_alternative == 0
  148. ? &quot;clrreg %0&quot; : &quot;clrmem %0&quot;);
  149. })
  150. </pre></div>
  151. <p>The example above, where the assembler code to generate was
  152. <em>solely</em> determined by the alternative, could also have been specified
  153. as follows, having the output control string start with a &lsquo;<samp>@</samp>&rsquo;:
  154. </p>
  155. <div class="smallexample">
  156. <pre class="smallexample">(define_insn &quot;&quot;
  157. [(set (match_operand:SI 0 &quot;general_operand&quot; &quot;=r,m&quot;)
  158. (const_int 0))]
  159. &quot;&quot;
  160. &quot;@
  161. clrreg %0
  162. clrmem %0&quot;)
  163. </pre></div>
  164. <p>If you just need a little bit of C code in one (or a few) alternatives,
  165. you can use &lsquo;<samp>*</samp>&rsquo; inside of a &lsquo;<samp>@</samp>&rsquo; multi-alternative template:
  166. </p>
  167. <div class="smallexample">
  168. <pre class="smallexample">(define_insn &quot;&quot;
  169. [(set (match_operand:SI 0 &quot;general_operand&quot; &quot;=r,&lt;,m&quot;)
  170. (const_int 0))]
  171. &quot;&quot;
  172. &quot;@
  173. clrreg %0
  174. * return stack_mem_p (operands[0]) ? \&quot;push 0\&quot; : \&quot;clrmem %0\&quot;;
  175. clrmem %0&quot;)
  176. </pre></div>
  177. <hr>
  178. <div class="header">
  179. <p>
  180. Next: <a href="Predicates.html#Predicates" accesskey="n" rel="next">Predicates</a>, Previous: <a href="Output-Template.html#Output-Template" accesskey="p" rel="prev">Output Template</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>
  181. </div>
  182. </body>
  183. </html>