Simple-Constraints.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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>Using the GNU Compiler Collection (GCC): Simple Constraints</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Simple Constraints">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Simple Constraints">
  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="Multi_002dAlternative.html#Multi_002dAlternative" rel="next" title="Multi-Alternative">
  31. <link href="Constraints.html#Constraints" rel="prev" title="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="Simple-Constraints"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Multi_002dAlternative.html#Multi_002dAlternative" accesskey="n" rel="next">Multi-Alternative</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="Simple-Constraints-1"></a>
  69. <h4 class="subsubsection">6.45.3.1 Simple Constraints</h4>
  70. <a name="index-simple-constraints"></a>
  71. <p>The simplest kind of constraint is a string full of letters, each of
  72. which describes one kind of operand that is permitted. Here are
  73. the letters that are allowed:
  74. </p>
  75. <dl compact="compact">
  76. <dt>whitespace</dt>
  77. <dd><p>Whitespace characters are ignored and can be inserted at any position
  78. except the first. This enables each alternative for different operands to
  79. be visually aligned in the machine description even if they have different
  80. number of constraints and modifiers.
  81. </p>
  82. <a name="index-m-in-constraint"></a>
  83. <a name="index-memory-references-in-constraints"></a>
  84. </dd>
  85. <dt>&lsquo;<samp>m</samp>&rsquo;</dt>
  86. <dd><p>A memory operand is allowed, with any kind of address that the machine
  87. supports in general.
  88. Note that the letter used for the general memory constraint can be
  89. re-defined by a back end using the <code>TARGET_MEM_CONSTRAINT</code> macro.
  90. </p>
  91. <a name="index-offsettable-address"></a>
  92. <a name="index-o-in-constraint"></a>
  93. </dd>
  94. <dt>&lsquo;<samp>o</samp>&rsquo;</dt>
  95. <dd><p>A memory operand is allowed, but only if the address is
  96. <em>offsettable</em>. This means that adding a small integer (actually,
  97. the width in bytes of the operand, as determined by its machine mode)
  98. may be added to the address and the result is also a valid memory
  99. address.
  100. </p>
  101. <a name="index-autoincrement_002fdecrement-addressing"></a>
  102. <p>For example, an address which is constant is offsettable; so is an
  103. address that is the sum of a register and a constant (as long as a
  104. slightly larger constant is also within the range of address-offsets
  105. supported by the machine); but an autoincrement or autodecrement
  106. address is not offsettable. More complicated indirect/indexed
  107. addresses may or may not be offsettable depending on the other
  108. addressing modes that the machine supports.
  109. </p>
  110. <p>Note that in an output operand which can be matched by another
  111. operand, the constraint letter &lsquo;<samp>o</samp>&rsquo; is valid only when accompanied
  112. by both &lsquo;<samp>&lt;</samp>&rsquo; (if the target machine has predecrement addressing)
  113. and &lsquo;<samp>&gt;</samp>&rsquo; (if the target machine has preincrement addressing).
  114. </p>
  115. <a name="index-V-in-constraint"></a>
  116. </dd>
  117. <dt>&lsquo;<samp>V</samp>&rsquo;</dt>
  118. <dd><p>A memory operand that is not offsettable. In other words, anything that
  119. would fit the &lsquo;<samp>m</samp>&rsquo; constraint but not the &lsquo;<samp>o</samp>&rsquo; constraint.
  120. </p>
  121. <a name="index-_003c-in-constraint"></a>
  122. </dd>
  123. <dt>&lsquo;<samp>&lt;</samp>&rsquo;</dt>
  124. <dd><p>A memory operand with autodecrement addressing (either predecrement or
  125. postdecrement) is allowed. In inline <code>asm</code> this constraint is only
  126. allowed if the operand is used exactly once in an instruction that can
  127. handle the side-effects. Not using an operand with &lsquo;<samp>&lt;</samp>&rsquo; in constraint
  128. string in the inline <code>asm</code> pattern at all or using it in multiple
  129. instructions isn&rsquo;t valid, because the side-effects wouldn&rsquo;t be performed
  130. or would be performed more than once. Furthermore, on some targets
  131. the operand with &lsquo;<samp>&lt;</samp>&rsquo; in constraint string must be accompanied by
  132. special instruction suffixes like <code>%U0</code> instruction suffix on PowerPC
  133. or <code>%P0</code> on IA-64.
  134. </p>
  135. <a name="index-_003e-in-constraint"></a>
  136. </dd>
  137. <dt>&lsquo;<samp>&gt;</samp>&rsquo;</dt>
  138. <dd><p>A memory operand with autoincrement addressing (either preincrement or
  139. postincrement) is allowed. In inline <code>asm</code> the same restrictions
  140. as for &lsquo;<samp>&lt;</samp>&rsquo; apply.
  141. </p>
  142. <a name="index-r-in-constraint"></a>
  143. <a name="index-registers-in-constraints"></a>
  144. </dd>
  145. <dt>&lsquo;<samp>r</samp>&rsquo;</dt>
  146. <dd><p>A register operand is allowed provided that it is in a general
  147. register.
  148. </p>
  149. <a name="index-constants-in-constraints"></a>
  150. <a name="index-i-in-constraint"></a>
  151. </dd>
  152. <dt>&lsquo;<samp>i</samp>&rsquo;</dt>
  153. <dd><p>An immediate integer operand (one with constant value) is allowed.
  154. This includes symbolic constants whose values will be known only at
  155. assembly time or later.
  156. </p>
  157. <a name="index-n-in-constraint"></a>
  158. </dd>
  159. <dt>&lsquo;<samp>n</samp>&rsquo;</dt>
  160. <dd><p>An immediate integer operand with a known numeric value is allowed.
  161. Many systems cannot support assembly-time constants for operands less
  162. than a word wide. Constraints for these operands should use &lsquo;<samp>n</samp>&rsquo;
  163. rather than &lsquo;<samp>i</samp>&rsquo;.
  164. </p>
  165. <a name="index-I-in-constraint"></a>
  166. </dd>
  167. <dt>&lsquo;<samp>I</samp>&rsquo;, &lsquo;<samp>J</samp>&rsquo;, &lsquo;<samp>K</samp>&rsquo;, &hellip; &lsquo;<samp>P</samp>&rsquo;</dt>
  168. <dd><p>Other letters in the range &lsquo;<samp>I</samp>&rsquo; through &lsquo;<samp>P</samp>&rsquo; may be defined in
  169. a machine-dependent fashion to permit immediate integer operands with
  170. explicit integer values in specified ranges. For example, on the
  171. 68000, &lsquo;<samp>I</samp>&rsquo; is defined to stand for the range of values 1 to 8.
  172. This is the range permitted as a shift count in the shift
  173. instructions.
  174. </p>
  175. <a name="index-E-in-constraint"></a>
  176. </dd>
  177. <dt>&lsquo;<samp>E</samp>&rsquo;</dt>
  178. <dd><p>An immediate floating operand (expression code <code>const_double</code>) is
  179. allowed, but only if the target floating point format is the same as
  180. that of the host machine (on which the compiler is running).
  181. </p>
  182. <a name="index-F-in-constraint"></a>
  183. </dd>
  184. <dt>&lsquo;<samp>F</samp>&rsquo;</dt>
  185. <dd><p>An immediate floating operand (expression code <code>const_double</code> or
  186. <code>const_vector</code>) is allowed.
  187. </p>
  188. <a name="index-G-in-constraint"></a>
  189. <a name="index-H-in-constraint"></a>
  190. </dd>
  191. <dt>&lsquo;<samp>G</samp>&rsquo;, &lsquo;<samp>H</samp>&rsquo;</dt>
  192. <dd><p>&lsquo;<samp>G</samp>&rsquo; and &lsquo;<samp>H</samp>&rsquo; may be defined in a machine-dependent fashion to
  193. permit immediate floating operands in particular ranges of values.
  194. </p>
  195. <a name="index-s-in-constraint"></a>
  196. </dd>
  197. <dt>&lsquo;<samp>s</samp>&rsquo;</dt>
  198. <dd><p>An immediate integer operand whose value is not an explicit integer is
  199. allowed.
  200. </p>
  201. <p>This might appear strange; if an insn allows a constant operand with a
  202. value not known at compile time, it certainly must allow any known
  203. value. So why use &lsquo;<samp>s</samp>&rsquo; instead of &lsquo;<samp>i</samp>&rsquo;? Sometimes it allows
  204. better code to be generated.
  205. </p>
  206. <p>For example, on the 68000 in a fullword instruction it is possible to
  207. use an immediate operand; but if the immediate value is between -128
  208. and 127, better code results from loading the value into a register and
  209. using the register. This is because the load into the register can be
  210. done with a &lsquo;<samp>moveq</samp>&rsquo; instruction. We arrange for this to happen
  211. by defining the letter &lsquo;<samp>K</samp>&rsquo; to mean &ldquo;any integer outside the
  212. range -128 to 127&rdquo;, and then specifying &lsquo;<samp>Ks</samp>&rsquo; in the operand
  213. constraints.
  214. </p>
  215. <a name="index-g-in-constraint"></a>
  216. </dd>
  217. <dt>&lsquo;<samp>g</samp>&rsquo;</dt>
  218. <dd><p>Any register, memory or immediate integer operand is allowed, except for
  219. registers that are not general registers.
  220. </p>
  221. <a name="index-X-in-constraint"></a>
  222. </dd>
  223. <dt>&lsquo;<samp>X</samp>&rsquo;</dt>
  224. <dd><p>Any operand whatsoever is allowed.
  225. </p>
  226. <a name="index-0-in-constraint"></a>
  227. <a name="index-digits-in-constraint"></a>
  228. </dd>
  229. <dt>&lsquo;<samp>0</samp>&rsquo;, &lsquo;<samp>1</samp>&rsquo;, &lsquo;<samp>2</samp>&rsquo;, &hellip; &lsquo;<samp>9</samp>&rsquo;</dt>
  230. <dd><p>An operand that matches the specified operand number is allowed. If a
  231. digit is used together with letters within the same alternative, the
  232. digit should come last.
  233. </p>
  234. <p>This number is allowed to be more than a single digit. If multiple
  235. digits are encountered consecutively, they are interpreted as a single
  236. decimal integer. There is scant chance for ambiguity, since to-date
  237. it has never been desirable that &lsquo;<samp>10</samp>&rsquo; be interpreted as matching
  238. either operand 1 <em>or</em> operand 0. Should this be desired, one
  239. can use multiple alternatives instead.
  240. </p>
  241. <a name="index-matching-constraint"></a>
  242. <a name="index-constraint_002c-matching"></a>
  243. <p>This is called a <em>matching constraint</em> and what it really means is
  244. that the assembler has only a single operand that fills two roles
  245. which <code>asm</code> distinguishes. For example, an add instruction uses
  246. two input operands and an output operand, but on most CISC
  247. machines an add instruction really has only two operands, one of them an
  248. input-output operand:
  249. </p>
  250. <div class="smallexample">
  251. <pre class="smallexample">addl #35,r12
  252. </pre></div>
  253. <p>Matching constraints are used in these circumstances.
  254. More precisely, the two operands that match must include one input-only
  255. operand and one output-only operand. Moreover, the digit must be a
  256. smaller number than the number of the operand that uses it in the
  257. constraint.
  258. </p>
  259. <a name="index-load-address-instruction"></a>
  260. <a name="index-push-address-instruction"></a>
  261. <a name="index-address-constraints"></a>
  262. <a name="index-p-in-constraint"></a>
  263. </dd>
  264. <dt>&lsquo;<samp>p</samp>&rsquo;</dt>
  265. <dd><p>An operand that is a valid memory address is allowed. This is
  266. for &ldquo;load address&rdquo; and &ldquo;push address&rdquo; instructions.
  267. </p>
  268. <a name="index-address_005foperand"></a>
  269. <p>&lsquo;<samp>p</samp>&rsquo; in the constraint must be accompanied by <code>address_operand</code>
  270. as the predicate in the <code>match_operand</code>. This predicate interprets
  271. the mode specified in the <code>match_operand</code> as the mode of the memory
  272. reference for which the address would be valid.
  273. </p>
  274. <a name="index-other-register-constraints"></a>
  275. <a name="index-extensible-constraints"></a>
  276. </dd>
  277. <dt><var>other-letters</var></dt>
  278. <dd><p>Other letters can be defined in machine-dependent fashion to stand for
  279. particular classes of registers or other arbitrary operand types.
  280. &lsquo;<samp>d</samp>&rsquo;, &lsquo;<samp>a</samp>&rsquo; and &lsquo;<samp>f</samp>&rsquo; are defined on the 68000/68020 to stand
  281. for data, address and floating point registers.
  282. </p></dd>
  283. </dl>
  284. <hr>
  285. <div class="header">
  286. <p>
  287. Next: <a href="Multi_002dAlternative.html#Multi_002dAlternative" accesskey="n" rel="next">Multi-Alternative</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>
  288. </div>
  289. </body>
  290. </html>