summaryrefslogtreecommitdiff
path: root/media/libyuv/source/rotate_lsx.cc
blob: 94a2b91cd84931ad1737dad14d8b1c166b63b9d2 (plain)
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
/*
 *  Copyright 2022 The LibYuv Project Authors. All rights reserved.
 *
 *  Copyright (c) 2022 Loongson Technology Corporation Limited
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS. All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "libyuv/rotate_row.h"

#if !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx)
#include "libyuv/loongson_intrinsics.h"

#ifdef __cplusplus
namespace libyuv {
extern "C" {
#endif

#define ILVLH_B(in0, in1, in2, in3, out0, out1, out2, out3)   \
  {                                                           \
    DUP2_ARG2(__lsx_vilvl_b, in1, in0, in3, in2, out0, out2); \
    DUP2_ARG2(__lsx_vilvh_b, in1, in0, in3, in2, out1, out3); \
  }

#define ILVLH_H(in0, in1, in2, in3, out0, out1, out2, out3)   \
  {                                                           \
    DUP2_ARG2(__lsx_vilvl_h, in1, in0, in3, in2, out0, out2); \
    DUP2_ARG2(__lsx_vilvh_h, in1, in0, in3, in2, out1, out3); \
  }

#define ILVLH_W(in0, in1, in2, in3, out0, out1, out2, out3)   \
  {                                                           \
    DUP2_ARG2(__lsx_vilvl_w, in1, in0, in3, in2, out0, out2); \
    DUP2_ARG2(__lsx_vilvh_w, in1, in0, in3, in2, out1, out3); \
  }

#define ILVLH_D(in0, in1, in2, in3, out0, out1, out2, out3)   \
  {                                                           \
    DUP2_ARG2(__lsx_vilvl_d, in1, in0, in3, in2, out0, out2); \
    DUP2_ARG2(__lsx_vilvh_d, in1, in0, in3, in2, out1, out3); \
  }

#define LSX_ST_4(_dst0, _dst1, _dst2, _dst3, _dst, _stride, _stride2, \
                 _stride3, _stride4)                                  \
  {                                                                   \
    __lsx_vst(_dst0, _dst, 0);                                        \
    __lsx_vstx(_dst1, _dst, _stride);                                 \
    __lsx_vstx(_dst2, _dst, _stride2);                                \
    __lsx_vstx(_dst3, _dst, _stride3);                                \
    _dst += _stride4;                                                 \
  }

#define LSX_ST_2(_dst0, _dst1, _dst, _stride, _stride2) \
  {                                                     \
    __lsx_vst(_dst0, _dst, 0);                          \
    __lsx_vstx(_dst1, _dst, _stride);                   \
    _dst += _stride2;                                   \
  }

void TransposeWx16_C(const uint8_t* src,
                     int src_stride,
                     uint8_t* dst,
                     int dst_stride,
                     int width) {
  TransposeWx8_C(src, src_stride, dst, dst_stride, width);
  TransposeWx8_C((src + 8 * src_stride), src_stride, (dst + 8), dst_stride,
                 width);
}

void TransposeUVWx16_C(const uint8_t* src,
                       int src_stride,
                       uint8_t* dst_a,
                       int dst_stride_a,
                       uint8_t* dst_b,
                       int dst_stride_b,
                       int width) {
  TransposeUVWx8_C(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b,
                   width);
  TransposeUVWx8_C((src + 8 * src_stride), src_stride, (dst_a + 8),
                   dst_stride_a, (dst_b + 8), dst_stride_b, width);
}

void TransposeWx16_LSX(const uint8_t* src,
                       int src_stride,
                       uint8_t* dst,
                       int dst_stride,
                       int width) {
  int x;
  int len = width / 16;
  uint8_t* s;
  int src_stride2 = src_stride << 1;
  int src_stride3 = src_stride + src_stride2;
  int src_stride4 = src_stride2 << 1;
  int dst_stride2 = dst_stride << 1;
  int dst_stride3 = dst_stride + dst_stride2;
  int dst_stride4 = dst_stride2 << 1;
  __m128i src0, src1, src2, src3, dst0, dst1, dst2, dst3;
  __m128i tmp0, tmp1, tmp2, tmp3;
  __m128i reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7;
  __m128i res0, res1, res2, res3, res4, res5, res6, res7, res8, res9;

  for (x = 0; x < len; x++) {
    s = (uint8_t*)src;
    src0 = __lsx_vld(s, 0);
    src1 = __lsx_vldx(s, src_stride);
    src2 = __lsx_vldx(s, src_stride2);
    src3 = __lsx_vldx(s, src_stride3);
    s += src_stride4;
    ILVLH_B(src0, src1, src2, src3, tmp0, tmp1, tmp2, tmp3);
    ILVLH_H(tmp0, tmp2, tmp1, tmp3, reg0, reg1, reg2, reg3);
    src0 = __lsx_vld(s, 0);
    src1 = __lsx_vldx(s, src_stride);
    src2 = __lsx_vldx(s, src_stride2);
    src3 = __lsx_vldx(s, src_stride3);
    s += src_stride4;
    ILVLH_B(src0, src1, src2, src3, tmp0, tmp1, tmp2, tmp3);
    ILVLH_H(tmp0, tmp2, tmp1, tmp3, reg4, reg5, reg6, reg7);
    ILVLH_W(reg0, reg4, reg1, reg5, res0, res1, res2, res3);
    ILVLH_W(reg2, reg6, reg3, reg7, res4, res5, res6, res7);
    src0 = __lsx_vld(s, 0);
    src1 = __lsx_vldx(s, src_stride);
    src2 = __lsx_vldx(s, src_stride2);
    src3 = __lsx_vldx(s, src_stride3);
    s += src_stride4;
    ILVLH_B(src0, src1, src2, src3, tmp0, tmp1, tmp2, tmp3);
    ILVLH_H(tmp0, tmp2, tmp1, tmp3, reg0, reg1, reg2, reg3);
    src0 = __lsx_vld(s, 0);
    src1 = __lsx_vldx(s, src_stride);
    src2 = __lsx_vldx(s, src_stride2);
    src3 = __lsx_vldx(s, src_stride3);
    s += src_stride4;
    ILVLH_B(src0, src1, src2, src3, tmp0, tmp1, tmp2, tmp3);
    ILVLH_H(tmp0, tmp2, tmp1, tmp3, reg4, reg5, reg6, reg7);
    res8 = __lsx_vilvl_w(reg4, reg0);
    res9 = __lsx_vilvh_w(reg4, reg0);
    ILVLH_D(res0, res8, res1, res9, dst0, dst1, dst2, dst3);
    LSX_ST_4(dst0, dst1, dst2, dst3, dst, dst_stride, dst_stride2, dst_stride3,
             dst_stride4);
    res8 = __lsx_vilvl_w(reg5, reg1);
    res9 = __lsx_vilvh_w(reg5, reg1);
    ILVLH_D(res2, res8, res3, res9, dst0, dst1, dst2, dst3);
    LSX_ST_4(dst0, dst1, dst2, dst3, dst, dst_stride, dst_stride2, dst_stride3,
             dst_stride4);
    res8 = __lsx_vilvl_w(reg6, reg2);
    res9 = __lsx_vilvh_w(reg6, reg2);
    ILVLH_D(res4, res8, res5, res9, dst0, dst1, dst2, dst3);
    LSX_ST_4(dst0, dst1, dst2, dst3, dst, dst_stride, dst_stride2, dst_stride3,
             dst_stride4);
    res8 = __lsx_vilvl_w(reg7, reg3);
    res9 = __lsx_vilvh_w(reg7, reg3);
    ILVLH_D(res6, res8, res7, res9, dst0, dst1, dst2, dst3);
    LSX_ST_4(dst0, dst1, dst2, dst3, dst, dst_stride, dst_stride2, dst_stride3,
             dst_stride4);
    src += 16;
  }
}

void TransposeUVWx16_LSX(const uint8_t* src,
                         int src_stride,
                         uint8_t* dst_a,
                         int dst_stride_a,
                         uint8_t* dst_b,
                         int dst_stride_b,
                         int width) {
  int x;
  int len = width / 8;
  uint8_t* s;
  int src_stride2 = src_stride << 1;
  int src_stride3 = src_stride + src_stride2;
  int src_stride4 = src_stride2 << 1;
  int dst_stride_a2 = dst_stride_a << 1;
  int dst_stride_b2 = dst_stride_b << 1;
  __m128i src0, src1, src2, src3, dst0, dst1, dst2, dst3;
  __m128i tmp0, tmp1, tmp2, tmp3;
  __m128i reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7;
  __m128i res0, res1, res2, res3, res4, res5, res6, res7, res8, res9;

  for (x = 0; x < len; x++) {
    s = (uint8_t*)src;
    src0 = __lsx_vld(s, 0);
    src1 = __lsx_vldx(s, src_stride);
    src2 = __lsx_vldx(s, src_stride2);
    src3 = __lsx_vldx(s, src_stride3);
    s += src_stride4;
    ILVLH_B(src0, src1, src2, src3, tmp0, tmp1, tmp2, tmp3);
    ILVLH_H(tmp0, tmp2, tmp1, tmp3, reg0, reg1, reg2, reg3);
    src0 = __lsx_vld(s, 0);
    src1 = __lsx_vldx(s, src_stride);
    src2 = __lsx_vldx(s, src_stride2);
    src3 = __lsx_vldx(s, src_stride3);
    s += src_stride4;
    ILVLH_B(src0, src1, src2, src3, tmp0, tmp1, tmp2, tmp3);
    ILVLH_H(tmp0, tmp2, tmp1, tmp3, reg4, reg5, reg6, reg7);
    ILVLH_W(reg0, reg4, reg1, reg5, res0, res1, res2, res3);
    ILVLH_W(reg2, reg6, reg3, reg7, res4, res5, res6, res7);
    src0 = __lsx_vld(s, 0);
    src1 = __lsx_vldx(s, src_stride);
    src2 = __lsx_vldx(s, src_stride2);
    src3 = __lsx_vldx(s, src_stride3);
    s += src_stride4;
    ILVLH_B(src0, src1, src2, src3, tmp0, tmp1, tmp2, tmp3);
    ILVLH_H(tmp0, tmp2, tmp1, tmp3, reg0, reg1, reg2, reg3);
    src0 = __lsx_vld(s, 0);
    src1 = __lsx_vldx(s, src_stride);
    src2 = __lsx_vldx(s, src_stride2);
    src3 = __lsx_vldx(s, src_stride3);
    s += src_stride4;
    ILVLH_B(src0, src1, src2, src3, tmp0, tmp1, tmp2, tmp3);
    ILVLH_H(tmp0, tmp2, tmp1, tmp3, reg4, reg5, reg6, reg7);
    res8 = __lsx_vilvl_w(reg4, reg0);
    res9 = __lsx_vilvh_w(reg4, reg0);
    ILVLH_D(res0, res8, res1, res9, dst0, dst1, dst2, dst3);
    LSX_ST_2(dst0, dst2, dst_a, dst_stride_a, dst_stride_a2);
    LSX_ST_2(dst1, dst3, dst_b, dst_stride_b, dst_stride_b2);
    res8 = __lsx_vilvl_w(reg5, reg1);
    res9 = __lsx_vilvh_w(reg5, reg1);
    ILVLH_D(res2, res8, res3, res9, dst0, dst1, dst2, dst3);
    LSX_ST_2(dst0, dst2, dst_a, dst_stride_a, dst_stride_a2);
    LSX_ST_2(dst1, dst3, dst_b, dst_stride_b, dst_stride_b2);
    res8 = __lsx_vilvl_w(reg6, reg2);
    res9 = __lsx_vilvh_w(reg6, reg2);
    ILVLH_D(res4, res8, res5, res9, dst0, dst1, dst2, dst3);
    LSX_ST_2(dst0, dst2, dst_a, dst_stride_a, dst_stride_a2);
    LSX_ST_2(dst1, dst3, dst_b, dst_stride_b, dst_stride_b2);
    res8 = __lsx_vilvl_w(reg7, reg3);
    res9 = __lsx_vilvh_w(reg7, reg3);
    ILVLH_D(res6, res8, res7, res9, dst0, dst1, dst2, dst3);
    LSX_ST_2(dst0, dst2, dst_a, dst_stride_a, dst_stride_a2);
    LSX_ST_2(dst1, dst3, dst_b, dst_stride_b, dst_stride_b2);
    src += 16;
  }
}

#ifdef __cplusplus
}  // extern "C"
}  // namespace libyuv
#endif

#endif  // !defined(LIBYUV_DISABLE_LSX) && defined(__loongarch_sx)