h264_deblock_sse2.asm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. ;*****************************************************************************
  2. ;* MMX/SSE2-optimized H.264 deblocking code
  3. ;*****************************************************************************
  4. ;* Copyright (C) 2005-2008 x264 project
  5. ;*
  6. ;* Authors: Loren Merritt <lorenm@u.washington.edu>
  7. ;*
  8. ;* This program is free software; you can redistribute it and/or modify
  9. ;* it under the terms of the GNU General Public License as published by
  10. ;* the Free Software Foundation; either version 2 of the License, or
  11. ;* (at your option) any later version.
  12. ;*
  13. ;* This program is distributed in the hope that it will be useful,
  14. ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;* GNU General Public License for more details.
  17. ;*
  18. ;* You should have received a copy of the GNU General Public License
  19. ;* along with this program; if not, write to the Free Software
  20. ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
  21. ;*****************************************************************************
  22. %include "x86inc.asm"
  23. SECTION_RODATA
  24. pb_00: times 16 db 0x00
  25. pb_01: times 16 db 0x01
  26. pb_03: times 16 db 0x03
  27. pb_a1: times 16 db 0xa1
  28. SECTION .text
  29. ; expands to [base],...,[base+7*stride]
  30. %define PASS8ROWS(base, base3, stride, stride3) \
  31. [base], [base+stride], [base+stride*2], [base3], \
  32. [base3+stride], [base3+stride*2], [base3+stride3], [base3+stride*4]
  33. ; in: 8 rows of 4 bytes in %1..%8
  34. ; out: 4 rows of 8 bytes in m0..m3
  35. %macro TRANSPOSE4x8_LOAD 8
  36. movd m0, %1
  37. movd m2, %2
  38. movd m1, %3
  39. movd m3, %4
  40. punpcklbw m0, m2
  41. punpcklbw m1, m3
  42. movq m2, m0
  43. punpcklwd m0, m1
  44. punpckhwd m2, m1
  45. movd m4, %5
  46. movd m6, %6
  47. movd m5, %7
  48. movd m7, %8
  49. punpcklbw m4, m6
  50. punpcklbw m5, m7
  51. movq m6, m4
  52. punpcklwd m4, m5
  53. punpckhwd m6, m5
  54. movq m1, m0
  55. movq m3, m2
  56. punpckldq m0, m4
  57. punpckhdq m1, m4
  58. punpckldq m2, m6
  59. punpckhdq m3, m6
  60. %endmacro
  61. ; in: 4 rows of 8 bytes in m0..m3
  62. ; out: 8 rows of 4 bytes in %1..%8
  63. %macro TRANSPOSE8x4_STORE 8
  64. movq m4, m0
  65. movq m5, m1
  66. movq m6, m2
  67. punpckhdq m4, m4
  68. punpckhdq m5, m5
  69. punpckhdq m6, m6
  70. punpcklbw m0, m1
  71. punpcklbw m2, m3
  72. movq m1, m0
  73. punpcklwd m0, m2
  74. punpckhwd m1, m2
  75. movd %1, m0
  76. punpckhdq m0, m0
  77. movd %2, m0
  78. movd %3, m1
  79. punpckhdq m1, m1
  80. movd %4, m1
  81. punpckhdq m3, m3
  82. punpcklbw m4, m5
  83. punpcklbw m6, m3
  84. movq m5, m4
  85. punpcklwd m4, m6
  86. punpckhwd m5, m6
  87. movd %5, m4
  88. punpckhdq m4, m4
  89. movd %6, m4
  90. movd %7, m5
  91. punpckhdq m5, m5
  92. movd %8, m5
  93. %endmacro
  94. %macro SBUTTERFLY 4
  95. movq %4, %2
  96. punpckl%1 %2, %3
  97. punpckh%1 %4, %3
  98. %endmacro
  99. ; in: 8 rows of 8 (only the middle 6 pels are used) in %1..%8
  100. ; out: 6 rows of 8 in [%9+0*16] .. [%9+5*16]
  101. %macro TRANSPOSE6x8_MEM 9
  102. movq m0, %1
  103. movq m1, %2
  104. movq m2, %3
  105. movq m3, %4
  106. movq m4, %5
  107. movq m5, %6
  108. movq m6, %7
  109. SBUTTERFLY bw, m0, m1, m7
  110. SBUTTERFLY bw, m2, m3, m1
  111. SBUTTERFLY bw, m4, m5, m3
  112. movq [%9+0x10], m1
  113. SBUTTERFLY bw, m6, %8, m5
  114. SBUTTERFLY wd, m0, m2, m1
  115. SBUTTERFLY wd, m4, m6, m2
  116. punpckhdq m0, m4
  117. movq [%9+0x00], m0
  118. SBUTTERFLY wd, m7, [%9+0x10], m6
  119. SBUTTERFLY wd, m3, m5, m4
  120. SBUTTERFLY dq, m7, m3, m0
  121. SBUTTERFLY dq, m1, m2, m5
  122. punpckldq m6, m4
  123. movq [%9+0x10], m1
  124. movq [%9+0x20], m5
  125. movq [%9+0x30], m7
  126. movq [%9+0x40], m0
  127. movq [%9+0x50], m6
  128. %endmacro
  129. ; in: 8 rows of 8 in %1..%8
  130. ; out: 8 rows of 8 in %9..%16
  131. %macro TRANSPOSE8x8_MEM 16
  132. movq m0, %1
  133. movq m1, %2
  134. movq m2, %3
  135. movq m3, %4
  136. movq m4, %5
  137. movq m5, %6
  138. movq m6, %7
  139. SBUTTERFLY bw, m0, m1, m7
  140. SBUTTERFLY bw, m2, m3, m1
  141. SBUTTERFLY bw, m4, m5, m3
  142. SBUTTERFLY bw, m6, %8, m5
  143. movq %9, m3
  144. SBUTTERFLY wd, m0, m2, m3
  145. SBUTTERFLY wd, m4, m6, m2
  146. SBUTTERFLY wd, m7, m1, m6
  147. movq %11, m2
  148. movq m2, %9
  149. SBUTTERFLY wd, m2, m5, m1
  150. SBUTTERFLY dq, m0, m4, m5
  151. SBUTTERFLY dq, m7, m2, m4
  152. movq %9, m0
  153. movq %10, m5
  154. movq %13, m7
  155. movq %14, m4
  156. SBUTTERFLY dq, m3, %11, m0
  157. SBUTTERFLY dq, m6, m1, m5
  158. movq %11, m3
  159. movq %12, m0
  160. movq %15, m6
  161. movq %16, m5
  162. %endmacro
  163. ; out: %4 = |%1-%2|>%3
  164. ; clobbers: %5
  165. %macro DIFF_GT 5
  166. mova %5, %2
  167. mova %4, %1
  168. psubusb %5, %1
  169. psubusb %4, %2
  170. por %4, %5
  171. psubusb %4, %3
  172. %endmacro
  173. ; out: %4 = |%1-%2|>%3
  174. ; clobbers: %5
  175. %macro DIFF_GT2 5
  176. mova %5, %2
  177. mova %4, %1
  178. psubusb %5, %1
  179. psubusb %4, %2
  180. psubusb %5, %3
  181. psubusb %4, %3
  182. pcmpeqb %4, %5
  183. %endmacro
  184. %macro SPLATW 1
  185. %ifidn m0, xmm0
  186. pshuflw %1, %1, 0
  187. punpcklqdq %1, %1
  188. %else
  189. pshufw %1, %1, 0
  190. %endif
  191. %endmacro
  192. ; in: m0=p1 m1=p0 m2=q0 m3=q1 %1=alpha-1 %2=beta-1
  193. ; out: m5=beta-1, m7=mask, %3=alpha-1
  194. ; clobbers: m4,m6
  195. %macro LOAD_MASK 2-3
  196. movd m4, %1
  197. movd m5, %2
  198. SPLATW m4
  199. SPLATW m5
  200. packuswb m4, m4 ; 16x alpha-1
  201. packuswb m5, m5 ; 16x beta-1
  202. %if %0>2
  203. mova %3, m4
  204. %endif
  205. DIFF_GT m1, m2, m4, m7, m6 ; |p0-q0| > alpha-1
  206. DIFF_GT m0, m1, m5, m4, m6 ; |p1-p0| > beta-1
  207. por m7, m4
  208. DIFF_GT m3, m2, m5, m4, m6 ; |q1-q0| > beta-1
  209. por m7, m4
  210. pxor m6, m6
  211. pcmpeqb m7, m6
  212. %endmacro
  213. ; in: m0=p1 m1=p0 m2=q0 m3=q1 m7=(tc&mask)
  214. ; out: m1=p0' m2=q0'
  215. ; clobbers: m0,3-6
  216. %macro DEBLOCK_P0_Q0 0
  217. mova m5, m1
  218. pxor m5, m2 ; p0^q0
  219. pand m5, [pb_01 GLOBAL] ; (p0^q0)&1
  220. pcmpeqb m4, m4
  221. pxor m3, m4
  222. pavgb m3, m0 ; (p1 - q1 + 256)>>1
  223. pavgb m3, [pb_03 GLOBAL] ; (((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2
  224. pxor m4, m1
  225. pavgb m4, m2 ; (q0 - p0 + 256)>>1
  226. pavgb m3, m5
  227. paddusb m3, m4 ; d+128+33
  228. mova m6, [pb_a1 GLOBAL]
  229. psubusb m6, m3
  230. psubusb m3, [pb_a1 GLOBAL]
  231. pminub m6, m7
  232. pminub m3, m7
  233. psubusb m1, m6
  234. psubusb m2, m3
  235. paddusb m1, m3
  236. paddusb m2, m6
  237. %endmacro
  238. ; in: m1=p0 m2=q0
  239. ; %1=p1 %2=q2 %3=[q2] %4=[q1] %5=tc0 %6=tmp
  240. ; out: [q1] = clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 )
  241. ; clobbers: q2, tmp, tc0
  242. %macro LUMA_Q1 6
  243. mova %6, m1
  244. pavgb %6, m2
  245. pavgb %2, %6 ; avg(p2,avg(p0,q0))
  246. pxor %6, %3
  247. pand %6, [pb_01 GLOBAL] ; (p2^avg(p0,q0))&1
  248. psubusb %2, %6 ; (p2+((p0+q0+1)>>1))>>1
  249. mova %6, %1
  250. psubusb %6, %5
  251. paddusb %5, %1
  252. pmaxub %2, %6
  253. pminub %2, %5
  254. mova %4, %2
  255. %endmacro
  256. %ifdef ARCH_X86_64
  257. ;-----------------------------------------------------------------------------
  258. ; void x264_deblock_v_luma_sse2( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 )
  259. ;-----------------------------------------------------------------------------
  260. INIT_XMM
  261. cglobal x264_deblock_v_luma_sse2
  262. movd m8, [r4] ; tc0
  263. lea r4, [r1*3]
  264. dec r2d ; alpha-1
  265. neg r4
  266. dec r3d ; beta-1
  267. add r4, r0 ; pix-3*stride
  268. mova m0, [r4+r1] ; p1
  269. mova m1, [r4+2*r1] ; p0
  270. mova m2, [r0] ; q0
  271. mova m3, [r0+r1] ; q1
  272. LOAD_MASK r2d, r3d
  273. punpcklbw m8, m8
  274. punpcklbw m8, m8 ; tc = 4x tc0[3], 4x tc0[2], 4x tc0[1], 4x tc0[0]
  275. pcmpeqb m9, m9
  276. pcmpeqb m9, m8
  277. pandn m9, m7
  278. pand m8, m9
  279. movdqa m3, [r4] ; p2
  280. DIFF_GT2 m1, m3, m5, m6, m7 ; |p2-p0| > beta-1
  281. pand m6, m9
  282. mova m7, m8
  283. psubb m7, m6
  284. pand m6, m8
  285. LUMA_Q1 m0, m3, [r4], [r4+r1], m6, m4
  286. movdqa m4, [r0+2*r1] ; q2
  287. DIFF_GT2 m2, m4, m5, m6, m3 ; |q2-q0| > beta-1
  288. pand m6, m9
  289. pand m8, m6
  290. psubb m7, m6
  291. mova m3, [r0+r1]
  292. LUMA_Q1 m3, m4, [r0+2*r1], [r0+r1], m8, m6
  293. DEBLOCK_P0_Q0
  294. mova [r4+2*r1], m1
  295. mova [r0], m2
  296. ret
  297. ;-----------------------------------------------------------------------------
  298. ; void x264_deblock_h_luma_sse2( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 )
  299. ;-----------------------------------------------------------------------------
  300. INIT_MMX
  301. cglobal x264_deblock_h_luma_sse2
  302. movsxd r10, esi
  303. lea r11, [r10+r10*2]
  304. lea rax, [r0-4]
  305. lea r9, [r0-4+r11]
  306. sub rsp, 0x68
  307. %define pix_tmp rsp
  308. ; transpose 6x16 -> tmp space
  309. TRANSPOSE6x8_MEM PASS8ROWS(rax, r9, r10, r11), pix_tmp
  310. lea rax, [rax+r10*8]
  311. lea r9, [r9 +r10*8]
  312. TRANSPOSE6x8_MEM PASS8ROWS(rax, r9, r10, r11), pix_tmp+8
  313. ; vertical filter
  314. ; alpha, beta, tc0 are still in r2d, r3d, r4
  315. ; don't backup rax, r9, r10, r11 because x264_deblock_v_luma_sse2 doesn't use them
  316. lea r0, [pix_tmp+0x30]
  317. mov esi, 0x10
  318. call x264_deblock_v_luma_sse2
  319. ; transpose 16x4 -> original space (only the middle 4 rows were changed by the filter)
  320. add rax, 2
  321. add r9, 2
  322. movq m0, [pix_tmp+0x18]
  323. movq m1, [pix_tmp+0x28]
  324. movq m2, [pix_tmp+0x38]
  325. movq m3, [pix_tmp+0x48]
  326. TRANSPOSE8x4_STORE PASS8ROWS(rax, r9, r10, r11)
  327. shl r10, 3
  328. sub rax, r10
  329. sub r9, r10
  330. shr r10, 3
  331. movq m0, [pix_tmp+0x10]
  332. movq m1, [pix_tmp+0x20]
  333. movq m2, [pix_tmp+0x30]
  334. movq m3, [pix_tmp+0x40]
  335. TRANSPOSE8x4_STORE PASS8ROWS(rax, r9, r10, r11)
  336. add rsp, 0x68
  337. ret
  338. %else
  339. %macro DEBLOCK_LUMA 3
  340. ;-----------------------------------------------------------------------------
  341. ; void x264_deblock_v8_luma_mmxext( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 )
  342. ;-----------------------------------------------------------------------------
  343. cglobal x264_deblock_%2_luma_%1, 5,5
  344. lea r4, [r1*3]
  345. dec r2 ; alpha-1
  346. neg r4
  347. dec r3 ; beta-1
  348. add r4, r0 ; pix-3*stride
  349. %assign pad 2*%3+12-(stack_offset&15)
  350. SUB esp, pad
  351. mova m0, [r4+r1] ; p1
  352. mova m1, [r4+2*r1] ; p0
  353. mova m2, [r0] ; q0
  354. mova m3, [r0+r1] ; q1
  355. LOAD_MASK r2, r3
  356. mov r3, r4m
  357. movd m4, [r3] ; tc0
  358. punpcklbw m4, m4
  359. punpcklbw m4, m4 ; tc = 4x tc0[3], 4x tc0[2], 4x tc0[1], 4x tc0[0]
  360. mova [esp+%3], m4 ; tc
  361. pcmpeqb m3, m3
  362. pcmpgtb m4, m3
  363. pand m4, m7
  364. mova [esp], m4 ; mask
  365. mova m3, [r4] ; p2
  366. DIFF_GT2 m1, m3, m5, m6, m7 ; |p2-p0| > beta-1
  367. pand m6, m4
  368. pand m4, [esp+%3] ; tc
  369. mova m7, m4
  370. psubb m7, m6
  371. pand m6, m4
  372. LUMA_Q1 m0, m3, [r4], [r4+r1], m6, m4
  373. mova m4, [r0+2*r1] ; q2
  374. DIFF_GT2 m2, m4, m5, m6, m3 ; |q2-q0| > beta-1
  375. mova m5, [esp] ; mask
  376. pand m6, m5
  377. mova m5, [esp+%3] ; tc
  378. pand m5, m6
  379. psubb m7, m6
  380. mova m3, [r0+r1]
  381. LUMA_Q1 m3, m4, [r0+2*r1], [r0+r1], m5, m6
  382. DEBLOCK_P0_Q0
  383. mova [r4+2*r1], m1
  384. mova [r0], m2
  385. ADD esp, pad
  386. RET
  387. ;-----------------------------------------------------------------------------
  388. ; void x264_deblock_h_luma_mmxext( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 )
  389. ;-----------------------------------------------------------------------------
  390. INIT_MMX
  391. cglobal x264_deblock_h_luma_%1, 0,5
  392. mov r0, r0m
  393. mov r3, r1m
  394. lea r4, [r3*3]
  395. sub r0, 4
  396. lea r1, [r0+r4]
  397. %assign pad 0x78-(stack_offset&15)
  398. SUB esp, pad
  399. %define pix_tmp esp+12
  400. ; transpose 6x16 -> tmp space
  401. TRANSPOSE6x8_MEM PASS8ROWS(r0, r1, r3, r4), pix_tmp
  402. lea r0, [r0+r3*8]
  403. lea r1, [r1+r3*8]
  404. TRANSPOSE6x8_MEM PASS8ROWS(r0, r1, r3, r4), pix_tmp+8
  405. ; vertical filter
  406. lea r0, [pix_tmp+0x30]
  407. PUSH dword r4m
  408. PUSH dword r3m
  409. PUSH dword r2m
  410. PUSH dword 16
  411. PUSH dword r0
  412. call x264_deblock_%2_luma_%1
  413. %ifidn %2, v8
  414. add dword [esp ], 8 ; pix_tmp+0x38
  415. add dword [esp+16], 2 ; tc0+2
  416. call x264_deblock_%2_luma_%1
  417. %endif
  418. ADD esp, 20
  419. ; transpose 16x4 -> original space (only the middle 4 rows were changed by the filter)
  420. mov r0, r0m
  421. sub r0, 2
  422. lea r1, [r0+r4]
  423. movq m0, [pix_tmp+0x10]
  424. movq m1, [pix_tmp+0x20]
  425. movq m2, [pix_tmp+0x30]
  426. movq m3, [pix_tmp+0x40]
  427. TRANSPOSE8x4_STORE PASS8ROWS(r0, r1, r3, r4)
  428. lea r0, [r0+r3*8]
  429. lea r1, [r1+r3*8]
  430. movq m0, [pix_tmp+0x18]
  431. movq m1, [pix_tmp+0x28]
  432. movq m2, [pix_tmp+0x38]
  433. movq m3, [pix_tmp+0x48]
  434. TRANSPOSE8x4_STORE PASS8ROWS(r0, r1, r3, r4)
  435. ADD esp, pad
  436. RET
  437. %endmacro ; DEBLOCK_LUMA
  438. INIT_XMM
  439. DEBLOCK_LUMA sse2, v, 16
  440. %endif ; ARCH
  441. %macro LUMA_INTRA_P012 4 ; p0..p3 in memory
  442. mova t0, p2
  443. mova t1, p0
  444. pavgb t0, p1
  445. pavgb t1, q0
  446. pavgb t0, t1 ; ((p2+p1+1)/2 + (p0+q0+1)/2 + 1)/2
  447. mova t5, t1
  448. mova t2, p2
  449. mova t3, p0
  450. paddb t2, p1
  451. paddb t3, q0
  452. paddb t2, t3
  453. mova t3, t2
  454. mova t4, t2
  455. psrlw t2, 1
  456. pavgb t2, mpb_00
  457. pxor t2, t0
  458. pand t2, mpb_01
  459. psubb t0, t2 ; p1' = (p2+p1+p0+q0+2)/4;
  460. mova t1, p2
  461. mova t2, p2
  462. pavgb t1, q1
  463. psubb t2, q1
  464. paddb t3, t3
  465. psubb t3, t2 ; p2+2*p1+2*p0+2*q0+q1
  466. pand t2, mpb_01
  467. psubb t1, t2
  468. pavgb t1, p1
  469. pavgb t1, t5 ; (((p2+q1)/2 + p1+1)/2 + (p0+q0+1)/2 + 1)/2
  470. psrlw t3, 2
  471. pavgb t3, mpb_00
  472. pxor t3, t1
  473. pand t3, mpb_01
  474. psubb t1, t3 ; p0'a = (p2+2*p1+2*p0+2*q0+q1+4)/8
  475. mova t3, p0
  476. mova t2, p0
  477. pxor t3, q1
  478. pavgb t2, q1
  479. pand t3, mpb_01
  480. psubb t2, t3
  481. pavgb t2, p1 ; p0'b = (2*p1+p0+q0+2)/4
  482. pxor t1, t2
  483. pxor t2, p0
  484. pand t1, mask1p
  485. pand t2, mask0
  486. pxor t1, t2
  487. pxor t1, p0
  488. mova %1, t1 ; store p0
  489. mova t1, %4 ; p3
  490. mova t2, t1
  491. pavgb t1, p2
  492. paddb t2, p2
  493. pavgb t1, t0 ; (p3+p2+1)/2 + (p2+p1+p0+q0+2)/4
  494. paddb t2, t2
  495. paddb t2, t4 ; 2*p3+3*p2+p1+p0+q0
  496. psrlw t2, 2
  497. pavgb t2, mpb_00
  498. pxor t2, t1
  499. pand t2, mpb_01
  500. psubb t1, t2 ; p2' = (2*p3+3*p2+p1+p0+q0+4)/8
  501. pxor t0, p1
  502. pxor t1, p2
  503. pand t0, mask1p
  504. pand t1, mask1p
  505. pxor t0, p1
  506. pxor t1, p2
  507. mova %2, t0 ; store p1
  508. mova %3, t1 ; store p2
  509. %endmacro
  510. %macro LUMA_INTRA_SWAP_PQ 0
  511. %define q1 m0
  512. %define q0 m1
  513. %define p0 m2
  514. %define p1 m3
  515. %define p2 q2
  516. %define mask1p mask1q
  517. %endmacro
  518. %macro DEBLOCK_LUMA_INTRA 2
  519. %define p1 m0
  520. %define p0 m1
  521. %define q0 m2
  522. %define q1 m3
  523. %define t0 m4
  524. %define t1 m5
  525. %define t2 m6
  526. %define t3 m7
  527. %ifdef ARCH_X86_64
  528. %define p2 m8
  529. %define q2 m9
  530. %define t4 m10
  531. %define t5 m11
  532. %define mask0 m12
  533. %define mask1p m13
  534. %define mask1q [rsp-24]
  535. %define mpb_00 m14
  536. %define mpb_01 m15
  537. %else
  538. %define spill(x) [esp+16*x+((stack_offset+4)&15)]
  539. %define p2 [r4+r1]
  540. %define q2 [r0+2*r1]
  541. %define t4 spill(0)
  542. %define t5 spill(1)
  543. %define mask0 spill(2)
  544. %define mask1p spill(3)
  545. %define mask1q spill(4)
  546. %define mpb_00 [pb_00 GLOBAL]
  547. %define mpb_01 [pb_01 GLOBAL]
  548. %endif
  549. ;-----------------------------------------------------------------------------
  550. ; void x264_deblock_v_luma_intra_sse2( uint8_t *pix, int stride, int alpha, int beta )
  551. ;-----------------------------------------------------------------------------
  552. cglobal x264_deblock_%2_luma_intra_%1, 4,6
  553. %ifndef ARCH_X86_64
  554. sub esp, 0x60
  555. %endif
  556. lea r4, [r1*4]
  557. lea r5, [r1*3] ; 3*stride
  558. dec r2d ; alpha-1
  559. jl .end
  560. neg r4
  561. dec r3d ; beta-1
  562. jl .end
  563. add r4, r0 ; pix-4*stride
  564. mova p1, [r4+2*r1]
  565. mova p0, [r4+r5]
  566. mova q0, [r0]
  567. mova q1, [r0+r1]
  568. %ifdef ARCH_X86_64
  569. pxor mpb_00, mpb_00
  570. mova mpb_01, [pb_01 GLOBAL]
  571. LOAD_MASK r2d, r3d, t5 ; m5=beta-1, t5=alpha-1, m7=mask0
  572. SWAP 7, 12 ; m12=mask0
  573. pavgb t5, mpb_00
  574. pavgb t5, mpb_01 ; alpha/4+1
  575. movdqa p2, [r4+r1]
  576. movdqa q2, [r0+2*r1]
  577. DIFF_GT2 p0, q0, t5, t0, t3 ; t0 = |p0-q0| > alpha/4+1
  578. DIFF_GT2 p0, p2, m5, t2, t5 ; mask1 = |p2-p0| > beta-1
  579. DIFF_GT2 q0, q2, m5, t4, t5 ; t4 = |q2-q0| > beta-1
  580. pand t0, mask0
  581. pand t4, t0
  582. pand t2, t0
  583. mova mask1q, t4
  584. mova mask1p, t2
  585. %else
  586. LOAD_MASK r2d, r3d, t5 ; m5=beta-1, t5=alpha-1, m7=mask0
  587. mova m4, t5
  588. mova mask0, m7
  589. pavgb m4, [pb_00 GLOBAL]
  590. pavgb m4, [pb_01 GLOBAL] ; alpha/4+1
  591. DIFF_GT2 p0, q0, m4, m6, m7 ; m6 = |p0-q0| > alpha/4+1
  592. pand m6, mask0
  593. DIFF_GT2 p0, p2, m5, m4, m7 ; m4 = |p2-p0| > beta-1
  594. pand m4, m6
  595. mova mask1p, m4
  596. DIFF_GT2 q0, q2, m5, m4, m7 ; m4 = |q2-q0| > beta-1
  597. pand m4, m6
  598. mova mask1q, m4
  599. %endif
  600. LUMA_INTRA_P012 [r4+r5], [r4+2*r1], [r4+r1], [r4]
  601. LUMA_INTRA_SWAP_PQ
  602. LUMA_INTRA_P012 [r0], [r0+r1], [r0+2*r1], [r0+r5]
  603. .end:
  604. %ifndef ARCH_X86_64
  605. add esp, 0x60
  606. %endif
  607. RET
  608. INIT_MMX
  609. %ifdef ARCH_X86_64
  610. ;-----------------------------------------------------------------------------
  611. ; void x264_deblock_h_luma_intra_sse2( uint8_t *pix, int stride, int alpha, int beta )
  612. ;-----------------------------------------------------------------------------
  613. cglobal x264_deblock_h_luma_intra_%1
  614. movsxd r10, r1d
  615. lea r11, [r10*3]
  616. lea rax, [r0-4]
  617. lea r9, [r0-4+r11]
  618. sub rsp, 0x88
  619. %define pix_tmp rsp
  620. ; transpose 8x16 -> tmp space
  621. TRANSPOSE8x8_MEM PASS8ROWS(rax, r9, r10, r11), PASS8ROWS(pix_tmp, pix_tmp+0x30, 0x10, 0x30)
  622. lea rax, [rax+r10*8]
  623. lea r9, [r9+r10*8]
  624. TRANSPOSE8x8_MEM PASS8ROWS(rax, r9, r10, r11), PASS8ROWS(pix_tmp+8, pix_tmp+0x38, 0x10, 0x30)
  625. lea r0, [pix_tmp+0x40]
  626. mov r1, 0x10
  627. call x264_deblock_v_luma_intra_%1
  628. ; transpose 16x6 -> original space (but we can't write only 6 pixels, so really 16x8)
  629. lea r9, [rax+r11]
  630. TRANSPOSE8x8_MEM PASS8ROWS(pix_tmp+8, pix_tmp+0x38, 0x10, 0x30), PASS8ROWS(rax, r9, r10, r11)
  631. shl r10, 3
  632. sub rax, r10
  633. sub r9, r10
  634. shr r10, 3
  635. TRANSPOSE8x8_MEM PASS8ROWS(pix_tmp, pix_tmp+0x30, 0x10, 0x30), PASS8ROWS(rax, r9, r10, r11)
  636. add rsp, 0x88
  637. ret
  638. %else
  639. cglobal x264_deblock_h_luma_intra_%1, 2,4
  640. lea r3, [r1*3]
  641. sub r0, 4
  642. lea r2, [r0+r3]
  643. %assign pad 0x8c-(stack_offset&15)
  644. SUB rsp, pad
  645. %define pix_tmp rsp
  646. ; transpose 8x16 -> tmp space
  647. TRANSPOSE8x8_MEM PASS8ROWS(r0, r2, r1, r3), PASS8ROWS(pix_tmp, pix_tmp+0x30, 0x10, 0x30)
  648. lea r0, [r0+r1*8]
  649. lea r2, [r2+r1*8]
  650. TRANSPOSE8x8_MEM PASS8ROWS(r0, r2, r1, r3), PASS8ROWS(pix_tmp+8, pix_tmp+0x38, 0x10, 0x30)
  651. lea r0, [pix_tmp+0x40]
  652. PUSH dword r3m
  653. PUSH dword r2m
  654. PUSH dword 16
  655. PUSH r0
  656. call x264_deblock_%2_luma_intra_%1
  657. %ifidn %2, v8
  658. add dword [rsp], 8 ; pix_tmp+8
  659. call x264_deblock_%2_luma_intra_%1
  660. %endif
  661. ADD esp, 16
  662. mov r1, r1m
  663. mov r0, r0m
  664. lea r3, [r1*3]
  665. sub r0, 4
  666. lea r2, [r0+r3]
  667. ; transpose 16x6 -> original space (but we can't write only 6 pixels, so really 16x8)
  668. TRANSPOSE8x8_MEM PASS8ROWS(pix_tmp, pix_tmp+0x30, 0x10, 0x30), PASS8ROWS(r0, r2, r1, r3)
  669. lea r0, [r0+r1*8]
  670. lea r2, [r2+r1*8]
  671. TRANSPOSE8x8_MEM PASS8ROWS(pix_tmp+8, pix_tmp+0x38, 0x10, 0x30), PASS8ROWS(r0, r2, r1, r3)
  672. ADD rsp, pad
  673. RET
  674. %endif ; ARCH_X86_64
  675. %endmacro ; DEBLOCK_LUMA_INTRA
  676. INIT_XMM
  677. DEBLOCK_LUMA_INTRA sse2, v
  678. %ifndef ARCH_X86_64
  679. INIT_MMX
  680. DEBLOCK_LUMA_INTRA mmxext, v8
  681. %endif