/* * Copyright (c) 2018, 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.
*/
staticinlinevoid acc_stat_win7_one_line_sse4_1( const uint8_t *dgd, const uint8_t *src, int h_start, int h_end, int dgd_stride, const __m128i *shuffle, int32_t *sumX,
int32_t sumY[WIENER_WIN][WIENER_WIN], int32_t M_int[WIENER_WIN][WIENER_WIN],
int32_t H_int[WIENER_WIN2][WIENER_WIN * 8]) { constint wiener_win = 7; int j, k, l; // Main loop handles two pixels at a time // We can assume that h_start is even, since it will always be aligned to // a tile edge + some number of restoration units, and both of those will // be 64-pixel aligned. // However, at the edge of the image, h_end may be odd, so we need to handle // that case correctly.
assert(h_start % 2 == 0); constint h_end_even = h_end & ~1; constint has_odd_pixel = h_end & 1; for (j = h_start; j < h_end_even; j += 2) { const uint8_t *dgd_ij = dgd + j; const uint8_t X1 = src[j]; const uint8_t X2 = src[j + 1];
*sumX += X1 + X2; for (k = 0; k < wiener_win; k++) { const uint8_t *dgd_ijk = dgd_ij + k * dgd_stride; for (l = 0; l < wiener_win; l++) {
int32_t *H_ = &H_int[(l * wiener_win + k)][0]; const uint8_t D1 = dgd_ijk[l]; const uint8_t D2 = dgd_ijk[l + 1];
sumY[k][l] += D1 + D2;
M_int[k][l] += D1 * X1 + D2 * X2;
staticinlinevoid acc_stat_highbd_win7_one_line_sse4_1( const uint16_t *dgd, const uint16_t *src, int h_start, int h_end, int dgd_stride, const __m128i *shuffle, int32_t *sumX,
int32_t sumY[WIENER_WIN][WIENER_WIN], int64_t M_int[WIENER_WIN][WIENER_WIN],
int64_t H_int[WIENER_WIN2][WIENER_WIN * 8]) { int j, k, l; constint wiener_win = WIENER_WIN; // Main loop handles two pixels at a time // We can assume that h_start is even, since it will always be aligned to // a tile edge + some number of restoration units, and both of those will // be 64-pixel aligned. // However, at the edge of the image, h_end may be odd, so we need to handle // that case correctly.
assert(h_start % 2 == 0); constint h_end_even = h_end & ~1; constint has_odd_pixel = h_end & 1; for (j = h_start; j < h_end_even; j += 2) { const uint16_t X1 = src[j]; const uint16_t X2 = src[j + 1];
*sumX += X1 + X2; const uint16_t *dgd_ij = dgd + j; for (k = 0; k < wiener_win; k++) { const uint16_t *dgd_ijk = dgd_ij + k * dgd_stride; for (l = 0; l < wiener_win; l++) {
int64_t *H_ = &H_int[(l * wiener_win + k)][0]; const uint16_t D1 = dgd_ijk[l]; const uint16_t D2 = dgd_ijk[l + 1];
sumY[k][l] += D1 + D2;
M_int[k][l] += D1 * X1 + D2 * X2;
// Load two u16 values from dgd as a single u32 // Then broadcast to 4x u32 slots of a 128 const __m128i dgd_ijkl = _mm_set1_epi32(loadu_int32(dgd_ijk + l)); // dgd_ijkl = [y x y x y x y x] as u16
// The `acc_stat_highbd_sse41` function wants its input to have // interleaved copies of two pixels, but we only have one. However, the // pixels are (effectively) used as inputs to a multiply-accumulate. So // if we set the extra pixel slot to 0, then it is effectively ignored. const __m128i dgd_ijkl = _mm_set1_epi32((int)D1);
// Load just half of the 256-bit shuffle control used for the AVX2 version const __m128i shuffle = xx_loadu_128(g_shuffle_stats_highbd_data); for (j = v_start; j < v_end; j += 64) { constint vert_end = AOMMIN(64, v_end - j) + j; for (i = j; i < vert_end; i++) {
acc_stat_highbd_win7_one_line_sse4_1(
dgd_win + i * dgd_stride, src + i * src_stride, h_start, h_end,
dgd_stride, &shuffle, &sumX, sumY, M_int, H_int);
}
}
staticinlinevoid acc_stat_highbd_win5_one_line_sse4_1( const uint16_t *dgd, const uint16_t *src, int h_start, int h_end, int dgd_stride, const __m128i *shuffle, int32_t *sumX,
int32_t sumY[WIENER_WIN_CHROMA][WIENER_WIN_CHROMA],
int64_t M_int[WIENER_WIN_CHROMA][WIENER_WIN_CHROMA],
int64_t H_int[WIENER_WIN2_CHROMA][WIENER_WIN_CHROMA * 8]) { int j, k, l; constint wiener_win = WIENER_WIN_CHROMA; // Main loop handles two pixels at a time // We can assume that h_start is even, since it will always be aligned to // a tile edge + some number of restoration units, and both of those will // be 64-pixel aligned. // However, at the edge of the image, h_end may be odd, so we need to handle // that case correctly.
assert(h_start % 2 == 0); constint h_end_even = h_end & ~1; constint has_odd_pixel = h_end & 1; for (j = h_start; j < h_end_even; j += 2) { const uint16_t X1 = src[j]; const uint16_t X2 = src[j + 1];
*sumX += X1 + X2; const uint16_t *dgd_ij = dgd + j; for (k = 0; k < wiener_win; k++) { const uint16_t *dgd_ijk = dgd_ij + k * dgd_stride; for (l = 0; l < wiener_win; l++) {
int64_t *H_ = &H_int[(l * wiener_win + k)][0]; const uint16_t D1 = dgd_ijk[l]; const uint16_t D2 = dgd_ijk[l + 1];
sumY[k][l] += D1 + D2;
M_int[k][l] += D1 * X1 + D2 * X2;
// Load two u16 values from dgd as a single u32 // then broadcast to 4x u32 slots of a 128 const __m128i dgd_ijkl = _mm_set1_epi32(loadu_int32(dgd_ijk + l)); // dgd_ijkl = [y x y x y x y x] as u16
// The `acc_stat_highbd_sse41` function wants its input to have // interleaved copies of two pixels, but we only have one. However, the // pixels are (effectively) used as inputs to a multiply-accumulate. So // if we set the extra pixel slot to 0, then it is effectively ignored. const __m128i dgd_ijkl = _mm_set1_epi32((int)D1);
// Load just half of the 256-bit shuffle control used for the AVX2 version const __m128i shuffle = xx_loadu_128(g_shuffle_stats_highbd_data); for (j = v_start; j < v_end; j += 64) { constint vert_end = AOMMIN(64, v_end - j) + j; for (i = j; i < vert_end; i++) {
acc_stat_highbd_win5_one_line_sse4_1(
dgd_win + i * dgd_stride, src + i * src_stride, h_start, h_end,
dgd_stride, &shuffle, &sumX, sumY, M_int, H_int);
}
}
void av1_compute_stats_highbd_sse4_1(int wiener_win, const uint8_t *dgd8, const uint8_t *src8, int16_t *dgd_avg,
int16_t *src_avg, int h_start, int h_end, int v_start, int v_end, int dgd_stride, int src_stride, int64_t *M, int64_t *H,
aom_bit_depth_t bit_depth) { if (wiener_win == WIENER_WIN) {
(void)dgd_avg;
(void)src_avg;
compute_stats_highbd_win7_opt_sse4_1(dgd8, src8, h_start, h_end, v_start,
v_end, dgd_stride, src_stride, M, H,
bit_depth);
} elseif (wiener_win == WIENER_WIN_CHROMA) {
(void)dgd_avg;
(void)src_avg;
compute_stats_highbd_win5_opt_sse4_1(dgd8, src8, h_start, h_end, v_start,
v_end, dgd_stride, src_stride, M, H,
bit_depth);
} else {
av1_compute_stats_highbd_c(wiener_win, dgd8, src8, dgd_avg, src_avg,
h_start, h_end, v_start, v_end, dgd_stride,
src_stride, M, H, bit_depth);
}
} #endif// CONFIG_AV1_HIGHBITDEPTH
staticinlinevoid acc_stat_win5_one_line_sse4_1( const uint8_t *dgd, const uint8_t *src, int h_start, int h_end, int dgd_stride, const __m128i *shuffle, int32_t *sumX,
int32_t sumY[WIENER_WIN_CHROMA][WIENER_WIN_CHROMA],
int32_t M_int[WIENER_WIN_CHROMA][WIENER_WIN_CHROMA],
int32_t H_int[WIENER_WIN2_CHROMA][WIENER_WIN_CHROMA * 8]) { constint wiener_win = WIENER_WIN_CHROMA; int j, k, l; // Main loop handles two pixels at a time // We can assume that h_start is even, since it will always be aligned to // a tile edge + some number of restoration units, and both of those will // be 64-pixel aligned. // However, at the edge of the image, h_end may be odd, so we need to handle // that case correctly.
assert(h_start % 2 == 0); constint h_end_even = h_end & ~1; constint has_odd_pixel = h_end & 1; for (j = h_start; j < h_end_even; j += 2) { const uint8_t *dgd_ij = dgd + j; const uint8_t X1 = src[j]; const uint8_t X2 = src[j + 1];
*sumX += X1 + X2; for (k = 0; k < wiener_win; k++) { const uint8_t *dgd_ijk = dgd_ij + k * dgd_stride; for (l = 0; l < wiener_win; l++) {
int32_t *H_ = &H_int[(l * wiener_win + k)][0]; const uint8_t D1 = dgd_ijk[l]; const uint8_t D2 = dgd_ijk[l + 1];
sumY[k][l] += D1 + D2;
M_int[k][l] += D1 * X1 + D2 * X2;
// The `acc_stat_sse41` function wants its input to have interleaved // copies of two pixels, but we only have one. However, the pixels // are (effectively) used as inputs to a multiply-accumulate. // So if we set the extra pixel slot to 0, then it is effectively // ignored. const __m128i kl = _mm_cvtepu8_epi16(_mm_set1_epi16((int16_t)D1));
acc_stat_sse41(H_ + 0 * 8, dgd_ij + 0 * dgd_stride, shuffle, &kl);
acc_stat_sse41(H_ + 1 * 8, dgd_ij + 1 * dgd_stride, shuffle, &kl);
acc_stat_sse41(H_ + 2 * 8, dgd_ij + 2 * dgd_stride, shuffle, &kl);
acc_stat_sse41(H_ + 3 * 8, dgd_ij + 3 * dgd_stride, shuffle, &kl);
acc_stat_sse41(H_ + 4 * 8, dgd_ij + 4 * dgd_stride, shuffle, &kl);
}
}
}
}
staticinlinevoid compute_stats_win5_opt_sse4_1( const uint8_t *dgd, const uint8_t *src, int h_start, int h_end, int v_start, int v_end, int dgd_stride, int src_stride, int64_t *M, int64_t *H, int use_downsampled_wiener_stats) { int i, j, k, l, m, n; constint wiener_win = WIENER_WIN_CHROMA; constint pixel_count = (h_end - h_start) * (v_end - v_start); constint wiener_win2 = wiener_win * wiener_win; constint wiener_halfwin = (wiener_win >> 1); const uint8_t avg =
find_average(dgd, h_start, h_end, v_start, v_end, dgd_stride);
// When params->r[0] > 0 and params->r[1] > 0. In this case all elements of // C and H need to be computed. staticinlinevoid calc_proj_params_r0_r1_sse4_1( const uint8_t *src8, int width, int height, int src_stride, const uint8_t *dat8, int dat_stride, int32_t *flt0, int flt0_stride,
int32_t *flt1, int flt1_stride, int64_t H[2][2], int64_t C[2]) { constint size = width * height; const uint8_t *src = src8; const uint8_t *dat = dat8;
__m128i h00, h01, h11, c0, c1; const __m128i zero = _mm_setzero_si128();
h01 = h11 = c0 = c1 = h00 = zero;
for (int i = 0; i < height; ++i) { for (int j = 0; j < width; j += 4) { const __m128i u_load = _mm_cvtepu8_epi32(
_mm_cvtsi32_si128(*((int *)(dat + i * dat_stride + j)))); const __m128i s_load = _mm_cvtepu8_epi32(
_mm_cvtsi32_si128(*((int *)(src + i * src_stride + j))));
__m128i f1 = _mm_loadu_si128((__m128i *)(flt0 + i * flt0_stride + j));
__m128i f2 = _mm_loadu_si128((__m128i *)(flt1 + i * flt1_stride + j));
__m128i d = _mm_slli_epi32(u_load, SGRPROJ_RST_BITS);
__m128i s = _mm_slli_epi32(s_load, SGRPROJ_RST_BITS);
s = _mm_sub_epi32(s, d);
f1 = _mm_sub_epi32(f1, d);
f2 = _mm_sub_epi32(f2, d);
// Using the symmetric properties of H, calculations of H[1][0] are not // needed.
__m128i h1x_low = _mm_unpacklo_epi64(zero, h11); const __m128i h1x_high = _mm_unpackhi_epi64(zero, h11);
h1x_low = _mm_add_epi64(h1x_low, h1x_high);
// Since H is a symmetric matrix
H[1][0] = H[0][1];
C[0] /= size;
C[1] /= size;
}
// When only params->r[0] > 0. In this case only H[0][0] and C[0] are // non-zero and need to be computed. staticinlinevoid calc_proj_params_r0_sse4_1(const uint8_t *src8, int width, int height, int src_stride, const uint8_t *dat8, int dat_stride, int32_t *flt0, int flt0_stride, int64_t H[2][2],
int64_t C[2]) { constint size = width * height; const uint8_t *src = src8; const uint8_t *dat = dat8;
__m128i h00, c0; const __m128i zero = _mm_setzero_si128();
c0 = h00 = zero;
for (int i = 0; i < height; ++i) { for (int j = 0; j < width; j += 4) { const __m128i u_load = _mm_cvtepu8_epi32(
_mm_cvtsi32_si128(*((int *)(dat + i * dat_stride + j)))); const __m128i s_load = _mm_cvtepu8_epi32(
_mm_cvtsi32_si128(*((int *)(src + i * src_stride + j))));
__m128i f1 = _mm_loadu_si128((__m128i *)(flt0 + i * flt0_stride + j));
__m128i d = _mm_slli_epi32(u_load, SGRPROJ_RST_BITS);
__m128i s = _mm_slli_epi32(s_load, SGRPROJ_RST_BITS);
s = _mm_sub_epi32(s, d);
f1 = _mm_sub_epi32(f1, d);
// When only params->r[1] > 0. In this case only H[1][1] and C[1] are // non-zero and need to be computed. staticinlinevoid calc_proj_params_r1_sse4_1(const uint8_t *src8, int width, int height, int src_stride, const uint8_t *dat8, int dat_stride, int32_t *flt1, int flt1_stride, int64_t H[2][2],
int64_t C[2]) { constint size = width * height; const uint8_t *src = src8; const uint8_t *dat = dat8;
__m128i h11, c1; const __m128i zero = _mm_setzero_si128();
c1 = h11 = zero;
for (int i = 0; i < height; ++i) { for (int j = 0; j < width; j += 4) { const __m128i u_load = _mm_cvtepu8_epi32(
_mm_cvtsi32_si128(*((int *)(dat + i * dat_stride + j)))); const __m128i s_load = _mm_cvtepu8_epi32(
_mm_cvtsi32_si128(*((int *)(src + i * src_stride + j))));
__m128i f2 = _mm_loadu_si128((__m128i *)(flt1 + i * flt1_stride + j));
__m128i d = _mm_slli_epi32(u_load, SGRPROJ_RST_BITS);
__m128i s = _mm_slli_epi32(s_load, SGRPROJ_RST_BITS);
s = _mm_sub_epi32(s, d);
f2 = _mm_sub_epi32(f2, d);
// Using the symmetric properties of H, calculations of H[1][0] are not // needed.
__m128i h1x_low = _mm_unpacklo_epi64(zero, h11); const __m128i h1x_high = _mm_unpackhi_epi64(zero, h11);
h1x_low = _mm_add_epi64(h1x_low, h1x_high);
// Since H is a symmetric matrix
H[1][0] = H[0][1];
C[0] /= size;
C[1] /= size;
}
// When only params->r[0] > 0. In this case only H[0][0] and C[0] are // non-zero and need to be computed. staticinlinevoid calc_proj_params_r0_high_bd_sse4_1( const uint8_t *src8, int width, int height, int src_stride, const uint8_t *dat8, int dat_stride, int32_t *flt0, int flt0_stride,
int64_t H[2][2], int64_t C[2]) { constint size = width * height; const uint16_t *src = CONVERT_TO_SHORTPTR(src8); const uint16_t *dat = CONVERT_TO_SHORTPTR(dat8);
__m128i h00, c0; const __m128i zero = _mm_setzero_si128();
c0 = h00 = zero;
for (int i = 0; i < height; ++i) { for (int j = 0; j < width; j += 4) { const __m128i u_load = _mm_cvtepu16_epi32(
_mm_loadl_epi64((__m128i *)(dat + i * dat_stride + j))); const __m128i s_load = _mm_cvtepu16_epi32(
_mm_loadl_epi64((__m128i *)(src + i * src_stride + j)));
__m128i f1 = _mm_loadu_si128((__m128i *)(flt0 + i * flt0_stride + j));
__m128i d = _mm_slli_epi32(u_load, SGRPROJ_RST_BITS);
__m128i s = _mm_slli_epi32(s_load, SGRPROJ_RST_BITS);
s = _mm_sub_epi32(s, d);
f1 = _mm_sub_epi32(f1, d);
// When only params->r[1] > 0. In this case only H[1][1] and C[1] are // non-zero and need to be computed. staticinlinevoid calc_proj_params_r1_high_bd_sse4_1( const uint8_t *src8, int width, int height, int src_stride, const uint8_t *dat8, int dat_stride, int32_t *flt1, int flt1_stride,
int64_t H[2][2], int64_t C[2]) { constint size = width * height; const uint16_t *src = CONVERT_TO_SHORTPTR(src8); const uint16_t *dat = CONVERT_TO_SHORTPTR(dat8);
__m128i h11, c1; const __m128i zero = _mm_setzero_si128();
c1 = h11 = zero;
for (int i = 0; i < height; ++i) { for (int j = 0; j < width; j += 4) { const __m128i u_load = _mm_cvtepu16_epi32(
_mm_loadl_epi64((__m128i *)(dat + i * dat_stride + j))); const __m128i s_load = _mm_cvtepu16_epi32(
_mm_loadl_epi64((__m128i *)(src + i * src_stride + j)));
__m128i f2 = _mm_loadu_si128((__m128i *)(flt1 + i * flt1_stride + j));
__m128i d = _mm_slli_epi32(u_load, SGRPROJ_RST_BITS);
__m128i s = _mm_slli_epi32(s_load, SGRPROJ_RST_BITS);
s = _mm_sub_epi32(s, d);
f2 = _mm_sub_epi32(f2, d);
int64_t av1_highbd_pixel_proj_error_sse4_1( const uint8_t *src8, int width, int height, int src_stride, const uint8_t *dat8, int dat_stride, int32_t *flt0, int flt0_stride,
int32_t *flt1, int flt1_stride, int xq[2], const sgr_params_type *params) { int i, j, k; const int32_t shift = SGRPROJ_RST_BITS + SGRPROJ_PRJ_BITS; const __m128i rounding = _mm_set1_epi32(1 << (shift - 1));
__m128i sum64 = _mm_setzero_si128(); const uint16_t *src = CONVERT_TO_SHORTPTR(src8); const uint16_t *dat = CONVERT_TO_SHORTPTR(dat8);
int64_t err = 0; if (params->r[0] > 0 && params->r[1] > 0) { // Both filters are enabled const __m128i xq0 = _mm_set1_epi32(xq[0]); const __m128i xq1 = _mm_set1_epi32(xq[1]);
for (i = 0; i < height; ++i) {
__m128i sum32 = _mm_setzero_si128(); for (j = 0; j <= width - 8; j += 8) { // Load 8x pixels from source image const __m128i s0 = xx_loadu_128(src + j); // s0 = [7 6 5 4 3 2 1 0] as i16 (indices of src[])
// Load 8x pixels from corrupted image const __m128i d0 = xx_loadu_128(dat + j); // d0 = [7 6 5 4 3 2 1 0] as i16 (indices of dat[])
// Shift each pixel value up by SGRPROJ_RST_BITS const __m128i u0 = _mm_slli_epi16(d0, SGRPROJ_RST_BITS);
// Split u0 into two halves and pad each from u16 to i32 const __m128i u0l = _mm_cvtepu16_epi32(u0); const __m128i u0h = _mm_cvtepu16_epi32(_mm_srli_si128(u0, 8)); // u0h = [7 6 5 4] as i32, u0l = [3 2 1 0] as i32, all dat[] indices
// Load 8 pixels from first and second filtered images const __m128i flt0l = xx_loadu_128(flt0 + j); const __m128i flt0h = xx_loadu_128(flt0 + j + 4); const __m128i flt1l = xx_loadu_128(flt1 + j); const __m128i flt1h = xx_loadu_128(flt1 + j + 4); // flt0 = [7 6 5 4] [3 2 1 0] as i32 (indices of flt0+j) // flt1 = [7 6 5 4] [3 2 1 0] as i32 (indices of flt1+j)
// Subtract shifted corrupt image from each filtered image // This gives our two basis vectors for the projection const __m128i flt0l_subu = _mm_sub_epi32(flt0l, u0l); const __m128i flt0h_subu = _mm_sub_epi32(flt0h, u0h); const __m128i flt1l_subu = _mm_sub_epi32(flt1l, u0l); const __m128i flt1h_subu = _mm_sub_epi32(flt1h, u0h); // flt?h_subu = [ f[7]-u[7] f[6]-u[6] f[5]-u[5] f[4]-u[4] ] as i32 // flt?l_subu = [ f[3]-u[3] f[2]-u[2] f[1]-u[1] f[0]-u[0] ] as i32
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.