summaryrefslogtreecommitdiff
path: root/vp9/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'vp9/encoder')
-rw-r--r--vp9/encoder/vp9_block.h2
-rw-r--r--vp9/encoder/vp9_encodemb.c6
-rw-r--r--vp9/encoder/vp9_onyx_int.h24
-rw-r--r--vp9/encoder/vp9_quantize.c113
-rw-r--r--vp9/encoder/vp9_rdopt.c2
-rw-r--r--vp9/encoder/vp9_tokenize.c4
-rw-r--r--vp9/encoder/x86/vp9_quantize_ssse3.asm165
7 files changed, 250 insertions, 66 deletions
diff --git a/vp9/encoder/vp9_block.h b/vp9/encoder/vp9_block.h
index 1e7aad7fc..43e26be8c 100644
--- a/vp9/encoder/vp9_block.h
+++ b/vp9/encoder/vp9_block.h
@@ -66,7 +66,7 @@ struct macroblock_plane {
// Quantizer setings
int16_t *quant;
- uint8_t *quant_shift;
+ int16_t *quant_shift;
int16_t *zbin;
int16_t *round;
diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c
index e69624832..253f1ae84 100644
--- a/vp9/encoder/vp9_encodemb.c
+++ b/vp9/encoder/vp9_encodemb.c
@@ -109,8 +109,8 @@ static const int plane_rd_mult[4] = {
// This function is a place holder for now but may ultimately need
// to scan previous tokens to work out the correct context.
-static int trellis_get_coeff_context(const int *scan,
- const int *nb,
+static int trellis_get_coeff_context(const int16_t *scan,
+ const int16_t *nb,
int idx, int token,
uint8_t *token_cache,
int pad, int l) {
@@ -142,7 +142,7 @@ static void optimize_b(VP9_COMMON *const cm, MACROBLOCK *mb,
PLANE_TYPE type = xd->plane[plane].plane_type;
int err_mult = plane_rd_mult[type];
int default_eob, pad;
- int const *scan, *nb;
+ const int16_t *scan, *nb;
const int mul = 1 + (tx_size == TX_32X32);
uint8_t token_cache[1024];
const int ib = txfrm_block_to_raster_block(xd, bsize, plane,
diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h
index 980095ba6..ba11a9344 100644
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -253,21 +253,21 @@ enum BlockSize {
typedef struct VP9_COMP {
- DECLARE_ALIGNED(16, short, y_quant[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, unsigned char, y_quant_shift[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, short, y_zbin[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, short, y_round[QINDEX_RANGE][16]);
+ DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, y_zbin[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, y_round[QINDEX_RANGE][8]);
- DECLARE_ALIGNED(16, short, uv_quant[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, unsigned char, uv_quant_shift[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, short, uv_zbin[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, short, uv_round[QINDEX_RANGE][16]);
+ DECLARE_ALIGNED(16, int16_t, uv_quant[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, uv_quant_shift[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, uv_zbin[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE][8]);
#if CONFIG_ALPHA
- DECLARE_ALIGNED(16, short, a_quant[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, unsigned char, a_quant_shift[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, short, a_zbin[QINDEX_RANGE][16]);
- DECLARE_ALIGNED(16, short, a_round[QINDEX_RANGE][16]);
+ DECLARE_ALIGNED(16, int16_t, a_quant[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, a_quant_shift[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, a_zbin[QINDEX_RANGE][8]);
+ DECLARE_ALIGNED(16, int16_t, a_round[QINDEX_RANGE][8]);
#endif
MACROBLOCK mb;
diff --git a/vp9/encoder/vp9_quantize.c b/vp9/encoder/vp9_quantize.c
index e68a48b12..6f2e13a0e 100644
--- a/vp9/encoder/vp9_quantize.c
+++ b/vp9/encoder/vp9_quantize.c
@@ -21,12 +21,12 @@
extern int enc_debug;
#endif
-static void quantize(int16_t *coeff_ptr, int n_coeffs, int skip_block,
- int16_t *zbin_ptr, int16_t *round_ptr, int16_t *quant_ptr,
- uint8_t *quant_shift_ptr,
- int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
- int16_t *dequant_ptr, int zbin_oq_value,
- uint16_t *eob_ptr, const int *scan) {
+void vp9_quantize_b_c(int16_t *coeff_ptr, intptr_t n_coeffs, int skip_block,
+ int16_t *zbin_ptr, int16_t *round_ptr, int16_t *quant_ptr,
+ int16_t *quant_shift_ptr, int16_t *qcoeff_ptr,
+ int16_t *dqcoeff_ptr, int16_t *dequant_ptr,
+ int zbin_oq_value, uint16_t *eob_ptr, const int16_t *scan,
+ const int16_t *iscan) {
int i, rc, eob;
int zbins[2], nzbins[2], zbin;
int x, y, z, sz;
@@ -69,8 +69,8 @@ static void quantize(int16_t *coeff_ptr, int n_coeffs, int skip_block,
if (x >= zbin) {
x += (round_ptr[rc != 0]);
- y = ((int)(((int)(x * quant_ptr[rc != 0]) >> 16) + x))
- >> quant_shift_ptr[rc != 0]; // quantize (x)
+ y = (((int)(((int)(x * quant_ptr[rc != 0]) >> 16) + x)) *
+ quant_shift_ptr[rc != 0]) >> 16; // quantize (x)
x = (y ^ sz) - sz; // get the sign back
qcoeff_ptr[rc] = x; // write to destination
dqcoeff_ptr[rc] = x * dequant_ptr[rc != 0]; // dequantized value
@@ -85,12 +85,13 @@ static void quantize(int16_t *coeff_ptr, int n_coeffs, int skip_block,
}
// This function works well for large transform size.
-static void quantize_sparse(int16_t *coeff_ptr, int n_coeffs, int skip_block,
+static void quantize_sparse(int16_t *coeff_ptr, intptr_t n_coeffs,
+ int skip_block,
int16_t *zbin_ptr, int16_t *round_ptr,
- int16_t *quant_ptr, uint8_t *quant_shift_ptr,
+ int16_t *quant_ptr, int16_t *quant_shift_ptr,
int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
int16_t *dequant_ptr, int zbin_oq_value,
- uint16_t *eob_ptr, const int *scan,
+ uint16_t *eob_ptr, const int16_t *scan,
int *idx_arr) {
int i, rc, eob;
int zbins[2], nzbins[2], zbin;
@@ -134,8 +135,8 @@ static void quantize_sparse(int16_t *coeff_ptr, int n_coeffs, int skip_block,
if (x >= zbin) {
x += (round_ptr[rc != 0]);
- y = ((int)(((int)(x * quant_ptr[rc != 0]) >> 16) + x))
- >> quant_shift_ptr[rc != 0]; // quantize (x)
+ y = (((int)(((int)(x * quant_ptr[rc != 0]) >> 16) + x)) *
+ quant_shift_ptr[rc != 0]) >> 16; // quantize (x)
x = (y ^ sz) - sz; // get the sign back
qcoeff_ptr[rc] = x; // write to destination
@@ -153,21 +154,25 @@ static void quantize_sparse(int16_t *coeff_ptr, int n_coeffs, int skip_block,
void vp9_quantize(MACROBLOCK *mb, int plane, int block, int n_coeffs,
TX_TYPE tx_type) {
MACROBLOCKD *const xd = &mb->e_mbd;
- const int *scan;
+ const int16_t *scan, *iscan;
// These contexts may be available in the caller
switch (n_coeffs) {
case 4 * 4:
scan = get_scan_4x4(tx_type);
+ iscan = get_iscan_4x4(tx_type);
break;
case 8 * 8:
scan = get_scan_8x8(tx_type);
+ iscan = get_iscan_8x8(tx_type);
break;
case 16 * 16:
scan = get_scan_16x16(tx_type);
+ iscan = get_iscan_16x16(tx_type);
break;
default:
scan = vp9_default_scan_32x32;
+ iscan = vp9_default_iscan_32x32;
break;
}
@@ -190,18 +195,18 @@ void vp9_quantize(MACROBLOCK *mb, int plane, int block, int n_coeffs,
scan, idx_arr);
}
else {
- quantize(BLOCK_OFFSET(mb->plane[plane].coeff, block, 16),
- n_coeffs, mb->skip_block,
- mb->plane[plane].zbin,
- mb->plane[plane].round,
- mb->plane[plane].quant,
- mb->plane[plane].quant_shift,
- BLOCK_OFFSET(xd->plane[plane].qcoeff, block, 16),
- BLOCK_OFFSET(xd->plane[plane].dqcoeff, block, 16),
- xd->plane[plane].dequant,
- mb->plane[plane].zbin_extra,
- &xd->plane[plane].eobs[block],
- scan);
+ vp9_quantize_b(BLOCK_OFFSET(mb->plane[plane].coeff, block, 16),
+ n_coeffs, mb->skip_block,
+ mb->plane[plane].zbin,
+ mb->plane[plane].round,
+ mb->plane[plane].quant,
+ mb->plane[plane].quant_shift,
+ BLOCK_OFFSET(xd->plane[plane].qcoeff, block, 16),
+ BLOCK_OFFSET(xd->plane[plane].dqcoeff, block, 16),
+ xd->plane[plane].dequant,
+ mb->plane[plane].zbin_extra,
+ &xd->plane[plane].eobs[block],
+ scan, iscan);
}
}
@@ -209,9 +214,10 @@ void vp9_regular_quantize_b_4x4(MACROBLOCK *mb, int b_idx, TX_TYPE tx_type,
int y_blocks) {
MACROBLOCKD *const xd = &mb->e_mbd;
const struct plane_block_idx pb_idx = plane_block_idx(y_blocks, b_idx);
- const int *pt_scan = get_scan_4x4(tx_type);
+ const int16_t *scan = get_scan_4x4(tx_type);
+ const int16_t *iscan = get_iscan_4x4(tx_type);
- quantize(BLOCK_OFFSET(mb->plane[pb_idx.plane].coeff, pb_idx.block, 16),
+ vp9_quantize_b(BLOCK_OFFSET(mb->plane[pb_idx.plane].coeff, pb_idx.block, 16),
16, mb->skip_block,
mb->plane[pb_idx.plane].zbin,
mb->plane[pb_idx.plane].round,
@@ -222,10 +228,10 @@ void vp9_regular_quantize_b_4x4(MACROBLOCK *mb, int b_idx, TX_TYPE tx_type,
xd->plane[pb_idx.plane].dequant,
mb->plane[pb_idx.plane].zbin_extra,
&xd->plane[pb_idx.plane].eobs[pb_idx.block],
- pt_scan);
+ scan, iscan);
}
-static void invert_quant(int16_t *quant, uint8_t *shift, int d) {
+static void invert_quant(int16_t *quant, int16_t *shift, int d) {
unsigned t;
int l;
t = d;
@@ -233,7 +239,7 @@ static void invert_quant(int16_t *quant, uint8_t *shift, int d) {
t >>= 1;
t = 1 + (1 << (16 + l)) / d;
*quant = (int16_t)(t - (1 << 16));
- *shift = l;
+ *shift = 1 << (16 - l);
}
void vp9_init_quantizer(VP9_COMP *cpi) {
@@ -252,6 +258,7 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
qzbin_factor = 64;
qrounding_factor = 64;
}
+
// dc values
quant_val = vp9_dc_quant(q, cpi->common.y_dc_delta_q);
invert_quant(cpi->y_quant[q] + 0, cpi->y_quant_shift[q] + 0, quant_val);
@@ -274,32 +281,46 @@ void vp9_init_quantizer(VP9_COMP *cpi) {
#endif
quant_val = vp9_ac_quant(q, 0);
+ invert_quant(cpi->y_quant[q] + 1, cpi->y_quant_shift[q] + 1, quant_val);
+ cpi->y_zbin[q][1] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7);
+ cpi->y_round[q][1] = (qrounding_factor * quant_val) >> 7;
cpi->common.y_dequant[q][1] = quant_val;
+
quant_uv_val = vp9_ac_quant(q, cpi->common.uv_ac_delta_q);
+ invert_quant(cpi->uv_quant[q] + 1, cpi->uv_quant_shift[q] + 1,
+ quant_uv_val);
+ cpi->uv_zbin[q][1] = ROUND_POWER_OF_TWO(qzbin_factor * quant_uv_val, 7);
+ cpi->uv_round[q][1] = (qrounding_factor * quant_uv_val) >> 7;
cpi->common.uv_dequant[q][1] = quant_uv_val;
+
#if CONFIG_ALPHA
quant_alpha_val = vp9_ac_quant(q, cpi->common.a_ac_delta_q);
+ invert_quant(cpi->a_quant[q] + 1, cpi->a_quant_shift[q] + 1,
+ quant_alpha_val);
+ cpi->a_zbin[q][1] = ROUND_POWER_OF_TWO(qzbin_factor * quant_alpha_val, 7);
+ cpi->a_round[q][1] = (qrounding_factor * quant_alpha_val) >> 7;
cpi->common.a_dequant[q][1] = quant_alpha_val;
#endif
- // all the 4x4 ac values =;
- for (i = 1; i < 16; i++) {
- int rc = vp9_default_scan_4x4[i];
- invert_quant(cpi->y_quant[q] + rc, cpi->y_quant_shift[q] + rc, quant_val);
- cpi->y_zbin[q][rc] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7);
- cpi->y_round[q][rc] = (qrounding_factor * quant_val) >> 7;
+ for (i = 2; i < 8; i++) {
+ cpi->y_quant[q][i] = cpi->y_quant[q][1];
+ cpi->y_quant_shift[q][i] = cpi->y_quant_shift[q][1];
+ cpi->y_zbin[q][i] = cpi->y_zbin[q][1];
+ cpi->y_round[q][i] = cpi->y_round[q][1];
+ cpi->common.y_dequant[q][i] = cpi->common.y_dequant[q][1];
- invert_quant(cpi->uv_quant[q] + rc, cpi->uv_quant_shift[q] + rc,
- quant_uv_val);
- cpi->uv_zbin[q][rc] = ROUND_POWER_OF_TWO(qzbin_factor * quant_uv_val, 7);
- cpi->uv_round[q][rc] = (qrounding_factor * quant_uv_val) >> 7;
+ cpi->uv_quant[q][i] = cpi->uv_quant[q][1];
+ cpi->uv_quant_shift[q][i] = cpi->uv_quant_shift[q][1];
+ cpi->uv_zbin[q][i] = cpi->uv_zbin[q][1];
+ cpi->uv_round[q][i] = cpi->uv_round[q][1];
+ cpi->common.uv_dequant[q][i] = cpi->common.uv_dequant[q][1];
#if CONFIG_ALPHA
- invert_quant(cpi->a_quant[q] + rc, cpi->a_quant_shift[q] + rc,
- quant_alpha_val);
- cpi->a_zbin[q][rc] =
- ROUND_POWER_OF_TWO(qzbin_factor * quant_alpha_val, 7);
- cpi->a_round[q][rc] = (qrounding_factor * quant_alpha_val) >> 7;
+ cpi->a_quant[q][i] = cpi->a_quant[q][1];
+ cpi->a_quant_shift[q][i] = cpi->a_quant_shift[q][1];
+ cpi->a_zbin[q][i] = cpi->a_zbin[q][1];
+ cpi->a_round[q][i] = cpi->a_round[q][1];
+ cpi->common.a_dequant[q][i] = cpi->common.a_dequant[q][1];
#endif
}
}
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index 5b4b7522b..0cf413011 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -305,7 +305,7 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb,
int pt;
int c = 0;
int cost = 0, pad;
- const int *scan, *nb;
+ const int16_t *scan, *nb;
const int eob = xd->plane[plane].eobs[block];
const int16_t *qcoeff_ptr = BLOCK_OFFSET(xd->plane[plane].qcoeff, block, 16);
const int ref = mbmi->ref_frame[0] != INTRA_FRAME;
diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c
index abf05c254..91c2a14d1 100644
--- a/vp9/encoder/vp9_tokenize.c
+++ b/vp9/encoder/vp9_tokenize.c
@@ -90,8 +90,6 @@ static void fill_value_tokens() {
vp9_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE;
}
-extern const int *vp9_get_coef_neighbors_handle(const int *scan, int *pad);
-
struct tokenize_b_args {
VP9_COMP *cpi;
MACROBLOCKD *xd;
@@ -127,7 +125,7 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
ENTROPY_CONTEXT *L = xd->plane[plane].left_context + loff;
int seg_eob, default_eob, pad;
const int segment_id = mbmi->segment_id;
- const int *scan, *nb;
+ const int16_t *scan, *nb;
vp9_coeff_count *counts;
vp9_coeff_probs_model *coef_probs;
const int ref = mbmi->ref_frame[0] != INTRA_FRAME;
diff --git a/vp9/encoder/x86/vp9_quantize_ssse3.asm b/vp9/encoder/x86/vp9_quantize_ssse3.asm
new file mode 100644
index 000000000..665bafacb
--- /dev/null
+++ b/vp9/encoder/x86/vp9_quantize_ssse3.asm
@@ -0,0 +1,165 @@
+;
+; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
+;
+; Use of this source code is governed by a BSD-style license
+; that can be found in the LICENSE file in the root of the source
+; tree. An additional intellectual property rights grant can be found
+; in the file PATENTS. All contributing project authors may
+; be found in the AUTHORS file in the root of the source tree.
+;
+
+%include "third_party/x86inc/x86inc.asm"
+
+SECTION_RODATA
+pw_1: times 8 dw 1
+
+SECTION .text
+
+INIT_XMM ssse3
+cglobal quantize_b, 0, 6, 15, coeff, ncoeff, skip, zbin, round, quant, \
+ shift, qcoeff, dqcoeff, dequant, zbin_oq, \
+ eob, scan, iscan
+ cmp dword skipm, 0
+ jne .blank
+
+ ; actual quantize loop - setup pointers, rounders, etc.
+ movifnidn coeffq, coeffmp
+ movifnidn ncoeffq, ncoeffmp
+ mov r2, dequantmp
+ movifnidn zbinq, zbinmp
+ movifnidn roundq, roundmp
+ movifnidn quantq, quantmp
+ movd m4, dword zbin_oqm ; m4 = zbin_oq
+ mova m0, [zbinq] ; m0 = zbin
+ punpcklwd m4, m4
+ mova m1, [roundq] ; m1 = round
+ pshufd m4, m4, 0
+ mova m2, [quantq] ; m2 = quant
+ paddw m0, m4 ; m0 = zbin + zbin_oq
+ mova m3, [r2q] ; m3 = dequant
+ psubw m0, [pw_1]
+ mov r2, shiftmp
+ mov r3, qcoeffmp
+ mova m4, [r2] ; m4 = shift
+ mov r4, dqcoeffmp
+ mov r5, iscanmp
+ mov r2, eobmp
+ pxor m5, m5 ; m5 = dedicated zero
+ DEFINE_ARGS coeff, ncoeff, eob, qcoeff, dqcoeff, iscan
+ lea coeffq, [ coeffq+ncoeffq*2]
+ lea iscanq, [ iscanq+ncoeffq*2]
+ lea qcoeffq, [ qcoeffq+ncoeffq*2]
+ lea dqcoeffq, [dqcoeffq+ncoeffq*2]
+ neg ncoeffq
+
+ ; get DC and first 15 AC coeffs
+ mova m9, [ coeffq+ncoeffq*2+ 0] ; m9 = c[i]
+ mova m10, [ coeffq+ncoeffq*2+16] ; m10 = c[i]
+ pabsw m6, m9 ; m6 = abs(m9)
+ pabsw m11, m10 ; m11 = abs(m10)
+ pcmpgtw m7, m6, m0 ; m7 = c[i] >= zbin
+ punpckhqdq m0, m0
+ pcmpgtw m12, m11, m0 ; m12 = c[i] >= zbin
+ paddw m6, m1 ; m6 += round
+ punpckhqdq m1, m1
+ paddw m11, m1 ; m11 += round
+ pmulhw m8, m6, m2 ; m8 = m6*q>>16
+ punpckhqdq m2, m2
+ pmulhw m13, m11, m2 ; m13 = m11*q>>16
+ paddw m8, m6 ; m8 += m6
+ paddw m13, m11 ; m13 += m11
+ pmulhw m8, m4 ; m8 = m8*qsh>>16
+ punpckhqdq m4, m4
+ pmulhw m13, m4 ; m13 = m13*qsh>>16
+ psignw m8, m9 ; m8 = reinsert sign
+ psignw m13, m10 ; m13 = reinsert sign
+ pand m8, m7
+ pand m13, m12
+ mova [qcoeffq+ncoeffq*2+ 0], m8
+ mova [qcoeffq+ncoeffq*2+16], m13
+ pmullw m8, m3 ; dqc[i] = qc[i] * q
+ punpckhqdq m3, m3
+ pmullw m13, m3 ; dqc[i] = qc[i] * q
+ mova [dqcoeffq+ncoeffq*2+ 0], m8
+ mova [dqcoeffq+ncoeffq*2+16], m13
+ pcmpeqw m8, m5 ; m8 = c[i] == 0
+ pcmpeqw m13, m5 ; m13 = c[i] == 0
+ mova m6, [ iscanq+ncoeffq*2+ 0] ; m6 = scan[i]
+ mova m11, [ iscanq+ncoeffq*2+16] ; m11 = scan[i]
+ psubw m6, m7 ; m6 = scan[i] + 1
+ psubw m11, m12 ; m11 = scan[i] + 1
+ pandn m8, m6 ; m8 = max(eob)
+ pandn m13, m11 ; m13 = max(eob)
+ pmaxsw m8, m13
+ add ncoeffq, mmsize
+ jz .accumulate_eob
+
+.ac_only_loop:
+ mova m9, [ coeffq+ncoeffq*2+ 0] ; m9 = c[i]
+ mova m10, [ coeffq+ncoeffq*2+16] ; m10 = c[i]
+ pabsw m6, m9 ; m6 = abs(m9)
+ pabsw m11, m10 ; m11 = abs(m10)
+ pcmpgtw m7, m6, m0 ; m7 = c[i] >= zbin
+ pcmpgtw m12, m11, m0 ; m12 = c[i] >= zbin
+ paddw m6, m1 ; m6 += round
+ paddw m11, m1 ; m11 += round
+ pmulhw m14, m6, m2 ; m14 = m6*q>>16
+ pmulhw m13, m11, m2 ; m13 = m11*q>>16
+ paddw m14, m6 ; m14 += m6
+ paddw m13, m11 ; m13 += m11
+ pmulhw m14, m4 ; m14 = m14*qsh>>16
+ pmulhw m13, m4 ; m13 = m13*qsh>>16
+ psignw m14, m9 ; m14 = reinsert sign
+ psignw m13, m10 ; m13 = reinsert sign
+ pand m14, m7
+ pand m13, m12
+ mova [qcoeffq+ncoeffq*2+ 0], m14
+ mova [qcoeffq+ncoeffq*2+16], m13
+ pmullw m14, m3 ; dqc[i] = qc[i] * q
+ pmullw m13, m3 ; dqc[i] = qc[i] * q
+ mova [dqcoeffq+ncoeffq*2+ 0], m14
+ mova [dqcoeffq+ncoeffq*2+16], m13
+ pcmpeqw m14, m5 ; m14 = c[i] == 0
+ pcmpeqw m13, m5 ; m13 = c[i] == 0
+ mova m6, [ iscanq+ncoeffq*2+ 0] ; m6 = scan[i]
+ mova m11, [ iscanq+ncoeffq*2+16] ; m11 = scan[i]
+ psubw m6, m7 ; m6 = scan[i] + 1
+ psubw m11, m12 ; m11 = scan[i] + 1
+ pandn m14, m6 ; m14 = max(eob)
+ pandn m13, m11 ; m13 = max(eob)
+ pmaxsw m8, m14
+ pmaxsw m8, m13
+ add ncoeffq, mmsize
+ jl .ac_only_loop
+
+.accumulate_eob:
+ ; horizontally accumulate/max eobs and write into [eob] memory pointer
+ pshufd m7, m8, 0xe
+ pmaxsw m8, m7
+ pshuflw m7, m8, 0xe
+ pmaxsw m8, m7
+ pshuflw m7, m8, 0x1
+ pmaxsw m8, m7
+ pextrw [eobq], m8, 0
+ RET
+
+ ; skip-block, i.e. just write all zeroes
+.blank:
+ mov r0, dqcoeffmp
+ movifnidn ncoeffq, ncoeffmp
+ mov r2, qcoeffmp
+ mov r3, eobmp
+ DEFINE_ARGS dqcoeff, ncoeff, qcoeff, eob
+ lea dqcoeffq, [dqcoeffq+ncoeffq*2]
+ lea qcoeffq, [ qcoeffq+ncoeffq*2]
+ neg ncoeffq
+ pxor m7, m7
+.blank_loop:
+ mova [dqcoeffq+ncoeffq*2+ 0], m7
+ mova [dqcoeffq+ncoeffq*2+16], m7
+ mova [qcoeffq+ncoeffq*2+ 0], m7
+ mova [qcoeffq+ncoeffq*2+16], m7
+ add ncoeffq, mmsize
+ jl .blank_loop
+ mov word [eobq], 0
+ RET