summaryrefslogtreecommitdiffstats
path: root/media/libvpx/libvpx/third_party/libyuv/include/libyuv/macros_msa.h
blob: bba0e8aedac2a88f3e1d9ad0b1446520c0a7d466 (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
/*
 *  Copyright 2016 The LibYuv Project Authors. All rights reserved.
 *
 *  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.
 */

#ifndef INCLUDE_LIBYUV_MACROS_MSA_H_
#define INCLUDE_LIBYUV_MACROS_MSA_H_

#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa)
#include <msa.h>
#include <stdint.h>

#if (__mips_isa_rev >= 6)
#define LW(psrc)                                        \
  ({                                                    \
    const uint8_t* psrc_lw_m = (const uint8_t*)(psrc);  \
    uint32_t val_m;                                     \
    asm volatile("lw  %[val_m],  %[psrc_lw_m]  \n"      \
                 : [val_m] "=r"(val_m)                  \
                 : [psrc_lw_m] "m"(*psrc_lw_m));        \
    val_m;                                              \
  })

#if (__mips == 64)
#define LD(psrc)                                        \
  ({                                                    \
    const uint8_t* psrc_ld_m = (const uint8_t*)(psrc);  \
    uint64_t val_m = 0;                                 \
    asm volatile("ld  %[val_m],  %[psrc_ld_m]  \n"      \
                 : [val_m] "=r"(val_m)                  \
                 : [psrc_ld_m] "m"(*psrc_ld_m));        \
    val_m;                                              \
  })
#else  // !(__mips == 64)
#define LD(psrc)                                                         \
  ({                                                                     \
    const uint8_t* psrc_ld_m = (const uint8_t*)(psrc);                   \
    uint32_t val0_m, val1_m;                                             \
    uint64_t val_m = 0;                                                  \
    val0_m = LW(psrc_ld_m);                                              \
    val1_m = LW(psrc_ld_m + 4);                                          \
    val_m = (uint64_t)(val1_m);                             /* NOLINT */ \
    val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000); /* NOLINT */ \
    val_m = (uint64_t)(val_m | (uint64_t)val0_m);           /* NOLINT */ \
    val_m;                                                               \
  })
#endif  // (__mips == 64)

#define SW(val, pdst)                                   \
  ({                                                    \
    uint8_t* pdst_sw_m = (uint8_t*)(pdst); /* NOLINT */ \
    uint32_t val_m = (val);                             \
    asm volatile("sw  %[val_m],  %[pdst_sw_m]  \n"      \
                 : [pdst_sw_m] "=m"(*pdst_sw_m)         \
                 : [val_m] "r"(val_m));                 \
  })

#if (__mips == 64)
#define SD(val, pdst)                                   \
  ({                                                    \
    uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */ \
    uint64_t val_m = (val);                             \
    asm volatile("sd  %[val_m],  %[pdst_sd_m]  \n"      \
                 : [pdst_sd_m] "=m"(*pdst_sd_m)         \
                 : [val_m] "r"(val_m));                 \
  })
#else  // !(__mips == 64)
#define SD(val, pdst)                                        \
  ({                                                         \
    uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */      \
    uint32_t val0_m, val1_m;                                 \
    val0_m = (uint32_t)((val)&0x00000000FFFFFFFF);           \
    val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \
    SW(val0_m, pdst_sd_m);                                   \
    SW(val1_m, pdst_sd_m + 4);                               \
  })
#endif  // !(__mips == 64)
#else   // !(__mips_isa_rev >= 6)
#define LW(psrc)                                        \
  ({                                                    \
    const uint8_t* psrc_lw_m = (const uint8_t*)(psrc);  \
    uint32_t val_m;                                     \
    asm volatile("ulw  %[val_m],  %[psrc_lw_m]  \n"     \
                 : [val_m] "=r"(val_m)                  \
                 : [psrc_lw_m] "m"(*psrc_lw_m));        \
    val_m;                                              \
  })

#if (__mips == 64)
#define LD(psrc)                                        \
  ({                                                    \
    const uint8_t* psrc_ld_m = (const uint8_t*)(psrc);  \
    uint64_t val_m = 0;                                 \
    asm volatile("uld  %[val_m],  %[psrc_ld_m]  \n"     \
                 : [val_m] "=r"(val_m)                  \
                 : [psrc_ld_m] "m"(*psrc_ld_m));        \
    val_m;                                              \
  })
#else  // !(__mips == 64)
#define LD(psrc)                                                         \
  ({                                                                     \
    const uint8_t* psrc_ld_m = (const uint8_t*)(psrc);                   \
    uint32_t val0_m, val1_m;                                             \
    uint64_t val_m = 0;                                                  \
    val0_m = LW(psrc_ld_m);                                              \
    val1_m = LW(psrc_ld_m + 4);                                          \
    val_m = (uint64_t)(val1_m);                             /* NOLINT */ \
    val_m = (uint64_t)((val_m << 32) & 0xFFFFFFFF00000000); /* NOLINT */ \
    val_m = (uint64_t)(val_m | (uint64_t)val0_m);           /* NOLINT */ \
    val_m;                                                               \
  })
#endif  // (__mips == 64)

#define SW(val, pdst)                                   \
  ({                                                    \
    uint8_t* pdst_sw_m = (uint8_t*)(pdst); /* NOLINT */ \
    uint32_t val_m = (val);                             \
    asm volatile("usw  %[val_m],  %[pdst_sw_m]  \n"     \
                 : [pdst_sw_m] "=m"(*pdst_sw_m)         \
                 : [val_m] "r"(val_m));                 \
  })

#define SD(val, pdst)                                        \
  ({                                                         \
    uint8_t* pdst_sd_m = (uint8_t*)(pdst); /* NOLINT */      \
    uint32_t val0_m, val1_m;                                 \
    val0_m = (uint32_t)((val)&0x00000000FFFFFFFF);           \
    val1_m = (uint32_t)(((val) >> 32) & 0x00000000FFFFFFFF); \
    SW(val0_m, pdst_sd_m);                                   \
    SW(val1_m, pdst_sd_m + 4);                               \
  })
#endif  // (__mips_isa_rev >= 6)

// TODO(fbarchard): Consider removing __VAR_ARGS versions.
#define LD_B(RTYPE, psrc) *((RTYPE*)(psrc)) /* NOLINT */
#define LD_UB(...) LD_B(const v16u8, __VA_ARGS__)

#define ST_B(RTYPE, in, pdst) *((RTYPE*)(pdst)) = (in) /* NOLINT */
#define ST_UB(...) ST_B(v16u8, __VA_ARGS__)

#define ST_H(RTYPE, in, pdst) *((RTYPE*)(pdst)) = (in) /* NOLINT */
#define ST_UH(...) ST_H(v8u16, __VA_ARGS__)

/* Description : Load two vectors with 16 'byte' sized elements
   Arguments   : Inputs  - psrc, stride
                 Outputs - out0, out1
                 Return Type - as per RTYPE
   Details     : Load 16 byte elements in 'out0' from (psrc)
                 Load 16 byte elements in 'out1' from (psrc + stride)
*/
#define LD_B2(RTYPE, psrc, stride, out0, out1) \
  {                                            \
    out0 = LD_B(RTYPE, (psrc));                \
    out1 = LD_B(RTYPE, (psrc) + stride);       \
  }
#define LD_UB2(...) LD_B2(const v16u8, __VA_ARGS__)

#define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3) \
  {                                                        \
    LD_B2(RTYPE, (psrc), stride, out0, out1);              \
    LD_B2(RTYPE, (psrc) + 2 * stride, stride, out2, out3); \
  }
#define LD_UB4(...) LD_B4(const v16u8, __VA_ARGS__)

/* Description : Store two vectors with stride each having 16 'byte' sized
                 elements
   Arguments   : Inputs - in0, in1, pdst, stride
   Details     : Store 16 byte elements from 'in0' to (pdst)
                 Store 16 byte elements from 'in1' to (pdst + stride)
*/
#define ST_B2(RTYPE, in0, in1, pdst, stride) \
  {                                          \
    ST_B(RTYPE, in0, (pdst));                \
    ST_B(RTYPE, in1, (pdst) + stride);       \
  }
#define ST_UB2(...) ST_B2(v16u8, __VA_ARGS__)

#define ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride)   \
  {                                                      \
    ST_B2(RTYPE, in0, in1, (pdst), stride);              \
    ST_B2(RTYPE, in2, in3, (pdst) + 2 * stride, stride); \
  }
#define ST_UB4(...) ST_B4(v16u8, __VA_ARGS__)

/* Description : Store vectors of 8 halfword elements with stride
   Arguments   : Inputs - in0, in1, pdst, stride
   Details     : Store 8 halfword elements from 'in0' to (pdst)
                 Store 8 halfword elements from 'in1' to (pdst + stride)
*/
#define ST_H2(RTYPE, in0, in1, pdst, stride) \
  {                                          \
    ST_H(RTYPE, in0, (pdst));                \
    ST_H(RTYPE, in1, (pdst) + stride);       \
  }
#define ST_UH2(...) ST_H2(v8u16, __VA_ARGS__)

// TODO(fbarchard): Consider using __msa_vshf_b and __msa_ilvr_b directly.
/* Description : Shuffle byte vector elements as per mask vector
   Arguments   : Inputs  - in0, in1, in2, in3, mask0, mask1
                 Outputs - out0, out1
                 Return Type - as per RTYPE
   Details     : Byte elements from 'in0' & 'in1' are copied selectively to
                 'out0' as per control vector 'mask0'
*/
#define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1)  \
  {                                                                   \
    out0 = (RTYPE)__msa_vshf_b((v16i8)mask0, (v16i8)in1, (v16i8)in0); \
    out1 = (RTYPE)__msa_vshf_b((v16i8)mask1, (v16i8)in3, (v16i8)in2); \
  }
#define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)

/* Description : Interleave both left and right half of input vectors
   Arguments   : Inputs  - in0, in1
                 Outputs - out0, out1
                 Return Type - as per RTYPE
   Details     : Right half of byte elements from 'in0' and 'in1' are
                 interleaved and written to 'out0'
*/
#define ILVRL_B2(RTYPE, in0, in1, out0, out1)           \
  {                                                     \
    out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \
    out1 = (RTYPE)__msa_ilvl_b((v16i8)in0, (v16i8)in1); \
  }
#define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__)

#endif /* !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa) */

#endif  // INCLUDE_LIBYUV_MACROS_MSA_H_