blob: 02572d40597570d8c47a70f13a73a965ddf914a8 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include <arm_neon.h>
13#include <assert.h>
14
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "./aom_config.h"
Urvang Joshi454280d2016-10-14 16:51:44 -070016#include "./av1_rtcd.h"
17#include "aom_dsp/txfm_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070018#include "av1/common/common.h"
19
Yaowu Xuc27fc142016-08-22 16:08:15 -070020static INLINE void TRANSPOSE4X4(int16x8_t *q8s16, int16x8_t *q9s16) {
21 int32x4_t q8s32, q9s32;
22 int16x4x2_t d0x2s16, d1x2s16;
23 int32x4x2_t q0x2s32;
24
25 d0x2s16 = vtrn_s16(vget_low_s16(*q8s16), vget_high_s16(*q8s16));
26 d1x2s16 = vtrn_s16(vget_low_s16(*q9s16), vget_high_s16(*q9s16));
27
28 q8s32 = vreinterpretq_s32_s16(vcombine_s16(d0x2s16.val[0], d0x2s16.val[1]));
29 q9s32 = vreinterpretq_s32_s16(vcombine_s16(d1x2s16.val[0], d1x2s16.val[1]));
30 q0x2s32 = vtrnq_s32(q8s32, q9s32);
31
32 *q8s16 = vreinterpretq_s16_s32(q0x2s32.val[0]);
33 *q9s16 = vreinterpretq_s16_s32(q0x2s32.val[1]);
34 return;
35}
36
37static INLINE void GENERATE_COSINE_CONSTANTS(int16x4_t *d0s16, int16x4_t *d1s16,
38 int16x4_t *d2s16) {
Urvang Joshi454280d2016-10-14 16:51:44 -070039 *d0s16 = vdup_n_s16((int16_t)cospi_8_64);
40 *d1s16 = vdup_n_s16((int16_t)cospi_16_64);
41 *d2s16 = vdup_n_s16((int16_t)cospi_24_64);
Yaowu Xuc27fc142016-08-22 16:08:15 -070042 return;
43}
44
45static INLINE void GENERATE_SINE_CONSTANTS(int16x4_t *d3s16, int16x4_t *d4s16,
46 int16x4_t *d5s16, int16x8_t *q3s16) {
Urvang Joshi454280d2016-10-14 16:51:44 -070047 *d3s16 = vdup_n_s16((int16_t)sinpi_1_9);
48 *d4s16 = vdup_n_s16((int16_t)sinpi_2_9);
49 *q3s16 = vdupq_n_s16((int16_t)sinpi_3_9);
50 *d5s16 = vdup_n_s16((int16_t)sinpi_4_9);
Yaowu Xuc27fc142016-08-22 16:08:15 -070051 return;
52}
53
54static INLINE void IDCT4x4_1D(int16x4_t *d0s16, int16x4_t *d1s16,
55 int16x4_t *d2s16, int16x8_t *q8s16,
56 int16x8_t *q9s16) {
57 int16x4_t d16s16, d17s16, d18s16, d19s16, d23s16, d24s16;
58 int16x4_t d26s16, d27s16, d28s16, d29s16;
59 int32x4_t q10s32, q13s32, q14s32, q15s32;
60 int16x8_t q13s16, q14s16;
61
62 d16s16 = vget_low_s16(*q8s16);
63 d17s16 = vget_high_s16(*q8s16);
64 d18s16 = vget_low_s16(*q9s16);
65 d19s16 = vget_high_s16(*q9s16);
66
67 d23s16 = vadd_s16(d16s16, d18s16);
68 d24s16 = vsub_s16(d16s16, d18s16);
69
70 q15s32 = vmull_s16(d17s16, *d2s16);
71 q10s32 = vmull_s16(d17s16, *d0s16);
72 q13s32 = vmull_s16(d23s16, *d1s16);
73 q14s32 = vmull_s16(d24s16, *d1s16);
74 q15s32 = vmlsl_s16(q15s32, d19s16, *d0s16);
75 q10s32 = vmlal_s16(q10s32, d19s16, *d2s16);
76
77 d26s16 = vqrshrn_n_s32(q13s32, 14);
78 d27s16 = vqrshrn_n_s32(q14s32, 14);
79 d29s16 = vqrshrn_n_s32(q15s32, 14);
80 d28s16 = vqrshrn_n_s32(q10s32, 14);
81
82 q13s16 = vcombine_s16(d26s16, d27s16);
83 q14s16 = vcombine_s16(d28s16, d29s16);
84 *q8s16 = vaddq_s16(q13s16, q14s16);
85 *q9s16 = vsubq_s16(q13s16, q14s16);
86 *q9s16 = vcombine_s16(vget_high_s16(*q9s16), vget_low_s16(*q9s16)); // vswp
87 return;
88}
89
90static INLINE void IADST4x4_1D(int16x4_t *d3s16, int16x4_t *d4s16,
91 int16x4_t *d5s16, int16x8_t *q3s16,
92 int16x8_t *q8s16, int16x8_t *q9s16) {
93 int16x4_t d6s16, d16s16, d17s16, d18s16, d19s16;
94 int32x4_t q8s32, q9s32, q10s32, q11s32, q12s32, q13s32, q14s32, q15s32;
95
96 d6s16 = vget_low_s16(*q3s16);
97
98 d16s16 = vget_low_s16(*q8s16);
99 d17s16 = vget_high_s16(*q8s16);
100 d18s16 = vget_low_s16(*q9s16);
101 d19s16 = vget_high_s16(*q9s16);
102
103 q10s32 = vmull_s16(*d3s16, d16s16);
104 q11s32 = vmull_s16(*d4s16, d16s16);
105 q12s32 = vmull_s16(d6s16, d17s16);
106 q13s32 = vmull_s16(*d5s16, d18s16);
107 q14s32 = vmull_s16(*d3s16, d18s16);
108 q15s32 = vmovl_s16(d16s16);
109 q15s32 = vaddw_s16(q15s32, d19s16);
110 q8s32 = vmull_s16(*d4s16, d19s16);
111 q15s32 = vsubw_s16(q15s32, d18s16);
112 q9s32 = vmull_s16(*d5s16, d19s16);
113
114 q10s32 = vaddq_s32(q10s32, q13s32);
115 q10s32 = vaddq_s32(q10s32, q8s32);
116 q11s32 = vsubq_s32(q11s32, q14s32);
Urvang Joshi454280d2016-10-14 16:51:44 -0700117 q8s32 = vdupq_n_s32((int32_t)sinpi_3_9);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700118 q11s32 = vsubq_s32(q11s32, q9s32);
119 q15s32 = vmulq_s32(q15s32, q8s32);
120
121 q13s32 = vaddq_s32(q10s32, q12s32);
122 q10s32 = vaddq_s32(q10s32, q11s32);
123 q14s32 = vaddq_s32(q11s32, q12s32);
124 q10s32 = vsubq_s32(q10s32, q12s32);
125
126 d16s16 = vqrshrn_n_s32(q13s32, 14);
127 d17s16 = vqrshrn_n_s32(q14s32, 14);
128 d18s16 = vqrshrn_n_s32(q15s32, 14);
129 d19s16 = vqrshrn_n_s32(q10s32, 14);
130
131 *q8s16 = vcombine_s16(d16s16, d17s16);
132 *q9s16 = vcombine_s16(d18s16, d19s16);
133 return;
134}
135
Yaowu Xuf883b422016-08-30 14:01:10 -0700136void av1_iht4x4_16_add_neon(const tran_low_t *input, uint8_t *dest,
137 int dest_stride, int tx_type) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700138 uint8x8_t d26u8, d27u8;
139 int16x4_t d0s16, d1s16, d2s16, d3s16, d4s16, d5s16;
140 uint32x2_t d26u32, d27u32;
141 int16x8_t q3s16, q8s16, q9s16;
142 uint16x8_t q8u16, q9u16;
143
144 d26u32 = d27u32 = vdup_n_u32(0);
145
146 q8s16 = vld1q_s16(input);
147 q9s16 = vld1q_s16(input + 8);
148
149 TRANSPOSE4X4(&q8s16, &q9s16);
150
151 switch (tx_type) {
152 case 0: // idct_idct is not supported. Fall back to C
Yaowu Xuf883b422016-08-30 14:01:10 -0700153 av1_iht4x4_16_add_c(input, dest, dest_stride, tx_type);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700154 return;
155 break;
156 case 1: // iadst_idct
157 // generate constants
158 GENERATE_COSINE_CONSTANTS(&d0s16, &d1s16, &d2s16);
159 GENERATE_SINE_CONSTANTS(&d3s16, &d4s16, &d5s16, &q3s16);
160
161 // first transform rows
162 IDCT4x4_1D(&d0s16, &d1s16, &d2s16, &q8s16, &q9s16);
163
164 // transpose the matrix
165 TRANSPOSE4X4(&q8s16, &q9s16);
166
167 // then transform columns
168 IADST4x4_1D(&d3s16, &d4s16, &d5s16, &q3s16, &q8s16, &q9s16);
169 break;
170 case 2: // idct_iadst
171 // generate constantsyy
172 GENERATE_COSINE_CONSTANTS(&d0s16, &d1s16, &d2s16);
173 GENERATE_SINE_CONSTANTS(&d3s16, &d4s16, &d5s16, &q3s16);
174
175 // first transform rows
176 IADST4x4_1D(&d3s16, &d4s16, &d5s16, &q3s16, &q8s16, &q9s16);
177
178 // transpose the matrix
179 TRANSPOSE4X4(&q8s16, &q9s16);
180
181 // then transform columns
182 IDCT4x4_1D(&d0s16, &d1s16, &d2s16, &q8s16, &q9s16);
183 break;
184 case 3: // iadst_iadst
185 // generate constants
186 GENERATE_SINE_CONSTANTS(&d3s16, &d4s16, &d5s16, &q3s16);
187
188 // first transform rows
189 IADST4x4_1D(&d3s16, &d4s16, &d5s16, &q3s16, &q8s16, &q9s16);
190
191 // transpose the matrix
192 TRANSPOSE4X4(&q8s16, &q9s16);
193
194 // then transform columns
195 IADST4x4_1D(&d3s16, &d4s16, &d5s16, &q3s16, &q8s16, &q9s16);
196 break;
197 default: // iadst_idct
198 assert(0);
199 break;
200 }
201
202 q8s16 = vrshrq_n_s16(q8s16, 4);
203 q9s16 = vrshrq_n_s16(q9s16, 4);
204
205 d26u32 = vld1_lane_u32((const uint32_t *)dest, d26u32, 0);
206 dest += dest_stride;
207 d26u32 = vld1_lane_u32((const uint32_t *)dest, d26u32, 1);
208 dest += dest_stride;
209 d27u32 = vld1_lane_u32((const uint32_t *)dest, d27u32, 0);
210 dest += dest_stride;
211 d27u32 = vld1_lane_u32((const uint32_t *)dest, d27u32, 1);
212
213 q8u16 = vaddw_u8(vreinterpretq_u16_s16(q8s16), vreinterpret_u8_u32(d26u32));
214 q9u16 = vaddw_u8(vreinterpretq_u16_s16(q9s16), vreinterpret_u8_u32(d27u32));
215
216 d26u8 = vqmovun_s16(vreinterpretq_s16_u16(q8u16));
217 d27u8 = vqmovun_s16(vreinterpretq_s16_u16(q9u16));
218
219 vst1_lane_u32((uint32_t *)dest, vreinterpret_u32_u8(d27u8), 1);
220 dest -= dest_stride;
221 vst1_lane_u32((uint32_t *)dest, vreinterpret_u32_u8(d27u8), 0);
222 dest -= dest_stride;
223 vst1_lane_u32((uint32_t *)dest, vreinterpret_u32_u8(d26u8), 1);
224 dest -= dest_stride;
225 vst1_lane_u32((uint32_t *)dest, vreinterpret_u32_u8(d26u8), 0);
226 return;
227}