2 * Copyright (c) 2015 Shivraj Patil (Shivraj.Patil@imgtec.com)
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavcodec/vp9dsp.h"
22 #include "libavutil/mips/generic_macros_msa.h"
23 #include "vp9dsp_mips.h"
25 #define IPRED_SUBS_UH2_UH(in0, in1, out0, out1) \
27 out0 = __msa_subs_u_h(out0, in0); \
28 out1 = __msa_subs_u_h(out1, in1); \
31 void ff_vert_16x16_msa(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *left,
39 for (row = 16; row--;) {
45 void ff_vert_32x32_msa(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *left,
52 src2 = LD_UB(src + 16);
54 for (row = 32; row--;) {
55 ST_UB2(src1, src2, dst, 16);
60 void ff_hor_16x16_msa(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src,
64 v16u8 src0, src1, src2, src3;
67 for (row = 4; row--;) {
71 src0 = (v16u8) __msa_fill_b(inp >> 24);
72 src1 = (v16u8) __msa_fill_b(inp >> 16);
73 src2 = (v16u8) __msa_fill_b(inp >> 8);
74 src3 = (v16u8) __msa_fill_b(inp);
76 ST_UB4(src0, src1, src2, src3, dst, dst_stride);
77 dst += (4 * dst_stride);
81 void ff_hor_32x32_msa(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src,
85 v16u8 src0, src1, src2, src3;
88 for (row = 8; row--;) {
92 src0 = (v16u8) __msa_fill_b(inp >> 24);
93 src1 = (v16u8) __msa_fill_b(inp >> 16);
94 src2 = (v16u8) __msa_fill_b(inp >> 8);
95 src3 = (v16u8) __msa_fill_b(inp);
97 ST_UB2(src0, src0, dst, 16);
99 ST_UB2(src1, src1, dst, 16);
101 ST_UB2(src2, src2, dst, 16);
103 ST_UB2(src3, src3, dst, 16);
108 void ff_dc_4x4_msa(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src_left,
109 const uint8_t *src_top)
112 v16i8 store, src = { 0 };
119 INSERT_W2_SB(val0, val1, src);
120 sum_h = __msa_hadd_u_h((v16u8) src, (v16u8) src);
121 sum_w = __msa_hadd_u_w(sum_h, sum_h);
122 sum_d = __msa_hadd_u_d(sum_w, sum_w);
123 sum_w = (v4u32) __msa_srari_w((v4i32) sum_d, 3);
124 store = __msa_splati_b((v16i8) sum_w, 0);
125 val0 = __msa_copy_u_w((v4i32) store, 0);
127 SW4(val0, val0, val0, val0, dst, dst_stride);
130 #define INTRA_DC_TL_4x4(dir) \
131 void ff_dc_##dir##_4x4_msa(uint8_t *dst, ptrdiff_t dst_stride, \
132 const uint8_t *left, \
133 const uint8_t *top) \
136 v16i8 store, data = { 0 }; \
141 data = (v16i8) __msa_insert_w((v4i32) data, 0, val0); \
142 sum_h = __msa_hadd_u_h((v16u8) data, (v16u8) data); \
143 sum_w = __msa_hadd_u_w(sum_h, sum_h); \
144 sum_w = (v4u32) __msa_srari_w((v4i32) sum_w, 2); \
145 store = __msa_splati_b((v16i8) sum_w, 0); \
146 val0 = __msa_copy_u_w((v4i32) store, 0); \
148 SW4(val0, val0, val0, val0, dst, dst_stride); \
150 INTRA_DC_TL_4x4(top);
151 INTRA_DC_TL_4x4(left);
153 void ff_dc_8x8_msa(uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src_left,
154 const uint8_t *src_top)
165 INSERT_D2_UB(val0, val1, src);
166 sum_h = __msa_hadd_u_h(src, src);
167 sum_w = __msa_hadd_u_w(sum_h, sum_h);
168 sum_d = __msa_hadd_u_d(sum_w, sum_w);
169 sum_w = (v4u32) __msa_pckev_w((v4i32) sum_d, (v4i32) sum_d);
170 sum_d = __msa_hadd_u_d(sum_w, sum_w);
171 sum_w = (v4u32) __msa_srari_w((v4i32) sum_d, 4);
172 store = __msa_splati_b((v16i8) sum_w, 0);
173 val0 = __msa_copy_u_d((v2i64) store, 0);
175 SD4(val0, val0, val0, val0, dst, dst_stride);
176 dst += (4 * dst_stride);
177 SD4(val0, val0, val0, val0, dst, dst_stride);
180 #define INTRA_DC_TL_8x8(dir) \
181 void ff_dc_##dir##_8x8_msa(uint8_t *dst, ptrdiff_t dst_stride, \
182 const uint8_t *left, \
183 const uint8_t *top) \
187 v16u8 data = { 0 }; \
193 data = (v16u8) __msa_insert_d((v2i64) data, 0, val0); \
194 sum_h = __msa_hadd_u_h(data, data); \
195 sum_w = __msa_hadd_u_w(sum_h, sum_h); \
196 sum_d = __msa_hadd_u_d(sum_w, sum_w); \
197 sum_w = (v4u32) __msa_srari_w((v4i32) sum_d, 3); \
198 store = __msa_splati_b((v16i8) sum_w, 0); \
199 val0 = __msa_copy_u_d((v2i64) store, 0); \
201 SD4(val0, val0, val0, val0, dst, dst_stride); \
202 dst += (4 * dst_stride); \
203 SD4(val0, val0, val0, val0, dst, dst_stride); \
206 INTRA_DC_TL_8x8(top);
207 INTRA_DC_TL_8x8(left);
209 void ff_dc_16x16_msa(uint8_t *dst, ptrdiff_t dst_stride,
210 const uint8_t *src_left, const uint8_t *src_top)
212 v16u8 top, left, out;
213 v8u16 sum_h, sum_top, sum_left;
217 top = LD_UB(src_top);
218 left = LD_UB(src_left);
219 HADD_UB2_UH(top, left, sum_top, sum_left);
220 sum_h = sum_top + sum_left;
221 sum_w = __msa_hadd_u_w(sum_h, sum_h);
222 sum_d = __msa_hadd_u_d(sum_w, sum_w);
223 sum_w = (v4u32) __msa_pckev_w((v4i32) sum_d, (v4i32) sum_d);
224 sum_d = __msa_hadd_u_d(sum_w, sum_w);
225 sum_w = (v4u32) __msa_srari_w((v4i32) sum_d, 5);
226 out = (v16u8) __msa_splati_b((v16i8) sum_w, 0);
228 ST_UB8(out, out, out, out, out, out, out, out, dst, dst_stride);
229 dst += (8 * dst_stride);
230 ST_UB8(out, out, out, out, out, out, out, out, dst, dst_stride);
233 #define INTRA_DC_TL_16x16(dir) \
234 void ff_dc_##dir##_16x16_msa(uint8_t *dst, ptrdiff_t dst_stride, \
235 const uint8_t *left, \
236 const uint8_t *top) \
244 sum_h = __msa_hadd_u_h(data, data); \
245 sum_w = __msa_hadd_u_w(sum_h, sum_h); \
246 sum_d = __msa_hadd_u_d(sum_w, sum_w); \
247 sum_w = (v4u32) __msa_pckev_w((v4i32) sum_d, (v4i32) sum_d); \
248 sum_d = __msa_hadd_u_d(sum_w, sum_w); \
249 sum_w = (v4u32) __msa_srari_w((v4i32) sum_d, 4); \
250 out = (v16u8) __msa_splati_b((v16i8) sum_w, 0); \
252 ST_UB8(out, out, out, out, out, out, out, out, dst, dst_stride); \
253 dst += (8 * dst_stride); \
254 ST_UB8(out, out, out, out, out, out, out, out, dst, dst_stride); \
256 INTRA_DC_TL_16x16(top);
257 INTRA_DC_TL_16x16(left);
259 void ff_dc_32x32_msa(uint8_t *dst, ptrdiff_t dst_stride,
260 const uint8_t *src_left, const uint8_t *src_top)
263 v16u8 top0, top1, left0, left1, out;
264 v8u16 sum_h, sum_top0, sum_top1, sum_left0, sum_left1;
268 LD_UB2(src_top, 16, top0, top1);
269 LD_UB2(src_left, 16, left0, left1);
270 HADD_UB2_UH(top0, top1, sum_top0, sum_top1);
271 HADD_UB2_UH(left0, left1, sum_left0, sum_left1);
272 sum_h = sum_top0 + sum_top1;
273 sum_h += sum_left0 + sum_left1;
274 sum_w = __msa_hadd_u_w(sum_h, sum_h);
275 sum_d = __msa_hadd_u_d(sum_w, sum_w);
276 sum_w = (v4u32) __msa_pckev_w((v4i32) sum_d, (v4i32) sum_d);
277 sum_d = __msa_hadd_u_d(sum_w, sum_w);
278 sum_w = (v4u32) __msa_srari_w((v4i32) sum_d, 6);
279 out = (v16u8) __msa_splati_b((v16i8) sum_w, 0);
281 for (row = 16; row--;)
283 ST_UB2(out, out, dst, 16);
285 ST_UB2(out, out, dst, 16);
290 #define INTRA_DC_TL_32x32(dir) \
291 void ff_dc_##dir##_32x32_msa(uint8_t *dst, ptrdiff_t dst_stride, \
292 const uint8_t *left, \
293 const uint8_t *top) \
296 v16u8 data0, data1, out; \
297 v8u16 sum_h, sum_data0, sum_data1; \
301 LD_UB2(dir, 16, data0, data1); \
302 HADD_UB2_UH(data0, data1, sum_data0, sum_data1); \
303 sum_h = sum_data0 + sum_data1; \
304 sum_w = __msa_hadd_u_w(sum_h, sum_h); \
305 sum_d = __msa_hadd_u_d(sum_w, sum_w); \
306 sum_w = (v4u32) __msa_pckev_w((v4i32) sum_d, (v4i32) sum_d); \
307 sum_d = __msa_hadd_u_d(sum_w, sum_w); \
308 sum_w = (v4u32) __msa_srari_w((v4i32) sum_d, 5); \
309 out = (v16u8) __msa_splati_b((v16i8) sum_w, 0); \
311 for (row = 16; row--;) \
313 ST_UB2(out, out, dst, 16); \
315 ST_UB2(out, out, dst, 16); \
319 INTRA_DC_TL_32x32(top);
320 INTRA_DC_TL_32x32(left);
322 #define INTRA_PREDICT_VALDC_16X16_MSA(val) \
323 void ff_dc_##val##_16x16_msa(uint8_t *dst, ptrdiff_t dst_stride, \
324 const uint8_t *left, const uint8_t *top) \
326 v16u8 out = (v16u8) __msa_ldi_b(val); \
328 ST_UB8(out, out, out, out, out, out, out, out, dst, dst_stride); \
329 dst += (8 * dst_stride); \
330 ST_UB8(out, out, out, out, out, out, out, out, dst, dst_stride); \
333 INTRA_PREDICT_VALDC_16X16_MSA(127);
334 INTRA_PREDICT_VALDC_16X16_MSA(128);
335 INTRA_PREDICT_VALDC_16X16_MSA(129);
337 #define INTRA_PREDICT_VALDC_32X32_MSA(val) \
338 void ff_dc_##val##_32x32_msa(uint8_t *dst, ptrdiff_t dst_stride, \
339 const uint8_t *left, const uint8_t *top) \
342 v16u8 out = (v16u8) __msa_ldi_b(val); \
344 for (row = 16; row--;) \
346 ST_UB2(out, out, dst, 16); \
348 ST_UB2(out, out, dst, 16); \
353 INTRA_PREDICT_VALDC_32X32_MSA(127);
354 INTRA_PREDICT_VALDC_32X32_MSA(128);
355 INTRA_PREDICT_VALDC_32X32_MSA(129);
357 void ff_tm_4x4_msa(uint8_t *dst, ptrdiff_t dst_stride,
358 const uint8_t *src_left, const uint8_t *src_top_ptr)
361 uint8_t top_left = src_top_ptr[-1];
362 v16i8 src_top, src_left0, src_left1, src_left2, src_left3, tmp0, tmp1;
363 v16u8 src0, src1, src2, src3;
364 v8u16 src_top_left, vec0, vec1, vec2, vec3;
366 src_top_left = (v8u16) __msa_fill_h(top_left);
367 src_top = LD_SB(src_top_ptr);
369 src_left0 = __msa_fill_b(left >> 24);
370 src_left1 = __msa_fill_b(left >> 16);
371 src_left2 = __msa_fill_b(left >> 8);
372 src_left3 = __msa_fill_b(left);
374 ILVR_B4_UB(src_left0, src_top, src_left1, src_top, src_left2, src_top,
375 src_left3, src_top, src0, src1, src2, src3);
376 HADD_UB4_UH(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
377 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, vec0, vec1);
378 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, vec2, vec3);
379 SAT_UH4_UH(vec0, vec1, vec2, vec3, 7);
380 PCKEV_B2_SB(vec1, vec0, vec3, vec2, tmp0, tmp1);
381 ST4x4_UB(tmp0, tmp1, 0, 2, 0, 2, dst, dst_stride);
384 void ff_tm_8x8_msa(uint8_t *dst, ptrdiff_t dst_stride,
385 const uint8_t *src_left, const uint8_t *src_top_ptr)
387 uint8_t top_left = src_top_ptr[-1];
388 uint32_t loop_cnt, left;
389 v16i8 src_top, src_left0, src_left1, src_left2, src_left3, tmp0, tmp1;
390 v8u16 src_top_left, vec0, vec1, vec2, vec3;
391 v16u8 src0, src1, src2, src3;
393 src_top = LD_SB(src_top_ptr);
394 src_top_left = (v8u16) __msa_fill_h(top_left);
397 for (loop_cnt = 2; loop_cnt--;) {
399 src_left0 = __msa_fill_b(left >> 24);
400 src_left1 = __msa_fill_b(left >> 16);
401 src_left2 = __msa_fill_b(left >> 8);
402 src_left3 = __msa_fill_b(left);
405 ILVR_B4_UB(src_left0, src_top, src_left1, src_top, src_left2, src_top,
406 src_left3, src_top, src0, src1, src2, src3);
407 HADD_UB4_UH(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
408 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, vec0, vec1);
409 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, vec2, vec3);
410 SAT_UH4_UH(vec0, vec1, vec2, vec3, 7);
411 PCKEV_B2_SB(vec1, vec0, vec3, vec2, tmp0, tmp1);
412 ST8x4_UB(tmp0, tmp1, dst, dst_stride);
413 dst += (4 * dst_stride);
417 void ff_tm_16x16_msa(uint8_t *dst, ptrdiff_t dst_stride,
418 const uint8_t *src_left, const uint8_t *src_top_ptr)
420 uint8_t top_left = src_top_ptr[-1];
421 uint32_t loop_cnt, left;
422 v16i8 src_top, src_left0, src_left1, src_left2, src_left3;
423 v8u16 src_top_left, res_r, res_l;
425 src_top = LD_SB(src_top_ptr);
426 src_top_left = (v8u16) __msa_fill_h(top_left);
429 for (loop_cnt = 4; loop_cnt--;) {
431 src_left0 = __msa_fill_b(left >> 24);
432 src_left1 = __msa_fill_b(left >> 16);
433 src_left2 = __msa_fill_b(left >> 8);
434 src_left3 = __msa_fill_b(left);
437 ILVRL_B2_UH(src_left0, src_top, res_r, res_l);
438 HADD_UB2_UH(res_r, res_l, res_r, res_l);
439 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r, res_l);
441 SAT_UH2_UH(res_r, res_l, 7);
442 PCKEV_ST_SB(res_r, res_l, dst);
445 ILVRL_B2_UH(src_left1, src_top, res_r, res_l);
446 HADD_UB2_UH(res_r, res_l, res_r, res_l);
447 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r, res_l);
448 SAT_UH2_UH(res_r, res_l, 7);
449 PCKEV_ST_SB(res_r, res_l, dst);
452 ILVRL_B2_UH(src_left2, src_top, res_r, res_l);
453 HADD_UB2_UH(res_r, res_l, res_r, res_l);
454 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r, res_l);
455 SAT_UH2_UH(res_r, res_l, 7);
456 PCKEV_ST_SB(res_r, res_l, dst);
459 ILVRL_B2_UH(src_left3, src_top, res_r, res_l);
460 HADD_UB2_UH(res_r, res_l, res_r, res_l);
461 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r, res_l);
462 SAT_UH2_UH(res_r, res_l, 7);
463 PCKEV_ST_SB(res_r, res_l, dst);
468 void ff_tm_32x32_msa(uint8_t *dst, ptrdiff_t dst_stride,
469 const uint8_t *src_left, const uint8_t *src_top_ptr)
471 uint8_t top_left = src_top_ptr[-1];
472 uint32_t loop_cnt, left;
473 v16i8 src_top0, src_top1, src_left0, src_left1, src_left2, src_left3;
474 v8u16 src_top_left, res_r0, res_r1, res_l0, res_l1;
476 src_top0 = LD_SB(src_top_ptr);
477 src_top1 = LD_SB(src_top_ptr + 16);
478 src_top_left = (v8u16) __msa_fill_h(top_left);
481 for (loop_cnt = 8; loop_cnt--;) {
483 src_left0 = __msa_fill_b(left >> 24);
484 src_left1 = __msa_fill_b(left >> 16);
485 src_left2 = __msa_fill_b(left >> 8);
486 src_left3 = __msa_fill_b(left);
489 ILVR_B2_UH(src_left0, src_top0, src_left0, src_top1, res_r0, res_r1);
490 ILVL_B2_UH(src_left0, src_top0, src_left0, src_top1, res_l0, res_l1);
491 HADD_UB4_UH(res_r0, res_l0, res_r1, res_l1, res_r0, res_l0, res_r1,
493 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r0, res_l0);
494 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r1, res_l1);
495 SAT_UH4_UH(res_r0, res_l0, res_r1, res_l1, 7);
496 PCKEV_ST_SB(res_r0, res_l0, dst);
497 PCKEV_ST_SB(res_r1, res_l1, dst + 16);
500 ILVR_B2_UH(src_left1, src_top0, src_left1, src_top1, res_r0, res_r1);
501 ILVL_B2_UH(src_left1, src_top0, src_left1, src_top1, res_l0, res_l1);
502 HADD_UB4_UH(res_r0, res_l0, res_r1, res_l1, res_r0, res_l0, res_r1,
504 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r0, res_l0);
505 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r1, res_l1);
506 SAT_UH4_UH(res_r0, res_l0, res_r1, res_l1, 7);
507 PCKEV_ST_SB(res_r0, res_l0, dst);
508 PCKEV_ST_SB(res_r1, res_l1, dst + 16);
511 ILVR_B2_UH(src_left2, src_top0, src_left2, src_top1, res_r0, res_r1);
512 ILVL_B2_UH(src_left2, src_top0, src_left2, src_top1, res_l0, res_l1);
513 HADD_UB4_UH(res_r0, res_l0, res_r1, res_l1, res_r0, res_l0, res_r1,
515 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r0, res_l0);
516 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r1, res_l1);
517 SAT_UH4_UH(res_r0, res_l0, res_r1, res_l1, 7);
518 PCKEV_ST_SB(res_r0, res_l0, dst);
519 PCKEV_ST_SB(res_r1, res_l1, dst + 16);
522 ILVR_B2_UH(src_left3, src_top0, src_left3, src_top1, res_r0, res_r1);
523 ILVL_B2_UH(src_left3, src_top0, src_left3, src_top1, res_l0, res_l1);
524 HADD_UB4_UH(res_r0, res_l0, res_r1, res_l1, res_r0, res_l0, res_r1,
526 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r0, res_l0);
527 IPRED_SUBS_UH2_UH(src_top_left, src_top_left, res_r1, res_l1);
528 SAT_UH4_UH(res_r0, res_l0, res_r1, res_l1, 7);
529 PCKEV_ST_SB(res_r0, res_l0, dst);
530 PCKEV_ST_SB(res_r1, res_l1, dst + 16);