2 ; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 ; Use of this source code is governed by a BSD-style license and patent
5 ; grant that can be found in the LICENSE file in the root of the source
6 ; tree. All contributing project authors may be found in the AUTHORS
7 ; file in the root of the source tree.
11 %include "vpx_ports/x86_abi_support.asm"
12 %include "asm_enc_offsets.asm"
15 ; void vp8_regular_quantize_b_sse2 | arg
19 global sym(vp8_regular_quantize_b_sse2) PRIVATE
20 sym(vp8_regular_quantize_b_sse2):
30 %ifidn __OUTPUT_FORMAT__,x64
37 %define zrun_zbin_boost 0 ; 8
38 %define abs_minus_zbin 8 ; 32
39 %define temp_qcoeff 40 ; 32
40 %define qcoeff 72 ; 32
41 %define stack_size 104
46 mov rdi, arg(0) ; BLOCK *b
47 mov rsi, arg(1) ; BLOCKD *d
49 %ifidn __OUTPUT_FORMAT__,x64
50 mov rdi, rcx ; BLOCK *b
51 mov rsi, rdx ; BLOCKD *d
53 ;mov rdi, rdi ; BLOCK *b
54 ;mov rsi, rsi ; BLOCKD *d
58 mov rdx, [rdi + vp8_block_coeff] ; coeff_ptr
59 mov rcx, [rdi + vp8_block_zbin] ; zbin_ptr
60 movd xmm7, [rdi + vp8_block_zbin_extra] ; zbin_oq_value
64 movdqa xmm4, [rdx + 16]
65 mov rdx, [rdi + vp8_block_round] ; round_ptr
68 punpcklwd xmm7, xmm7 ; duplicated zbin_oq_value
86 movdqa xmm3, [rcx + 16]
87 mov rcx, [rdi + vp8_block_quant] ; quant_ptr
89 ; *zbin_ptr + zbin_oq_value
93 ; x - (*zbin_ptr + zbin_oq_value)
96 movdqa [rsp + abs_minus_zbin], xmm1
97 movdqa [rsp + abs_minus_zbin + 16], xmm5
99 ; add (zbin_ptr + zbin_oq_value) back
104 movdqa xmm6, [rdx + 16]
107 movdqa xmm7, [rcx + 16]
113 ; y = x * quant_ptr >> 16
121 movdqa [rsp + temp_qcoeff], xmm1
122 movdqa [rsp + temp_qcoeff + 16], xmm5
126 movdqa [rsp + qcoeff], xmm6
127 movdqa [rsp + qcoeff + 16], xmm6
129 mov rdx, [rdi + vp8_block_zrun_zbin_boost] ; zbin_boost_ptr
130 mov rax, [rdi + vp8_block_quant_shift] ; quant_shift_ptr
131 mov [rsp + zrun_zbin_boost], rdx
135 movsx ecx, WORD PTR[rsp + abs_minus_zbin + %1 * 2]
138 sub cx, WORD PTR[rdx] ; x - zbin
139 lea rdx, [rdx + 2] ; zbin_boost_ptr++
140 jl .rq_zigzag_loop_%1 ; x < zbin
142 movsx edi, WORD PTR[rsp + temp_qcoeff + %1 * 2]
144 ; downshift by quant_shift[rc]
145 movsx cx, BYTE PTR[rax + %1] ; quant_shift_ptr[rc]
146 sar edi, cl ; also sets Z bit
147 je .rq_zigzag_loop_%1 ; !y
148 mov WORD PTR[rsp + qcoeff + %1 * 2], di ;qcoeff_ptr[rc] = temp_qcoeff[rc]
149 mov rdx, [rsp + zrun_zbin_boost] ; reset to b->zrun_zbin_boost
152 ; in vp8_default_zig_zag1d order: see vp8/common/entropy.c
170 movdqa xmm2, [rsp + qcoeff]
171 movdqa xmm3, [rsp + qcoeff + 16]
173 mov rcx, [rsi + vp8_blockd_dequant] ; dequant_ptr
174 mov rdi, [rsi + vp8_blockd_dqcoeff] ; dqcoeff_ptr
185 movdqa xmm1, [rcx + 16]
187 mov rcx, [rsi + vp8_blockd_qcoeff] ; qcoeff_ptr
192 movdqa [rcx], xmm2 ; store qcoeff
193 movdqa [rcx + 16], xmm3
194 movdqa [rdi], xmm0 ; store dqcoeff
195 movdqa [rdi + 16], xmm1
197 mov rcx, [rsi + vp8_blockd_eob]
199 ; select the last value (in zig_zag order) for EOB
207 pand xmm2, [GLOBAL(inv_zig_zag)]
208 pand xmm3, [GLOBAL(inv_zig_zag + 16)]
209 ; select the max value
211 pshufd xmm3, xmm2, 00001110b
213 pshuflw xmm3, xmm2, 00001110b
215 pshuflw xmm3, xmm2, 00000001b
220 mov BYTE PTR [rcx], al ; store eob
229 %ifidn __OUTPUT_FORMAT__,x64
239 ; void vp8_fast_quantize_b_sse2 | arg
243 global sym(vp8_fast_quantize_b_sse2) PRIVATE
244 sym(vp8_fast_quantize_b_sse2):
253 %ifidn __OUTPUT_FORMAT__,x64
257 ; these registers are used for passing arguments
264 mov rdi, arg(0) ; BLOCK *b
265 mov rsi, arg(1) ; BLOCKD *d
267 %ifidn __OUTPUT_FORMAT__,x64
268 mov rdi, rcx ; BLOCK *b
269 mov rsi, rdx ; BLOCKD *d
271 ;mov rdi, rdi ; BLOCK *b
272 ;mov rsi, rsi ; BLOCKD *d
276 mov rax, [rdi + vp8_block_coeff]
277 mov rcx, [rdi + vp8_block_round]
278 mov rdx, [rdi + vp8_block_quant_fast]
282 movdqa xmm4, [rax + 16]
284 ; dup z so we can save sz
292 ; x = abs(z) = (z ^ sz) - sz
300 paddw xmm5, [rcx + 16]
302 mov rax, [rsi + vp8_blockd_qcoeff]
303 mov rcx, [rsi + vp8_blockd_dequant]
304 mov rdi, [rsi + vp8_blockd_dqcoeff]
306 ; y = x * quant >> 16
308 pmulhw xmm5, [rdx + 16]
318 movdqa [rax + 16], xmm5
324 pmullw xmm3, [rcx + 16]
326 ; dqcoeff = x * dequant
328 movdqa [rdi + 16], xmm3
330 pxor xmm4, xmm4 ;clear all bits
334 pcmpeqw xmm4, xmm4 ;set all bits
338 pand xmm1, [GLOBAL(inv_zig_zag)]
339 pand xmm5, [GLOBAL(inv_zig_zag + 16)]
343 mov rcx, [rsi + vp8_blockd_eob]
346 pshufd xmm5, xmm1, 00001110b
351 pshuflw xmm5, xmm1, 00001110b
356 pshuflw xmm5, xmm1, 00000001b
363 mov BYTE PTR [rcx], al ; store eob
370 %ifidn __OUTPUT_FORMAT__,x64
383 dw 0x0001, 0x0002, 0x0006, 0x0007
384 dw 0x0003, 0x0005, 0x0008, 0x000d
385 dw 0x0004, 0x0009, 0x000c, 0x000e
386 dw 0x000a, 0x000b, 0x000f, 0x0010