• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2023, Alliance for Open Media. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <arm_neon.h>
12 #include <assert.h>
13 
14 #include "config/aom_config.h"
15 #include "config/aom_dsp_rtcd.h"
16 #include "aom/aom_integer.h"
17 #include "aom_dsp/arm/aom_neon_sve_bridge.h"
18 #include "aom_dsp/arm/mem_neon.h"
19 #include "aom_ports/mem.h"
20 
aom_vector_var_sve(const int16_t * ref,const int16_t * src,int bwl)21 int aom_vector_var_sve(const int16_t *ref, const int16_t *src, int bwl) {
22   assert(bwl >= 2 && bwl <= 5);
23   int width = 4 << bwl;
24 
25   int64x2_t sse_s64[2] = { vdupq_n_s64(0), vdupq_n_s64(0) };
26   int16x8_t v_mean[2] = { vdupq_n_s16(0), vdupq_n_s16(0) };
27 
28   do {
29     int16x8_t r0 = vld1q_s16(ref);
30     int16x8_t s0 = vld1q_s16(src);
31 
32     // diff: dynamic range [-510, 510] 10 (signed) bits.
33     int16x8_t diff0 = vsubq_s16(r0, s0);
34     // v_mean: dynamic range 16 * diff -> [-8160, 8160], 14 (signed) bits.
35     v_mean[0] = vaddq_s16(v_mean[0], diff0);
36 
37     // v_sse: dynamic range 2 * 16 * diff^2 -> [0, 8,323,200], 24 (signed) bits.
38     sse_s64[0] = aom_sdotq_s16(sse_s64[0], diff0, diff0);
39 
40     int16x8_t r1 = vld1q_s16(ref + 8);
41     int16x8_t s1 = vld1q_s16(src + 8);
42 
43     // diff: dynamic range [-510, 510] 10 (signed) bits.
44     int16x8_t diff1 = vsubq_s16(r1, s1);
45     // v_mean: dynamic range 16 * diff -> [-8160, 8160], 14 (signed) bits.
46     v_mean[1] = vaddq_s16(v_mean[1], diff1);
47 
48     // v_sse: dynamic range 2 * 16 * diff^2 -> [0, 8,323,200], 24 (signed) bits.
49     sse_s64[1] = aom_sdotq_s16(sse_s64[1], diff1, diff1);
50 
51     ref += 16;
52     src += 16;
53     width -= 16;
54   } while (width != 0);
55 
56   // Dynamic range [0, 65280], 16 (unsigned) bits.
57   const uint32_t mean_abs = abs(vaddlvq_s16(vaddq_s16(v_mean[0], v_mean[1])));
58   const int64_t sse = vaddvq_s64(vaddq_s64(sse_s64[0], sse_s64[1]));
59 
60   // (mean_abs * mean_abs): dynamic range 32 (unsigned) bits.
61   return (int)(sse - ((mean_abs * mean_abs) >> (bwl + 2)));
62 }
63