Comparisons.html 10 KB

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