itrans4_dspr2.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /*
  2. * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "./vpx_config.h"
  11. #include "./vpx_dsp_rtcd.h"
  12. #include "vpx_dsp/mips/inv_txfm_dspr2.h"
  13. #include "vpx_dsp/txfm_common.h"
  14. #if HAVE_DSPR2
  15. void vpx_idct4_rows_dspr2(const int16_t *input, int16_t *output) {
  16. int step_0, step_1, step_2, step_3;
  17. int Temp0, Temp1, Temp2, Temp3;
  18. const int const_2_power_13 = 8192;
  19. int i;
  20. for (i = 4; i--;) {
  21. __asm__ __volatile__(
  22. /*
  23. temp_1 = (input[0] + input[2]) * cospi_16_64;
  24. step_0 = dct_const_round_shift(temp_1);
  25. temp_2 = (input[0] - input[2]) * cospi_16_64;
  26. step_1 = dct_const_round_shift(temp_2);
  27. */
  28. "lh %[Temp0], 0(%[input]) \n\t"
  29. "lh %[Temp1], 4(%[input]) \n\t"
  30. "mtlo %[const_2_power_13], $ac0 \n\t"
  31. "mthi $zero, $ac0 \n\t"
  32. "mtlo %[const_2_power_13], $ac1 \n\t"
  33. "mthi $zero, $ac1 \n\t"
  34. "add %[Temp2], %[Temp0], %[Temp1] \n\t"
  35. "sub %[Temp3], %[Temp0], %[Temp1] \n\t"
  36. "madd $ac0, %[Temp2], %[cospi_16_64] \n\t"
  37. "lh %[Temp0], 2(%[input]) \n\t"
  38. "lh %[Temp1], 6(%[input]) \n\t"
  39. "extp %[step_0], $ac0, 31 \n\t"
  40. "mtlo %[const_2_power_13], $ac0 \n\t"
  41. "mthi $zero, $ac0 \n\t"
  42. "madd $ac1, %[Temp3], %[cospi_16_64] \n\t"
  43. "extp %[step_1], $ac1, 31 \n\t"
  44. "mtlo %[const_2_power_13], $ac1 \n\t"
  45. "mthi $zero, $ac1 \n\t"
  46. /*
  47. temp1 = input[1] * cospi_24_64 - input[3] * cospi_8_64;
  48. step_2 = dct_const_round_shift(temp1);
  49. */
  50. "madd $ac0, %[Temp0], %[cospi_24_64] \n\t"
  51. "msub $ac0, %[Temp1], %[cospi_8_64] \n\t"
  52. "extp %[step_2], $ac0, 31 \n\t"
  53. /*
  54. temp2 = input[1] * cospi_8_64 + input[3] * cospi_24_64;
  55. step_3 = dct_const_round_shift(temp2);
  56. */
  57. "madd $ac1, %[Temp0], %[cospi_8_64] \n\t"
  58. "madd $ac1, %[Temp1], %[cospi_24_64] \n\t"
  59. "extp %[step_3], $ac1, 31 \n\t"
  60. /*
  61. output[0] = step_0 + step_3;
  62. output[4] = step_1 + step_2;
  63. output[8] = step_1 - step_2;
  64. output[12] = step_0 - step_3;
  65. */
  66. "add %[Temp0], %[step_0], %[step_3] \n\t"
  67. "sh %[Temp0], 0(%[output]) \n\t"
  68. "add %[Temp1], %[step_1], %[step_2] \n\t"
  69. "sh %[Temp1], 8(%[output]) \n\t"
  70. "sub %[Temp2], %[step_1], %[step_2] \n\t"
  71. "sh %[Temp2], 16(%[output]) \n\t"
  72. "sub %[Temp3], %[step_0], %[step_3] \n\t"
  73. "sh %[Temp3], 24(%[output]) \n\t"
  74. : [Temp0] "=&r"(Temp0), [Temp1] "=&r"(Temp1), [Temp2] "=&r"(Temp2),
  75. [Temp3] "=&r"(Temp3), [step_0] "=&r"(step_0), [step_1] "=&r"(step_1),
  76. [step_2] "=&r"(step_2), [step_3] "=&r"(step_3), [output] "+r"(output)
  77. : [const_2_power_13] "r"(const_2_power_13),
  78. [cospi_8_64] "r"(cospi_8_64), [cospi_16_64] "r"(cospi_16_64),
  79. [cospi_24_64] "r"(cospi_24_64), [input] "r"(input));
  80. input += 4;
  81. output += 1;
  82. }
  83. }
  84. void vpx_idct4_columns_add_blk_dspr2(int16_t *input, uint8_t *dest,
  85. int stride) {
  86. int step_0, step_1, step_2, step_3;
  87. int Temp0, Temp1, Temp2, Temp3;
  88. const int const_2_power_13 = 8192;
  89. const int const_255 = 255;
  90. int i;
  91. uint8_t *dest_pix;
  92. for (i = 0; i < 4; ++i) {
  93. dest_pix = (dest + i);
  94. __asm__ __volatile__(
  95. /*
  96. temp_1 = (input[0] + input[2]) * cospi_16_64;
  97. step_0 = dct_const_round_shift(temp_1);
  98. temp_2 = (input[0] - input[2]) * cospi_16_64;
  99. step_1 = dct_const_round_shift(temp_2);
  100. */
  101. "lh %[Temp0], 0(%[input]) \n\t"
  102. "lh %[Temp1], 4(%[input]) \n\t"
  103. "mtlo %[const_2_power_13], $ac0 \n\t"
  104. "mthi $zero, $ac0 \n\t"
  105. "mtlo %[const_2_power_13], $ac1 \n\t"
  106. "mthi $zero, $ac1 \n\t"
  107. "add %[Temp2], %[Temp0], %[Temp1] \n\t"
  108. "sub %[Temp3], %[Temp0], %[Temp1] \n\t"
  109. "madd $ac0, %[Temp2], %[cospi_16_64] \n\t"
  110. "lh %[Temp0], 2(%[input]) \n\t"
  111. "lh %[Temp1], 6(%[input]) \n\t"
  112. "extp %[step_0], $ac0, 31 \n\t"
  113. "mtlo %[const_2_power_13], $ac0 \n\t"
  114. "mthi $zero, $ac0 \n\t"
  115. "madd $ac1, %[Temp3], %[cospi_16_64] \n\t"
  116. "extp %[step_1], $ac1, 31 \n\t"
  117. "mtlo %[const_2_power_13], $ac1 \n\t"
  118. "mthi $zero, $ac1 \n\t"
  119. /*
  120. temp1 = input[1] * cospi_24_64 - input[3] * cospi_8_64;
  121. step_2 = dct_const_round_shift(temp1);
  122. */
  123. "madd $ac0, %[Temp0], %[cospi_24_64] \n\t"
  124. "msub $ac0, %[Temp1], %[cospi_8_64] \n\t"
  125. "extp %[step_2], $ac0, 31 \n\t"
  126. /*
  127. temp2 = input[1] * cospi_8_64 + input[3] * cospi_24_64;
  128. step_3 = dct_const_round_shift(temp2);
  129. */
  130. "madd $ac1, %[Temp0], %[cospi_8_64] \n\t"
  131. "madd $ac1, %[Temp1], %[cospi_24_64] \n\t"
  132. "extp %[step_3], $ac1, 31 \n\t"
  133. /*
  134. output[0] = step_0 + step_3;
  135. output[4] = step_1 + step_2;
  136. output[8] = step_1 - step_2;
  137. output[12] = step_0 - step_3;
  138. */
  139. "add %[Temp0], %[step_0], %[step_3] \n\t"
  140. "addi %[Temp0], %[Temp0], 8 \n\t"
  141. "sra %[Temp0], %[Temp0], 4 \n\t"
  142. "lbu %[Temp1], 0(%[dest_pix]) \n\t"
  143. "add %[Temp1], %[Temp1], %[Temp0] \n\t"
  144. "slt %[Temp2], %[Temp1], %[const_255] \n\t"
  145. "slt %[Temp3], $zero, %[Temp1] \n\t"
  146. "movz %[Temp1], %[const_255], %[Temp2] \n\t"
  147. "movz %[Temp1], $zero, %[Temp3] \n\t"
  148. "sb %[Temp1], 0(%[dest_pix]) \n\t"
  149. "addu %[dest_pix], %[dest_pix], %[stride] \n\t"
  150. "add %[Temp0], %[step_1], %[step_2] \n\t"
  151. "addi %[Temp0], %[Temp0], 8 \n\t"
  152. "sra %[Temp0], %[Temp0], 4 \n\t"
  153. "lbu %[Temp1], 0(%[dest_pix]) \n\t"
  154. "add %[Temp1], %[Temp1], %[Temp0] \n\t"
  155. "slt %[Temp2], %[Temp1], %[const_255] \n\t"
  156. "slt %[Temp3], $zero, %[Temp1] \n\t"
  157. "movz %[Temp1], %[const_255], %[Temp2] \n\t"
  158. "movz %[Temp1], $zero, %[Temp3] \n\t"
  159. "sb %[Temp1], 0(%[dest_pix]) \n\t"
  160. "addu %[dest_pix], %[dest_pix], %[stride] \n\t"
  161. "sub %[Temp0], %[step_1], %[step_2] \n\t"
  162. "addi %[Temp0], %[Temp0], 8 \n\t"
  163. "sra %[Temp0], %[Temp0], 4 \n\t"
  164. "lbu %[Temp1], 0(%[dest_pix]) \n\t"
  165. "add %[Temp1], %[Temp1], %[Temp0] \n\t"
  166. "slt %[Temp2], %[Temp1], %[const_255] \n\t"
  167. "slt %[Temp3], $zero, %[Temp1] \n\t"
  168. "movz %[Temp1], %[const_255], %[Temp2] \n\t"
  169. "movz %[Temp1], $zero, %[Temp3] \n\t"
  170. "sb %[Temp1], 0(%[dest_pix]) \n\t"
  171. "addu %[dest_pix], %[dest_pix], %[stride] \n\t"
  172. "sub %[Temp0], %[step_0], %[step_3] \n\t"
  173. "addi %[Temp0], %[Temp0], 8 \n\t"
  174. "sra %[Temp0], %[Temp0], 4 \n\t"
  175. "lbu %[Temp1], 0(%[dest_pix]) \n\t"
  176. "add %[Temp1], %[Temp1], %[Temp0] \n\t"
  177. "slt %[Temp2], %[Temp1], %[const_255] \n\t"
  178. "slt %[Temp3], $zero, %[Temp1] \n\t"
  179. "movz %[Temp1], %[const_255], %[Temp2] \n\t"
  180. "movz %[Temp1], $zero, %[Temp3] \n\t"
  181. "sb %[Temp1], 0(%[dest_pix]) \n\t"
  182. : [Temp0] "=&r"(Temp0), [Temp1] "=&r"(Temp1), [Temp2] "=&r"(Temp2),
  183. [Temp3] "=&r"(Temp3), [step_0] "=&r"(step_0), [step_1] "=&r"(step_1),
  184. [step_2] "=&r"(step_2), [step_3] "=&r"(step_3),
  185. [dest_pix] "+r"(dest_pix)
  186. : [const_2_power_13] "r"(const_2_power_13), [const_255] "r"(const_255),
  187. [cospi_8_64] "r"(cospi_8_64), [cospi_16_64] "r"(cospi_16_64),
  188. [cospi_24_64] "r"(cospi_24_64), [input] "r"(input),
  189. [stride] "r"(stride));
  190. input += 4;
  191. }
  192. }
  193. void vpx_idct4x4_16_add_dspr2(const int16_t *input, uint8_t *dest, int stride) {
  194. DECLARE_ALIGNED(32, int16_t, out[4 * 4]);
  195. int16_t *outptr = out;
  196. uint32_t pos = 45;
  197. /* bit positon for extract from acc */
  198. __asm__ __volatile__("wrdsp %[pos], 1 \n\t"
  199. :
  200. : [pos] "r"(pos));
  201. // Rows
  202. vpx_idct4_rows_dspr2(input, outptr);
  203. // Columns
  204. vpx_idct4_columns_add_blk_dspr2(&out[0], dest, stride);
  205. }
  206. void vpx_idct4x4_1_add_dspr2(const int16_t *input, uint8_t *dest, int stride) {
  207. int a1, absa1;
  208. int r;
  209. int32_t out;
  210. int t2, vector_a1, vector_a;
  211. uint32_t pos = 45;
  212. int16_t input_dc = input[0];
  213. /* bit positon for extract from acc */
  214. __asm__ __volatile__("wrdsp %[pos], 1 \n\t"
  215. :
  216. : [pos] "r"(pos));
  217. out = DCT_CONST_ROUND_SHIFT_TWICE_COSPI_16_64(input_dc);
  218. __asm__ __volatile__(
  219. "addi %[out], %[out], 8 \n\t"
  220. "sra %[a1], %[out], 4 \n\t"
  221. : [out] "+r"(out), [a1] "=r"(a1)
  222. :);
  223. if (a1 < 0) {
  224. /* use quad-byte
  225. * input and output memory are four byte aligned */
  226. __asm__ __volatile__(
  227. "abs %[absa1], %[a1] \n\t"
  228. "replv.qb %[vector_a1], %[absa1] \n\t"
  229. : [absa1] "=r"(absa1), [vector_a1] "=r"(vector_a1)
  230. : [a1] "r"(a1));
  231. for (r = 4; r--;) {
  232. __asm__ __volatile__(
  233. "lw %[t2], 0(%[dest]) \n\t"
  234. "subu_s.qb %[vector_a], %[t2], %[vector_a1] \n\t"
  235. "sw %[vector_a], 0(%[dest]) \n\t"
  236. "add %[dest], %[dest], %[stride] \n\t"
  237. : [t2] "=&r"(t2), [vector_a] "=&r"(vector_a), [dest] "+&r"(dest)
  238. : [stride] "r"(stride), [vector_a1] "r"(vector_a1));
  239. }
  240. } else if (a1 > 255) {
  241. int32_t a11, a12, vector_a11, vector_a12;
  242. /* use quad-byte
  243. * input and output memory are four byte aligned */
  244. a11 = a1 >> 3;
  245. a12 = a1 - (a11 * 7);
  246. __asm__ __volatile__(
  247. "replv.qb %[vector_a11], %[a11] \n\t"
  248. "replv.qb %[vector_a12], %[a12] \n\t"
  249. : [vector_a11] "=&r"(vector_a11), [vector_a12] "=&r"(vector_a12)
  250. : [a11] "r"(a11), [a12] "r"(a12));
  251. for (r = 4; r--;) {
  252. __asm__ __volatile__(
  253. "lw %[t2], 4(%[dest]) \n\t"
  254. "addu_s.qb %[vector_a], %[t2], %[vector_a11] \n\t"
  255. "addu_s.qb %[vector_a], %[vector_a], %[vector_a11] \n\t"
  256. "addu_s.qb %[vector_a], %[vector_a], %[vector_a11] \n\t"
  257. "addu_s.qb %[vector_a], %[vector_a], %[vector_a11] \n\t"
  258. "addu_s.qb %[vector_a], %[vector_a], %[vector_a11] \n\t"
  259. "addu_s.qb %[vector_a], %[vector_a], %[vector_a11] \n\t"
  260. "addu_s.qb %[vector_a], %[vector_a], %[vector_a11] \n\t"
  261. "addu_s.qb %[vector_a], %[vector_a], %[vector_a12] \n\t"
  262. "sw %[vector_a], 0(%[dest]) \n\t"
  263. "add %[dest], %[dest], %[stride] \n\t"
  264. : [t2] "=&r"(t2), [vector_a] "=&r"(vector_a), [dest] "+&r"(dest)
  265. : [stride] "r"(stride), [vector_a11] "r"(vector_a11),
  266. [vector_a12] "r"(vector_a12));
  267. }
  268. } else {
  269. /* use quad-byte
  270. * input and output memory are four byte aligned */
  271. __asm__ __volatile__("replv.qb %[vector_a1], %[a1] \n\t"
  272. : [vector_a1] "=r"(vector_a1)
  273. : [a1] "r"(a1));
  274. for (r = 4; r--;) {
  275. __asm__ __volatile__(
  276. "lw %[t2], 0(%[dest]) \n\t"
  277. "addu_s.qb %[vector_a], %[t2], %[vector_a1] \n\t"
  278. "sw %[vector_a], 0(%[dest]) \n\t"
  279. "add %[dest], %[dest], %[stride] \n\t"
  280. : [t2] "=&r"(t2), [vector_a] "=&r"(vector_a), [dest] "+&r"(dest)
  281. : [stride] "r"(stride), [vector_a1] "r"(vector_a1));
  282. }
  283. }
  284. }
  285. void iadst4_dspr2(const int16_t *input, int16_t *output) {
  286. int s0, s1, s2, s3, s4, s5, s6, s7;
  287. int x0, x1, x2, x3;
  288. x0 = input[0];
  289. x1 = input[1];
  290. x2 = input[2];
  291. x3 = input[3];
  292. if (!(x0 | x1 | x2 | x3)) {
  293. output[0] = output[1] = output[2] = output[3] = 0;
  294. return;
  295. }
  296. // 32-bit result is enough for the following multiplications.
  297. s0 = sinpi_1_9 * x0;
  298. s1 = sinpi_2_9 * x0;
  299. s2 = sinpi_3_9 * x1;
  300. s3 = sinpi_4_9 * x2;
  301. s4 = sinpi_1_9 * x2;
  302. s5 = sinpi_2_9 * x3;
  303. s6 = sinpi_4_9 * x3;
  304. s7 = x0 - x2 + x3;
  305. x0 = s0 + s3 + s5;
  306. x1 = s1 - s4 - s6;
  307. x2 = sinpi_3_9 * s7;
  308. x3 = s2;
  309. s0 = x0 + x3;
  310. s1 = x1 + x3;
  311. s2 = x2;
  312. s3 = x0 + x1 - x3;
  313. // 1-D transform scaling factor is sqrt(2).
  314. // The overall dynamic range is 14b (input) + 14b (multiplication scaling)
  315. // + 1b (addition) = 29b.
  316. // Hence the output bit depth is 15b.
  317. output[0] = dct_const_round_shift(s0);
  318. output[1] = dct_const_round_shift(s1);
  319. output[2] = dct_const_round_shift(s2);
  320. output[3] = dct_const_round_shift(s3);
  321. }
  322. #endif // #if HAVE_DSPR2