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.

181 satır
8.0KB

  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>Insn Lengths (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Insn Lengths (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Insn Lengths (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="Insn-Attributes.html#Insn-Attributes" rel="up" title="Insn Attributes">
  30. <link href="Constant-Attributes.html#Constant-Attributes" rel="next" title="Constant Attributes">
  31. <link href="Attr-Example.html#Attr-Example" rel="prev" title="Attr Example">
  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="Insn-Lengths"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Constant-Attributes.html#Constant-Attributes" accesskey="n" rel="next">Constant Attributes</a>, Previous: <a href="Attr-Example.html#Attr-Example" accesskey="p" rel="prev">Attr Example</a>, Up: <a href="Insn-Attributes.html#Insn-Attributes" accesskey="u" rel="up">Insn Attributes</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="Computing-the-Length-of-an-Insn"></a>
  68. <h4 class="subsection">17.19.5 Computing the Length of an Insn</h4>
  69. <a name="index-insn-lengths_002c-computing"></a>
  70. <a name="index-computing-the-length-of-an-insn"></a>
  71. <p>For many machines, multiple types of branch instructions are provided, each
  72. for different length branch displacements. In most cases, the assembler
  73. will choose the correct instruction to use. However, when the assembler
  74. cannot do so, GCC can when a special attribute, the <code>length</code>
  75. attribute, is defined. This attribute must be defined to have numeric
  76. values by specifying a null string in its <code>define_attr</code>.
  77. </p>
  78. <p>In the case of the <code>length</code> attribute, two additional forms of
  79. arithmetic terms are allowed in test expressions:
  80. </p>
  81. <dl compact="compact">
  82. <dd><a name="index-match_005fdup-and-attributes"></a>
  83. </dd>
  84. <dt><code>(match_dup <var>n</var>)</code></dt>
  85. <dd><p>This refers to the address of operand <var>n</var> of the current insn, which
  86. must be a <code>label_ref</code>.
  87. </p>
  88. <a name="index-pc-and-attributes"></a>
  89. </dd>
  90. <dt><code>(pc)</code></dt>
  91. <dd><p>For non-branch instructions and backward branch instructions, this refers
  92. to the address of the current insn. But for forward branch instructions,
  93. this refers to the address of the next insn, because the length of the
  94. current insn is to be computed.
  95. </p></dd>
  96. </dl>
  97. <a name="index-addr_005fvec_002c-length-of"></a>
  98. <a name="index-addr_005fdiff_005fvec_002c-length-of"></a>
  99. <p>For normal insns, the length will be determined by value of the
  100. <code>length</code> attribute. In the case of <code>addr_vec</code> and
  101. <code>addr_diff_vec</code> insn patterns, the length is computed as
  102. the number of vectors multiplied by the size of each vector.
  103. </p>
  104. <p>Lengths are measured in addressable storage units (bytes).
  105. </p>
  106. <p>Note that it is possible to call functions via the <code>symbol_ref</code>
  107. mechanism to compute the length of an insn. However, if you use this
  108. mechanism you must provide dummy clauses to express the maximum length
  109. without using the function call. You can an example of this in the
  110. <code>pa</code> machine description for the <code>call_symref</code> pattern.
  111. </p>
  112. <p>The following macros can be used to refine the length computation:
  113. </p>
  114. <dl compact="compact">
  115. <dd><a name="index-ADJUST_005fINSN_005fLENGTH"></a>
  116. </dd>
  117. <dt><code>ADJUST_INSN_LENGTH (<var>insn</var>, <var>length</var>)</code></dt>
  118. <dd><p>If defined, modifies the length assigned to instruction <var>insn</var> as a
  119. function of the context in which it is used. <var>length</var> is an lvalue
  120. that contains the initially computed length of the insn and should be
  121. updated with the correct length of the insn.
  122. </p>
  123. <p>This macro will normally not be required. A case in which it is
  124. required is the ROMP. On this machine, the size of an <code>addr_vec</code>
  125. insn must be increased by two to compensate for the fact that alignment
  126. may be required.
  127. </p></dd>
  128. </dl>
  129. <a name="index-get_005fattr_005flength"></a>
  130. <p>The routine that returns <code>get_attr_length</code> (the value of the
  131. <code>length</code> attribute) can be used by the output routine to
  132. determine the form of the branch instruction to be written, as the
  133. example below illustrates.
  134. </p>
  135. <p>As an example of the specification of variable-length branches, consider
  136. the IBM 360. If we adopt the convention that a register will be set to
  137. the starting address of a function, we can jump to labels within 4k of
  138. the start using a four-byte instruction. Otherwise, we need a six-byte
  139. sequence to load the address from memory and then branch to it.
  140. </p>
  141. <p>On such a machine, a pattern for a branch instruction might be specified
  142. as follows:
  143. </p>
  144. <div class="smallexample">
  145. <pre class="smallexample">(define_insn &quot;jump&quot;
  146. [(set (pc)
  147. (label_ref (match_operand 0 &quot;&quot; &quot;&quot;)))]
  148. &quot;&quot;
  149. {
  150. return (get_attr_length (insn) == 4
  151. ? &quot;b %l0&quot; : &quot;l r15,=a(%l0); br r15&quot;);
  152. }
  153. [(set (attr &quot;length&quot;)
  154. (if_then_else (lt (match_dup 0) (const_int 4096))
  155. (const_int 4)
  156. (const_int 6)))])
  157. </pre></div>
  158. <hr>
  159. <div class="header">
  160. <p>
  161. Next: <a href="Constant-Attributes.html#Constant-Attributes" accesskey="n" rel="next">Constant Attributes</a>, Previous: <a href="Attr-Example.html#Attr-Example" accesskey="p" rel="prev">Attr Example</a>, Up: <a href="Insn-Attributes.html#Insn-Attributes" accesskey="u" rel="up">Insn Attributes</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>
  162. </div>
  163. </body>
  164. </html>