Clone of mesa.
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.

rtasm_ppc_spe.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * (C) Copyright IBM Corporation 2008
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * \file
  26. * Real-time assembly generation interface for Cell B.E. SPEs.
  27. * For details, see /opt/cell/sdk/docs/arch/SPU_ISA_v1.2_27Jan2007_pub.pdf
  28. *
  29. * \author Ian Romanick <idr@us.ibm.com>
  30. */
  31. #ifndef RTASM_PPC_SPE_H
  32. #define RTASM_PPC_SPE_H
  33. /** 4 bytes per instruction */
  34. #define SPE_INST_SIZE 4
  35. /** number of general-purpose SIMD registers */
  36. #define SPE_NUM_REGS 128
  37. /** Return Address register */
  38. #define SPE_REG_RA 0
  39. /** Stack Pointer register */
  40. #define SPE_REG_SP 1
  41. struct spe_function
  42. {
  43. uint32_t *store; /**< instruction buffer */
  44. uint num_inst;
  45. uint max_inst;
  46. /**
  47. * Mask of used / unused registers
  48. *
  49. * Each set bit corresponds to an available register. Each cleared bit
  50. * corresponds to an allocated register.
  51. *
  52. * \sa
  53. * spe_allocate_register, spe_allocate_available_register,
  54. * spe_release_register
  55. */
  56. uint64_t regs[SPE_NUM_REGS / 64];
  57. };
  58. extern void spe_init_func(struct spe_function *p, unsigned code_size);
  59. extern void spe_release_func(struct spe_function *p);
  60. extern int spe_allocate_available_register(struct spe_function *p);
  61. extern int spe_allocate_register(struct spe_function *p, int reg);
  62. extern void spe_release_register(struct spe_function *p, int reg);
  63. #endif /* RTASM_PPC_SPE_H */
  64. #ifndef EMIT_
  65. #define EMIT_(name, _op) \
  66. extern void _name (struct spe_function *p, unsigned rT)
  67. #define EMIT_R(_name, _op) \
  68. extern void _name (struct spe_function *p, unsigned rT, unsigned rA)
  69. #define EMIT_RR(_name, _op) \
  70. extern void _name (struct spe_function *p, unsigned rT, unsigned rA, \
  71. unsigned rB)
  72. #define EMIT_RRR(_name, _op) \
  73. extern void _name (struct spe_function *p, unsigned rT, unsigned rA, \
  74. unsigned rB, unsigned rC)
  75. #define EMIT_RI7(_name, _op) \
  76. extern void _name (struct spe_function *p, unsigned rT, unsigned rA, \
  77. int imm)
  78. #define EMIT_RI8(_name, _op, bias) \
  79. extern void _name (struct spe_function *p, unsigned rT, unsigned rA, \
  80. int imm)
  81. #define EMIT_RI10(_name, _op) \
  82. extern void _name (struct spe_function *p, unsigned rT, unsigned rA, \
  83. int imm)
  84. #define EMIT_RI16(_name, _op) \
  85. extern void _name (struct spe_function *p, unsigned rT, int imm)
  86. #define EMIT_RI18(_name, _op) \
  87. extern void _name (struct spe_function *p, unsigned rT, int imm)
  88. #define EMIT_I16(_name, _op) \
  89. extern void _name (struct spe_function *p, int imm)
  90. #define UNDEF_EMIT_MACROS
  91. #endif /* EMIT_ */
  92. /* Memory load / store instructions
  93. */
  94. EMIT_RI10(spe_lqd, 0x034);
  95. EMIT_RR (spe_lqx, 0x1c4);
  96. EMIT_RI16(spe_lqa, 0x061);
  97. EMIT_RI16(spe_lqr, 0x067);
  98. EMIT_RI10(spe_stqd, 0x024);
  99. EMIT_RR (spe_stqx, 0x144);
  100. EMIT_RI16(spe_stqa, 0x041);
  101. EMIT_RI16(spe_stqr, 0x047);
  102. EMIT_RI7 (spe_cbd, 0x1f4);
  103. EMIT_RR (spe_cbx, 0x1d4);
  104. EMIT_RI7 (spe_chd, 0x1f5);
  105. EMIT_RI7 (spe_chx, 0x1d5);
  106. EMIT_RI7 (spe_cwd, 0x1f6);
  107. EMIT_RI7 (spe_cwx, 0x1d6);
  108. EMIT_RI7 (spe_cdd, 0x1f7);
  109. EMIT_RI7 (spe_cdx, 0x1d7);
  110. /* Constant formation instructions
  111. */
  112. EMIT_RI16(spe_ilh, 0x083);
  113. EMIT_RI16(spe_ilhu, 0x082);
  114. EMIT_RI16(spe_il, 0x081);
  115. EMIT_RI18(spe_ila, 0x021);
  116. EMIT_RI16(spe_iohl, 0x0c1);
  117. EMIT_RI16(spe_fsmbi, 0x065);
  118. /* Integer and logical instructions
  119. */
  120. EMIT_RR (spe_ah, 0x0c8);
  121. EMIT_RI10(spe_ahi, 0x01d);
  122. EMIT_RR (spe_a, 0x0c0);
  123. EMIT_RI10(spe_ai, 0x01c);
  124. EMIT_RR (spe_sfh, 0x048);
  125. EMIT_RI10(spe_sfhi, 0x00d);
  126. EMIT_RR (spe_sf, 0x040);
  127. EMIT_RI10(spe_sfi, 0x00c);
  128. EMIT_RR (spe_addx, 0x340);
  129. EMIT_RR (spe_cg, 0x0c2);
  130. EMIT_RR (spe_cgx, 0x342);
  131. EMIT_RR (spe_sfx, 0x341);
  132. EMIT_RR (spe_bg, 0x042);
  133. EMIT_RR (spe_bgx, 0x343);
  134. EMIT_RR (spe_mpy, 0x3c4);
  135. EMIT_RR (spe_mpyu, 0x3cc);
  136. EMIT_RI10(spe_mpyi, 0x074);
  137. EMIT_RI10(spe_mpyui, 0x075);
  138. EMIT_RRR (spe_mpya, 0x00c);
  139. EMIT_RR (spe_mpyh, 0x3c5);
  140. EMIT_RR (spe_mpys, 0x3c7);
  141. EMIT_RR (spe_mpyhh, 0x3c6);
  142. EMIT_RR (spe_mpyhha, 0x346);
  143. EMIT_RR (spe_mpyhhu, 0x3ce);
  144. EMIT_RR (spe_mpyhhau, 0x34e);
  145. EMIT_R (spe_clz, 0x2a5);
  146. EMIT_R (spe_cntb, 0x2b4);
  147. EMIT_R (spe_fsmb, 0x1b6);
  148. EMIT_R (spe_fsmh, 0x1b5);
  149. EMIT_R (spe_fsm, 0x1b4);
  150. EMIT_R (spe_gbb, 0x1b2);
  151. EMIT_R (spe_gbh, 0x1b1);
  152. EMIT_R (spe_gb, 0x1b0);
  153. EMIT_RR (spe_avgb, 0x0d3);
  154. EMIT_RR (spe_absdb, 0x053);
  155. EMIT_RR (spe_sumb, 0x253);
  156. EMIT_R (spe_xsbh, 0x2b6);
  157. EMIT_R (spe_xshw, 0x2ae);
  158. EMIT_R (spe_xswd, 0x2a6);
  159. EMIT_RR (spe_and, 0x0c1);
  160. EMIT_RR (spe_andc, 0x2c1);
  161. EMIT_RI10(spe_andbi, 0x016);
  162. EMIT_RI10(spe_andhi, 0x015);
  163. EMIT_RI10(spe_andi, 0x014);
  164. EMIT_RR (spe_or, 0x041);
  165. EMIT_RR (spe_orc, 0x2c9);
  166. EMIT_RI10(spe_orbi, 0x006);
  167. EMIT_RI10(spe_orhi, 0x005);
  168. EMIT_RI10(spe_ori, 0x004);
  169. EMIT_R (spe_orx, 0x1f0);
  170. EMIT_RR (spe_xor, 0x241);
  171. EMIT_RI10(spe_xorbi, 0x026);
  172. EMIT_RI10(spe_xorhi, 0x025);
  173. EMIT_RI10(spe_xori, 0x024);
  174. EMIT_RR (spe_nand, 0x0c9);
  175. EMIT_RR (spe_nor, 0x049);
  176. EMIT_RR (spe_eqv, 0x249);
  177. EMIT_RRR (spe_selb, 0x008);
  178. EMIT_RRR (spe_shufb, 0x00b);
  179. /* Shift and rotate instructions
  180. */
  181. EMIT_RR (spe_shlh, 0x05f);
  182. EMIT_RI7 (spe_shlhi, 0x07f);
  183. EMIT_RR (spe_shl, 0x05b);
  184. EMIT_RI7 (spe_shli, 0x07b);
  185. EMIT_RR (spe_shlqbi, 0x1db);
  186. EMIT_RI7 (spe_shlqbii, 0x1fb);
  187. EMIT_RR (spe_shlqby, 0x1df);
  188. EMIT_RI7 (spe_shlqbyi, 0x1ff);
  189. EMIT_RR (spe_shlqbybi, 0x1cf);
  190. EMIT_RR (spe_roth, 0x05c);
  191. EMIT_RI7 (spe_rothi, 0x07c);
  192. EMIT_RR (spe_rot, 0x058);
  193. EMIT_RI7 (spe_roti, 0x078);
  194. EMIT_RR (spe_rotqby, 0x1dc);
  195. EMIT_RI7 (spe_rotqbyi, 0x1fc);
  196. EMIT_RR (spe_rotqbybi, 0x1cc);
  197. EMIT_RR (spe_rotqbi, 0x1d8);
  198. EMIT_RI7 (spe_rotqbii, 0x1f8);
  199. EMIT_RR (spe_rothm, 0x05d);
  200. EMIT_RI7 (spe_rothmi, 0x07d);
  201. EMIT_RR (spe_rotm, 0x059);
  202. EMIT_RI7 (spe_rotmi, 0x079);
  203. EMIT_RR (spe_rotqmby, 0x1dd);
  204. EMIT_RI7 (spe_rotqmbyi, 0x1fd);
  205. EMIT_RR (spe_rotqmbybi, 0x1cd);
  206. EMIT_RR (spe_rotqmbi, 0x1c9);
  207. EMIT_RI7 (spe_rotqmbii, 0x1f9);
  208. EMIT_RR (spe_rotmah, 0x05e);
  209. EMIT_RI7 (spe_rotmahi, 0x07e);
  210. EMIT_RR (spe_rotma, 0x05a);
  211. EMIT_RI7 (spe_rotmai, 0x07a);
  212. /* Compare, branch, and halt instructions
  213. */
  214. EMIT_RR (spe_heq, 0x3d8);
  215. EMIT_RI10(spe_heqi, 0x07f);
  216. EMIT_RR (spe_hgt, 0x258);
  217. EMIT_RI10(spe_hgti, 0x04f);
  218. EMIT_RR (spe_hlgt, 0x2d8);
  219. EMIT_RI10(spe_hlgti, 0x05f);
  220. EMIT_RR (spe_ceqb, 0x3d0);
  221. EMIT_RI10(spe_ceqbi, 0x07e);
  222. EMIT_RR (spe_ceqh, 0x3c8);
  223. EMIT_RI10(spe_ceqhi, 0x07d);
  224. EMIT_RR (spe_ceq, 0x3c0);
  225. EMIT_RI10(spe_ceqi, 0x07c);
  226. EMIT_RR (spe_cgtb, 0x250);
  227. EMIT_RI10(spe_cgtbi, 0x04e);
  228. EMIT_RR (spe_cgth, 0x248);
  229. EMIT_RI10(spe_cgthi, 0x04d);
  230. EMIT_RR (spe_cgt, 0x240);
  231. EMIT_RI10(spe_cgti, 0x04c);
  232. EMIT_RR (spe_clgtb, 0x2d0);
  233. EMIT_RI10(spe_clgtbi, 0x05e);
  234. EMIT_RR (spe_clgth, 0x2c8);
  235. EMIT_RI10(spe_clgthi, 0x05d);
  236. EMIT_RR (spe_clgt, 0x2c0);
  237. EMIT_RI10(spe_clgti, 0x05c);
  238. EMIT_I16 (spe_br, 0x064);
  239. EMIT_I16 (spe_bra, 0x060);
  240. EMIT_RI16(spe_brsl, 0x066);
  241. EMIT_RI16(spe_brasl, 0x062);
  242. EMIT_RI16(spe_brnz, 0x042);
  243. EMIT_RI16(spe_brz, 0x040);
  244. EMIT_RI16(spe_brhnz, 0x046);
  245. EMIT_RI16(spe_brhz, 0x044);
  246. extern void spe_bi(struct spe_function *p, unsigned rA, int d, int e);
  247. extern void spe_iret(struct spe_function *p, unsigned rA, int d, int e);
  248. extern void spe_bisled(struct spe_function *p, unsigned rT, unsigned rA,
  249. int d, int e);
  250. extern void spe_bisl(struct spe_function *p, unsigned rT, unsigned rA,
  251. int d, int e);
  252. extern void spe_biz(struct spe_function *p, unsigned rT, unsigned rA,
  253. int d, int e);
  254. extern void spe_binz(struct spe_function *p, unsigned rT, unsigned rA,
  255. int d, int e);
  256. extern void spe_bihz(struct spe_function *p, unsigned rT, unsigned rA,
  257. int d, int e);
  258. extern void spe_bihnz(struct spe_function *p, unsigned rT, unsigned rA,
  259. int d, int e);
  260. /** Load/splat immediate float into rT. */
  261. extern void
  262. spe_load_float(struct spe_function *p, unsigned rT, float x);
  263. /** Load/splat immediate int into rT. */
  264. extern void
  265. spe_load_int(struct spe_function *p, unsigned rT, int i);
  266. /** Replicate word 0 of rA across rT. */
  267. extern void
  268. spe_splat(struct spe_function *p, unsigned rT, unsigned rA);
  269. /** Complement/invert all bits in rT. */
  270. extern void
  271. spe_complement(struct spe_function *p, unsigned rT);
  272. /** rT = rA. */
  273. extern void
  274. spe_move(struct spe_function *p, unsigned rT, unsigned rA);
  275. /** rT = {0,0,0,0}. */
  276. extern void
  277. spe_zero(struct spe_function *p, unsigned rT);
  278. /* Floating-point instructions
  279. */
  280. EMIT_RR (spe_fa, 0x2c4);
  281. EMIT_RR (spe_dfa, 0x2cc);
  282. EMIT_RR (spe_fs, 0x2c5);
  283. EMIT_RR (spe_dfs, 0x2cd);
  284. EMIT_RR (spe_fm, 0x2c6);
  285. EMIT_RR (spe_dfm, 0x2ce);
  286. EMIT_RRR (spe_fma, 0x00e);
  287. EMIT_RR (spe_dfma, 0x35c);
  288. EMIT_RRR (spe_fnms, 0x00d);
  289. EMIT_RR (spe_dfnms, 0x35e);
  290. EMIT_RRR (spe_fms, 0x00f);
  291. EMIT_RR (spe_dfms, 0x35d);
  292. EMIT_RR (spe_dfnma, 0x35f);
  293. EMIT_R (spe_frest, 0x1b8);
  294. EMIT_R (spe_frsqest, 0x1b9);
  295. EMIT_RR (spe_fi, 0x3d4);
  296. EMIT_RI8 (spe_csflt, 0x1da, 155);
  297. EMIT_RI8 (spe_cflts, 0x1d8, 173);
  298. EMIT_RI8 (spe_cuflt, 0x1db, 155);
  299. EMIT_RI8 (spe_cfltu, 0x1d9, 173);
  300. EMIT_R (spe_frds, 0x3b9);
  301. EMIT_R (spe_fesd, 0x3b8);
  302. EMIT_RR (spe_dfceq, 0x3c3);
  303. EMIT_RR (spe_dfcmeq, 0x3cb);
  304. EMIT_RR (spe_dfcgt, 0x2c3);
  305. EMIT_RR (spe_dfcmgt, 0x2cb);
  306. EMIT_RI7 (spe_dftsv, 0x3bf);
  307. EMIT_RR (spe_fceq, 0x3c2);
  308. EMIT_RR (spe_fcmeq, 0x3ca);
  309. EMIT_RR (spe_fcgt, 0x2c2);
  310. EMIT_RR (spe_fcmgt, 0x2ca);
  311. EMIT_R (spe_fscrwr, 0x3ba);
  312. EMIT_ (spe_fscrrd, 0x398);
  313. /* Channel instructions
  314. */
  315. EMIT_R (spe_rdch, 0x00d);
  316. EMIT_R (spe_rdchcnt, 0x00f);
  317. EMIT_R (spe_wrch, 0x10d);
  318. #ifdef UNDEF_EMIT_MACROS
  319. #undef EMIT_
  320. #undef EMIT_R
  321. #undef EMIT_RR
  322. #undef EMIT_RRR
  323. #undef EMIT_RI7
  324. #undef EMIT_RI8
  325. #undef EMIT_RI10
  326. #undef EMIT_RI16
  327. #undef EMIT_RI18
  328. #undef EMIT_I16
  329. #undef UNDEF_EMIT_MACROS
  330. #endif /* EMIT_ */