convolve2_avg_dspr2.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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_convolve.h"
  15. #include "vpx_dsp/vpx_dsp_common.h"
  16. #include "vpx_ports/mem.h"
  17. #if HAVE_DSPR2
  18. static void convolve_bi_avg_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;
  28. uint32_t p1, p2;
  29. uint32_t scratch1, scratch2;
  30. uint32_t store1, store2;
  31. int32_t Temp1, Temp2;
  32. const int16_t *filter = &filter_y[3];
  33. uint32_t filter45;
  34. filter45 = ((const int32_t *)filter)[0];
  35. for (y = h; y--;) {
  36. /* prefetch data to cache memory */
  37. prefetch_store(dst + dst_stride);
  38. for (x = 0; x < w; x += 4) {
  39. src_ptr = src + x;
  40. dst_ptr = dst + x;
  41. __asm__ __volatile__(
  42. "ulw %[load1], 0(%[src_ptr]) \n\t"
  43. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  44. "ulw %[load2], 0(%[src_ptr]) \n\t"
  45. "mtlo %[vector4a], $ac0 \n\t"
  46. "mtlo %[vector4a], $ac1 \n\t"
  47. "mtlo %[vector4a], $ac2 \n\t"
  48. "mtlo %[vector4a], $ac3 \n\t"
  49. "mthi $zero, $ac0 \n\t"
  50. "mthi $zero, $ac1 \n\t"
  51. "mthi $zero, $ac2 \n\t"
  52. "mthi $zero, $ac3 \n\t"
  53. "preceu.ph.qbr %[scratch1], %[load1] \n\t"
  54. "preceu.ph.qbr %[p1], %[load2] \n\t"
  55. "precrq.ph.w %[p2], %[p1], %[scratch1] \n\t" /* pixel 2 */
  56. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  57. "dpa.w.ph $ac0, %[p1], %[filter45] \n\t"
  58. "dpa.w.ph $ac1, %[p2], %[filter45] \n\t"
  59. "preceu.ph.qbl %[scratch1], %[load1] \n\t"
  60. "preceu.ph.qbl %[p1], %[load2] \n\t"
  61. "precrq.ph.w %[p2], %[p1], %[scratch1] \n\t" /* pixel 2 */
  62. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  63. "dpa.w.ph $ac2, %[p1], %[filter45] \n\t"
  64. "dpa.w.ph $ac3, %[p2], %[filter45] \n\t"
  65. "extp %[Temp1], $ac0, 31 \n\t"
  66. "extp %[Temp2], $ac1, 31 \n\t"
  67. "lbu %[scratch1], 0(%[dst_ptr]) \n\t"
  68. "lbu %[scratch2], 1(%[dst_ptr]) \n\t"
  69. "lbux %[store1], %[Temp1](%[cm]) \n\t"
  70. "addqh_r.w %[store1], %[store1], %[scratch1] \n\t" /* pixel 1 */
  71. "extp %[Temp1], $ac2, 31 \n\t"
  72. "lbux %[store2], %[Temp2](%[cm]) \n\t"
  73. "addqh_r.w %[store2], %[store2], %[scratch2] \n\t" /* pixel 2 */
  74. "extp %[Temp2], $ac3, 31 \n\t"
  75. "lbu %[scratch1], 2(%[dst_ptr]) \n\t"
  76. "sb %[store1], 0(%[dst_ptr]) \n\t"
  77. "sb %[store2], 1(%[dst_ptr]) \n\t"
  78. "lbu %[scratch2], 3(%[dst_ptr]) \n\t"
  79. "lbux %[store1], %[Temp1](%[cm]) \n\t"
  80. "lbux %[store2], %[Temp2](%[cm]) \n\t"
  81. "addqh_r.w %[store1], %[store1], %[scratch1] \n\t" /* pixel 3 */
  82. "addqh_r.w %[store2], %[store2], %[scratch2] \n\t" /* pixel 4 */
  83. "sb %[store1], 2(%[dst_ptr]) \n\t"
  84. "sb %[store2], 3(%[dst_ptr]) \n\t"
  85. : [load1] "=&r"(load1), [load2] "=&r"(load2), [p1] "=&r"(p1),
  86. [p2] "=&r"(p2), [scratch1] "=&r"(scratch1),
  87. [scratch2] "=&r"(scratch2), [Temp1] "=&r"(Temp1),
  88. [Temp2] "=&r"(Temp2), [store1] "=&r"(store1),
  89. [store2] "=&r"(store2), [src_ptr] "+r"(src_ptr)
  90. : [filter45] "r"(filter45), [vector4a] "r"(vector4a),
  91. [src_stride] "r"(src_stride), [cm] "r"(cm), [dst_ptr] "r"(dst_ptr));
  92. }
  93. /* Next row... */
  94. src += src_stride;
  95. dst += dst_stride;
  96. }
  97. }
  98. static void convolve_bi_avg_vert_64_dspr2(const uint8_t *src,
  99. int32_t src_stride, uint8_t *dst,
  100. int32_t dst_stride,
  101. const int16_t *filter_y, int32_t h) {
  102. int32_t x, y;
  103. const uint8_t *src_ptr;
  104. uint8_t *dst_ptr;
  105. uint8_t *cm = vpx_ff_cropTbl;
  106. uint32_t vector4a = 64;
  107. uint32_t load1, load2;
  108. uint32_t p1, p2;
  109. uint32_t scratch1, scratch2;
  110. uint32_t store1, store2;
  111. int32_t Temp1, Temp2;
  112. const int16_t *filter = &filter_y[3];
  113. uint32_t filter45;
  114. filter45 = ((const int32_t *)filter)[0];
  115. for (y = h; y--;) {
  116. /* prefetch data to cache memory */
  117. prefetch_store(dst + dst_stride);
  118. prefetch_store(dst + dst_stride + 32);
  119. for (x = 0; x < 64; x += 4) {
  120. src_ptr = src + x;
  121. dst_ptr = dst + x;
  122. __asm__ __volatile__(
  123. "ulw %[load1], 0(%[src_ptr]) \n\t"
  124. "add %[src_ptr], %[src_ptr], %[src_stride] \n\t"
  125. "ulw %[load2], 0(%[src_ptr]) \n\t"
  126. "mtlo %[vector4a], $ac0 \n\t"
  127. "mtlo %[vector4a], $ac1 \n\t"
  128. "mtlo %[vector4a], $ac2 \n\t"
  129. "mtlo %[vector4a], $ac3 \n\t"
  130. "mthi $zero, $ac0 \n\t"
  131. "mthi $zero, $ac1 \n\t"
  132. "mthi $zero, $ac2 \n\t"
  133. "mthi $zero, $ac3 \n\t"
  134. "preceu.ph.qbr %[scratch1], %[load1] \n\t"
  135. "preceu.ph.qbr %[p1], %[load2] \n\t"
  136. "precrq.ph.w %[p2], %[p1], %[scratch1] \n\t" /* pixel 2 */
  137. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  138. "dpa.w.ph $ac0, %[p1], %[filter45] \n\t"
  139. "dpa.w.ph $ac1, %[p2], %[filter45] \n\t"
  140. "preceu.ph.qbl %[scratch1], %[load1] \n\t"
  141. "preceu.ph.qbl %[p1], %[load2] \n\t"
  142. "precrq.ph.w %[p2], %[p1], %[scratch1] \n\t" /* pixel 2 */
  143. "append %[p1], %[scratch1], 16 \n\t" /* pixel 1 */
  144. "dpa.w.ph $ac2, %[p1], %[filter45] \n\t"
  145. "dpa.w.ph $ac3, %[p2], %[filter45] \n\t"
  146. "extp %[Temp1], $ac0, 31 \n\t"
  147. "extp %[Temp2], $ac1, 31 \n\t"
  148. "lbu %[scratch1], 0(%[dst_ptr]) \n\t"
  149. "lbu %[scratch2], 1(%[dst_ptr]) \n\t"
  150. "lbux %[store1], %[Temp1](%[cm]) \n\t"
  151. "addqh_r.w %[store1], %[store1], %[scratch1] \n\t" /* pixel 1 */
  152. "extp %[Temp1], $ac2, 31 \n\t"
  153. "lbux %[store2], %[Temp2](%[cm]) \n\t"
  154. "addqh_r.w %[store2], %[store2], %[scratch2] \n\t" /* pixel 2 */
  155. "extp %[Temp2], $ac3, 31 \n\t"
  156. "lbu %[scratch1], 2(%[dst_ptr]) \n\t"
  157. "sb %[store1], 0(%[dst_ptr]) \n\t"
  158. "sb %[store2], 1(%[dst_ptr]) \n\t"
  159. "lbu %[scratch2], 3(%[dst_ptr]) \n\t"
  160. "lbux %[store1], %[Temp1](%[cm]) \n\t"
  161. "lbux %[store2], %[Temp2](%[cm]) \n\t"
  162. "addqh_r.w %[store1], %[store1], %[scratch1] \n\t" /* pixel 3 */
  163. "addqh_r.w %[store2], %[store2], %[scratch2] \n\t" /* pixel 4 */
  164. "sb %[store1], 2(%[dst_ptr]) \n\t"
  165. "sb %[store2], 3(%[dst_ptr]) \n\t"
  166. : [load1] "=&r"(load1), [load2] "=&r"(load2), [p1] "=&r"(p1),
  167. [p2] "=&r"(p2), [scratch1] "=&r"(scratch1),
  168. [scratch2] "=&r"(scratch2), [Temp1] "=&r"(Temp1),
  169. [Temp2] "=&r"(Temp2), [store1] "=&r"(store1),
  170. [store2] "=&r"(store2), [src_ptr] "+r"(src_ptr)
  171. : [filter45] "r"(filter45), [vector4a] "r"(vector4a),
  172. [src_stride] "r"(src_stride), [cm] "r"(cm), [dst_ptr] "r"(dst_ptr));
  173. }
  174. /* Next row... */
  175. src += src_stride;
  176. dst += dst_stride;
  177. }
  178. }
  179. void vpx_convolve2_avg_vert_dspr2(const uint8_t *src, ptrdiff_t src_stride,
  180. uint8_t *dst, ptrdiff_t dst_stride,
  181. const InterpKernel *filter, int x0_q4,
  182. int32_t x_step_q4, int y0_q4, int y_step_q4,
  183. int w, int h) {
  184. const int16_t *const filter_y = filter[y0_q4];
  185. uint32_t pos = 38;
  186. assert(y_step_q4 == 16);
  187. /* bit positon for extract from acc */
  188. __asm__ __volatile__("wrdsp %[pos], 1 \n\t"
  189. :
  190. : [pos] "r"(pos));
  191. prefetch_store(dst);
  192. switch (w) {
  193. case 4:
  194. case 8:
  195. case 16:
  196. case 32:
  197. convolve_bi_avg_vert_4_dspr2(src, src_stride, dst, dst_stride, filter_y,
  198. w, h);
  199. break;
  200. case 64:
  201. prefetch_store(dst + 32);
  202. convolve_bi_avg_vert_64_dspr2(src, src_stride, dst, dst_stride, filter_y,
  203. h);
  204. break;
  205. default:
  206. vpx_convolve8_avg_vert_c(src, src_stride, dst, dst_stride, filter, x0_q4,
  207. x_step_q4, y0_q4, y_step_q4, w, h);
  208. break;
  209. }
  210. }
  211. #endif