vis.h 13 KB

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