xref: /aosp_15_r20/external/libvpx/vpx_dsp/arm/sum_squares_sve.c (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
1 /*
2  *  Copyright (c) 2024 The WebM project authors. 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 "./vpx_dsp_rtcd.h"
15 #include "vpx_dsp/arm/mem_neon.h"
16 #include "vpx_dsp/arm/sum_neon.h"
17 #include "vpx_dsp/arm/vpx_neon_sve_bridge.h"
18 
vpx_sum_squares_2d_i16_sve(const int16_t * src,int stride,int size)19 uint64_t vpx_sum_squares_2d_i16_sve(const int16_t *src, int stride, int size) {
20   if (size == 4) {
21     int16x4_t s[4];
22     int64x2_t sum = vdupq_n_s64(0);
23 
24     s[0] = vld1_s16(src + 0 * stride);
25     s[1] = vld1_s16(src + 1 * stride);
26     s[2] = vld1_s16(src + 2 * stride);
27     s[3] = vld1_s16(src + 3 * stride);
28 
29     int16x8_t s01 = vcombine_s16(s[0], s[1]);
30     int16x8_t s23 = vcombine_s16(s[2], s[3]);
31 
32     sum = vpx_dotq_s16(sum, s01, s01);
33     sum = vpx_dotq_s16(sum, s23, s23);
34 
35     return horizontal_add_uint64x2(vreinterpretq_u64_s64(sum));
36   } else {
37     int rows = size;
38     int64x2_t sum[4] = { vdupq_n_s64(0), vdupq_n_s64(0), vdupq_n_s64(0),
39                          vdupq_n_s64(0) };
40 
41     do {
42       const int16_t *src_ptr = src;
43       int cols = size;
44 
45       do {
46         int16x8_t s[8];
47         load_s16_8x8(src_ptr, stride, &s[0], &s[1], &s[2], &s[3], &s[4], &s[5],
48                      &s[6], &s[7]);
49 
50         sum[0] = vpx_dotq_s16(sum[0], s[0], s[0]);
51         sum[1] = vpx_dotq_s16(sum[1], s[1], s[1]);
52         sum[2] = vpx_dotq_s16(sum[2], s[2], s[2]);
53         sum[3] = vpx_dotq_s16(sum[3], s[3], s[3]);
54         sum[0] = vpx_dotq_s16(sum[0], s[4], s[4]);
55         sum[1] = vpx_dotq_s16(sum[1], s[5], s[5]);
56         sum[2] = vpx_dotq_s16(sum[2], s[6], s[6]);
57         sum[3] = vpx_dotq_s16(sum[3], s[7], s[7]);
58 
59         src_ptr += 8;
60         cols -= 8;
61       } while (cols);
62 
63       src += 8 * stride;
64       rows -= 8;
65     } while (rows);
66 
67     sum[0] = vaddq_s64(sum[0], sum[1]);
68     sum[2] = vaddq_s64(sum[2], sum[3]);
69     sum[0] = vaddq_s64(sum[0], sum[2]);
70 
71     return horizontal_add_uint64x2(vreinterpretq_u64_s64(sum[0]));
72   }
73 }
74