rescaler_mips32.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. // Copyright 2014 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. // MIPS version of rescaling functions
  11. //
  12. // Author(s): Djordje Pesut (djordje.pesut@imgtec.com)
  13. #include "./dsp.h"
  14. #if defined(WEBP_USE_MIPS32) && !defined(WEBP_REDUCE_SIZE)
  15. #include <assert.h>
  16. #include "../utils/rescaler_utils.h"
  17. //------------------------------------------------------------------------------
  18. // Row import
  19. static void ImportRowShrink_MIPS32(WebPRescaler* const wrk,
  20. const uint8_t* src) {
  21. const int x_stride = wrk->num_channels;
  22. const int x_out_max = wrk->dst_width * wrk->num_channels;
  23. const int fx_scale = wrk->fx_scale;
  24. const int x_add = wrk->x_add;
  25. const int x_sub = wrk->x_sub;
  26. const int x_stride1 = x_stride << 2;
  27. int channel;
  28. assert(!wrk->x_expand);
  29. assert(!WebPRescalerInputDone(wrk));
  30. for (channel = 0; channel < x_stride; ++channel) {
  31. const uint8_t* src1 = src + channel;
  32. rescaler_t* frow = wrk->frow + channel;
  33. int temp1, temp2, temp3;
  34. int base, frac, sum;
  35. int accum, accum1;
  36. int loop_c = x_out_max - channel;
  37. __asm__ volatile (
  38. "li %[temp1], 0x8000 \n\t"
  39. "li %[temp2], 0x10000 \n\t"
  40. "li %[sum], 0 \n\t"
  41. "li %[accum], 0 \n\t"
  42. "1: \n\t"
  43. "addu %[accum], %[accum], %[x_add] \n\t"
  44. "li %[base], 0 \n\t"
  45. "blez %[accum], 3f \n\t"
  46. "2: \n\t"
  47. "lbu %[base], 0(%[src1]) \n\t"
  48. "subu %[accum], %[accum], %[x_sub] \n\t"
  49. "addu %[src1], %[src1], %[x_stride] \n\t"
  50. "addu %[sum], %[sum], %[base] \n\t"
  51. "bgtz %[accum], 2b \n\t"
  52. "3: \n\t"
  53. "negu %[accum1], %[accum] \n\t"
  54. "mul %[frac], %[base], %[accum1] \n\t"
  55. "mul %[temp3], %[sum], %[x_sub] \n\t"
  56. "subu %[loop_c], %[loop_c], %[x_stride] \n\t"
  57. "mult %[temp1], %[temp2] \n\t"
  58. "maddu %[frac], %[fx_scale] \n\t"
  59. "mfhi %[sum] \n\t"
  60. "subu %[temp3], %[temp3], %[frac] \n\t"
  61. "sw %[temp3], 0(%[frow]) \n\t"
  62. "addu %[frow], %[frow], %[x_stride1] \n\t"
  63. "bgtz %[loop_c], 1b \n\t"
  64. : [accum]"=&r"(accum), [src1]"+r"(src1), [temp3]"=&r"(temp3),
  65. [sum]"=&r"(sum), [base]"=&r"(base), [frac]"=&r"(frac),
  66. [frow]"+r"(frow), [accum1]"=&r"(accum1),
  67. [temp2]"=&r"(temp2), [temp1]"=&r"(temp1)
  68. : [x_stride]"r"(x_stride), [fx_scale]"r"(fx_scale),
  69. [x_sub]"r"(x_sub), [x_add]"r"(x_add),
  70. [loop_c]"r"(loop_c), [x_stride1]"r"(x_stride1)
  71. : "memory", "hi", "lo"
  72. );
  73. assert(accum == 0);
  74. }
  75. }
  76. static void ImportRowExpand_MIPS32(WebPRescaler* const wrk,
  77. const uint8_t* src) {
  78. const int x_stride = wrk->num_channels;
  79. const int x_out_max = wrk->dst_width * wrk->num_channels;
  80. const int x_add = wrk->x_add;
  81. const int x_sub = wrk->x_sub;
  82. const int src_width = wrk->src_width;
  83. const int x_stride1 = x_stride << 2;
  84. int channel;
  85. assert(wrk->x_expand);
  86. assert(!WebPRescalerInputDone(wrk));
  87. for (channel = 0; channel < x_stride; ++channel) {
  88. const uint8_t* src1 = src + channel;
  89. rescaler_t* frow = wrk->frow + channel;
  90. int temp1, temp2, temp3, temp4;
  91. int frac;
  92. int accum;
  93. int x_out = channel;
  94. __asm__ volatile (
  95. "addiu %[temp3], %[src_width], -1 \n\t"
  96. "lbu %[temp2], 0(%[src1]) \n\t"
  97. "addu %[src1], %[src1], %[x_stride] \n\t"
  98. "bgtz %[temp3], 0f \n\t"
  99. "addiu %[temp1], %[temp2], 0 \n\t"
  100. "b 3f \n\t"
  101. "0: \n\t"
  102. "lbu %[temp1], 0(%[src1]) \n\t"
  103. "3: \n\t"
  104. "addiu %[accum], %[x_add], 0 \n\t"
  105. "1: \n\t"
  106. "subu %[temp3], %[temp2], %[temp1] \n\t"
  107. "mul %[temp3], %[temp3], %[accum] \n\t"
  108. "mul %[temp4], %[temp1], %[x_add] \n\t"
  109. "addu %[temp3], %[temp4], %[temp3] \n\t"
  110. "sw %[temp3], 0(%[frow]) \n\t"
  111. "addu %[frow], %[frow], %[x_stride1] \n\t"
  112. "addu %[x_out], %[x_out], %[x_stride] \n\t"
  113. "subu %[temp3], %[x_out], %[x_out_max] \n\t"
  114. "bgez %[temp3], 2f \n\t"
  115. "subu %[accum], %[accum], %[x_sub] \n\t"
  116. "bgez %[accum], 4f \n\t"
  117. "addiu %[temp2], %[temp1], 0 \n\t"
  118. "addu %[src1], %[src1], %[x_stride] \n\t"
  119. "lbu %[temp1], 0(%[src1]) \n\t"
  120. "addu %[accum], %[accum], %[x_add] \n\t"
  121. "4: \n\t"
  122. "b 1b \n\t"
  123. "2: \n\t"
  124. : [src1]"+r"(src1), [accum]"=&r"(accum), [temp1]"=&r"(temp1),
  125. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), [temp4]"=&r"(temp4),
  126. [x_out]"+r"(x_out), [frac]"=&r"(frac), [frow]"+r"(frow)
  127. : [x_stride]"r"(x_stride), [x_add]"r"(x_add), [x_sub]"r"(x_sub),
  128. [x_stride1]"r"(x_stride1), [src_width]"r"(src_width),
  129. [x_out_max]"r"(x_out_max)
  130. : "memory", "hi", "lo"
  131. );
  132. assert(wrk->x_sub == 0 /* <- special case for src_width=1 */ || accum == 0);
  133. }
  134. }
  135. //------------------------------------------------------------------------------
  136. // Row export
  137. static void ExportRowExpand_MIPS32(WebPRescaler* const wrk) {
  138. uint8_t* dst = wrk->dst;
  139. rescaler_t* irow = wrk->irow;
  140. const int x_out_max = wrk->dst_width * wrk->num_channels;
  141. const rescaler_t* frow = wrk->frow;
  142. int temp0, temp1, temp3, temp4, temp5, loop_end;
  143. const int temp2 = (int)wrk->fy_scale;
  144. const int temp6 = x_out_max << 2;
  145. assert(!WebPRescalerOutputDone(wrk));
  146. assert(wrk->y_accum <= 0);
  147. assert(wrk->y_expand);
  148. assert(wrk->y_sub != 0);
  149. if (wrk->y_accum == 0) {
  150. __asm__ volatile (
  151. "li %[temp3], 0x10000 \n\t"
  152. "li %[temp4], 0x8000 \n\t"
  153. "addu %[loop_end], %[frow], %[temp6] \n\t"
  154. "1: \n\t"
  155. "lw %[temp0], 0(%[frow]) \n\t"
  156. "addiu %[dst], %[dst], 1 \n\t"
  157. "addiu %[frow], %[frow], 4 \n\t"
  158. "mult %[temp3], %[temp4] \n\t"
  159. "maddu %[temp0], %[temp2] \n\t"
  160. "mfhi %[temp5] \n\t"
  161. "sb %[temp5], -1(%[dst]) \n\t"
  162. "bne %[frow], %[loop_end], 1b \n\t"
  163. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp3]"=&r"(temp3),
  164. [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [frow]"+r"(frow),
  165. [dst]"+r"(dst), [loop_end]"=&r"(loop_end)
  166. : [temp2]"r"(temp2), [temp6]"r"(temp6)
  167. : "memory", "hi", "lo"
  168. );
  169. } else {
  170. const uint32_t B = WEBP_RESCALER_FRAC(-wrk->y_accum, wrk->y_sub);
  171. const uint32_t A = (uint32_t)(WEBP_RESCALER_ONE - B);
  172. __asm__ volatile (
  173. "li %[temp3], 0x10000 \n\t"
  174. "li %[temp4], 0x8000 \n\t"
  175. "addu %[loop_end], %[frow], %[temp6] \n\t"
  176. "1: \n\t"
  177. "lw %[temp0], 0(%[frow]) \n\t"
  178. "lw %[temp1], 0(%[irow]) \n\t"
  179. "addiu %[dst], %[dst], 1 \n\t"
  180. "mult %[temp3], %[temp4] \n\t"
  181. "maddu %[A], %[temp0] \n\t"
  182. "maddu %[B], %[temp1] \n\t"
  183. "addiu %[frow], %[frow], 4 \n\t"
  184. "addiu %[irow], %[irow], 4 \n\t"
  185. "mfhi %[temp5] \n\t"
  186. "mult %[temp3], %[temp4] \n\t"
  187. "maddu %[temp5], %[temp2] \n\t"
  188. "mfhi %[temp5] \n\t"
  189. "sb %[temp5], -1(%[dst]) \n\t"
  190. "bne %[frow], %[loop_end], 1b \n\t"
  191. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp3]"=&r"(temp3),
  192. [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [frow]"+r"(frow),
  193. [irow]"+r"(irow), [dst]"+r"(dst), [loop_end]"=&r"(loop_end)
  194. : [temp2]"r"(temp2), [temp6]"r"(temp6), [A]"r"(A), [B]"r"(B)
  195. : "memory", "hi", "lo"
  196. );
  197. }
  198. }
  199. #if 0 // disabled for now. TODO(skal): make match the C-code
  200. static void ExportRowShrink_MIPS32(WebPRescaler* const wrk) {
  201. const int x_out_max = wrk->dst_width * wrk->num_channels;
  202. uint8_t* dst = wrk->dst;
  203. rescaler_t* irow = wrk->irow;
  204. const rescaler_t* frow = wrk->frow;
  205. const int yscale = wrk->fy_scale * (-wrk->y_accum);
  206. int temp0, temp1, temp3, temp4, temp5, loop_end;
  207. const int temp2 = (int)wrk->fxy_scale;
  208. const int temp6 = x_out_max << 2;
  209. assert(!WebPRescalerOutputDone(wrk));
  210. assert(wrk->y_accum <= 0);
  211. assert(!wrk->y_expand);
  212. assert(wrk->fxy_scale != 0);
  213. if (yscale) {
  214. __asm__ volatile (
  215. "li %[temp3], 0x10000 \n\t"
  216. "li %[temp4], 0x8000 \n\t"
  217. "addu %[loop_end], %[frow], %[temp6] \n\t"
  218. "1: \n\t"
  219. "lw %[temp0], 0(%[frow]) \n\t"
  220. "mult %[temp3], %[temp4] \n\t"
  221. "addiu %[frow], %[frow], 4 \n\t"
  222. "maddu %[temp0], %[yscale] \n\t"
  223. "mfhi %[temp1] \n\t"
  224. "lw %[temp0], 0(%[irow]) \n\t"
  225. "addiu %[dst], %[dst], 1 \n\t"
  226. "addiu %[irow], %[irow], 4 \n\t"
  227. "subu %[temp0], %[temp0], %[temp1] \n\t"
  228. "mult %[temp3], %[temp4] \n\t"
  229. "maddu %[temp0], %[temp2] \n\t"
  230. "mfhi %[temp5] \n\t"
  231. "sw %[temp1], -4(%[irow]) \n\t"
  232. "sb %[temp5], -1(%[dst]) \n\t"
  233. "bne %[frow], %[loop_end], 1b \n\t"
  234. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp3]"=&r"(temp3),
  235. [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [frow]"+r"(frow),
  236. [irow]"+r"(irow), [dst]"+r"(dst), [loop_end]"=&r"(loop_end)
  237. : [temp2]"r"(temp2), [yscale]"r"(yscale), [temp6]"r"(temp6)
  238. : "memory", "hi", "lo"
  239. );
  240. } else {
  241. __asm__ volatile (
  242. "li %[temp3], 0x10000 \n\t"
  243. "li %[temp4], 0x8000 \n\t"
  244. "addu %[loop_end], %[irow], %[temp6] \n\t"
  245. "1: \n\t"
  246. "lw %[temp0], 0(%[irow]) \n\t"
  247. "addiu %[dst], %[dst], 1 \n\t"
  248. "addiu %[irow], %[irow], 4 \n\t"
  249. "mult %[temp3], %[temp4] \n\t"
  250. "maddu %[temp0], %[temp2] \n\t"
  251. "mfhi %[temp5] \n\t"
  252. "sw $zero, -4(%[irow]) \n\t"
  253. "sb %[temp5], -1(%[dst]) \n\t"
  254. "bne %[irow], %[loop_end], 1b \n\t"
  255. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp3]"=&r"(temp3),
  256. [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [irow]"+r"(irow),
  257. [dst]"+r"(dst), [loop_end]"=&r"(loop_end)
  258. : [temp2]"r"(temp2), [temp6]"r"(temp6)
  259. : "memory", "hi", "lo"
  260. );
  261. }
  262. }
  263. #endif // 0
  264. //------------------------------------------------------------------------------
  265. // Entry point
  266. extern void WebPRescalerDspInitMIPS32(void);
  267. WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInitMIPS32(void) {
  268. WebPRescalerImportRowExpand = ImportRowExpand_MIPS32;
  269. WebPRescalerImportRowShrink = ImportRowShrink_MIPS32;
  270. WebPRescalerExportRowExpand = ExportRowExpand_MIPS32;
  271. // WebPRescalerExportRowShrink = ExportRowShrink_MIPS32;
  272. }
  273. #else // !WEBP_USE_MIPS32
  274. WEBP_DSP_INIT_STUB(WebPRescalerDspInitMIPS32)
  275. #endif // WEBP_USE_MIPS32