Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: third_party/libwebp/dsp/msa_macro.h

Issue 2149863002: libwebp: update to v0.5.1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libwebp/dsp/lossless_enc_sse2.c ('k') | third_party/libwebp/dsp/rescaler_sse2.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 Google Inc. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 // -----------------------------------------------------------------------------
9 //
10 // MSA common macros
11 //
12 // Author(s): Prashant Patil (prashant.patil@imgtec.com)
13
14 #ifndef WEBP_DSP_MSA_MACRO_H_
15 #define WEBP_DSP_MSA_MACRO_H_
16
17 #include <stdint.h>
18 #include <msa.h>
19
20 #if defined(__clang__)
21 #define CLANG_BUILD
22 #endif
23
24 #ifdef CLANG_BUILD
25 #define ADDVI_H(a, b) __msa_addvi_h((v8i16)a, b)
26 #define SRAI_H(a, b) __msa_srai_h((v8i16)a, b)
27 #define SRAI_W(a, b) __msa_srai_w((v4i32)a, b)
28 #else
29 #define ADDVI_H(a, b) (a + b)
30 #define SRAI_H(a, b) (a >> b)
31 #define SRAI_W(a, b) (a >> b)
32 #endif
33
34 #define LD_B(RTYPE, psrc) *((RTYPE*)(psrc))
35 #define LD_UB(...) LD_B(v16u8, __VA_ARGS__)
36 #define LD_SB(...) LD_B(v16i8, __VA_ARGS__)
37
38 #define LD_H(RTYPE, psrc) *((RTYPE*)(psrc))
39 #define LD_UH(...) LD_H(v8u16, __VA_ARGS__)
40 #define LD_SH(...) LD_H(v8i16, __VA_ARGS__)
41
42 #define LD_W(RTYPE, psrc) *((RTYPE*)(psrc))
43 #define LD_UW(...) LD_W(v4u32, __VA_ARGS__)
44 #define LD_SW(...) LD_W(v4i32, __VA_ARGS__)
45
46 #define ST_B(RTYPE, in, pdst) *((RTYPE*)(pdst)) = in
47 #define ST_UB(...) ST_B(v16u8, __VA_ARGS__)
48 #define ST_SB(...) ST_B(v16i8, __VA_ARGS__)
49
50 #define ST_H(RTYPE, in, pdst) *((RTYPE*)(pdst)) = in
51 #define ST_UH(...) ST_H(v8u16, __VA_ARGS__)
52 #define ST_SH(...) ST_H(v8i16, __VA_ARGS__)
53
54 #define ST_W(RTYPE, in, pdst) *((RTYPE*)(pdst)) = in
55 #define ST_UW(...) ST_W(v4u32, __VA_ARGS__)
56 #define ST_SW(...) ST_W(v4i32, __VA_ARGS__)
57
58 #define MSA_LOAD_FUNC(TYPE, INSTR, FUNC_NAME) \
59 static inline TYPE FUNC_NAME(const void* const psrc) { \
60 const uint8_t* const psrc_m = (const uint8_t*)psrc; \
61 TYPE val_m; \
62 asm volatile ( \
63 "" #INSTR " %[val_m], %[psrc_m] \n\t" \
64 : [val_m] "=r" (val_m) \
65 : [psrc_m] "m" (*psrc_m)); \
66 return val_m; \
67 }
68
69 #define MSA_LOAD(psrc, FUNC_NAME) FUNC_NAME(psrc)
70
71 #define MSA_STORE_FUNC(TYPE, INSTR, FUNC_NAME) \
72 static inline void FUNC_NAME(TYPE val, void* const pdst) { \
73 uint8_t* const pdst_m = (uint8_t*)pdst; \
74 TYPE val_m = val; \
75 asm volatile ( \
76 " " #INSTR " %[val_m], %[pdst_m] \n\t" \
77 : [pdst_m] "=m" (*pdst_m) \
78 : [val_m] "r" (val_m)); \
79 }
80
81 #define MSA_STORE(val, pdst, FUNC_NAME) FUNC_NAME(val, pdst)
82
83 #if (__mips_isa_rev >= 6)
84 MSA_LOAD_FUNC(uint16_t, lh, msa_lh);
85 #define LH(psrc) MSA_LOAD(psrc, msa_lh)
86 MSA_LOAD_FUNC(uint32_t, lw, msa_lw);
87 #define LW(psrc) MSA_LOAD(psrc, msa_lw)
88 #if (__mips == 64)
89 MSA_LOAD_FUNC(uint64_t, ld, msa_ld);
90 #define LD(psrc) MSA_LOAD(psrc, msa_ld)
91 #else // !(__mips == 64)
92 #define LD(psrc) ((((uint64_t)MSA_LOAD(psrc + 4, msa_lw)) << 32) | \
93 MSA_LOAD(psrc, msa_lw))
94 #endif // (__mips == 64)
95
96 MSA_STORE_FUNC(uint16_t, sh, msa_sh);
97 #define SH(val, pdst) MSA_STORE(val, pdst, msa_sh)
98 MSA_STORE_FUNC(uint32_t, sw, msa_sw);
99 #define SW(val, pdst) MSA_STORE(val, pdst, msa_sw)
100 MSA_STORE_FUNC(uint64_t, sd, msa_sd);
101 #define SD(val, pdst) MSA_STORE(val, pdst, msa_sd)
102 #else // !(__mips_isa_rev >= 6)
103 MSA_LOAD_FUNC(uint16_t, ulh, msa_ulh);
104 #define LH(psrc) MSA_LOAD(psrc, msa_ulh)
105 MSA_LOAD_FUNC(uint32_t, ulw, msa_ulw);
106 #define LW(psrc) MSA_LOAD(psrc, msa_ulw)
107 #if (__mips == 64)
108 MSA_LOAD_FUNC(uint64_t, uld, msa_uld);
109 #define LD(psrc) MSA_LOAD(psrc, msa_uld)
110 #else // !(__mips == 64)
111 #define LD(psrc) ((((uint64_t)MSA_LOAD(psrc + 4, msa_ulw)) << 32) | \
112 MSA_LOAD(psrc, msa_ulw))
113 #endif // (__mips == 64)
114
115 MSA_STORE_FUNC(uint16_t, ush, msa_ush);
116 #define SH(val, pdst) MSA_STORE(val, pdst, msa_ush)
117 MSA_STORE_FUNC(uint32_t, usw, msa_usw);
118 #define SW(val, pdst) MSA_STORE(val, pdst, msa_usw)
119 #define SD(val, pdst) { \
120 uint8_t* const pdst_sd_m = (uint8_t*)(pdst); \
121 const uint32_t val0_m = (uint32_t)(val & 0x00000000FFFFFFFF); \
122 const uint32_t val1_m = (uint32_t)((val >> 32) & 0x00000000FFFFFFFF); \
123 SW(val0_m, pdst_sd_m); \
124 SW(val1_m, pdst_sd_m + 4); \
125 }
126 #endif // (__mips_isa_rev >= 6)
127
128 /* Description : Load 4 words with stride
129 * Arguments : Inputs - psrc, stride
130 * Outputs - out0, out1, out2, out3
131 * Details : Load word in 'out0' from (psrc)
132 * Load word in 'out1' from (psrc + stride)
133 * Load word in 'out2' from (psrc + 2 * stride)
134 * Load word in 'out3' from (psrc + 3 * stride)
135 */
136 #define LW4(psrc, stride, out0, out1, out2, out3) { \
137 const uint8_t* ptmp = (const uint8_t*)psrc; \
138 out0 = LW(ptmp); \
139 ptmp += stride; \
140 out1 = LW(ptmp); \
141 ptmp += stride; \
142 out2 = LW(ptmp); \
143 ptmp += stride; \
144 out3 = LW(ptmp); \
145 }
146
147 /* Description : Store 4 words with stride
148 * Arguments : Inputs - in0, in1, in2, in3, pdst, stride
149 * Details : Store word from 'in0' to (pdst)
150 * Store word from 'in1' to (pdst + stride)
151 * Store word from 'in2' to (pdst + 2 * stride)
152 * Store word from 'in3' to (pdst + 3 * stride)
153 */
154 #define SW4(in0, in1, in2, in3, pdst, stride) { \
155 uint8_t* ptmp = (uint8_t*)pdst; \
156 SW(in0, ptmp); \
157 ptmp += stride; \
158 SW(in1, ptmp); \
159 ptmp += stride; \
160 SW(in2, ptmp); \
161 ptmp += stride; \
162 SW(in3, ptmp); \
163 }
164
165 /* Description : Load vectors with 16 byte elements with stride
166 * Arguments : Inputs - psrc, stride
167 * Outputs - out0, out1
168 * Return Type - as per RTYPE
169 * Details : Load 16 byte elements in 'out0' from (psrc)
170 * Load 16 byte elements in 'out1' from (psrc + stride)
171 */
172 #define LD_B2(RTYPE, psrc, stride, out0, out1) { \
173 out0 = LD_B(RTYPE, psrc); \
174 out1 = LD_B(RTYPE, psrc + stride); \
175 }
176 #define LD_UB2(...) LD_B2(v16u8, __VA_ARGS__)
177 #define LD_SB2(...) LD_B2(v16i8, __VA_ARGS__)
178
179 #define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3) { \
180 LD_B2(RTYPE, psrc, stride, out0, out1); \
181 LD_B2(RTYPE, psrc + 2 * stride , stride, out2, out3); \
182 }
183 #define LD_UB4(...) LD_B4(v16u8, __VA_ARGS__)
184 #define LD_SB4(...) LD_B4(v16i8, __VA_ARGS__)
185
186 /* Description : Load vectors with 8 halfword elements with stride
187 * Arguments : Inputs - psrc, stride
188 * Outputs - out0, out1
189 * Details : Load 8 halfword elements in 'out0' from (psrc)
190 * Load 8 halfword elements in 'out1' from (psrc + stride)
191 */
192 #define LD_H2(RTYPE, psrc, stride, out0, out1) { \
193 out0 = LD_H(RTYPE, psrc); \
194 out1 = LD_H(RTYPE, psrc + stride); \
195 }
196 #define LD_UH2(...) LD_H2(v8u16, __VA_ARGS__)
197 #define LD_SH2(...) LD_H2(v8i16, __VA_ARGS__)
198
199 /* Description : Store 4x4 byte block to destination memory from input vector
200 * Arguments : Inputs - in0, in1, pdst, stride
201 * Details : 'Idx0' word element from input vector 'in0' is copied to the
202 * GP register and stored to (pdst)
203 * 'Idx1' word element from input vector 'in0' is copied to the
204 * GP register and stored to (pdst + stride)
205 * 'Idx2' word element from input vector 'in0' is copied to the
206 * GP register and stored to (pdst + 2 * stride)
207 * 'Idx3' word element from input vector 'in0' is copied to the
208 * GP register and stored to (pdst + 3 * stride)
209 */
210 #define ST4x4_UB(in0, in1, idx0, idx1, idx2, idx3, pdst, stride) { \
211 uint8_t* const pblk_4x4_m = (uint8_t*)pdst; \
212 const uint32_t out0_m = __msa_copy_s_w((v4i32)in0, idx0); \
213 const uint32_t out1_m = __msa_copy_s_w((v4i32)in0, idx1); \
214 const uint32_t out2_m = __msa_copy_s_w((v4i32)in1, idx2); \
215 const uint32_t out3_m = __msa_copy_s_w((v4i32)in1, idx3); \
216 SW4(out0_m, out1_m, out2_m, out3_m, pblk_4x4_m, stride); \
217 }
218
219 /* Description : Immediate number of elements to slide
220 * Arguments : Inputs - in0, in1, slide_val
221 * Outputs - out
222 * Return Type - as per RTYPE
223 * Details : Byte elements from 'in1' vector are slid into 'in0' by
224 * value specified in the 'slide_val'
225 */
226 #define SLDI_B(RTYPE, in0, in1, slide_val) \
227 (RTYPE)__msa_sldi_b((v16i8)in0, (v16i8)in1, slide_val) \
228
229 #define SLDI_UB(...) SLDI_B(v16u8, __VA_ARGS__)
230 #define SLDI_SB(...) SLDI_B(v16i8, __VA_ARGS__)
231 #define SLDI_SH(...) SLDI_B(v8i16, __VA_ARGS__)
232
233 /* Description : Shuffle halfword vector elements as per mask vector
234 * Arguments : Inputs - in0, in1, in2, in3, mask0, mask1
235 * Outputs - out0, out1
236 * Return Type - as per RTYPE
237 * Details : halfword elements from 'in0' & 'in1' are copied selectively to
238 * 'out0' as per control vector 'mask0'
239 */
240 #define VSHF_H2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1) { \
241 out0 = (RTYPE)__msa_vshf_h((v8i16)mask0, (v8i16)in1, (v8i16)in0); \
242 out1 = (RTYPE)__msa_vshf_h((v8i16)mask1, (v8i16)in3, (v8i16)in2); \
243 }
244 #define VSHF_H2_UH(...) VSHF_H2(v8u16, __VA_ARGS__)
245 #define VSHF_H2_SH(...) VSHF_H2(v8i16, __VA_ARGS__)
246
247 /* Description : Clips all signed halfword elements of input vector
248 * between 0 & 255
249 * Arguments : Input/output - val
250 * Return Type - signed halfword
251 */
252 #define CLIP_SH_0_255(val) { \
253 const v8i16 max_m = __msa_ldi_h(255); \
254 val = __msa_maxi_s_h((v8i16)val, 0); \
255 val = __msa_min_s_h(max_m, (v8i16)val); \
256 }
257 #define CLIP_SH2_0_255(in0, in1) { \
258 CLIP_SH_0_255(in0); \
259 CLIP_SH_0_255(in1); \
260 }
261
262 /* Description : Clips all signed word elements of input vector
263 * between 0 & 255
264 * Arguments : Input/output - val
265 * Return Type - signed word
266 */
267 #define CLIP_SW_0_255(val) { \
268 const v4i32 max_m = __msa_ldi_w(255); \
269 val = __msa_maxi_s_w((v4i32)val, 0); \
270 val = __msa_min_s_w(max_m, (v4i32)val); \
271 }
272 #define CLIP_SW4_0_255(in0, in1, in2, in3) { \
273 CLIP_SW_0_255(in0); \
274 CLIP_SW_0_255(in1); \
275 CLIP_SW_0_255(in2); \
276 CLIP_SW_0_255(in3); \
277 }
278
279 /* Description : Set element n input vector to GPR value
280 * Arguments : Inputs - in0, in1, in2, in3
281 * Output - out
282 * Return Type - as per RTYPE
283 * Details : Set element 0 in vector 'out' to value specified in 'in0'
284 */
285 #define INSERT_W2(RTYPE, in0, in1, out) { \
286 out = (RTYPE)__msa_insert_w((v4i32)out, 0, in0); \
287 out = (RTYPE)__msa_insert_w((v4i32)out, 1, in1); \
288 }
289 #define INSERT_W2_UB(...) INSERT_W2(v16u8, __VA_ARGS__)
290 #define INSERT_W2_SB(...) INSERT_W2(v16i8, __VA_ARGS__)
291
292 #define INSERT_W4(RTYPE, in0, in1, in2, in3, out) { \
293 out = (RTYPE)__msa_insert_w((v4i32)out, 0, in0); \
294 out = (RTYPE)__msa_insert_w((v4i32)out, 1, in1); \
295 out = (RTYPE)__msa_insert_w((v4i32)out, 2, in2); \
296 out = (RTYPE)__msa_insert_w((v4i32)out, 3, in3); \
297 }
298 #define INSERT_W4_UB(...) INSERT_W4(v16u8, __VA_ARGS__)
299 #define INSERT_W4_SB(...) INSERT_W4(v16i8, __VA_ARGS__)
300 #define INSERT_W4_SW(...) INSERT_W4(v4i32, __VA_ARGS__)
301
302 /* Description : Interleave right half of byte elements from vectors
303 * Arguments : Inputs - in0, in1, in2, in3
304 * Outputs - out0, out1
305 * Return Type - as per RTYPE
306 * Details : Right half of byte elements of 'in0' and 'in1' are interleaved
307 * and written to out0.
308 */
309 #define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1) { \
310 out0 = (RTYPE)__msa_ilvr_b((v16i8)in0, (v16i8)in1); \
311 out1 = (RTYPE)__msa_ilvr_b((v16i8)in2, (v16i8)in3); \
312 }
313 #define ILVR_B2_UB(...) ILVR_B2(v16u8, __VA_ARGS__)
314 #define ILVR_B2_SB(...) ILVR_B2(v16i8, __VA_ARGS__)
315 #define ILVR_B2_UH(...) ILVR_B2(v8u16, __VA_ARGS__)
316 #define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)
317 #define ILVR_B2_SW(...) ILVR_B2(v4i32, __VA_ARGS__)
318
319 #define ILVR_B4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
320 out0, out1, out2, out3) { \
321 ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1); \
322 ILVR_B2(RTYPE, in4, in5, in6, in7, out2, out3); \
323 }
324 #define ILVR_B4_UB(...) ILVR_B4(v16u8, __VA_ARGS__)
325 #define ILVR_B4_SB(...) ILVR_B4(v16i8, __VA_ARGS__)
326 #define ILVR_B4_UH(...) ILVR_B4(v8u16, __VA_ARGS__)
327 #define ILVR_B4_SH(...) ILVR_B4(v8i16, __VA_ARGS__)
328 #define ILVR_B4_SW(...) ILVR_B4(v4i32, __VA_ARGS__)
329
330 /* Description : Interleave right half of halfword elements from vectors
331 * Arguments : Inputs - in0, in1, in2, in3
332 * Outputs - out0, out1
333 * Return Type - as per RTYPE
334 * Details : Right half of halfword elements of 'in0' and 'in1' are
335 * interleaved and written to 'out0'.
336 */
337 #define ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1) { \
338 out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1); \
339 out1 = (RTYPE)__msa_ilvr_h((v8i16)in2, (v8i16)in3); \
340 }
341 #define ILVR_H2_UB(...) ILVR_H2(v16u8, __VA_ARGS__)
342 #define ILVR_H2_SH(...) ILVR_H2(v8i16, __VA_ARGS__)
343 #define ILVR_H2_SW(...) ILVR_H2(v4i32, __VA_ARGS__)
344
345 #define ILVR_H4(RTYPE, in0, in1, in2, in3, in4, in5, in6, in7, \
346 out0, out1, out2, out3) { \
347 ILVR_H2(RTYPE, in0, in1, in2, in3, out0, out1); \
348 ILVR_H2(RTYPE, in4, in5, in6, in7, out2, out3); \
349 }
350 #define ILVR_H4_UB(...) ILVR_H4(v16u8, __VA_ARGS__)
351 #define ILVR_H4_SH(...) ILVR_H4(v8i16, __VA_ARGS__)
352 #define ILVR_H4_SW(...) ILVR_H4(v4i32, __VA_ARGS__)
353
354 /* Description : Interleave right half of double word elements from vectors
355 * Arguments : Inputs - in0, in1, in2, in3
356 * Outputs - out0, out1
357 * Return Type - as per RTYPE
358 * Details : Right half of double word elements of 'in0' and 'in1' are
359 * interleaved and written to 'out0'.
360 */
361 #define ILVR_D2(RTYPE, in0, in1, in2, in3, out0, out1) { \
362 out0 = (RTYPE)__msa_ilvr_d((v2i64)in0, (v2i64)in1); \
363 out1 = (RTYPE)__msa_ilvr_d((v2i64)in2, (v2i64)in3); \
364 }
365 #define ILVR_D2_UB(...) ILVR_D2(v16u8, __VA_ARGS__)
366 #define ILVR_D2_SB(...) ILVR_D2(v16i8, __VA_ARGS__)
367 #define ILVR_D2_SH(...) ILVR_D2(v8i16, __VA_ARGS__)
368
369 #define ILVRL_H2(RTYPE, in0, in1, out0, out1) { \
370 out0 = (RTYPE)__msa_ilvr_h((v8i16)in0, (v8i16)in1); \
371 out1 = (RTYPE)__msa_ilvl_h((v8i16)in0, (v8i16)in1); \
372 }
373 #define ILVRL_H2_UB(...) ILVRL_H2(v16u8, __VA_ARGS__)
374 #define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__)
375 #define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__)
376 #define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__)
377 #define ILVRL_H2_UW(...) ILVRL_H2(v4u32, __VA_ARGS__)
378
379 #define ILVRL_W2(RTYPE, in0, in1, out0, out1) { \
380 out0 = (RTYPE)__msa_ilvr_w((v4i32)in0, (v4i32)in1); \
381 out1 = (RTYPE)__msa_ilvl_w((v4i32)in0, (v4i32)in1); \
382 }
383 #define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__)
384 #define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__)
385 #define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__)
386
387 /* Description : Pack even byte elements of vector pairs
388 * Arguments : Inputs - in0, in1, in2, in3
389 * Outputs - out0, out1
390 * Return Type - as per RTYPE
391 * Details : Even byte elements of 'in0' are copied to the left half of
392 * 'out0' & even byte elements of 'in1' are copied to the right
393 * half of 'out0'.
394 */
395 #define PCKEV_B2(RTYPE, in0, in1, in2, in3, out0, out1) { \
396 out0 = (RTYPE)__msa_pckev_b((v16i8)in0, (v16i8)in1); \
397 out1 = (RTYPE)__msa_pckev_b((v16i8)in2, (v16i8)in3); \
398 }
399 #define PCKEV_B2_SB(...) PCKEV_B2(v16i8, __VA_ARGS__)
400 #define PCKEV_B2_UB(...) PCKEV_B2(v16u8, __VA_ARGS__)
401 #define PCKEV_B2_SH(...) PCKEV_B2(v8i16, __VA_ARGS__)
402 #define PCKEV_B2_SW(...) PCKEV_B2(v4i32, __VA_ARGS__)
403
404 /* Description : Arithmetic immediate shift right all elements of word vector
405 * Arguments : Inputs - in0, in1, shift
406 * Outputs - in place operation
407 * Return Type - as per input vector RTYPE
408 * Details : Each element of vector 'in0' is right shifted by 'shift' and
409 * the result is written in-place. 'shift' is a GP variable.
410 */
411 #define SRAI_W2(RTYPE, in0, in1, shift_val) { \
412 in0 = (RTYPE)SRAI_W(in0, shift_val); \
413 in1 = (RTYPE)SRAI_W(in1, shift_val); \
414 }
415 #define SRAI_W2_SW(...) SRAI_W2(v4i32, __VA_ARGS__)
416 #define SRAI_W2_UW(...) SRAI_W2(v4u32, __VA_ARGS__)
417
418 #define SRAI_W4(RTYPE, in0, in1, in2, in3, shift_val) { \
419 SRAI_W2(RTYPE, in0, in1, shift_val); \
420 SRAI_W2(RTYPE, in2, in3, shift_val); \
421 }
422 #define SRAI_W4_SW(...) SRAI_W4(v4i32, __VA_ARGS__)
423 #define SRAI_W4_UW(...) SRAI_W4(v4u32, __VA_ARGS__)
424
425 /* Description : Arithmetic shift right all elements of half-word vector
426 * Arguments : Inputs - in0, in1, shift
427 * Outputs - in place operation
428 * Return Type - as per input vector RTYPE
429 * Details : Each element of vector 'in0' is right shifted by 'shift' and
430 * the result is written in-place. 'shift' is a GP variable.
431 */
432 #define SRAI_H2(RTYPE, in0, in1, shift_val) { \
433 in0 = (RTYPE)SRAI_H(in0, shift_val); \
434 in1 = (RTYPE)SRAI_H(in1, shift_val); \
435 }
436 #define SRAI_H2_SH(...) SRAI_H2(v8i16, __VA_ARGS__)
437 #define SRAI_H2_UH(...) SRAI_H2(v8u16, __VA_ARGS__)
438
439 /* Description : Arithmetic rounded shift right all elements of word vector
440 * Arguments : Inputs - in0, in1, shift
441 * Outputs - in place operation
442 * Return Type - as per input vector RTYPE
443 * Details : Each element of vector 'in0' is right shifted by 'shift' and
444 * the result is written in-place. 'shift' is a GP variable.
445 */
446 #define SRARI_W2(RTYPE, in0, in1, shift) { \
447 in0 = (RTYPE)__msa_srari_w((v4i32)in0, shift); \
448 in1 = (RTYPE)__msa_srari_w((v4i32)in1, shift); \
449 }
450 #define SRARI_W2_SW(...) SRARI_W2(v4i32, __VA_ARGS__)
451
452 #define SRARI_W4(RTYPE, in0, in1, in2, in3, shift) { \
453 SRARI_W2(RTYPE, in0, in1, shift); \
454 SRARI_W2(RTYPE, in2, in3, shift); \
455 }
456 #define SRARI_W4_SH(...) SRARI_W4(v8i16, __VA_ARGS__)
457 #define SRARI_W4_UW(...) SRARI_W4(v4u32, __VA_ARGS__)
458 #define SRARI_W4_SW(...) SRARI_W4(v4i32, __VA_ARGS__)
459
460 /* Description : Addition of 2 pairs of half-word vectors
461 * Arguments : Inputs - in0, in1, in2, in3
462 * Outputs - out0, out1
463 * Details : Each element in 'in0' is added to 'in1' and result is written
464 * to 'out0'.
465 */
466 #define ADDVI_H2(RTYPE, in0, in1, in2, in3, out0, out1) { \
467 out0 = (RTYPE)ADDVI_H(in0, in1); \
468 out1 = (RTYPE)ADDVI_H(in2, in3); \
469 }
470 #define ADDVI_H2_SH(...) ADDVI_H2(v8i16, __VA_ARGS__)
471 #define ADDVI_H2_UH(...) ADDVI_H2(v8u16, __VA_ARGS__)
472
473 /* Description : Addition of 2 pairs of vectors
474 * Arguments : Inputs - in0, in1, in2, in3
475 * Outputs - out0, out1
476 * Details : Each element in 'in0' is added to 'in1' and result is written
477 * to 'out0'.
478 */
479 #define ADD2(in0, in1, in2, in3, out0, out1) { \
480 out0 = in0 + in1; \
481 out1 = in2 + in3; \
482 }
483 #define ADD4(in0, in1, in2, in3, in4, in5, in6, in7, \
484 out0, out1, out2, out3) { \
485 ADD2(in0, in1, in2, in3, out0, out1); \
486 ADD2(in4, in5, in6, in7, out2, out3); \
487 }
488
489 /* Description : Sign extend halfword elements from input vector and return
490 * the result in pair of vectors
491 * Arguments : Input - in (halfword vector)
492 * Outputs - out0, out1 (sign extended word vectors)
493 * Return Type - signed word
494 * Details : Sign bit of halfword elements from input vector 'in' is
495 * extracted and interleaved right with same vector 'in0' to
496 * generate 4 signed word elements in 'out0'
497 * Then interleaved left with same vector 'in0' to
498 * generate 4 signed word elements in 'out1'
499 */
500 #define UNPCK_SH_SW(in, out0, out1) { \
501 const v8i16 tmp_m = __msa_clti_s_h((v8i16)in, 0); \
502 ILVRL_H2_SW(tmp_m, in, out0, out1); \
503 }
504
505 /* Description : Butterfly of 4 input vectors
506 * Arguments : Inputs - in0, in1, in2, in3
507 * Outputs - out0, out1, out2, out3
508 * Details : Butterfly operation
509 */
510 #define BUTTERFLY_4(in0, in1, in2, in3, out0, out1, out2, out3) { \
511 out0 = in0 + in3; \
512 out1 = in1 + in2; \
513 out2 = in1 - in2; \
514 out3 = in0 - in3; \
515 }
516
517 /* Description : Transpose 4x4 block with word elements in vectors
518 * Arguments : Inputs - in0, in1, in2, in3
519 * Outputs - out0, out1, out2, out3
520 * Return Type - as per RTYPE
521 */
522 #define TRANSPOSE4x4_W(RTYPE, in0, in1, in2, in3, out0, out1, out2, out3) { \
523 v4i32 s0_m, s1_m, s2_m, s3_m; \
524 ILVRL_W2_SW(in1, in0, s0_m, s1_m); \
525 ILVRL_W2_SW(in3, in2, s2_m, s3_m); \
526 out0 = (RTYPE)__msa_ilvr_d((v2i64)s2_m, (v2i64)s0_m); \
527 out1 = (RTYPE)__msa_ilvl_d((v2i64)s2_m, (v2i64)s0_m); \
528 out2 = (RTYPE)__msa_ilvr_d((v2i64)s3_m, (v2i64)s1_m); \
529 out3 = (RTYPE)__msa_ilvl_d((v2i64)s3_m, (v2i64)s1_m); \
530 }
531 #define TRANSPOSE4x4_SW_SW(...) TRANSPOSE4x4_W(v4i32, __VA_ARGS__)
532
533 /* Description : Add block 4x4
534 * Arguments : Inputs - in0, in1, in2, in3, pdst, stride
535 * Details : Least significant 4 bytes from each input vector are added to
536 * the destination bytes, clipped between 0-255 and stored.
537 */
538 #define ADDBLK_ST4x4_UB(in0, in1, in2, in3, pdst, stride) { \
539 uint32_t src0_m, src1_m, src2_m, src3_m; \
540 v8i16 inp0_m, inp1_m, res0_m, res1_m; \
541 v16i8 dst0_m = { 0 }; \
542 v16i8 dst1_m = { 0 }; \
543 const v16i8 zero_m = { 0 }; \
544 ILVR_D2_SH(in1, in0, in3, in2, inp0_m, inp1_m); \
545 LW4(pdst, stride, src0_m, src1_m, src2_m, src3_m); \
546 INSERT_W2_SB(src0_m, src1_m, dst0_m); \
547 INSERT_W2_SB(src2_m, src3_m, dst1_m); \
548 ILVR_B2_SH(zero_m, dst0_m, zero_m, dst1_m, res0_m, res1_m); \
549 ADD2(res0_m, inp0_m, res1_m, inp1_m, res0_m, res1_m); \
550 CLIP_SH2_0_255(res0_m, res1_m); \
551 PCKEV_B2_SB(res0_m, res0_m, res1_m, res1_m, dst0_m, dst1_m); \
552 ST4x4_UB(dst0_m, dst1_m, 0, 1, 0, 1, pdst, stride); \
553 }
554
555 #endif /* WEBP_DSP_MSA_MACRO_H_ */
OLDNEW
« no previous file with comments | « third_party/libwebp/dsp/lossless_enc_sse2.c ('k') | third_party/libwebp/dsp/rescaler_sse2.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698