1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
/*
* Copyright (c) 2018, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef AOM_AV1_COMMON_X86_AV1_TXFM_SSE2_H_
#define AOM_AV1_COMMON_X86_AV1_TXFM_SSE2_H_
#include <emmintrin.h> // SSE2
#include "config/aom_config.h"
#include "config/av1_rtcd.h"
#include "aom/aom_integer.h"
#include "aom_dsp/x86/transpose_sse2.h"
#include "aom_dsp/x86/txfm_common_sse2.h"
#include "av1/common/av1_txfm.h"
#ifdef __cplusplus
extern "C" {
#endif
static INLINE void btf_16_w4_sse2(
const __m128i *const w0, const __m128i *const w1, const __m128i __rounding,
const int8_t cos_bit, const __m128i *const in0, const __m128i *const in1,
__m128i *const out0, __m128i *const out1) {
const __m128i t0 = _mm_unpacklo_epi16(*in0, *in1);
const __m128i u0 = _mm_madd_epi16(t0, *w0);
const __m128i v0 = _mm_madd_epi16(t0, *w1);
const __m128i a0 = _mm_add_epi32(u0, __rounding);
const __m128i b0 = _mm_add_epi32(v0, __rounding);
const __m128i c0 = _mm_srai_epi32(a0, cos_bit);
const __m128i d0 = _mm_srai_epi32(b0, cos_bit);
*out0 = _mm_packs_epi32(c0, c0);
*out1 = _mm_packs_epi32(d0, c0);
}
#define btf_16_4p_sse2(w0, w1, in0, in1, out0, out1) \
{ \
__m128i t0 = _mm_unpacklo_epi16(in0, in1); \
__m128i u0 = _mm_madd_epi16(t0, w0); \
__m128i v0 = _mm_madd_epi16(t0, w1); \
\
__m128i a0 = _mm_add_epi32(u0, __rounding); \
__m128i b0 = _mm_add_epi32(v0, __rounding); \
\
__m128i c0 = _mm_srai_epi32(a0, cos_bit); \
__m128i d0 = _mm_srai_epi32(b0, cos_bit); \
\
out0 = _mm_packs_epi32(c0, c0); \
out1 = _mm_packs_epi32(d0, d0); \
}
#define btf_16_sse2(w0, w1, in0, in1, out0, out1) \
{ \
__m128i t0 = _mm_unpacklo_epi16(in0, in1); \
__m128i t1 = _mm_unpackhi_epi16(in0, in1); \
__m128i u0 = _mm_madd_epi16(t0, w0); \
__m128i u1 = _mm_madd_epi16(t1, w0); \
__m128i v0 = _mm_madd_epi16(t0, w1); \
__m128i v1 = _mm_madd_epi16(t1, w1); \
\
__m128i a0 = _mm_add_epi32(u0, __rounding); \
__m128i a1 = _mm_add_epi32(u1, __rounding); \
__m128i b0 = _mm_add_epi32(v0, __rounding); \
__m128i b1 = _mm_add_epi32(v1, __rounding); \
\
__m128i c0 = _mm_srai_epi32(a0, cos_bit); \
__m128i c1 = _mm_srai_epi32(a1, cos_bit); \
__m128i d0 = _mm_srai_epi32(b0, cos_bit); \
__m128i d1 = _mm_srai_epi32(b1, cos_bit); \
\
out0 = _mm_packs_epi32(c0, c1); \
out1 = _mm_packs_epi32(d0, d1); \
}
static INLINE __m128i load_16bit_to_16bit(const int16_t *a) {
return _mm_load_si128((const __m128i *)a);
}
static INLINE __m128i load_32bit_to_16bit(const int32_t *a) {
const __m128i a_low = _mm_load_si128((const __m128i *)a);
return _mm_packs_epi32(a_low, *(const __m128i *)(a + 4));
}
static INLINE __m128i load_32bit_to_16bit_w4(const int32_t *a) {
const __m128i a_low = _mm_load_si128((const __m128i *)a);
return _mm_packs_epi32(a_low, a_low);
}
// Store 4 16 bit values. Sign extend the values.
static INLINE void store_16bit_to_32bit_w4(const __m128i a, int32_t *const b) {
const __m128i a_lo = _mm_unpacklo_epi16(a, a);
const __m128i a_1 = _mm_srai_epi32(a_lo, 16);
_mm_store_si128((__m128i *)b, a_1);
}
// Store 8 16 bit values. Sign extend the values.
static INLINE void store_16bit_to_32bit(__m128i a, int32_t *b) {
const __m128i a_lo = _mm_unpacklo_epi16(a, a);
const __m128i a_hi = _mm_unpackhi_epi16(a, a);
const __m128i a_1 = _mm_srai_epi32(a_lo, 16);
const __m128i a_2 = _mm_srai_epi32(a_hi, 16);
_mm_store_si128((__m128i *)b, a_1);
_mm_store_si128((__m128i *)(b + 4), a_2);
}
static INLINE __m128i scale_round_sse2(const __m128i a, const int scale) {
const __m128i scale_rounding = pair_set_epi16(scale, 1 << (NewSqrt2Bits - 1));
const __m128i b = _mm_madd_epi16(a, scale_rounding);
return _mm_srai_epi32(b, NewSqrt2Bits);
}
static INLINE void store_rect_16bit_to_32bit_w4(const __m128i a,
int32_t *const b) {
const __m128i one = _mm_set1_epi16(1);
const __m128i a_lo = _mm_unpacklo_epi16(a, one);
const __m128i b_lo = scale_round_sse2(a_lo, NewSqrt2);
_mm_store_si128((__m128i *)b, b_lo);
}
static INLINE void store_rect_16bit_to_32bit(const __m128i a,
int32_t *const b) {
const __m128i one = _mm_set1_epi16(1);
const __m128i a_lo = _mm_unpacklo_epi16(a, one);
const __m128i a_hi = _mm_unpackhi_epi16(a, one);
const __m128i b_lo = scale_round_sse2(a_lo, NewSqrt2);
const __m128i b_hi = scale_round_sse2(a_hi, NewSqrt2);
_mm_store_si128((__m128i *)b, b_lo);
_mm_store_si128((__m128i *)(b + 4), b_hi);
}
static INLINE void load_buffer_16bit_to_16bit_w4(const int16_t *const in,
const int stride,
__m128i *const out,
const int out_size) {
for (int i = 0; i < out_size; ++i) {
out[i] = _mm_loadl_epi64((const __m128i *)(in + i * stride));
}
}
static INLINE void load_buffer_16bit_to_16bit_w4_flip(const int16_t *const in,
const int stride,
__m128i *const out,
const int out_size) {
for (int i = 0; i < out_size; ++i) {
out[out_size - i - 1] = _mm_loadl_epi64((const __m128i *)(in + i * stride));
}
}
static INLINE void load_buffer_16bit_to_16bit(const int16_t *in, int stride,
__m128i *out, int out_size) {
for (int i = 0; i < out_size; ++i) {
out[i] = load_16bit_to_16bit(in + i * stride);
}
}
static INLINE void load_buffer_16bit_to_16bit_flip(const int16_t *in,
int stride, __m128i *out,
int out_size) {
for (int i = 0; i < out_size; ++i) {
out[out_size - i - 1] = load_16bit_to_16bit(in + i * stride);
}
}
static INLINE void load_buffer_32bit_to_16bit(const int32_t *in, int stride,
__m128i *out, int out_size) {
for (int i = 0; i < out_size; ++i) {
out[i] = load_32bit_to_16bit(in + i * stride);
}
}
static INLINE void load_buffer_32bit_to_16bit_w4(const int32_t *in, int stride,
__m128i *out, int out_size) {
for (int i = 0; i < out_size; ++i) {
out[i] = load_32bit_to_16bit_w4(in + i * stride);
}
}
static INLINE void load_buffer_32bit_to_16bit_flip(const int32_t *in,
int stride, __m128i *out,
int out_size) {
for (int i = 0; i < out_size; ++i) {
out[out_size - i - 1] = load_32bit_to_16bit(in + i * stride);
}
}
static INLINE void store_buffer_16bit_to_32bit_w4(const __m128i *const in,
int32_t *const out,
const int stride,
const int out_size) {
for (int i = 0; i < out_size; ++i) {
store_16bit_to_32bit_w4(in[i], out + i * stride);
}
}
static INLINE void store_buffer_16bit_to_32bit_w8(const __m128i *const in,
int32_t *const out,
const int stride,
const int out_size) {
for (int i = 0; i < out_size; ++i) {
store_16bit_to_32bit(in[i], out + i * stride);
}
}
static INLINE void store_rect_buffer_16bit_to_32bit_w4(const __m128i *const in,
int32_t *const out,
const int stride,
const int out_size) {
for (int i = 0; i < out_size; ++i) {
store_rect_16bit_to_32bit_w4(in[i], out + i * stride);
}
}
static INLINE void store_rect_buffer_16bit_to_32bit_w8(const __m128i *const in,
int32_t *const out,
const int stride,
const int out_size) {
for (int i = 0; i < out_size; ++i) {
store_rect_16bit_to_32bit(in[i], out + i * stride);
}
}
static INLINE void store_buffer_16bit_to_16bit_8x8(const __m128i *in,
uint16_t *out,
const int stride) {
for (int i = 0; i < 8; ++i) {
_mm_store_si128((__m128i *)(out + i * stride), in[i]);
}
}
static INLINE void round_shift_16bit(__m128i *in, int size, int bit) {
if (bit < 0) {
bit = -bit;
__m128i rounding = _mm_set1_epi16(1 << (bit - 1));
for (int i = 0; i < size; ++i) {
in[i] = _mm_adds_epi16(in[i], rounding);
in[i] = _mm_srai_epi16(in[i], bit);
}
} else if (bit > 0) {
for (int i = 0; i < size; ++i) {
in[i] = _mm_slli_epi16(in[i], bit);
}
}
}
static INLINE void flip_buf_sse2(__m128i *in, __m128i *out, int size) {
for (int i = 0; i < size; ++i) {
out[size - i - 1] = in[i];
}
}
void av1_lowbd_fwd_txfm2d_4x4_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_4x8_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_4x16_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_8x4_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_8x8_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_8x16_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_8x32_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_16x4_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_16x8_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_16x16_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_16x32_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_32x8_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_32x16_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_32x32_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_16x64_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
void av1_lowbd_fwd_txfm2d_64x16_sse2(const int16_t *input, int32_t *output,
int stride, TX_TYPE tx_type, int bd);
typedef void (*transform_1d_sse2)(const __m128i *input, __m128i *output,
int8_t cos_bit);
typedef struct {
transform_1d_sse2 col, row; // vertical and horizontal
} transform_2d_sse2;
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // AOM_AV1_COMMON_X86_AV1_TXFM_SSE2_H_
|