Commit a50f9f57 authored by Cheng Chen's avatar Cheng Chen
Browse files

JNT_COMP: highbd SIMD implemenation

Add av1/common/x86/highbd_convolve_2d_sse4.c.
Specifically, function av1_highbd_jnt_convolve_2d

Change-Id: I1bfe0431c793bd5f78c30bc763aa7691e5d74b04
parent 15a18e3d
......@@ -319,6 +319,12 @@ if (CONFIG_HIGHBITDEPTH)
set(AOM_AV1_COMMON_INTRIN_SSSE3
${AOM_AV1_COMMON_INTRIN_SSSE3}
"${AOM_ROOT}/av1/common/x86/highbd_convolve_2d_ssse3.c")
if (CONFIG_JNT_COMP)
set(AOM_AV1_COMMON_INTRIN_SSE4_1
${AOM_AV1_COMMON_INTRIN_SSE4_1}
"${AOM_ROOT}/av1/common/x86/highbd_convolve_2d_sse4.c")
endif ()
endif ()
if (CONFIG_JNT_COMP)
......
......@@ -154,11 +154,16 @@ endif
AV1_COMMON_SRCS-$(HAVE_SSE2) += common/x86/convolve_sse2.c
AV1_COMMON_SRCS-$(HAVE_SSE2) += common/x86/convolve_2d_sse2.c
ifeq ($(CONFIG_JNT_COMP), yes)
AV1_COMMON_SRCS-$(HAVE_SSE4_1) += common/x86/convolve_2d_sse4.c
endif
AV1_COMMON_SRCS-$(HAVE_AVX2) += common/x86/convolve_2d_avx2.c
ifeq ($(CONFIG_HIGHBITDEPTH),yes)
AV1_COMMON_SRCS-$(HAVE_SSSE3) += common/x86/highbd_convolve_2d_ssse3.c
AV1_COMMON_SRCS-$(HAVE_AVX2) += common/x86/highbd_convolve_2d_avx2.c
ifeq ($(CONFIG_JNT_COMP), yes)
AV1_COMMON_SRCS-$(HAVE_SSE4_1) += common/x86/highbd_convolve_2d_sse4.c
endif
endif
ifeq ($(CONFIG_LV_MAP),yes)
......
......@@ -616,6 +616,11 @@ if (aom_config("CONFIG_HIGHBITDEPTH") eq "yes") {
add_proto qw/void av1_highbd_convolve_2d_scale/, "const uint16_t *src, int src_stride, CONV_BUF_TYPE *dst, int dst_stride, int w, int h, InterpFilterParams *filter_params_x, InterpFilterParams *filter_params_y, const int subpel_x_q4, const int x_step_qn, const int subpel_y_q4, const int y_step_qn, ConvolveParams *conv_params, int bd";
specialize qw/av1_highbd_convolve_2d_scale sse4_1/;
if (aom_config("CONFIG_JNT_COMP") eq "yes") {
add_proto qw/void av1_highbd_jnt_convolve_2d/, "const uint16_t *src, int src_stride, CONV_BUF_TYPE *dst, int dst_stride, int w, int h, InterpFilterParams *filter_params_x, InterpFilterParams *filter_params_y, const int subpel_x_q4, const int subpel_y_q4, ConvolveParams *conv_params, int bd";
specialize qw/av1_highbd_jnt_convolve_2d sse4_1/;
}
}
# INTRA_EDGE functions
......
......@@ -884,6 +884,72 @@ void av1_highbd_convolve_2d_c(const uint16_t *src, int src_stride,
}
}
#if CONFIG_JNT_COMP
void av1_highbd_jnt_convolve_2d_c(const uint16_t *src, int src_stride,
CONV_BUF_TYPE *dst, int dst_stride, int w,
int h, InterpFilterParams *filter_params_x,
InterpFilterParams *filter_params_y,
const int subpel_x_q4, const int subpel_y_q4,
ConvolveParams *conv_params, int bd) {
int x, y, k;
int32_t im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE];
int im_h = h + filter_params_y->taps - 1;
int im_stride = w;
const int fo_vert = filter_params_y->taps / 2 - 1;
const int fo_horiz = filter_params_x->taps / 2 - 1;
// horizontal filter
const uint16_t *src_horiz = src - fo_vert * src_stride;
const int16_t *x_filter = av1_get_interp_filter_subpel_kernel(
*filter_params_x, subpel_x_q4 & SUBPEL_MASK);
for (y = 0; y < im_h; ++y) {
for (x = 0; x < w; ++x) {
int32_t sum = (1 << (bd + FILTER_BITS - 1));
for (k = 0; k < filter_params_x->taps; ++k) {
sum += x_filter[k] * src_horiz[y * src_stride + x - fo_horiz + k];
}
assert(0 <= sum && sum < (1 << (bd + FILTER_BITS + 1)));
(void)bd;
im_block[y * im_stride + x] =
ROUND_POWER_OF_TWO(sum, conv_params->round_0);
}
}
// vertical filter
int32_t *src_vert = im_block + fo_vert * im_stride;
const int offset_bits = bd + 2 * FILTER_BITS - conv_params->round_0;
const int16_t *y_filter = av1_get_interp_filter_subpel_kernel(
*filter_params_y, subpel_y_q4 & SUBPEL_MASK);
for (y = 0; y < h; ++y) {
for (x = 0; x < w; ++x) {
CONV_BUF_TYPE sum = 1 << offset_bits;
for (k = 0; k < filter_params_y->taps; ++k) {
sum += y_filter[k] * src_vert[(y - fo_vert + k) * im_stride + x];
}
assert(0 <= sum && sum < (1 << (offset_bits + 2)));
CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1) -
((1 << (offset_bits - conv_params->round_1)) +
(1 << (offset_bits - conv_params->round_1 - 1)));
if (conv_params->use_jnt_comp_avg) {
if (conv_params->do_average) {
dst[y * dst_stride + x] += res * conv_params->bck_offset;
dst[y * dst_stride + x] = ROUND_POWER_OF_TWO(dst[y * dst_stride + x],
DIST_PRECISION_BITS - 1);
} else {
dst[y * dst_stride + x] = res * conv_params->fwd_offset;
}
} else {
if (conv_params->do_average)
dst[y * dst_stride + x] += res;
else
dst[y * dst_stride + x] = res;
}
}
}
}
#endif // CONFIG_JNT_COMP
void av1_highbd_convolve_2d_scale_c(const uint16_t *src, int src_stride,
CONV_BUF_TYPE *dst, int dst_stride, int w,
int h, InterpFilterParams *filter_params_x,
......@@ -938,10 +1004,28 @@ void av1_highbd_convolve_2d_scale_c(const uint16_t *src, int src_stride,
CONV_BUF_TYPE res = ROUND_POWER_OF_TWO(sum, conv_params->round_1) -
((1 << (offset_bits - conv_params->round_1)) +
(1 << (offset_bits - conv_params->round_1 - 1)));
#if CONFIG_JNT_COMP
if (conv_params->use_jnt_comp_avg) {
if (conv_params->do_average) {
dst[y * dst_stride + x] += res * conv_params->bck_offset;
dst[y * dst_stride + x] = ROUND_POWER_OF_TWO(dst[y * dst_stride + x],
DIST_PRECISION_BITS - 1);
} else {
dst[y * dst_stride + x] = res * conv_params->fwd_offset;
}
} else {
if (conv_params->do_average)
dst[y * dst_stride + x] += res;
else
dst[y * dst_stride + x] = res;
}
#else
if (conv_params->do_average)
dst[y * dst_stride + x] += res;
else
dst[y * dst_stride + x] = res;
#endif // CONFIG_JNT_COMP
}
src_vert++;
}
......@@ -982,7 +1066,19 @@ void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride,
transpose_int32(tr_dst, tr_dst_stride, conv_params->dst,
conv_params->dst_stride, w, h);
// horizontal and vertical parameters are swapped because of the transpose
// horizontal and vertical parameters are swapped because of the transpose
#if CONFIG_JNT_COMP
if (scaled)
av1_highbd_convolve_2d_scale(
tr_src + fo_horiz * tr_src_stride + fo_vert, tr_src_stride, tr_dst,
tr_dst_stride, h, w, &filter_params_y, &filter_params_x, subpel_y_q4,
y_step_q4, subpel_x_q4, x_step_q4, conv_params, bd);
else
av1_highbd_jnt_convolve_2d(tr_src + fo_horiz * tr_src_stride + fo_vert,
tr_src_stride, tr_dst, tr_dst_stride, h, w,
&filter_params_y, &filter_params_x,
subpel_y_q4, subpel_x_q4, conv_params, bd);
#else
if (scaled)
av1_highbd_convolve_2d_scale(
tr_src + fo_horiz * tr_src_stride + fo_vert, tr_src_stride, tr_dst,
......@@ -993,9 +1089,22 @@ void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride,
tr_src_stride, tr_dst, tr_dst_stride, h, w,
&filter_params_y, &filter_params_x, subpel_y_q4,
subpel_x_q4, conv_params, bd);
#endif // CONFIG_JNT_COMP
transpose_int32(conv_params->dst, conv_params->dst_stride, tr_dst,
tr_dst_stride, h, w);
} else {
#if CONFIG_JNT_COMP
if (scaled)
av1_highbd_convolve_2d_scale(
src, src_stride, conv_params->dst, conv_params->dst_stride, w, h,
&filter_params_x, &filter_params_y, subpel_x_q4, x_step_q4,
subpel_y_q4, y_step_q4, conv_params, bd);
else
av1_highbd_jnt_convolve_2d(src, src_stride, conv_params->dst,
conv_params->dst_stride, w, h,
&filter_params_x, &filter_params_y,
subpel_x_q4, subpel_y_q4, conv_params, bd);
#else
if (scaled)
av1_highbd_convolve_2d_scale(
src, src_stride, conv_params->dst, conv_params->dst_stride, w, h,
......@@ -1006,6 +1115,7 @@ void av1_highbd_convolve_2d_facade(const uint8_t *src8, int src_stride,
conv_params->dst_stride, w, h, &filter_params_x,
&filter_params_y, subpel_x_q4, subpel_y_q4,
conv_params, bd);
#endif // CONFIG_JNT_COMP
}
}
#endif // CONFIG_HIGHBITDEPTH
......
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include <tmmintrin.h>
#include <smmintrin.h>
#include <assert.h>
#include "./aom_dsp_rtcd.h"
#include "aom_dsp/aom_convolve.h"
#include "aom_dsp/aom_dsp_common.h"
#include "aom_dsp/aom_filter.h"
#include "av1/common/convolve.h"
#if CONFIG_JNT_COMP
void av1_highbd_jnt_convolve_2d_sse4_1(
const uint16_t *src, int src_stride, CONV_BUF_TYPE *dst, int dst_stride,
int w, int h, InterpFilterParams *filter_params_x,
InterpFilterParams *filter_params_y, const int subpel_x_q4,
const int subpel_y_q4, ConvolveParams *conv_params, int bd) {
DECLARE_ALIGNED(16, int16_t,
im_block[(MAX_SB_SIZE + MAX_FILTER_TAP - 1) * MAX_SB_SIZE]);
int im_h = h + filter_params_y->taps - 1;
int im_stride = MAX_SB_SIZE;
int i, j;
const int do_average = conv_params->do_average;
const int fo_vert = filter_params_y->taps / 2 - 1;
const int fo_horiz = filter_params_x->taps / 2 - 1;
const uint16_t *const src_ptr = src - fo_vert * src_stride - fo_horiz;
const int w0 = conv_params->fwd_offset;
const int w1 = conv_params->bck_offset;
const __m128i wt0 = _mm_set1_epi32(w0);
const __m128i wt1 = _mm_set1_epi32(w1);
const int jnt_round_const = 1 << (DIST_PRECISION_BITS - 2);
const __m128i jnt_r = _mm_set1_epi32(jnt_round_const);
// Check that, even with 12-bit input, the intermediate values will fit
// into an unsigned 15-bit intermediate array.
assert(conv_params->round_0 >= 5);
/* Horizontal filter */
{
const int16_t *x_filter = av1_get_interp_filter_subpel_kernel(
*filter_params_x, subpel_x_q4 & SUBPEL_MASK);
const __m128i coeffs_x = _mm_loadu_si128((__m128i *)x_filter);
// coeffs 0 1 0 1 2 3 2 3
const __m128i tmp_0 = _mm_unpacklo_epi32(coeffs_x, coeffs_x);
// coeffs 4 5 4 5 6 7 6 7
const __m128i tmp_1 = _mm_unpackhi_epi32(coeffs_x, coeffs_x);
// coeffs 0 1 0 1 0 1 0 1
const __m128i coeff_01 = _mm_unpacklo_epi64(tmp_0, tmp_0);
// coeffs 2 3 2 3 2 3 2 3
const __m128i coeff_23 = _mm_unpackhi_epi64(tmp_0, tmp_0);
// coeffs 4 5 4 5 4 5 4 5
const __m128i coeff_45 = _mm_unpacklo_epi64(tmp_1, tmp_1);
// coeffs 6 7 6 7 6 7 6 7
const __m128i coeff_67 = _mm_unpackhi_epi64(tmp_1, tmp_1);
const __m128i round_const = _mm_set1_epi32(
((1 << conv_params->round_0) >> 1) + (1 << (bd + FILTER_BITS - 1)));
const __m128i round_shift = _mm_cvtsi32_si128(conv_params->round_0);
for (i = 0; i < im_h; ++i) {
for (j = 0; j < w; j += 8) {
const __m128i data =
_mm_loadu_si128((__m128i *)&src_ptr[i * src_stride + j]);
const __m128i data2 =
_mm_loadu_si128((__m128i *)&src_ptr[i * src_stride + j + 8]);
// Filter even-index pixels
const __m128i res_0 = _mm_madd_epi16(data, coeff_01);
const __m128i res_2 =
_mm_madd_epi16(_mm_alignr_epi8(data2, data, 4), coeff_23);
const __m128i res_4 =
_mm_madd_epi16(_mm_alignr_epi8(data2, data, 8), coeff_45);
const __m128i res_6 =
_mm_madd_epi16(_mm_alignr_epi8(data2, data, 12), coeff_67);
__m128i res_even = _mm_add_epi32(_mm_add_epi32(res_0, res_4),
_mm_add_epi32(res_2, res_6));
res_even =
_mm_sra_epi32(_mm_add_epi32(res_even, round_const), round_shift);
// Filter odd-index pixels
const __m128i res_1 =
_mm_madd_epi16(_mm_alignr_epi8(data2, data, 2), coeff_01);
const __m128i res_3 =
_mm_madd_epi16(_mm_alignr_epi8(data2, data, 6), coeff_23);
const __m128i res_5 =
_mm_madd_epi16(_mm_alignr_epi8(data2, data, 10), coeff_45);
const __m128i res_7 =
_mm_madd_epi16(_mm_alignr_epi8(data2, data, 14), coeff_67);
__m128i res_odd = _mm_add_epi32(_mm_add_epi32(res_1, res_5),
_mm_add_epi32(res_3, res_7));
res_odd =
_mm_sra_epi32(_mm_add_epi32(res_odd, round_const), round_shift);
// Pack in the column order 0, 2, 4, 6, 1, 3, 5, 7
__m128i res = _mm_packs_epi32(res_even, res_odd);
_mm_storeu_si128((__m128i *)&im_block[i * im_stride + j], res);
}
}
}
/* Vertical filter */
{
const int16_t *y_filter = av1_get_interp_filter_subpel_kernel(
*filter_params_y, subpel_y_q4 & SUBPEL_MASK);
const __m128i coeffs_y = _mm_loadu_si128((__m128i *)y_filter);
// coeffs 0 1 0 1 2 3 2 3
const __m128i tmp_0 = _mm_unpacklo_epi32(coeffs_y, coeffs_y);
// coeffs 4 5 4 5 6 7 6 7
const __m128i tmp_1 = _mm_unpackhi_epi32(coeffs_y, coeffs_y);
// coeffs 0 1 0 1 0 1 0 1
const __m128i coeff_01 = _mm_unpacklo_epi64(tmp_0, tmp_0);
// coeffs 2 3 2 3 2 3 2 3
const __m128i coeff_23 = _mm_unpackhi_epi64(tmp_0, tmp_0);
// coeffs 4 5 4 5 4 5 4 5
const __m128i coeff_45 = _mm_unpacklo_epi64(tmp_1, tmp_1);
// coeffs 6 7 6 7 6 7 6 7
const __m128i coeff_67 = _mm_unpackhi_epi64(tmp_1, tmp_1);
const __m128i round_const = _mm_set1_epi32(
((1 << conv_params->round_1) >> 1) -
(1 << (bd + 2 * FILTER_BITS - conv_params->round_0 - 1)));
const __m128i round_shift = _mm_cvtsi32_si128(conv_params->round_1);
for (i = 0; i < h; ++i) {
for (j = 0; j < w; j += 8) {
// Filter even-index pixels
const int16_t *data = &im_block[i * im_stride + j];
const __m128i src_0 =
_mm_unpacklo_epi16(*(__m128i *)(data + 0 * im_stride),
*(__m128i *)(data + 1 * im_stride));
const __m128i src_2 =
_mm_unpacklo_epi16(*(__m128i *)(data + 2 * im_stride),
*(__m128i *)(data + 3 * im_stride));
const __m128i src_4 =
_mm_unpacklo_epi16(*(__m128i *)(data + 4 * im_stride),
*(__m128i *)(data + 5 * im_stride));
const __m128i src_6 =
_mm_unpacklo_epi16(*(__m128i *)(data + 6 * im_stride),
*(__m128i *)(data + 7 * im_stride));
const __m128i res_0 = _mm_madd_epi16(src_0, coeff_01);
const __m128i res_2 = _mm_madd_epi16(src_2, coeff_23);
const __m128i res_4 = _mm_madd_epi16(src_4, coeff_45);
const __m128i res_6 = _mm_madd_epi16(src_6, coeff_67);
const __m128i res_even = _mm_add_epi32(_mm_add_epi32(res_0, res_2),
_mm_add_epi32(res_4, res_6));
// Filter odd-index pixels
const __m128i src_1 =
_mm_unpackhi_epi16(*(__m128i *)(data + 0 * im_stride),
*(__m128i *)(data + 1 * im_stride));
const __m128i src_3 =
_mm_unpackhi_epi16(*(__m128i *)(data + 2 * im_stride),
*(__m128i *)(data + 3 * im_stride));
const __m128i src_5 =
_mm_unpackhi_epi16(*(__m128i *)(data + 4 * im_stride),
*(__m128i *)(data + 5 * im_stride));
const __m128i src_7 =
_mm_unpackhi_epi16(*(__m128i *)(data + 6 * im_stride),
*(__m128i *)(data + 7 * im_stride));
const __m128i res_1 = _mm_madd_epi16(src_1, coeff_01);
const __m128i res_3 = _mm_madd_epi16(src_3, coeff_23);
const __m128i res_5 = _mm_madd_epi16(src_5, coeff_45);
const __m128i res_7 = _mm_madd_epi16(src_7, coeff_67);
const __m128i res_odd = _mm_add_epi32(_mm_add_epi32(res_1, res_3),
_mm_add_epi32(res_5, res_7));
// Rearrange pixels back into the order 0 ... 7
const __m128i res_lo = _mm_unpacklo_epi32(res_even, res_odd);
const __m128i res_hi = _mm_unpackhi_epi32(res_even, res_odd);
const __m128i res_lo_round =
_mm_sra_epi32(_mm_add_epi32(res_lo, round_const), round_shift);
const __m128i res_hi_round =
_mm_sra_epi32(_mm_add_epi32(res_hi, round_const), round_shift);
// Accumulate values into the destination buffer
__m128i *const p = (__m128i *)&dst[i * dst_stride + j];
if (conv_params->use_jnt_comp_avg) {
if (do_average) {
const __m128i jnt_sum_lo = _mm_add_epi32(
_mm_loadu_si128(p + 0), _mm_mullo_epi32(res_lo_round, wt1));
const __m128i jnt_sum_hi = _mm_add_epi32(
_mm_loadu_si128(p + 1), _mm_mullo_epi32(res_hi_round, wt1));
const __m128i jnt_round_res_lo = _mm_add_epi32(jnt_sum_lo, jnt_r);
const __m128i jnt_round_res_hi = _mm_add_epi32(jnt_sum_hi, jnt_r);
const __m128i final_lo =
_mm_srai_epi32(jnt_round_res_lo, DIST_PRECISION_BITS - 1);
const __m128i final_hi =
_mm_srai_epi32(jnt_round_res_hi, DIST_PRECISION_BITS - 1);
_mm_storeu_si128(p + 0, final_lo);
_mm_storeu_si128(p + 1, final_hi);
} else {
_mm_storeu_si128(p + 0, _mm_mullo_epi32(res_lo_round, wt0));
_mm_storeu_si128(p + 1, _mm_mullo_epi32(res_hi_round, wt0));
}
} else {
if (do_average) {
_mm_storeu_si128(
p + 0, _mm_add_epi32(_mm_loadu_si128(p + 0), res_lo_round));
_mm_storeu_si128(
p + 1, _mm_add_epi32(_mm_loadu_si128(p + 1), res_hi_round));
} else {
_mm_storeu_si128(p + 0, res_lo_round);
_mm_storeu_si128(p + 1, res_hi_round);
}
}
}
}
}
}
#endif // CONFIG_JNT_COMP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment