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.

Comparisons.html 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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>Comparisons (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Comparisons (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Comparisons (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="RTL.html#RTL" rel="up" title="RTL">
  30. <link href="Bit_002dFields.html#Bit_002dFields" rel="next" title="Bit-Fields">
  31. <link href="Arithmetic.html#Arithmetic" rel="prev" title="Arithmetic">
  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="Comparisons"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Bit_002dFields.html#Bit_002dFields" accesskey="n" rel="next">Bit-Fields</a>, Previous: <a href="Arithmetic.html#Arithmetic" accesskey="p" rel="prev">Arithmetic</a>, Up: <a href="RTL.html#RTL" accesskey="u" rel="up">RTL</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="Comparison-Operations"></a>
  68. <h3 class="section">14.10 Comparison Operations</h3>
  69. <a name="index-RTL-comparison-operations"></a>
  70. <p>Comparison operators test a relation on two operands and are considered
  71. to represent a machine-dependent nonzero value described by, but not
  72. necessarily equal to, <code>STORE_FLAG_VALUE</code> (see <a href="Misc.html#Misc">Misc</a>)
  73. if the relation holds, or zero if it does not, for comparison operators
  74. whose results have a &lsquo;MODE_INT&rsquo; mode,
  75. <code>FLOAT_STORE_FLAG_VALUE</code> (see <a href="Misc.html#Misc">Misc</a>) if the relation holds, or
  76. zero if it does not, for comparison operators that return floating-point
  77. values, and a vector of either <code>VECTOR_STORE_FLAG_VALUE</code> (see <a href="Misc.html#Misc">Misc</a>)
  78. if the relation holds, or of zeros if it does not, for comparison operators
  79. that return vector results.
  80. The mode of the comparison operation is independent of the mode
  81. of the data being compared. If the comparison operation is being tested
  82. (e.g., the first operand of an <code>if_then_else</code>), the mode must be
  83. <code>VOIDmode</code>.
  84. </p>
  85. <a name="index-condition-codes"></a>
  86. <p>There are two ways that comparison operations may be used. The
  87. comparison operators may be used to compare the condition codes
  88. <code>(cc0)</code> against zero, as in <code>(eq (cc0) (const_int 0))</code>. Such
  89. a construct actually refers to the result of the preceding instruction
  90. in which the condition codes were set. The instruction setting the
  91. condition code must be adjacent to the instruction using the condition
  92. code; only <code>note</code> insns may separate them.
  93. </p>
  94. <p>Alternatively, a comparison operation may directly compare two data
  95. objects. The mode of the comparison is determined by the operands; they
  96. must both be valid for a common machine mode. A comparison with both
  97. operands constant would be invalid as the machine mode could not be
  98. deduced from it, but such a comparison should never exist in RTL due to
  99. constant folding.
  100. </p>
  101. <p>In the example above, if <code>(cc0)</code> were last set to
  102. <code>(compare <var>x</var> <var>y</var>)</code>, the comparison operation is
  103. identical to <code>(eq <var>x</var> <var>y</var>)</code>. Usually only one style
  104. of comparisons is supported on a particular machine, but the combine
  105. pass will try to merge the operations to produce the <code>eq</code> shown
  106. in case it exists in the context of the particular insn involved.
  107. </p>
  108. <p>Inequality comparisons come in two flavors, signed and unsigned. Thus,
  109. there are distinct expression codes <code>gt</code> and <code>gtu</code> for signed and
  110. unsigned greater-than. These can produce different results for the same
  111. pair of integer values: for example, 1 is signed greater-than -1 but not
  112. unsigned greater-than, because -1 when regarded as unsigned is actually
  113. <code>0xffffffff</code> which is greater than 1.
  114. </p>
  115. <p>The signed comparisons are also used for floating point values. Floating
  116. point comparisons are distinguished by the machine modes of the operands.
  117. </p>
  118. <dl compact="compact">
  119. <dd><a name="index-eq"></a>
  120. <a name="index-equal"></a>
  121. </dd>
  122. <dt><code>(eq:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  123. <dd><p><code>STORE_FLAG_VALUE</code> if the values represented by <var>x</var> and <var>y</var>
  124. are equal, otherwise 0.
  125. </p>
  126. <a name="index-ne"></a>
  127. <a name="index-not-equal"></a>
  128. </dd>
  129. <dt><code>(ne:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  130. <dd><p><code>STORE_FLAG_VALUE</code> if the values represented by <var>x</var> and <var>y</var>
  131. are not equal, otherwise 0.
  132. </p>
  133. <a name="index-gt"></a>
  134. <a name="index-greater-than"></a>
  135. </dd>
  136. <dt><code>(gt:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  137. <dd><p><code>STORE_FLAG_VALUE</code> if the <var>x</var> is greater than <var>y</var>. If they
  138. are fixed-point, the comparison is done in a signed sense.
  139. </p>
  140. <a name="index-gtu"></a>
  141. <a name="index-greater-than-1"></a>
  142. <a name="index-unsigned-greater-than"></a>
  143. </dd>
  144. <dt><code>(gtu:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  145. <dd><p>Like <code>gt</code> but does unsigned comparison, on fixed-point numbers only.
  146. </p>
  147. <a name="index-lt"></a>
  148. <a name="index-less-than"></a>
  149. <a name="index-ltu"></a>
  150. <a name="index-unsigned-less-than"></a>
  151. </dd>
  152. <dt><code>(lt:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  153. <dt><code>(ltu:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  154. <dd><p>Like <code>gt</code> and <code>gtu</code> but test for &ldquo;less than&rdquo;.
  155. </p>
  156. <a name="index-ge"></a>
  157. <a name="index-greater-than-2"></a>
  158. <a name="index-geu"></a>
  159. <a name="index-unsigned-greater-than-1"></a>
  160. </dd>
  161. <dt><code>(ge:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  162. <dt><code>(geu:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  163. <dd><p>Like <code>gt</code> and <code>gtu</code> but test for &ldquo;greater than or equal&rdquo;.
  164. </p>
  165. <a name="index-le"></a>
  166. <a name="index-less-than-or-equal"></a>
  167. <a name="index-leu"></a>
  168. <a name="index-unsigned-less-than-1"></a>
  169. </dd>
  170. <dt><code>(le:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  171. <dt><code>(leu:<var>m</var> <var>x</var> <var>y</var>)</code></dt>
  172. <dd><p>Like <code>gt</code> and <code>gtu</code> but test for &ldquo;less than or equal&rdquo;.
  173. </p>
  174. <a name="index-if_005fthen_005felse"></a>
  175. </dd>
  176. <dt><code>(if_then_else <var>cond</var> <var>then</var> <var>else</var>)</code></dt>
  177. <dd><p>This is not a comparison operation but is listed here because it is
  178. always used in conjunction with a comparison operation. To be
  179. precise, <var>cond</var> is a comparison expression. This expression
  180. represents a choice, according to <var>cond</var>, between the value
  181. represented by <var>then</var> and the one represented by <var>else</var>.
  182. </p>
  183. <p>On most machines, <code>if_then_else</code> expressions are valid only
  184. to express conditional jumps.
  185. </p>
  186. <a name="index-cond"></a>
  187. </dd>
  188. <dt><code>(cond [<var>test1</var> <var>value1</var> <var>test2</var> <var>value2</var> &hellip;] <var>default</var>)</code></dt>
  189. <dd><p>Similar to <code>if_then_else</code>, but more general. Each of <var>test1</var>,
  190. <var>test2</var>, &hellip; is performed in turn. The result of this expression is
  191. the <var>value</var> corresponding to the first nonzero test, or <var>default</var> if
  192. none of the tests are nonzero expressions.
  193. </p>
  194. <p>This is currently not valid for instruction patterns and is supported only
  195. for insn attributes. See <a href="Insn-Attributes.html#Insn-Attributes">Insn Attributes</a>.
  196. </p></dd>
  197. </dl>
  198. <hr>
  199. <div class="header">
  200. <p>
  201. Next: <a href="Bit_002dFields.html#Bit_002dFields" accesskey="n" rel="next">Bit-Fields</a>, Previous: <a href="Arithmetic.html#Arithmetic" accesskey="p" rel="prev">Arithmetic</a>, Up: <a href="RTL.html#RTL" accesskey="u" rel="up">RTL</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>
  202. </div>
  203. </body>
  204. </html>