/src/libvpx/vp8/encoder/x86/vp8_quantize_ssse3.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
3 | | * |
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. |
9 | | */ |
10 | | |
11 | | #include <tmmintrin.h> /* SSSE3 */ |
12 | | |
13 | | #include "./vp8_rtcd.h" |
14 | | #include "vp8/encoder/block.h" |
15 | | #include "vpx_ports/bitops.h" /* get_msb */ |
16 | | |
17 | 261M | void vp8_fast_quantize_b_ssse3(BLOCK *b, BLOCKD *d) { |
18 | 261M | int eob, mask; |
19 | | |
20 | 261M | __m128i z0 = _mm_load_si128((__m128i *)(b->coeff)); |
21 | 261M | __m128i z1 = _mm_load_si128((__m128i *)(b->coeff + 8)); |
22 | 261M | __m128i round0 = _mm_load_si128((__m128i *)(b->round)); |
23 | 261M | __m128i round1 = _mm_load_si128((__m128i *)(b->round + 8)); |
24 | 261M | __m128i quant_fast0 = _mm_load_si128((__m128i *)(b->quant_fast)); |
25 | 261M | __m128i quant_fast1 = _mm_load_si128((__m128i *)(b->quant_fast + 8)); |
26 | 261M | __m128i dequant0 = _mm_load_si128((__m128i *)(d->dequant)); |
27 | 261M | __m128i dequant1 = _mm_load_si128((__m128i *)(d->dequant + 8)); |
28 | | |
29 | 261M | __m128i sz0, sz1, x, x0, x1, y0, y1, zeros, abs0, abs1; |
30 | | |
31 | 261M | DECLARE_ALIGNED(16, const uint8_t, |
32 | 261M | pshufb_zig_zag_mask[16]) = { 0, 1, 4, 8, 5, 2, 3, 6, |
33 | 261M | 9, 12, 13, 10, 7, 11, 14, 15 }; |
34 | 261M | __m128i zig_zag = _mm_load_si128((const __m128i *)pshufb_zig_zag_mask); |
35 | | |
36 | | /* sign of z: z >> 15 */ |
37 | 261M | sz0 = _mm_srai_epi16(z0, 15); |
38 | 261M | sz1 = _mm_srai_epi16(z1, 15); |
39 | | |
40 | | /* x = abs(z) */ |
41 | 261M | x0 = _mm_abs_epi16(z0); |
42 | 261M | x1 = _mm_abs_epi16(z1); |
43 | | |
44 | | /* x += round */ |
45 | 261M | x0 = _mm_add_epi16(x0, round0); |
46 | 261M | x1 = _mm_add_epi16(x1, round1); |
47 | | |
48 | | /* y = (x * quant) >> 16 */ |
49 | 261M | y0 = _mm_mulhi_epi16(x0, quant_fast0); |
50 | 261M | y1 = _mm_mulhi_epi16(x1, quant_fast1); |
51 | | |
52 | | /* ASM saves Y for EOB */ |
53 | | /* I think we can ignore that because adding the sign doesn't change anything |
54 | | * and multiplying 0 by dequant is OK as well */ |
55 | 261M | abs0 = y0; |
56 | 261M | abs1 = y1; |
57 | | |
58 | | /* Restore the sign bit. */ |
59 | 261M | y0 = _mm_xor_si128(y0, sz0); |
60 | 261M | y1 = _mm_xor_si128(y1, sz1); |
61 | 261M | x0 = _mm_sub_epi16(y0, sz0); |
62 | 261M | x1 = _mm_sub_epi16(y1, sz1); |
63 | | |
64 | | /* qcoeff = x */ |
65 | 261M | _mm_store_si128((__m128i *)(d->qcoeff), x0); |
66 | 261M | _mm_store_si128((__m128i *)(d->qcoeff + 8), x1); |
67 | | |
68 | | /* x * dequant */ |
69 | 261M | x0 = _mm_mullo_epi16(x0, dequant0); |
70 | 261M | x1 = _mm_mullo_epi16(x1, dequant1); |
71 | | |
72 | | /* dqcoeff = x * dequant */ |
73 | 261M | _mm_store_si128((__m128i *)(d->dqcoeff), x0); |
74 | 261M | _mm_store_si128((__m128i *)(d->dqcoeff + 8), x1); |
75 | | |
76 | 261M | zeros = _mm_setzero_si128(); |
77 | | |
78 | 261M | x0 = _mm_cmpgt_epi16(abs0, zeros); |
79 | 261M | x1 = _mm_cmpgt_epi16(abs1, zeros); |
80 | | |
81 | 261M | x = _mm_packs_epi16(x0, x1); |
82 | | |
83 | 261M | x = _mm_shuffle_epi8(x, zig_zag); |
84 | | |
85 | 261M | mask = _mm_movemask_epi8(x); |
86 | | |
87 | | /* x2 is needed to increase the result from non-zero masks by 1, |
88 | | * +1 is needed to mask undefined behavior for a null argument, |
89 | | * the result of get_msb(1) is 0 */ |
90 | 261M | eob = get_msb(mask * 2 + 1); |
91 | | |
92 | 261M | *d->eob = eob; |
93 | 261M | } |