2016-07-05 15:36:25 +03:00
|
|
|
/*
|
2016-09-02 00:32:49 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2016-07-05 15:36:25 +03:00
|
|
|
*
|
2016-09-02 00:32:49 +03:00
|
|
|
* 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.
|
2016-07-05 15:36:25 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <immintrin.h>
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "./aom_config.h"
|
2016-08-23 02:08:15 +03:00
|
|
|
#include "aom_ports/mem.h"
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "aom/aom_integer.h"
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "aom_dsp/aom_dsp_common.h"
|
2016-08-23 02:08:15 +03:00
|
|
|
#include "aom_dsp/x86/synonyms.h"
|
2016-07-05 15:36:25 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 8 bit
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-09 08:59:08 +03:00
|
|
|
static INLINE unsigned int obmc_sad_w4(const uint8_t *pre, const int pre_stride,
|
|
|
|
const int32_t *wsrc, const int32_t *mask,
|
2016-07-05 15:36:25 +03:00
|
|
|
const int height) {
|
2016-07-12 15:20:04 +03:00
|
|
|
const int pre_step = pre_stride - 4;
|
2016-07-05 15:36:25 +03:00
|
|
|
int n = 0;
|
|
|
|
__m128i v_sad_d = _mm_setzero_si128();
|
|
|
|
|
|
|
|
do {
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_p_b = xx_loadl_32(pre + n);
|
|
|
|
const __m128i v_m_d = xx_load_128(mask + n);
|
|
|
|
const __m128i v_w_d = xx_load_128(wsrc + n);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_p_d = _mm_cvtepu8_epi32(v_p_b);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
// Values in both pre and mask fit in 15 bits, and are packed at 32 bit
|
2016-07-05 15:36:25 +03:00
|
|
|
// boundaries. We use pmaddwd, as it has lower latency on Haswell
|
|
|
|
// than pmulld but produces the same result with these inputs.
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_pm_d = _mm_madd_epi16(v_p_d, v_m_d);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_diff_d = _mm_sub_epi32(v_w_d, v_pm_d);
|
2016-07-05 15:36:25 +03:00
|
|
|
const __m128i v_absdiff_d = _mm_abs_epi32(v_diff_d);
|
|
|
|
|
|
|
|
// Rounded absolute difference
|
|
|
|
const __m128i v_rad_d = xx_roundn_epu32(v_absdiff_d, 12);
|
|
|
|
|
|
|
|
v_sad_d = _mm_add_epi32(v_sad_d, v_rad_d);
|
|
|
|
|
|
|
|
n += 4;
|
|
|
|
|
2016-07-12 13:41:54 +03:00
|
|
|
if (n % 4 == 0) pre += pre_step;
|
2016-07-05 15:36:25 +03:00
|
|
|
} while (n < 4 * height);
|
|
|
|
|
|
|
|
return xx_hsum_epi32_si32(v_sad_d);
|
|
|
|
}
|
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
static INLINE unsigned int obmc_sad_w8n(const uint8_t *pre,
|
|
|
|
const int pre_stride,
|
|
|
|
const int32_t *wsrc,
|
2016-08-09 08:59:08 +03:00
|
|
|
const int32_t *mask, const int width,
|
2016-07-12 15:20:04 +03:00
|
|
|
const int height) {
|
|
|
|
const int pre_step = pre_stride - width;
|
2016-07-05 15:36:25 +03:00
|
|
|
int n = 0;
|
|
|
|
__m128i v_sad_d = _mm_setzero_si128();
|
2016-07-12 13:41:54 +03:00
|
|
|
|
|
|
|
assert(width >= 8);
|
|
|
|
assert(IS_POWER_OF_TWO(width));
|
2016-07-05 15:36:25 +03:00
|
|
|
|
|
|
|
do {
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_p1_b = xx_loadl_32(pre + n + 4);
|
|
|
|
const __m128i v_m1_d = xx_load_128(mask + n + 4);
|
|
|
|
const __m128i v_w1_d = xx_load_128(wsrc + n + 4);
|
|
|
|
const __m128i v_p0_b = xx_loadl_32(pre + n);
|
|
|
|
const __m128i v_m0_d = xx_load_128(mask + n);
|
|
|
|
const __m128i v_w0_d = xx_load_128(wsrc + n);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_p0_d = _mm_cvtepu8_epi32(v_p0_b);
|
|
|
|
const __m128i v_p1_d = _mm_cvtepu8_epi32(v_p1_b);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
// Values in both pre and mask fit in 15 bits, and are packed at 32 bit
|
2016-07-05 15:36:25 +03:00
|
|
|
// boundaries. We use pmaddwd, as it has lower latency on Haswell
|
|
|
|
// than pmulld but produces the same result with these inputs.
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_pm0_d = _mm_madd_epi16(v_p0_d, v_m0_d);
|
|
|
|
const __m128i v_pm1_d = _mm_madd_epi16(v_p1_d, v_m1_d);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_diff0_d = _mm_sub_epi32(v_w0_d, v_pm0_d);
|
|
|
|
const __m128i v_diff1_d = _mm_sub_epi32(v_w1_d, v_pm1_d);
|
2016-07-05 15:36:25 +03:00
|
|
|
const __m128i v_absdiff0_d = _mm_abs_epi32(v_diff0_d);
|
|
|
|
const __m128i v_absdiff1_d = _mm_abs_epi32(v_diff1_d);
|
|
|
|
|
|
|
|
// Rounded absolute difference
|
|
|
|
const __m128i v_rad0_d = xx_roundn_epu32(v_absdiff0_d, 12);
|
|
|
|
const __m128i v_rad1_d = xx_roundn_epu32(v_absdiff1_d, 12);
|
|
|
|
|
|
|
|
v_sad_d = _mm_add_epi32(v_sad_d, v_rad0_d);
|
|
|
|
v_sad_d = _mm_add_epi32(v_sad_d, v_rad1_d);
|
|
|
|
|
|
|
|
n += 8;
|
|
|
|
|
2016-07-12 13:41:54 +03:00
|
|
|
if (n % width == 0) pre += pre_step;
|
2016-07-05 15:36:25 +03:00
|
|
|
} while (n < width * height);
|
|
|
|
|
|
|
|
return xx_hsum_epi32_si32(v_sad_d);
|
|
|
|
}
|
|
|
|
|
2016-08-09 08:59:08 +03:00
|
|
|
#define OBMCSADWXH(w, h) \
|
2016-08-31 00:01:10 +03:00
|
|
|
unsigned int aom_obmc_sad##w##x##h##_sse4_1( \
|
2016-08-09 08:59:08 +03:00
|
|
|
const uint8_t *pre, int pre_stride, const int32_t *wsrc, \
|
|
|
|
const int32_t *msk) { \
|
|
|
|
if (w == 4) { \
|
|
|
|
return obmc_sad_w4(pre, pre_stride, wsrc, msk, h); \
|
|
|
|
} else { \
|
|
|
|
return obmc_sad_w8n(pre, pre_stride, wsrc, msk, w, h); \
|
|
|
|
} \
|
|
|
|
}
|
2016-07-05 15:36:25 +03:00
|
|
|
|
|
|
|
#if CONFIG_EXT_PARTITION
|
|
|
|
OBMCSADWXH(128, 128)
|
|
|
|
OBMCSADWXH(128, 64)
|
|
|
|
OBMCSADWXH(64, 128)
|
|
|
|
#endif // CONFIG_EXT_PARTITION
|
|
|
|
OBMCSADWXH(64, 64)
|
|
|
|
OBMCSADWXH(64, 32)
|
|
|
|
OBMCSADWXH(32, 64)
|
|
|
|
OBMCSADWXH(32, 32)
|
|
|
|
OBMCSADWXH(32, 16)
|
|
|
|
OBMCSADWXH(16, 32)
|
|
|
|
OBMCSADWXH(16, 16)
|
|
|
|
OBMCSADWXH(16, 8)
|
|
|
|
OBMCSADWXH(8, 16)
|
|
|
|
OBMCSADWXH(8, 8)
|
|
|
|
OBMCSADWXH(8, 4)
|
|
|
|
OBMCSADWXH(4, 8)
|
|
|
|
OBMCSADWXH(4, 4)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// High bit-depth
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#if CONFIG_AOM_HIGHBITDEPTH
|
2016-07-12 15:20:04 +03:00
|
|
|
static INLINE unsigned int hbd_obmc_sad_w4(const uint8_t *pre8,
|
|
|
|
const int pre_stride,
|
|
|
|
const int32_t *wsrc,
|
|
|
|
const int32_t *mask,
|
2016-07-05 15:36:25 +03:00
|
|
|
const int height) {
|
2016-07-12 15:20:04 +03:00
|
|
|
const uint16_t *pre = CONVERT_TO_SHORTPTR(pre8);
|
|
|
|
const int pre_step = pre_stride - 4;
|
2016-07-05 15:36:25 +03:00
|
|
|
int n = 0;
|
|
|
|
__m128i v_sad_d = _mm_setzero_si128();
|
|
|
|
|
|
|
|
do {
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_p_w = xx_loadl_64(pre + n);
|
|
|
|
const __m128i v_m_d = xx_load_128(mask + n);
|
|
|
|
const __m128i v_w_d = xx_load_128(wsrc + n);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_p_d = _mm_cvtepu16_epi32(v_p_w);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
// Values in both pre and mask fit in 15 bits, and are packed at 32 bit
|
2016-07-05 15:36:25 +03:00
|
|
|
// boundaries. We use pmaddwd, as it has lower latency on Haswell
|
|
|
|
// than pmulld but produces the same result with these inputs.
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_pm_d = _mm_madd_epi16(v_p_d, v_m_d);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_diff_d = _mm_sub_epi32(v_w_d, v_pm_d);
|
2016-07-05 15:36:25 +03:00
|
|
|
const __m128i v_absdiff_d = _mm_abs_epi32(v_diff_d);
|
|
|
|
|
|
|
|
// Rounded absolute difference
|
|
|
|
const __m128i v_rad_d = xx_roundn_epu32(v_absdiff_d, 12);
|
|
|
|
|
|
|
|
v_sad_d = _mm_add_epi32(v_sad_d, v_rad_d);
|
|
|
|
|
|
|
|
n += 4;
|
|
|
|
|
2016-07-12 13:41:54 +03:00
|
|
|
if (n % 4 == 0) pre += pre_step;
|
2016-07-05 15:36:25 +03:00
|
|
|
} while (n < 4 * height);
|
|
|
|
|
|
|
|
return xx_hsum_epi32_si32(v_sad_d);
|
|
|
|
}
|
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
static INLINE unsigned int hbd_obmc_sad_w8n(const uint8_t *pre8,
|
|
|
|
const int pre_stride,
|
|
|
|
const int32_t *wsrc,
|
|
|
|
const int32_t *mask,
|
2016-08-09 08:59:08 +03:00
|
|
|
const int width, const int height) {
|
2016-07-12 15:20:04 +03:00
|
|
|
const uint16_t *pre = CONVERT_TO_SHORTPTR(pre8);
|
|
|
|
const int pre_step = pre_stride - width;
|
2016-07-05 15:36:25 +03:00
|
|
|
int n = 0;
|
|
|
|
__m128i v_sad_d = _mm_setzero_si128();
|
2016-07-12 13:41:54 +03:00
|
|
|
|
|
|
|
assert(width >= 8);
|
|
|
|
assert(IS_POWER_OF_TWO(width));
|
2016-07-05 15:36:25 +03:00
|
|
|
|
|
|
|
do {
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_p1_w = xx_loadl_64(pre + n + 4);
|
|
|
|
const __m128i v_m1_d = xx_load_128(mask + n + 4);
|
|
|
|
const __m128i v_w1_d = xx_load_128(wsrc + n + 4);
|
|
|
|
const __m128i v_p0_w = xx_loadl_64(pre + n);
|
|
|
|
const __m128i v_m0_d = xx_load_128(mask + n);
|
|
|
|
const __m128i v_w0_d = xx_load_128(wsrc + n);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_p0_d = _mm_cvtepu16_epi32(v_p0_w);
|
|
|
|
const __m128i v_p1_d = _mm_cvtepu16_epi32(v_p1_w);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
// Values in both pre and mask fit in 15 bits, and are packed at 32 bit
|
2016-07-05 15:36:25 +03:00
|
|
|
// boundaries. We use pmaddwd, as it has lower latency on Haswell
|
|
|
|
// than pmulld but produces the same result with these inputs.
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_pm0_d = _mm_madd_epi16(v_p0_d, v_m0_d);
|
|
|
|
const __m128i v_pm1_d = _mm_madd_epi16(v_p1_d, v_m1_d);
|
2016-07-05 15:36:25 +03:00
|
|
|
|
2016-07-12 15:20:04 +03:00
|
|
|
const __m128i v_diff0_d = _mm_sub_epi32(v_w0_d, v_pm0_d);
|
|
|
|
const __m128i v_diff1_d = _mm_sub_epi32(v_w1_d, v_pm1_d);
|
2016-07-05 15:36:25 +03:00
|
|
|
const __m128i v_absdiff0_d = _mm_abs_epi32(v_diff0_d);
|
|
|
|
const __m128i v_absdiff1_d = _mm_abs_epi32(v_diff1_d);
|
|
|
|
|
|
|
|
// Rounded absolute difference
|
|
|
|
const __m128i v_rad0_d = xx_roundn_epu32(v_absdiff0_d, 12);
|
|
|
|
const __m128i v_rad1_d = xx_roundn_epu32(v_absdiff1_d, 12);
|
|
|
|
|
|
|
|
v_sad_d = _mm_add_epi32(v_sad_d, v_rad0_d);
|
|
|
|
v_sad_d = _mm_add_epi32(v_sad_d, v_rad1_d);
|
|
|
|
|
|
|
|
n += 8;
|
|
|
|
|
2016-07-12 13:41:54 +03:00
|
|
|
if (n % width == 0) pre += pre_step;
|
2016-07-05 15:36:25 +03:00
|
|
|
} while (n < width * height);
|
|
|
|
|
|
|
|
return xx_hsum_epi32_si32(v_sad_d);
|
|
|
|
}
|
|
|
|
|
2016-08-09 08:59:08 +03:00
|
|
|
#define HBD_OBMCSADWXH(w, h) \
|
2016-08-31 00:01:10 +03:00
|
|
|
unsigned int aom_highbd_obmc_sad##w##x##h##_sse4_1( \
|
2016-08-09 08:59:08 +03:00
|
|
|
const uint8_t *pre, int pre_stride, const int32_t *wsrc, \
|
|
|
|
const int32_t *mask) { \
|
|
|
|
if (w == 4) { \
|
|
|
|
return hbd_obmc_sad_w4(pre, pre_stride, wsrc, mask, h); \
|
|
|
|
} else { \
|
|
|
|
return hbd_obmc_sad_w8n(pre, pre_stride, wsrc, mask, w, h); \
|
|
|
|
} \
|
|
|
|
}
|
2016-07-05 15:36:25 +03:00
|
|
|
|
|
|
|
#if CONFIG_EXT_PARTITION
|
|
|
|
HBD_OBMCSADWXH(128, 128)
|
|
|
|
HBD_OBMCSADWXH(128, 64)
|
|
|
|
HBD_OBMCSADWXH(64, 128)
|
|
|
|
#endif // CONFIG_EXT_PARTITION
|
|
|
|
HBD_OBMCSADWXH(64, 64)
|
|
|
|
HBD_OBMCSADWXH(64, 32)
|
|
|
|
HBD_OBMCSADWXH(32, 64)
|
|
|
|
HBD_OBMCSADWXH(32, 32)
|
|
|
|
HBD_OBMCSADWXH(32, 16)
|
|
|
|
HBD_OBMCSADWXH(16, 32)
|
|
|
|
HBD_OBMCSADWXH(16, 16)
|
|
|
|
HBD_OBMCSADWXH(16, 8)
|
|
|
|
HBD_OBMCSADWXH(8, 16)
|
|
|
|
HBD_OBMCSADWXH(8, 8)
|
|
|
|
HBD_OBMCSADWXH(8, 4)
|
|
|
|
HBD_OBMCSADWXH(4, 8)
|
|
|
|
HBD_OBMCSADWXH(4, 4)
|
2016-08-31 00:01:10 +03:00
|
|
|
#endif // CONFIG_AOM_HIGHBITDEPTH
|