enc_msa.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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 version of encoder dsp functions.
  11. //
  12. // Author: Prashant Patil (prashant.patil@imgtec.com)
  13. #include "./dsp.h"
  14. #if defined(WEBP_USE_MSA)
  15. #include <stdlib.h>
  16. #include "./msa_macro.h"
  17. #include "../enc/vp8i_enc.h"
  18. //------------------------------------------------------------------------------
  19. // Transforms
  20. #define IDCT_1D_W(in0, in1, in2, in3, out0, out1, out2, out3) do { \
  21. v4i32 a1_m, b1_m, c1_m, d1_m; \
  22. const v4i32 cospi8sqrt2minus1 = __msa_fill_w(20091); \
  23. const v4i32 sinpi8sqrt2 = __msa_fill_w(35468); \
  24. v4i32 c_tmp1_m = in1 * sinpi8sqrt2; \
  25. v4i32 c_tmp2_m = in3 * cospi8sqrt2minus1; \
  26. v4i32 d_tmp1_m = in1 * cospi8sqrt2minus1; \
  27. v4i32 d_tmp2_m = in3 * sinpi8sqrt2; \
  28. \
  29. ADDSUB2(in0, in2, a1_m, b1_m); \
  30. SRAI_W2_SW(c_tmp1_m, c_tmp2_m, 16); \
  31. c_tmp2_m = c_tmp2_m + in3; \
  32. c1_m = c_tmp1_m - c_tmp2_m; \
  33. SRAI_W2_SW(d_tmp1_m, d_tmp2_m, 16); \
  34. d_tmp1_m = d_tmp1_m + in1; \
  35. d1_m = d_tmp1_m + d_tmp2_m; \
  36. BUTTERFLY_4(a1_m, b1_m, c1_m, d1_m, out0, out1, out2, out3); \
  37. } while (0)
  38. static WEBP_INLINE void ITransformOne(const uint8_t* ref, const int16_t* in,
  39. uint8_t* dst) {
  40. v8i16 input0, input1;
  41. v4i32 in0, in1, in2, in3, hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3;
  42. v4i32 res0, res1, res2, res3;
  43. v16i8 dest0, dest1, dest2, dest3;
  44. const v16i8 zero = { 0 };
  45. LD_SH2(in, 8, input0, input1);
  46. UNPCK_SH_SW(input0, in0, in1);
  47. UNPCK_SH_SW(input1, in2, in3);
  48. IDCT_1D_W(in0, in1, in2, in3, hz0, hz1, hz2, hz3);
  49. TRANSPOSE4x4_SW_SW(hz0, hz1, hz2, hz3, hz0, hz1, hz2, hz3);
  50. IDCT_1D_W(hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3);
  51. SRARI_W4_SW(vt0, vt1, vt2, vt3, 3);
  52. TRANSPOSE4x4_SW_SW(vt0, vt1, vt2, vt3, vt0, vt1, vt2, vt3);
  53. LD_SB4(ref, BPS, dest0, dest1, dest2, dest3);
  54. ILVR_B4_SW(zero, dest0, zero, dest1, zero, dest2, zero, dest3,
  55. res0, res1, res2, res3);
  56. ILVR_H4_SW(zero, res0, zero, res1, zero, res2, zero, res3,
  57. res0, res1, res2, res3);
  58. ADD4(res0, vt0, res1, vt1, res2, vt2, res3, vt3, res0, res1, res2, res3);
  59. CLIP_SW4_0_255(res0, res1, res2, res3);
  60. PCKEV_B2_SW(res0, res1, res2, res3, vt0, vt1);
  61. res0 = (v4i32)__msa_pckev_b((v16i8)vt0, (v16i8)vt1);
  62. ST4x4_UB(res0, res0, 3, 2, 1, 0, dst, BPS);
  63. }
  64. static void ITransform_MSA(const uint8_t* ref, const int16_t* in, uint8_t* dst,
  65. int do_two) {
  66. ITransformOne(ref, in, dst);
  67. if (do_two) {
  68. ITransformOne(ref + 4, in + 16, dst + 4);
  69. }
  70. }
  71. static void FTransform_MSA(const uint8_t* src, const uint8_t* ref,
  72. int16_t* out) {
  73. uint64_t out0, out1, out2, out3;
  74. uint32_t in0, in1, in2, in3;
  75. v4i32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  76. v8i16 t0, t1, t2, t3;
  77. v16u8 srcl0, srcl1, src0 = { 0 }, src1 = { 0 };
  78. const v8i16 mask0 = { 0, 4, 8, 12, 1, 5, 9, 13 };
  79. const v8i16 mask1 = { 3, 7, 11, 15, 2, 6, 10, 14 };
  80. const v8i16 mask2 = { 4, 0, 5, 1, 6, 2, 7, 3 };
  81. const v8i16 mask3 = { 0, 4, 1, 5, 2, 6, 3, 7 };
  82. const v8i16 cnst0 = { 2217, -5352, 2217, -5352, 2217, -5352, 2217, -5352 };
  83. const v8i16 cnst1 = { 5352, 2217, 5352, 2217, 5352, 2217, 5352, 2217 };
  84. LW4(src, BPS, in0, in1, in2, in3);
  85. INSERT_W4_UB(in0, in1, in2, in3, src0);
  86. LW4(ref, BPS, in0, in1, in2, in3);
  87. INSERT_W4_UB(in0, in1, in2, in3, src1);
  88. ILVRL_B2_UB(src0, src1, srcl0, srcl1);
  89. HSUB_UB2_SH(srcl0, srcl1, t0, t1);
  90. VSHF_H2_SH(t0, t1, t0, t1, mask0, mask1, t2, t3);
  91. ADDSUB2(t2, t3, t0, t1);
  92. t0 = SRLI_H(t0, 3);
  93. VSHF_H2_SH(t0, t0, t1, t1, mask2, mask3, t3, t2);
  94. tmp0 = __msa_hadd_s_w(t3, t3);
  95. tmp2 = __msa_hsub_s_w(t3, t3);
  96. FILL_W2_SW(1812, 937, tmp1, tmp3);
  97. DPADD_SH2_SW(t2, t2, cnst0, cnst1, tmp3, tmp1);
  98. SRAI_W2_SW(tmp1, tmp3, 9);
  99. PCKEV_H2_SH(tmp1, tmp0, tmp3, tmp2, t0, t1);
  100. VSHF_H2_SH(t0, t1, t0, t1, mask0, mask1, t2, t3);
  101. ADDSUB2(t2, t3, t0, t1);
  102. VSHF_H2_SH(t0, t0, t1, t1, mask2, mask3, t3, t2);
  103. tmp0 = __msa_hadd_s_w(t3, t3);
  104. tmp2 = __msa_hsub_s_w(t3, t3);
  105. ADDVI_W2_SW(tmp0, 7, tmp2, 7, tmp0, tmp2);
  106. SRAI_W2_SW(tmp0, tmp2, 4);
  107. FILL_W2_SW(12000, 51000, tmp1, tmp3);
  108. DPADD_SH2_SW(t2, t2, cnst0, cnst1, tmp3, tmp1);
  109. SRAI_W2_SW(tmp1, tmp3, 16);
  110. UNPCK_R_SH_SW(t1, tmp4);
  111. tmp5 = __msa_ceqi_w(tmp4, 0);
  112. tmp4 = (v4i32)__msa_nor_v((v16u8)tmp5, (v16u8)tmp5);
  113. tmp5 = __msa_fill_w(1);
  114. tmp5 = (v4i32)__msa_and_v((v16u8)tmp5, (v16u8)tmp4);
  115. tmp1 += tmp5;
  116. PCKEV_H2_SH(tmp1, tmp0, tmp3, tmp2, t0, t1);
  117. out0 = __msa_copy_s_d((v2i64)t0, 0);
  118. out1 = __msa_copy_s_d((v2i64)t0, 1);
  119. out2 = __msa_copy_s_d((v2i64)t1, 0);
  120. out3 = __msa_copy_s_d((v2i64)t1, 1);
  121. SD4(out0, out1, out2, out3, out, 8);
  122. }
  123. static void FTransformWHT_MSA(const int16_t* in, int16_t* out) {
  124. v8i16 in0 = { 0 };
  125. v8i16 in1 = { 0 };
  126. v8i16 tmp0, tmp1, tmp2, tmp3;
  127. v8i16 out0, out1;
  128. const v8i16 mask0 = { 0, 1, 2, 3, 8, 9, 10, 11 };
  129. const v8i16 mask1 = { 4, 5, 6, 7, 12, 13, 14, 15 };
  130. const v8i16 mask2 = { 0, 4, 8, 12, 1, 5, 9, 13 };
  131. const v8i16 mask3 = { 3, 7, 11, 15, 2, 6, 10, 14 };
  132. in0 = __msa_insert_h(in0, 0, in[ 0]);
  133. in0 = __msa_insert_h(in0, 1, in[ 64]);
  134. in0 = __msa_insert_h(in0, 2, in[128]);
  135. in0 = __msa_insert_h(in0, 3, in[192]);
  136. in0 = __msa_insert_h(in0, 4, in[ 16]);
  137. in0 = __msa_insert_h(in0, 5, in[ 80]);
  138. in0 = __msa_insert_h(in0, 6, in[144]);
  139. in0 = __msa_insert_h(in0, 7, in[208]);
  140. in1 = __msa_insert_h(in1, 0, in[ 48]);
  141. in1 = __msa_insert_h(in1, 1, in[112]);
  142. in1 = __msa_insert_h(in1, 2, in[176]);
  143. in1 = __msa_insert_h(in1, 3, in[240]);
  144. in1 = __msa_insert_h(in1, 4, in[ 32]);
  145. in1 = __msa_insert_h(in1, 5, in[ 96]);
  146. in1 = __msa_insert_h(in1, 6, in[160]);
  147. in1 = __msa_insert_h(in1, 7, in[224]);
  148. ADDSUB2(in0, in1, tmp0, tmp1);
  149. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask0, mask1, tmp2, tmp3);
  150. ADDSUB2(tmp2, tmp3, tmp0, tmp1);
  151. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask2, mask3, in0, in1);
  152. ADDSUB2(in0, in1, tmp0, tmp1);
  153. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask0, mask1, tmp2, tmp3);
  154. ADDSUB2(tmp2, tmp3, out0, out1);
  155. SRAI_H2_SH(out0, out1, 1);
  156. ST_SH2(out0, out1, out, 8);
  157. }
  158. static int TTransform_MSA(const uint8_t* in, const uint16_t* w) {
  159. int sum;
  160. uint32_t in0_m, in1_m, in2_m, in3_m;
  161. v16i8 src0 = { 0 };
  162. v8i16 in0, in1, tmp0, tmp1, tmp2, tmp3;
  163. v4i32 dst0, dst1;
  164. const v16i8 zero = { 0 };
  165. const v8i16 mask0 = { 0, 1, 2, 3, 8, 9, 10, 11 };
  166. const v8i16 mask1 = { 4, 5, 6, 7, 12, 13, 14, 15 };
  167. const v8i16 mask2 = { 0, 4, 8, 12, 1, 5, 9, 13 };
  168. const v8i16 mask3 = { 3, 7, 11, 15, 2, 6, 10, 14 };
  169. LW4(in, BPS, in0_m, in1_m, in2_m, in3_m);
  170. INSERT_W4_SB(in0_m, in1_m, in2_m, in3_m, src0);
  171. ILVRL_B2_SH(zero, src0, tmp0, tmp1);
  172. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask2, mask3, in0, in1);
  173. ADDSUB2(in0, in1, tmp0, tmp1);
  174. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask0, mask1, tmp2, tmp3);
  175. ADDSUB2(tmp2, tmp3, tmp0, tmp1);
  176. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask2, mask3, in0, in1);
  177. ADDSUB2(in0, in1, tmp0, tmp1);
  178. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask0, mask1, tmp2, tmp3);
  179. ADDSUB2(tmp2, tmp3, tmp0, tmp1);
  180. tmp0 = __msa_add_a_h(tmp0, (v8i16)zero);
  181. tmp1 = __msa_add_a_h(tmp1, (v8i16)zero);
  182. LD_SH2(w, 8, tmp2, tmp3);
  183. DOTP_SH2_SW(tmp0, tmp1, tmp2, tmp3, dst0, dst1);
  184. dst0 = dst0 + dst1;
  185. sum = HADD_SW_S32(dst0);
  186. return sum;
  187. }
  188. static int Disto4x4_MSA(const uint8_t* const a, const uint8_t* const b,
  189. const uint16_t* const w) {
  190. const int sum1 = TTransform_MSA(a, w);
  191. const int sum2 = TTransform_MSA(b, w);
  192. return abs(sum2 - sum1) >> 5;
  193. }
  194. static int Disto16x16_MSA(const uint8_t* const a, const uint8_t* const b,
  195. const uint16_t* const w) {
  196. int D = 0;
  197. int x, y;
  198. for (y = 0; y < 16 * BPS; y += 4 * BPS) {
  199. for (x = 0; x < 16; x += 4) {
  200. D += Disto4x4_MSA(a + x + y, b + x + y, w);
  201. }
  202. }
  203. return D;
  204. }
  205. //------------------------------------------------------------------------------
  206. // Histogram
  207. static void CollectHistogram_MSA(const uint8_t* ref, const uint8_t* pred,
  208. int start_block, int end_block,
  209. VP8Histogram* const histo) {
  210. int j;
  211. int distribution[MAX_COEFF_THRESH + 1] = { 0 };
  212. for (j = start_block; j < end_block; ++j) {
  213. int16_t out[16];
  214. VP8FTransform(ref + VP8DspScan[j], pred + VP8DspScan[j], out);
  215. {
  216. int k;
  217. v8i16 coeff0, coeff1;
  218. const v8i16 zero = { 0 };
  219. const v8i16 max_coeff_thr = __msa_ldi_h(MAX_COEFF_THRESH);
  220. LD_SH2(&out[0], 8, coeff0, coeff1);
  221. coeff0 = __msa_add_a_h(coeff0, zero);
  222. coeff1 = __msa_add_a_h(coeff1, zero);
  223. SRAI_H2_SH(coeff0, coeff1, 3);
  224. coeff0 = __msa_min_s_h(coeff0, max_coeff_thr);
  225. coeff1 = __msa_min_s_h(coeff1, max_coeff_thr);
  226. ST_SH2(coeff0, coeff1, &out[0], 8);
  227. for (k = 0; k < 16; ++k) {
  228. ++distribution[out[k]];
  229. }
  230. }
  231. }
  232. VP8SetHistogramData(distribution, histo);
  233. }
  234. //------------------------------------------------------------------------------
  235. // Intra predictions
  236. // luma 4x4 prediction
  237. #define DST(x, y) dst[(x) + (y) * BPS]
  238. #define AVG3(a, b, c) (((a) + 2 * (b) + (c) + 2) >> 2)
  239. #define AVG2(a, b) (((a) + (b) + 1) >> 1)
  240. static WEBP_INLINE void VE4(uint8_t* dst, const uint8_t* top) { // vertical
  241. const v16u8 A1 = { 0 };
  242. const uint64_t val_m = LD(top - 1);
  243. const v16u8 A = (v16u8)__msa_insert_d((v2i64)A1, 0, val_m);
  244. const v16u8 B = SLDI_UB(A, A, 1);
  245. const v16u8 C = SLDI_UB(A, A, 2);
  246. const v16u8 AC = __msa_ave_u_b(A, C);
  247. const v16u8 B2 = __msa_ave_u_b(B, B);
  248. const v16u8 R = __msa_aver_u_b(AC, B2);
  249. const uint32_t out = __msa_copy_s_w((v4i32)R, 0);
  250. SW4(out, out, out, out, dst, BPS);
  251. }
  252. static WEBP_INLINE void HE4(uint8_t* dst, const uint8_t* top) { // horizontal
  253. const int X = top[-1];
  254. const int I = top[-2];
  255. const int J = top[-3];
  256. const int K = top[-4];
  257. const int L = top[-5];
  258. WebPUint32ToMem(dst + 0 * BPS, 0x01010101U * AVG3(X, I, J));
  259. WebPUint32ToMem(dst + 1 * BPS, 0x01010101U * AVG3(I, J, K));
  260. WebPUint32ToMem(dst + 2 * BPS, 0x01010101U * AVG3(J, K, L));
  261. WebPUint32ToMem(dst + 3 * BPS, 0x01010101U * AVG3(K, L, L));
  262. }
  263. static WEBP_INLINE void DC4(uint8_t* dst, const uint8_t* top) {
  264. uint32_t dc = 4;
  265. int i;
  266. for (i = 0; i < 4; ++i) dc += top[i] + top[-5 + i];
  267. dc >>= 3;
  268. dc = dc | (dc << 8) | (dc << 16) | (dc << 24);
  269. SW4(dc, dc, dc, dc, dst, BPS);
  270. }
  271. static WEBP_INLINE void RD4(uint8_t* dst, const uint8_t* top) {
  272. const v16u8 A2 = { 0 };
  273. const uint64_t val_m = LD(top - 5);
  274. const v16u8 A1 = (v16u8)__msa_insert_d((v2i64)A2, 0, val_m);
  275. const v16u8 A = (v16u8)__msa_insert_b((v16i8)A1, 8, top[3]);
  276. const v16u8 B = SLDI_UB(A, A, 1);
  277. const v16u8 C = SLDI_UB(A, A, 2);
  278. const v16u8 AC = __msa_ave_u_b(A, C);
  279. const v16u8 B2 = __msa_ave_u_b(B, B);
  280. const v16u8 R0 = __msa_aver_u_b(AC, B2);
  281. const v16u8 R1 = SLDI_UB(R0, R0, 1);
  282. const v16u8 R2 = SLDI_UB(R1, R1, 1);
  283. const v16u8 R3 = SLDI_UB(R2, R2, 1);
  284. const uint32_t val0 = __msa_copy_s_w((v4i32)R0, 0);
  285. const uint32_t val1 = __msa_copy_s_w((v4i32)R1, 0);
  286. const uint32_t val2 = __msa_copy_s_w((v4i32)R2, 0);
  287. const uint32_t val3 = __msa_copy_s_w((v4i32)R3, 0);
  288. SW4(val3, val2, val1, val0, dst, BPS);
  289. }
  290. static WEBP_INLINE void LD4(uint8_t* dst, const uint8_t* top) {
  291. const v16u8 A1 = { 0 };
  292. const uint64_t val_m = LD(top);
  293. const v16u8 A = (v16u8)__msa_insert_d((v2i64)A1, 0, val_m);
  294. const v16u8 B = SLDI_UB(A, A, 1);
  295. const v16u8 C1 = SLDI_UB(A, A, 2);
  296. const v16u8 C = (v16u8)__msa_insert_b((v16i8)C1, 6, top[7]);
  297. const v16u8 AC = __msa_ave_u_b(A, C);
  298. const v16u8 B2 = __msa_ave_u_b(B, B);
  299. const v16u8 R0 = __msa_aver_u_b(AC, B2);
  300. const v16u8 R1 = SLDI_UB(R0, R0, 1);
  301. const v16u8 R2 = SLDI_UB(R1, R1, 1);
  302. const v16u8 R3 = SLDI_UB(R2, R2, 1);
  303. const uint32_t val0 = __msa_copy_s_w((v4i32)R0, 0);
  304. const uint32_t val1 = __msa_copy_s_w((v4i32)R1, 0);
  305. const uint32_t val2 = __msa_copy_s_w((v4i32)R2, 0);
  306. const uint32_t val3 = __msa_copy_s_w((v4i32)R3, 0);
  307. SW4(val0, val1, val2, val3, dst, BPS);
  308. }
  309. static WEBP_INLINE void VR4(uint8_t* dst, const uint8_t* top) {
  310. const int X = top[-1];
  311. const int I = top[-2];
  312. const int J = top[-3];
  313. const int K = top[-4];
  314. const int A = top[0];
  315. const int B = top[1];
  316. const int C = top[2];
  317. const int D = top[3];
  318. DST(0, 0) = DST(1, 2) = AVG2(X, A);
  319. DST(1, 0) = DST(2, 2) = AVG2(A, B);
  320. DST(2, 0) = DST(3, 2) = AVG2(B, C);
  321. DST(3, 0) = AVG2(C, D);
  322. DST(0, 3) = AVG3(K, J, I);
  323. DST(0, 2) = AVG3(J, I, X);
  324. DST(0, 1) = DST(1, 3) = AVG3(I, X, A);
  325. DST(1, 1) = DST(2, 3) = AVG3(X, A, B);
  326. DST(2, 1) = DST(3, 3) = AVG3(A, B, C);
  327. DST(3, 1) = AVG3(B, C, D);
  328. }
  329. static WEBP_INLINE void VL4(uint8_t* dst, const uint8_t* top) {
  330. const int A = top[0];
  331. const int B = top[1];
  332. const int C = top[2];
  333. const int D = top[3];
  334. const int E = top[4];
  335. const int F = top[5];
  336. const int G = top[6];
  337. const int H = top[7];
  338. DST(0, 0) = AVG2(A, B);
  339. DST(1, 0) = DST(0, 2) = AVG2(B, C);
  340. DST(2, 0) = DST(1, 2) = AVG2(C, D);
  341. DST(3, 0) = DST(2, 2) = AVG2(D, E);
  342. DST(0, 1) = AVG3(A, B, C);
  343. DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
  344. DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
  345. DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
  346. DST(3, 2) = AVG3(E, F, G);
  347. DST(3, 3) = AVG3(F, G, H);
  348. }
  349. static WEBP_INLINE void HU4(uint8_t* dst, const uint8_t* top) {
  350. const int I = top[-2];
  351. const int J = top[-3];
  352. const int K = top[-4];
  353. const int L = top[-5];
  354. DST(0, 0) = AVG2(I, J);
  355. DST(2, 0) = DST(0, 1) = AVG2(J, K);
  356. DST(2, 1) = DST(0, 2) = AVG2(K, L);
  357. DST(1, 0) = AVG3(I, J, K);
  358. DST(3, 0) = DST(1, 1) = AVG3(J, K, L);
  359. DST(3, 1) = DST(1, 2) = AVG3(K, L, L);
  360. DST(3, 2) = DST(2, 2) =
  361. DST(0, 3) = DST(1, 3) = DST(2, 3) = DST(3, 3) = L;
  362. }
  363. static WEBP_INLINE void HD4(uint8_t* dst, const uint8_t* top) {
  364. const int X = top[-1];
  365. const int I = top[-2];
  366. const int J = top[-3];
  367. const int K = top[-4];
  368. const int L = top[-5];
  369. const int A = top[0];
  370. const int B = top[1];
  371. const int C = top[2];
  372. DST(0, 0) = DST(2, 1) = AVG2(I, X);
  373. DST(0, 1) = DST(2, 2) = AVG2(J, I);
  374. DST(0, 2) = DST(2, 3) = AVG2(K, J);
  375. DST(0, 3) = AVG2(L, K);
  376. DST(3, 0) = AVG3(A, B, C);
  377. DST(2, 0) = AVG3(X, A, B);
  378. DST(1, 0) = DST(3, 1) = AVG3(I, X, A);
  379. DST(1, 1) = DST(3, 2) = AVG3(J, I, X);
  380. DST(1, 2) = DST(3, 3) = AVG3(K, J, I);
  381. DST(1, 3) = AVG3(L, K, J);
  382. }
  383. static WEBP_INLINE void TM4(uint8_t* dst, const uint8_t* top) {
  384. const v16i8 zero = { 0 };
  385. const v8i16 TL = (v8i16)__msa_fill_h(top[-1]);
  386. const v8i16 L0 = (v8i16)__msa_fill_h(top[-2]);
  387. const v8i16 L1 = (v8i16)__msa_fill_h(top[-3]);
  388. const v8i16 L2 = (v8i16)__msa_fill_h(top[-4]);
  389. const v8i16 L3 = (v8i16)__msa_fill_h(top[-5]);
  390. const v16u8 T1 = LD_UB(top);
  391. const v8i16 T = (v8i16)__msa_ilvr_b(zero, (v16i8)T1);
  392. const v8i16 d = T - TL;
  393. v8i16 r0, r1, r2, r3;
  394. ADD4(d, L0, d, L1, d, L2, d, L3, r0, r1, r2, r3);
  395. CLIP_SH4_0_255(r0, r1, r2, r3);
  396. PCKEV_ST4x4_UB(r0, r1, r2, r3, dst, BPS);
  397. }
  398. #undef DST
  399. #undef AVG3
  400. #undef AVG2
  401. static void Intra4Preds_MSA(uint8_t* dst, const uint8_t* top) {
  402. DC4(I4DC4 + dst, top);
  403. TM4(I4TM4 + dst, top);
  404. VE4(I4VE4 + dst, top);
  405. HE4(I4HE4 + dst, top);
  406. RD4(I4RD4 + dst, top);
  407. VR4(I4VR4 + dst, top);
  408. LD4(I4LD4 + dst, top);
  409. VL4(I4VL4 + dst, top);
  410. HD4(I4HD4 + dst, top);
  411. HU4(I4HU4 + dst, top);
  412. }
  413. // luma 16x16 prediction
  414. #define STORE16x16(out, dst) do { \
  415. ST_UB8(out, out, out, out, out, out, out, out, dst + 0 * BPS, BPS); \
  416. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS); \
  417. } while (0)
  418. static WEBP_INLINE void VerticalPred16x16(uint8_t* dst, const uint8_t* top) {
  419. if (top != NULL) {
  420. const v16u8 out = LD_UB(top);
  421. STORE16x16(out, dst);
  422. } else {
  423. const v16u8 out = (v16u8)__msa_fill_b(0x7f);
  424. STORE16x16(out, dst);
  425. }
  426. }
  427. static WEBP_INLINE void HorizontalPred16x16(uint8_t* dst,
  428. const uint8_t* left) {
  429. if (left != NULL) {
  430. int j;
  431. for (j = 0; j < 16; j += 4) {
  432. const v16u8 L0 = (v16u8)__msa_fill_b(left[0]);
  433. const v16u8 L1 = (v16u8)__msa_fill_b(left[1]);
  434. const v16u8 L2 = (v16u8)__msa_fill_b(left[2]);
  435. const v16u8 L3 = (v16u8)__msa_fill_b(left[3]);
  436. ST_UB4(L0, L1, L2, L3, dst, BPS);
  437. dst += 4 * BPS;
  438. left += 4;
  439. }
  440. } else {
  441. const v16u8 out = (v16u8)__msa_fill_b(0x81);
  442. STORE16x16(out, dst);
  443. }
  444. }
  445. static WEBP_INLINE void TrueMotion16x16(uint8_t* dst, const uint8_t* left,
  446. const uint8_t* top) {
  447. if (left != NULL) {
  448. if (top != NULL) {
  449. int j;
  450. v8i16 d1, d2;
  451. const v16i8 zero = { 0 };
  452. const v8i16 TL = (v8i16)__msa_fill_h(left[-1]);
  453. const v16u8 T = LD_UB(top);
  454. ILVRL_B2_SH(zero, T, d1, d2);
  455. SUB2(d1, TL, d2, TL, d1, d2);
  456. for (j = 0; j < 16; j += 4) {
  457. v16i8 t0, t1, t2, t3;
  458. v8i16 r0, r1, r2, r3, r4, r5, r6, r7;
  459. const v8i16 L0 = (v8i16)__msa_fill_h(left[j + 0]);
  460. const v8i16 L1 = (v8i16)__msa_fill_h(left[j + 1]);
  461. const v8i16 L2 = (v8i16)__msa_fill_h(left[j + 2]);
  462. const v8i16 L3 = (v8i16)__msa_fill_h(left[j + 3]);
  463. ADD4(d1, L0, d1, L1, d1, L2, d1, L3, r0, r1, r2, r3);
  464. ADD4(d2, L0, d2, L1, d2, L2, d2, L3, r4, r5, r6, r7);
  465. CLIP_SH4_0_255(r0, r1, r2, r3);
  466. CLIP_SH4_0_255(r4, r5, r6, r7);
  467. PCKEV_B4_SB(r4, r0, r5, r1, r6, r2, r7, r3, t0, t1, t2, t3);
  468. ST_SB4(t0, t1, t2, t3, dst, BPS);
  469. dst += 4 * BPS;
  470. }
  471. } else {
  472. HorizontalPred16x16(dst, left);
  473. }
  474. } else {
  475. if (top != NULL) {
  476. VerticalPred16x16(dst, top);
  477. } else {
  478. const v16u8 out = (v16u8)__msa_fill_b(0x81);
  479. STORE16x16(out, dst);
  480. }
  481. }
  482. }
  483. static WEBP_INLINE void DCMode16x16(uint8_t* dst, const uint8_t* left,
  484. const uint8_t* top) {
  485. int DC;
  486. v16u8 out;
  487. if (top != NULL && left != NULL) {
  488. const v16u8 rtop = LD_UB(top);
  489. const v8u16 dctop = __msa_hadd_u_h(rtop, rtop);
  490. const v16u8 rleft = LD_UB(left);
  491. const v8u16 dcleft = __msa_hadd_u_h(rleft, rleft);
  492. const v8u16 dctemp = dctop + dcleft;
  493. DC = HADD_UH_U32(dctemp);
  494. DC = (DC + 16) >> 5;
  495. } else if (left != NULL) { // left but no top
  496. const v16u8 rleft = LD_UB(left);
  497. const v8u16 dcleft = __msa_hadd_u_h(rleft, rleft);
  498. DC = HADD_UH_U32(dcleft);
  499. DC = (DC + DC + 16) >> 5;
  500. } else if (top != NULL) { // top but no left
  501. const v16u8 rtop = LD_UB(top);
  502. const v8u16 dctop = __msa_hadd_u_h(rtop, rtop);
  503. DC = HADD_UH_U32(dctop);
  504. DC = (DC + DC + 16) >> 5;
  505. } else { // no top, no left, nothing.
  506. DC = 0x80;
  507. }
  508. out = (v16u8)__msa_fill_b(DC);
  509. STORE16x16(out, dst);
  510. }
  511. static void Intra16Preds_MSA(uint8_t* dst,
  512. const uint8_t* left, const uint8_t* top) {
  513. DCMode16x16(I16DC16 + dst, left, top);
  514. VerticalPred16x16(I16VE16 + dst, top);
  515. HorizontalPred16x16(I16HE16 + dst, left);
  516. TrueMotion16x16(I16TM16 + dst, left, top);
  517. }
  518. // Chroma 8x8 prediction
  519. #define CALC_DC8(in, out) do { \
  520. const v8u16 temp0 = __msa_hadd_u_h(in, in); \
  521. const v4u32 temp1 = __msa_hadd_u_w(temp0, temp0); \
  522. const v2i64 temp2 = (v2i64)__msa_hadd_u_d(temp1, temp1); \
  523. const v2i64 temp3 = __msa_splati_d(temp2, 1); \
  524. const v2i64 temp4 = temp3 + temp2; \
  525. const v16i8 temp5 = (v16i8)__msa_srari_d(temp4, 4); \
  526. const v2i64 temp6 = (v2i64)__msa_splati_b(temp5, 0); \
  527. out = __msa_copy_s_d(temp6, 0); \
  528. } while (0)
  529. #define STORE8x8(out, dst) do { \
  530. SD4(out, out, out, out, dst + 0 * BPS, BPS); \
  531. SD4(out, out, out, out, dst + 4 * BPS, BPS); \
  532. } while (0)
  533. static WEBP_INLINE void VerticalPred8x8(uint8_t* dst, const uint8_t* top) {
  534. if (top != NULL) {
  535. const uint64_t out = LD(top);
  536. STORE8x8(out, dst);
  537. } else {
  538. const uint64_t out = 0x7f7f7f7f7f7f7f7fULL;
  539. STORE8x8(out, dst);
  540. }
  541. }
  542. static WEBP_INLINE void HorizontalPred8x8(uint8_t* dst, const uint8_t* left) {
  543. if (left != NULL) {
  544. int j;
  545. for (j = 0; j < 8; j += 4) {
  546. const v16u8 L0 = (v16u8)__msa_fill_b(left[0]);
  547. const v16u8 L1 = (v16u8)__msa_fill_b(left[1]);
  548. const v16u8 L2 = (v16u8)__msa_fill_b(left[2]);
  549. const v16u8 L3 = (v16u8)__msa_fill_b(left[3]);
  550. const uint64_t out0 = __msa_copy_s_d((v2i64)L0, 0);
  551. const uint64_t out1 = __msa_copy_s_d((v2i64)L1, 0);
  552. const uint64_t out2 = __msa_copy_s_d((v2i64)L2, 0);
  553. const uint64_t out3 = __msa_copy_s_d((v2i64)L3, 0);
  554. SD4(out0, out1, out2, out3, dst, BPS);
  555. dst += 4 * BPS;
  556. left += 4;
  557. }
  558. } else {
  559. const uint64_t out = 0x8181818181818181ULL;
  560. STORE8x8(out, dst);
  561. }
  562. }
  563. static WEBP_INLINE void TrueMotion8x8(uint8_t* dst, const uint8_t* left,
  564. const uint8_t* top) {
  565. if (left != NULL) {
  566. if (top != NULL) {
  567. int j;
  568. const v8i16 TL = (v8i16)__msa_fill_h(left[-1]);
  569. const v16u8 T1 = LD_UB(top);
  570. const v16i8 zero = { 0 };
  571. const v8i16 T = (v8i16)__msa_ilvr_b(zero, (v16i8)T1);
  572. const v8i16 d = T - TL;
  573. for (j = 0; j < 8; j += 4) {
  574. uint64_t out0, out1, out2, out3;
  575. v16i8 t0, t1;
  576. v8i16 r0 = (v8i16)__msa_fill_h(left[j + 0]);
  577. v8i16 r1 = (v8i16)__msa_fill_h(left[j + 1]);
  578. v8i16 r2 = (v8i16)__msa_fill_h(left[j + 2]);
  579. v8i16 r3 = (v8i16)__msa_fill_h(left[j + 3]);
  580. ADD4(d, r0, d, r1, d, r2, d, r3, r0, r1, r2, r3);
  581. CLIP_SH4_0_255(r0, r1, r2, r3);
  582. PCKEV_B2_SB(r1, r0, r3, r2, t0, t1);
  583. out0 = __msa_copy_s_d((v2i64)t0, 0);
  584. out1 = __msa_copy_s_d((v2i64)t0, 1);
  585. out2 = __msa_copy_s_d((v2i64)t1, 0);
  586. out3 = __msa_copy_s_d((v2i64)t1, 1);
  587. SD4(out0, out1, out2, out3, dst, BPS);
  588. dst += 4 * BPS;
  589. }
  590. } else {
  591. HorizontalPred8x8(dst, left);
  592. }
  593. } else {
  594. if (top != NULL) {
  595. VerticalPred8x8(dst, top);
  596. } else {
  597. const uint64_t out = 0x8181818181818181ULL;
  598. STORE8x8(out, dst);
  599. }
  600. }
  601. }
  602. static WEBP_INLINE void DCMode8x8(uint8_t* dst, const uint8_t* left,
  603. const uint8_t* top) {
  604. uint64_t out;
  605. v16u8 src = { 0 };
  606. if (top != NULL && left != NULL) {
  607. const uint64_t left_m = LD(left);
  608. const uint64_t top_m = LD(top);
  609. INSERT_D2_UB(left_m, top_m, src);
  610. CALC_DC8(src, out);
  611. } else if (left != NULL) { // left but no top
  612. const uint64_t left_m = LD(left);
  613. INSERT_D2_UB(left_m, left_m, src);
  614. CALC_DC8(src, out);
  615. } else if (top != NULL) { // top but no left
  616. const uint64_t top_m = LD(top);
  617. INSERT_D2_UB(top_m, top_m, src);
  618. CALC_DC8(src, out);
  619. } else { // no top, no left, nothing.
  620. src = (v16u8)__msa_fill_b(0x80);
  621. out = __msa_copy_s_d((v2i64)src, 0);
  622. }
  623. STORE8x8(out, dst);
  624. }
  625. static void IntraChromaPreds_MSA(uint8_t* dst, const uint8_t* left,
  626. const uint8_t* top) {
  627. // U block
  628. DCMode8x8(C8DC8 + dst, left, top);
  629. VerticalPred8x8(C8VE8 + dst, top);
  630. HorizontalPred8x8(C8HE8 + dst, left);
  631. TrueMotion8x8(C8TM8 + dst, left, top);
  632. // V block
  633. dst += 8;
  634. if (top != NULL) top += 8;
  635. if (left != NULL) left += 16;
  636. DCMode8x8(C8DC8 + dst, left, top);
  637. VerticalPred8x8(C8VE8 + dst, top);
  638. HorizontalPred8x8(C8HE8 + dst, left);
  639. TrueMotion8x8(C8TM8 + dst, left, top);
  640. }
  641. //------------------------------------------------------------------------------
  642. // Metric
  643. #define PACK_DOTP_UB4_SW(in0, in1, in2, in3, out0, out1, out2, out3) do { \
  644. v16u8 tmp0, tmp1; \
  645. v8i16 tmp2, tmp3; \
  646. ILVRL_B2_UB(in0, in1, tmp0, tmp1); \
  647. HSUB_UB2_SH(tmp0, tmp1, tmp2, tmp3); \
  648. DOTP_SH2_SW(tmp2, tmp3, tmp2, tmp3, out0, out1); \
  649. ILVRL_B2_UB(in2, in3, tmp0, tmp1); \
  650. HSUB_UB2_SH(tmp0, tmp1, tmp2, tmp3); \
  651. DOTP_SH2_SW(tmp2, tmp3, tmp2, tmp3, out2, out3); \
  652. } while (0)
  653. #define PACK_DPADD_UB4_SW(in0, in1, in2, in3, out0, out1, out2, out3) do { \
  654. v16u8 tmp0, tmp1; \
  655. v8i16 tmp2, tmp3; \
  656. ILVRL_B2_UB(in0, in1, tmp0, tmp1); \
  657. HSUB_UB2_SH(tmp0, tmp1, tmp2, tmp3); \
  658. DPADD_SH2_SW(tmp2, tmp3, tmp2, tmp3, out0, out1); \
  659. ILVRL_B2_UB(in2, in3, tmp0, tmp1); \
  660. HSUB_UB2_SH(tmp0, tmp1, tmp2, tmp3); \
  661. DPADD_SH2_SW(tmp2, tmp3, tmp2, tmp3, out2, out3); \
  662. } while (0)
  663. static int SSE16x16_MSA(const uint8_t* a, const uint8_t* b) {
  664. uint32_t sum;
  665. v16u8 src0, src1, src2, src3, src4, src5, src6, src7;
  666. v16u8 ref0, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
  667. v4i32 out0, out1, out2, out3;
  668. LD_UB8(a, BPS, src0, src1, src2, src3, src4, src5, src6, src7);
  669. LD_UB8(b, BPS, ref0, ref1, ref2, ref3, ref4, ref5, ref6, ref7);
  670. PACK_DOTP_UB4_SW(src0, ref0, src1, ref1, out0, out1, out2, out3);
  671. PACK_DPADD_UB4_SW(src2, ref2, src3, ref3, out0, out1, out2, out3);
  672. PACK_DPADD_UB4_SW(src4, ref4, src5, ref5, out0, out1, out2, out3);
  673. PACK_DPADD_UB4_SW(src6, ref6, src7, ref7, out0, out1, out2, out3);
  674. a += 8 * BPS;
  675. b += 8 * BPS;
  676. LD_UB8(a, BPS, src0, src1, src2, src3, src4, src5, src6, src7);
  677. LD_UB8(b, BPS, ref0, ref1, ref2, ref3, ref4, ref5, ref6, ref7);
  678. PACK_DPADD_UB4_SW(src0, ref0, src1, ref1, out0, out1, out2, out3);
  679. PACK_DPADD_UB4_SW(src2, ref2, src3, ref3, out0, out1, out2, out3);
  680. PACK_DPADD_UB4_SW(src4, ref4, src5, ref5, out0, out1, out2, out3);
  681. PACK_DPADD_UB4_SW(src6, ref6, src7, ref7, out0, out1, out2, out3);
  682. out0 += out1;
  683. out2 += out3;
  684. out0 += out2;
  685. sum = HADD_SW_S32(out0);
  686. return sum;
  687. }
  688. static int SSE16x8_MSA(const uint8_t* a, const uint8_t* b) {
  689. uint32_t sum;
  690. v16u8 src0, src1, src2, src3, src4, src5, src6, src7;
  691. v16u8 ref0, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
  692. v4i32 out0, out1, out2, out3;
  693. LD_UB8(a, BPS, src0, src1, src2, src3, src4, src5, src6, src7);
  694. LD_UB8(b, BPS, ref0, ref1, ref2, ref3, ref4, ref5, ref6, ref7);
  695. PACK_DOTP_UB4_SW(src0, ref0, src1, ref1, out0, out1, out2, out3);
  696. PACK_DPADD_UB4_SW(src2, ref2, src3, ref3, out0, out1, out2, out3);
  697. PACK_DPADD_UB4_SW(src4, ref4, src5, ref5, out0, out1, out2, out3);
  698. PACK_DPADD_UB4_SW(src6, ref6, src7, ref7, out0, out1, out2, out3);
  699. out0 += out1;
  700. out2 += out3;
  701. out0 += out2;
  702. sum = HADD_SW_S32(out0);
  703. return sum;
  704. }
  705. static int SSE8x8_MSA(const uint8_t* a, const uint8_t* b) {
  706. uint32_t sum;
  707. v16u8 src0, src1, src2, src3, src4, src5, src6, src7;
  708. v16u8 ref0, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
  709. v16u8 t0, t1, t2, t3;
  710. v4i32 out0, out1, out2, out3;
  711. LD_UB8(a, BPS, src0, src1, src2, src3, src4, src5, src6, src7);
  712. LD_UB8(b, BPS, ref0, ref1, ref2, ref3, ref4, ref5, ref6, ref7);
  713. ILVR_B4_UB(src0, src1, src2, src3, ref0, ref1, ref2, ref3, t0, t1, t2, t3);
  714. PACK_DOTP_UB4_SW(t0, t2, t1, t3, out0, out1, out2, out3);
  715. ILVR_B4_UB(src4, src5, src6, src7, ref4, ref5, ref6, ref7, t0, t1, t2, t3);
  716. PACK_DPADD_UB4_SW(t0, t2, t1, t3, out0, out1, out2, out3);
  717. out0 += out1;
  718. out2 += out3;
  719. out0 += out2;
  720. sum = HADD_SW_S32(out0);
  721. return sum;
  722. }
  723. static int SSE4x4_MSA(const uint8_t* a, const uint8_t* b) {
  724. uint32_t sum = 0;
  725. uint32_t src0, src1, src2, src3, ref0, ref1, ref2, ref3;
  726. v16u8 src = { 0 }, ref = { 0 }, tmp0, tmp1;
  727. v8i16 diff0, diff1;
  728. v4i32 out0, out1;
  729. LW4(a, BPS, src0, src1, src2, src3);
  730. LW4(b, BPS, ref0, ref1, ref2, ref3);
  731. INSERT_W4_UB(src0, src1, src2, src3, src);
  732. INSERT_W4_UB(ref0, ref1, ref2, ref3, ref);
  733. ILVRL_B2_UB(src, ref, tmp0, tmp1);
  734. HSUB_UB2_SH(tmp0, tmp1, diff0, diff1);
  735. DOTP_SH2_SW(diff0, diff1, diff0, diff1, out0, out1);
  736. out0 += out1;
  737. sum = HADD_SW_S32(out0);
  738. return sum;
  739. }
  740. //------------------------------------------------------------------------------
  741. // Quantization
  742. static int QuantizeBlock_MSA(int16_t in[16], int16_t out[16],
  743. const VP8Matrix* const mtx) {
  744. int sum;
  745. v8i16 in0, in1, sh0, sh1, out0, out1;
  746. v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, sign0, sign1;
  747. v4i32 s0, s1, s2, s3, b0, b1, b2, b3, t0, t1, t2, t3;
  748. const v8i16 zero = { 0 };
  749. const v8i16 zigzag0 = { 0, 1, 4, 8, 5, 2, 3, 6 };
  750. const v8i16 zigzag1 = { 9, 12, 13, 10, 7, 11, 14, 15 };
  751. const v8i16 maxlevel = __msa_fill_h(MAX_LEVEL);
  752. LD_SH2(&in[0], 8, in0, in1);
  753. LD_SH2(&mtx->sharpen_[0], 8, sh0, sh1);
  754. tmp4 = __msa_add_a_h(in0, zero);
  755. tmp5 = __msa_add_a_h(in1, zero);
  756. ILVRL_H2_SH(sh0, tmp4, tmp0, tmp1);
  757. ILVRL_H2_SH(sh1, tmp5, tmp2, tmp3);
  758. HADD_SH4_SW(tmp0, tmp1, tmp2, tmp3, s0, s1, s2, s3);
  759. sign0 = (in0 < zero);
  760. sign1 = (in1 < zero); // sign
  761. LD_SH2(&mtx->iq_[0], 8, tmp0, tmp1); // iq
  762. ILVRL_H2_SW(zero, tmp0, t0, t1);
  763. ILVRL_H2_SW(zero, tmp1, t2, t3);
  764. LD_SW4(&mtx->bias_[0], 4, b0, b1, b2, b3); // bias
  765. MUL4(t0, s0, t1, s1, t2, s2, t3, s3, t0, t1, t2, t3);
  766. ADD4(b0, t0, b1, t1, b2, t2, b3, t3, b0, b1, b2, b3);
  767. SRAI_W4_SW(b0, b1, b2, b3, 17);
  768. PCKEV_H2_SH(b1, b0, b3, b2, tmp2, tmp3);
  769. tmp0 = (tmp2 > maxlevel);
  770. tmp1 = (tmp3 > maxlevel);
  771. tmp2 = (v8i16)__msa_bmnz_v((v16u8)tmp2, (v16u8)maxlevel, (v16u8)tmp0);
  772. tmp3 = (v8i16)__msa_bmnz_v((v16u8)tmp3, (v16u8)maxlevel, (v16u8)tmp1);
  773. SUB2(zero, tmp2, zero, tmp3, tmp0, tmp1);
  774. tmp2 = (v8i16)__msa_bmnz_v((v16u8)tmp2, (v16u8)tmp0, (v16u8)sign0);
  775. tmp3 = (v8i16)__msa_bmnz_v((v16u8)tmp3, (v16u8)tmp1, (v16u8)sign1);
  776. LD_SW4(&mtx->zthresh_[0], 4, t0, t1, t2, t3); // zthresh
  777. t0 = (s0 > t0);
  778. t1 = (s1 > t1);
  779. t2 = (s2 > t2);
  780. t3 = (s3 > t3);
  781. PCKEV_H2_SH(t1, t0, t3, t2, tmp0, tmp1);
  782. tmp4 = (v8i16)__msa_bmnz_v((v16u8)zero, (v16u8)tmp2, (v16u8)tmp0);
  783. tmp5 = (v8i16)__msa_bmnz_v((v16u8)zero, (v16u8)tmp3, (v16u8)tmp1);
  784. LD_SH2(&mtx->q_[0], 8, tmp0, tmp1);
  785. MUL2(tmp4, tmp0, tmp5, tmp1, in0, in1);
  786. VSHF_H2_SH(tmp4, tmp5, tmp4, tmp5, zigzag0, zigzag1, out0, out1);
  787. ST_SH2(in0, in1, &in[0], 8);
  788. ST_SH2(out0, out1, &out[0], 8);
  789. out0 = __msa_add_a_h(out0, out1);
  790. sum = HADD_SH_S32(out0);
  791. return (sum > 0);
  792. }
  793. static int Quantize2Blocks_MSA(int16_t in[32], int16_t out[32],
  794. const VP8Matrix* const mtx) {
  795. int nz;
  796. nz = VP8EncQuantizeBlock(in + 0 * 16, out + 0 * 16, mtx) << 0;
  797. nz |= VP8EncQuantizeBlock(in + 1 * 16, out + 1 * 16, mtx) << 1;
  798. return nz;
  799. }
  800. //------------------------------------------------------------------------------
  801. // Entry point
  802. extern void VP8EncDspInitMSA(void);
  803. WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInitMSA(void) {
  804. VP8ITransform = ITransform_MSA;
  805. VP8FTransform = FTransform_MSA;
  806. VP8FTransformWHT = FTransformWHT_MSA;
  807. VP8TDisto4x4 = Disto4x4_MSA;
  808. VP8TDisto16x16 = Disto16x16_MSA;
  809. VP8CollectHistogram = CollectHistogram_MSA;
  810. VP8EncPredLuma4 = Intra4Preds_MSA;
  811. VP8EncPredLuma16 = Intra16Preds_MSA;
  812. VP8EncPredChroma8 = IntraChromaPreds_MSA;
  813. VP8SSE16x16 = SSE16x16_MSA;
  814. VP8SSE16x8 = SSE16x8_MSA;
  815. VP8SSE8x8 = SSE8x8_MSA;
  816. VP8SSE4x4 = SSE4x4_MSA;
  817. VP8EncQuantizeBlock = QuantizeBlock_MSA;
  818. VP8EncQuantize2Blocks = Quantize2Blocks_MSA;
  819. VP8EncQuantizeBlockWHT = QuantizeBlock_MSA;
  820. }
  821. #else // !WEBP_USE_MSA
  822. WEBP_DSP_INIT_STUB(VP8EncDspInitMSA)
  823. #endif // WEBP_USE_MSA