⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 other-builtins.html

📁 gcc手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<td align="left">long <b>__builtin_expect</b><i> </i>(<i>long </i><var>exp</var><i>, long </i><var>c</var><i></i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

You may use <code>__builtin_expect</code> to provide the compiler with

branch prediction information.  In general, you should prefer to

use actual profile feedback for this (<code>-fprofile-arcs</code>), as

programmers are notoriously bad at predicting how their programs

actually perform.  However, there are applications in which this

data is hard to collect.



     <p>The return value is the value of <var>exp</var>, which should be an

integral expression.  The value of <var>c</var> must be a compile-time

constant.  The semantics of the built-in are that it is expected

that <var>exp</var> == <var>c</var>.  For example:



     <pre class="smallexample">          if (__builtin_expect (x, 0))

            foo ();

          </pre>



     <p>would indicate that we do not expect to call <code>foo</code>, since

we expect <code>x</code> to be zero.  Since you are limited to integral

expressions for <var>exp</var>, you should use constructions such as



     <pre class="smallexample">          if (__builtin_expect (ptr != NULL, 1))

            error ();

          </pre>



     <p>when testing pointer or floating-point values. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">void <b>__builtin_prefetch</b><i> </i>(<i>const void *</i><var>addr</var><i>, ...</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

This function is used to minimize cache-miss latency by moving data into

a cache before it is accessed. 

You can insert calls to <code>__builtin_prefetch</code> into code for which

you know addresses of data in memory that is likely to be accessed soon. 

If the target supports them, data prefetch instructions will be generated. 

If the prefetch is done early enough before the access then the data will

be in the cache by the time it is accessed.



     <p>The value of <var>addr</var> is the address of the memory to prefetch. 

There are two optional arguments, <var>rw</var> and <var>locality</var>. 

The value of <var>rw</var> is a compile-time constant one or zero; one

means that the prefetch is preparing for a write to the memory address

and zero, the default, means that the prefetch is preparing for a read. 

The value <var>locality</var> must be a compile-time constant integer between

zero and three.  A value of zero means that the data has no temporal

locality, so it need not be left in the cache after the access.  A value

of three means that the data has a high degree of temporal locality and

should be left in all levels of cache possible.  Values of one and two

mean, respectively, a low or moderate degree of temporal locality.  The

default is three.



     <pre class="smallexample">          for (i = 0; i &lt; n; i++)

            {

              a[i] = a[i] + b[i];

              __builtin_prefetch (&amp;a[i+j], 1, 1);

              __builtin_prefetch (&amp;b[i+j], 0, 1);

              /* <small class="dots">...</small> */

            }

          </pre>



     <p>Data prefetch does not generate faults if <var>addr</var> is invalid, but

the address expression itself must be valid.  For example, a prefetch

of <code>p-&gt;next</code> will not fault if <code>p-&gt;next</code> is not a valid

address, but evaluation will fault if <code>p</code> is not a valid address.



     <p>If the target does not support data prefetch, the address expression

is evaluated if it includes side effects but no other code is generated

and GCC does not issue a warning. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">double <b>__builtin_huge_val</b><i> </i>(<i>void</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Returns a positive infinity, if supported by the floating-point format,

else <code>DBL_MAX</code>.  This function is suitable for implementing the

ISO C macro <code>HUGE_VAL</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">float <b>__builtin_huge_valf</b><i> </i>(<i>void</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_huge_val</code>, except the return type is <code>float</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">long double <b>__builtin_huge_vall</b><i> </i>(<i>void</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_huge_val</code>, except the return

type is <code>long double</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">double <b>__builtin_inf</b><i> </i>(<i>void</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_huge_val</code>, except a warning is generated

if the target floating-point format does not support infinities. 

This function is suitable for implementing the ISO C99 macro <code>INFINITY</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">float <b>__builtin_inff</b><i> </i>(<i>void</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_inf</code>, except the return type is <code>float</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">long double <b>__builtin_infl</b><i> </i>(<i>void</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_inf</code>, except the return

type is <code>long double</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">double <b>__builtin_nan</b><i> </i>(<i>const char *str</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

This is an implementation of the ISO C99 function <code>nan</code>.



     <p>Since ISO C99 defines this function in terms of <code>strtod</code>, which we

do not implement, a description of the parsing is in order.  The string

is parsed as by <code>strtol</code>; that is, the base is recognized by

leading <code>0</code> or <code>0x</code> prefixes.  The number parsed is placed

in the significand such that the least significant bit of the number

is at the least significant bit of the significand.  The number is

truncated to fit the significand field provided.  The significand is

forced to be a quiet NaN.



     <p>This function, if given a string literal, is evaluated early enough

that it is considered a compile-time constant. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">float <b>__builtin_nanf</b><i> </i>(<i>const char *str</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_nan</code>, except the return type is <code>float</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">long double <b>__builtin_nanl</b><i> </i>(<i>const char *str</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_nan</code>, except the return type is <code>long double</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">double <b>__builtin_nans</b><i> </i>(<i>const char *str</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_nan</code>, except the significand is forced

to be a signaling NaN.  The <code>nans</code> function is proposed by

<a href="http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n965.htm">WG14 N965</a>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">float <b>__builtin_nansf</b><i> </i>(<i>const char *str</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_nans</code>, except the return type is <code>float</code>. 

</td></tr>

</table>



<p>

<table width="100%">

<tr>

<td align="left">long double <b>__builtin_nansl</b><i> </i>(<i>const char *str</i>)<i>

     </i></td>

<td align="right">Built-in Function</td>

</tr>

</table>

<table width="95%" align="center">

<tr><td>

Similar to <code>__builtin_nans</code>, except the return type is <code>long double</code>. 

</td></tr>

</table>



   </body></html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -