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.

189 lines
9.6KB

  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>Converting poly_ints (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Converting poly_ints (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Converting poly_ints (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="poly_005fint.html#poly_005fint" rel="up" title="poly_int">
  30. <link href="Miscellaneous-poly_005fint-routines.html#Miscellaneous-poly_005fint-routines" rel="next" title="Miscellaneous poly_int routines">
  31. <link href="Computing-bounds-on-poly_005fints.html#Computing-bounds-on-poly_005fints" rel="prev" title="Computing bounds on poly_ints">
  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="Converting-poly_005fints"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Miscellaneous-poly_005fint-routines.html#Miscellaneous-poly_005fint-routines" accesskey="n" rel="next">Miscellaneous <code>poly_int</code> routines</a>, Previous: <a href="Computing-bounds-on-poly_005fints.html#Computing-bounds-on-poly_005fints" accesskey="p" rel="prev">Computing bounds on <code>poly_int</code>s</a>, Up: <a href="poly_005fint.html#poly_005fint" accesskey="u" rel="up">poly_int</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="Converting-poly_005fints-1"></a>
  68. <h3 class="section">10.7 Converting <code>poly_int</code>s</h3>
  69. <p>A <code>poly_int&lt;<var>n</var>, <var>T</var>&gt;</code> can be constructed from up to
  70. <var>n</var> individual <var>T</var> coefficients, with the remaining coefficients
  71. being implicitly zero. In particular, this means that every
  72. <code>poly_int&lt;<var>n</var>, <var>T</var>&gt;</code> can be constructed from a single
  73. scalar <var>T</var>, or something compatible with <var>T</var>.
  74. </p>
  75. <p>Also, a <code>poly_int&lt;<var>n</var>, <var>T</var>&gt;</code> can be constructed from
  76. a <code>poly_int&lt;<var>n</var>, <var>U</var>&gt;</code> if <var>T</var> can be constructed
  77. from <var>U</var>.
  78. </p>
  79. <p>The following functions provide other forms of conversion,
  80. or test whether such a conversion would succeed.
  81. </p>
  82. <dl compact="compact">
  83. <dt>&lsquo;<samp><var>value</var>.is_constant ()</samp>&rsquo;</dt>
  84. <dd><p>Return true if <code>poly_int</code> <var>value</var> is a compile-time constant.
  85. </p>
  86. </dd>
  87. <dt>&lsquo;<samp><var>value</var>.is_constant (&amp;<var>c1</var>)</samp>&rsquo;</dt>
  88. <dd><p>Return true if <code>poly_int</code> <var>value</var> is a compile-time constant,
  89. storing it in <var>c1</var> if so. <var>c1</var> must be able to hold all
  90. constant values of <var>value</var> without loss of precision.
  91. </p>
  92. </dd>
  93. <dt>&lsquo;<samp><var>value</var>.to_constant ()</samp>&rsquo;</dt>
  94. <dd><p>Assert that <var>value</var> is a compile-time constant and return its value.
  95. When using this function, please add a comment explaining why the
  96. condition is known to hold (for example, because an earlier phase
  97. of analysis rejected non-constants).
  98. </p>
  99. </dd>
  100. <dt>&lsquo;<samp><var>value</var>.to_shwi (&amp;<var>p2</var>)</samp>&rsquo;</dt>
  101. <dd><p>Return true if &lsquo;<samp>poly_int&lt;<var>N</var>, <var>T</var>&gt;</samp>&rsquo; <var>value</var> can be
  102. represented without loss of precision as a
  103. &lsquo;<samp>poly_int&lt;<var>N</var>, <code>HOST_WIDE_INT</code>&gt;</samp>&rsquo;, storing it in that
  104. form in <var>p2</var> if so.
  105. </p>
  106. </dd>
  107. <dt>&lsquo;<samp><var>value</var>.to_uhwi (&amp;<var>p2</var>)</samp>&rsquo;</dt>
  108. <dd><p>Return true if &lsquo;<samp>poly_int&lt;<var>N</var>, <var>T</var>&gt;</samp>&rsquo; <var>value</var> can be
  109. represented without loss of precision as a
  110. &lsquo;<samp>poly_int&lt;<var>N</var>, <code>unsigned HOST_WIDE_INT</code>&gt;</samp>&rsquo;, storing it in that
  111. form in <var>p2</var> if so.
  112. </p>
  113. </dd>
  114. <dt>&lsquo;<samp><var>value</var>.force_shwi ()</samp>&rsquo;</dt>
  115. <dd><p>Forcibly convert each coefficient of &lsquo;<samp>poly_int&lt;<var>N</var>, <var>T</var>&gt;</samp>&rsquo;
  116. <var>value</var> to <code>HOST_WIDE_INT</code>, truncating any that are out of range.
  117. Return the result as a &lsquo;<samp>poly_int&lt;<var>N</var>, <code>HOST_WIDE_INT</code>&gt;</samp>&rsquo;.
  118. </p>
  119. </dd>
  120. <dt>&lsquo;<samp><var>value</var>.force_uhwi ()</samp>&rsquo;</dt>
  121. <dd><p>Forcibly convert each coefficient of &lsquo;<samp>poly_int&lt;<var>N</var>, <var>T</var>&gt;</samp>&rsquo;
  122. <var>value</var> to <code>unsigned HOST_WIDE_INT</code>, truncating any that are
  123. out of range. Return the result as a
  124. &lsquo;<samp>poly_int&lt;<var>N</var>, <code>unsigned HOST_WIDE_INT</code>&gt;</samp>&rsquo;.
  125. </p>
  126. </dd>
  127. <dt>&lsquo;<samp>wi::shwi (<var>value</var>, <var>precision</var>)</samp>&rsquo;</dt>
  128. <dd><p>Return a <code>poly_int</code> with the same value as <var>value</var>, but with
  129. the coefficients converted from <code>HOST_WIDE_INT</code> to <code>wide_int</code>.
  130. <var>precision</var> specifies the precision of the <code>wide_int</code> cofficients;
  131. if this is wider than a <code>HOST_WIDE_INT</code>, the coefficients of
  132. <var>value</var> will be sign-extended to fit.
  133. </p>
  134. </dd>
  135. <dt>&lsquo;<samp>wi::uhwi (<var>value</var>, <var>precision</var>)</samp>&rsquo;</dt>
  136. <dd><p>Like <code>wi::shwi</code>, except that <var>value</var> has coefficients of
  137. type <code>unsigned HOST_WIDE_INT</code>. If <var>precision</var> is wider than
  138. a <code>HOST_WIDE_INT</code>, the coefficients of <var>value</var> will be
  139. zero-extended to fit.
  140. </p>
  141. </dd>
  142. <dt>&lsquo;<samp>wi::sext (<var>value</var>, <var>precision</var>)</samp>&rsquo;</dt>
  143. <dd><p>Return a <code>poly_int</code> of the same type as <var>value</var>, sign-extending
  144. every coefficient from the low <var>precision</var> bits. This in effect
  145. applies <code>wi::sext</code> to each coefficient individually.
  146. </p>
  147. </dd>
  148. <dt>&lsquo;<samp>wi::zext (<var>value</var>, <var>precision</var>)</samp>&rsquo;</dt>
  149. <dd><p>Like <code>wi::sext</code>, but for zero extension.
  150. </p>
  151. </dd>
  152. <dt>&lsquo;<samp>poly_wide_int::from (<var>value</var>, <var>precision</var>, <var>sign</var>)</samp>&rsquo;</dt>
  153. <dd><p>Convert <var>value</var> to a <code>poly_wide_int</code> in which each coefficient
  154. has <var>precision</var> bits. Extend the coefficients according to
  155. <var>sign</var> if the coefficients have fewer bits.
  156. </p>
  157. </dd>
  158. <dt>&lsquo;<samp>poly_offset_int::from (<var>value</var>, <var>sign</var>)</samp>&rsquo;</dt>
  159. <dd><p>Convert <var>value</var> to a <code>poly_offset_int</code>, extending its coefficients
  160. according to <var>sign</var> if they have fewer bits than <code>offset_int</code>.
  161. </p>
  162. </dd>
  163. <dt>&lsquo;<samp>poly_widest_int::from (<var>value</var>, <var>sign</var>)</samp>&rsquo;</dt>
  164. <dd><p>Convert <var>value</var> to a <code>poly_widest_int</code>, extending its coefficients
  165. according to <var>sign</var> if they have fewer bits than <code>widest_int</code>.
  166. </p></dd>
  167. </dl>
  168. <hr>
  169. <div class="header">
  170. <p>
  171. Next: <a href="Miscellaneous-poly_005fint-routines.html#Miscellaneous-poly_005fint-routines" accesskey="n" rel="next">Miscellaneous <code>poly_int</code> routines</a>, Previous: <a href="Computing-bounds-on-poly_005fints.html#Computing-bounds-on-poly_005fints" accesskey="p" rel="prev">Computing bounds on <code>poly_int</code>s</a>, Up: <a href="poly_005fint.html#poly_005fint" accesskey="u" rel="up">poly_int</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>
  172. </div>
  173. </body>
  174. </html>