1 /*
2 * Copyright (c) 2018, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #include <tmmintrin.h>
13
14 #include "config/av1_rtcd.h"
15
16 #include "aom/aom_integer.h"
17 #include "aom_dsp/blend.h"
18 #include "aom_dsp/x86/synonyms.h"
19 #include "av1/common/blockd.h"
20
av1_build_compound_diffwtd_mask_highbd_ssse3(uint8_t * mask,DIFFWTD_MASK_TYPE mask_type,const uint8_t * src0,int src0_stride,const uint8_t * src1,int src1_stride,int h,int w,int bd)21 void av1_build_compound_diffwtd_mask_highbd_ssse3(
22 uint8_t *mask, DIFFWTD_MASK_TYPE mask_type, const uint8_t *src0,
23 int src0_stride, const uint8_t *src1, int src1_stride, int h, int w,
24 int bd) {
25 if (w < 8) {
26 av1_build_compound_diffwtd_mask_highbd_c(mask, mask_type, src0, src0_stride,
27 src1, src1_stride, h, w, bd);
28 } else {
29 assert(bd >= 8);
30 assert((w % 8) == 0);
31 assert(mask_type == DIFFWTD_38 || mask_type == DIFFWTD_38_INV);
32 const __m128i x0 = _mm_setzero_si128();
33 const __m128i xAOM_BLEND_A64_MAX_ALPHA =
34 _mm_set1_epi16(AOM_BLEND_A64_MAX_ALPHA);
35 const int mask_base = 38;
36 const __m128i xmask_base = _mm_set1_epi16(mask_base);
37 const uint16_t *ssrc0 = CONVERT_TO_SHORTPTR(src0);
38 const uint16_t *ssrc1 = CONVERT_TO_SHORTPTR(src1);
39 if (bd == 8) {
40 if (mask_type == DIFFWTD_38_INV) {
41 for (int i = 0; i < h; ++i) {
42 for (int j = 0; j < w; j += 8) {
43 __m128i s0 = _mm_loadu_si128((const __m128i *)&ssrc0[j]);
44 __m128i s1 = _mm_loadu_si128((const __m128i *)&ssrc1[j]);
45 __m128i diff = _mm_srai_epi16(_mm_abs_epi16(_mm_sub_epi16(s0, s1)),
46 DIFF_FACTOR_LOG2);
47 __m128i m = _mm_min_epi16(
48 _mm_max_epi16(x0, _mm_add_epi16(diff, xmask_base)),
49 xAOM_BLEND_A64_MAX_ALPHA);
50 m = _mm_sub_epi16(xAOM_BLEND_A64_MAX_ALPHA, m);
51 m = _mm_packus_epi16(m, m);
52 _mm_storel_epi64((__m128i *)&mask[j], m);
53 }
54 ssrc0 += src0_stride;
55 ssrc1 += src1_stride;
56 mask += w;
57 }
58 } else {
59 for (int i = 0; i < h; ++i) {
60 for (int j = 0; j < w; j += 8) {
61 __m128i s0 = _mm_loadu_si128((const __m128i *)&ssrc0[j]);
62 __m128i s1 = _mm_loadu_si128((const __m128i *)&ssrc1[j]);
63 __m128i diff = _mm_srai_epi16(_mm_abs_epi16(_mm_sub_epi16(s0, s1)),
64 DIFF_FACTOR_LOG2);
65 __m128i m = _mm_min_epi16(
66 _mm_max_epi16(x0, _mm_add_epi16(diff, xmask_base)),
67 xAOM_BLEND_A64_MAX_ALPHA);
68 m = _mm_packus_epi16(m, m);
69 _mm_storel_epi64((__m128i *)&mask[j], m);
70 }
71 ssrc0 += src0_stride;
72 ssrc1 += src1_stride;
73 mask += w;
74 }
75 }
76 } else {
77 const __m128i xshift = xx_set1_64_from_32i(bd - 8 + DIFF_FACTOR_LOG2);
78 if (mask_type == DIFFWTD_38_INV) {
79 for (int i = 0; i < h; ++i) {
80 for (int j = 0; j < w; j += 8) {
81 __m128i s0 = _mm_loadu_si128((const __m128i *)&ssrc0[j]);
82 __m128i s1 = _mm_loadu_si128((const __m128i *)&ssrc1[j]);
83 __m128i diff =
84 _mm_sra_epi16(_mm_abs_epi16(_mm_sub_epi16(s0, s1)), xshift);
85 __m128i m = _mm_min_epi16(
86 _mm_max_epi16(x0, _mm_add_epi16(diff, xmask_base)),
87 xAOM_BLEND_A64_MAX_ALPHA);
88 m = _mm_sub_epi16(xAOM_BLEND_A64_MAX_ALPHA, m);
89 m = _mm_packus_epi16(m, m);
90 _mm_storel_epi64((__m128i *)&mask[j], m);
91 }
92 ssrc0 += src0_stride;
93 ssrc1 += src1_stride;
94 mask += w;
95 }
96 } else {
97 for (int i = 0; i < h; ++i) {
98 for (int j = 0; j < w; j += 8) {
99 __m128i s0 = _mm_loadu_si128((const __m128i *)&ssrc0[j]);
100 __m128i s1 = _mm_loadu_si128((const __m128i *)&ssrc1[j]);
101 __m128i diff =
102 _mm_sra_epi16(_mm_abs_epi16(_mm_sub_epi16(s0, s1)), xshift);
103 __m128i m = _mm_min_epi16(
104 _mm_max_epi16(x0, _mm_add_epi16(diff, xmask_base)),
105 xAOM_BLEND_A64_MAX_ALPHA);
106 m = _mm_packus_epi16(m, m);
107 _mm_storel_epi64((__m128i *)&mask[j], m);
108 }
109 ssrc0 += src0_stride;
110 ssrc1 += src1_stride;
111 mask += w;
112 }
113 }
114 }
115 }
116 }
117