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. \
  205. FLIP_SIGN4(p1, p0, q0, q1, p1_m, p0_m, q0_m, q1_m); \
  206. filt = __msa_subs_s_b(p1_m, q1_m); \
  207. FILT_VAL(q0_m, p0_m, mask, filt); \
  208. FLIP_SIGN2(p2, q2, p2_m, q2_m); \
  209. t2 = filt & hev; \
  210. /* filt_val &= ~hev */ \
  211. hev = __msa_xori_b(hev, 0xff); \
  212. filt = filt & hev; \
  213. t1 = __msa_adds_s_b(t2, cnst4b); \
  214. t1 = SRAI_B(t1, 3); \
  215. t2 = __msa_adds_s_b(t2, cnst3b); \
  216. t2 = SRAI_B(t2, 3); \
  217. q0_m = __msa_subs_s_b(q0_m, t1); \
  218. p0_m = __msa_adds_s_b(p0_m, t2); \
  219. filt_sign = __msa_clti_s_b(filt, 0); \
  220. ILVRL_B2_SH(filt_sign, filt, filt_r, filt_l); \
  221. /* update q2/p2 */ \
  222. temp0 = filt_r * cnst9h; \
  223. temp1 = ADDVI_H(temp0, 63); \
  224. temp2 = filt_l * cnst9h; \
  225. temp3 = ADDVI_H(temp2, 63); \
  226. FILT2(q2_m, p2_m, q2, p2); \
  227. /* update q1/p1 */ \
  228. temp1 = temp1 + temp0; \
  229. temp3 = temp3 + temp2; \
  230. FILT2(q1_m, p1_m, q1, p1); \
  231. /* update q0/p0 */ \
  232. temp1 = temp1 + temp0; \
  233. temp3 = temp3 + temp2; \
  234. FILT2(q0_m, p0_m, q0, p0); \
  235. } while (0)
  236. #define LPF_MASK_HEV(p3_in, p2_in, p1_in, p0_in, \
  237. q0_in, q1_in, q2_in, q3_in, \
  238. limit_in, b_limit_in, thresh_in, \
  239. hev_out, mask_out) do { \
  240. v16u8 p3_asub_p2_m, p2_asub_p1_m, p1_asub_p0_m, q1_asub_q0_m; \
  241. v16u8 p1_asub_q1_m, p0_asub_q0_m, q3_asub_q2_m, q2_asub_q1_m; \
  242. v16u8 flat_out; \
  243. \
  244. /* absolute subtraction of pixel values */ \
  245. p3_asub_p2_m = __msa_asub_u_b(p3_in, p2_in); \
  246. p2_asub_p1_m = __msa_asub_u_b(p2_in, p1_in); \
  247. p1_asub_p0_m = __msa_asub_u_b(p1_in, p0_in); \
  248. q1_asub_q0_m = __msa_asub_u_b(q1_in, q0_in); \
  249. q2_asub_q1_m = __msa_asub_u_b(q2_in, q1_in); \
  250. q3_asub_q2_m = __msa_asub_u_b(q3_in, q2_in); \
  251. p0_asub_q0_m = __msa_asub_u_b(p0_in, q0_in); \
  252. p1_asub_q1_m = __msa_asub_u_b(p1_in, q1_in); \
  253. /* calculation of hev */ \
  254. flat_out = __msa_max_u_b(p1_asub_p0_m, q1_asub_q0_m); \
  255. hev_out = (thresh_in < flat_out); \
  256. /* calculation of mask */ \
  257. p0_asub_q0_m = __msa_adds_u_b(p0_asub_q0_m, p0_asub_q0_m); \
  258. p1_asub_q1_m = SRAI_B(p1_asub_q1_m, 1); \
  259. p0_asub_q0_m = __msa_adds_u_b(p0_asub_q0_m, p1_asub_q1_m); \
  260. mask_out = (b_limit_in < p0_asub_q0_m); \
  261. mask_out = __msa_max_u_b(flat_out, mask_out); \
  262. p3_asub_p2_m = __msa_max_u_b(p3_asub_p2_m, p2_asub_p1_m); \
  263. mask_out = __msa_max_u_b(p3_asub_p2_m, mask_out); \
  264. q2_asub_q1_m = __msa_max_u_b(q2_asub_q1_m, q3_asub_q2_m); \
  265. mask_out = __msa_max_u_b(q2_asub_q1_m, mask_out); \
  266. mask_out = (limit_in < mask_out); \
  267. mask_out = __msa_xori_b(mask_out, 0xff); \
  268. } while (0)
  269. #define ST6x1_UB(in0, in0_idx, in1, in1_idx, pdst, stride) do { \
  270. const uint16_t tmp0_h = __msa_copy_s_h((v8i16)in1, in1_idx); \
  271. const uint32_t tmp0_w = __msa_copy_s_w((v4i32)in0, in0_idx); \
  272. SW(tmp0_w, pdst); \
  273. SH(tmp0_h, pdst + stride); \
  274. } while (0)
  275. #define ST6x4_UB(in0, start_in0_idx, in1, start_in1_idx, pdst, stride) do { \
  276. uint8_t* ptmp1 = (uint8_t*)pdst; \
  277. ST6x1_UB(in0, start_in0_idx, in1, start_in1_idx, ptmp1, 4); \
  278. ptmp1 += stride; \
  279. ST6x1_UB(in0, start_in0_idx + 1, in1, start_in1_idx + 1, ptmp1, 4); \
  280. ptmp1 += stride; \
  281. ST6x1_UB(in0, start_in0_idx + 2, in1, start_in1_idx + 2, ptmp1, 4); \
  282. ptmp1 += stride; \
  283. ST6x1_UB(in0, start_in0_idx + 3, in1, start_in1_idx + 3, ptmp1, 4); \
  284. } while (0)
  285. #define LPF_SIMPLE_FILT(p1_in, p0_in, q0_in, q1_in, mask) do { \
  286. v16i8 p1_m, p0_m, q0_m, q1_m, filt, filt1, filt2; \
  287. const v16i8 cnst4b = __msa_ldi_b(4); \
  288. const v16i8 cnst3b = __msa_ldi_b(3); \
  289. \
  290. FLIP_SIGN4(p1_in, p0_in, q0_in, q1_in, p1_m, p0_m, q0_m, q1_m); \
  291. filt = __msa_subs_s_b(p1_m, q1_m); \
  292. FILT_VAL(q0_m, p0_m, mask, filt); \
  293. filt1 = __msa_adds_s_b(filt, cnst4b); \
  294. filt1 = SRAI_B(filt1, 3); \
  295. filt2 = __msa_adds_s_b(filt, cnst3b); \
  296. filt2 = SRAI_B(filt2, 3); \
  297. q0_m = __msa_subs_s_b(q0_m, filt1); \
  298. p0_m = __msa_adds_s_b(p0_m, filt2); \
  299. q0_in = __msa_xori_b((v16u8)q0_m, 0x80); \
  300. p0_in = __msa_xori_b((v16u8)p0_m, 0x80); \
  301. } while (0)
  302. #define LPF_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask) do { \
  303. v16u8 p1_a_sub_q1, p0_a_sub_q0; \
  304. \
  305. p0_a_sub_q0 = __msa_asub_u_b(p0, q0); \
  306. p1_a_sub_q1 = __msa_asub_u_b(p1, q1); \
  307. p1_a_sub_q1 = (v16u8)__msa_srli_b((v16i8)p1_a_sub_q1, 1); \
  308. p0_a_sub_q0 = __msa_adds_u_b(p0_a_sub_q0, p0_a_sub_q0); \
  309. mask = __msa_adds_u_b(p0_a_sub_q0, p1_a_sub_q1); \
  310. mask = (mask <= b_limit); \
  311. } while (0)
  312. static void VFilter16(uint8_t* src, int stride,
  313. int b_limit_in, int limit_in, int thresh_in) {
  314. uint8_t* ptemp = src - 4 * stride;
  315. v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
  316. v16u8 mask, hev;
  317. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  318. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  319. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  320. LD_UB8(ptemp, stride, p3, p2, p1, p0, q0, q1, q2, q3);
  321. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  322. hev, mask);
  323. LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
  324. ptemp = src - 3 * stride;
  325. ST_UB4(p2, p1, p0, q0, ptemp, stride);
  326. ptemp += (4 * stride);
  327. ST_UB2(q1, q2, ptemp, stride);
  328. }
  329. static void HFilter16(uint8_t* src, int stride,
  330. int b_limit_in, int limit_in, int thresh_in) {
  331. uint8_t* ptmp = src - 4;
  332. v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
  333. v16u8 mask, hev;
  334. v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
  335. v16u8 row9, row10, row11, row12, row13, row14, row15;
  336. v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  337. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  338. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  339. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  340. LD_UB8(ptmp, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  341. ptmp += (8 * stride);
  342. LD_UB8(ptmp, stride, row8, row9, row10, row11, row12, row13, row14, row15);
  343. TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  344. row8, row9, row10, row11, row12, row13, row14, row15,
  345. p3, p2, p1, p0, q0, q1, q2, q3);
  346. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  347. hev, mask);
  348. LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
  349. ILVR_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
  350. ILVRL_H2_SH(tmp1, tmp0, tmp3, tmp4);
  351. ILVL_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
  352. ILVRL_H2_SH(tmp1, tmp0, tmp6, tmp7);
  353. ILVRL_B2_SH(q2, q1, tmp2, tmp5);
  354. ptmp = src - 3;
  355. ST6x1_UB(tmp3, 0, tmp2, 0, ptmp, 4);
  356. ptmp += stride;
  357. ST6x1_UB(tmp3, 1, tmp2, 1, ptmp, 4);
  358. ptmp += stride;
  359. ST6x1_UB(tmp3, 2, tmp2, 2, ptmp, 4);
  360. ptmp += stride;
  361. ST6x1_UB(tmp3, 3, tmp2, 3, ptmp, 4);
  362. ptmp += stride;
  363. ST6x1_UB(tmp4, 0, tmp2, 4, ptmp, 4);
  364. ptmp += stride;
  365. ST6x1_UB(tmp4, 1, tmp2, 5, ptmp, 4);
  366. ptmp += stride;
  367. ST6x1_UB(tmp4, 2, tmp2, 6, ptmp, 4);
  368. ptmp += stride;
  369. ST6x1_UB(tmp4, 3, tmp2, 7, ptmp, 4);
  370. ptmp += stride;
  371. ST6x1_UB(tmp6, 0, tmp5, 0, ptmp, 4);
  372. ptmp += stride;
  373. ST6x1_UB(tmp6, 1, tmp5, 1, ptmp, 4);
  374. ptmp += stride;
  375. ST6x1_UB(tmp6, 2, tmp5, 2, ptmp, 4);
  376. ptmp += stride;
  377. ST6x1_UB(tmp6, 3, tmp5, 3, ptmp, 4);
  378. ptmp += stride;
  379. ST6x1_UB(tmp7, 0, tmp5, 4, ptmp, 4);
  380. ptmp += stride;
  381. ST6x1_UB(tmp7, 1, tmp5, 5, ptmp, 4);
  382. ptmp += stride;
  383. ST6x1_UB(tmp7, 2, tmp5, 6, ptmp, 4);
  384. ptmp += stride;
  385. ST6x1_UB(tmp7, 3, tmp5, 7, ptmp, 4);
  386. }
  387. // on three inner edges
  388. static void VFilterHorEdge16i(uint8_t* src, int stride,
  389. int b_limit, int limit, int thresh) {
  390. v16u8 mask, hev;
  391. v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
  392. const v16u8 thresh0 = (v16u8)__msa_fill_b(thresh);
  393. const v16u8 b_limit0 = (v16u8)__msa_fill_b(b_limit);
  394. const v16u8 limit0 = (v16u8)__msa_fill_b(limit);
  395. LD_UB8((src - 4 * stride), stride, p3, p2, p1, p0, q0, q1, q2, q3);
  396. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit0, b_limit0, thresh0,
  397. hev, mask);
  398. LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
  399. ST_UB4(p1, p0, q0, q1, (src - 2 * stride), stride);
  400. }
  401. static void VFilter16i(uint8_t* src_y, int stride,
  402. int b_limit, int limit, int thresh) {
  403. VFilterHorEdge16i(src_y + 4 * stride, stride, b_limit, limit, thresh);
  404. VFilterHorEdge16i(src_y + 8 * stride, stride, b_limit, limit, thresh);
  405. VFilterHorEdge16i(src_y + 12 * stride, stride, b_limit, limit, thresh);
  406. }
  407. static void HFilterVertEdge16i(uint8_t* src, int stride,
  408. int b_limit, int limit, int thresh) {
  409. v16u8 mask, hev;
  410. v16u8 p3, p2, p1, p0, q3, q2, q1, q0;
  411. v16u8 row0, row1, row2, row3, row4, row5, row6, row7;
  412. v16u8 row8, row9, row10, row11, row12, row13, row14, row15;
  413. v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  414. const v16u8 thresh0 = (v16u8)__msa_fill_b(thresh);
  415. const v16u8 b_limit0 = (v16u8)__msa_fill_b(b_limit);
  416. const v16u8 limit0 = (v16u8)__msa_fill_b(limit);
  417. LD_UB8(src - 4, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  418. LD_UB8(src - 4 + (8 * stride), stride,
  419. row8, row9, row10, row11, row12, row13, row14, row15);
  420. TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  421. row8, row9, row10, row11, row12, row13, row14, row15,
  422. p3, p2, p1, p0, q0, q1, q2, q3);
  423. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit0, b_limit0, thresh0,
  424. hev, mask);
  425. LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
  426. ILVR_B2_SH(p0, p1, q1, q0, tmp0, tmp1);
  427. ILVRL_H2_SH(tmp1, tmp0, tmp2, tmp3);
  428. ILVL_B2_SH(p0, p1, q1, q0, tmp0, tmp1);
  429. ILVRL_H2_SH(tmp1, tmp0, tmp4, tmp5);
  430. src -= 2;
  431. ST4x8_UB(tmp2, tmp3, src, stride);
  432. src += (8 * stride);
  433. ST4x8_UB(tmp4, tmp5, src, stride);
  434. }
  435. static void HFilter16i(uint8_t* src_y, int stride,
  436. int b_limit, int limit, int thresh) {
  437. HFilterVertEdge16i(src_y + 4, stride, b_limit, limit, thresh);
  438. HFilterVertEdge16i(src_y + 8, stride, b_limit, limit, thresh);
  439. HFilterVertEdge16i(src_y + 12, stride, b_limit, limit, thresh);
  440. }
  441. // 8-pixels wide variants, for chroma filtering
  442. static void VFilter8(uint8_t* src_u, uint8_t* src_v, int stride,
  443. int b_limit_in, int limit_in, int thresh_in) {
  444. uint8_t* ptmp_src_u = src_u - 4 * stride;
  445. uint8_t* ptmp_src_v = src_v - 4 * stride;
  446. uint64_t p2_d, p1_d, p0_d, q0_d, q1_d, q2_d;
  447. v16u8 p3, p2, p1, p0, q3, q2, q1, q0, mask, hev;
  448. v16u8 p3_u, p2_u, p1_u, p0_u, q3_u, q2_u, q1_u, q0_u;
  449. v16u8 p3_v, p2_v, p1_v, p0_v, q3_v, q2_v, q1_v, q0_v;
  450. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  451. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  452. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  453. LD_UB8(ptmp_src_u, stride, p3_u, p2_u, p1_u, p0_u, q0_u, q1_u, q2_u, q3_u);
  454. LD_UB8(ptmp_src_v, stride, p3_v, p2_v, p1_v, p0_v, q0_v, q1_v, q2_v, q3_v);
  455. ILVR_D4_UB(p3_v, p3_u, p2_v, p2_u, p1_v, p1_u, p0_v, p0_u, p3, p2, p1, p0);
  456. ILVR_D4_UB(q0_v, q0_u, q1_v, q1_u, q2_v, q2_u, q3_v, q3_u, q0, q1, q2, q3);
  457. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  458. hev, mask);
  459. LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
  460. p2_d = __msa_copy_s_d((v2i64)p2, 0);
  461. p1_d = __msa_copy_s_d((v2i64)p1, 0);
  462. p0_d = __msa_copy_s_d((v2i64)p0, 0);
  463. q0_d = __msa_copy_s_d((v2i64)q0, 0);
  464. q1_d = __msa_copy_s_d((v2i64)q1, 0);
  465. q2_d = __msa_copy_s_d((v2i64)q2, 0);
  466. ptmp_src_u += stride;
  467. SD4(p2_d, p1_d, p0_d, q0_d, ptmp_src_u, stride);
  468. ptmp_src_u += (4 * stride);
  469. SD(q1_d, ptmp_src_u);
  470. ptmp_src_u += stride;
  471. SD(q2_d, ptmp_src_u);
  472. p2_d = __msa_copy_s_d((v2i64)p2, 1);
  473. p1_d = __msa_copy_s_d((v2i64)p1, 1);
  474. p0_d = __msa_copy_s_d((v2i64)p0, 1);
  475. q0_d = __msa_copy_s_d((v2i64)q0, 1);
  476. q1_d = __msa_copy_s_d((v2i64)q1, 1);
  477. q2_d = __msa_copy_s_d((v2i64)q2, 1);
  478. ptmp_src_v += stride;
  479. SD4(p2_d, p1_d, p0_d, q0_d, ptmp_src_v, stride);
  480. ptmp_src_v += (4 * stride);
  481. SD(q1_d, ptmp_src_v);
  482. ptmp_src_v += stride;
  483. SD(q2_d, ptmp_src_v);
  484. }
  485. static void HFilter8(uint8_t* src_u, uint8_t* src_v, int stride,
  486. int b_limit_in, int limit_in, int thresh_in) {
  487. uint8_t* ptmp_src_u = src_u - 4;
  488. uint8_t* ptmp_src_v = src_v - 4;
  489. v16u8 p3, p2, p1, p0, q3, q2, q1, q0, mask, hev;
  490. v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
  491. v16u8 row9, row10, row11, row12, row13, row14, row15;
  492. v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  493. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  494. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  495. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  496. LD_UB8(ptmp_src_u, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  497. LD_UB8(ptmp_src_v, stride,
  498. row8, row9, row10, row11, row12, row13, row14, row15);
  499. TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  500. row8, row9, row10, row11, row12, row13, row14, row15,
  501. p3, p2, p1, p0, q0, q1, q2, q3);
  502. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  503. hev, mask);
  504. LPF_MBFILTER(p2, p1, p0, q0, q1, q2, mask, hev);
  505. ILVR_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
  506. ILVRL_H2_SH(tmp1, tmp0, tmp3, tmp4);
  507. ILVL_B2_SH(p1, p2, q0, p0, tmp0, tmp1);
  508. ILVRL_H2_SH(tmp1, tmp0, tmp6, tmp7);
  509. ILVRL_B2_SH(q2, q1, tmp2, tmp5);
  510. ptmp_src_u += 1;
  511. ST6x4_UB(tmp3, 0, tmp2, 0, ptmp_src_u, stride);
  512. ptmp_src_u += 4 * stride;
  513. ST6x4_UB(tmp4, 0, tmp2, 4, ptmp_src_u, stride);
  514. ptmp_src_v += 1;
  515. ST6x4_UB(tmp6, 0, tmp5, 0, ptmp_src_v, stride);
  516. ptmp_src_v += 4 * stride;
  517. ST6x4_UB(tmp7, 0, tmp5, 4, ptmp_src_v, stride);
  518. }
  519. static void VFilter8i(uint8_t* src_u, uint8_t* src_v, int stride,
  520. int b_limit_in, int limit_in, int thresh_in) {
  521. uint64_t p1_d, p0_d, q0_d, q1_d;
  522. v16u8 p3, p2, p1, p0, q3, q2, q1, q0, mask, hev;
  523. v16u8 p3_u, p2_u, p1_u, p0_u, q3_u, q2_u, q1_u, q0_u;
  524. v16u8 p3_v, p2_v, p1_v, p0_v, q3_v, q2_v, q1_v, q0_v;
  525. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  526. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  527. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  528. LD_UB8(src_u, stride, p3_u, p2_u, p1_u, p0_u, q0_u, q1_u, q2_u, q3_u);
  529. src_u += (5 * stride);
  530. LD_UB8(src_v, stride, p3_v, p2_v, p1_v, p0_v, q0_v, q1_v, q2_v, q3_v);
  531. src_v += (5 * stride);
  532. ILVR_D4_UB(p3_v, p3_u, p2_v, p2_u, p1_v, p1_u, p0_v, p0_u, p3, p2, p1, p0);
  533. ILVR_D4_UB(q0_v, q0_u, q1_v, q1_u, q2_v, q2_u, q3_v, q3_u, q0, q1, q2, q3);
  534. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  535. hev, mask);
  536. LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
  537. p1_d = __msa_copy_s_d((v2i64)p1, 0);
  538. p0_d = __msa_copy_s_d((v2i64)p0, 0);
  539. q0_d = __msa_copy_s_d((v2i64)q0, 0);
  540. q1_d = __msa_copy_s_d((v2i64)q1, 0);
  541. SD4(q1_d, q0_d, p0_d, p1_d, src_u, -stride);
  542. p1_d = __msa_copy_s_d((v2i64)p1, 1);
  543. p0_d = __msa_copy_s_d((v2i64)p0, 1);
  544. q0_d = __msa_copy_s_d((v2i64)q0, 1);
  545. q1_d = __msa_copy_s_d((v2i64)q1, 1);
  546. SD4(q1_d, q0_d, p0_d, p1_d, src_v, -stride);
  547. }
  548. static void HFilter8i(uint8_t* src_u, uint8_t* src_v, int stride,
  549. int b_limit_in, int limit_in, int thresh_in) {
  550. v16u8 p3, p2, p1, p0, q3, q2, q1, q0, mask, hev;
  551. v16u8 row0, row1, row2, row3, row4, row5, row6, row7, row8;
  552. v16u8 row9, row10, row11, row12, row13, row14, row15;
  553. v4i32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
  554. const v16u8 thresh = (v16u8)__msa_fill_b(thresh_in);
  555. const v16u8 limit = (v16u8)__msa_fill_b(limit_in);
  556. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  557. LD_UB8(src_u, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  558. LD_UB8(src_v, stride,
  559. row8, row9, row10, row11, row12, row13, row14, row15);
  560. TRANSPOSE16x8_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  561. row8, row9, row10, row11, row12, row13, row14, row15,
  562. p3, p2, p1, p0, q0, q1, q2, q3);
  563. LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
  564. hev, mask);
  565. LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev);
  566. ILVR_B2_SW(p0, p1, q1, q0, tmp0, tmp1);
  567. ILVRL_H2_SW(tmp1, tmp0, tmp2, tmp3);
  568. ILVL_B2_SW(p0, p1, q1, q0, tmp0, tmp1);
  569. ILVRL_H2_SW(tmp1, tmp0, tmp4, tmp5);
  570. src_u += 2;
  571. ST4x4_UB(tmp2, tmp2, 0, 1, 2, 3, src_u, stride);
  572. src_u += 4 * stride;
  573. ST4x4_UB(tmp3, tmp3, 0, 1, 2, 3, src_u, stride);
  574. src_v += 2;
  575. ST4x4_UB(tmp4, tmp4, 0, 1, 2, 3, src_v, stride);
  576. src_v += 4 * stride;
  577. ST4x4_UB(tmp5, tmp5, 0, 1, 2, 3, src_v, stride);
  578. }
  579. static void SimpleVFilter16(uint8_t* src, int stride, int b_limit_in) {
  580. v16u8 p1, p0, q1, q0, mask;
  581. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  582. LD_UB4(src - 2 * stride, stride, p1, p0, q0, q1);
  583. LPF_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask);
  584. LPF_SIMPLE_FILT(p1, p0, q0, q1, mask);
  585. ST_UB2(p0, q0, src - stride, stride);
  586. }
  587. static void SimpleHFilter16(uint8_t* src, int stride, int b_limit_in) {
  588. v16u8 p1, p0, q1, q0, mask, row0, row1, row2, row3, row4, row5, row6, row7;
  589. v16u8 row8, row9, row10, row11, row12, row13, row14, row15;
  590. v8i16 tmp0, tmp1;
  591. const v16u8 b_limit = (v16u8)__msa_fill_b(b_limit_in);
  592. uint8_t* ptemp_src = src - 2;
  593. LD_UB8(ptemp_src, stride, row0, row1, row2, row3, row4, row5, row6, row7);
  594. LD_UB8(ptemp_src + 8 * stride, stride,
  595. row8, row9, row10, row11, row12, row13, row14, row15);
  596. TRANSPOSE16x4_UB_UB(row0, row1, row2, row3, row4, row5, row6, row7,
  597. row8, row9, row10, row11, row12, row13, row14, row15,
  598. p1, p0, q0, q1);
  599. LPF_SIMPLE_MASK(p1, p0, q0, q1, b_limit, mask);
  600. LPF_SIMPLE_FILT(p1, p0, q0, q1, mask);
  601. ILVRL_B2_SH(q0, p0, tmp1, tmp0);
  602. ptemp_src += 1;
  603. ST2x4_UB(tmp1, 0, ptemp_src, stride);
  604. ptemp_src += 4 * stride;
  605. ST2x4_UB(tmp1, 4, ptemp_src, stride);
  606. ptemp_src += 4 * stride;
  607. ST2x4_UB(tmp0, 0, ptemp_src, stride);
  608. ptemp_src += 4 * stride;
  609. ST2x4_UB(tmp0, 4, ptemp_src, stride);
  610. ptemp_src += 4 * stride;
  611. }
  612. static void SimpleVFilter16i(uint8_t* src_y, int stride, int b_limit_in) {
  613. SimpleVFilter16(src_y + 4 * stride, stride, b_limit_in);
  614. SimpleVFilter16(src_y + 8 * stride, stride, b_limit_in);
  615. SimpleVFilter16(src_y + 12 * stride, stride, b_limit_in);
  616. }
  617. static void SimpleHFilter16i(uint8_t* src_y, int stride, int b_limit_in) {
  618. SimpleHFilter16(src_y + 4, stride, b_limit_in);
  619. SimpleHFilter16(src_y + 8, stride, b_limit_in);
  620. SimpleHFilter16(src_y + 12, stride, b_limit_in);
  621. }
  622. //------------------------------------------------------------------------------
  623. // Intra predictions
  624. //------------------------------------------------------------------------------
  625. // 4x4
  626. static void DC4(uint8_t* dst) { // DC
  627. uint32_t dc = 4;
  628. int i;
  629. for (i = 0; i < 4; ++i) dc += dst[i - BPS] + dst[-1 + i * BPS];
  630. dc >>= 3;
  631. dc = dc | (dc << 8) | (dc << 16) | (dc << 24);
  632. SW4(dc, dc, dc, dc, dst, BPS);
  633. }
  634. static void TM4(uint8_t* dst) {
  635. const uint8_t* const ptemp = dst - BPS - 1;
  636. v8i16 T, d, r0, r1, r2, r3;
  637. const v16i8 zero = { 0 };
  638. const v8i16 TL = (v8i16)__msa_fill_h(ptemp[0 * BPS]);
  639. const v8i16 L0 = (v8i16)__msa_fill_h(ptemp[1 * BPS]);
  640. const v8i16 L1 = (v8i16)__msa_fill_h(ptemp[2 * BPS]);
  641. const v8i16 L2 = (v8i16)__msa_fill_h(ptemp[3 * BPS]);
  642. const v8i16 L3 = (v8i16)__msa_fill_h(ptemp[4 * BPS]);
  643. const v16u8 T1 = LD_UB(ptemp + 1);
  644. T = (v8i16)__msa_ilvr_b(zero, (v16i8)T1);
  645. d = T - TL;
  646. ADD4(d, L0, d, L1, d, L2, d, L3, r0, r1, r2, r3);
  647. CLIP_SH4_0_255(r0, r1, r2, r3);
  648. PCKEV_ST4x4_UB(r0, r1, r2, r3, dst, BPS);
  649. }
  650. static void VE4(uint8_t* dst) { // vertical
  651. const uint8_t* const ptop = dst - BPS - 1;
  652. const uint32_t val0 = LW(ptop + 0);
  653. const uint32_t val1 = LW(ptop + 4);
  654. uint32_t out;
  655. v16u8 A, B, C, AC, B2, R;
  656. INSERT_W2_UB(val0, val1, A);
  657. B = SLDI_UB(A, A, 1);
  658. C = SLDI_UB(A, A, 2);
  659. AC = __msa_ave_u_b(A, C);
  660. B2 = __msa_ave_u_b(B, B);
  661. R = __msa_aver_u_b(AC, B2);
  662. out = __msa_copy_s_w((v4i32)R, 0);
  663. SW4(out, out, out, out, dst, BPS);
  664. }
  665. static void RD4(uint8_t* dst) { // Down-right
  666. const uint8_t* const ptop = dst - 1 - BPS;
  667. uint32_t val0 = LW(ptop + 0);
  668. uint32_t val1 = LW(ptop + 4);
  669. uint32_t val2, val3;
  670. v16u8 A, B, C, AC, B2, R, A1;
  671. INSERT_W2_UB(val0, val1, A1);
  672. A = SLDI_UB(A1, A1, 12);
  673. A = (v16u8)__msa_insert_b((v16i8)A, 3, ptop[1 * BPS]);
  674. A = (v16u8)__msa_insert_b((v16i8)A, 2, ptop[2 * BPS]);
  675. A = (v16u8)__msa_insert_b((v16i8)A, 1, ptop[3 * BPS]);
  676. A = (v16u8)__msa_insert_b((v16i8)A, 0, ptop[4 * BPS]);
  677. B = SLDI_UB(A, A, 1);
  678. C = SLDI_UB(A, A, 2);
  679. AC = __msa_ave_u_b(A, C);
  680. B2 = __msa_ave_u_b(B, B);
  681. R = __msa_aver_u_b(AC, B2);
  682. val3 = __msa_copy_s_w((v4i32)R, 0);
  683. R = SLDI_UB(R, R, 1);
  684. val2 = __msa_copy_s_w((v4i32)R, 0);
  685. R = SLDI_UB(R, R, 1);
  686. val1 = __msa_copy_s_w((v4i32)R, 0);
  687. R = SLDI_UB(R, R, 1);
  688. val0 = __msa_copy_s_w((v4i32)R, 0);
  689. SW4(val0, val1, val2, val3, dst, BPS);
  690. }
  691. static void LD4(uint8_t* dst) { // Down-Left
  692. const uint8_t* const ptop = dst - BPS;
  693. uint32_t val0 = LW(ptop + 0);
  694. uint32_t val1 = LW(ptop + 4);
  695. uint32_t val2, val3;
  696. v16u8 A, B, C, AC, B2, R;
  697. INSERT_W2_UB(val0, val1, A);
  698. B = SLDI_UB(A, A, 1);
  699. C = SLDI_UB(A, A, 2);
  700. C = (v16u8)__msa_insert_b((v16i8)C, 6, ptop[7]);
  701. AC = __msa_ave_u_b(A, C);
  702. B2 = __msa_ave_u_b(B, B);
  703. R = __msa_aver_u_b(AC, B2);
  704. val0 = __msa_copy_s_w((v4i32)R, 0);
  705. R = SLDI_UB(R, R, 1);
  706. val1 = __msa_copy_s_w((v4i32)R, 0);
  707. R = SLDI_UB(R, R, 1);
  708. val2 = __msa_copy_s_w((v4i32)R, 0);
  709. R = SLDI_UB(R, R, 1);
  710. val3 = __msa_copy_s_w((v4i32)R, 0);
  711. SW4(val0, val1, val2, val3, dst, BPS);
  712. }
  713. // 16x16
  714. static void DC16(uint8_t* dst) { // DC
  715. uint32_t dc = 16;
  716. int i;
  717. const v16u8 rtop = LD_UB(dst - BPS);
  718. const v8u16 dctop = __msa_hadd_u_h(rtop, rtop);
  719. v16u8 out;
  720. for (i = 0; i < 16; ++i) {
  721. dc += dst[-1 + i * BPS];
  722. }
  723. dc += HADD_UH_U32(dctop);
  724. out = (v16u8)__msa_fill_b(dc >> 5);
  725. ST_UB8(out, out, out, out, out, out, out, out, dst, BPS);
  726. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS);
  727. }
  728. static void TM16(uint8_t* dst) {
  729. int j;
  730. v8i16 d1, d2;
  731. const v16i8 zero = { 0 };
  732. const v8i16 TL = (v8i16)__msa_fill_h(dst[-1 - BPS]);
  733. const v16i8 T = LD_SB(dst - BPS);
  734. ILVRL_B2_SH(zero, T, d1, d2);
  735. SUB2(d1, TL, d2, TL, d1, d2);
  736. for (j = 0; j < 16; j += 4) {
  737. v16i8 t0, t1, t2, t3;
  738. v8i16 r0, r1, r2, r3, r4, r5, r6, r7;
  739. const v8i16 L0 = (v8i16)__msa_fill_h(dst[-1 + 0 * BPS]);
  740. const v8i16 L1 = (v8i16)__msa_fill_h(dst[-1 + 1 * BPS]);
  741. const v8i16 L2 = (v8i16)__msa_fill_h(dst[-1 + 2 * BPS]);
  742. const v8i16 L3 = (v8i16)__msa_fill_h(dst[-1 + 3 * BPS]);
  743. ADD4(d1, L0, d1, L1, d1, L2, d1, L3, r0, r1, r2, r3);
  744. ADD4(d2, L0, d2, L1, d2, L2, d2, L3, r4, r5, r6, r7);
  745. CLIP_SH4_0_255(r0, r1, r2, r3);
  746. CLIP_SH4_0_255(r4, r5, r6, r7);
  747. PCKEV_B4_SB(r4, r0, r5, r1, r6, r2, r7, r3, t0, t1, t2, t3);
  748. ST_SB4(t0, t1, t2, t3, dst, BPS);
  749. dst += 4 * BPS;
  750. }
  751. }
  752. static void VE16(uint8_t* dst) { // vertical
  753. const v16u8 rtop = LD_UB(dst - BPS);
  754. ST_UB8(rtop, rtop, rtop, rtop, rtop, rtop, rtop, rtop, dst, BPS);
  755. ST_UB8(rtop, rtop, rtop, rtop, rtop, rtop, rtop, rtop, dst + 8 * BPS, BPS);
  756. }
  757. static void HE16(uint8_t* dst) { // horizontal
  758. int j;
  759. for (j = 16; j > 0; j -= 4) {
  760. const v16u8 L0 = (v16u8)__msa_fill_b(dst[-1 + 0 * BPS]);
  761. const v16u8 L1 = (v16u8)__msa_fill_b(dst[-1 + 1 * BPS]);
  762. const v16u8 L2 = (v16u8)__msa_fill_b(dst[-1 + 2 * BPS]);
  763. const v16u8 L3 = (v16u8)__msa_fill_b(dst[-1 + 3 * BPS]);
  764. ST_UB4(L0, L1, L2, L3, dst, BPS);
  765. dst += 4 * BPS;
  766. }
  767. }
  768. static void DC16NoTop(uint8_t* dst) { // DC with top samples not available
  769. int j;
  770. uint32_t dc = 8;
  771. v16u8 out;
  772. for (j = 0; j < 16; ++j) {
  773. dc += dst[-1 + j * BPS];
  774. }
  775. out = (v16u8)__msa_fill_b(dc >> 4);
  776. ST_UB8(out, out, out, out, out, out, out, out, dst, BPS);
  777. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS);
  778. }
  779. static void DC16NoLeft(uint8_t* dst) { // DC with left samples not available
  780. uint32_t dc = 8;
  781. const v16u8 rtop = LD_UB(dst - BPS);
  782. const v8u16 dctop = __msa_hadd_u_h(rtop, rtop);
  783. v16u8 out;
  784. dc += HADD_UH_U32(dctop);
  785. out = (v16u8)__msa_fill_b(dc >> 4);
  786. ST_UB8(out, out, out, out, out, out, out, out, dst, BPS);
  787. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS);
  788. }
  789. static void DC16NoTopLeft(uint8_t* dst) { // DC with nothing
  790. const v16u8 out = (v16u8)__msa_fill_b(0x80);
  791. ST_UB8(out, out, out, out, out, out, out, out, dst, BPS);
  792. ST_UB8(out, out, out, out, out, out, out, out, dst + 8 * BPS, BPS);
  793. }
  794. // Chroma
  795. #define STORE8x8(out, dst) do { \
  796. SD4(out, out, out, out, dst + 0 * BPS, BPS); \
  797. SD4(out, out, out, out, dst + 4 * BPS, BPS); \
  798. } while (0)
  799. static void DC8uv(uint8_t* dst) { // DC
  800. uint32_t dc = 8;
  801. int i;
  802. uint64_t out;
  803. const v16u8 rtop = LD_UB(dst - BPS);
  804. const v8u16 temp0 = __msa_hadd_u_h(rtop, rtop);
  805. const v4u32 temp1 = __msa_hadd_u_w(temp0, temp0);
  806. const v2u64 temp2 = __msa_hadd_u_d(temp1, temp1);
  807. v16u8 dctemp;
  808. for (i = 0; i < 8; ++i) {
  809. dc += dst[-1 + i * BPS];
  810. }
  811. dc += __msa_copy_s_w((v4i32)temp2, 0);
  812. dctemp = (v16u8)__msa_fill_b(dc >> 4);
  813. out = __msa_copy_s_d((v2i64)dctemp, 0);
  814. STORE8x8(out, dst);
  815. }
  816. static void TM8uv(uint8_t* dst) {
  817. int j;
  818. const v16i8 T1 = LD_SB(dst - BPS);
  819. const v16i8 zero = { 0 };
  820. const v8i16 T = (v8i16)__msa_ilvr_b(zero, T1);
  821. const v8i16 TL = (v8i16)__msa_fill_h(dst[-1 - BPS]);
  822. const v8i16 d = T - TL;
  823. for (j = 0; j < 8; j += 4) {
  824. v16i8 t0, t1;
  825. v8i16 r0 = (v8i16)__msa_fill_h(dst[-1 + 0 * BPS]);
  826. v8i16 r1 = (v8i16)__msa_fill_h(dst[-1 + 1 * BPS]);
  827. v8i16 r2 = (v8i16)__msa_fill_h(dst[-1 + 2 * BPS]);
  828. v8i16 r3 = (v8i16)__msa_fill_h(dst[-1 + 3 * BPS]);
  829. ADD4(d, r0, d, r1, d, r2, d, r3, r0, r1, r2, r3);
  830. CLIP_SH4_0_255(r0, r1, r2, r3);
  831. PCKEV_B2_SB(r1, r0, r3, r2, t0, t1);
  832. ST4x4_UB(t0, t1, 0, 2, 0, 2, dst, BPS);
  833. ST4x4_UB(t0, t1, 1, 3, 1, 3, dst + 4, BPS);
  834. dst += 4 * BPS;
  835. }
  836. }
  837. static void VE8uv(uint8_t* dst) { // vertical
  838. const v16u8 rtop = LD_UB(dst - BPS);
  839. const uint64_t out = __msa_copy_s_d((v2i64)rtop, 0);
  840. STORE8x8(out, dst);
  841. }
  842. static void HE8uv(uint8_t* dst) { // horizontal
  843. int j;
  844. for (j = 0; j < 8; j += 4) {
  845. const v16u8 L0 = (v16u8)__msa_fill_b(dst[-1 + 0 * BPS]);
  846. const v16u8 L1 = (v16u8)__msa_fill_b(dst[-1 + 1 * BPS]);
  847. const v16u8 L2 = (v16u8)__msa_fill_b(dst[-1 + 2 * BPS]);
  848. const v16u8 L3 = (v16u8)__msa_fill_b(dst[-1 + 3 * BPS]);
  849. const uint64_t out0 = __msa_copy_s_d((v2i64)L0, 0);
  850. const uint64_t out1 = __msa_copy_s_d((v2i64)L1, 0);
  851. const uint64_t out2 = __msa_copy_s_d((v2i64)L2, 0);
  852. const uint64_t out3 = __msa_copy_s_d((v2i64)L3, 0);
  853. SD4(out0, out1, out2, out3, dst, BPS);
  854. dst += 4 * BPS;
  855. }
  856. }
  857. static void DC8uvNoLeft(uint8_t* dst) { // DC with no left samples
  858. const uint32_t dc = 4;
  859. const v16u8 rtop = LD_UB(dst - BPS);
  860. const v8u16 temp0 = __msa_hadd_u_h(rtop, rtop);
  861. const v4u32 temp1 = __msa_hadd_u_w(temp0, temp0);
  862. const v2u64 temp2 = __msa_hadd_u_d(temp1, temp1);
  863. const uint32_t sum_m = __msa_copy_s_w((v4i32)temp2, 0);
  864. const v16u8 dcval = (v16u8)__msa_fill_b((dc + sum_m) >> 3);
  865. const uint64_t out = __msa_copy_s_d((v2i64)dcval, 0);
  866. STORE8x8(out, dst);
  867. }
  868. static void DC8uvNoTop(uint8_t* dst) { // DC with no top samples
  869. uint32_t dc = 4;
  870. int i;
  871. uint64_t out;
  872. v16u8 dctemp;
  873. for (i = 0; i < 8; ++i) {
  874. dc += dst[-1 + i * BPS];
  875. }
  876. dctemp = (v16u8)__msa_fill_b(dc >> 3);
  877. out = __msa_copy_s_d((v2i64)dctemp, 0);
  878. STORE8x8(out, dst);
  879. }
  880. static void DC8uvNoTopLeft(uint8_t* dst) { // DC with nothing
  881. const uint64_t out = 0x8080808080808080ULL;
  882. STORE8x8(out, dst);
  883. }
  884. //------------------------------------------------------------------------------
  885. // Entry point
  886. extern void VP8DspInitMSA(void);
  887. WEBP_TSAN_IGNORE_FUNCTION void VP8DspInitMSA(void) {
  888. VP8TransformWHT = TransformWHT;
  889. VP8Transform = TransformTwo;
  890. VP8TransformDC = TransformDC;
  891. VP8TransformAC3 = TransformAC3;
  892. VP8VFilter16 = VFilter16;
  893. VP8HFilter16 = HFilter16;
  894. VP8VFilter16i = VFilter16i;
  895. VP8HFilter16i = HFilter16i;
  896. VP8VFilter8 = VFilter8;
  897. VP8HFilter8 = HFilter8;
  898. VP8VFilter8i = VFilter8i;
  899. VP8HFilter8i = HFilter8i;
  900. VP8SimpleVFilter16 = SimpleVFilter16;
  901. VP8SimpleHFilter16 = SimpleHFilter16;
  902. VP8SimpleVFilter16i = SimpleVFilter16i;
  903. VP8SimpleHFilter16i = SimpleHFilter16i;
  904. VP8PredLuma4[0] = DC4;
  905. VP8PredLuma4[1] = TM4;
  906. VP8PredLuma4[2] = VE4;
  907. VP8PredLuma4[4] = RD4;
  908. VP8PredLuma4[6] = LD4;
  909. VP8PredLuma16[0] = DC16;
  910. VP8PredLuma16[1] = TM16;
  911. VP8PredLuma16[2] = VE16;
  912. VP8PredLuma16[3] = HE16;
  913. VP8PredLuma16[4] = DC16NoTop;
  914. VP8PredLuma16[5] = DC16NoLeft;
  915. VP8PredLuma16[6] = DC16NoTopLeft;
  916. VP8PredChroma8[0] = DC8uv;
  917. VP8PredChroma8[1] = TM8uv;
  918. VP8PredChroma8[2] = VE8uv;
  919. VP8PredChroma8[3] = HE8uv;
  920. VP8PredChroma8[4] = DC8uvNoTop;
  921. VP8PredChroma8[5] = DC8uvNoLeft;
  922. VP8PredChroma8[6] = DC8uvNoTopLeft;
  923. }
  924. #else // !WEBP_USE_MSA
  925. WEBP_DSP_INIT_STUB(VP8DspInitMSA)
  926. #endif // WEBP_USE_MSA