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.

239 lines
12KB

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