xref: /aosp_15_r20/external/libvpx/vpx_dsp/arm/highbd_hadamard_neon.c (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
1 /*
2  *  Copyright (c) 2023 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 
13 #include "./vpx_dsp_rtcd.h"
14 #include "./vpx_config.h"
15 
16 #include "vpx_dsp/arm/mem_neon.h"
17 #include "vpx_dsp/arm/transpose_neon.h"
18 
hadamard_highbd_col8_first_pass(int16x8_t * a0,int16x8_t * a1,int16x8_t * a2,int16x8_t * a3,int16x8_t * a4,int16x8_t * a5,int16x8_t * a6,int16x8_t * a7)19 static INLINE void hadamard_highbd_col8_first_pass(int16x8_t *a0, int16x8_t *a1,
20                                                    int16x8_t *a2, int16x8_t *a3,
21                                                    int16x8_t *a4, int16x8_t *a5,
22                                                    int16x8_t *a6,
23                                                    int16x8_t *a7) {
24   int16x8_t b0 = vaddq_s16(*a0, *a1);
25   int16x8_t b1 = vsubq_s16(*a0, *a1);
26   int16x8_t b2 = vaddq_s16(*a2, *a3);
27   int16x8_t b3 = vsubq_s16(*a2, *a3);
28   int16x8_t b4 = vaddq_s16(*a4, *a5);
29   int16x8_t b5 = vsubq_s16(*a4, *a5);
30   int16x8_t b6 = vaddq_s16(*a6, *a7);
31   int16x8_t b7 = vsubq_s16(*a6, *a7);
32 
33   int16x8_t c0 = vaddq_s16(b0, b2);
34   int16x8_t c2 = vsubq_s16(b0, b2);
35   int16x8_t c1 = vaddq_s16(b1, b3);
36   int16x8_t c3 = vsubq_s16(b1, b3);
37   int16x8_t c4 = vaddq_s16(b4, b6);
38   int16x8_t c6 = vsubq_s16(b4, b6);
39   int16x8_t c5 = vaddq_s16(b5, b7);
40   int16x8_t c7 = vsubq_s16(b5, b7);
41 
42   *a0 = vaddq_s16(c0, c4);
43   *a2 = vsubq_s16(c0, c4);
44   *a7 = vaddq_s16(c1, c5);
45   *a6 = vsubq_s16(c1, c5);
46   *a3 = vaddq_s16(c2, c6);
47   *a1 = vsubq_s16(c2, c6);
48   *a4 = vaddq_s16(c3, c7);
49   *a5 = vsubq_s16(c3, c7);
50 }
51 
hadamard_highbd_col4_second_pass(int16x4_t a0,int16x4_t a1,int16x4_t a2,int16x4_t a3,int16x4_t a4,int16x4_t a5,int16x4_t a6,int16x4_t a7,tran_low_t * coeff)52 static INLINE void hadamard_highbd_col4_second_pass(int16x4_t a0, int16x4_t a1,
53                                                     int16x4_t a2, int16x4_t a3,
54                                                     int16x4_t a4, int16x4_t a5,
55                                                     int16x4_t a6, int16x4_t a7,
56                                                     tran_low_t *coeff) {
57   int32x4_t b0 = vaddl_s16(a0, a1);
58   int32x4_t b1 = vsubl_s16(a0, a1);
59   int32x4_t b2 = vaddl_s16(a2, a3);
60   int32x4_t b3 = vsubl_s16(a2, a3);
61   int32x4_t b4 = vaddl_s16(a4, a5);
62   int32x4_t b5 = vsubl_s16(a4, a5);
63   int32x4_t b6 = vaddl_s16(a6, a7);
64   int32x4_t b7 = vsubl_s16(a6, a7);
65 
66   int32x4_t c0 = vaddq_s32(b0, b2);
67   int32x4_t c2 = vsubq_s32(b0, b2);
68   int32x4_t c1 = vaddq_s32(b1, b3);
69   int32x4_t c3 = vsubq_s32(b1, b3);
70   int32x4_t c4 = vaddq_s32(b4, b6);
71   int32x4_t c6 = vsubq_s32(b4, b6);
72   int32x4_t c5 = vaddq_s32(b5, b7);
73   int32x4_t c7 = vsubq_s32(b5, b7);
74 
75   int32x4_t d0 = vaddq_s32(c0, c4);
76   int32x4_t d2 = vsubq_s32(c0, c4);
77   int32x4_t d7 = vaddq_s32(c1, c5);
78   int32x4_t d6 = vsubq_s32(c1, c5);
79   int32x4_t d3 = vaddq_s32(c2, c6);
80   int32x4_t d1 = vsubq_s32(c2, c6);
81   int32x4_t d4 = vaddq_s32(c3, c7);
82   int32x4_t d5 = vsubq_s32(c3, c7);
83 
84   store_s32q_to_tran_low(coeff + 0, d0);
85   store_s32q_to_tran_low(coeff + 4, d1);
86   store_s32q_to_tran_low(coeff + 8, d2);
87   store_s32q_to_tran_low(coeff + 12, d3);
88   store_s32q_to_tran_low(coeff + 16, d4);
89   store_s32q_to_tran_low(coeff + 20, d5);
90   store_s32q_to_tran_low(coeff + 24, d6);
91   store_s32q_to_tran_low(coeff + 28, d7);
92 }
93 
vpx_highbd_hadamard_8x8_neon(const int16_t * src_diff,ptrdiff_t src_stride,tran_low_t * coeff)94 void vpx_highbd_hadamard_8x8_neon(const int16_t *src_diff, ptrdiff_t src_stride,
95                                   tran_low_t *coeff) {
96   int16x4_t b0, b1, b2, b3, b4, b5, b6, b7;
97 
98   int16x8_t s0 = vld1q_s16(src_diff + 0 * src_stride);
99   int16x8_t s1 = vld1q_s16(src_diff + 1 * src_stride);
100   int16x8_t s2 = vld1q_s16(src_diff + 2 * src_stride);
101   int16x8_t s3 = vld1q_s16(src_diff + 3 * src_stride);
102   int16x8_t s4 = vld1q_s16(src_diff + 4 * src_stride);
103   int16x8_t s5 = vld1q_s16(src_diff + 5 * src_stride);
104   int16x8_t s6 = vld1q_s16(src_diff + 6 * src_stride);
105   int16x8_t s7 = vld1q_s16(src_diff + 7 * src_stride);
106 
107   // For the first pass we can stay in 16-bit elements (4095*8 = 32760).
108   hadamard_highbd_col8_first_pass(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7);
109 
110   transpose_s16_8x8(&s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7);
111 
112   // For the second pass we need to widen to 32-bit elements, so we're
113   // processing 4 columns at a time.
114   // Skip the second transpose because it is not required.
115 
116   b0 = vget_low_s16(s0);
117   b1 = vget_low_s16(s1);
118   b2 = vget_low_s16(s2);
119   b3 = vget_low_s16(s3);
120   b4 = vget_low_s16(s4);
121   b5 = vget_low_s16(s5);
122   b6 = vget_low_s16(s6);
123   b7 = vget_low_s16(s7);
124 
125   hadamard_highbd_col4_second_pass(b0, b1, b2, b3, b4, b5, b6, b7, coeff);
126 
127   b0 = vget_high_s16(s0);
128   b1 = vget_high_s16(s1);
129   b2 = vget_high_s16(s2);
130   b3 = vget_high_s16(s3);
131   b4 = vget_high_s16(s4);
132   b5 = vget_high_s16(s5);
133   b6 = vget_high_s16(s6);
134   b7 = vget_high_s16(s7);
135 
136   hadamard_highbd_col4_second_pass(b0, b1, b2, b3, b4, b5, b6, b7, coeff + 32);
137 }
138 
vpx_highbd_hadamard_16x16_neon(const int16_t * src_diff,ptrdiff_t src_stride,tran_low_t * coeff)139 void vpx_highbd_hadamard_16x16_neon(const int16_t *src_diff,
140                                     ptrdiff_t src_stride, tran_low_t *coeff) {
141   int i = 0;
142 
143   // Rearrange 16x16 to 8x32 and remove stride.
144   // Top left first.
145   vpx_highbd_hadamard_8x8_neon(src_diff, src_stride, coeff);
146   // Top right.
147   vpx_highbd_hadamard_8x8_neon(src_diff + 8, src_stride, coeff + 64);
148   // Bottom left.
149   vpx_highbd_hadamard_8x8_neon(src_diff + 8 * src_stride, src_stride,
150                                coeff + 128);
151   // Bottom right.
152   vpx_highbd_hadamard_8x8_neon(src_diff + 8 * src_stride + 8, src_stride,
153                                coeff + 192);
154 
155   do {
156     int32x4_t a0 = load_tran_low_to_s32q(coeff + 4 * i);
157     int32x4_t a1 = load_tran_low_to_s32q(coeff + 4 * i + 64);
158     int32x4_t a2 = load_tran_low_to_s32q(coeff + 4 * i + 128);
159     int32x4_t a3 = load_tran_low_to_s32q(coeff + 4 * i + 192);
160 
161     int32x4_t b0 = vhaddq_s32(a0, a1);
162     int32x4_t b1 = vhsubq_s32(a0, a1);
163     int32x4_t b2 = vhaddq_s32(a2, a3);
164     int32x4_t b3 = vhsubq_s32(a2, a3);
165 
166     int32x4_t c0 = vaddq_s32(b0, b2);
167     int32x4_t c1 = vaddq_s32(b1, b3);
168     int32x4_t c2 = vsubq_s32(b0, b2);
169     int32x4_t c3 = vsubq_s32(b1, b3);
170 
171     store_s32q_to_tran_low(coeff + 4 * i, c0);
172     store_s32q_to_tran_low(coeff + 4 * i + 64, c1);
173     store_s32q_to_tran_low(coeff + 4 * i + 128, c2);
174     store_s32q_to_tran_low(coeff + 4 * i + 192, c3);
175   } while (++i < 16);
176 }
177 
vpx_highbd_hadamard_32x32_neon(const int16_t * src_diff,ptrdiff_t src_stride,tran_low_t * coeff)178 void vpx_highbd_hadamard_32x32_neon(const int16_t *src_diff,
179                                     ptrdiff_t src_stride, tran_low_t *coeff) {
180   int i = 0;
181 
182   // Rearrange 32x32 to 16x64 and remove stride.
183   // Top left first.
184   vpx_highbd_hadamard_16x16_neon(src_diff, src_stride, coeff);
185   // Top right.
186   vpx_highbd_hadamard_16x16_neon(src_diff + 16, src_stride, coeff + 256);
187   // Bottom left.
188   vpx_highbd_hadamard_16x16_neon(src_diff + 16 * src_stride, src_stride,
189                                  coeff + 512);
190   // Bottom right.
191   vpx_highbd_hadamard_16x16_neon(src_diff + 16 * src_stride + 16, src_stride,
192                                  coeff + 768);
193 
194   do {
195     int32x4_t a0 = load_tran_low_to_s32q(coeff + 4 * i);
196     int32x4_t a1 = load_tran_low_to_s32q(coeff + 4 * i + 256);
197     int32x4_t a2 = load_tran_low_to_s32q(coeff + 4 * i + 512);
198     int32x4_t a3 = load_tran_low_to_s32q(coeff + 4 * i + 768);
199 
200     int32x4_t b0 = vshrq_n_s32(vaddq_s32(a0, a1), 2);
201     int32x4_t b1 = vshrq_n_s32(vsubq_s32(a0, a1), 2);
202     int32x4_t b2 = vshrq_n_s32(vaddq_s32(a2, a3), 2);
203     int32x4_t b3 = vshrq_n_s32(vsubq_s32(a2, a3), 2);
204 
205     int32x4_t c0 = vaddq_s32(b0, b2);
206     int32x4_t c1 = vaddq_s32(b1, b3);
207     int32x4_t c2 = vsubq_s32(b0, b2);
208     int32x4_t c3 = vsubq_s32(b1, b3);
209 
210     store_s32q_to_tran_low(coeff + 4 * i, c0);
211     store_s32q_to_tran_low(coeff + 4 * i + 256, c1);
212     store_s32q_to_tran_low(coeff + 4 * i + 512, c2);
213     store_s32q_to_tran_low(coeff + 4 * i + 768, c3);
214   } while (++i < 64);
215 }
216