Commit b87cc923 authored by Steinar Midtskogen's avatar Steinar Midtskogen

Added generic SIMD support for CLPF.

Change-Id: Ie03f9a5b0a4c708a586532198d755a1e7509f149
parent 992cf8ae
......@@ -624,6 +624,15 @@ specialize qw/aom_lpf_horizontal_4 mmx neon dspr2 msa/;
add_proto qw/void aom_lpf_horizontal_4_dual/, "uint8_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0, const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, const uint8_t *thresh1";
specialize qw/aom_lpf_horizontal_4_dual sse2 neon dspr2 msa/;
if (aom_config("CONFIG_CLPF") eq "yes") {
add_proto qw/void aom_clpf_block/, "const uint8_t *src, uint8_t *dst, int stride, int x0, int y0, int sizex, int sizey, int width, int height, unsigned int strength";
specialize qw/aom_clpf_block sse2 ssse3 sse4_1 neon/;
add_proto qw/void aom_clpf_detect/, "const uint8_t *rec, const uint8_t *org, int rstride, int ostride, int x0, int y0, int width, int height, int *sum0, int *sum1, unsigned int strength";
specialize qw/aom_clpf_detect sse2 ssse3 sse4_1 neon/;
add_proto qw/void aom_clpf_detect_multi/, "const uint8_t *rec, const uint8_t *org, int rstride, int ostride, int x0, int y0, int width, int height, int *sum";
specialize qw/aom_clpf_detect_multi sse2 ssse3 sse4_1 neon/;
}
if (aom_config("CONFIG_AOM_HIGHBITDEPTH") eq "yes") {
add_proto qw/void aom_highbd_lpf_vertical_16/, "uint16_t *s, int pitch, const uint8_t *blimit, const uint8_t *limit, const uint8_t *thresh, int bd";
specialize qw/aom_highbd_lpf_vertical_16 sse2/;
......
......@@ -75,6 +75,11 @@ AV1_COMMON_SRCS-$(CONFIG_AV1_ENCODER) += common/av1_fwd_txfm.c
ifeq ($(CONFIG_CLPF),yes)
AV1_COMMON_SRCS-yes += common/clpf.c
AV1_COMMON_SRCS-yes += common/clpf.h
AV1_COMMON_SRCS-yes += common/clpf_simd.h
AV1_COMMON_SRCS-$(HAVE_SSE2) += common/clpf_sse2.c
AV1_COMMON_SRCS-$(HAVE_SSSE3) += common/clpf_ssse3.c
AV1_COMMON_SRCS-$(HAVE_SSE4_1) += common/clpf_sse4_1.c
AV1_COMMON_SRCS-$(HAVE_NEON) += common/clpf_neon.c
endif
ifeq ($(CONFIG_DERING),yes)
AV1_COMMON_SRCS-yes += common/od_dering.c
......
......@@ -89,6 +89,11 @@ AV1_CX_SRCS-$(CONFIG_DERING) += encoder/pickdering.c
ifeq ($(CONFIG_CLPF),yes)
AV1_CX_SRCS-yes += encoder/clpf_rdo.c
AV1_CX_SRCS-yes += encoder/clpf_rdo.h
AV1_CX_SRCS-yes += encoder/clpf_rdo_simd.h
AV1_CX_SRCS-$(HAVE_SSE2) += encoder/clpf_rdo_sse2.c
AV1_CX_SRCS-$(HAVE_SSSE3) += encoder/clpf_rdo_ssse3.c
AV1_CX_SRCS-$(HAVE_SSE4_1) += encoder/clpf_rdo_sse4_1.c
AV1_CX_SRCS-$(HAVE_NEON) += encoder/clpf_rdo_neon.c
endif
AV1_CX_SRCS-$(HAVE_SSE2) += encoder/x86/temporal_filter_apply_sse2.asm
......
......@@ -9,6 +9,7 @@
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include "av1/common/clpf.h"
#include "./aom_dsp_rtcd.h"
#include "aom_dsp/aom_dsp_common.h"
int av1_clpf_maxbits(const AV1_COMMON *cm) {
......@@ -27,9 +28,9 @@ int av1_clpf_sample(int X, int A, int B, int C, int D, int E, int F, int b) {
return (8 + delta - (delta < 0)) >> 4;
}
static void clpf_block(const uint8_t *src, uint8_t *dst, int stride, int x0,
int y0, int sizex, int sizey, int width, int height,
unsigned int strength) {
void aom_clpf_block_c(const uint8_t *src, uint8_t *dst, int stride, int x0,
int y0, int sizex, int sizey, int width, int height,
unsigned int strength) {
int x, y;
for (y = y0; y < y0 + sizey; y++) {
for (x = x0; x < x0 + sizex; x++) {
......@@ -102,8 +103,8 @@ int av1_clpf_frame(const YV12_BUFFER_CONFIG *dst, const YV12_BUFFER_CONFIG *rec,
if (!cm->mi_grid_visible[ypos / bs * cm->mi_stride + xpos / bs]
->mbmi.skip) {
// Not skip block, apply the filter
clpf_block(rec->y_buffer, dst->y_buffer, stride_y, xpos, ypos, bs,
bs, width, height, strength);
aom_clpf_block(rec->y_buffer, dst->y_buffer, stride_y, xpos, ypos,
bs, bs, width, height, strength);
} else { // Skip block, copy instead
for (c = 0; c < bs; c++)
*(uint64_t *)(dst->y_buffer + (ypos + c) * stride_y + xpos) =
......
/*
* 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 "aom_dsp/aom_simd.h"
#define SIMD_FUNC(name) name##_neon
#include "./clpf_simd.h"
/*
* 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 "./aom_dsp_rtcd.h"
static void clpf_block(const uint8_t *src, uint8_t *dst, int stride, int x0,
int y0, int sizey, int width, int height,
unsigned int strength) {
dst += x0 + y0 * stride;
src += x0 + y0 * stride;
{
int bottom = height - 2 - y0;
const v128 sp = v128_dup_8(strength);
const v128 sm = v128_dup_8(-(int)strength);
const v128 c8 = v128_dup_8(8);
const v128 c128 = v128_dup_8(128);
if (!x0) { // Clip left
const v128 b_shuff = v128_from_v64(v64_from_64(0x0d0c0b0a09080808LL),
v64_from_64(0x0504030201000000LL));
const v128 c_shuff = v128_from_v64(v64_from_64(0x0e0d0c0b0a090808LL),
v64_from_64(0x0605040302010000LL));
int y;
for (y = 0; y < sizey; y += 2) {
const v64 l1 = v64_load_aligned(src);
const v64 l2 = v64_load_aligned(src + stride);
v128 o = v128_from_v64(l1, l2);
const v128 x = v128_add_8(c128, o);
const v128 a = v128_add_8(
c128,
v128_from_v64(v64_load_aligned(src - (y != -y0) * stride), l1));
const v128 b = v128_shuffle_8(x, b_shuff);
const v128 c = v128_shuffle_8(x, c_shuff);
const v128 d = v128_add_8(
c128, v128_from_v64(v64_load_unaligned(src + 1),
v64_load_unaligned(src + 1 + stride)));
const v128 e = v128_add_8(
c128, v128_from_v64(v64_load_unaligned(src + 2),
v64_load_unaligned(src + 2 + stride)));
const v128 f = v128_add_8(
c128, v128_from_v64(l2, v64_load_aligned(
src + ((y != bottom) + 1) * stride)));
const v128 tmp =
v128_add_8(v128_max_s8(v128_min_s8(v128_ssub_s8(c, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(d, x), sp), sm));
const v128 delta = v128_add_8(
v128_add_8(
v128_shl_8(
v128_add_8(
v128_max_s8(v128_min_s8(v128_ssub_s8(a, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(f, x), sp), sm)),
2),
v128_add_8(
v128_max_s8(v128_min_s8(v128_ssub_s8(b, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(e, x), sp), sm))),
v128_add_8(v128_add_8(tmp, tmp), tmp));
o = v128_add_8(
o, v128_shr_s8(
v128_add_8(c8, v128_add_8(delta, v128_cmplt_s8(
delta, v128_zero()))),
4));
v64_store_aligned(dst, v128_high_v64(o));
v64_store_aligned(dst + stride, v128_low_v64(o));
src += stride * 2;
dst += stride * 2;
}
} else if (!(width - x0 - 8)) { // Clip right
const v128 d_shuff = v128_from_v64(v64_from_64(0x0f0f0e0d0c0b0a09LL),
v64_from_64(0x0707060504030201LL));
const v128 e_shuff = v128_from_v64(v64_from_64(0x0f0f0f0e0d0c0b0aLL),
v64_from_64(0x0707070605040302LL));
int y;
for (y = 0; y < sizey; y += 2) {
const v64 l1 = v64_load_aligned(src);
const v64 l2 = v64_load_aligned(src + stride);
v128 o = v128_from_v64(l1, l2);
const v128 x = v128_add_8(c128, o);
const v128 a = v128_add_8(
c128,
v128_from_v64(v64_load_aligned(src - (y != -y0) * stride), l1));
const v128 b = v128_add_8(
c128, v128_from_v64(v64_load_unaligned(src - 2),
v64_load_unaligned(src - 2 + stride)));
const v128 c = v128_add_8(
c128, v128_from_v64(v64_load_unaligned(src - 1),
v64_load_unaligned(src - 1 + stride)));
const v128 d = v128_shuffle_8(x, d_shuff);
const v128 e = v128_shuffle_8(x, e_shuff);
const v128 f = v128_add_8(
c128, v128_from_v64(l2, v64_load_aligned(
src + ((y != bottom) + 1) * stride)));
const v128 tmp =
v128_add_8(v128_max_s8(v128_min_s8(v128_ssub_s8(c, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(d, x), sp), sm));
const v128 delta = v128_add_8(
v128_add_8(
v128_shl_8(
v128_add_8(
v128_max_s8(v128_min_s8(v128_ssub_s8(a, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(f, x), sp), sm)),
2),
v128_add_8(
v128_max_s8(v128_min_s8(v128_ssub_s8(b, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(e, x), sp), sm))),
v128_add_8(v128_add_8(tmp, tmp), tmp));
o = v128_add_8(
o, v128_shr_s8(
v128_add_8(c8, v128_add_8(delta, v128_cmplt_s8(
delta, v128_zero()))),
4));
v64_store_aligned(dst, v128_high_v64(o));
v64_store_aligned(dst + stride, v128_low_v64(o));
src += stride * 2;
dst += stride * 2;
}
} else { // No left/right clipping
int y;
for (y = 0; y < sizey; y += 2) {
const v64 l1 = v64_load_aligned(src);
const v64 l2 = v64_load_aligned(src + stride);
v128 o = v128_from_v64(l1, l2);
const v128 x = v128_add_8(c128, o);
const v128 a = v128_add_8(
c128,
v128_from_v64(v64_load_aligned(src - (y != -y0) * stride), l1));
const v128 b = v128_add_8(
c128, v128_from_v64(v64_load_unaligned(src - 2),
v64_load_unaligned(src - 2 + stride)));
const v128 c = v128_add_8(
c128, v128_from_v64(v64_load_unaligned(src - 1),
v64_load_unaligned(src - 1 + stride)));
const v128 d = v128_add_8(
c128, v128_from_v64(v64_load_unaligned(src + 1),
v64_load_unaligned(src + 1 + stride)));
const v128 e = v128_add_8(
c128, v128_from_v64(v64_load_unaligned(src + 2),
v64_load_unaligned(src + 2 + stride)));
const v128 f = v128_add_8(
c128, v128_from_v64(l2, v64_load_aligned(
src + ((y != bottom) + 1) * stride)));
const v128 tmp =
v128_add_8(v128_max_s8(v128_min_s8(v128_ssub_s8(c, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(d, x), sp), sm));
const v128 delta = v128_add_8(
v128_add_8(
v128_shl_8(
v128_add_8(
v128_max_s8(v128_min_s8(v128_ssub_s8(a, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(f, x), sp), sm)),
2),
v128_add_8(
v128_max_s8(v128_min_s8(v128_ssub_s8(b, x), sp), sm),
v128_max_s8(v128_min_s8(v128_ssub_s8(e, x), sp), sm))),
v128_add_8(v128_add_8(tmp, tmp), tmp));
o = v128_add_8(
o, v128_shr_s8(
v128_add_8(c8, v128_add_8(delta, v128_cmplt_s8(
delta, v128_zero()))),
4));
v64_store_aligned(dst, v128_high_v64(o));
v64_store_aligned(dst + stride, v128_low_v64(o));
src += stride * 2;
dst += stride * 2;
}
}
}
}
void SIMD_FUNC(aom_clpf_block)(const uint8_t *src, uint8_t *dst, int stride,
int x0, int y0, int sizex, int sizey, int width,
int height, unsigned int strength) {
// TODO(stemidts):
// A sizex different from 8 will only be needed if CLPF is extended to chroma.
// This will only be used if 4:2:0 and width not a multiple of 16 and along
// the right edge only, so we can fall back to the plain C implementation in
// this case. If not extended to chroma, this test will be redundant.
if (sizex != 8 || width < 16) { // Fallback to C if frame width < 16
aom_clpf_block_c(src, dst, stride, x0, y0, sizex, sizey, width, height,
strength);
} else {
clpf_block(src, dst, stride, x0, y0, sizey, width, height, strength);
}
}
/*
* 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 "aom_dsp/aom_simd.h"
#define SIMD_FUNC(name) name##_sse2
#include "./clpf_simd.h"
/*
* 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 "aom_dsp/aom_simd.h"
#define SIMD_FUNC(name) name##_sse4_1
#include "./clpf_simd.h"
/*
* 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 "aom_dsp/aom_simd.h"
#define SIMD_FUNC(name) name##_ssse3
#include "./clpf_simd.h"
......@@ -10,24 +10,25 @@
*/
#include "av1/common/clpf.h"
#include "./aom_dsp_rtcd.h"
#include "aom/aom_integer.h"
#include "av1/common/quant_common.h"
// Calculate the error of a filtered and unfiltered block
static void detect_clpf(const uint8_t *rec, const uint8_t *org, int x0, int y0,
int width, int height, int so, int stride, int *sum0,
int *sum1, unsigned int strength) {
void aom_clpf_detect_c(const uint8_t *rec, const uint8_t *org, int rstride,
int ostride, int x0, int y0, int width, int height,
int *sum0, int *sum1, unsigned int strength) {
int x, y;
for (y = y0; y < y0 + 8; y++) {
for (x = x0; x < x0 + 8; x++) {
int O = org[y * so + x];
int X = rec[y * stride + x];
int A = rec[AOMMAX(0, y - 1) * stride + x];
int B = rec[y * stride + AOMMAX(0, x - 2)];
int C = rec[y * stride + AOMMAX(0, x - 1)];
int D = rec[y * stride + AOMMIN(width - 1, x + 1)];
int E = rec[y * stride + AOMMIN(width - 1, x + 2)];
int F = rec[AOMMIN(height - 1, y + 1) * stride + x];
int O = org[y * ostride + x];
int X = rec[y * rstride + x];
int A = rec[AOMMAX(0, y - 1) * rstride + x];
int B = rec[y * rstride + AOMMAX(0, x - 2)];
int C = rec[y * rstride + AOMMAX(0, x - 1)];
int D = rec[y * rstride + AOMMIN(width - 1, x + 1)];
int E = rec[y * rstride + AOMMIN(width - 1, x + 2)];
int F = rec[AOMMIN(height - 1, y + 1) * rstride + x];
int delta = av1_clpf_sample(X, A, B, C, D, E, F, strength);
int Y = X + delta;
*sum0 += (O - X) * (O - X);
......@@ -36,21 +37,21 @@ static void detect_clpf(const uint8_t *rec, const uint8_t *org, int x0, int y0,
}
}
static void detect_multi_clpf(const uint8_t *rec, const uint8_t *org, int x0,
int y0, int width, int height, int so, int stride,
int *sum) {
void aom_clpf_detect_multi_c(const uint8_t *rec, const uint8_t *org,
int rstride, int ostride, int x0, int y0,
int width, int height, int *sum) {
int x, y;
for (y = y0; y < y0 + 8; y++) {
for (x = x0; x < x0 + 8; x++) {
int O = org[y * so + x];
int X = rec[y * stride + x];
int A = rec[AOMMAX(0, y - 1) * stride + x];
int B = rec[y * stride + AOMMAX(0, x - 2)];
int C = rec[y * stride + AOMMAX(0, x - 1)];
int D = rec[y * stride + AOMMIN(width - 1, x + 1)];
int E = rec[y * stride + AOMMIN(width - 1, x + 2)];
int F = rec[AOMMIN(height - 1, y + 1) * stride + x];
int O = org[y * ostride + x];
int X = rec[y * rstride + x];
int A = rec[AOMMAX(0, y - 1) * rstride + x];
int B = rec[y * rstride + AOMMAX(0, x - 2)];
int C = rec[y * rstride + AOMMAX(0, x - 1)];
int D = rec[y * rstride + AOMMIN(width - 1, x + 1)];
int E = rec[y * rstride + AOMMIN(width - 1, x + 2)];
int F = rec[AOMMIN(height - 1, y + 1) * rstride + x];
int delta1 = av1_clpf_sample(X, A, B, C, D, E, F, 1);
int delta2 = av1_clpf_sample(X, A, B, C, D, E, F, 2);
int delta3 = av1_clpf_sample(X, A, B, C, D, E, F, 4);
......@@ -77,9 +78,9 @@ int av1_clpf_decision(int k, int l, const YV12_BUFFER_CONFIG *rec,
const int bs = MAX_MIB_SIZE;
if (!cm->mi_grid_visible[ypos / bs * cm->mi_stride + xpos / bs]
->mbmi.skip)
detect_clpf(rec->y_buffer, org->y_buffer, xpos, ypos, rec->y_crop_width,
rec->y_crop_height, org->y_stride, rec->y_stride, &sum0,
&sum1, strength);
aom_clpf_detect(rec->y_buffer, org->y_buffer, rec->y_stride,
org->y_stride, xpos, ypos, rec->y_crop_width,
rec->y_crop_height, &sum0, &sum1, strength);
}
}
*res = sum1 < sum0;
......@@ -144,9 +145,9 @@ static int clpf_rdo(int y, int x, const YV12_BUFFER_CONFIG *rec,
if (!cm->mi_grid_visible[ypos / MAX_MIB_SIZE * cm->mi_stride +
xpos / MAX_MIB_SIZE]
->mbmi.skip) {
detect_multi_clpf(rec->y_buffer, org->y_buffer, xpos, ypos,
rec->y_crop_width, rec->y_crop_height, org->y_stride,
rec->y_stride, sum);
aom_clpf_detect_multi(rec->y_buffer, org->y_buffer, rec->y_stride,
org->y_stride, xpos, ypos, rec->y_crop_width,
rec->y_crop_height, sum);
filtered = 1;
}
}
......
/*
* 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 "aom_dsp/aom_simd.h"
#define SIMD_FUNC(name) name##_neon
#include "./clpf_rdo_simd.h"
This diff is collapsed.
/*
* 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 "aom_dsp/aom_simd.h"
#define SIMD_FUNC(name) name##_sse2
#include "./clpf_rdo_simd.h"
/*
* 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 "aom_dsp/aom_simd.h"
#define SIMD_FUNC(name) name##_sse4_1
#include "./clpf_rdo_simd.h"
/*
* 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 "aom_dsp/aom_simd.h"
#define SIMD_FUNC(name) name##_ssse3
#include "./clpf_rdo_simd.h"
/*
* 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 <cstdlib>
#include <string>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "./aom_config.h"
#include "./aom_dsp_rtcd.h"
#include "aom_ports/aom_timer.h"
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
using libaom_test::ACMRandom;
namespace {
typedef void (*clpf_block_t)(const uint8_t *src, uint8_t *dst, int stride,
int x0, int y0, int sizex, int sizey, int width,
int height, unsigned int strength);
typedef std::tr1::tuple<clpf_block_t, clpf_block_t, int, int>
clpf_block_param_t;
class ClpfBlockTest : public ::testing::TestWithParam<clpf_block_param_t> {
public:
virtual ~ClpfBlockTest() {}
virtual void SetUp() {
clpf = GET_PARAM(0);
ref_clpf = GET_PARAM(1);
sizex = GET_PARAM(2);
sizey = GET_PARAM(3);
}
virtual void TearDown() { libaom_test::ClearSystemState(); }
protected:
int sizex;
int sizey;
clpf_block_t clpf;
clpf_block_t ref_clpf;
};
typedef ClpfBlockTest ClpfSpeedTest;
TEST_P(ClpfBlockTest, TestSIMDNoMismatch) {
int w = sizex;
int h = sizey;
const int size = 32;
ACMRandom rnd(ACMRandom::DeterministicSeed());
DECLARE_ALIGNED(16, uint8_t, s[size * size]);
DECLARE_ALIGNED(16, uint8_t, d[size * size]);
DECLARE_ALIGNED(16, uint8_t, ref_d[size * size]);
memset(ref_d, 0, size * size);
memset(d, 0, size * size);
int error = 0;
int pos = 0;
int strength = 0;
int xpos = 0, ypos = 0;
int bits;
int level;
// Test every combination of:
// * Input with 1-8 bits of noise
// * Noise level around every value from 0 to 255
// * Blocks anywhere in the frame (along all egdes and also fully inside)
// * All strengths
for (level = 0; level < 256 && !error; level++) {
for (bits = 1; bits < 9 && !error; bits++) {
for (int i = 0; i < size * size; i++)
s[i] = clamp((rnd.Rand8() & ((1 << bits) - 1)) + level, 0, 255);
for (ypos = 0; ypos < size && !error; ypos += h * !error) {
for (xpos = 0; xpos < size && !error; xpos += w * !error) {
for (strength = 0; strength < 3 && !error; strength += !error) {
ref_clpf(s, ref_d, size, xpos, ypos, w, h, size, size,
1 << strength);
ASM_REGISTER_STATE_CHECK(
clpf(s, d, size, xpos, ypos, w, h, size, size, 1 << strength));
for (pos = 0; pos < size * size && !error; pos++) {
error = ref_d[pos] != d[pos];
}
}
}
}
}
}
EXPECT_EQ(0, error)
<< "Error: ClpfBlockTest, SIMD and C mismatch." << std::endl
<< "First error at " << pos % size << "," << pos / size << " ("
<< (int16_t)ref_d[pos] << " != " << (int16_t)d[pos] << ") " << std::endl
<< "strength: " << (1 << strength) << std::endl
<< "xpos: " << xpos << std::endl
<< "ypos: " << ypos << std::endl
<< "A=" << (pos > size ? (int16_t)s[pos - size] : -1) << std::endl
<< "B=" << (pos % size - 2 >= 0 ? (int16_t)s[pos - 2] : -1) << std::endl
<< "C=" << (pos % size - 1 >= 0 ? (int16_t)s[pos - 1] : -1) << std::endl
<< "X=" << (int16_t)s[pos] << std::endl
<< "D=" << (pos % size + 1 < size ? (int16_t)s[pos + 1] : -1) << std::endl
<< "E=" << (pos % size + 2 < size ? (int16_t)s[pos + 2] : -1) << std::endl
<< "F=" << (pos + size < size * size ? (int16_t)s[pos + size] : -1)
<< std::endl;
}
TEST_P(ClpfSpeedTest, TestSpeed) {
int w = sizex;
int h = sizey;
const int size = 32;