2014-07-16 21:54:46 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arm_neon.h>
|
2015-04-17 22:11:38 +02:00
|
|
|
|
2014-07-16 21:54:46 +02:00
|
|
|
#include "./vpx_config.h"
|
|
|
|
|
|
|
|
#include "vpx/vpx_integer.h"
|
2017-06-27 21:44:54 +02:00
|
|
|
#include "vpx_dsp/arm/mem_neon.h"
|
2014-07-16 21:54:46 +02:00
|
|
|
|
2017-06-27 21:44:54 +02:00
|
|
|
// TODO(johannkoenig): combine with avg_neon.h version.
|
|
|
|
static INLINE uint32_t horizontal_add_16x8(const uint16x8_t vec_16x8) {
|
|
|
|
const uint32x4_t a = vpaddlq_u16(vec_16x8);
|
|
|
|
const uint64x2_t b = vpaddlq_u32(a);
|
|
|
|
const uint32x2_t c = vadd_u32(vreinterpret_u32_u64(vget_low_u64(b)),
|
|
|
|
vreinterpret_u32_u64(vget_high_u64(b)));
|
|
|
|
return vget_lane_u32(c, 0);
|
|
|
|
}
|
2016-07-23 05:07:03 +02:00
|
|
|
|
2017-06-27 21:44:54 +02:00
|
|
|
uint32_t vpx_sad4x4_neon(const uint8_t *src_ptr, int src_stride,
|
|
|
|
const uint8_t *ref_ptr, int ref_stride) {
|
|
|
|
const uint8x16_t src_u8 = load_unaligned_u8q(src_ptr, src_stride);
|
|
|
|
const uint8x16_t ref_u8 = load_unaligned_u8q(ref_ptr, ref_stride);
|
|
|
|
uint16x8_t abs = vabdl_u8(vget_low_u8(src_u8), vget_low_u8(ref_u8));
|
|
|
|
abs = vabal_u8(abs, vget_high_u8(src_u8), vget_high_u8(ref_u8));
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
2015-04-17 22:11:38 +02:00
|
|
|
|
2017-06-28 22:20:13 +02:00
|
|
|
uint32_t vpx_sad4x4_avg_neon(const uint8_t *src_ptr, int src_stride,
|
|
|
|
const uint8_t *ref_ptr, int ref_stride,
|
|
|
|
const uint8_t *second_pred) {
|
|
|
|
const uint8x16_t src_u8 = load_unaligned_u8q(src_ptr, src_stride);
|
|
|
|
const uint8x16_t ref_u8 = load_unaligned_u8q(ref_ptr, ref_stride);
|
|
|
|
const uint8x16_t second_pred_u8 = vld1q_u8(second_pred);
|
|
|
|
const uint8x16_t avg = vrhaddq_u8(ref_u8, second_pred_u8);
|
|
|
|
uint16x8_t abs = vabdl_u8(vget_low_u8(src_u8), vget_low_u8(avg));
|
|
|
|
abs = vabal_u8(abs, vget_high_u8(src_u8), vget_high_u8(avg));
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
2017-06-27 21:44:54 +02:00
|
|
|
uint32_t vpx_sad4x8_neon(const uint8_t *src_ptr, int src_stride,
|
|
|
|
const uint8_t *ref_ptr, int ref_stride) {
|
|
|
|
int i;
|
|
|
|
uint16x8_t abs = vdupq_n_u16(0);
|
|
|
|
for (i = 0; i < 8; i += 4) {
|
|
|
|
const uint8x16_t src_u8 = load_unaligned_u8q(src_ptr, src_stride);
|
|
|
|
const uint8x16_t ref_u8 = load_unaligned_u8q(ref_ptr, ref_stride);
|
|
|
|
src_ptr += 4 * src_stride;
|
|
|
|
ref_ptr += 4 * ref_stride;
|
|
|
|
abs = vabal_u8(abs, vget_low_u8(src_u8), vget_low_u8(ref_u8));
|
|
|
|
abs = vabal_u8(abs, vget_high_u8(src_u8), vget_high_u8(ref_u8));
|
2016-07-23 05:07:03 +02:00
|
|
|
}
|
2015-04-17 22:11:38 +02:00
|
|
|
|
2017-06-27 21:44:54 +02:00
|
|
|
return horizontal_add_16x8(abs);
|
2015-04-17 22:11:38 +02:00
|
|
|
}
|
|
|
|
|
2017-06-28 22:20:13 +02:00
|
|
|
uint32_t vpx_sad4x8_avg_neon(const uint8_t *src_ptr, int src_stride,
|
|
|
|
const uint8_t *ref_ptr, int ref_stride,
|
|
|
|
const uint8_t *second_pred) {
|
|
|
|
int i;
|
|
|
|
uint16x8_t abs = vdupq_n_u16(0);
|
|
|
|
for (i = 0; i < 8; i += 4) {
|
|
|
|
const uint8x16_t src_u8 = load_unaligned_u8q(src_ptr, src_stride);
|
|
|
|
const uint8x16_t ref_u8 = load_unaligned_u8q(ref_ptr, ref_stride);
|
|
|
|
const uint8x16_t second_pred_u8 = vld1q_u8(second_pred);
|
|
|
|
const uint8x16_t avg = vrhaddq_u8(ref_u8, second_pred_u8);
|
|
|
|
src_ptr += 4 * src_stride;
|
|
|
|
ref_ptr += 4 * ref_stride;
|
|
|
|
second_pred += 16;
|
|
|
|
abs = vabal_u8(abs, vget_low_u8(src_u8), vget_low_u8(avg));
|
|
|
|
abs = vabal_u8(abs, vget_high_u8(src_u8), vget_high_u8(avg));
|
|
|
|
}
|
|
|
|
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
2017-06-27 22:02:28 +02:00
|
|
|
static INLINE uint16x8_t sad8x(const uint8_t *a, int a_stride, const uint8_t *b,
|
|
|
|
int b_stride, const int height) {
|
|
|
|
int i;
|
|
|
|
uint16x8_t abs = vdupq_n_u16(0);
|
|
|
|
|
|
|
|
for (i = 0; i < height; ++i) {
|
|
|
|
const uint8x8_t a_u8 = vld1_u8(a);
|
|
|
|
const uint8x8_t b_u8 = vld1_u8(b);
|
|
|
|
a += a_stride;
|
|
|
|
b += b_stride;
|
|
|
|
abs = vabal_u8(abs, a_u8, b_u8);
|
|
|
|
}
|
|
|
|
return abs;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad8x4_neon(const uint8_t *src, int src_stride, const uint8_t *ref,
|
|
|
|
int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad8x(src, src_stride, ref, ref_stride, 4);
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad8x8_neon(const uint8_t *src, int src_stride, const uint8_t *ref,
|
|
|
|
int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad8x(src, src_stride, ref, ref_stride, 8);
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad8x16_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad8x(src, src_stride, ref, ref_stride, 16);
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
2017-06-27 23:15:58 +02:00
|
|
|
static INLINE uint16x8_t sad16x(const uint8_t *a, int a_stride,
|
|
|
|
const uint8_t *b, int b_stride,
|
|
|
|
const int height) {
|
2016-07-23 05:07:03 +02:00
|
|
|
int i;
|
2017-06-27 23:15:58 +02:00
|
|
|
uint16x8_t abs = vdupq_n_u16(0);
|
2016-07-23 05:07:03 +02:00
|
|
|
|
2017-06-27 23:15:58 +02:00
|
|
|
for (i = 0; i < height; ++i) {
|
|
|
|
const uint8x16_t a_u8 = vld1q_u8(a);
|
|
|
|
const uint8x16_t b_u8 = vld1q_u8(b);
|
|
|
|
a += a_stride;
|
|
|
|
b += b_stride;
|
|
|
|
abs = vabal_u8(abs, vget_low_u8(a_u8), vget_low_u8(b_u8));
|
|
|
|
abs = vabal_u8(abs, vget_high_u8(a_u8), vget_high_u8(b_u8));
|
2016-07-23 05:07:03 +02:00
|
|
|
}
|
2017-06-27 23:15:58 +02:00
|
|
|
return abs;
|
|
|
|
}
|
2016-07-23 05:07:03 +02:00
|
|
|
|
2017-06-27 23:15:58 +02:00
|
|
|
uint32_t vpx_sad16x8_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad16x(src, src_stride, ref, ref_stride, 8);
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad16x16_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad16x(src, src_stride, ref, ref_stride, 16);
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
2016-07-23 05:07:03 +02:00
|
|
|
|
2017-06-27 23:15:58 +02:00
|
|
|
uint32_t vpx_sad16x32_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad16x(src, src_stride, ref, ref_stride, 32);
|
|
|
|
return horizontal_add_16x8(abs);
|
2015-04-17 22:11:38 +02:00
|
|
|
}
|
|
|
|
|
2017-06-27 23:33:28 +02:00
|
|
|
static INLINE uint16x8_t sad32x(const uint8_t *a, int a_stride,
|
|
|
|
const uint8_t *b, int b_stride,
|
|
|
|
const int height) {
|
|
|
|
int i;
|
|
|
|
uint16x8_t abs = vdupq_n_u16(0);
|
|
|
|
|
|
|
|
for (i = 0; i < height; ++i) {
|
|
|
|
const uint8x16_t a_lo = vld1q_u8(a);
|
|
|
|
const uint8x16_t a_hi = vld1q_u8(a + 16);
|
|
|
|
const uint8x16_t b_lo = vld1q_u8(b);
|
|
|
|
const uint8x16_t b_hi = vld1q_u8(b + 16);
|
|
|
|
a += a_stride;
|
|
|
|
b += b_stride;
|
|
|
|
abs = vabal_u8(abs, vget_low_u8(a_lo), vget_low_u8(b_lo));
|
|
|
|
abs = vabal_u8(abs, vget_high_u8(a_lo), vget_high_u8(b_lo));
|
|
|
|
abs = vabal_u8(abs, vget_low_u8(a_hi), vget_low_u8(b_hi));
|
|
|
|
abs = vabal_u8(abs, vget_high_u8(a_hi), vget_high_u8(b_hi));
|
|
|
|
}
|
|
|
|
return abs;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad32x16_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad32x(src, src_stride, ref, ref_stride, 16);
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad32x32_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad32x(src, src_stride, ref, ref_stride, 32);
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad32x64_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint16x8_t abs = sad32x(src, src_stride, ref, ref_stride, 64);
|
|
|
|
return horizontal_add_16x8(abs);
|
|
|
|
}
|
|
|
|
|
2017-06-28 00:17:31 +02:00
|
|
|
static INLINE uint32_t horizontal_add_32x4(const uint32x4_t a) {
|
2014-07-16 21:54:46 +02:00
|
|
|
const uint64x2_t b = vpaddlq_u32(a);
|
|
|
|
const uint32x2_t c = vadd_u32(vreinterpret_u32_u64(vget_low_u64(b)),
|
|
|
|
vreinterpret_u32_u64(vget_high_u64(b)));
|
|
|
|
return vget_lane_u32(c, 0);
|
|
|
|
}
|
|
|
|
|
2017-06-28 00:17:31 +02:00
|
|
|
static INLINE uint32x4_t sad64x(const uint8_t *a, int a_stride,
|
|
|
|
const uint8_t *b, int b_stride,
|
|
|
|
const int height) {
|
2014-07-16 21:54:46 +02:00
|
|
|
int i;
|
2017-06-28 00:17:31 +02:00
|
|
|
uint16x8_t abs_0 = vdupq_n_u16(0);
|
|
|
|
uint16x8_t abs_1 = vdupq_n_u16(0);
|
|
|
|
|
|
|
|
for (i = 0; i < height; ++i) {
|
|
|
|
const uint8x16_t a_0 = vld1q_u8(a);
|
|
|
|
const uint8x16_t a_1 = vld1q_u8(a + 16);
|
|
|
|
const uint8x16_t a_2 = vld1q_u8(a + 32);
|
|
|
|
const uint8x16_t a_3 = vld1q_u8(a + 48);
|
|
|
|
const uint8x16_t b_0 = vld1q_u8(b);
|
|
|
|
const uint8x16_t b_1 = vld1q_u8(b + 16);
|
|
|
|
const uint8x16_t b_2 = vld1q_u8(b + 32);
|
|
|
|
const uint8x16_t b_3 = vld1q_u8(b + 48);
|
|
|
|
a += a_stride;
|
|
|
|
b += b_stride;
|
|
|
|
abs_0 = vabal_u8(abs_0, vget_low_u8(a_0), vget_low_u8(b_0));
|
|
|
|
abs_0 = vabal_u8(abs_0, vget_high_u8(a_0), vget_high_u8(b_0));
|
|
|
|
abs_0 = vabal_u8(abs_0, vget_low_u8(a_1), vget_low_u8(b_1));
|
|
|
|
abs_0 = vabal_u8(abs_0, vget_high_u8(a_1), vget_high_u8(b_1));
|
|
|
|
abs_1 = vabal_u8(abs_1, vget_low_u8(a_2), vget_low_u8(b_2));
|
|
|
|
abs_1 = vabal_u8(abs_1, vget_high_u8(a_2), vget_high_u8(b_2));
|
|
|
|
abs_1 = vabal_u8(abs_1, vget_low_u8(a_3), vget_low_u8(b_3));
|
|
|
|
abs_1 = vabal_u8(abs_1, vget_high_u8(a_3), vget_high_u8(b_3));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const uint32x4_t sum = vpaddlq_u16(abs_0);
|
|
|
|
return vpadalq_u16(sum, abs_1);
|
2014-07-16 21:54:46 +02:00
|
|
|
}
|
2017-06-28 00:17:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad64x32_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint32x4_t abs = sad64x(src, src_stride, ref, ref_stride, 32);
|
|
|
|
return horizontal_add_32x4(abs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t vpx_sad64x64_neon(const uint8_t *src, int src_stride,
|
|
|
|
const uint8_t *ref, int ref_stride) {
|
|
|
|
const uint32x4_t abs = sad64x(src, src_stride, ref, ref_stride, 64);
|
|
|
|
return horizontal_add_32x4(abs);
|
2014-07-16 21:54:46 +02:00
|
|
|
}
|