dec_msa.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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 dsp functions
  11. //
  12. // Author(s): Prashant Patil (prashant.patil@imgtec.com)
  13. #include "./dsp.h"
  14. #if defined(WEBP_USE_MSA)
  15. #include "./msa_macro.h"
  16. //------------------------------------------------------------------------------
  17. // Transforms
  18. #define IDCT_1D_W(in0, in1, in2, in3, out0, out1, out2, out3) { \
  19. v4i32 a1_m, b1_m, c1_m, d1_m; \
  20. v4i32 c_tmp1_m, c_tmp2_m, d_tmp1_m, d_tmp2_m; \
  21. const v4i32 cospi8sqrt2minus1 = __msa_fill_w(20091); \
  22. const v4i32 sinpi8sqrt2 = __msa_fill_w(35468); \
  23. \
  24. a1_m = in0 + in2; \
  25. b1_m = in0 - in2; \
  26. c_tmp1_m = (in1 * sinpi8sqrt2) >> 16; \
  27. c_tmp2_m = in3 + ((in3 * cospi8sqrt2minus1) >> 16); \
  28. c1_m = c_tmp1_m - c_tmp2_m; \
  29. d_tmp1_m = in1 + ((in1 * cospi8sqrt2minus1) >> 16); \
  30. d_tmp2_m = (in3 * sinpi8sqrt2) >> 16; \
  31. d1_m = d_tmp1_m + d_tmp2_m; \
  32. BUTTERFLY_4(a1_m, b1_m, c1_m, d1_m, out0, out1, out2, out3); \
  33. }
  34. #define MULT1(a) ((((a) * 20091) >> 16) + (a))
  35. #define MULT2(a) (((a) * 35468) >> 16)
  36. static void TransformOne(const int16_t* in, uint8_t* dst) {
  37. v8i16 input0, input1;
  38. v4i32 in0, in1, in2, in3, hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3;
  39. v4i32 res0, res1, res2, res3;
  40. const v16i8 zero = { 0 };
  41. v16i8 dest0, dest1, dest2, dest3;
  42. LD_SH2(in, 8, input0, input1);
  43. UNPCK_SH_SW(input0, in0, in1);
  44. UNPCK_SH_SW(input1, in2, in3);
  45. IDCT_1D_W(in0, in1, in2, in3, hz0, hz1, hz2, hz3);
  46. TRANSPOSE4x4_SW_SW(hz0, hz1, hz2, hz3, hz0, hz1, hz2, hz3);
  47. IDCT_1D_W(hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3);
  48. SRARI_W4_SW(vt0, vt1, vt2, vt3, 3);
  49. TRANSPOSE4x4_SW_SW(vt0, vt1, vt2, vt3, vt0, vt1, vt2, vt3);
  50. LD_SB4(dst, BPS, dest0, dest1, dest2, dest3);
  51. ILVR_B4_SW(zero, dest0, zero, dest1, zero, dest2, zero, dest3,
  52. res0, res1, res2, res3);
  53. ILVR_H4_SW(zero, res0, zero, res1, zero, res2, zero, res3,
  54. res0, res1, res2, res3);
  55. ADD4(res0, vt0, res1, vt1, res2, vt2, res3, vt3, res0, res1, res2, res3);
  56. CLIP_SW4_0_255(res0, res1, res2, res3);
  57. PCKEV_B2_SW(res0, res1, res2, res3, vt0, vt1);
  58. res0 = (v4i32)__msa_pckev_b((v16i8)vt0, (v16i8)vt1);
  59. ST4x4_UB(res0, res0, 3, 2, 1, 0, dst, BPS);
  60. }
  61. static void TransformTwo(const int16_t* in, uint8_t* dst, int do_two) {
  62. TransformOne(in, dst);
  63. if (do_two) {
  64. TransformOne(in + 16, dst + 4);
  65. }
  66. }
  67. static void TransformWHT(const int16_t* in, int16_t* out) {
  68. v8i16 input0, input1;
  69. const v8i16 mask0 = { 0, 1, 2, 3, 8, 9, 10, 11 };
  70. const v8i16 mask1 = { 4, 5, 6, 7, 12, 13, 14, 15 };
  71. const v8i16 mask2 = { 0, 4, 8, 12, 1, 5, 9, 13 };
  72. const v8i16 mask3 = { 3, 7, 11, 15, 2, 6, 10, 14 };
  73. v8i16 tmp0, tmp1, tmp2, tmp3;
  74. v8i16 out0, out1;
  75. LD_SH2(in, 8, input0, input1);
  76. input1 = SLDI_SH(input1, input1, 8);
  77. tmp0 = input0 + input1;
  78. tmp1 = input0 - input1;
  79. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask0, mask1, tmp2, tmp3);
  80. out0 = tmp2 + tmp3;
  81. out1 = tmp2 - tmp3;
  82. VSHF_H2_SH(out0, out1, out0, out1, mask2, mask3, input0, input1);
  83. tmp0 = input0 + input1;
  84. tmp1 = input0 - input1;
  85. VSHF_H2_SH(tmp0, tmp1, tmp0, tmp1, mask0, mask1, tmp2, tmp3);
  86. tmp0 = tmp2 + tmp3;
  87. tmp1 = tmp2 - tmp3;
  88. ADDVI_H2_SH(tmp0, 3, tmp1, 3, out0, out1);
  89. SRAI_H2_SH(out0, out1, 3);
  90. out[0] = __msa_copy_s_h(out0, 0);
  91. out[16] = __msa_copy_s_h(out0, 4);
  92. out[32] = __msa_copy_s_h(out1, 0);
  93. out[48] = __msa_copy_s_h(out1, 4);
  94. out[64] = __msa_copy_s_h(out0, 1);
  95. out[80] = __msa_copy_s_h(out0, 5);
  96. out[96] = __msa_copy_s_h(out1, 1);
  97. out[112] = __msa_copy_s_h(out1, 5);
  98. out[128] = __msa_copy_s_h(out0, 2);
  99. out[144] = __msa_copy_s_h(out0, 6);
  100. out[160] = __msa_copy_s_h(out1, 2);
  101. out[176] = __msa_copy_s_h(out1, 6);
  102. out[192] = __msa_copy_s_h(out0, 3);
  103. out[208] = __msa_copy_s_h(out0, 7);
  104. out[224] = __msa_copy_s_h(out1, 3);
  105. out[240] = __msa_copy_s_h(out1, 7);
  106. }
  107. static void TransformDC(const int16_t* in, uint8_t* dst) {
  108. const int DC = (in[0] + 4) >> 3;
  109. const v8i16 tmp0 = __msa_fill_h(DC);
  110. ADDBLK_ST4x4_UB(tmp0, tmp0, tmp0, tmp0, dst, BPS);
  111. }
  112. static void TransformAC3(const int16_t* in, uint8_t* dst) {
  113. const int a = in[0] + 4;
  114. const int c4 = MULT2(in[4]);
  115. const int d4 = MULT1(in[4]);
  116. const int in2 = MULT2(in[1]);
  117. const int in3 = MULT1(in[1]);
  118. v4i32 tmp0 = { 0 };
  119. v4i32 out0 = __msa_fill_w(a + d4);
  120. v4i32 out1 = __msa_fill_w(a + c4);
  121. v4i32 out2 = __msa_fill_w(a - c4);
  122. v4i32 out3 = __msa_fill_w(a - d4);
  123. v4i32 res0, res1, res2, res3;
  124. const v4i32 zero = { 0 };
  125. v16u8 dest0, dest1, dest2, dest3;
  126. INSERT_W4_SW(in3, in2, -in2, -in3, tmp0);
  127. ADD4(out0, tmp0, out1, tmp0, out2, tmp0, out3, tmp0,
  128. out0, out1, out2, out3);
  129. SRAI_W4_SW(out0, out1, out2, out3, 3);
  130. LD_UB4(dst, BPS, dest0, dest1, dest2, dest3);
  131. ILVR_B4_SW(zero, dest0, zero, dest1, zero, dest2, zero, dest3,
  132. res0, res1, res2, res3);
  133. ILVR_H4_SW(zero, res0, zero, res1, zero, res2, zero, res3,
  134. res0, res1, res2, res3);
  135. ADD4(res0, out0, res1, out1, res2, out2, res3, out3, res0, res1, res2, res3);
  136. CLIP_SW4_0_255(res0, res1, res2, res3);
  137. PCKEV_B2_SW(res0, res1, res2, res3, out0, out1);
  138. res0 = (v4i32)__msa_pckev_b((v16i8)out0, (v16i8)out1);
  139. ST4x4_UB(res0, res0, 3, 2, 1, 0, dst, BPS);
  140. }
  141. //------------------------------------------------------------------------------
  142. // Edge filtering functions
  143. #define FLIP_SIGN2(in0, in1, out0, out1) { \
  144. out0 = (v16i8)__msa_xori_b(in0, 0x80); \
  145. out1 = (v16i8)__msa_xori_b(in1, 0x80); \
  146. }
  147. #define FLIP_SIGN4(in0, in1, in2, in3, out0, out1, out2, out3) { \
  148. FLIP_SIGN2(in0, in1, out0, out1); \
  149. FLIP_SIGN2(in2, in3, out2, out3); \
  150. }
  151. #define FILT_VAL(q0_m, p0_m, mask, filt) do { \
  152. v16i8 q0_sub_p0; \
  153. q0_sub_p0 = __msa_subs_s_b(q0_m, p0_m); \
  154. filt = __msa_adds_s_b(filt, q0_sub_p0); \
  155. filt = __msa_adds_s_b(filt, q0_sub_p0); \
  156. filt = __msa_adds_s_b(filt, q0_sub_p0); \
  157. filt = filt & mask; \
  158. } while (0)
  159. #define FILT2(q_m, p_m, q, p) do { \
  160. u_r = SRAI_H(temp1, 7); \
  161. u_r = __msa_sat_s_h(u_r, 7); \
  162. u_l = SRAI_H(temp3, 7); \
  163. u_l = __msa_sat_s_h(u_l, 7); \
  164. u = __msa_pckev_b((v16i8)u_l, (v16i8)u_r); \
  165. q_m = __msa_subs_s_b(q_m, u); \
  166. p_m = __msa_adds_s_b(p_m, u); \
  167. q = __msa_xori_b((v16u8)q_m, 0x80); \
  168. p = __msa_xori_b((v16u8)p_m, 0x80); \
  169. } while (0)
  170. #define LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev) do { \
  171. v16i8 p1_m, p0_m, q0_m, q1_m; \
  172. v16i8 filt, t1, t2; \
  173. const v16i8 cnst4b = __msa_ldi_b(4); \
  174. const v16i8 cnst3b = __msa_ldi_b(3); \
  175. \
  176. FLIP_SIGN4(p1, p0, q0, q1, p1_m, p0_m, q0_m, q1_m); \
  177. filt = __msa_subs_s_b(p1_m, q1_m); \
  178. filt = filt & hev; \
  179. FILT_VAL(q0_m, p0_m, mask, filt); \
  180. t1 = __msa_adds_s_b(filt, cnst4b); \
  181. t1 = SRAI_B(t1, 3); \
  182. t2 = __msa_adds_s_b(filt, cnst3b); \
  183. t2 = SRAI_B(t2, 3); \
  184. q0_m = __msa_subs_s_b(q0_m, t1); \
  185. q0 = __msa_xori_b((v16u8)q0_m, 0x80); \
  186. p0_m = __msa_adds_s_b(p0_m, t2); \
  187. p0 = __msa_xori_b((v16u8)p0_m, 0x80); \
  188. filt = __msa_srari_b(t1, 1); \
  189. hev = __msa_xori_b(hev, 0xff); \
  190. filt = filt & hev; \
  191. q1_m = __msa_subs_s_b(q1_m, filt); \
  192. q1 = __msa_xori_b((v16u8)q1_m, 0x80); \
  193. p1_m = __msa_adds_s_b(p1_m, filt); \
  194. p1 = __msa_xori_b((v16u8)p1_m, 0x80); \
  195. } while (0)
  196. #define LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev) do { \
  197. v16i8 p2_m, p1_m, p0_m, q2_m, q1_m, q0_m; \
  198. v16i8 u, filt, t1, t2, filt_sign; \
  199. v8i16 filt_r, filt_l, u_r, u_l; \
  200. v8i16 temp0, temp1, temp2, temp3; \
  201. const v16i8 cnst4b = __msa_ldi_b(4); \
  202. const v16i8 cnst3b = __msa_ldi_b(3); \
  203. const v8i16 cnst9h = __msa_ldi_h(9); \
  204. const v8i16 cnst63h = __msa_ldi_h(63); \
  205. \
  206. FLIP_SIGN4(p1, p0, q0, q1, p1_m, p0_m, q0_m, q1_m); \
  207. filt = __msa_subs_s_b(p1_m, q1_m); \
  208. FILT_VAL(q0_m, p0_m, mask, filt); \
  209. FLIP_SIGN2(p2, q2, p2_m, q2_m); \
  210. t2 = filt & hev; \
  211. /* filt_val &= ~hev */ \
  212. hev = __msa_xori_b(hev, 0xff); \
  213. filt = filt & hev; \
  214. t1 = __msa_adds_s_b(t2, cnst4b); \
  215. t1 = SRAI_B(t1, 3); \
  216. t2 = __msa_adds_s_b(t2, cnst3b); \
  217. t2 = SRAI_B(t2, 3); \
  218. q0_m = __msa_subs_s_b(q0_m, t1); \
  219. p0_m = __msa_adds_s_b(p0_m, t2); \
  220. filt_sign = __msa_clti_s_b(filt, 0); \
  221. ILVRL_B2_SH(filt_sign, filt, filt_r, filt_l); \
  222. /* update q2/p2 */ \
  223. temp0 = filt_r * cnst9h; \
  224. temp1 = temp0 + cnst63h; \
  225. temp2 = filt_l * cnst9h; \
  226. temp3 = temp2 + cnst63h; \
  227. FILT2(q2_m, p2_m, q2, p2); \
  228. /* update q1/p1 */ \
  229. temp1 = temp1 + temp0; \
  230. temp3 = temp3 + temp2; \
  231. FILT2(q1_m, p1_m, q1, p1); \
  232. /* update q0/p0 */ \
  233. temp1 = temp1 + temp0; \
  234. temp3 = temp3 + temp2; \
  235. FILT2(q0_m, p0_m, q0, p0); \
  236. } while (0)
  237. #define LPF_MASK_HEV(p3_in, p2_in, p1_in, p0_in, \
  238. q0_in, q1_in, q2_in, q3_in, \
  239. limit_in, b_limit_in, thresh_in, \
  240. hev_out, mask_out) do { \
  241. v16u8 p3_asub_p2_m, p2_asub_p1_m, p1_asub_p0_m, q1_asub_q0_m; \
  242. v16u8 p1_asub_q1_m, p0_asub_q0_m, q3_asub_q2_m, q2_asub_q1_m; \
  243. v16u8 flat_out; \
  244. \
  245. /* absolute subtraction of pixel values */ \
  246. p3_asub_p2_m = __msa_asub_u_b(p3_in, p2_in); \
  247. p2_asub_p1_m = __msa_asub_u_b(p2_in, p1_in); \
  248. p1_asub_p0_m = __msa_asub_u_b(p1_in, p0_in); \
  249. q1_asub_q0_m = __msa_asub_u_b(q1_in, q0_in); \
  250. q2_asub_q1_m = __msa_asub_u_b(q2_in, q1_in); \
  251. q3_asub_q2_m = __msa_asub_u_b(q3_in, q2_in); \
  252. p0_asub_q0_m = __msa_asub_u_b(p0_in, q0_in); \
  253. p1_asub_q1_m = __msa_asub_u_b(p1_in, q1_in); \
  254. /* calculation of hev */ \
  255. flat_out = __msa_max_u_b(p1_asub_p0_m, q1_asub_q0_m); \
  256. hev_out = (thresh_in < flat_out); \
  257. /* calculation of mask */ \
  258. p0_asub_q0_m = __msa_adds_u_b(p0_asub_q0_m, p0_asub_q0_m); \
  259. p1_asub_q1_m = SRAI_B(p1_asub_q1_m, 1); \
  260. p0_asub_q0_m = __msa_adds_u_b(p0_asub_q0_m, p1_asub_q1_m); \
  261. mask_out = (b_limit_in < p0_asub_q0_m); \
  262. mask_out = __msa_max_u_b(flat_out, mask_out); \
  263. p3_asub_p2_m = __msa_max_u_b(p3_asub_p2_m, p2_asub_p1_m); \
  264. mask_out = __msa_max_u_b(p3_asub_p2_m, mask_out); \
  265. q2_asub_q1_m = __msa_max_u_b(q2_asub_q1_m, q3_asub_q2_m); \
  266. mask_out = __msa_max_u_b(q2_asub_q1_m, mask_out); \
  267. mask_out = (limit_in < mask_out); \
  268. mask_out = __msa_xori_b(mask_out, 0xff); \
  269. } while (0)
  270. #define ST6x1_UB(in0, in0_idx, in1, in1_idx, pdst, stride) do { \
  271. const uint16_t tmp0_h = __msa_copy_s_h((v8i16)in1, in1_idx); \
  272. const uint32_t tmp0_w = __msa_copy_s_w((v4i32)in0, in0_idx); \
  273. SW(tmp0_w, pdst); \
  274. SH(tmp0_h, pdst + stride); \
  275. } while (0)
  276. #define ST6x4_UB(in0, start_in0_idx, in1, start_in1_idx, pdst, stride) do { \
  277. uint8_t* ptmp1 = (uint8_t*)pdst; \
  278. ST6x1_UB(in0, start_in0_idx, in1, start_in1_idx, ptmp1, 4); \
  279. ptmp1 += stride; \
  280. ST6x1_UB(in0, start_in0_idx + 1, in1, start_in1_idx + 1, ptmp1, 4); \
  281. ptmp1 += stride; \
  282. ST6x1_UB(in0, start_in0_idx + 2, in1, start_in1_idx + 2, ptmp1, 4); \
  283. ptmp1 += stride; \
  284. ST6x1_UB(in0, start_in0_idx + 3, in1, start_in1_idx + 3, ptmp1, 4); \
  285. } while (0)
  286. #define LPF_SIMPLE_FILT(p1_in, p0_in, q0_in, q1_in, mask) do { \
  287. v16i8 p1_m, p0_m, q0_m, q1_m, filt, filt1, filt2; \
  288. const v16i8 cnst4b = __msa_ldi_b(4); \
  289. const v16i8 cnst3b = __msa_ldi_b(3); \
  290. \
  291. FLIP_SIGN4(p1_in, p0_in, q0_in, q1_in, p1_m, p0_m, q0_m, q1_m); \
  292. filt = __msa_subs_s_b(p1_m, q1_m); \
  293. FILT_VAL(q0_m, p0_m, mask, filt); \
  294. filt1 = __msa_adds_s_b(filt, cnst4b); \
  295. filt1 = SRAI_B(filt1, 3); \
  296. filt2 = __msa_adds_s_b(filt, cnst3b); \
  297. filt2 = SRAI_B(filt2, 3); \
  298. q0_m = __msa_subs_s_b(q0_m, filt1); \
  299. p0_m = __msa_adds_s_b(p0_m, filt2); \
  300. q0_in = __msa_xori_b((v16u8)q0_m, 0x80); \
  301. p0_in = __msa_xori_b((v16u8)p0_m, 0x80); \
  302. } while (0)
  303. #define LPF_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask) do { \
  304. v16u8 p1_a_sub_q1, p0_a_sub_q0; \
  305. \
  306. p0_a_sub_q0 = __msa_asub_u_b(p0, q0); \
  307. p1_a_sub_q1 = __msa_asub_u_b(p1, q1); \
  308. p1_a_sub_q1 = (v16u8)__msa_srli_b((v16i8)p1_a_sub_q1, 1); \
  309. p0_a_sub_q0 = __msa_adds_u_b(p0_a_sub_q0, p0_a_sub_q0); \
  310. mask = __msa_adds_u_b(p0_a_sub_q0, p1_a_sub_q1); \
  311. mask = (mask <= b_limit); \
  312. } while (0)
  313. static void VFilter16(uint8_t* src, int stride,
  314. int b_limit_in, int limit_in, int thresh_in) {
  315. uint8_t* ptemp = src - 4 * stride;
  316. v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
  317. v16u8 mask, hev;
  318. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  319. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  320. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  321. LD_UB8(ptemp, stride, p3, p2, p1, p0, q0, q1, q2, q3);
  322. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  323. hev, mask);
  324. LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
  325. ptemp = src - 3 * stride;
  326. ST_UB4(p2, p1, p0, q0, ptemp, stride);
  327. ptemp += (4 * stride);
  328. ST_UB2(q1, q2, ptemp, stride);
  329. }
  330. static void HFilter16(uint8_t* src, int stride,
  331. int b_limit_in, int limit_in, int thresh_in) {
  332. uint8_t* ptmp = src - 4;
  333. v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
  334. v16u8 mask, hev;
  335. v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
  336. v16u8 row9, row10, row11, row12, row13, row14, row15;
  337. v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  338. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  339. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  340. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  341. LD_UB8(ptmp, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  342. ptmp += (8 * stride);
  343. LD_UB8(ptmp, stride, row8, row9, row10, row11, row12, row13, row14, row15);
  344. TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  345. row8, row9, row10, row11, row12, row13, row14, row15,
  346. p3, p2, p1, p0, q0, q1, q2, q3);
  347. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  348. hev, mask);
  349. LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
  350. ILVR_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
  351. ILVRL_H2_SH(tmp1, tmp0, tmp3, tmp4);
  352. ILVL_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
  353. ILVRL_H2_SH(tmp1, tmp0, tmp6, tmp7);
  354. ILVRL_B2_SH(q2, q1, tmp2, tmp5);
  355. ptmp = src - 3;
  356. ST6x1_UB(tmp3, 0, tmp2, 0, ptmp, 4);
  357. ptmp += stride;
  358. ST6x1_UB(tmp3, 1, tmp2, 1, ptmp, 4);
  359. ptmp += stride;
  360. ST6x1_UB(tmp3, 2, tmp2, 2, ptmp, 4);
  361. ptmp += stride;
  362. ST6x1_UB(tmp3, 3, tmp2, 3, ptmp, 4);
  363. ptmp += stride;
  364. ST6x1_UB(tmp4, 0, tmp2, 4, ptmp, 4);
  365. ptmp += stride;
  366. ST6x1_UB(tmp4, 1, tmp2, 5, ptmp, 4);
  367. ptmp += stride;
  368. ST6x1_UB(tmp4, 2, tmp2, 6, ptmp, 4);
  369. ptmp += stride;
  370. ST6x1_UB(tmp4, 3, tmp2, 7, ptmp, 4);
  371. ptmp += stride;
  372. ST6x1_UB(tmp6, 0, tmp5, 0, ptmp, 4);
  373. ptmp += stride;
  374. ST6x1_UB(tmp6, 1, tmp5, 1, ptmp, 4);
  375. ptmp += stride;
  376. ST6x1_UB(tmp6, 2, tmp5, 2, ptmp, 4);
  377. ptmp += stride;
  378. ST6x1_UB(tmp6, 3, tmp5, 3, ptmp, 4);
  379. ptmp += stride;
  380. ST6x1_UB(tmp7, 0, tmp5, 4, ptmp, 4);
  381. ptmp += stride;
  382. ST6x1_UB(tmp7, 1, tmp5, 5, ptmp, 4);
  383. ptmp += stride;
  384. ST6x1_UB(tmp7, 2, tmp5, 6, ptmp, 4);
  385. ptmp += stride;
  386. ST6x1_UB(tmp7, 3, tmp5, 7, ptmp, 4);
  387. }
  388. // on three inner edges
  389. static void VFilterHorEdge16i(uint8_t* src, int stride,
  390. int b_limit, int limit, int thresh) {
  391. v16u8 mask, hev;
  392. v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
  393. const v16u8 thresh0 = (v16u8)__msa_fill_b(thresh);
  394. const v16u8 b_limit0 = (v16u8)__msa_fill_b(b_limit);
  395. const v16u8 limit0 = (v16u8)__msa_fill_b(limit);
  396. LD_UB8((src - 4 * stride), stride, p3, p2, p1, p0, q0, q1, q2, q3);
  397. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit0, b_limit0, thresh0,
  398. hev, mask);
  399. LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
  400. ST_UB4(p1, p0, q0, q1, (src - 2 * stride), stride);
  401. }
  402. static void VFilter16i(uint8_t* src_y, int stride,
  403. int b_limit, int limit, int thresh) {
  404. VFilterHorEdge16i(src_y + 4 * stride, stride, b_limit, limit, thresh);
  405. VFilterHorEdge16i(src_y + 8 * stride, stride, b_limit, limit, thresh);
  406. VFilterHorEdge16i(src_y + 12 * stride, stride, b_limit, limit, thresh);
  407. }
  408. static void HFilterVertEdge16i(uint8_t* src, int stride,
  409. int b_limit, int limit, int thresh) {
  410. v16u8 mask, hev;
  411. v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
  412. v16u8 row0, row1, row2, row3, row4, row5, row6, row7;
  413. v16u8 row8, row9, row10, row11, row12, row13, row14, row15;
  414. v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  415. const v16u8 thresh0 = (v16u8)__msa_fill_b(thresh);
  416. const v16u8 b_limit0 = (v16u8)__msa_fill_b(b_limit);
  417. const v16u8 limit0 = (v16u8)__msa_fill_b(limit);
  418. LD_UB8(src - 4, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  419. LD_UB8(src - 4 + (8 * stride), stride,
  420. row8, row9, row10, row11, row12, row13, row14, row15);
  421. TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  422. row8, row9, row10, row11, row12, row13, row14, row15,
  423. p3, p2, p1, p0, q0, q1, q2, q3);
  424. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit0, b_limit0, thresh0,
  425. hev, mask);
  426. LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
  427. ILVR_B2_SH(p0, p1, q1, q0, tmp0, tmp1);
  428. ILVRL_H2_SH(tmp1, tmp0, tmp2, tmp3);
  429. ILVL_B2_SH(p0, p1, q1, q0, tmp0, tmp1);
  430. ILVRL_H2_SH(tmp1, tmp0, tmp4, tmp5);
  431. src -= 2;
  432. ST4x8_UB(tmp2, tmp3, src, stride);
  433. src += (8 * stride);
  434. ST4x8_UB(tmp4, tmp5, src, stride);
  435. }
  436. static void HFilter16i(uint8_t* src_y, int stride,
  437. int b_limit, int limit, int thresh) {
  438. HFilterVertEdge16i(src_y + 4, stride, b_limit, limit, thresh);
  439. HFilterVertEdge16i(src_y + 8, stride, b_limit, limit, thresh);
  440. HFilterVertEdge16i(src_y + 12, stride, b_limit, limit, thresh);
  441. }
  442. // 8-pixels wide variants, for chroma filtering
  443. static void VFilter8(uint8_t* src_u, uint8_t* src_v, int stride,
  444. int b_limit_in, int limit_in, int thresh_in) {
  445. uint8_t* ptmp_src_u = src_u - 4 * stride;
  446. uint8_t* ptmp_src_v = src_v - 4 * stride;
  447. uint64_t p2_d, p1_d, p0_d, q0_d, q1_d, q2_d;
  448. v16u8 p3, p2, p1, p0, q3, q2, q1, q0, mask, hev;
  449. v16u8 p3_u, p2_u, p1_u, p0_u, q3_u, q2_u, q1_u, q0_u;
  450. v16u8 p3_v, p2_v, p1_v, p0_v, q3_v, q2_v, q1_v, q0_v;
  451. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  452. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  453. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  454. LD_UB8(ptmp_src_u, stride, p3_u, p2_u, p1_u, p0_u, q0_u, q1_u, q2_u, q3_u);
  455. LD_UB8(ptmp_src_v, stride, p3_v, p2_v, p1_v, p0_v, q0_v, q1_v, q2_v, q3_v);
  456. ILVR_D4_UB(p3_v, p3_u, p2_v, p2_u, p1_v, p1_u, p0_v, p0_u, p3, p2, p1, p0);
  457. ILVR_D4_UB(q0_v, q0_u, q1_v, q1_u, q2_v, q2_u, q3_v, q3_u, q0, q1, q2, q3);
  458. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  459. hev, mask);
  460. LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
  461. p2_d = __msa_copy_s_d((v2i64)p2, 0);
  462. p1_d = __msa_copy_s_d((v2i64)p1, 0);
  463. p0_d = __msa_copy_s_d((v2i64)p0, 0);
  464. q0_d = __msa_copy_s_d((v2i64)q0, 0);
  465. q1_d = __msa_copy_s_d((v2i64)q1, 0);
  466. q2_d = __msa_copy_s_d((v2i64)q2, 0);
  467. ptmp_src_u += stride;
  468. SD4(p2_d, p1_d, p0_d, q0_d, ptmp_src_u, stride);
  469. ptmp_src_u += (4 * stride);
  470. SD(q1_d, ptmp_src_u);
  471. ptmp_src_u += stride;
  472. SD(q2_d, ptmp_src_u);
  473. p2_d = __msa_copy_s_d((v2i64)p2, 1);
  474. p1_d = __msa_copy_s_d((v2i64)p1, 1);
  475. p0_d = __msa_copy_s_d((v2i64)p0, 1);
  476. q0_d = __msa_copy_s_d((v2i64)q0, 1);
  477. q1_d = __msa_copy_s_d((v2i64)q1, 1);
  478. q2_d = __msa_copy_s_d((v2i64)q2, 1);
  479. ptmp_src_v += stride;
  480. SD4(p2_d, p1_d, p0_d, q0_d, ptmp_src_v, stride);
  481. ptmp_src_v += (4 * stride);
  482. SD(q1_d, ptmp_src_v);
  483. ptmp_src_v += stride;
  484. SD(q2_d, ptmp_src_v);
  485. }
  486. static void HFilter8(uint8_t* src_u, uint8_t* src_v, int stride,
  487. int b_limit_in, int limit_in, int thresh_in) {
  488. uint8_t* ptmp_src_u = src_u - 4;
  489. uint8_t* ptmp_src_v = src_v - 4;
  490. v16u8 p3, p2, p1, p0, q3, q2, q1, q0, mask, hev;
  491. v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
  492. v16u8 row9, row10, row11, row12, row13, row14, row15;
  493. v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  494. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  495. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  496. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  497. LD_UB8(ptmp_src_u, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  498. LD_UB8(ptmp_src_v, stride,
  499. row8, row9, row10, row11, row12, row13, row14, row15);
  500. TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  501. row8, row9, row10, row11, row12, row13, row14, row15,
  502. p3, p2, p1, p0, q0, q1, q2, q3);
  503. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  504. hev, mask);
  505. LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
  506. ILVR_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
  507. ILVRL_H2_SH(tmp1, tmp0, tmp3, tmp4);
  508. ILVL_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
  509. ILVRL_H2_SH(tmp1, tmp0, tmp6, tmp7);
  510. ILVRL_B2_SH(q2, q1, tmp2, tmp5);
  511. ptmp_src_u += 1;
  512. ST6x4_UB(tmp3, 0, tmp2, 0, ptmp_src_u, stride);
  513. ptmp_src_u += 4 * stride;
  514. ST6x4_UB(tmp4, 0, tmp2, 4, ptmp_src_u, stride);
  515. ptmp_src_v += 1;
  516. ST6x4_UB(tmp6, 0, tmp5, 0, ptmp_src_v, stride);
  517. ptmp_src_v += 4 * stride;
  518. ST6x4_UB(tmp7, 0, tmp5, 4, ptmp_src_v, stride);
  519. }
  520. static void VFilter8i(uint8_t* src_u, uint8_t* src_v, int stride,
  521. int b_limit_in, int limit_in, int thresh_in) {
  522. uint64_t p1_d, p0_d, q0_d, q1_d;
  523. v16u8 p3, p2, p1, p0, q3, q2, q1, q0, mask, hev;
  524. v16u8 p3_u, p2_u, p1_u, p0_u, q3_u, q2_u, q1_u, q0_u;
  525. v16u8 p3_v, p2_v, p1_v, p0_v, q3_v, q2_v, q1_v, q0_v;
  526. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  527. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  528. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  529. LD_UB8(src_u, stride, p3_u, p2_u, p1_u, p0_u, q0_u, q1_u, q2_u, q3_u);
  530. src_u += (5 * stride);
  531. LD_UB8(src_v, stride, p3_v, p2_v, p1_v, p0_v, q0_v, q1_v, q2_v, q3_v);
  532. src_v += (5 * stride);
  533. ILVR_D4_UB(p3_v, p3_u, p2_v, p2_u, p1_v, p1_u, p0_v, p0_u, p3, p2, p1, p0);
  534. ILVR_D4_UB(q0_v, q0_u, q1_v, q1_u, q2_v, q2_u, q3_v, q3_u, q0, q1, q2, q3);
  535. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  536. hev, mask);
  537. LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
  538. p1_d = __msa_copy_s_d((v2i64)p1, 0);
  539. p0_d = __msa_copy_s_d((v2i64)p0, 0);
  540. q0_d = __msa_copy_s_d((v2i64)q0, 0);
  541. q1_d = __msa_copy_s_d((v2i64)q1, 0);
  542. SD4(q1_d, q0_d, p0_d, p1_d, src_u, -stride);
  543. p1_d = __msa_copy_s_d((v2i64)p1, 1);
  544. p0_d = __msa_copy_s_d((v2i64)p0, 1);
  545. q0_d = __msa_copy_s_d((v2i64)q0, 1);
  546. q1_d = __msa_copy_s_d((v2i64)q1, 1);
  547. SD4(q1_d, q0_d, p0_d, p1_d, src_v, -stride);
  548. }
  549. static void HFilter8i(uint8_t* src_u, uint8_t* src_v, int stride,
  550. int b_limit_in, int limit_in, int thresh_in) {
  551. v16u8 p3, p2, p1, p0, q3, q2, q1, q0, mask, hev;
  552. v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
  553. v16u8 row9, row10, row11, row12, row13, row14, row15;
  554. v4i32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  555. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  556. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  557. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  558. LD_UB8(src_u, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  559. LD_UB8(src_v, stride,
  560. row8, row9, row10, row11, row12, row13, row14, row15);
  561. TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  562. row8, row9, row10, row11, row12, row13, row14, row15,
  563. p3, p2, p1, p0, q0, q1, q2, q3);
  564. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  565. hev, mask);
  566. LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
  567. ILVR_B2_SW(p0, p1, q1, q0, tmp0, tmp1);
  568. ILVRL_H2_SW(tmp1, tmp0, tmp2, tmp3);
  569. ILVL_B2_SW(p0, p1, q1, q0, tmp0, tmp1);
  570. ILVRL_H2_SW(tmp1, tmp0, tmp4, tmp5);
  571. src_u += 2;
  572. ST4x4_UB(tmp2, tmp2, 0, 1, 2, 3, src_u, stride);
  573. src_u += 4 * stride;
  574. ST4x4_UB(tmp3, tmp3, 0, 1, 2, 3, src_u, stride);
  575. src_v += 2;
  576. ST4x4_UB(tmp4, tmp4, 0, 1, 2, 3, src_v, stride);
  577. src_v += 4 * stride;
  578. ST4x4_UB(tmp5, tmp5, 0, 1, 2, 3, src_v, stride);
  579. }
  580. static void SimpleVFilter16(uint8_t* src, int stride, int b_limit_in) {
  581. v16u8 p1, p0, q1, q0, mask;
  582. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  583. LD_UB4(src - 2 * stride, stride, p1, p0, q0, q1);
  584. LPF_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask);
  585. LPF_SIMPLE_FILT(p1, p0, q0, q1, mask);
  586. ST_UB2(p0, q0, src - stride, stride);
  587. }
  588. static void SimpleHFilter16(uint8_t* src, int stride, int b_limit_in) {
  589. v16u8 p1, p0, q1, q0, mask, row0, row1, row2, row3, row4, row5, row6, row7;
  590. v16u8 row8, row9, row10, row11, row12, row13, row14, row15;
  591. v8i16 tmp0, tmp1;
  592. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  593. uint8_t* ptemp_src = src - 2;
  594. LD_UB8(ptemp_src, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  595. LD_UB8(ptemp_src + 8 * stride, stride,
  596. row8, row9, row10, row11, row12, row13, row14, row15);
  597. TRANSPOSE16x4_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  598. row8, row9, row10, row11, row12, row13, row14, row15,
  599. p1, p0, q0, q1);
  600. LPF_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask);
  601. LPF_SIMPLE_FILT(p1, p0, q0, q1, mask);
  602. ILVRL_B2_SH(q0, p0, tmp1, tmp0);
  603. ptemp_src += 1;
  604. ST2x4_UB(tmp1, 0, ptemp_src, stride);
  605. ptemp_src += 4 * stride;
  606. ST2x4_UB(tmp1, 4, ptemp_src, stride);
  607. ptemp_src += 4 * stride;
  608. ST2x4_UB(tmp0, 0, ptemp_src, stride);
  609. ptemp_src += 4 * stride;
  610. ST2x4_UB(tmp0, 4, ptemp_src, stride);
  611. ptemp_src += 4 * stride;
  612. }
  613. static void SimpleVFilter16i(uint8_t* src_y, int stride, int b_limit_in) {
  614. SimpleVFilter16(src_y + 4 * stride, stride, b_limit_in);
  615. SimpleVFilter16(src_y + 8 * stride, stride, b_limit_in);
  616. SimpleVFilter16(src_y + 12 * stride, stride, b_limit_in);
  617. }
  618. static void SimpleHFilter16i(uint8_t* src_y, int stride, int b_limit_in) {
  619. SimpleHFilter16(src_y + 4, stride, b_limit_in);
  620. SimpleHFilter16(src_y + 8, stride, b_limit_in);
  621. SimpleHFilter16(src_y + 12, stride, b_limit_in);
  622. }
  623. //------------------------------------------------------------------------------
  624. // Intra predictions
  625. //------------------------------------------------------------------------------
  626. // 4x4
  627. static void DC4(uint8_t* dst) { // DC
  628. uint32_t dc = 4;
  629. int i;
  630. for (i = 0; i < 4; ++i) dc += dst[i - BPS] + dst[-1 + i * BPS];
  631. dc >>= 3;
  632. dc = dc | (dc << 8) | (dc << 16) | (dc << 24);
  633. SW4(dc, dc, dc, dc, dst, BPS);
  634. }
  635. static void TM4(uint8_t* dst) {
  636. const uint8_t* const ptemp = dst - BPS - 1;
  637. v8i16 T, d, r0, r1, r2, r3;
  638. const v16i8 zero = { 0 };
  639. const v8i16 TL = (v8i16)__msa_fill_h(ptemp[0 * BPS]);
  640. const v8i16 L0 = (v8i16)__msa_fill_h(ptemp[1 * BPS]);
  641. const v8i16 L1 = (v8i16)__msa_fill_h(ptemp[2 * BPS]);
  642. const v8i16 L2 = (v8i16)__msa_fill_h(ptemp[3 * BPS]);
  643. const v8i16 L3 = (v8i16)__msa_fill_h(ptemp[4 * BPS]);
  644. const v16u8 T1 = LD_UB(ptemp + 1);
  645. T = (v8i16)__msa_ilvr_b(zero, (v16i8)T1);
  646. d = T - TL;
  647. ADD4(d, L0, d, L1, d, L2, d, L3, r0, r1, r2, r3);
  648. CLIP_SH4_0_255(r0, r1, r2, r3);
  649. PCKEV_ST4x4_UB(r0, r1, r2, r3, dst, BPS);
  650. }
  651. static void VE4(uint8_t* dst) { // vertical
  652. const uint8_t* const ptop = dst - BPS - 1;
  653. const uint32_t val0 = LW(ptop + 0);
  654. const uint32_t val1 = LW(ptop + 4);
  655. uint32_t out;
  656. v16u8 A = { 0 }, B, C, AC, B2, R;
  657. INSERT_W2_UB(val0, val1, A);
  658. B = SLDI_UB(A, A, 1);
  659. C = SLDI_UB(A, A, 2);
  660. AC = __msa_ave_u_b(A, C);
  661. B2 = __msa_ave_u_b(B, B);
  662. R = __msa_aver_u_b(AC, B2);
  663. out = __msa_copy_s_w((v4i32)R, 0);
  664. SW4(out, out, out, out, dst, BPS);
  665. }
  666. static void RD4(uint8_t* dst) { // Down-right
  667. const uint8_t* const ptop = dst - 1 - BPS;
  668. uint32_t val0 = LW(ptop + 0);
  669. uint32_t val1 = LW(ptop + 4);
  670. uint32_t val2, val3;
  671. v16u8 A, B, C, AC, B2, R, A1 = { 0 };
  672. INSERT_W2_UB(val0, val1, A1);
  673. A = SLDI_UB(A1, A1, 12);
  674. A = (v16u8)__msa_insert_b((v16i8)A, 3, ptop[1 * BPS]);
  675. A = (v16u8)__msa_insert_b((v16i8)A, 2, ptop[2 * BPS]);
  676. A = (v16u8)__msa_insert_b((v16i8)A, 1, ptop[3 * BPS]);
  677. A = (v16u8)__msa_insert_b((v16i8)A, 0, ptop[4 * BPS]);
  678. B = SLDI_UB(A, A, 1);
  679. C = SLDI_UB(A, A, 2);
  680. AC = __msa_ave_u_b(A, C);
  681. B2 = __msa_ave_u_b(B, B);
  682. R = __msa_aver_u_b(AC, B2);
  683. val3 = __msa_copy_s_w((v4i32)R, 0);
  684. R = SLDI_UB(R, R, 1);
  685. val2 = __msa_copy_s_w((v4i32)R, 0);
  686. R = SLDI_UB(R, R, 1);
  687. val1 = __msa_copy_s_w((v4i32)R, 0);
  688. R = SLDI_UB(R, R, 1);
  689. val0 = __msa_copy_s_w((v4i32)R, 0);
  690. SW4(val0, val1, val2, val3, dst, BPS);
  691. }
  692. static void LD4(uint8_t* dst) { // Down-Left
  693. const uint8_t* const ptop = dst - BPS;
  694. uint32_t val0 = LW(ptop + 0);
  695. uint32_t val1 = LW(ptop + 4);
  696. uint32_t val2, val3;
  697. v16u8 A = { 0 }, B, C, AC, B2, R;
  698. INSERT_W2_UB(val0, val1, A);
  699. B = SLDI_UB(A, A, 1);
  700. C = SLDI_UB(A, A, 2);
  701. C = (v16u8)__msa_insert_b((v16i8)C, 6, ptop[7]);
  702. AC = __msa_ave_u_b(A, C);
  703. B2 = __msa_ave_u_b(B, B);
  704. R = __msa_aver_u_b(AC, B2);
  705. val0 = __msa_copy_s_w((v4i32)R, 0);
  706. R = SLDI_UB(R, R, 1);
  707. val1 = __msa_copy_s_w((v4i32)R, 0);
  708. R = SLDI_UB(R, R, 1);
  709. val2 = __msa_copy_s_w((v4i32)R, 0);
  710. R = SLDI_UB(R, R, 1);
  711. val3 = __msa_copy_s_w((v4i32)R, 0);
  712. SW4(val0, val1, val2, val3, dst, BPS);
  713. }
  714. // 16x16
  715. static void DC16(uint8_t* dst) { // DC
  716. uint32_t dc = 16;
  717. int i;
  718. const v16u8 rtop = LD_UB(dst - BPS);
  719. const v8u16 dctop = __msa_hadd_u_h(rtop, rtop);
  720. v16u8 out;
  721. for (i = 0; i < 16; ++i) {
  722. dc += dst[-1 + i * BPS];
  723. }
  724. dc += HADD_UH_U32(dctop);
  725. out = (v16u8)__msa_fill_b(dc >> 5);
  726. ST_UB8(out, out, out, out, out, out, out, out, dst, BPS);
  727. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS);
  728. }
  729. static void TM16(uint8_t* dst) {
  730. int j;
  731. v8i16 d1, d2;
  732. const v16i8 zero = { 0 };
  733. const v8i16 TL = (v8i16)__msa_fill_h(dst[-1 - BPS]);
  734. const v16i8 T = LD_SB(dst - BPS);
  735. ILVRL_B2_SH(zero, T, d1, d2);
  736. SUB2(d1, TL, d2, TL, d1, d2);
  737. for (j = 0; j < 16; j += 4) {
  738. v16i8 t0, t1, t2, t3;
  739. v8i16 r0, r1, r2, r3, r4, r5, r6, r7;
  740. const v8i16 L0 = (v8i16)__msa_fill_h(dst[-1 + 0 * BPS]);
  741. const v8i16 L1 = (v8i16)__msa_fill_h(dst[-1 + 1 * BPS]);
  742. const v8i16 L2 = (v8i16)__msa_fill_h(dst[-1 + 2 * BPS]);
  743. const v8i16 L3 = (v8i16)__msa_fill_h(dst[-1 + 3 * BPS]);
  744. ADD4(d1, L0, d1, L1, d1, L2, d1, L3, r0, r1, r2, r3);
  745. ADD4(d2, L0, d2, L1, d2, L2, d2, L3, r4, r5, r6, r7);
  746. CLIP_SH4_0_255(r0, r1, r2, r3);
  747. CLIP_SH4_0_255(r4, r5, r6, r7);
  748. PCKEV_B4_SB(r4, r0, r5, r1, r6, r2, r7, r3, t0, t1, t2, t3);
  749. ST_SB4(t0, t1, t2, t3, dst, BPS);
  750. dst += 4 * BPS;
  751. }
  752. }
  753. static void VE16(uint8_t* dst) { // vertical
  754. const v16u8 rtop = LD_UB(dst - BPS);
  755. ST_UB8(rtop, rtop, rtop, rtop, rtop, rtop, rtop, rtop, dst, BPS);
  756. ST_UB8(rtop, rtop, rtop, rtop, rtop, rtop, rtop, rtop, dst + 8 * BPS, BPS);
  757. }
  758. static void HE16(uint8_t* dst) { // horizontal
  759. int j;
  760. for (j = 16; j > 0; j -= 4) {
  761. const v16u8 L0 = (v16u8)__msa_fill_b(dst[-1 + 0 * BPS]);
  762. const v16u8 L1 = (v16u8)__msa_fill_b(dst[-1 + 1 * BPS]);
  763. const v16u8 L2 = (v16u8)__msa_fill_b(dst[-1 + 2 * BPS]);
  764. const v16u8 L3 = (v16u8)__msa_fill_b(dst[-1 + 3 * BPS]);
  765. ST_UB4(L0, L1, L2, L3, dst, BPS);
  766. dst += 4 * BPS;
  767. }
  768. }
  769. static void DC16NoTop(uint8_t* dst) { // DC with top samples not available
  770. int j;
  771. uint32_t dc = 8;
  772. v16u8 out;
  773. for (j = 0; j < 16; ++j) {
  774. dc += dst[-1 + j * BPS];
  775. }
  776. out = (v16u8)__msa_fill_b(dc >> 4);
  777. ST_UB8(out, out, out, out, out, out, out, out, dst, BPS);
  778. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS);
  779. }
  780. static void DC16NoLeft(uint8_t* dst) { // DC with left samples not available
  781. uint32_t dc = 8;
  782. const v16u8 rtop = LD_UB(dst - BPS);
  783. const v8u16 dctop = __msa_hadd_u_h(rtop, rtop);
  784. v16u8 out;
  785. dc += HADD_UH_U32(dctop);
  786. out = (v16u8)__msa_fill_b(dc >> 4);
  787. ST_UB8(out, out, out, out, out, out, out, out, dst, BPS);
  788. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS);
  789. }
  790. static void DC16NoTopLeft(uint8_t* dst) { // DC with nothing
  791. const v16u8 out = (v16u8)__msa_fill_b(0x80);
  792. ST_UB8(out, out, out, out, out, out, out, out, dst, BPS);
  793. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS);
  794. }
  795. // Chroma
  796. #define STORE8x8(out, dst) do { \
  797. SD4(out, out, out, out, dst + 0 * BPS, BPS); \
  798. SD4(out, out, out, out, dst + 4 * BPS, BPS); \
  799. } while (0)
  800. static void DC8uv(uint8_t* dst) { // DC
  801. uint32_t dc = 8;
  802. int i;
  803. uint64_t out;
  804. const v16u8 rtop = LD_UB(dst - BPS);
  805. const v8u16 temp0 = __msa_hadd_u_h(rtop, rtop);
  806. const v4u32 temp1 = __msa_hadd_u_w(temp0, temp0);
  807. const v2u64 temp2 = __msa_hadd_u_d(temp1, temp1);
  808. v16u8 dctemp;
  809. for (i = 0; i < 8; ++i) {
  810. dc += dst[-1 + i * BPS];
  811. }
  812. dc += __msa_copy_s_w((v4i32)temp2, 0);
  813. dctemp = (v16u8)__msa_fill_b(dc >> 4);
  814. out = __msa_copy_s_d((v2i64)dctemp, 0);
  815. STORE8x8(out, dst);
  816. }
  817. static void TM8uv(uint8_t* dst) {
  818. int j;
  819. const v16i8 T1 = LD_SB(dst - BPS);
  820. const v16i8 zero = { 0 };
  821. const v8i16 T = (v8i16)__msa_ilvr_b(zero, T1);
  822. const v8i16 TL = (v8i16)__msa_fill_h(dst[-1 - BPS]);
  823. const v8i16 d = T - TL;
  824. for (j = 0; j < 8; j += 4) {
  825. v16i8 t0, t1;
  826. v8i16 r0 = (v8i16)__msa_fill_h(dst[-1 + 0 * BPS]);
  827. v8i16 r1 = (v8i16)__msa_fill_h(dst[-1 + 1 * BPS]);
  828. v8i16 r2 = (v8i16)__msa_fill_h(dst[-1 + 2 * BPS]);
  829. v8i16 r3 = (v8i16)__msa_fill_h(dst[-1 + 3 * BPS]);
  830. ADD4(d, r0, d, r1, d, r2, d, r3, r0, r1, r2, r3);
  831. CLIP_SH4_0_255(r0, r1, r2, r3);
  832. PCKEV_B2_SB(r1, r0, r3, r2, t0, t1);
  833. ST4x4_UB(t0, t1, 0, 2, 0, 2, dst, BPS);
  834. ST4x4_UB(t0, t1, 1, 3, 1, 3, dst + 4, BPS);
  835. dst += 4 * BPS;
  836. }
  837. }
  838. static void VE8uv(uint8_t* dst) { // vertical
  839. const v16u8 rtop = LD_UB(dst - BPS);
  840. const uint64_t out = __msa_copy_s_d((v2i64)rtop, 0);
  841. STORE8x8(out, dst);
  842. }
  843. static void HE8uv(uint8_t* dst) { // horizontal
  844. int j;
  845. for (j = 0; j < 8; j += 4) {
  846. const v16u8 L0 = (v16u8)__msa_fill_b(dst[-1 + 0 * BPS]);
  847. const v16u8 L1 = (v16u8)__msa_fill_b(dst[-1 + 1 * BPS]);
  848. const v16u8 L2 = (v16u8)__msa_fill_b(dst[-1 + 2 * BPS]);
  849. const v16u8 L3 = (v16u8)__msa_fill_b(dst[-1 + 3 * BPS]);
  850. const uint64_t out0 = __msa_copy_s_d((v2i64)L0, 0);
  851. const uint64_t out1 = __msa_copy_s_d((v2i64)L1, 0);
  852. const uint64_t out2 = __msa_copy_s_d((v2i64)L2, 0);
  853. const uint64_t out3 = __msa_copy_s_d((v2i64)L3, 0);
  854. SD4(out0, out1, out2, out3, dst, BPS);
  855. dst += 4 * BPS;
  856. }
  857. }
  858. static void DC8uvNoLeft(uint8_t* dst) { // DC with no left samples
  859. const uint32_t dc = 4;
  860. const v16u8 rtop = LD_UB(dst - BPS);
  861. const v8u16 temp0 = __msa_hadd_u_h(rtop, rtop);
  862. const v4u32 temp1 = __msa_hadd_u_w(temp0, temp0);
  863. const v2u64 temp2 = __msa_hadd_u_d(temp1, temp1);
  864. const uint32_t sum_m = __msa_copy_s_w((v4i32)temp2, 0);
  865. const v16u8 dcval = (v16u8)__msa_fill_b((dc + sum_m) >> 3);
  866. const uint64_t out = __msa_copy_s_d((v2i64)dcval, 0);
  867. STORE8x8(out, dst);
  868. }
  869. static void DC8uvNoTop(uint8_t* dst) { // DC with no top samples
  870. uint32_t dc = 4;
  871. int i;
  872. uint64_t out;
  873. v16u8 dctemp;
  874. for (i = 0; i < 8; ++i) {
  875. dc += dst[-1 + i * BPS];
  876. }
  877. dctemp = (v16u8)__msa_fill_b(dc >> 3);
  878. out = __msa_copy_s_d((v2i64)dctemp, 0);
  879. STORE8x8(out, dst);
  880. }
  881. static void DC8uvNoTopLeft(uint8_t* dst) { // DC with nothing
  882. const uint64_t out = 0x8080808080808080ULL;
  883. STORE8x8(out, dst);
  884. }
  885. //------------------------------------------------------------------------------
  886. // Entry point
  887. extern void VP8DspInitMSA(void);
  888. WEBP_TSAN_IGNORE_FUNCTION void VP8DspInitMSA(void) {
  889. VP8TransformWHT = TransformWHT;
  890. VP8Transform = TransformTwo;
  891. VP8TransformDC = TransformDC;
  892. VP8TransformAC3 = TransformAC3;
  893. VP8VFilter16 = VFilter16;
  894. VP8HFilter16 = HFilter16;
  895. VP8VFilter16i = VFilter16i;
  896. VP8HFilter16i = HFilter16i;
  897. VP8VFilter8 = VFilter8;
  898. VP8HFilter8 = HFilter8;
  899. VP8VFilter8i = VFilter8i;
  900. VP8HFilter8i = HFilter8i;
  901. VP8SimpleVFilter16 = SimpleVFilter16;
  902. VP8SimpleHFilter16 = SimpleHFilter16;
  903. VP8SimpleVFilter16i = SimpleVFilter16i;
  904. VP8SimpleHFilter16i = SimpleHFilter16i;
  905. VP8PredLuma4[0] = DC4;
  906. VP8PredLuma4[1] = TM4;
  907. VP8PredLuma4[2] = VE4;
  908. VP8PredLuma4[4] = RD4;
  909. VP8PredLuma4[6] = LD4;
  910. VP8PredLuma16[0] = DC16;
  911. VP8PredLuma16[1] = TM16;
  912. VP8PredLuma16[2] = VE16;
  913. VP8PredLuma16[3] = HE16;
  914. VP8PredLuma16[4] = DC16NoTop;
  915. VP8PredLuma16[5] = DC16NoLeft;
  916. VP8PredLuma16[6] = DC16NoTopLeft;
  917. VP8PredChroma8[0] = DC8uv;
  918. VP8PredChroma8[1] = TM8uv;
  919. VP8PredChroma8[2] = VE8uv;
  920. VP8PredChroma8[3] = HE8uv;
  921. VP8PredChroma8[4] = DC8uvNoTop;
  922. VP8PredChroma8[5] = DC8uvNoLeft;
  923. VP8PredChroma8[6] = DC8uvNoTopLeft;
  924. }
  925. #else // !WEBP_USE_MSA
  926. WEBP_DSP_INIT_STUB(VP8DspInitMSA)
  927. #endif // WEBP_USE_MSA