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.

382 lines
15KB

  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>Basic PowerPC Built-in Functions Available on all Configurations (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Basic PowerPC Built-in Functions Available on all Configurations (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Basic PowerPC Built-in Functions Available on all Configurations (Using the GNU Compiler Collection (GCC))">
  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="Basic-PowerPC-Built_002din-Functions.html#Basic-PowerPC-Built_002din-Functions" rel="up" title="Basic PowerPC Built-in Functions">
  30. <link href="Basic-PowerPC-Built_002din-Functions-Available-on-ISA-2_002e05.html#Basic-PowerPC-Built_002din-Functions-Available-on-ISA-2_002e05" rel="next" title="Basic PowerPC Built-in Functions Available on ISA 2.05">
  31. <link href="Basic-PowerPC-Built_002din-Functions.html#Basic-PowerPC-Built_002din-Functions" rel="prev" title="Basic PowerPC Built-in Functions">
  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="Basic-PowerPC-Built_002din-Functions-Available-on-all-Configurations"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Basic-PowerPC-Built_002din-Functions-Available-on-ISA-2_002e05.html#Basic-PowerPC-Built_002din-Functions-Available-on-ISA-2_002e05" accesskey="n" rel="next">Basic PowerPC Built-in Functions Available on ISA 2.05</a>, Up: <a href="Basic-PowerPC-Built_002din-Functions.html#Basic-PowerPC-Built_002din-Functions" accesskey="u" rel="up">Basic PowerPC Built-in Functions</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="Basic-PowerPC-Built_002din-Functions-Available-on-all-Configurations-1"></a>
  68. <h4 class="subsubsection">6.60.22.1 Basic PowerPC Built-in Functions Available on all Configurations</h4>
  69. <dl>
  70. <dt><a name="index-_005f_005fbuiltin_005fcpu_005finit"></a>Built-in Function: <em>void</em> <strong>__builtin_cpu_init</strong> <em>(void)</em></dt>
  71. <dd><p>This function is a <code>nop</code> on the PowerPC platform and is included solely
  72. to maintain API compatibility with the x86 builtins.
  73. </p></dd></dl>
  74. <dl>
  75. <dt><a name="index-_005f_005fbuiltin_005fcpu_005fis"></a>Built-in Function: <em>int</em> <strong>__builtin_cpu_is</strong> <em>(const char *<var>cpuname</var>)</em></dt>
  76. <dd><p>This function returns a value of <code>1</code> if the run-time CPU is of type
  77. <var>cpuname</var> and returns <code>0</code> otherwise
  78. </p>
  79. <p>The <code>__builtin_cpu_is</code> function requires GLIBC 2.23 or newer
  80. which exports the hardware capability bits. GCC defines the macro
  81. <code>__BUILTIN_CPU_SUPPORTS__</code> if the <code>__builtin_cpu_supports</code>
  82. built-in function is fully supported.
  83. </p>
  84. <p>If GCC was configured to use a GLIBC before 2.23, the built-in
  85. function <code>__builtin_cpu_is</code> always returns a 0 and the compiler
  86. issues a warning.
  87. </p>
  88. <p>The following CPU names can be detected:
  89. </p>
  90. <dl compact="compact">
  91. <dt>&lsquo;<samp>power10</samp>&rsquo;</dt>
  92. <dd><p>IBM POWER10 Server CPU.
  93. </p></dd>
  94. <dt>&lsquo;<samp>power9</samp>&rsquo;</dt>
  95. <dd><p>IBM POWER9 Server CPU.
  96. </p></dd>
  97. <dt>&lsquo;<samp>power8</samp>&rsquo;</dt>
  98. <dd><p>IBM POWER8 Server CPU.
  99. </p></dd>
  100. <dt>&lsquo;<samp>power7</samp>&rsquo;</dt>
  101. <dd><p>IBM POWER7 Server CPU.
  102. </p></dd>
  103. <dt>&lsquo;<samp>power6x</samp>&rsquo;</dt>
  104. <dd><p>IBM POWER6 Server CPU (RAW mode).
  105. </p></dd>
  106. <dt>&lsquo;<samp>power6</samp>&rsquo;</dt>
  107. <dd><p>IBM POWER6 Server CPU (Architected mode).
  108. </p></dd>
  109. <dt>&lsquo;<samp>power5+</samp>&rsquo;</dt>
  110. <dd><p>IBM POWER5+ Server CPU.
  111. </p></dd>
  112. <dt>&lsquo;<samp>power5</samp>&rsquo;</dt>
  113. <dd><p>IBM POWER5 Server CPU.
  114. </p></dd>
  115. <dt>&lsquo;<samp>ppc970</samp>&rsquo;</dt>
  116. <dd><p>IBM 970 Server CPU (ie, Apple G5).
  117. </p></dd>
  118. <dt>&lsquo;<samp>power4</samp>&rsquo;</dt>
  119. <dd><p>IBM POWER4 Server CPU.
  120. </p></dd>
  121. <dt>&lsquo;<samp>ppca2</samp>&rsquo;</dt>
  122. <dd><p>IBM A2 64-bit Embedded CPU
  123. </p></dd>
  124. <dt>&lsquo;<samp>ppc476</samp>&rsquo;</dt>
  125. <dd><p>IBM PowerPC 476FP 32-bit Embedded CPU.
  126. </p></dd>
  127. <dt>&lsquo;<samp>ppc464</samp>&rsquo;</dt>
  128. <dd><p>IBM PowerPC 464 32-bit Embedded CPU.
  129. </p></dd>
  130. <dt>&lsquo;<samp>ppc440</samp>&rsquo;</dt>
  131. <dd><p>PowerPC 440 32-bit Embedded CPU.
  132. </p></dd>
  133. <dt>&lsquo;<samp>ppc405</samp>&rsquo;</dt>
  134. <dd><p>PowerPC 405 32-bit Embedded CPU.
  135. </p></dd>
  136. <dt>&lsquo;<samp>ppc-cell-be</samp>&rsquo;</dt>
  137. <dd><p>IBM PowerPC Cell Broadband Engine Architecture CPU.
  138. </p></dd>
  139. </dl>
  140. <p>Here is an example:
  141. </p><div class="smallexample">
  142. <pre class="smallexample">#ifdef __BUILTIN_CPU_SUPPORTS__
  143. if (__builtin_cpu_is (&quot;power8&quot;))
  144. {
  145. do_power8 (); // POWER8 specific implementation.
  146. }
  147. else
  148. #endif
  149. {
  150. do_generic (); // Generic implementation.
  151. }
  152. </pre></div>
  153. </dd></dl>
  154. <dl>
  155. <dt><a name="index-_005f_005fbuiltin_005fcpu_005fsupports"></a>Built-in Function: <em>int</em> <strong>__builtin_cpu_supports</strong> <em>(const char *<var>feature</var>)</em></dt>
  156. <dd><p>This function returns a value of <code>1</code> if the run-time CPU supports the HWCAP
  157. feature <var>feature</var> and returns <code>0</code> otherwise.
  158. </p>
  159. <p>The <code>__builtin_cpu_supports</code> function requires GLIBC 2.23 or
  160. newer which exports the hardware capability bits. GCC defines the
  161. macro <code>__BUILTIN_CPU_SUPPORTS__</code> if the
  162. <code>__builtin_cpu_supports</code> built-in function is fully supported.
  163. </p>
  164. <p>If GCC was configured to use a GLIBC before 2.23, the built-in
  165. function <code>__builtin_cpu_suports</code> always returns a 0 and the
  166. compiler issues a warning.
  167. </p>
  168. <p>The following features can be
  169. detected:
  170. </p>
  171. <dl compact="compact">
  172. <dt>&lsquo;<samp>4xxmac</samp>&rsquo;</dt>
  173. <dd><p>4xx CPU has a Multiply Accumulator.
  174. </p></dd>
  175. <dt>&lsquo;<samp>altivec</samp>&rsquo;</dt>
  176. <dd><p>CPU has a SIMD/Vector Unit.
  177. </p></dd>
  178. <dt>&lsquo;<samp>arch_2_05</samp>&rsquo;</dt>
  179. <dd><p>CPU supports ISA 2.05 (eg, POWER6)
  180. </p></dd>
  181. <dt>&lsquo;<samp>arch_2_06</samp>&rsquo;</dt>
  182. <dd><p>CPU supports ISA 2.06 (eg, POWER7)
  183. </p></dd>
  184. <dt>&lsquo;<samp>arch_2_07</samp>&rsquo;</dt>
  185. <dd><p>CPU supports ISA 2.07 (eg, POWER8)
  186. </p></dd>
  187. <dt>&lsquo;<samp>arch_3_00</samp>&rsquo;</dt>
  188. <dd><p>CPU supports ISA 3.0 (eg, POWER9)
  189. </p></dd>
  190. <dt>&lsquo;<samp>arch_3_1</samp>&rsquo;</dt>
  191. <dd><p>CPU supports ISA 3.1 (eg, POWER10)
  192. </p></dd>
  193. <dt>&lsquo;<samp>archpmu</samp>&rsquo;</dt>
  194. <dd><p>CPU supports the set of compatible performance monitoring events.
  195. </p></dd>
  196. <dt>&lsquo;<samp>booke</samp>&rsquo;</dt>
  197. <dd><p>CPU supports the Embedded ISA category.
  198. </p></dd>
  199. <dt>&lsquo;<samp>cellbe</samp>&rsquo;</dt>
  200. <dd><p>CPU has a CELL broadband engine.
  201. </p></dd>
  202. <dt>&lsquo;<samp>darn</samp>&rsquo;</dt>
  203. <dd><p>CPU supports the <code>darn</code> (deliver a random number) instruction.
  204. </p></dd>
  205. <dt>&lsquo;<samp>dfp</samp>&rsquo;</dt>
  206. <dd><p>CPU has a decimal floating point unit.
  207. </p></dd>
  208. <dt>&lsquo;<samp>dscr</samp>&rsquo;</dt>
  209. <dd><p>CPU supports the data stream control register.
  210. </p></dd>
  211. <dt>&lsquo;<samp>ebb</samp>&rsquo;</dt>
  212. <dd><p>CPU supports event base branching.
  213. </p></dd>
  214. <dt>&lsquo;<samp>efpdouble</samp>&rsquo;</dt>
  215. <dd><p>CPU has a SPE double precision floating point unit.
  216. </p></dd>
  217. <dt>&lsquo;<samp>efpsingle</samp>&rsquo;</dt>
  218. <dd><p>CPU has a SPE single precision floating point unit.
  219. </p></dd>
  220. <dt>&lsquo;<samp>fpu</samp>&rsquo;</dt>
  221. <dd><p>CPU has a floating point unit.
  222. </p></dd>
  223. <dt>&lsquo;<samp>htm</samp>&rsquo;</dt>
  224. <dd><p>CPU has hardware transaction memory instructions.
  225. </p></dd>
  226. <dt>&lsquo;<samp>htm-nosc</samp>&rsquo;</dt>
  227. <dd><p>Kernel aborts hardware transactions when a syscall is made.
  228. </p></dd>
  229. <dt>&lsquo;<samp>htm-no-suspend</samp>&rsquo;</dt>
  230. <dd><p>CPU supports hardware transaction memory but does not support the
  231. <code>tsuspend.</code> instruction.
  232. </p></dd>
  233. <dt>&lsquo;<samp>ic_snoop</samp>&rsquo;</dt>
  234. <dd><p>CPU supports icache snooping capabilities.
  235. </p></dd>
  236. <dt>&lsquo;<samp>ieee128</samp>&rsquo;</dt>
  237. <dd><p>CPU supports 128-bit IEEE binary floating point instructions.
  238. </p></dd>
  239. <dt>&lsquo;<samp>isel</samp>&rsquo;</dt>
  240. <dd><p>CPU supports the integer select instruction.
  241. </p></dd>
  242. <dt>&lsquo;<samp>mma</samp>&rsquo;</dt>
  243. <dd><p>CPU supports the matrix-multiply assist instructions.
  244. </p></dd>
  245. <dt>&lsquo;<samp>mmu</samp>&rsquo;</dt>
  246. <dd><p>CPU has a memory management unit.
  247. </p></dd>
  248. <dt>&lsquo;<samp>notb</samp>&rsquo;</dt>
  249. <dd><p>CPU does not have a timebase (eg, 601 and 403gx).
  250. </p></dd>
  251. <dt>&lsquo;<samp>pa6t</samp>&rsquo;</dt>
  252. <dd><p>CPU supports the PA Semi 6T CORE ISA.
  253. </p></dd>
  254. <dt>&lsquo;<samp>power4</samp>&rsquo;</dt>
  255. <dd><p>CPU supports ISA 2.00 (eg, POWER4)
  256. </p></dd>
  257. <dt>&lsquo;<samp>power5</samp>&rsquo;</dt>
  258. <dd><p>CPU supports ISA 2.02 (eg, POWER5)
  259. </p></dd>
  260. <dt>&lsquo;<samp>power5+</samp>&rsquo;</dt>
  261. <dd><p>CPU supports ISA 2.03 (eg, POWER5+)
  262. </p></dd>
  263. <dt>&lsquo;<samp>power6x</samp>&rsquo;</dt>
  264. <dd><p>CPU supports ISA 2.05 (eg, POWER6) extended opcodes mffgpr and mftgpr.
  265. </p></dd>
  266. <dt>&lsquo;<samp>ppc32</samp>&rsquo;</dt>
  267. <dd><p>CPU supports 32-bit mode execution.
  268. </p></dd>
  269. <dt>&lsquo;<samp>ppc601</samp>&rsquo;</dt>
  270. <dd><p>CPU supports the old POWER ISA (eg, 601)
  271. </p></dd>
  272. <dt>&lsquo;<samp>ppc64</samp>&rsquo;</dt>
  273. <dd><p>CPU supports 64-bit mode execution.
  274. </p></dd>
  275. <dt>&lsquo;<samp>ppcle</samp>&rsquo;</dt>
  276. <dd><p>CPU supports a little-endian mode that uses address swizzling.
  277. </p></dd>
  278. <dt>&lsquo;<samp>scv</samp>&rsquo;</dt>
  279. <dd><p>Kernel supports system call vectored.
  280. </p></dd>
  281. <dt>&lsquo;<samp>smt</samp>&rsquo;</dt>
  282. <dd><p>CPU support simultaneous multi-threading.
  283. </p></dd>
  284. <dt>&lsquo;<samp>spe</samp>&rsquo;</dt>
  285. <dd><p>CPU has a signal processing extension unit.
  286. </p></dd>
  287. <dt>&lsquo;<samp>tar</samp>&rsquo;</dt>
  288. <dd><p>CPU supports the target address register.
  289. </p></dd>
  290. <dt>&lsquo;<samp>true_le</samp>&rsquo;</dt>
  291. <dd><p>CPU supports true little-endian mode.
  292. </p></dd>
  293. <dt>&lsquo;<samp>ucache</samp>&rsquo;</dt>
  294. <dd><p>CPU has unified I/D cache.
  295. </p></dd>
  296. <dt>&lsquo;<samp>vcrypto</samp>&rsquo;</dt>
  297. <dd><p>CPU supports the vector cryptography instructions.
  298. </p></dd>
  299. <dt>&lsquo;<samp>vsx</samp>&rsquo;</dt>
  300. <dd><p>CPU supports the vector-scalar extension.
  301. </p></dd>
  302. </dl>
  303. <p>Here is an example:
  304. </p><div class="smallexample">
  305. <pre class="smallexample">#ifdef __BUILTIN_CPU_SUPPORTS__
  306. if (__builtin_cpu_supports (&quot;fpu&quot;))
  307. {
  308. asm(&quot;fadd %0,%1,%2&quot; : &quot;=d&quot;(dst) : &quot;d&quot;(src1), &quot;d&quot;(src2));
  309. }
  310. else
  311. #endif
  312. {
  313. dst = __fadd (src1, src2); // Software FP addition function.
  314. }
  315. </pre></div>
  316. </dd></dl>
  317. <p>The following built-in functions are also available on all PowerPC
  318. processors:
  319. </p><div class="smallexample">
  320. <pre class="smallexample">uint64_t __builtin_ppc_get_timebase ();
  321. unsigned long __builtin_ppc_mftb ();
  322. double __builtin_unpack_ibm128 (__ibm128, int);
  323. __ibm128 __builtin_pack_ibm128 (double, double);
  324. double __builtin_mffs (void);
  325. void __builtin_mtfsf (const int, double);
  326. void __builtin_mtfsb0 (const int);
  327. void __builtin_mtfsb1 (const int);
  328. void __builtin_set_fpscr_rn (int);
  329. </pre></div>
  330. <p>The <code>__builtin_ppc_get_timebase</code> and <code>__builtin_ppc_mftb</code>
  331. functions generate instructions to read the Time Base Register. The
  332. <code>__builtin_ppc_get_timebase</code> function may generate multiple
  333. instructions and always returns the 64 bits of the Time Base Register.
  334. The <code>__builtin_ppc_mftb</code> function always generates one instruction and
  335. returns the Time Base Register value as an unsigned long, throwing away
  336. the most significant word on 32-bit environments. The <code>__builtin_mffs</code>
  337. return the value of the FPSCR register. Note, ISA 3.0 supports the
  338. <code>__builtin_mffsl()</code> which permits software to read the control and
  339. non-sticky status bits in the FSPCR without the higher latency associated with
  340. accessing the sticky status bits. The <code>__builtin_mtfsf</code> takes a constant
  341. 8-bit integer field mask and a double precision floating point argument
  342. and generates the <code>mtfsf</code> (extended mnemonic) instruction to write new
  343. values to selected fields of the FPSCR. The
  344. <code>__builtin_mtfsb0</code> and <code>__builtin_mtfsb1</code> take the bit to change
  345. as an argument. The valid bit range is between 0 and 31. The builtins map to
  346. the <code>mtfsb0</code> and <code>mtfsb1</code> instructions which take the argument and
  347. add 32. Hence these instructions only modify the FPSCR[32:63] bits by
  348. changing the specified bit to a zero or one respectively. The
  349. <code>__builtin_set_fpscr_rn</code> builtin allows changing both of the floating
  350. point rounding mode bits. The argument is a 2-bit value. The argument can
  351. either be a <code>const int</code> or stored in a variable. The builtin uses
  352. the ISA 3.0
  353. instruction <code>mffscrn</code> if available, otherwise it reads the FPSCR, masks
  354. the current rounding mode bits out and OR&rsquo;s in the new value.
  355. </p>
  356. <hr>
  357. <div class="header">
  358. <p>
  359. Next: <a href="Basic-PowerPC-Built_002din-Functions-Available-on-ISA-2_002e05.html#Basic-PowerPC-Built_002din-Functions-Available-on-ISA-2_002e05" accesskey="n" rel="next">Basic PowerPC Built-in Functions Available on ISA 2.05</a>, Up: <a href="Basic-PowerPC-Built_002din-Functions.html#Basic-PowerPC-Built_002din-Functions" accesskey="u" rel="up">Basic PowerPC Built-in Functions</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>
  360. </div>
  361. </body>
  362. </html>