subpel variance neon: reduce stack usage

Unlike x86, arm does not impose additional alignment restrictions on
vector loads. For incoming values to the first pass, it uses vld1_u32()
which typically does impose a 4 byte alignment. However, as the first
pass operates on user-supplied values we must prepare for unaligned
values anyway (and have, see mem_neon.h).

But for the local temporary values there is no stride and the load will
use vld1_u8 which does not require 4 byte alignment.

There are 3 temporary structures. In the C, one is uint16_t. The arm
saturates between passes but still passes tests. If this becomes an
issue new functions will be needed.

Change-Id: I3c9d4701bfeb14b77c783d0164608e621bfecfb1
This commit is contained in:
Johann 2017-05-24 11:52:42 -07:00
parent d204c4bf01
commit f3c97ed32e

View File

@ -12,7 +12,6 @@
#include "./vpx_dsp_rtcd.h"
#include "./vpx_config.h"
#include "vpx_ports/mem.h"
#include "vpx/vpx_integer.h"
#include "vpx_dsp/variance.h"
@ -40,8 +39,7 @@ static void var_filter_block2d_bil_w4(const uint8_t *src_ptr,
const uint16x8_t a = vmull_u8(src_0, f0);
const uint16x8_t b = vmlal_u8(a, src_1, f1);
const uint8x8_t out = vrshrn_n_u16(b, FILTER_BITS);
store_unaligned_u8(output_ptr, 4, out);
// Next row...
vst1_u8(output_ptr, out);
src_ptr += 2 * src_pixels_per_line;
output_ptr += 8;
}
@ -63,8 +61,7 @@ static void var_filter_block2d_bil_w8(const uint8_t *src_ptr,
const uint16x8_t a = vmull_u8(src_0, f0);
const uint16x8_t b = vmlal_u8(a, src_1, f1);
const uint8x8_t out = vrshrn_n_u16(b, FILTER_BITS);
vst1_u8(&output_ptr[0], out);
// Next row...
vst1_u8(output_ptr, out);
src_ptr += src_pixels_per_line;
output_ptr += 8;
}
@ -91,9 +88,8 @@ static void var_filter_block2d_bil_w16(const uint8_t *src_ptr,
const uint16x8_t c = vmull_u8(vget_high_u8(src_0), f0);
const uint16x8_t d = vmlal_u8(c, vget_high_u8(src_1), f1);
const uint8x8_t out_hi = vrshrn_n_u16(d, FILTER_BITS);
vst1q_u8(&output_ptr[j], vcombine_u8(out_lo, out_hi));
vst1q_u8(output_ptr + j, vcombine_u8(out_lo, out_hi));
}
// Next row...
src_ptr += src_pixels_per_line;
output_ptr += output_width;
}
@ -101,30 +97,30 @@ static void var_filter_block2d_bil_w16(const uint8_t *src_ptr,
// 4xM filter writes an extra row to fdata because it processes two rows at a
// time.
#define sub_pixel_varianceNxM(n, m) \
uint32_t vpx_sub_pixel_variance##n##x##m##_neon( \
const uint8_t *a, int a_stride, int xoffset, int yoffset, \
const uint8_t *b, int b_stride, uint32_t *sse) { \
DECLARE_ALIGNED(16, uint8_t, fdata3[n * (m + (n == 4 ? 2 : 1))]); \
DECLARE_ALIGNED(16, uint8_t, temp2[n * m]); \
\
if (n == 4) { \
var_filter_block2d_bil_w4(a, fdata3, a_stride, 1, (m + 2), \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w4(fdata3, temp2, n, n, m, \
bilinear_filters[yoffset]); \
} else if (n == 8) { \
var_filter_block2d_bil_w8(a, fdata3, a_stride, 1, (m + 1), \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w8(fdata3, temp2, n, n, m, \
bilinear_filters[yoffset]); \
} else { \
var_filter_block2d_bil_w16(a, fdata3, a_stride, 1, (m + 1), n, \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w16(fdata3, temp2, n, n, m, n, \
bilinear_filters[yoffset]); \
} \
return vpx_variance##n##x##m(temp2, n, b, b_stride, sse); \
#define sub_pixel_varianceNxM(n, m) \
uint32_t vpx_sub_pixel_variance##n##x##m##_neon( \
const uint8_t *a, int a_stride, int xoffset, int yoffset, \
const uint8_t *b, int b_stride, uint32_t *sse) { \
uint8_t temp0[n * (m + (n == 4 ? 2 : 1))]; \
uint8_t temp1[n * m]; \
\
if (n == 4) { \
var_filter_block2d_bil_w4(a, temp0, a_stride, 1, (m + 2), \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w4(temp0, temp1, n, n, m, \
bilinear_filters[yoffset]); \
} else if (n == 8) { \
var_filter_block2d_bil_w8(a, temp0, a_stride, 1, (m + 1), \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w8(temp0, temp1, n, n, m, \
bilinear_filters[yoffset]); \
} else { \
var_filter_block2d_bil_w16(a, temp0, a_stride, 1, (m + 1), n, \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w16(temp0, temp1, n, n, m, n, \
bilinear_filters[yoffset]); \
} \
return vpx_variance##n##x##m(temp1, n, b, b_stride, sse); \
}
sub_pixel_varianceNxM(4, 4);
@ -143,35 +139,34 @@ sub_pixel_varianceNxM(64, 64);
// 4xM filter writes an extra row to fdata because it processes two rows at a
// time.
#define sub_pixel_avg_varianceNxM(n, m) \
uint32_t vpx_sub_pixel_avg_variance##n##x##m##_neon( \
const uint8_t *a, int a_stride, int xoffset, int yoffset, \
const uint8_t *b, int b_stride, uint32_t *sse, \
const uint8_t *second_pred) { \
DECLARE_ALIGNED(16, uint8_t, fdata3[n * (m + (n == 4 ? 2 : 1))]); \
DECLARE_ALIGNED(16, uint8_t, temp2[n * m]); \
DECLARE_ALIGNED(16, uint8_t, temp3[n * m]); \
\
if (n == 4) { \
var_filter_block2d_bil_w4(a, fdata3, a_stride, 1, (m + 2), \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w4(fdata3, temp2, n, n, m, \
bilinear_filters[yoffset]); \
} else if (n == 8) { \
var_filter_block2d_bil_w8(a, fdata3, a_stride, 1, (m + 1), \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w8(fdata3, temp2, n, n, m, \
bilinear_filters[yoffset]); \
} else { \
var_filter_block2d_bil_w16(a, fdata3, a_stride, 1, (m + 1), n, \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w16(fdata3, temp2, n, n, m, n, \
bilinear_filters[yoffset]); \
} \
\
vpx_comp_avg_pred(temp3, second_pred, n, m, temp2, n); \
\
return vpx_variance##n##x##m(temp3, n, b, b_stride, sse); \
#define sub_pixel_avg_varianceNxM(n, m) \
uint32_t vpx_sub_pixel_avg_variance##n##x##m##_neon( \
const uint8_t *a, int a_stride, int xoffset, int yoffset, \
const uint8_t *b, int b_stride, uint32_t *sse, \
const uint8_t *second_pred) { \
uint8_t temp0[n * (m + (n == 4 ? 2 : 1))]; \
uint8_t temp1[n * m]; \
\
if (n == 4) { \
var_filter_block2d_bil_w4(a, temp0, a_stride, 1, (m + 2), \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w4(temp0, temp1, n, n, m, \
bilinear_filters[yoffset]); \
} else if (n == 8) { \
var_filter_block2d_bil_w8(a, temp0, a_stride, 1, (m + 1), \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w8(temp0, temp1, n, n, m, \
bilinear_filters[yoffset]); \
} else { \
var_filter_block2d_bil_w16(a, temp0, a_stride, 1, (m + 1), n, \
bilinear_filters[xoffset]); \
var_filter_block2d_bil_w16(temp0, temp1, n, n, m, n, \
bilinear_filters[yoffset]); \
} \
\
vpx_comp_avg_pred(temp0, second_pred, n, m, temp1, n); \
\
return vpx_variance##n##x##m(temp0, n, b, b_stride, sse); \
}
sub_pixel_avg_varianceNxM(4, 4);