MODE_005fCC-Condition-Codes.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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: MODE_CC Condition Codes</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: MODE_CC Condition Codes">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: MODE_CC Condition Codes">
  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="Condition-Code.html#Condition-Code" rel="up" title="Condition Code">
  30. <link href="Costs.html#Costs" rel="next" title="Costs">
  31. <link href="CC0-Condition-Codes.html#CC0-Condition-Codes" rel="prev" title="CC0 Condition Codes">
  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="MODE_005fCC-Condition-Codes"></a>
  63. <div class="header">
  64. <p>
  65. Previous: <a href="CC0-Condition-Codes.html#CC0-Condition-Codes" accesskey="p" rel="prev">CC0 Condition Codes</a>, Up: <a href="Condition-Code.html#Condition-Code" accesskey="u" rel="up">Condition Code</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="Representation-of-condition-codes-using-registers"></a>
  69. <h4 class="subsection">17.15.2 Representation of condition codes using registers</h4>
  70. <a name="index-CCmode-1"></a>
  71. <a name="index-MODE_005fCC-1"></a>
  72. <dl>
  73. <dt><a name="index-SELECT_005fCC_005fMODE"></a>Macro: <strong>SELECT_CC_MODE</strong> <em>(<var>op</var>, <var>x</var>, <var>y</var>)</em></dt>
  74. <dd><p>On many machines, the condition code may be produced by other instructions
  75. than compares, for example the branch can use directly the condition
  76. code set by a subtract instruction. However, on some machines
  77. when the condition code is set this way some bits (such as the overflow
  78. bit) are not set in the same way as a test instruction, so that a different
  79. branch instruction must be used for some conditional branches. When
  80. this happens, use the machine mode of the condition code register to
  81. record different formats of the condition code register. Modes can
  82. also be used to record which compare instruction (e.g. a signed or an
  83. unsigned comparison) produced the condition codes.
  84. </p>
  85. <p>If other modes than <code>CCmode</code> are required, add them to
  86. <samp><var>machine</var>-modes.def</samp> and define <code>SELECT_CC_MODE</code> to choose
  87. a mode given an operand of a compare. This is needed because the modes
  88. have to be chosen not only during RTL generation but also, for example,
  89. by instruction combination. The result of <code>SELECT_CC_MODE</code> should
  90. be consistent with the mode used in the patterns; for example to support
  91. the case of the add on the SPARC discussed above, we have the pattern
  92. </p>
  93. <div class="smallexample">
  94. <pre class="smallexample">(define_insn &quot;&quot;
  95. [(set (reg:CCNZ 0)
  96. (compare:CCNZ
  97. (plus:SI (match_operand:SI 0 &quot;register_operand&quot; &quot;%r&quot;)
  98. (match_operand:SI 1 &quot;arith_operand&quot; &quot;rI&quot;))
  99. (const_int 0)))]
  100. &quot;&quot;
  101. &quot;&hellip;&quot;)
  102. </pre></div>
  103. <p>together with a <code>SELECT_CC_MODE</code> that returns <code>CCNZmode</code>
  104. for comparisons whose argument is a <code>plus</code>:
  105. </p>
  106. <div class="smallexample">
  107. <pre class="smallexample">#define SELECT_CC_MODE(OP,X,Y) \
  108. (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT \
  109. ? ((OP == LT || OP == LE || OP == GT || OP == GE) \
  110. ? CCFPEmode : CCFPmode) \
  111. : ((GET_CODE (X) == PLUS || GET_CODE (X) == MINUS \
  112. || GET_CODE (X) == NEG || GET_CODE (x) == ASHIFT) \
  113. ? CCNZmode : CCmode))
  114. </pre></div>
  115. <p>Another reason to use modes is to retain information on which operands
  116. were used by the comparison; see <code>REVERSIBLE_CC_MODE</code> later in
  117. this section.
  118. </p>
  119. <p>You should define this macro if and only if you define extra CC modes
  120. in <samp><var>machine</var>-modes.def</samp>.
  121. </p></dd></dl>
  122. <dl>
  123. <dt><a name="index-TARGET_005fCANONICALIZE_005fCOMPARISON"></a>Target Hook: <em>void</em> <strong>TARGET_CANONICALIZE_COMPARISON</strong> <em>(int *<var>code</var>, rtx *<var>op0</var>, rtx *<var>op1</var>, bool <var>op0_preserve_value</var>)</em></dt>
  124. <dd><p>On some machines not all possible comparisons are defined, but you can
  125. convert an invalid comparison into a valid one. For example, the Alpha
  126. does not have a <code>GT</code> comparison, but you can use an <code>LT</code>
  127. comparison instead and swap the order of the operands.
  128. </p>
  129. <p>On such machines, implement this hook to do any required conversions.
  130. <var>code</var> is the initial comparison code and <var>op0</var> and <var>op1</var>
  131. are the left and right operands of the comparison, respectively. If
  132. <var>op0_preserve_value</var> is <code>true</code> the implementation is not
  133. allowed to change the value of <var>op0</var> since the value might be used
  134. in RTXs which aren&rsquo;t comparisons. E.g. the implementation is not
  135. allowed to swap operands in that case.
  136. </p>
  137. <p>GCC will not assume that the comparison resulting from this macro is
  138. valid but will see if the resulting insn matches a pattern in the
  139. <samp>md</samp> file.
  140. </p>
  141. <p>You need not to implement this hook if it would never change the
  142. comparison code or operands.
  143. </p></dd></dl>
  144. <dl>
  145. <dt><a name="index-REVERSIBLE_005fCC_005fMODE"></a>Macro: <strong>REVERSIBLE_CC_MODE</strong> <em>(<var>mode</var>)</em></dt>
  146. <dd><p>A C expression whose value is one if it is always safe to reverse a
  147. comparison whose mode is <var>mode</var>. If <code>SELECT_CC_MODE</code>
  148. can ever return <var>mode</var> for a floating-point inequality comparison,
  149. then <code>REVERSIBLE_CC_MODE (<var>mode</var>)</code> must be zero.
  150. </p>
  151. <p>You need not define this macro if it would always returns zero or if the
  152. floating-point format is anything other than <code>IEEE_FLOAT_FORMAT</code>.
  153. For example, here is the definition used on the SPARC, where floating-point
  154. inequality comparisons are given either <code>CCFPEmode</code> or <code>CCFPmode</code>:
  155. </p>
  156. <div class="smallexample">
  157. <pre class="smallexample">#define REVERSIBLE_CC_MODE(MODE) \
  158. ((MODE) != CCFPEmode &amp;&amp; (MODE) != CCFPmode)
  159. </pre></div>
  160. </dd></dl>
  161. <dl>
  162. <dt><a name="index-REVERSE_005fCONDITION"></a>Macro: <strong>REVERSE_CONDITION</strong> <em>(<var>code</var>, <var>mode</var>)</em></dt>
  163. <dd><p>A C expression whose value is reversed condition code of the <var>code</var> for
  164. comparison done in CC_MODE <var>mode</var>. The macro is used only in case
  165. <code>REVERSIBLE_CC_MODE (<var>mode</var>)</code> is nonzero. Define this macro in case
  166. machine has some non-standard way how to reverse certain conditionals. For
  167. instance in case all floating point conditions are non-trapping, compiler may
  168. freely convert unordered compares to ordered ones. Then definition may look
  169. like:
  170. </p>
  171. <div class="smallexample">
  172. <pre class="smallexample">#define REVERSE_CONDITION(CODE, MODE) \
  173. ((MODE) != CCFPmode ? reverse_condition (CODE) \
  174. : reverse_condition_maybe_unordered (CODE))
  175. </pre></div>
  176. </dd></dl>
  177. <dl>
  178. <dt><a name="index-TARGET_005fFIXED_005fCONDITION_005fCODE_005fREGS"></a>Target Hook: <em>bool</em> <strong>TARGET_FIXED_CONDITION_CODE_REGS</strong> <em>(unsigned int *<var>p1</var>, unsigned int *<var>p2</var>)</em></dt>
  179. <dd><p>On targets which do not use <code>(cc0)</code>, and which use a hard
  180. register rather than a pseudo-register to hold condition codes, the
  181. regular CSE passes are often not able to identify cases in which the
  182. hard register is set to a common value. Use this hook to enable a
  183. small pass which optimizes such cases. This hook should return true
  184. to enable this pass, and it should set the integers to which its
  185. arguments point to the hard register numbers used for condition codes.
  186. When there is only one such register, as is true on most systems, the
  187. integer pointed to by <var>p2</var> should be set to
  188. <code>INVALID_REGNUM</code>.
  189. </p>
  190. <p>The default version of this hook returns false.
  191. </p></dd></dl>
  192. <dl>
  193. <dt><a name="index-TARGET_005fCC_005fMODES_005fCOMPATIBLE"></a>Target Hook: <em>machine_mode</em> <strong>TARGET_CC_MODES_COMPATIBLE</strong> <em>(machine_mode <var>m1</var>, machine_mode <var>m2</var>)</em></dt>
  194. <dd><p>On targets which use multiple condition code modes in class
  195. <code>MODE_CC</code>, it is sometimes the case that a comparison can be
  196. validly done in more than one mode. On such a system, define this
  197. target hook to take two mode arguments and to return a mode in which
  198. both comparisons may be validly done. If there is no such mode,
  199. return <code>VOIDmode</code>.
  200. </p>
  201. <p>The default version of this hook checks whether the modes are the
  202. same. If they are, it returns that mode. If they are different, it
  203. returns <code>VOIDmode</code>.
  204. </p></dd></dl>
  205. <dl>
  206. <dt><a name="index-TARGET_005fFLAGS_005fREGNUM"></a>Target Hook: <em>unsigned int</em> <strong>TARGET_FLAGS_REGNUM</strong></dt>
  207. <dd><p>If the target has a dedicated flags register, and it needs to use the post-reload comparison elimination pass, then this value should be set appropriately.
  208. </p></dd></dl>
  209. <hr>
  210. <div class="header">
  211. <p>
  212. Previous: <a href="CC0-Condition-Codes.html#CC0-Condition-Codes" accesskey="p" rel="prev">CC0 Condition Codes</a>, Up: <a href="Condition-Code.html#Condition-Code" accesskey="u" rel="up">Condition Code</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>
  213. </div>
  214. </body>
  215. </html>