sad_sse3.asm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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_X3 0
  12. %if ABI_IS_32BIT
  13. %define src_ptr rsi
  14. %define src_stride rax
  15. %define ref_ptr rdi
  16. %define ref_stride rdx
  17. %define end_ptr rcx
  18. %define ret_var rbx
  19. %define result_ptr arg(4)
  20. %define height dword ptr arg(4)
  21. push rbp
  22. mov rbp, rsp
  23. push rsi
  24. push rdi
  25. push rbx
  26. mov rsi, arg(0) ; src_ptr
  27. mov rdi, arg(2) ; ref_ptr
  28. movsxd rax, dword ptr arg(1) ; src_stride
  29. movsxd rdx, dword ptr arg(3) ; ref_stride
  30. %else
  31. %if LIBVPX_YASM_WIN64
  32. SAVE_XMM 7, u
  33. %define src_ptr rcx
  34. %define src_stride rdx
  35. %define ref_ptr r8
  36. %define ref_stride r9
  37. %define end_ptr r10
  38. %define ret_var r11
  39. %define result_ptr [rsp+xmm_stack_space+8+4*8]
  40. %define height dword ptr [rsp+xmm_stack_space+8+4*8]
  41. %else
  42. %define src_ptr rdi
  43. %define src_stride rsi
  44. %define ref_ptr rdx
  45. %define ref_stride rcx
  46. %define end_ptr r9
  47. %define ret_var r10
  48. %define result_ptr r8
  49. %define height r8
  50. %endif
  51. %endif
  52. %endmacro
  53. %macro STACK_FRAME_DESTROY_X3 0
  54. %define src_ptr
  55. %define src_stride
  56. %define ref_ptr
  57. %define ref_stride
  58. %define end_ptr
  59. %define ret_var
  60. %define result_ptr
  61. %define height
  62. %if ABI_IS_32BIT
  63. pop rbx
  64. pop rdi
  65. pop rsi
  66. pop rbp
  67. %else
  68. %if LIBVPX_YASM_WIN64
  69. RESTORE_XMM
  70. %endif
  71. %endif
  72. ret
  73. %endmacro
  74. %macro PROCESS_16X2X3 5
  75. %if %1==0
  76. movdqa xmm0, XMMWORD PTR [%2]
  77. lddqu xmm5, XMMWORD PTR [%3]
  78. lddqu xmm6, XMMWORD PTR [%3+1]
  79. lddqu xmm7, XMMWORD PTR [%3+2]
  80. psadbw xmm5, xmm0
  81. psadbw xmm6, xmm0
  82. psadbw xmm7, xmm0
  83. %else
  84. movdqa xmm0, XMMWORD PTR [%2]
  85. lddqu xmm1, XMMWORD PTR [%3]
  86. lddqu xmm2, XMMWORD PTR [%3+1]
  87. lddqu xmm3, XMMWORD PTR [%3+2]
  88. psadbw xmm1, xmm0
  89. psadbw xmm2, xmm0
  90. psadbw xmm3, xmm0
  91. paddw xmm5, xmm1
  92. paddw xmm6, xmm2
  93. paddw xmm7, xmm3
  94. %endif
  95. movdqa xmm0, XMMWORD PTR [%2+%4]
  96. lddqu xmm1, XMMWORD PTR [%3+%5]
  97. lddqu xmm2, XMMWORD PTR [%3+%5+1]
  98. lddqu xmm3, XMMWORD PTR [%3+%5+2]
  99. %if %1==0 || %1==1
  100. lea %2, [%2+%4*2]
  101. lea %3, [%3+%5*2]
  102. %endif
  103. psadbw xmm1, xmm0
  104. psadbw xmm2, xmm0
  105. psadbw xmm3, xmm0
  106. paddw xmm5, xmm1
  107. paddw xmm6, xmm2
  108. paddw xmm7, xmm3
  109. %endmacro
  110. %macro PROCESS_8X2X3 5
  111. %if %1==0
  112. movq mm0, QWORD PTR [%2]
  113. movq mm5, QWORD PTR [%3]
  114. movq mm6, QWORD PTR [%3+1]
  115. movq mm7, QWORD PTR [%3+2]
  116. psadbw mm5, mm0
  117. psadbw mm6, mm0
  118. psadbw mm7, mm0
  119. %else
  120. movq mm0, QWORD PTR [%2]
  121. movq mm1, QWORD PTR [%3]
  122. movq mm2, QWORD PTR [%3+1]
  123. movq mm3, QWORD PTR [%3+2]
  124. psadbw mm1, mm0
  125. psadbw mm2, mm0
  126. psadbw mm3, mm0
  127. paddw mm5, mm1
  128. paddw mm6, mm2
  129. paddw mm7, mm3
  130. %endif
  131. movq mm0, QWORD PTR [%2+%4]
  132. movq mm1, QWORD PTR [%3+%5]
  133. movq mm2, QWORD PTR [%3+%5+1]
  134. movq mm3, QWORD PTR [%3+%5+2]
  135. %if %1==0 || %1==1
  136. lea %2, [%2+%4*2]
  137. lea %3, [%3+%5*2]
  138. %endif
  139. psadbw mm1, mm0
  140. psadbw mm2, mm0
  141. psadbw mm3, mm0
  142. paddw mm5, mm1
  143. paddw mm6, mm2
  144. paddw mm7, mm3
  145. %endmacro
  146. SECTION .text
  147. ;void int vpx_sad16x16x3_sse3(
  148. ; unsigned char *src_ptr,
  149. ; int src_stride,
  150. ; unsigned char *ref_ptr,
  151. ; int ref_stride,
  152. ; int *results)
  153. global sym(vpx_sad16x16x3_sse3) PRIVATE
  154. sym(vpx_sad16x16x3_sse3):
  155. STACK_FRAME_CREATE_X3
  156. PROCESS_16X2X3 0, src_ptr, ref_ptr, src_stride, ref_stride
  157. PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  158. PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  159. PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  160. PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  161. PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  162. PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  163. PROCESS_16X2X3 2, src_ptr, ref_ptr, src_stride, ref_stride
  164. mov rcx, result_ptr
  165. movq xmm0, xmm5
  166. psrldq xmm5, 8
  167. paddw xmm0, xmm5
  168. movd [rcx], xmm0
  169. ;-
  170. movq xmm0, xmm6
  171. psrldq xmm6, 8
  172. paddw xmm0, xmm6
  173. movd [rcx+4], xmm0
  174. ;-
  175. movq xmm0, xmm7
  176. psrldq xmm7, 8
  177. paddw xmm0, xmm7
  178. movd [rcx+8], xmm0
  179. STACK_FRAME_DESTROY_X3
  180. ;void int vpx_sad16x8x3_sse3(
  181. ; unsigned char *src_ptr,
  182. ; int src_stride,
  183. ; unsigned char *ref_ptr,
  184. ; int ref_stride,
  185. ; int *results)
  186. global sym(vpx_sad16x8x3_sse3) PRIVATE
  187. sym(vpx_sad16x8x3_sse3):
  188. STACK_FRAME_CREATE_X3
  189. PROCESS_16X2X3 0, src_ptr, ref_ptr, src_stride, ref_stride
  190. PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  191. PROCESS_16X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  192. PROCESS_16X2X3 2, src_ptr, ref_ptr, src_stride, ref_stride
  193. mov rcx, result_ptr
  194. movq xmm0, xmm5
  195. psrldq xmm5, 8
  196. paddw xmm0, xmm5
  197. movd [rcx], xmm0
  198. ;-
  199. movq xmm0, xmm6
  200. psrldq xmm6, 8
  201. paddw xmm0, xmm6
  202. movd [rcx+4], xmm0
  203. ;-
  204. movq xmm0, xmm7
  205. psrldq xmm7, 8
  206. paddw xmm0, xmm7
  207. movd [rcx+8], xmm0
  208. STACK_FRAME_DESTROY_X3
  209. ;void int vpx_sad8x16x3_sse3(
  210. ; unsigned char *src_ptr,
  211. ; int src_stride,
  212. ; unsigned char *ref_ptr,
  213. ; int ref_stride,
  214. ; int *results)
  215. global sym(vpx_sad8x16x3_sse3) PRIVATE
  216. sym(vpx_sad8x16x3_sse3):
  217. STACK_FRAME_CREATE_X3
  218. PROCESS_8X2X3 0, src_ptr, ref_ptr, src_stride, ref_stride
  219. PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  220. PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  221. PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  222. PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  223. PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  224. PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  225. PROCESS_8X2X3 2, src_ptr, ref_ptr, src_stride, ref_stride
  226. mov rcx, result_ptr
  227. punpckldq mm5, mm6
  228. movq [rcx], mm5
  229. movd [rcx+8], mm7
  230. STACK_FRAME_DESTROY_X3
  231. ;void int vpx_sad8x8x3_sse3(
  232. ; unsigned char *src_ptr,
  233. ; int src_stride,
  234. ; unsigned char *ref_ptr,
  235. ; int ref_stride,
  236. ; int *results)
  237. global sym(vpx_sad8x8x3_sse3) PRIVATE
  238. sym(vpx_sad8x8x3_sse3):
  239. STACK_FRAME_CREATE_X3
  240. PROCESS_8X2X3 0, src_ptr, ref_ptr, src_stride, ref_stride
  241. PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  242. PROCESS_8X2X3 1, src_ptr, ref_ptr, src_stride, ref_stride
  243. PROCESS_8X2X3 2, src_ptr, ref_ptr, src_stride, ref_stride
  244. mov rcx, result_ptr
  245. punpckldq mm5, mm6
  246. movq [rcx], mm5
  247. movd [rcx+8], mm7
  248. STACK_FRAME_DESTROY_X3
  249. ;void int vpx_sad4x4x3_sse3(
  250. ; unsigned char *src_ptr,
  251. ; int src_stride,
  252. ; unsigned char *ref_ptr,
  253. ; int ref_stride,
  254. ; int *results)
  255. global sym(vpx_sad4x4x3_sse3) PRIVATE
  256. sym(vpx_sad4x4x3_sse3):
  257. STACK_FRAME_CREATE_X3
  258. movd mm0, DWORD PTR [src_ptr]
  259. movd mm1, DWORD PTR [ref_ptr]
  260. movd mm2, DWORD PTR [src_ptr+src_stride]
  261. movd mm3, DWORD PTR [ref_ptr+ref_stride]
  262. punpcklbw mm0, mm2
  263. punpcklbw mm1, mm3
  264. movd mm4, DWORD PTR [ref_ptr+1]
  265. movd mm5, DWORD PTR [ref_ptr+2]
  266. movd mm2, DWORD PTR [ref_ptr+ref_stride+1]
  267. movd mm3, DWORD PTR [ref_ptr+ref_stride+2]
  268. psadbw mm1, mm0
  269. punpcklbw mm4, mm2
  270. punpcklbw mm5, mm3
  271. psadbw mm4, mm0
  272. psadbw mm5, mm0
  273. lea src_ptr, [src_ptr+src_stride*2]
  274. lea ref_ptr, [ref_ptr+ref_stride*2]
  275. movd mm0, DWORD PTR [src_ptr]
  276. movd mm2, DWORD PTR [ref_ptr]
  277. movd mm3, DWORD PTR [src_ptr+src_stride]
  278. movd mm6, DWORD PTR [ref_ptr+ref_stride]
  279. punpcklbw mm0, mm3
  280. punpcklbw mm2, mm6
  281. movd mm3, DWORD PTR [ref_ptr+1]
  282. movd mm7, DWORD PTR [ref_ptr+2]
  283. psadbw mm2, mm0
  284. paddw mm1, mm2
  285. movd mm2, DWORD PTR [ref_ptr+ref_stride+1]
  286. movd mm6, DWORD PTR [ref_ptr+ref_stride+2]
  287. punpcklbw mm3, mm2
  288. punpcklbw mm7, mm6
  289. psadbw mm3, mm0
  290. psadbw mm7, mm0
  291. paddw mm3, mm4
  292. paddw mm7, mm5
  293. mov rcx, result_ptr
  294. punpckldq mm1, mm3
  295. movq [rcx], mm1
  296. movd [rcx+8], mm7
  297. STACK_FRAME_DESTROY_X3