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
)
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 ; select the last value (in zig_zag order) for EOB
205 pand xmm2
, [GLOBAL(inv_zig_zag
)]
206 pand xmm3
, [GLOBAL(inv_zig_zag
+ 16)]
207 ; select the max value
209 pshufd xmm3
, xmm2
, 00001110b
211 pshuflw xmm3
, xmm2
, 00001110b
213 pshuflw xmm3
, xmm2
, 00000001b
217 mov [rsi
+ vp8_blockd_eob
], eax
226 %ifidn __OUTPUT_FORMAT__
,x64
236 ; void vp8_fast_quantize_b_sse2 | arg
240 global sym
(vp8_fast_quantize_b_sse2
)
241 sym
(vp8_fast_quantize_b_sse2
):
250 %ifidn __OUTPUT_FORMAT__
,x64
254 ; these registers are used for passing arguments
261 mov rdi
, arg
(0) ; BLOCK *b
262 mov rsi
, arg
(1) ; BLOCKD *d
264 %ifidn __OUTPUT_FORMAT__
,x64
265 mov rdi
, rcx
; BLOCK *b
266 mov rsi
, rdx
; BLOCKD *d
268 ;mov rdi, rdi ; BLOCK *b
269 ;mov rsi, rsi ; BLOCKD *d
273 mov rax
, [rdi
+ vp8_block_coeff
]
274 mov rcx
, [rdi
+ vp8_block_round
]
275 mov rdx
, [rdi
+ vp8_block_quant_fast
]
279 movdqa xmm4
, [rax
+ 16]
281 ; dup z so we can save sz
289 ; x = abs(z) = (z ^ sz) - sz
297 paddw xmm5
, [rcx
+ 16]
299 mov rax
, [rsi
+ vp8_blockd_qcoeff
]
300 mov rcx
, [rsi
+ vp8_blockd_dequant
]
301 mov rdi
, [rsi
+ vp8_blockd_dqcoeff
]
303 ; y = x * quant >> 16
305 pmulhw xmm5
, [rdx
+ 16]
315 movdqa
[rax
+ 16], xmm5
321 pmullw xmm3
, [rcx
+ 16]
323 ; dqcoeff = x * dequant
325 movdqa
[rdi
+ 16], xmm3
327 pxor xmm4
, xmm4
;clear all bits
331 pcmpeqw xmm4
, xmm4
;set all bits
335 pand xmm1
, [GLOBAL(inv_zig_zag
)]
336 pand xmm5
, [GLOBAL(inv_zig_zag
+ 16)]
341 pshufd xmm5
, xmm1
, 00001110b
346 pshuflw xmm5
, xmm1
, 00001110b
351 pshuflw xmm5
, xmm1
, 00000001b
357 mov [rsi
+ vp8_blockd_eob
], eax
364 %ifidn __OUTPUT_FORMAT__
,x64
377 dw 0x0001, 0x0002, 0x0006, 0x0007
378 dw 0x0003, 0x0005, 0x0008, 0x000d
379 dw 0x0004, 0x0009, 0x000c, 0x000e
380 dw 0x000a, 0x000b, 0x000f, 0x0010