Conversions.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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: Conversions</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Conversions">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Conversions">
  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="RTL-Declarations.html#RTL-Declarations" rel="next" title="RTL Declarations">
  31. <link href="Vector-Operations.html#Vector-Operations" rel="prev" title="Vector Operations">
  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="Conversions"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="RTL-Declarations.html#RTL-Declarations" accesskey="n" rel="next">RTL Declarations</a>, Previous: <a href="Vector-Operations.html#Vector-Operations" accesskey="p" rel="prev">Vector Operations</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="Conversions-1"></a>
  69. <h3 class="section">13.13 Conversions</h3>
  70. <a name="index-conversions"></a>
  71. <a name="index-machine-mode-conversions"></a>
  72. <p>All conversions between machine modes must be represented by
  73. explicit conversion operations. For example, an expression
  74. which is the sum of a byte and a full word cannot be written as
  75. <code>(plus:SI (reg:QI 34) (reg:SI 80))</code> because the <code>plus</code>
  76. operation requires two operands of the same machine mode.
  77. Therefore, the byte-sized operand is enclosed in a conversion
  78. operation, as in
  79. </p>
  80. <div class="smallexample">
  81. <pre class="smallexample">(plus:SI (sign_extend:SI (reg:QI 34)) (reg:SI 80))
  82. </pre></div>
  83. <p>The conversion operation is not a mere placeholder, because there
  84. may be more than one way of converting from a given starting mode
  85. to the desired final mode. The conversion operation code says how
  86. to do it.
  87. </p>
  88. <p>For all conversion operations, <var>x</var> must not be <code>VOIDmode</code>
  89. because the mode in which to do the conversion would not be known.
  90. The conversion must either be done at compile-time or <var>x</var>
  91. must be placed into a register.
  92. </p>
  93. <dl compact="compact">
  94. <dd><a name="index-sign_005fextend"></a>
  95. </dd>
  96. <dt><code>(sign_extend:<var>m</var> <var>x</var>)</code></dt>
  97. <dd><p>Represents the result of sign-extending the value <var>x</var>
  98. to machine mode <var>m</var>. <var>m</var> must be a fixed-point mode
  99. and <var>x</var> a fixed-point value of a mode narrower than <var>m</var>.
  100. </p>
  101. <a name="index-zero_005fextend"></a>
  102. </dd>
  103. <dt><code>(zero_extend:<var>m</var> <var>x</var>)</code></dt>
  104. <dd><p>Represents the result of zero-extending the value <var>x</var>
  105. to machine mode <var>m</var>. <var>m</var> must be a fixed-point mode
  106. and <var>x</var> a fixed-point value of a mode narrower than <var>m</var>.
  107. </p>
  108. <a name="index-float_005fextend"></a>
  109. </dd>
  110. <dt><code>(float_extend:<var>m</var> <var>x</var>)</code></dt>
  111. <dd><p>Represents the result of extending the value <var>x</var>
  112. to machine mode <var>m</var>. <var>m</var> must be a floating point mode
  113. and <var>x</var> a floating point value of a mode narrower than <var>m</var>.
  114. </p>
  115. <a name="index-truncate"></a>
  116. </dd>
  117. <dt><code>(truncate:<var>m</var> <var>x</var>)</code></dt>
  118. <dd><p>Represents the result of truncating the value <var>x</var>
  119. to machine mode <var>m</var>. <var>m</var> must be a fixed-point mode
  120. and <var>x</var> a fixed-point value of a mode wider than <var>m</var>.
  121. </p>
  122. <a name="index-ss_005ftruncate"></a>
  123. </dd>
  124. <dt><code>(ss_truncate:<var>m</var> <var>x</var>)</code></dt>
  125. <dd><p>Represents the result of truncating the value <var>x</var>
  126. to machine mode <var>m</var>, using signed saturation in the case of
  127. overflow. Both <var>m</var> and the mode of <var>x</var> must be fixed-point
  128. modes.
  129. </p>
  130. <a name="index-us_005ftruncate"></a>
  131. </dd>
  132. <dt><code>(us_truncate:<var>m</var> <var>x</var>)</code></dt>
  133. <dd><p>Represents the result of truncating the value <var>x</var>
  134. to machine mode <var>m</var>, using unsigned saturation in the case of
  135. overflow. Both <var>m</var> and the mode of <var>x</var> must be fixed-point
  136. modes.
  137. </p>
  138. <a name="index-float_005ftruncate"></a>
  139. </dd>
  140. <dt><code>(float_truncate:<var>m</var> <var>x</var>)</code></dt>
  141. <dd><p>Represents the result of truncating the value <var>x</var>
  142. to machine mode <var>m</var>. <var>m</var> must be a floating point mode
  143. and <var>x</var> a floating point value of a mode wider than <var>m</var>.
  144. </p>
  145. <a name="index-float"></a>
  146. </dd>
  147. <dt><code>(float:<var>m</var> <var>x</var>)</code></dt>
  148. <dd><p>Represents the result of converting fixed point value <var>x</var>,
  149. regarded as signed, to floating point mode <var>m</var>.
  150. </p>
  151. <a name="index-unsigned_005ffloat"></a>
  152. </dd>
  153. <dt><code>(unsigned_float:<var>m</var> <var>x</var>)</code></dt>
  154. <dd><p>Represents the result of converting fixed point value <var>x</var>,
  155. regarded as unsigned, to floating point mode <var>m</var>.
  156. </p>
  157. <a name="index-fix"></a>
  158. </dd>
  159. <dt><code>(fix:<var>m</var> <var>x</var>)</code></dt>
  160. <dd><p>When <var>m</var> is a floating-point mode, represents the result of
  161. converting floating point value <var>x</var> (valid for mode <var>m</var>) to an
  162. integer, still represented in floating point mode <var>m</var>, by rounding
  163. towards zero.
  164. </p>
  165. <p>When <var>m</var> is a fixed-point mode, represents the result of
  166. converting floating point value <var>x</var> to mode <var>m</var>, regarded as
  167. signed. How rounding is done is not specified, so this operation may
  168. be used validly in compiling C code only for integer-valued operands.
  169. </p>
  170. <a name="index-unsigned_005ffix"></a>
  171. </dd>
  172. <dt><code>(unsigned_fix:<var>m</var> <var>x</var>)</code></dt>
  173. <dd><p>Represents the result of converting floating point value <var>x</var> to
  174. fixed point mode <var>m</var>, regarded as unsigned. How rounding is done
  175. is not specified.
  176. </p>
  177. <a name="index-fract_005fconvert"></a>
  178. </dd>
  179. <dt><code>(fract_convert:<var>m</var> <var>x</var>)</code></dt>
  180. <dd><p>Represents the result of converting fixed-point value <var>x</var> to
  181. fixed-point mode <var>m</var>, signed integer value <var>x</var> to
  182. fixed-point mode <var>m</var>, floating-point value <var>x</var> to
  183. fixed-point mode <var>m</var>, fixed-point value <var>x</var> to integer mode <var>m</var>
  184. regarded as signed, or fixed-point value <var>x</var> to floating-point mode <var>m</var>.
  185. When overflows or underflows happen, the results are undefined.
  186. </p>
  187. <a name="index-sat_005ffract"></a>
  188. </dd>
  189. <dt><code>(sat_fract:<var>m</var> <var>x</var>)</code></dt>
  190. <dd><p>Represents the result of converting fixed-point value <var>x</var> to
  191. fixed-point mode <var>m</var>, signed integer value <var>x</var> to
  192. fixed-point mode <var>m</var>, or floating-point value <var>x</var> to
  193. fixed-point mode <var>m</var>.
  194. When overflows or underflows happen, the results are saturated to the
  195. maximum or the minimum.
  196. </p>
  197. <a name="index-unsigned_005ffract_005fconvert"></a>
  198. </dd>
  199. <dt><code>(unsigned_fract_convert:<var>m</var> <var>x</var>)</code></dt>
  200. <dd><p>Represents the result of converting fixed-point value <var>x</var> to
  201. integer mode <var>m</var> regarded as unsigned, or unsigned integer value <var>x</var> to
  202. fixed-point mode <var>m</var>.
  203. When overflows or underflows happen, the results are undefined.
  204. </p>
  205. <a name="index-unsigned_005fsat_005ffract"></a>
  206. </dd>
  207. <dt><code>(unsigned_sat_fract:<var>m</var> <var>x</var>)</code></dt>
  208. <dd><p>Represents the result of converting unsigned integer value <var>x</var> to
  209. fixed-point mode <var>m</var>.
  210. When overflows or underflows happen, the results are saturated to the
  211. maximum or the minimum.
  212. </p></dd>
  213. </dl>
  214. <hr>
  215. <div class="header">
  216. <p>
  217. Next: <a href="RTL-Declarations.html#RTL-Declarations" accesskey="n" rel="next">RTL Declarations</a>, Previous: <a href="Vector-Operations.html#Vector-Operations" accesskey="p" rel="prev">Vector Operations</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>
  218. </div>
  219. </body>
  220. </html>