AVR-Built_002din-Functions.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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>Using the GNU Compiler Collection (GCC): AVR Built-in Functions</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): AVR Built-in Functions">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): AVR Built-in Functions">
  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="Target-Builtins.html#Target-Builtins" rel="up" title="Target Builtins">
  30. <link href="Blackfin-Built_002din-Functions.html#Blackfin-Built_002din-Functions" rel="next" title="Blackfin Built-in Functions">
  31. <link href="ARM-ARMv8_002dM-Security-Extensions.html#ARM-ARMv8_002dM-Security-Extensions" rel="prev" title="ARM ARMv8-M Security Extensions">
  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="AVR-Built_002din-Functions"></a>
  63. <div class="header">
  64. <p>
  65. 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>
  66. </div>
  67. <hr>
  68. <a name="AVR-Built_002din-Functions-1"></a>
  69. <h4 class="subsection">6.60.10 AVR Built-in Functions</h4>
  70. <p>For each built-in function for AVR, there is an equally named,
  71. uppercase built-in macro defined. That way users can easily query if
  72. or if not a specific built-in is implemented or not. For example, if
  73. <code>__builtin_avr_nop</code> is available the macro
  74. <code>__BUILTIN_AVR_NOP</code> is defined to <code>1</code> and undefined otherwise.
  75. </p>
  76. <p>The following built-in functions map to the respective machine
  77. instruction, i.e. <code>nop</code>, <code>sei</code>, <code>cli</code>, <code>sleep</code>,
  78. <code>wdr</code>, <code>swap</code>, <code>fmul</code>, <code>fmuls</code>
  79. resp. <code>fmulsu</code>. The three <code>fmul*</code> built-ins are implemented
  80. as library call if no hardware multiplier is available.
  81. </p>
  82. <div class="smallexample">
  83. <pre class="smallexample">void __builtin_avr_nop (void)
  84. void __builtin_avr_sei (void)
  85. void __builtin_avr_cli (void)
  86. void __builtin_avr_sleep (void)
  87. void __builtin_avr_wdr (void)
  88. unsigned char __builtin_avr_swap (unsigned char)
  89. unsigned int __builtin_avr_fmul (unsigned char, unsigned char)
  90. int __builtin_avr_fmuls (char, char)
  91. int __builtin_avr_fmulsu (char, unsigned char)
  92. </pre></div>
  93. <p>In order to delay execution for a specific number of cycles, GCC
  94. implements
  95. </p><div class="smallexample">
  96. <pre class="smallexample">void __builtin_avr_delay_cycles (unsigned long ticks)
  97. </pre></div>
  98. <p><code>ticks</code> is the number of ticks to delay execution. Note that this
  99. built-in does not take into account the effect of interrupts that
  100. might increase delay time. <code>ticks</code> must be a compile-time
  101. integer constant; delays with a variable number of cycles are not supported.
  102. </p>
  103. <div class="smallexample">
  104. <pre class="smallexample">char __builtin_avr_flash_segment (const __memx void*)
  105. </pre></div>
  106. <p>This built-in takes a byte address to the 24-bit
  107. <a href="Named-Address-Spaces.html#AVR-Named-Address-Spaces">address space</a> <code>__memx</code> and returns
  108. the number of the flash segment (the 64 KiB chunk) where the address
  109. points to. Counting starts at <code>0</code>.
  110. If the address does not point to flash memory, return <code>-1</code>.
  111. </p>
  112. <div class="smallexample">
  113. <pre class="smallexample">unsigned char __builtin_avr_insert_bits (unsigned long map,
  114. unsigned char bits,
  115. unsigned char val)
  116. </pre></div>
  117. <p>Insert bits from <var>bits</var> into <var>val</var> and return the resulting
  118. value. The nibbles of <var>map</var> determine how the insertion is
  119. performed: Let <var>X</var> be the <var>n</var>-th nibble of <var>map</var>
  120. </p><ol>
  121. <li> If <var>X</var> is <code>0xf</code>,
  122. then the <var>n</var>-th bit of <var>val</var> is returned unaltered.
  123. </li><li> If X is in the range 0&hellip;7,
  124. then the <var>n</var>-th result bit is set to the <var>X</var>-th bit of <var>bits</var>
  125. </li><li> If X is in the range 8&hellip;<code>0xe</code>,
  126. then the <var>n</var>-th result bit is undefined.
  127. </li></ol>
  128. <p>One typical use case for this built-in is adjusting input and
  129. output values to non-contiguous port layouts. Some examples:
  130. </p>
  131. <div class="smallexample">
  132. <pre class="smallexample">// same as val, bits is unused
  133. __builtin_avr_insert_bits (0xffffffff, bits, val)
  134. </pre></div>
  135. <div class="smallexample">
  136. <pre class="smallexample">// same as bits, val is unused
  137. __builtin_avr_insert_bits (0x76543210, bits, val)
  138. </pre></div>
  139. <div class="smallexample">
  140. <pre class="smallexample">// same as rotating bits by 4
  141. __builtin_avr_insert_bits (0x32107654, bits, 0)
  142. </pre></div>
  143. <div class="smallexample">
  144. <pre class="smallexample">// high nibble of result is the high nibble of val
  145. // low nibble of result is the low nibble of bits
  146. __builtin_avr_insert_bits (0xffff3210, bits, val)
  147. </pre></div>
  148. <div class="smallexample">
  149. <pre class="smallexample">// reverse the bit order of bits
  150. __builtin_avr_insert_bits (0x01234567, bits, 0)
  151. </pre></div>
  152. <div class="smallexample">
  153. <pre class="smallexample">void __builtin_avr_nops (unsigned count)
  154. </pre></div>
  155. <p>Insert <code>count</code> <code>NOP</code> instructions.
  156. The number of instructions must be a compile-time integer constant.
  157. </p>
  158. <hr>
  159. <div class="header">
  160. <p>
  161. 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>
  162. </div>
  163. </body>
  164. </html>