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.

378 lines
17KB

  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>MIPS DSP Built-in Functions (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="MIPS DSP Built-in Functions (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="MIPS DSP Built-in Functions (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="Target-Builtins.html#Target-Builtins" rel="up" title="Target Builtins">
  30. <link href="MIPS-Paired_002dSingle-Support.html#MIPS-Paired_002dSingle-Support" rel="next" title="MIPS Paired-Single Support">
  31. <link href="Other-Built_002din-Functions.html#Other-Built_002din-Functions" rel="prev" title="Other 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="MIPS-DSP-Built_002din-Functions"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="MIPS-Paired_002dSingle-Support.html#MIPS-Paired_002dSingle-Support" accesskey="n" rel="next">MIPS Paired-Single Support</a>, Previous: <a href="FR_002dV-Built_002din-Functions.html#FR_002dV-Built_002din-Functions" accesskey="p" rel="prev">FR-V Built-in Functions</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>
  65. </div>
  66. <hr>
  67. <a name="MIPS-DSP-Built_002din-Functions-1"></a>
  68. <h4 class="subsection">6.60.14 MIPS DSP Built-in Functions</h4>
  69. <p>The MIPS DSP Application-Specific Extension (ASE) includes new
  70. instructions that are designed to improve the performance of DSP and
  71. media applications. It provides instructions that operate on packed
  72. 8-bit/16-bit integer data, Q7, Q15 and Q31 fractional data.
  73. </p>
  74. <p>GCC supports MIPS DSP operations using both the generic
  75. vector extensions (see <a href="Vector-Extensions.html#Vector-Extensions">Vector Extensions</a>) and a collection of
  76. MIPS-specific built-in functions. Both kinds of support are
  77. enabled by the <samp>-mdsp</samp> command-line option.
  78. </p>
  79. <p>Revision 2 of the ASE was introduced in the second half of 2006.
  80. This revision adds extra instructions to the original ASE, but is
  81. otherwise backwards-compatible with it. You can select revision 2
  82. using the command-line option <samp>-mdspr2</samp>; this option implies
  83. <samp>-mdsp</samp>.
  84. </p>
  85. <p>The SCOUNT and POS bits of the DSP control register are global. The
  86. WRDSP, EXTPDP, EXTPDPV and MTHLIP instructions modify the SCOUNT and
  87. POS bits. During optimization, the compiler does not delete these
  88. instructions and it does not delete calls to functions containing
  89. these instructions.
  90. </p>
  91. <p>At present, GCC only provides support for operations on 32-bit
  92. vectors. The vector type associated with 8-bit integer data is
  93. usually called <code>v4i8</code>, the vector type associated with Q7
  94. is usually called <code>v4q7</code>, the vector type associated with 16-bit
  95. integer data is usually called <code>v2i16</code>, and the vector type
  96. associated with Q15 is usually called <code>v2q15</code>. They can be
  97. defined in C as follows:
  98. </p>
  99. <div class="smallexample">
  100. <pre class="smallexample">typedef signed char v4i8 __attribute__ ((vector_size(4)));
  101. typedef signed char v4q7 __attribute__ ((vector_size(4)));
  102. typedef short v2i16 __attribute__ ((vector_size(4)));
  103. typedef short v2q15 __attribute__ ((vector_size(4)));
  104. </pre></div>
  105. <p><code>v4i8</code>, <code>v4q7</code>, <code>v2i16</code> and <code>v2q15</code> values are
  106. initialized in the same way as aggregates. For example:
  107. </p>
  108. <div class="smallexample">
  109. <pre class="smallexample">v4i8 a = {1, 2, 3, 4};
  110. v4i8 b;
  111. b = (v4i8) {5, 6, 7, 8};
  112. v2q15 c = {0x0fcb, 0x3a75};
  113. v2q15 d;
  114. d = (v2q15) {0.1234 * 0x1.0p15, 0.4567 * 0x1.0p15};
  115. </pre></div>
  116. <p><em>Note:</em> The CPU&rsquo;s endianness determines the order in which values
  117. are packed. On little-endian targets, the first value is the least
  118. significant and the last value is the most significant. The opposite
  119. order applies to big-endian targets. For example, the code above
  120. sets the lowest byte of <code>a</code> to <code>1</code> on little-endian targets
  121. and <code>4</code> on big-endian targets.
  122. </p>
  123. <p><em>Note:</em> Q7, Q15 and Q31 values must be initialized with their integer
  124. representation. As shown in this example, the integer representation
  125. of a Q7 value can be obtained by multiplying the fractional value by
  126. <code>0x1.0p7</code>. The equivalent for Q15 values is to multiply by
  127. <code>0x1.0p15</code>. The equivalent for Q31 values is to multiply by
  128. <code>0x1.0p31</code>.
  129. </p>
  130. <p>The table below lists the <code>v4i8</code> and <code>v2q15</code> operations for which
  131. hardware support exists. <code>a</code> and <code>b</code> are <code>v4i8</code> values,
  132. and <code>c</code> and <code>d</code> are <code>v2q15</code> values.
  133. </p>
  134. <table>
  135. <tr><td width="50%">C code</td><td width="50%">MIPS instruction</td></tr>
  136. <tr><td width="50%"><code>a + b</code></td><td width="50%"><code>addu.qb</code></td></tr>
  137. <tr><td width="50%"><code>c + d</code></td><td width="50%"><code>addq.ph</code></td></tr>
  138. <tr><td width="50%"><code>a - b</code></td><td width="50%"><code>subu.qb</code></td></tr>
  139. <tr><td width="50%"><code>c - d</code></td><td width="50%"><code>subq.ph</code></td></tr>
  140. </table>
  141. <p>The table below lists the <code>v2i16</code> operation for which
  142. hardware support exists for the DSP ASE REV 2. <code>e</code> and <code>f</code> are
  143. <code>v2i16</code> values.
  144. </p>
  145. <table>
  146. <tr><td width="50%">C code</td><td width="50%">MIPS instruction</td></tr>
  147. <tr><td width="50%"><code>e * f</code></td><td width="50%"><code>mul.ph</code></td></tr>
  148. </table>
  149. <p>It is easier to describe the DSP built-in functions if we first define
  150. the following types:
  151. </p>
  152. <div class="smallexample">
  153. <pre class="smallexample">typedef int q31;
  154. typedef int i32;
  155. typedef unsigned int ui32;
  156. typedef long long a64;
  157. </pre></div>
  158. <p><code>q31</code> and <code>i32</code> are actually the same as <code>int</code>, but we
  159. use <code>q31</code> to indicate a Q31 fractional value and <code>i32</code> to
  160. indicate a 32-bit integer value. Similarly, <code>a64</code> is the same as
  161. <code>long long</code>, but we use <code>a64</code> to indicate values that are
  162. placed in one of the four DSP accumulators (<code>$ac0</code>,
  163. <code>$ac1</code>, <code>$ac2</code> or <code>$ac3</code>).
  164. </p>
  165. <p>Also, some built-in functions prefer or require immediate numbers as
  166. parameters, because the corresponding DSP instructions accept both immediate
  167. numbers and register operands, or accept immediate numbers only. The
  168. immediate parameters are listed as follows.
  169. </p>
  170. <div class="smallexample">
  171. <pre class="smallexample">imm0_3: 0 to 3.
  172. imm0_7: 0 to 7.
  173. imm0_15: 0 to 15.
  174. imm0_31: 0 to 31.
  175. imm0_63: 0 to 63.
  176. imm0_255: 0 to 255.
  177. imm_n32_31: -32 to 31.
  178. imm_n512_511: -512 to 511.
  179. </pre></div>
  180. <p>The following built-in functions map directly to a particular MIPS DSP
  181. instruction. Please refer to the architecture specification
  182. for details on what each instruction does.
  183. </p>
  184. <div class="smallexample">
  185. <pre class="smallexample">v2q15 __builtin_mips_addq_ph (v2q15, v2q15)
  186. v2q15 __builtin_mips_addq_s_ph (v2q15, v2q15)
  187. q31 __builtin_mips_addq_s_w (q31, q31)
  188. v4i8 __builtin_mips_addu_qb (v4i8, v4i8)
  189. v4i8 __builtin_mips_addu_s_qb (v4i8, v4i8)
  190. v2q15 __builtin_mips_subq_ph (v2q15, v2q15)
  191. v2q15 __builtin_mips_subq_s_ph (v2q15, v2q15)
  192. q31 __builtin_mips_subq_s_w (q31, q31)
  193. v4i8 __builtin_mips_subu_qb (v4i8, v4i8)
  194. v4i8 __builtin_mips_subu_s_qb (v4i8, v4i8)
  195. i32 __builtin_mips_addsc (i32, i32)
  196. i32 __builtin_mips_addwc (i32, i32)
  197. i32 __builtin_mips_modsub (i32, i32)
  198. i32 __builtin_mips_raddu_w_qb (v4i8)
  199. v2q15 __builtin_mips_absq_s_ph (v2q15)
  200. q31 __builtin_mips_absq_s_w (q31)
  201. v4i8 __builtin_mips_precrq_qb_ph (v2q15, v2q15)
  202. v2q15 __builtin_mips_precrq_ph_w (q31, q31)
  203. v2q15 __builtin_mips_precrq_rs_ph_w (q31, q31)
  204. v4i8 __builtin_mips_precrqu_s_qb_ph (v2q15, v2q15)
  205. q31 __builtin_mips_preceq_w_phl (v2q15)
  206. q31 __builtin_mips_preceq_w_phr (v2q15)
  207. v2q15 __builtin_mips_precequ_ph_qbl (v4i8)
  208. v2q15 __builtin_mips_precequ_ph_qbr (v4i8)
  209. v2q15 __builtin_mips_precequ_ph_qbla (v4i8)
  210. v2q15 __builtin_mips_precequ_ph_qbra (v4i8)
  211. v2q15 __builtin_mips_preceu_ph_qbl (v4i8)
  212. v2q15 __builtin_mips_preceu_ph_qbr (v4i8)
  213. v2q15 __builtin_mips_preceu_ph_qbla (v4i8)
  214. v2q15 __builtin_mips_preceu_ph_qbra (v4i8)
  215. v4i8 __builtin_mips_shll_qb (v4i8, imm0_7)
  216. v4i8 __builtin_mips_shll_qb (v4i8, i32)
  217. v2q15 __builtin_mips_shll_ph (v2q15, imm0_15)
  218. v2q15 __builtin_mips_shll_ph (v2q15, i32)
  219. v2q15 __builtin_mips_shll_s_ph (v2q15, imm0_15)
  220. v2q15 __builtin_mips_shll_s_ph (v2q15, i32)
  221. q31 __builtin_mips_shll_s_w (q31, imm0_31)
  222. q31 __builtin_mips_shll_s_w (q31, i32)
  223. v4i8 __builtin_mips_shrl_qb (v4i8, imm0_7)
  224. v4i8 __builtin_mips_shrl_qb (v4i8, i32)
  225. v2q15 __builtin_mips_shra_ph (v2q15, imm0_15)
  226. v2q15 __builtin_mips_shra_ph (v2q15, i32)
  227. v2q15 __builtin_mips_shra_r_ph (v2q15, imm0_15)
  228. v2q15 __builtin_mips_shra_r_ph (v2q15, i32)
  229. q31 __builtin_mips_shra_r_w (q31, imm0_31)
  230. q31 __builtin_mips_shra_r_w (q31, i32)
  231. v2q15 __builtin_mips_muleu_s_ph_qbl (v4i8, v2q15)
  232. v2q15 __builtin_mips_muleu_s_ph_qbr (v4i8, v2q15)
  233. v2q15 __builtin_mips_mulq_rs_ph (v2q15, v2q15)
  234. q31 __builtin_mips_muleq_s_w_phl (v2q15, v2q15)
  235. q31 __builtin_mips_muleq_s_w_phr (v2q15, v2q15)
  236. a64 __builtin_mips_dpau_h_qbl (a64, v4i8, v4i8)
  237. a64 __builtin_mips_dpau_h_qbr (a64, v4i8, v4i8)
  238. a64 __builtin_mips_dpsu_h_qbl (a64, v4i8, v4i8)
  239. a64 __builtin_mips_dpsu_h_qbr (a64, v4i8, v4i8)
  240. a64 __builtin_mips_dpaq_s_w_ph (a64, v2q15, v2q15)
  241. a64 __builtin_mips_dpaq_sa_l_w (a64, q31, q31)
  242. a64 __builtin_mips_dpsq_s_w_ph (a64, v2q15, v2q15)
  243. a64 __builtin_mips_dpsq_sa_l_w (a64, q31, q31)
  244. a64 __builtin_mips_mulsaq_s_w_ph (a64, v2q15, v2q15)
  245. a64 __builtin_mips_maq_s_w_phl (a64, v2q15, v2q15)
  246. a64 __builtin_mips_maq_s_w_phr (a64, v2q15, v2q15)
  247. a64 __builtin_mips_maq_sa_w_phl (a64, v2q15, v2q15)
  248. a64 __builtin_mips_maq_sa_w_phr (a64, v2q15, v2q15)
  249. i32 __builtin_mips_bitrev (i32)
  250. i32 __builtin_mips_insv (i32, i32)
  251. v4i8 __builtin_mips_repl_qb (imm0_255)
  252. v4i8 __builtin_mips_repl_qb (i32)
  253. v2q15 __builtin_mips_repl_ph (imm_n512_511)
  254. v2q15 __builtin_mips_repl_ph (i32)
  255. void __builtin_mips_cmpu_eq_qb (v4i8, v4i8)
  256. void __builtin_mips_cmpu_lt_qb (v4i8, v4i8)
  257. void __builtin_mips_cmpu_le_qb (v4i8, v4i8)
  258. i32 __builtin_mips_cmpgu_eq_qb (v4i8, v4i8)
  259. i32 __builtin_mips_cmpgu_lt_qb (v4i8, v4i8)
  260. i32 __builtin_mips_cmpgu_le_qb (v4i8, v4i8)
  261. void __builtin_mips_cmp_eq_ph (v2q15, v2q15)
  262. void __builtin_mips_cmp_lt_ph (v2q15, v2q15)
  263. void __builtin_mips_cmp_le_ph (v2q15, v2q15)
  264. v4i8 __builtin_mips_pick_qb (v4i8, v4i8)
  265. v2q15 __builtin_mips_pick_ph (v2q15, v2q15)
  266. v2q15 __builtin_mips_packrl_ph (v2q15, v2q15)
  267. i32 __builtin_mips_extr_w (a64, imm0_31)
  268. i32 __builtin_mips_extr_w (a64, i32)
  269. i32 __builtin_mips_extr_r_w (a64, imm0_31)
  270. i32 __builtin_mips_extr_s_h (a64, i32)
  271. i32 __builtin_mips_extr_rs_w (a64, imm0_31)
  272. i32 __builtin_mips_extr_rs_w (a64, i32)
  273. i32 __builtin_mips_extr_s_h (a64, imm0_31)
  274. i32 __builtin_mips_extr_r_w (a64, i32)
  275. i32 __builtin_mips_extp (a64, imm0_31)
  276. i32 __builtin_mips_extp (a64, i32)
  277. i32 __builtin_mips_extpdp (a64, imm0_31)
  278. i32 __builtin_mips_extpdp (a64, i32)
  279. a64 __builtin_mips_shilo (a64, imm_n32_31)
  280. a64 __builtin_mips_shilo (a64, i32)
  281. a64 __builtin_mips_mthlip (a64, i32)
  282. void __builtin_mips_wrdsp (i32, imm0_63)
  283. i32 __builtin_mips_rddsp (imm0_63)
  284. i32 __builtin_mips_lbux (void *, i32)
  285. i32 __builtin_mips_lhx (void *, i32)
  286. i32 __builtin_mips_lwx (void *, i32)
  287. a64 __builtin_mips_ldx (void *, i32) [MIPS64 only]
  288. i32 __builtin_mips_bposge32 (void)
  289. a64 __builtin_mips_madd (a64, i32, i32);
  290. a64 __builtin_mips_maddu (a64, ui32, ui32);
  291. a64 __builtin_mips_msub (a64, i32, i32);
  292. a64 __builtin_mips_msubu (a64, ui32, ui32);
  293. a64 __builtin_mips_mult (i32, i32);
  294. a64 __builtin_mips_multu (ui32, ui32);
  295. </pre></div>
  296. <p>The following built-in functions map directly to a particular MIPS DSP REV 2
  297. instruction. Please refer to the architecture specification
  298. for details on what each instruction does.
  299. </p>
  300. <div class="smallexample">
  301. <pre class="smallexample">v4q7 __builtin_mips_absq_s_qb (v4q7);
  302. v2i16 __builtin_mips_addu_ph (v2i16, v2i16);
  303. v2i16 __builtin_mips_addu_s_ph (v2i16, v2i16);
  304. v4i8 __builtin_mips_adduh_qb (v4i8, v4i8);
  305. v4i8 __builtin_mips_adduh_r_qb (v4i8, v4i8);
  306. i32 __builtin_mips_append (i32, i32, imm0_31);
  307. i32 __builtin_mips_balign (i32, i32, imm0_3);
  308. i32 __builtin_mips_cmpgdu_eq_qb (v4i8, v4i8);
  309. i32 __builtin_mips_cmpgdu_lt_qb (v4i8, v4i8);
  310. i32 __builtin_mips_cmpgdu_le_qb (v4i8, v4i8);
  311. a64 __builtin_mips_dpa_w_ph (a64, v2i16, v2i16);
  312. a64 __builtin_mips_dps_w_ph (a64, v2i16, v2i16);
  313. v2i16 __builtin_mips_mul_ph (v2i16, v2i16);
  314. v2i16 __builtin_mips_mul_s_ph (v2i16, v2i16);
  315. q31 __builtin_mips_mulq_rs_w (q31, q31);
  316. v2q15 __builtin_mips_mulq_s_ph (v2q15, v2q15);
  317. q31 __builtin_mips_mulq_s_w (q31, q31);
  318. a64 __builtin_mips_mulsa_w_ph (a64, v2i16, v2i16);
  319. v4i8 __builtin_mips_precr_qb_ph (v2i16, v2i16);
  320. v2i16 __builtin_mips_precr_sra_ph_w (i32, i32, imm0_31);
  321. v2i16 __builtin_mips_precr_sra_r_ph_w (i32, i32, imm0_31);
  322. i32 __builtin_mips_prepend (i32, i32, imm0_31);
  323. v4i8 __builtin_mips_shra_qb (v4i8, imm0_7);
  324. v4i8 __builtin_mips_shra_r_qb (v4i8, imm0_7);
  325. v4i8 __builtin_mips_shra_qb (v4i8, i32);
  326. v4i8 __builtin_mips_shra_r_qb (v4i8, i32);
  327. v2i16 __builtin_mips_shrl_ph (v2i16, imm0_15);
  328. v2i16 __builtin_mips_shrl_ph (v2i16, i32);
  329. v2i16 __builtin_mips_subu_ph (v2i16, v2i16);
  330. v2i16 __builtin_mips_subu_s_ph (v2i16, v2i16);
  331. v4i8 __builtin_mips_subuh_qb (v4i8, v4i8);
  332. v4i8 __builtin_mips_subuh_r_qb (v4i8, v4i8);
  333. v2q15 __builtin_mips_addqh_ph (v2q15, v2q15);
  334. v2q15 __builtin_mips_addqh_r_ph (v2q15, v2q15);
  335. q31 __builtin_mips_addqh_w (q31, q31);
  336. q31 __builtin_mips_addqh_r_w (q31, q31);
  337. v2q15 __builtin_mips_subqh_ph (v2q15, v2q15);
  338. v2q15 __builtin_mips_subqh_r_ph (v2q15, v2q15);
  339. q31 __builtin_mips_subqh_w (q31, q31);
  340. q31 __builtin_mips_subqh_r_w (q31, q31);
  341. a64 __builtin_mips_dpax_w_ph (a64, v2i16, v2i16);
  342. a64 __builtin_mips_dpsx_w_ph (a64, v2i16, v2i16);
  343. a64 __builtin_mips_dpaqx_s_w_ph (a64, v2q15, v2q15);
  344. a64 __builtin_mips_dpaqx_sa_w_ph (a64, v2q15, v2q15);
  345. a64 __builtin_mips_dpsqx_s_w_ph (a64, v2q15, v2q15);
  346. a64 __builtin_mips_dpsqx_sa_w_ph (a64, v2q15, v2q15);
  347. </pre></div>
  348. <hr>
  349. <div class="header">
  350. <p>
  351. Next: <a href="MIPS-Paired_002dSingle-Support.html#MIPS-Paired_002dSingle-Support" accesskey="n" rel="next">MIPS Paired-Single Support</a>, Previous: <a href="FR_002dV-Built_002din-Functions.html#FR_002dV-Built_002din-Functions" accesskey="p" rel="prev">FR-V Built-in Functions</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>
  352. </div>
  353. </body>
  354. </html>