2 ; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
12 %include "vpx_ports/x86_abi_support.asm"
14 ;void vp8_post_proc_down_and_across_xmm
16 ; unsigned char *src_ptr,
17 ; unsigned char *dst_ptr,
18 ; int src_pixels_per_line,
19 ; int dst_pixels_per_line,
24 global sym(vp8_post_proc_down_and_across_xmm) PRIVATE
25 sym(vp8_post_proc_down_and_across_xmm):
28 SHADOW_ARGS_TO_STACK 7
35 %if ABI_IS_32BIT=1 && CONFIG_PIC=1
37 ; move the global rd onto the stack, since we don't have enough registers
38 ; to do PIC addressing
39 movdqa xmm0, [GLOBAL(rd42)]
44 %define RD42 [GLOBAL(rd42)]
48 movd xmm2, dword ptr arg(6) ;flimit
53 mov rsi, arg(0) ;src_ptr
54 mov rdi, arg(1) ;dst_ptr
56 movsxd rcx, DWORD PTR arg(4) ;rows
57 movsxd rax, DWORD PTR arg(2) ;src_pixels_per_line ; destination pitch?
58 pxor xmm0, xmm0 ; mm0 = 00000000
62 xor rdx, rdx ; clear out rdx for use as loop counter
64 movq xmm3, QWORD PTR [rsi] ; mm4 = r0 p0..p7
65 punpcklbw xmm3, xmm0 ; mm3 = p0..p3
66 movdqa xmm1, xmm3 ; mm1 = p0..p3
69 movq xmm5, QWORD PTR [rsi + rax] ; mm4 = r1 p0..p7
70 punpcklbw xmm5, xmm0 ; mm5 = r1 p0..p3
71 paddusw xmm3, xmm5 ; mm3 += mm6
74 movdqa xmm7, xmm1 ; mm7 = r0 p0..p3
75 psubusw xmm7, xmm5 ; mm7 = r0 p0..p3 - r1 p0..p3
76 psubusw xmm5, xmm1 ; mm5 = r1 p0..p3 - r0 p0..p3
77 paddusw xmm7, xmm5 ; mm7 = abs(r0 p0..p3 - r1 p0..p3)
80 movq xmm5, QWORD PTR [rsi + 2*rax] ; mm4 = r2 p0..p7
81 punpcklbw xmm5, xmm0 ; mm5 = r2 p0..p3
82 paddusw xmm3, xmm5 ; mm3 += mm5
85 movdqa xmm6, xmm1 ; mm6 = r0 p0..p3
86 psubusw xmm6, xmm5 ; mm6 = r0 p0..p3 - r2 p0..p3
87 psubusw xmm5, xmm1 ; mm5 = r2 p0..p3 - r2 p0..p3
88 paddusw xmm6, xmm5 ; mm6 = abs(r0 p0..p3 - r2 p0..p3)
90 por xmm7, xmm6 ; accumulate thresholds
94 movq xmm5, QWORD PTR [rsi+2*rax] ; mm4 = r-2 p0..p7
95 punpcklbw xmm5, xmm0 ; mm5 = r-2 p0..p3
96 paddusw xmm3, xmm5 ; mm3 += mm5
99 movdqa xmm6, xmm1 ; mm6 = r0 p0..p3
100 psubusw xmm6, xmm5 ; mm6 = p0..p3 - r-2 p0..p3
101 psubusw xmm5, xmm1 ; mm5 = r-2 p0..p3 - p0..p3
102 paddusw xmm6, xmm5 ; mm6 = abs(r0 p0..p3 - r-2 p0..p3)
104 por xmm7, xmm6 ; accumulate thresholds
106 movq xmm4, QWORD PTR [rsi+rax] ; mm4 = r-1 p0..p7
107 punpcklbw xmm4, xmm0 ; mm4 = r-1 p0..p3
108 paddusw xmm3, xmm4 ; mm3 += mm5
111 movdqa xmm6, xmm1 ; mm6 = r0 p0..p3
112 psubusw xmm6, xmm4 ; mm6 = p0..p3 - r-2 p0..p3
113 psubusw xmm4, xmm1 ; mm5 = r-1 p0..p3 - p0..p3
114 paddusw xmm6, xmm4 ; mm6 = abs(r0 p0..p3 - r-1 p0..p3)
116 por xmm7, xmm6 ; accumulate thresholds
119 paddusw xmm3, RD42 ; mm3 += round value
120 psraw xmm3, 3 ; mm3 /= 8
122 pand xmm1, xmm7 ; mm1 select vals > thresh from source
123 pandn xmm7, xmm3 ; mm7 select vals < thresh from blurred result
124 paddusw xmm1, xmm7 ; combination
126 packuswb xmm1, xmm0 ; pack to bytes
127 movq QWORD PTR [rdi], xmm1 ;
129 neg rax ; pitch is positive
134 cmp edx, dword arg(5) ;cols
138 ; done with the all cols, start the across filtering in place
143 ; dup the first byte into the left border 8 times
152 ; dup the last byte into the right border
153 movsxd rdx, dword arg(5)
154 movq mm1, [rdi + rdx + -1]
161 movq mm0, QWORD PTR [rdi-8];
164 movq xmm7, QWORD PTR [rdi +rdx -2]
165 movd xmm4, DWORD PTR [rdi +rdx +6]
172 punpcklbw xmm3, xmm0 ; mm3 = p0..p3
173 movdqa xmm1, xmm3 ; mm1 = p0..p3
179 punpcklbw xmm5, xmm0 ; mm5 = p1..p4
180 paddusw xmm3, xmm5 ; mm3 += mm6
183 movdqa xmm7, xmm1 ; mm7 = p0..p3
184 psubusw xmm7, xmm5 ; mm7 = p0..p3 - p1..p4
185 psubusw xmm5, xmm1 ; mm5 = p1..p4 - p0..p3
186 paddusw xmm7, xmm5 ; mm7 = abs(p0..p3 - p1..p4)
191 punpcklbw xmm5, xmm0 ; mm5 = p2..p5
192 paddusw xmm3, xmm5 ; mm3 += mm5
195 movdqa xmm6, xmm1 ; mm6 = p0..p3
196 psubusw xmm6, xmm5 ; mm6 = p0..p3 - p1..p4
197 psubusw xmm5, xmm1 ; mm5 = p1..p4 - p0..p3
198 paddusw xmm6, xmm5 ; mm6 = abs(p0..p3 - p1..p4)
200 por xmm7, xmm6 ; accumulate thresholds
203 movdqa xmm5, xmm4 ; mm5 = p-2..p5
204 punpcklbw xmm5, xmm0 ; mm5 = p-2..p1
205 paddusw xmm3, xmm5 ; mm3 += mm5
208 movdqa xmm6, xmm1 ; mm6 = p0..p3
209 psubusw xmm6, xmm5 ; mm6 = p0..p3 - p1..p4
210 psubusw xmm5, xmm1 ; mm5 = p1..p4 - p0..p3
211 paddusw xmm6, xmm5 ; mm6 = abs(p0..p3 - p1..p4)
213 por xmm7, xmm6 ; accumulate thresholds
215 psrldq xmm4, 1 ; mm4 = p-1..p5
216 punpcklbw xmm4, xmm0 ; mm4 = p-1..p2
217 paddusw xmm3, xmm4 ; mm3 += mm5
220 movdqa xmm6, xmm1 ; mm6 = p0..p3
221 psubusw xmm6, xmm4 ; mm6 = p0..p3 - p1..p4
222 psubusw xmm4, xmm1 ; mm5 = p1..p4 - p0..p3
223 paddusw xmm6, xmm4 ; mm6 = abs(p0..p3 - p1..p4)
225 por xmm7, xmm6 ; accumulate thresholds
227 paddusw xmm3, RD42 ; mm3 += round value
228 psraw xmm3, 3 ; mm3 /= 8
230 pand xmm1, xmm7 ; mm1 select vals > thresh from source
231 pandn xmm7, xmm3 ; mm7 select vals < thresh from blurred result
232 paddusw xmm1, xmm7 ; combination
234 packuswb xmm1, xmm0 ; pack to bytes
235 movq QWORD PTR [rdi+rdx-8], mm0 ; store previous four bytes
239 cmp edx, dword arg(5) ;cols
243 movq QWORD PTR [rdi+rdx-8], mm0
246 add rsi,rax ; next line
247 mov eax, dword arg(3) ;dst_pixels_per_line ; destination pitch?
248 add rdi,rax ; next destination
249 mov eax, dword arg(2) ;src_pixels_per_line ; destination pitch?
251 dec rcx ; decrement count
252 jnz .nextrow ; next row
254 %if ABI_IS_32BIT=1 && CONFIG_PIC=1
269 ;void vp8_mbpost_proc_down_xmm(unsigned char *dst,
270 ; int pitch, int rows, int cols,int flimit)
272 global sym(vp8_mbpost_proc_down_xmm) PRIVATE
273 sym(vp8_mbpost_proc_down_xmm):
276 SHADOW_ARGS_TO_STACK 5
286 ; unsigned char d[16][8] at [rsp]
287 ; create flimit2 at [rsp+128]
288 mov eax, dword ptr arg(4) ;flimit
292 mov [rsp+128+12], eax
293 %define flimit4 [rsp+128]
296 lea r8, [GLOBAL(sym(vp8_rv))]
302 ;for(c=0; c<cols; c+=8)
307 movsxd rax, dword ptr arg(1) ;pitch ;
309 ; this copies the last row down into the border 8 rows
315 movq xmm1, QWORD ptr[rdi] ; first row
317 .init_borderd ; initialize borders
324 neg rax ; rax = -pitch
326 ; this copies the first row up into the border 8 rows
328 movq xmm1, QWORD ptr[rdi] ; first row
330 .init_border ; initialize borders
339 lea rsi, [rsi + rax*8]; ; rdi = s[-pitch*8]
351 movq xmm1, QWORD PTR [rdi];
352 punpcklbw xmm1, xmm0 ;
358 punpcklwd xmm1, xmm0 ;
360 punpckhwd xmm2, xmm0 ;
368 ;save the var and sum
371 movq xmm1, QWORD PTR [rsi] ; [s-pitch*8]
372 movq xmm2, QWORD PTR [rdi] ; [s+pitch*7]
431 movq xmm1, QWORD PTR [rsi+rax*8]
440 %if ABI_IS_32BIT=1 && CONFIG_PIC=1
442 lea rax, [GLOBAL(sym(vp8_rv))]
443 movdqu xmm4, [rax + rcx*2] ;vp8_rv[rcx*2]
446 movdqu xmm4, [r8 + rcx*2] ;vp8_rv[rcx*2]
448 movdqu xmm4, [sym(vp8_rv) + rcx*2]
462 movq QWORD PTR [rsp + rcx*8], xmm1 ;d[rcx*8]
468 movq mm0, [rsp + rcx*8] ;d[rcx*8]
476 cmp edx, dword arg(2) ;rows
479 add dword arg(0), 8 ; s += 8
480 sub dword arg(3), 8 ; cols -= 8
498 ;void vp8_mbpost_proc_across_ip_xmm(unsigned char *src,
499 ; int pitch, int rows, int cols,int flimit)
500 global sym(vp8_mbpost_proc_across_ip_xmm) PRIVATE
501 sym(vp8_mbpost_proc_across_ip_xmm):
504 SHADOW_ARGS_TO_STACK 5
514 ; create flimit4 at [rsp]
515 mov eax, dword ptr arg(4) ;flimit
520 %define flimit4 [rsp]
526 xor rdx, rdx ;sumsq=0;
531 ; dup the first byte into the left border 8 times
540 ; dup the last byte into the right border
541 movsxd rdx, dword arg(3)
542 movq mm1, [rsi + rdx + -1]
551 ; sumsq += s[i]*s[i];
554 movzx eax, byte [rsi+rdi]
574 movsxd rdx, dword arg(3) ;cols
582 movd xmm1, DWORD PTR [rsi+rcx-8] ; -8 -7 -6 -5
583 movd xmm2, DWORD PTR [rsi+rcx+7] ; +7 +8 +9 +10
585 punpcklbw xmm1, xmm0 ; expanding
586 punpcklbw xmm2, xmm0 ; expanding
588 punpcklwd xmm1, xmm0 ; expanding to dwords
589 punpcklwd xmm2, xmm0 ; expanding to dwords
591 psubd xmm2, xmm1 ; 7--8 8--7 9--6 10--5
592 paddd xmm1, xmm1 ; -8*2 -7*2 -6*2 -5*2
594 paddd xmm1, xmm2 ; 7+-8 8+-7 9+-6 10+-5
595 pmaddwd xmm1, xmm2 ; squared of 7+-8 8+-7 9+-6 10+-5
600 pshufd xmm6, xmm6, 0 ; duplicate the last ones
601 pshufd xmm7, xmm7, 0 ; duplicate the last ones
603 psrldq xmm1, 4 ; 8--7 9--6 10--5 0000
604 psrldq xmm2, 4 ; 8--7 9--6 10--5 0000
606 pshufd xmm3, xmm1, 3 ; 0000 8--7 8--7 8--7 squared
607 pshufd xmm4, xmm2, 3 ; 0000 8--7 8--7 8--7 squared
612 pshufd xmm3, xmm1, 01011111b ; 0000 0000 9--6 9--6 squared
613 pshufd xmm4, xmm2, 01011111b ; 0000 0000 9--6 9--6 squared
618 pshufd xmm3, xmm1, 10111111b ; 0000 0000 8--7 8--7 squared
619 pshufd xmm4, xmm2, 10111111b ; 0000 0000 8--7 8--7 squared
639 movd xmm1, DWORD PTR [rsi+rcx]
646 paddd xmm1, [GLOBAL(four8s)]
657 movd [rsi+rcx-8], mm0
670 movsxd rax, dword arg(1)
673 sub dword arg(2), 1 ;rows-=1
691 ;void vp8_plane_add_noise_wmt (unsigned char *Start, unsigned char *noise,
692 ; unsigned char blackclamp[16],
693 ; unsigned char whiteclamp[16],
694 ; unsigned char bothclamp[16],
695 ; unsigned int Width, unsigned int Height, int Pitch)
697 global sym(vp8_plane_add_noise_wmt) PRIVATE
698 sym(vp8_plane_add_noise_wmt):
701 SHADOW_ARGS_TO_STACK 8
708 call sym(rand) WRT_PLT
709 mov rcx, arg(1) ;noise
713 ; we rely on the fact that the clamping vectors are stored contiguously
714 ; in black/white/both order. Note that we have to reload this here because
715 ; rdx could be trashed by rand()
716 mov rdx, arg(2) ; blackclamp
720 movsxd rcx, dword arg(5) ;[Width]
725 movdqu xmm1,[rsi+rax] ; get the source
727 psubusb xmm1, [rdx] ;blackclamp ; clamp both sides so we don't outrange adding noise
728 paddusb xmm1, [rdx+32] ;bothclamp
729 psubusb xmm1, [rdx+16] ;whiteclamp
731 movdqu xmm2,[rdi+rax] ; get the noise for this line
732 paddb xmm1,xmm2 ; add it in
733 movdqu [rsi+rax],xmm1 ; store the result
735 add rax,16 ; move to the next line
740 movsxd rax, dword arg(7) ; Pitch
741 add arg(0), rax ; Start += Pitch
742 sub dword arg(6), 1 ; Height -= 1