convolve8_vert_dspr2.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * Copyright (c) 2013 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 <assert.h>
  11. #include <stdio.h>
  12. #include "./vpx_dsp_rtcd.h"
  13. #include "vpx_dsp/mips/convolve_common_dspr2.h"
  14. #include "vpx_dsp/vpx_dsp_common.h"
  15. #include "vpx_dsp/vpx_filter.h"
  16. #include "vpx_ports/mem.h"
  17. #if HAVE_DSPR2
  18. static void convolve_vert_4_dspr2(const uint8_t *src, int32_t src_stride,
  19. uint8_t *dst, int32_t dst_stride,
  20. const int16_t *filter_y, int32_t w,
  21. int32_t h) {
  22. int32_t x, y;
  23. const uint8_t *src_ptr;
  24. uint8_t *dst_ptr;
  25. uint8_t *cm = vpx_ff_cropTbl;
  26. uint32_t vector4a = 64;
  27. uint32_t load1, load2, load3, load4;
  28. uint32_t p1, p2;
  29. uint32_t n1, n2;
  30. uint32_t scratch1, scratch2;
  31. uint32_t store1, store2;
  32. int32_t vector1b, vector2b, vector3b, vector4b;
  33. int32_t Temp1, Temp2;
  34. vector1b = ((const int32_t *)filter_y)[0];
  35. vector2b = ((const int32_t *)filter_y)[1];
  36. vector3b = ((const int32_t *)filter_y)[2];
  37. vector4b = ((const int32_t *)filter_y)[3];
  38. src -= 3 * src_stride;
  39. for (y = h; y--;) {
  40. /* prefetch data to cache memory */
  41. prefetch_store(dst + dst_stride);
  42. for (x = 0; x < w; x += 4) {
  43. src_ptr = src + x;
  44. dst_ptr = dst + x;
  45. __asm__ __volatile__(
  46. "ulw %[load1], 0(%[src_ptr]) \n\t"
  47. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  48. "ulw %[load2], 0(%[src_ptr]) \n\t"
  49. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  50. "ulw %[load3], 0(%[src_ptr]) \n\t"
  51. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  52. "ulw %[load4], 0(%[src_ptr]) \n\t"
  53. "mtlo %[vector4a], $ac0 \n\t"
  54. "mtlo %[vector4a], $ac1 \n\t"
  55. "mtlo %[vector4a], $ac2 \n\t"
  56. "mtlo %[vector4a], $ac3 \n\t"
  57. "mthi $zero, $ac0 \n\t"
  58. "mthi $zero, $ac1 \n\t"
  59. "mthi $zero, $ac2 \n\t"
  60. "mthi $zero, $ac3 \n\t"
  61. "preceu.ph.qbr %[scratch1], %[load1] \n\t"
  62. "preceu.ph.qbr %[p1], %[load2] \n\t"
  63. "precrq.ph.w %[n1], %[p1], %[scratch1] \n\t" /* pixel 2 */
  64. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  65. "preceu.ph.qbr %[scratch2], %[load3] \n\t"
  66. "preceu.ph.qbr %[p2], %[load4] \n\t"
  67. "precrq.ph.w %[n2], %[p2], %[scratch2] \n\t" /* pixel 2 */
  68. "append %[p2], %[scratch2], 16 \n\t" /* pixel 1 */
  69. "dpa.w.ph $ac0, %[p1], %[vector1b] \n\t"
  70. "dpa.w.ph $ac0, %[p2], %[vector2b] \n\t"
  71. "dpa.w.ph $ac1, %[n1], %[vector1b] \n\t"
  72. "dpa.w.ph $ac1, %[n2], %[vector2b] \n\t"
  73. "preceu.ph.qbl %[scratch1], %[load1] \n\t"
  74. "preceu.ph.qbl %[p1], %[load2] \n\t"
  75. "precrq.ph.w %[n1], %[p1], %[scratch1] \n\t" /* pixel 2 */
  76. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  77. "preceu.ph.qbl %[scratch2], %[load3] \n\t"
  78. "preceu.ph.qbl %[p2], %[load4] \n\t"
  79. "precrq.ph.w %[n2], %[p2], %[scratch2] \n\t" /* pixel 2 */
  80. "append %[p2], %[scratch2], 16 \n\t" /* pixel 1 */
  81. "dpa.w.ph $ac2, %[p1], %[vector1b] \n\t"
  82. "dpa.w.ph $ac2, %[p2], %[vector2b] \n\t"
  83. "dpa.w.ph $ac3, %[n1], %[vector1b] \n\t"
  84. "dpa.w.ph $ac3, %[n2], %[vector2b] \n\t"
  85. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  86. "ulw %[load1], 0(%[src_ptr]) \n\t"
  87. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  88. "ulw %[load2], 0(%[src_ptr]) \n\t"
  89. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  90. "ulw %[load3], 0(%[src_ptr]) \n\t"
  91. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  92. "ulw %[load4], 0(%[src_ptr]) \n\t"
  93. "preceu.ph.qbr %[scratch1], %[load1] \n\t"
  94. "preceu.ph.qbr %[p1], %[load2] \n\t"
  95. "precrq.ph.w %[n1], %[p1], %[scratch1] \n\t" /* pixel 2 */
  96. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  97. "preceu.ph.qbr %[scratch2], %[load3] \n\t"
  98. "preceu.ph.qbr %[p2], %[load4] \n\t"
  99. "precrq.ph.w %[n2], %[p2], %[scratch2] \n\t" /* pixel 2 */
  100. "append %[p2], %[scratch2], 16 \n\t" /* pixel 1 */
  101. "dpa.w.ph $ac0, %[p1], %[vector3b] \n\t"
  102. "dpa.w.ph $ac0, %[p2], %[vector4b] \n\t"
  103. "extp %[Temp1], $ac0, 31 \n\t"
  104. "dpa.w.ph $ac1, %[n1], %[vector3b] \n\t"
  105. "dpa.w.ph $ac1, %[n2], %[vector4b] \n\t"
  106. "extp %[Temp2], $ac1, 31 \n\t"
  107. "preceu.ph.qbl %[scratch1], %[load1] \n\t"
  108. "preceu.ph.qbl %[p1], %[load2] \n\t"
  109. "precrq.ph.w %[n1], %[p1], %[scratch1] \n\t" /* pixel 2 */
  110. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  111. "preceu.ph.qbl %[scratch2], %[load3] \n\t"
  112. "preceu.ph.qbl %[p2], %[load4] \n\t"
  113. "precrq.ph.w %[n2], %[p2], %[scratch2] \n\t" /* pixel 2 */
  114. "append %[p2], %[scratch2], 16 \n\t" /* pixel 1 */
  115. "lbux %[store1], %[Temp1](%[cm]) \n\t"
  116. "dpa.w.ph $ac2, %[p1], %[vector3b] \n\t"
  117. "dpa.w.ph $ac2, %[p2], %[vector4b] \n\t"
  118. "extp %[Temp1], $ac2, 31 \n\t"
  119. "lbux %[store2], %[Temp2](%[cm]) \n\t"
  120. "dpa.w.ph $ac3, %[n1], %[vector3b] \n\t"
  121. "dpa.w.ph $ac3, %[n2], %[vector4b] \n\t"
  122. "extp %[Temp2], $ac3, 31 \n\t"
  123. "sb %[store1], 0(%[dst_ptr]) \n\t"
  124. "sb %[store2], 1(%[dst_ptr]) \n\t"
  125. "lbux %[store1], %[Temp1](%[cm]) \n\t"
  126. "lbux %[store2], %[Temp2](%[cm]) \n\t"
  127. "sb %[store1], 2(%[dst_ptr]) \n\t"
  128. "sb %[store2], 3(%[dst_ptr]) \n\t"
  129. : [load1] "=&r"(load1), [load2] "=&r"(load2), [load3] "=&r"(load3),
  130. [load4] "=&r"(load4), [p1] "=&r"(p1), [p2] "=&r"(p2),
  131. [n1] "=&r"(n1), [n2] "=&r"(n2), [scratch1] "=&r"(scratch1),
  132. [scratch2] "=&r"(scratch2), [Temp1] "=&r"(Temp1),
  133. [Temp2] "=&r"(Temp2), [store1] "=&r"(store1),
  134. [store2] "=&r"(store2), [src_ptr] "+r"(src_ptr)
  135. : [vector1b] "r"(vector1b), [vector2b] "r"(vector2b),
  136. [vector3b] "r"(vector3b), [vector4b] "r"(vector4b),
  137. [vector4a] "r"(vector4a), [src_stride] "r"(src_stride),
  138. [cm] "r"(cm), [dst_ptr] "r"(dst_ptr));
  139. }
  140. /* Next row... */
  141. src += src_stride;
  142. dst += dst_stride;
  143. }
  144. }
  145. static void convolve_vert_64_dspr2(const uint8_t *src, int32_t src_stride,
  146. uint8_t *dst, int32_t dst_stride,
  147. const int16_t *filter_y, int32_t h) {
  148. int32_t x, y;
  149. const uint8_t *src_ptr;
  150. uint8_t *dst_ptr;
  151. uint8_t *cm = vpx_ff_cropTbl;
  152. uint32_t vector4a = 64;
  153. uint32_t load1, load2, load3, load4;
  154. uint32_t p1, p2;
  155. uint32_t n1, n2;
  156. uint32_t scratch1, scratch2;
  157. uint32_t store1, store2;
  158. int32_t vector1b, vector2b, vector3b, vector4b;
  159. int32_t Temp1, Temp2;
  160. vector1b = ((const int32_t *)filter_y)[0];
  161. vector2b = ((const int32_t *)filter_y)[1];
  162. vector3b = ((const int32_t *)filter_y)[2];
  163. vector4b = ((const int32_t *)filter_y)[3];
  164. src -= 3 * src_stride;
  165. for (y = h; y--;) {
  166. /* prefetch data to cache memory */
  167. prefetch_store(dst + dst_stride);
  168. prefetch_store(dst + dst_stride + 32);
  169. for (x = 0; x < 64; x += 4) {
  170. src_ptr = src + x;
  171. dst_ptr = dst + x;
  172. __asm__ __volatile__(
  173. "ulw %[load1], 0(%[src_ptr]) \n\t"
  174. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  175. "ulw %[load2], 0(%[src_ptr]) \n\t"
  176. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  177. "ulw %[load3], 0(%[src_ptr]) \n\t"
  178. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  179. "ulw %[load4], 0(%[src_ptr]) \n\t"
  180. "mtlo %[vector4a], $ac0 \n\t"
  181. "mtlo %[vector4a], $ac1 \n\t"
  182. "mtlo %[vector4a], $ac2 \n\t"
  183. "mtlo %[vector4a], $ac3 \n\t"
  184. "mthi $zero, $ac0 \n\t"
  185. "mthi $zero, $ac1 \n\t"
  186. "mthi $zero, $ac2 \n\t"
  187. "mthi $zero, $ac3 \n\t"
  188. "preceu.ph.qbr %[scratch1], %[load1] \n\t"
  189. "preceu.ph.qbr %[p1], %[load2] \n\t"
  190. "precrq.ph.w %[n1], %[p1], %[scratch1] \n\t" /* pixel 2 */
  191. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  192. "preceu.ph.qbr %[scratch2], %[load3] \n\t"
  193. "preceu.ph.qbr %[p2], %[load4] \n\t"
  194. "precrq.ph.w %[n2], %[p2], %[scratch2] \n\t" /* pixel 2 */
  195. "append %[p2], %[scratch2], 16 \n\t" /* pixel 1 */
  196. "dpa.w.ph $ac0, %[p1], %[vector1b] \n\t"
  197. "dpa.w.ph $ac0, %[p2], %[vector2b] \n\t"
  198. "dpa.w.ph $ac1, %[n1], %[vector1b] \n\t"
  199. "dpa.w.ph $ac1, %[n2], %[vector2b] \n\t"
  200. "preceu.ph.qbl %[scratch1], %[load1] \n\t"
  201. "preceu.ph.qbl %[p1], %[load2] \n\t"
  202. "precrq.ph.w %[n1], %[p1], %[scratch1] \n\t" /* pixel 2 */
  203. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  204. "preceu.ph.qbl %[scratch2], %[load3] \n\t"
  205. "preceu.ph.qbl %[p2], %[load4] \n\t"
  206. "precrq.ph.w %[n2], %[p2], %[scratch2] \n\t" /* pixel 2 */
  207. "append %[p2], %[scratch2], 16 \n\t" /* pixel 1 */
  208. "dpa.w.ph $ac2, %[p1], %[vector1b] \n\t"
  209. "dpa.w.ph $ac2, %[p2], %[vector2b] \n\t"
  210. "dpa.w.ph $ac3, %[n1], %[vector1b] \n\t"
  211. "dpa.w.ph $ac3, %[n2], %[vector2b] \n\t"
  212. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  213. "ulw %[load1], 0(%[src_ptr]) \n\t"
  214. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  215. "ulw %[load2], 0(%[src_ptr]) \n\t"
  216. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  217. "ulw %[load3], 0(%[src_ptr]) \n\t"
  218. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  219. "ulw %[load4], 0(%[src_ptr]) \n\t"
  220. "preceu.ph.qbr %[scratch1], %[load1] \n\t"
  221. "preceu.ph.qbr %[p1], %[load2] \n\t"
  222. "precrq.ph.w %[n1], %[p1], %[scratch1] \n\t" /* pixel 2 */
  223. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  224. "preceu.ph.qbr %[scratch2], %[load3] \n\t"
  225. "preceu.ph.qbr %[p2], %[load4] \n\t"
  226. "precrq.ph.w %[n2], %[p2], %[scratch2] \n\t" /* pixel 2 */
  227. "append %[p2], %[scratch2], 16 \n\t" /* pixel 1 */
  228. "dpa.w.ph $ac0, %[p1], %[vector3b] \n\t"
  229. "dpa.w.ph $ac0, %[p2], %[vector4b] \n\t"
  230. "extp %[Temp1], $ac0, 31 \n\t"
  231. "dpa.w.ph $ac1, %[n1], %[vector3b] \n\t"
  232. "dpa.w.ph $ac1, %[n2], %[vector4b] \n\t"
  233. "extp %[Temp2], $ac1, 31 \n\t"
  234. "preceu.ph.qbl %[scratch1], %[load1] \n\t"
  235. "preceu.ph.qbl %[p1], %[load2] \n\t"
  236. "precrq.ph.w %[n1], %[p1], %[scratch1] \n\t" /* pixel 2 */
  237. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  238. "preceu.ph.qbl %[scratch2], %[load3] \n\t"
  239. "preceu.ph.qbl %[p2], %[load4] \n\t"
  240. "precrq.ph.w %[n2], %[p2], %[scratch2] \n\t" /* pixel 2 */
  241. "append %[p2], %[scratch2], 16 \n\t" /* pixel 1 */
  242. "lbux %[store1], %[Temp1](%[cm]) \n\t"
  243. "dpa.w.ph $ac2, %[p1], %[vector3b] \n\t"
  244. "dpa.w.ph $ac2, %[p2], %[vector4b] \n\t"
  245. "extp %[Temp1], $ac2, 31 \n\t"
  246. "lbux %[store2], %[Temp2](%[cm]) \n\t"
  247. "dpa.w.ph $ac3, %[n1], %[vector3b] \n\t"
  248. "dpa.w.ph $ac3, %[n2], %[vector4b] \n\t"
  249. "extp %[Temp2], $ac3, 31 \n\t"
  250. "sb %[store1], 0(%[dst_ptr]) \n\t"
  251. "sb %[store2], 1(%[dst_ptr]) \n\t"
  252. "lbux %[store1], %[Temp1](%[cm]) \n\t"
  253. "lbux %[store2], %[Temp2](%[cm]) \n\t"
  254. "sb %[store1], 2(%[dst_ptr]) \n\t"
  255. "sb %[store2], 3(%[dst_ptr]) \n\t"
  256. : [load1] "=&r"(load1), [load2] "=&r"(load2), [load3] "=&r"(load3),
  257. [load4] "=&r"(load4), [p1] "=&r"(p1), [p2] "=&r"(p2),
  258. [n1] "=&r"(n1), [n2] "=&r"(n2), [scratch1] "=&r"(scratch1),
  259. [scratch2] "=&r"(scratch2), [Temp1] "=&r"(Temp1),
  260. [Temp2] "=&r"(Temp2), [store1] "=&r"(store1),
  261. [store2] "=&r"(store2), [src_ptr] "+r"(src_ptr)
  262. : [vector1b] "r"(vector1b), [vector2b] "r"(vector2b),
  263. [vector3b] "r"(vector3b), [vector4b] "r"(vector4b),
  264. [vector4a] "r"(vector4a), [src_stride] "r"(src_stride),
  265. [cm] "r"(cm), [dst_ptr] "r"(dst_ptr));
  266. }
  267. /* Next row... */
  268. src += src_stride;
  269. dst += dst_stride;
  270. }
  271. }
  272. void vpx_convolve8_vert_dspr2(const uint8_t *src, ptrdiff_t src_stride,
  273. uint8_t *dst, ptrdiff_t dst_stride,
  274. const InterpKernel *filter, int x0_q4,
  275. int x_step_q4, int y0_q4, int y_step_q4, int w,
  276. int h) {
  277. const int16_t *const filter_y = filter[y0_q4];
  278. assert(y_step_q4 == 16);
  279. assert(((const int32_t *)filter_y)[1] != 0x800000);
  280. if (vpx_get_filter_taps(filter_y) == 2) {
  281. vpx_convolve2_vert_dspr2(src, src_stride, dst, dst_stride, filter, x0_q4,
  282. x_step_q4, y0_q4, y_step_q4, w, h);
  283. } else {
  284. uint32_t pos = 38;
  285. /* bit positon for extract from acc */
  286. __asm__ __volatile__("wrdsp %[pos], 1 \n\t"
  287. :
  288. : [pos] "r"(pos));
  289. prefetch_store(dst);
  290. switch (w) {
  291. case 4:
  292. case 8:
  293. case 16:
  294. case 32:
  295. convolve_vert_4_dspr2(src, src_stride, dst, dst_stride, filter_y, w, h);
  296. break;
  297. case 64:
  298. prefetch_store(dst + 32);
  299. convolve_vert_64_dspr2(src, src_stride, dst, dst_stride, filter_y, h);
  300. break;
  301. default:
  302. vpx_convolve8_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4,
  303. x_step_q4, y0_q4, y_step_q4, w, h);
  304. break;
  305. }
  306. }
  307. }
  308. #endif