toolchain/gcc-linaro-6.3.1-2017.02-x8.../share/doc/gcc/AVR-Built_002din-Functions....

182 lines
8.2 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2016 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below). A copy of the license is included in the section entitled
"GNU Free Documentation License".
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development. -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Using the GNU Compiler Collection (GCC): AVR Built-in Functions</title>
<meta name="description" content="Using the GNU Compiler Collection (GCC): AVR Built-in Functions">
<meta name="keywords" content="Using the GNU Compiler Collection (GCC): AVR Built-in Functions">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Target-Builtins.html#Target-Builtins" rel="up" title="Target Builtins">
<link href="Blackfin-Built_002din-Functions.html#Blackfin-Built_002din-Functions" rel="next" title="Blackfin Built-in Functions">
<link href="ARM-ARMv8_002dM-Security-Extensions.html#ARM-ARMv8_002dM-Security-Extensions" rel="prev" title="ARM ARMv8-M Security Extensions">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="AVR-Built_002din-Functions"></a>
<div class="header">
<p>
Next: <a href="Blackfin-Built_002din-Functions.html#Blackfin-Built_002din-Functions" accesskey="n" rel="next">Blackfin Built-in Functions</a>, Previous: <a href="ARM-ARMv8_002dM-Security-Extensions.html#ARM-ARMv8_002dM-Security-Extensions" accesskey="p" rel="prev">ARM ARMv8-M Security Extensions</a>, Up: <a href="Target-Builtins.html#Target-Builtins" accesskey="u" rel="up">Target Builtins</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>
</div>
<hr>
<a name="AVR-Built_002din-Functions-1"></a>
<h4 class="subsection">6.59.10 AVR Built-in Functions</h4>
<p>For each built-in function for AVR, there is an equally named,
uppercase built-in macro defined. That way users can easily query if
or if not a specific built-in is implemented or not. For example, if
<code>__builtin_avr_nop</code> is available the macro
<code>__BUILTIN_AVR_NOP</code> is defined to <code>1</code> and undefined otherwise.
</p>
<p>The following built-in functions map to the respective machine
instruction, i.e. <code>nop</code>, <code>sei</code>, <code>cli</code>, <code>sleep</code>,
<code>wdr</code>, <code>swap</code>, <code>fmul</code>, <code>fmuls</code>
resp. <code>fmulsu</code>. The three <code>fmul*</code> built-ins are implemented
as library call if no hardware multiplier is available.
</p>
<div class="smallexample">
<pre class="smallexample">void __builtin_avr_nop (void)
void __builtin_avr_sei (void)
void __builtin_avr_cli (void)
void __builtin_avr_sleep (void)
void __builtin_avr_wdr (void)
unsigned char __builtin_avr_swap (unsigned char)
unsigned int __builtin_avr_fmul (unsigned char, unsigned char)
int __builtin_avr_fmuls (char, char)
int __builtin_avr_fmulsu (char, unsigned char)
</pre></div>
<p>In order to delay execution for a specific number of cycles, GCC
implements
</p><div class="smallexample">
<pre class="smallexample">void __builtin_avr_delay_cycles (unsigned long ticks)
</pre></div>
<p><code>ticks</code> is the number of ticks to delay execution. Note that this
built-in does not take into account the effect of interrupts that
might increase delay time. <code>ticks</code> must be a compile-time
integer constant; delays with a variable number of cycles are not supported.
</p>
<div class="smallexample">
<pre class="smallexample">char __builtin_avr_flash_segment (const __memx void*)
</pre></div>
<p>This built-in takes a byte address to the 24-bit
<a href="Named-Address-Spaces.html#AVR-Named-Address-Spaces">address space</a> <code>__memx</code> and returns
the number of the flash segment (the 64 KiB chunk) where the address
points to. Counting starts at <code>0</code>.
If the address does not point to flash memory, return <code>-1</code>.
</p>
<div class="smallexample">
<pre class="smallexample">unsigned char __builtin_avr_insert_bits (unsigned long map, unsigned char bits, unsigned char val)
</pre></div>
<p>Insert bits from <var>bits</var> into <var>val</var> and return the resulting
value. The nibbles of <var>map</var> determine how the insertion is
performed: Let <var>X</var> be the <var>n</var>-th nibble of <var>map</var>
</p><ol>
<li> If <var>X</var> is <code>0xf</code>,
then the <var>n</var>-th bit of <var>val</var> is returned unaltered.
</li><li> If X is in the range 0&hellip;7,
then the <var>n</var>-th result bit is set to the <var>X</var>-th bit of <var>bits</var>
</li><li> If X is in the range 8&hellip;<code>0xe</code>,
then the <var>n</var>-th result bit is undefined.
</li></ol>
<p>One typical use case for this built-in is adjusting input and
output values to non-contiguous port layouts. Some examples:
</p>
<div class="smallexample">
<pre class="smallexample">// same as val, bits is unused
__builtin_avr_insert_bits (0xffffffff, bits, val)
</pre></div>
<div class="smallexample">
<pre class="smallexample">// same as bits, val is unused
__builtin_avr_insert_bits (0x76543210, bits, val)
</pre></div>
<div class="smallexample">
<pre class="smallexample">// same as rotating bits by 4
__builtin_avr_insert_bits (0x32107654, bits, 0)
</pre></div>
<div class="smallexample">
<pre class="smallexample">// high nibble of result is the high nibble of val
// low nibble of result is the low nibble of bits
__builtin_avr_insert_bits (0xffff3210, bits, val)
</pre></div>
<div class="smallexample">
<pre class="smallexample">// reverse the bit order of bits
__builtin_avr_insert_bits (0x01234567, bits, 0)
</pre></div>
<hr>
<div class="header">
<p>
Next: <a href="Blackfin-Built_002din-Functions.html#Blackfin-Built_002din-Functions" accesskey="n" rel="next">Blackfin Built-in Functions</a>, Previous: <a href="ARM-ARMv8_002dM-Security-Extensions.html#ARM-ARMv8_002dM-Security-Extensions" accesskey="p" rel="prev">ARM ARMv8-M Security Extensions</a>, Up: <a href="Target-Builtins.html#Target-Builtins" accesskey="u" rel="up">Target Builtins</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>
</div>
</body>
</html>