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.

328 lines
13KB

  1. /*
  2. * vis.h
  3. * Copyright (C) 2003 David S. Miller <davem@redhat.com>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /* You may be asking why I hard-code the instruction opcodes and don't
  22. * use the normal VIS assembler mnenomics for the VIS instructions.
  23. *
  24. * The reason is that Sun, in their infinite wisdom, decided that a binary
  25. * using a VIS instruction will cause it to be marked (in the ELF headers)
  26. * as doing so, and this prevents the OS from loading such binaries if the
  27. * current cpu doesn't have VIS. There is no way to easily override this
  28. * behavior of the assembler that I am aware of.
  29. *
  30. * This totally defeats what libmpeg2 is trying to do which is allow a
  31. * single binary to be created, and then detect the availability of VIS
  32. * at runtime.
  33. *
  34. * I'm not saying that tainting the binary by default is bad, rather I'm
  35. * saying that not providing a way to override this easily unnecessarily
  36. * ties people's hands.
  37. *
  38. * Thus, we do the opcode encoding by hand and output 32-bit words in
  39. * the assembler to keep the binary from becoming tainted.
  40. */
  41. #define vis_opc_base ((0x1 << 31) | (0x36 << 19))
  42. #define vis_opf(X) ((X) << 5)
  43. #define vis_sreg(X) (X)
  44. #define vis_dreg(X) (((X)&0x1f)|((X)>>5))
  45. #define vis_rs1_s(X) (vis_sreg(X) << 14)
  46. #define vis_rs1_d(X) (vis_dreg(X) << 14)
  47. #define vis_rs2_s(X) (vis_sreg(X) << 0)
  48. #define vis_rs2_d(X) (vis_dreg(X) << 0)
  49. #define vis_rd_s(X) (vis_sreg(X) << 25)
  50. #define vis_rd_d(X) (vis_dreg(X) << 25)
  51. #define vis_ss2s(opf,rs1,rs2,rd) \
  52. __asm__ __volatile__ (".word %0" \
  53. : : "i" (vis_opc_base | vis_opf(opf) | \
  54. vis_rs1_s(rs1) | \
  55. vis_rs2_s(rs2) | \
  56. vis_rd_s(rd)))
  57. #define vis_dd2d(opf,rs1,rs2,rd) \
  58. __asm__ __volatile__ (".word %0" \
  59. : : "i" (vis_opc_base | vis_opf(opf) | \
  60. vis_rs1_d(rs1) | \
  61. vis_rs2_d(rs2) | \
  62. vis_rd_d(rd)))
  63. #define vis_ss2d(opf,rs1,rs2,rd) \
  64. __asm__ __volatile__ (".word %0" \
  65. : : "i" (vis_opc_base | vis_opf(opf) | \
  66. vis_rs1_s(rs1) | \
  67. vis_rs2_s(rs2) | \
  68. vis_rd_d(rd)))
  69. #define vis_sd2d(opf,rs1,rs2,rd) \
  70. __asm__ __volatile__ (".word %0" \
  71. : : "i" (vis_opc_base | vis_opf(opf) | \
  72. vis_rs1_s(rs1) | \
  73. vis_rs2_d(rs2) | \
  74. vis_rd_d(rd)))
  75. #define vis_d2s(opf,rs2,rd) \
  76. __asm__ __volatile__ (".word %0" \
  77. : : "i" (vis_opc_base | vis_opf(opf) | \
  78. vis_rs2_d(rs2) | \
  79. vis_rd_s(rd)))
  80. #define vis_s2d(opf,rs2,rd) \
  81. __asm__ __volatile__ (".word %0" \
  82. : : "i" (vis_opc_base | vis_opf(opf) | \
  83. vis_rs2_s(rs2) | \
  84. vis_rd_d(rd)))
  85. #define vis_d12d(opf,rs1,rd) \
  86. __asm__ __volatile__ (".word %0" \
  87. : : "i" (vis_opc_base | vis_opf(opf) | \
  88. vis_rs1_d(rs1) | \
  89. vis_rd_d(rd)))
  90. #define vis_d22d(opf,rs2,rd) \
  91. __asm__ __volatile__ (".word %0" \
  92. : : "i" (vis_opc_base | vis_opf(opf) | \
  93. vis_rs2_d(rs2) | \
  94. vis_rd_d(rd)))
  95. #define vis_s12s(opf,rs1,rd) \
  96. __asm__ __volatile__ (".word %0" \
  97. : : "i" (vis_opc_base | vis_opf(opf) | \
  98. vis_rs1_s(rs1) | \
  99. vis_rd_s(rd)))
  100. #define vis_s22s(opf,rs2,rd) \
  101. __asm__ __volatile__ (".word %0" \
  102. : : "i" (vis_opc_base | vis_opf(opf) | \
  103. vis_rs2_s(rs2) | \
  104. vis_rd_s(rd)))
  105. #define vis_s(opf,rd) \
  106. __asm__ __volatile__ (".word %0" \
  107. : : "i" (vis_opc_base | vis_opf(opf) | \
  108. vis_rd_s(rd)))
  109. #define vis_d(opf,rd) \
  110. __asm__ __volatile__ (".word %0" \
  111. : : "i" (vis_opc_base | vis_opf(opf) | \
  112. vis_rd_d(rd)))
  113. #define vis_r2m(op,rd,mem) \
  114. __asm__ __volatile__ (#op "\t%%f" #rd ", [%0]" : : "r" (&(mem)) )
  115. #define vis_r2m_2(op,rd,mem1,mem2) \
  116. __asm__ __volatile__ (#op "\t%%f" #rd ", [%0 + %1]" : : "r" (mem1), "r" (mem2) )
  117. #define vis_m2r(op,mem,rd) \
  118. __asm__ __volatile__ (#op "\t[%0], %%f" #rd : : "r" (&(mem)) )
  119. #define vis_m2r_2(op,mem1,mem2,rd) \
  120. __asm__ __volatile__ (#op "\t[%0 + %1], %%f" #rd : : "r" (mem1), "r" (mem2) )
  121. static inline void vis_set_gsr(unsigned int _val)
  122. {
  123. register unsigned int val asm("g1");
  124. val = _val;
  125. __asm__ __volatile__(".word 0xa7804000"
  126. : : "r" (val));
  127. }
  128. #define VIS_GSR_ALIGNADDR_MASK 0x0000007
  129. #define VIS_GSR_ALIGNADDR_SHIFT 0
  130. #define VIS_GSR_SCALEFACT_MASK 0x0000078
  131. #define VIS_GSR_SCALEFACT_SHIFT 3
  132. #define vis_ld32(mem,rs1) vis_m2r(ld, mem, rs1)
  133. #define vis_ld32_2(mem1,mem2,rs1) vis_m2r_2(ld, mem1, mem2, rs1)
  134. #define vis_st32(rs1,mem) vis_r2m(st, rs1, mem)
  135. #define vis_st32_2(rs1,mem1,mem2) vis_r2m_2(st, rs1, mem1, mem2)
  136. #define vis_ld64(mem,rs1) vis_m2r(ldd, mem, rs1)
  137. #define vis_ld64_2(mem1,mem2,rs1) vis_m2r_2(ldd, mem1, mem2, rs1)
  138. #define vis_st64(rs1,mem) vis_r2m(std, rs1, mem)
  139. #define vis_st64_2(rs1,mem1,mem2) vis_r2m_2(std, rs1, mem1, mem2)
  140. #define vis_ldblk(mem, rd) \
  141. do { register void *__mem asm("g1"); \
  142. __mem = &(mem); \
  143. __asm__ __volatile__(".word 0xc1985e00 | %1" \
  144. : \
  145. : "r" (__mem), \
  146. "i" (vis_rd_d(rd)) \
  147. : "memory"); \
  148. } while (0)
  149. #define vis_stblk(rd, mem) \
  150. do { register void *__mem asm("g1"); \
  151. __mem = &(mem); \
  152. __asm__ __volatile__(".word 0xc1b85e00 | %1" \
  153. : \
  154. : "r" (__mem), \
  155. "i" (vis_rd_d(rd)) \
  156. : "memory"); \
  157. } while (0)
  158. #define vis_membar_storestore() \
  159. __asm__ __volatile__(".word 0x8143e008" : : : "memory")
  160. #define vis_membar_sync() \
  161. __asm__ __volatile__(".word 0x8143e040" : : : "memory")
  162. /* 16 and 32 bit partitioned addition and subtraction. The normal
  163. * versions perform 4 16-bit or 2 32-bit additions or subtractions.
  164. * The 's' versions perform 2 16-bit or 1 32-bit additions or
  165. * subtractions.
  166. */
  167. #define vis_padd16(rs1,rs2,rd) vis_dd2d(0x50, rs1, rs2, rd)
  168. #define vis_padd16s(rs1,rs2,rd) vis_ss2s(0x51, rs1, rs2, rd)
  169. #define vis_padd32(rs1,rs2,rd) vis_dd2d(0x52, rs1, rs2, rd)
  170. #define vis_padd32s(rs1,rs2,rd) vis_ss2s(0x53, rs1, rs2, rd)
  171. #define vis_psub16(rs1,rs2,rd) vis_dd2d(0x54, rs1, rs2, rd)
  172. #define vis_psub16s(rs1,rs2,rd) vis_ss2s(0x55, rs1, rs2, rd)
  173. #define vis_psub32(rs1,rs2,rd) vis_dd2d(0x56, rs1, rs2, rd)
  174. #define vis_psub32s(rs1,rs2,rd) vis_ss2s(0x57, rs1, rs2, rd)
  175. /* Pixel formatting instructions. */
  176. #define vis_pack16(rs2,rd) vis_d2s( 0x3b, rs2, rd)
  177. #define vis_pack32(rs1,rs2,rd) vis_dd2d(0x3a, rs1, rs2, rd)
  178. #define vis_packfix(rs2,rd) vis_d2s( 0x3d, rs2, rd)
  179. #define vis_expand(rs2,rd) vis_s2d( 0x4d, rs2, rd)
  180. #define vis_pmerge(rs1,rs2,rd) vis_ss2d(0x4b, rs1, rs2, rd)
  181. /* Partitioned multiply instructions. */
  182. #define vis_mul8x16(rs1,rs2,rd) vis_sd2d(0x31, rs1, rs2, rd)
  183. #define vis_mul8x16au(rs1,rs2,rd) vis_ss2d(0x33, rs1, rs2, rd)
  184. #define vis_mul8x16al(rs1,rs2,rd) vis_ss2d(0x35, rs1, rs2, rd)
  185. #define vis_mul8sux16(rs1,rs2,rd) vis_dd2d(0x36, rs1, rs2, rd)
  186. #define vis_mul8ulx16(rs1,rs2,rd) vis_dd2d(0x37, rs1, rs2, rd)
  187. #define vis_muld8sux16(rs1,rs2,rd) vis_ss2d(0x38, rs1, rs2, rd)
  188. #define vis_muld8ulx16(rs1,rs2,rd) vis_ss2d(0x39, rs1, rs2, rd)
  189. /* Alignment instructions. */
  190. static inline void *vis_alignaddr(void *_ptr)
  191. {
  192. register void *ptr asm("g1");
  193. ptr = _ptr;
  194. __asm__ __volatile__(".word %2"
  195. : "=&r" (ptr)
  196. : "0" (ptr),
  197. "i" (vis_opc_base | vis_opf(0x18) |
  198. vis_rs1_s(1) |
  199. vis_rs2_s(0) |
  200. vis_rd_s(1)));
  201. return ptr;
  202. }
  203. static inline void vis_alignaddr_g0(void *_ptr)
  204. {
  205. register void *ptr asm("g1");
  206. ptr = _ptr;
  207. __asm__ __volatile__(".word %2"
  208. : "=&r" (ptr)
  209. : "0" (ptr),
  210. "i" (vis_opc_base | vis_opf(0x18) |
  211. vis_rs1_s(1) |
  212. vis_rs2_s(0) |
  213. vis_rd_s(0)));
  214. }
  215. static inline void *vis_alignaddrl(void *_ptr)
  216. {
  217. register void *ptr asm("g1");
  218. ptr = _ptr;
  219. __asm__ __volatile__(".word %2"
  220. : "=&r" (ptr)
  221. : "0" (ptr),
  222. "i" (vis_opc_base | vis_opf(0x19) |
  223. vis_rs1_s(1) |
  224. vis_rs2_s(0) |
  225. vis_rd_s(1)));
  226. return ptr;
  227. }
  228. static inline void vis_alignaddrl_g0(void *_ptr)
  229. {
  230. register void *ptr asm("g1");
  231. ptr = _ptr;
  232. __asm__ __volatile__(".word %2"
  233. : "=&r" (ptr)
  234. : "0" (ptr),
  235. "i" (vis_opc_base | vis_opf(0x19) |
  236. vis_rs1_s(1) |
  237. vis_rs2_s(0) |
  238. vis_rd_s(0)));
  239. }
  240. #define vis_faligndata(rs1,rs2,rd) vis_dd2d(0x48, rs1, rs2, rd)
  241. /* Logical operate instructions. */
  242. #define vis_fzero(rd) vis_d( 0x60, rd)
  243. #define vis_fzeros(rd) vis_s( 0x61, rd)
  244. #define vis_fone(rd) vis_d( 0x7e, rd)
  245. #define vis_fones(rd) vis_s( 0x7f, rd)
  246. #define vis_src1(rs1,rd) vis_d12d(0x74, rs1, rd)
  247. #define vis_src1s(rs1,rd) vis_s12s(0x75, rs1, rd)
  248. #define vis_src2(rs2,rd) vis_d22d(0x78, rs2, rd)
  249. #define vis_src2s(rs2,rd) vis_s22s(0x79, rs2, rd)
  250. #define vis_not1(rs1,rd) vis_d12d(0x6a, rs1, rd)
  251. #define vis_not1s(rs1,rd) vis_s12s(0x6b, rs1, rd)
  252. #define vis_not2(rs2,rd) vis_d22d(0x66, rs2, rd)
  253. #define vis_not2s(rs2,rd) vis_s22s(0x67, rs2, rd)
  254. #define vis_or(rs1,rs2,rd) vis_dd2d(0x7c, rs1, rs2, rd)
  255. #define vis_ors(rs1,rs2,rd) vis_ss2s(0x7d, rs1, rs2, rd)
  256. #define vis_nor(rs1,rs2,rd) vis_dd2d(0x62, rs1, rs2, rd)
  257. #define vis_nors(rs1,rs2,rd) vis_ss2s(0x63, rs1, rs2, rd)
  258. #define vis_and(rs1,rs2,rd) vis_dd2d(0x70, rs1, rs2, rd)
  259. #define vis_ands(rs1,rs2,rd) vis_ss2s(0x71, rs1, rs2, rd)
  260. #define vis_nand(rs1,rs2,rd) vis_dd2d(0x6e, rs1, rs2, rd)
  261. #define vis_nands(rs1,rs2,rd) vis_ss2s(0x6f, rs1, rs2, rd)
  262. #define vis_xor(rs1,rs2,rd) vis_dd2d(0x6c, rs1, rs2, rd)
  263. #define vis_xors(rs1,rs2,rd) vis_ss2s(0x6d, rs1, rs2, rd)
  264. #define vis_xnor(rs1,rs2,rd) vis_dd2d(0x72, rs1, rs2, rd)
  265. #define vis_xnors(rs1,rs2,rd) vis_ss2s(0x73, rs1, rs2, rd)
  266. #define vis_ornot1(rs1,rs2,rd) vis_dd2d(0x7a, rs1, rs2, rd)
  267. #define vis_ornot1s(rs1,rs2,rd) vis_ss2s(0x7b, rs1, rs2, rd)
  268. #define vis_ornot2(rs1,rs2,rd) vis_dd2d(0x76, rs1, rs2, rd)
  269. #define vis_ornot2s(rs1,rs2,rd) vis_ss2s(0x77, rs1, rs2, rd)
  270. #define vis_andnot1(rs1,rs2,rd) vis_dd2d(0x68, rs1, rs2, rd)
  271. #define vis_andnot1s(rs1,rs2,rd) vis_ss2s(0x69, rs1, rs2, rd)
  272. #define vis_andnot2(rs1,rs2,rd) vis_dd2d(0x64, rs1, rs2, rd)
  273. #define vis_andnot2s(rs1,rs2,rd) vis_ss2s(0x65, rs1, rs2, rd)
  274. /* Pixel component distance. */
  275. #define vis_pdist(rs1,rs2,rd) vis_dd2d(0x3e, rs1, rs2, rd)