dct_sse2.asm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. ;
  2. ; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. ;
  4. ; Use of this source code is governed by a BSD-style license
  5. ; that can be found in the LICENSE file in the root of the source
  6. ; tree. An additional intellectual property rights grant can be found
  7. ; in the file PATENTS. All contributing project authors may
  8. ; be found in the AUTHORS file in the root of the source tree.
  9. ;
  10. %include "vpx_ports/x86_abi_support.asm"
  11. %macro STACK_FRAME_CREATE 0
  12. %if ABI_IS_32BIT
  13. %define input rsi
  14. %define output rdi
  15. %define pitch rax
  16. push rbp
  17. mov rbp, rsp
  18. GET_GOT rbx
  19. push rsi
  20. push rdi
  21. ; end prolog
  22. mov rsi, arg(0)
  23. mov rdi, arg(1)
  24. movsxd rax, dword ptr arg(2)
  25. lea rcx, [rsi + rax*2]
  26. %else
  27. %if LIBVPX_YASM_WIN64
  28. %define input rcx
  29. %define output rdx
  30. %define pitch r8
  31. SAVE_XMM 7, u
  32. %else
  33. %define input rdi
  34. %define output rsi
  35. %define pitch rdx
  36. %endif
  37. %endif
  38. %endmacro
  39. %macro STACK_FRAME_DESTROY 0
  40. %define input
  41. %define output
  42. %define pitch
  43. %if ABI_IS_32BIT
  44. pop rdi
  45. pop rsi
  46. RESTORE_GOT
  47. pop rbp
  48. %else
  49. %if LIBVPX_YASM_WIN64
  50. RESTORE_XMM
  51. %endif
  52. %endif
  53. ret
  54. %endmacro
  55. SECTION .text
  56. ;void vp8_short_fdct4x4_sse2(short *input, short *output, int pitch)
  57. global sym(vp8_short_fdct4x4_sse2) PRIVATE
  58. sym(vp8_short_fdct4x4_sse2):
  59. STACK_FRAME_CREATE
  60. movq xmm0, MMWORD PTR[input ] ;03 02 01 00
  61. movq xmm2, MMWORD PTR[input+ pitch] ;13 12 11 10
  62. lea input, [input+2*pitch]
  63. movq xmm1, MMWORD PTR[input ] ;23 22 21 20
  64. movq xmm3, MMWORD PTR[input+ pitch] ;33 32 31 30
  65. punpcklqdq xmm0, xmm2 ;13 12 11 10 03 02 01 00
  66. punpcklqdq xmm1, xmm3 ;33 32 31 30 23 22 21 20
  67. movdqa xmm2, xmm0
  68. punpckldq xmm0, xmm1 ;23 22 03 02 21 20 01 00
  69. punpckhdq xmm2, xmm1 ;33 32 13 12 31 30 11 10
  70. movdqa xmm1, xmm0
  71. punpckldq xmm0, xmm2 ;31 21 30 20 11 10 01 00
  72. pshufhw xmm1, xmm1, 0b1h ;22 23 02 03 xx xx xx xx
  73. pshufhw xmm2, xmm2, 0b1h ;32 33 12 13 xx xx xx xx
  74. punpckhdq xmm1, xmm2 ;32 33 22 23 12 13 02 03
  75. movdqa xmm3, xmm0
  76. paddw xmm0, xmm1 ;b1 a1 b1 a1 b1 a1 b1 a1
  77. psubw xmm3, xmm1 ;c1 d1 c1 d1 c1 d1 c1 d1
  78. psllw xmm0, 3 ;b1 <<= 3 a1 <<= 3
  79. psllw xmm3, 3 ;c1 <<= 3 d1 <<= 3
  80. movdqa xmm1, xmm0
  81. pmaddwd xmm0, XMMWORD PTR[GLOBAL(_mult_add)] ;a1 + b1
  82. pmaddwd xmm1, XMMWORD PTR[GLOBAL(_mult_sub)] ;a1 - b1
  83. movdqa xmm4, xmm3
  84. pmaddwd xmm3, XMMWORD PTR[GLOBAL(_5352_2217)] ;c1*2217 + d1*5352
  85. pmaddwd xmm4, XMMWORD PTR[GLOBAL(_2217_neg5352)];d1*2217 - c1*5352
  86. paddd xmm3, XMMWORD PTR[GLOBAL(_14500)]
  87. paddd xmm4, XMMWORD PTR[GLOBAL(_7500)]
  88. psrad xmm3, 12 ;(c1 * 2217 + d1 * 5352 + 14500)>>12
  89. psrad xmm4, 12 ;(d1 * 2217 - c1 * 5352 + 7500)>>12
  90. packssdw xmm0, xmm1 ;op[2] op[0]
  91. packssdw xmm3, xmm4 ;op[3] op[1]
  92. ; 23 22 21 20 03 02 01 00
  93. ;
  94. ; 33 32 31 30 13 12 11 10
  95. ;
  96. movdqa xmm2, xmm0
  97. punpcklqdq xmm0, xmm3 ;13 12 11 10 03 02 01 00
  98. punpckhqdq xmm2, xmm3 ;23 22 21 20 33 32 31 30
  99. movdqa xmm3, xmm0
  100. punpcklwd xmm0, xmm2 ;32 30 22 20 12 10 02 00
  101. punpckhwd xmm3, xmm2 ;33 31 23 21 13 11 03 01
  102. movdqa xmm2, xmm0
  103. punpcklwd xmm0, xmm3 ;13 12 11 10 03 02 01 00
  104. punpckhwd xmm2, xmm3 ;33 32 31 30 23 22 21 20
  105. movdqa xmm5, XMMWORD PTR[GLOBAL(_7)]
  106. pshufd xmm2, xmm2, 04eh
  107. movdqa xmm3, xmm0
  108. paddw xmm0, xmm2 ;b1 b1 b1 b1 a1 a1 a1 a1
  109. psubw xmm3, xmm2 ;c1 c1 c1 c1 d1 d1 d1 d1
  110. pshufd xmm0, xmm0, 0d8h ;b1 b1 a1 a1 b1 b1 a1 a1
  111. movdqa xmm2, xmm3 ;save d1 for compare
  112. pshufd xmm3, xmm3, 0d8h ;c1 c1 d1 d1 c1 c1 d1 d1
  113. pshuflw xmm0, xmm0, 0d8h ;b1 b1 a1 a1 b1 a1 b1 a1
  114. pshuflw xmm3, xmm3, 0d8h ;c1 c1 d1 d1 c1 d1 c1 d1
  115. pshufhw xmm0, xmm0, 0d8h ;b1 a1 b1 a1 b1 a1 b1 a1
  116. pshufhw xmm3, xmm3, 0d8h ;c1 d1 c1 d1 c1 d1 c1 d1
  117. movdqa xmm1, xmm0
  118. pmaddwd xmm0, XMMWORD PTR[GLOBAL(_mult_add)] ;a1 + b1
  119. pmaddwd xmm1, XMMWORD PTR[GLOBAL(_mult_sub)] ;a1 - b1
  120. pxor xmm4, xmm4 ;zero out for compare
  121. paddd xmm0, xmm5
  122. paddd xmm1, xmm5
  123. pcmpeqw xmm2, xmm4
  124. psrad xmm0, 4 ;(a1 + b1 + 7)>>4
  125. psrad xmm1, 4 ;(a1 - b1 + 7)>>4
  126. pandn xmm2, XMMWORD PTR[GLOBAL(_cmp_mask)] ;clear upper,
  127. ;and keep bit 0 of lower
  128. movdqa xmm4, xmm3
  129. pmaddwd xmm3, XMMWORD PTR[GLOBAL(_5352_2217)] ;c1*2217 + d1*5352
  130. pmaddwd xmm4, XMMWORD PTR[GLOBAL(_2217_neg5352)] ;d1*2217 - c1*5352
  131. paddd xmm3, XMMWORD PTR[GLOBAL(_12000)]
  132. paddd xmm4, XMMWORD PTR[GLOBAL(_51000)]
  133. packssdw xmm0, xmm1 ;op[8] op[0]
  134. psrad xmm3, 16 ;(c1 * 2217 + d1 * 5352 + 12000)>>16
  135. psrad xmm4, 16 ;(d1 * 2217 - c1 * 5352 + 51000)>>16
  136. packssdw xmm3, xmm4 ;op[12] op[4]
  137. movdqa xmm1, xmm0
  138. paddw xmm3, xmm2 ;op[4] += (d1!=0)
  139. punpcklqdq xmm0, xmm3 ;op[4] op[0]
  140. punpckhqdq xmm1, xmm3 ;op[12] op[8]
  141. movdqa XMMWORD PTR[output + 0], xmm0
  142. movdqa XMMWORD PTR[output + 16], xmm1
  143. STACK_FRAME_DESTROY
  144. ;void vp8_short_fdct8x4_sse2(short *input, short *output, int pitch)
  145. global sym(vp8_short_fdct8x4_sse2) PRIVATE
  146. sym(vp8_short_fdct8x4_sse2):
  147. STACK_FRAME_CREATE
  148. ; read the input data
  149. movdqa xmm0, [input ]
  150. movdqa xmm2, [input+ pitch]
  151. lea input, [input+2*pitch]
  152. movdqa xmm4, [input ]
  153. movdqa xmm3, [input+ pitch]
  154. ; transpose for the first stage
  155. movdqa xmm1, xmm0 ; 00 01 02 03 04 05 06 07
  156. movdqa xmm5, xmm4 ; 20 21 22 23 24 25 26 27
  157. punpcklwd xmm0, xmm2 ; 00 10 01 11 02 12 03 13
  158. punpckhwd xmm1, xmm2 ; 04 14 05 15 06 16 07 17
  159. punpcklwd xmm4, xmm3 ; 20 30 21 31 22 32 23 33
  160. punpckhwd xmm5, xmm3 ; 24 34 25 35 26 36 27 37
  161. movdqa xmm2, xmm0 ; 00 10 01 11 02 12 03 13
  162. punpckldq xmm0, xmm4 ; 00 10 20 30 01 11 21 31
  163. punpckhdq xmm2, xmm4 ; 02 12 22 32 03 13 23 33
  164. movdqa xmm4, xmm1 ; 04 14 05 15 06 16 07 17
  165. punpckldq xmm4, xmm5 ; 04 14 24 34 05 15 25 35
  166. punpckhdq xmm1, xmm5 ; 06 16 26 36 07 17 27 37
  167. movdqa xmm3, xmm2 ; 02 12 22 32 03 13 23 33
  168. punpckhqdq xmm3, xmm1 ; 03 13 23 33 07 17 27 37
  169. punpcklqdq xmm2, xmm1 ; 02 12 22 32 06 16 26 36
  170. movdqa xmm1, xmm0 ; 00 10 20 30 01 11 21 31
  171. punpcklqdq xmm0, xmm4 ; 00 10 20 30 04 14 24 34
  172. punpckhqdq xmm1, xmm4 ; 01 11 21 32 05 15 25 35
  173. ; xmm0 0
  174. ; xmm1 1
  175. ; xmm2 2
  176. ; xmm3 3
  177. ; first stage
  178. movdqa xmm5, xmm0
  179. movdqa xmm4, xmm1
  180. paddw xmm0, xmm3 ; a1 = 0 + 3
  181. paddw xmm1, xmm2 ; b1 = 1 + 2
  182. psubw xmm4, xmm2 ; c1 = 1 - 2
  183. psubw xmm5, xmm3 ; d1 = 0 - 3
  184. psllw xmm5, 3
  185. psllw xmm4, 3
  186. psllw xmm0, 3
  187. psllw xmm1, 3
  188. ; output 0 and 2
  189. movdqa xmm2, xmm0 ; a1
  190. paddw xmm0, xmm1 ; op[0] = a1 + b1
  191. psubw xmm2, xmm1 ; op[2] = a1 - b1
  192. ; output 1 and 3
  193. ; interleave c1, d1
  194. movdqa xmm1, xmm5 ; d1
  195. punpcklwd xmm1, xmm4 ; c1 d1
  196. punpckhwd xmm5, xmm4 ; c1 d1
  197. movdqa xmm3, xmm1
  198. movdqa xmm4, xmm5
  199. pmaddwd xmm1, XMMWORD PTR[GLOBAL (_5352_2217)] ; c1*2217 + d1*5352
  200. pmaddwd xmm4, XMMWORD PTR[GLOBAL (_5352_2217)] ; c1*2217 + d1*5352
  201. pmaddwd xmm3, XMMWORD PTR[GLOBAL(_2217_neg5352)] ; d1*2217 - c1*5352
  202. pmaddwd xmm5, XMMWORD PTR[GLOBAL(_2217_neg5352)] ; d1*2217 - c1*5352
  203. paddd xmm1, XMMWORD PTR[GLOBAL(_14500)]
  204. paddd xmm4, XMMWORD PTR[GLOBAL(_14500)]
  205. paddd xmm3, XMMWORD PTR[GLOBAL(_7500)]
  206. paddd xmm5, XMMWORD PTR[GLOBAL(_7500)]
  207. psrad xmm1, 12 ; (c1 * 2217 + d1 * 5352 + 14500)>>12
  208. psrad xmm4, 12 ; (c1 * 2217 + d1 * 5352 + 14500)>>12
  209. psrad xmm3, 12 ; (d1 * 2217 - c1 * 5352 + 7500)>>12
  210. psrad xmm5, 12 ; (d1 * 2217 - c1 * 5352 + 7500)>>12
  211. packssdw xmm1, xmm4 ; op[1]
  212. packssdw xmm3, xmm5 ; op[3]
  213. ; done with vertical
  214. ; transpose for the second stage
  215. movdqa xmm4, xmm0 ; 00 10 20 30 04 14 24 34
  216. movdqa xmm5, xmm2 ; 02 12 22 32 06 16 26 36
  217. punpcklwd xmm0, xmm1 ; 00 01 10 11 20 21 30 31
  218. punpckhwd xmm4, xmm1 ; 04 05 14 15 24 25 34 35
  219. punpcklwd xmm2, xmm3 ; 02 03 12 13 22 23 32 33
  220. punpckhwd xmm5, xmm3 ; 06 07 16 17 26 27 36 37
  221. movdqa xmm1, xmm0 ; 00 01 10 11 20 21 30 31
  222. punpckldq xmm0, xmm2 ; 00 01 02 03 10 11 12 13
  223. punpckhdq xmm1, xmm2 ; 20 21 22 23 30 31 32 33
  224. movdqa xmm2, xmm4 ; 04 05 14 15 24 25 34 35
  225. punpckldq xmm2, xmm5 ; 04 05 06 07 14 15 16 17
  226. punpckhdq xmm4, xmm5 ; 24 25 26 27 34 35 36 37
  227. movdqa xmm3, xmm1 ; 20 21 22 23 30 31 32 33
  228. punpckhqdq xmm3, xmm4 ; 30 31 32 33 34 35 36 37
  229. punpcklqdq xmm1, xmm4 ; 20 21 22 23 24 25 26 27
  230. movdqa xmm4, xmm0 ; 00 01 02 03 10 11 12 13
  231. punpcklqdq xmm0, xmm2 ; 00 01 02 03 04 05 06 07
  232. punpckhqdq xmm4, xmm2 ; 10 11 12 13 14 15 16 17
  233. ; xmm0 0
  234. ; xmm1 4
  235. ; xmm2 1
  236. ; xmm3 3
  237. movdqa xmm5, xmm0
  238. movdqa xmm2, xmm1
  239. paddw xmm0, xmm3 ; a1 = 0 + 3
  240. paddw xmm1, xmm4 ; b1 = 1 + 2
  241. psubw xmm4, xmm2 ; c1 = 1 - 2
  242. psubw xmm5, xmm3 ; d1 = 0 - 3
  243. pxor xmm6, xmm6 ; zero out for compare
  244. pcmpeqw xmm6, xmm5 ; d1 != 0
  245. pandn xmm6, XMMWORD PTR[GLOBAL(_cmp_mask8x4)] ; clear upper,
  246. ; and keep bit 0 of lower
  247. ; output 0 and 2
  248. movdqa xmm2, xmm0 ; a1
  249. paddw xmm0, xmm1 ; a1 + b1
  250. psubw xmm2, xmm1 ; a1 - b1
  251. paddw xmm0, XMMWORD PTR[GLOBAL(_7w)]
  252. paddw xmm2, XMMWORD PTR[GLOBAL(_7w)]
  253. psraw xmm0, 4 ; op[0] = (a1 + b1 + 7)>>4
  254. psraw xmm2, 4 ; op[8] = (a1 - b1 + 7)>>4
  255. ; output 1 and 3
  256. ; interleave c1, d1
  257. movdqa xmm1, xmm5 ; d1
  258. punpcklwd xmm1, xmm4 ; c1 d1
  259. punpckhwd xmm5, xmm4 ; c1 d1
  260. movdqa xmm3, xmm1
  261. movdqa xmm4, xmm5
  262. pmaddwd xmm1, XMMWORD PTR[GLOBAL (_5352_2217)] ; c1*2217 + d1*5352
  263. pmaddwd xmm4, XMMWORD PTR[GLOBAL (_5352_2217)] ; c1*2217 + d1*5352
  264. pmaddwd xmm3, XMMWORD PTR[GLOBAL(_2217_neg5352)] ; d1*2217 - c1*5352
  265. pmaddwd xmm5, XMMWORD PTR[GLOBAL(_2217_neg5352)] ; d1*2217 - c1*5352
  266. paddd xmm1, XMMWORD PTR[GLOBAL(_12000)]
  267. paddd xmm4, XMMWORD PTR[GLOBAL(_12000)]
  268. paddd xmm3, XMMWORD PTR[GLOBAL(_51000)]
  269. paddd xmm5, XMMWORD PTR[GLOBAL(_51000)]
  270. psrad xmm1, 16 ; (c1 * 2217 + d1 * 5352 + 14500)>>16
  271. psrad xmm4, 16 ; (c1 * 2217 + d1 * 5352 + 14500)>>16
  272. psrad xmm3, 16 ; (d1 * 2217 - c1 * 5352 + 7500)>>16
  273. psrad xmm5, 16 ; (d1 * 2217 - c1 * 5352 + 7500)>>16
  274. packssdw xmm1, xmm4 ; op[4]
  275. packssdw xmm3, xmm5 ; op[12]
  276. paddw xmm1, xmm6 ; op[4] += (d1!=0)
  277. movdqa xmm4, xmm0
  278. movdqa xmm5, xmm2
  279. punpcklqdq xmm0, xmm1
  280. punpckhqdq xmm4, xmm1
  281. punpcklqdq xmm2, xmm3
  282. punpckhqdq xmm5, xmm3
  283. movdqa XMMWORD PTR[output + 0 ], xmm0
  284. movdqa XMMWORD PTR[output + 16], xmm2
  285. movdqa XMMWORD PTR[output + 32], xmm4
  286. movdqa XMMWORD PTR[output + 48], xmm5
  287. STACK_FRAME_DESTROY
  288. SECTION_RODATA
  289. align 16
  290. _5352_2217:
  291. dw 5352
  292. dw 2217
  293. dw 5352
  294. dw 2217
  295. dw 5352
  296. dw 2217
  297. dw 5352
  298. dw 2217
  299. align 16
  300. _2217_neg5352:
  301. dw 2217
  302. dw -5352
  303. dw 2217
  304. dw -5352
  305. dw 2217
  306. dw -5352
  307. dw 2217
  308. dw -5352
  309. align 16
  310. _mult_add:
  311. times 8 dw 1
  312. align 16
  313. _cmp_mask:
  314. times 4 dw 1
  315. times 4 dw 0
  316. align 16
  317. _cmp_mask8x4:
  318. times 8 dw 1
  319. align 16
  320. _mult_sub:
  321. dw 1
  322. dw -1
  323. dw 1
  324. dw -1
  325. dw 1
  326. dw -1
  327. dw 1
  328. dw -1
  329. align 16
  330. _7:
  331. times 4 dd 7
  332. align 16
  333. _7w:
  334. times 8 dw 7
  335. align 16
  336. _14500:
  337. times 4 dd 14500
  338. align 16
  339. _7500:
  340. times 4 dd 7500
  341. align 16
  342. _12000:
  343. times 4 dd 12000
  344. align 16
  345. _51000:
  346. times 4 dd 51000