enc_mips32.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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 speed-critical encoding functions.
  11. //
  12. // Author(s): Djordje Pesut (djordje.pesut@imgtec.com)
  13. // Jovan Zelincevic (jovan.zelincevic@imgtec.com)
  14. // Slobodan Prijic (slobodan.prijic@imgtec.com)
  15. #include "./dsp.h"
  16. #if defined(WEBP_USE_MIPS32)
  17. #include "./mips_macro.h"
  18. #include "../enc/vp8i_enc.h"
  19. #include "../enc/cost_enc.h"
  20. static const int kC1 = 20091 + (1 << 16);
  21. static const int kC2 = 35468;
  22. // macro for one vertical pass in ITransformOne
  23. // MUL macro inlined
  24. // temp0..temp15 holds tmp[0]..tmp[15]
  25. // A..D - offsets in bytes to load from in buffer
  26. // TEMP0..TEMP3 - registers for corresponding tmp elements
  27. // TEMP4..TEMP5 - temporary registers
  28. #define VERTICAL_PASS(A, B, C, D, TEMP4, TEMP0, TEMP1, TEMP2, TEMP3) \
  29. "lh %[temp16], " #A "(%[temp20]) \n\t" \
  30. "lh %[temp18], " #B "(%[temp20]) \n\t" \
  31. "lh %[temp17], " #C "(%[temp20]) \n\t" \
  32. "lh %[temp19], " #D "(%[temp20]) \n\t" \
  33. "addu %[" #TEMP4 "], %[temp16], %[temp18] \n\t" \
  34. "subu %[temp16], %[temp16], %[temp18] \n\t" \
  35. "mul %[" #TEMP0 "], %[temp17], %[kC2] \n\t" \
  36. "mul %[temp18], %[temp19], %[kC1] \n\t" \
  37. "mul %[temp17], %[temp17], %[kC1] \n\t" \
  38. "mul %[temp19], %[temp19], %[kC2] \n\t" \
  39. "sra %[" #TEMP0 "], %[" #TEMP0 "], 16 \n\n" \
  40. "sra %[temp18], %[temp18], 16 \n\n" \
  41. "sra %[temp17], %[temp17], 16 \n\n" \
  42. "sra %[temp19], %[temp19], 16 \n\n" \
  43. "subu %[" #TEMP2 "], %[" #TEMP0 "], %[temp18] \n\t" \
  44. "addu %[" #TEMP3 "], %[temp17], %[temp19] \n\t" \
  45. "addu %[" #TEMP0 "], %[" #TEMP4 "], %[" #TEMP3 "] \n\t" \
  46. "addu %[" #TEMP1 "], %[temp16], %[" #TEMP2 "] \n\t" \
  47. "subu %[" #TEMP2 "], %[temp16], %[" #TEMP2 "] \n\t" \
  48. "subu %[" #TEMP3 "], %[" #TEMP4 "], %[" #TEMP3 "] \n\t"
  49. // macro for one horizontal pass in ITransformOne
  50. // MUL and STORE macros inlined
  51. // a = clip_8b(a) is replaced with: a = max(a, 0); a = min(a, 255)
  52. // temp0..temp15 holds tmp[0]..tmp[15]
  53. // A - offset in bytes to load from ref and store to dst buffer
  54. // TEMP0, TEMP4, TEMP8 and TEMP12 - registers for corresponding tmp elements
  55. #define HORIZONTAL_PASS(A, TEMP0, TEMP4, TEMP8, TEMP12) \
  56. "addiu %[" #TEMP0 "], %[" #TEMP0 "], 4 \n\t" \
  57. "addu %[temp16], %[" #TEMP0 "], %[" #TEMP8 "] \n\t" \
  58. "subu %[temp17], %[" #TEMP0 "], %[" #TEMP8 "] \n\t" \
  59. "mul %[" #TEMP0 "], %[" #TEMP4 "], %[kC2] \n\t" \
  60. "mul %[" #TEMP8 "], %[" #TEMP12 "], %[kC1] \n\t" \
  61. "mul %[" #TEMP4 "], %[" #TEMP4 "], %[kC1] \n\t" \
  62. "mul %[" #TEMP12 "], %[" #TEMP12 "], %[kC2] \n\t" \
  63. "sra %[" #TEMP0 "], %[" #TEMP0 "], 16 \n\t" \
  64. "sra %[" #TEMP8 "], %[" #TEMP8 "], 16 \n\t" \
  65. "sra %[" #TEMP4 "], %[" #TEMP4 "], 16 \n\t" \
  66. "sra %[" #TEMP12 "], %[" #TEMP12 "], 16 \n\t" \
  67. "subu %[temp18], %[" #TEMP0 "], %[" #TEMP8 "] \n\t" \
  68. "addu %[temp19], %[" #TEMP4 "], %[" #TEMP12 "] \n\t" \
  69. "addu %[" #TEMP0 "], %[temp16], %[temp19] \n\t" \
  70. "addu %[" #TEMP4 "], %[temp17], %[temp18] \n\t" \
  71. "subu %[" #TEMP8 "], %[temp17], %[temp18] \n\t" \
  72. "subu %[" #TEMP12 "], %[temp16], %[temp19] \n\t" \
  73. "lw %[temp20], 0(%[args]) \n\t" \
  74. "sra %[" #TEMP0 "], %[" #TEMP0 "], 3 \n\t" \
  75. "sra %[" #TEMP4 "], %[" #TEMP4 "], 3 \n\t" \
  76. "sra %[" #TEMP8 "], %[" #TEMP8 "], 3 \n\t" \
  77. "sra %[" #TEMP12 "], %[" #TEMP12 "], 3 \n\t" \
  78. "lbu %[temp16], 0+" XSTR(BPS) "*" #A "(%[temp20]) \n\t" \
  79. "lbu %[temp17], 1+" XSTR(BPS) "*" #A "(%[temp20]) \n\t" \
  80. "lbu %[temp18], 2+" XSTR(BPS) "*" #A "(%[temp20]) \n\t" \
  81. "lbu %[temp19], 3+" XSTR(BPS) "*" #A "(%[temp20]) \n\t" \
  82. "addu %[" #TEMP0 "], %[temp16], %[" #TEMP0 "] \n\t" \
  83. "addu %[" #TEMP4 "], %[temp17], %[" #TEMP4 "] \n\t" \
  84. "addu %[" #TEMP8 "], %[temp18], %[" #TEMP8 "] \n\t" \
  85. "addu %[" #TEMP12 "], %[temp19], %[" #TEMP12 "] \n\t" \
  86. "slt %[temp16], %[" #TEMP0 "], $zero \n\t" \
  87. "slt %[temp17], %[" #TEMP4 "], $zero \n\t" \
  88. "slt %[temp18], %[" #TEMP8 "], $zero \n\t" \
  89. "slt %[temp19], %[" #TEMP12 "], $zero \n\t" \
  90. "movn %[" #TEMP0 "], $zero, %[temp16] \n\t" \
  91. "movn %[" #TEMP4 "], $zero, %[temp17] \n\t" \
  92. "movn %[" #TEMP8 "], $zero, %[temp18] \n\t" \
  93. "movn %[" #TEMP12 "], $zero, %[temp19] \n\t" \
  94. "addiu %[temp20], $zero, 255 \n\t" \
  95. "slt %[temp16], %[" #TEMP0 "], %[temp20] \n\t" \
  96. "slt %[temp17], %[" #TEMP4 "], %[temp20] \n\t" \
  97. "slt %[temp18], %[" #TEMP8 "], %[temp20] \n\t" \
  98. "slt %[temp19], %[" #TEMP12 "], %[temp20] \n\t" \
  99. "movz %[" #TEMP0 "], %[temp20], %[temp16] \n\t" \
  100. "movz %[" #TEMP4 "], %[temp20], %[temp17] \n\t" \
  101. "lw %[temp16], 8(%[args]) \n\t" \
  102. "movz %[" #TEMP8 "], %[temp20], %[temp18] \n\t" \
  103. "movz %[" #TEMP12 "], %[temp20], %[temp19] \n\t" \
  104. "sb %[" #TEMP0 "], 0+" XSTR(BPS) "*" #A "(%[temp16]) \n\t" \
  105. "sb %[" #TEMP4 "], 1+" XSTR(BPS) "*" #A "(%[temp16]) \n\t" \
  106. "sb %[" #TEMP8 "], 2+" XSTR(BPS) "*" #A "(%[temp16]) \n\t" \
  107. "sb %[" #TEMP12 "], 3+" XSTR(BPS) "*" #A "(%[temp16]) \n\t"
  108. // Does one or two inverse transforms.
  109. static WEBP_INLINE void ITransformOne_MIPS32(const uint8_t* ref,
  110. const int16_t* in,
  111. uint8_t* dst) {
  112. int temp0, temp1, temp2, temp3, temp4, temp5, temp6;
  113. int temp7, temp8, temp9, temp10, temp11, temp12, temp13;
  114. int temp14, temp15, temp16, temp17, temp18, temp19, temp20;
  115. const int* args[3] = {(const int*)ref, (const int*)in, (const int*)dst};
  116. __asm__ volatile(
  117. "lw %[temp20], 4(%[args]) \n\t"
  118. VERTICAL_PASS(0, 16, 8, 24, temp4, temp0, temp1, temp2, temp3)
  119. VERTICAL_PASS(2, 18, 10, 26, temp8, temp4, temp5, temp6, temp7)
  120. VERTICAL_PASS(4, 20, 12, 28, temp12, temp8, temp9, temp10, temp11)
  121. VERTICAL_PASS(6, 22, 14, 30, temp20, temp12, temp13, temp14, temp15)
  122. HORIZONTAL_PASS(0, temp0, temp4, temp8, temp12)
  123. HORIZONTAL_PASS(1, temp1, temp5, temp9, temp13)
  124. HORIZONTAL_PASS(2, temp2, temp6, temp10, temp14)
  125. HORIZONTAL_PASS(3, temp3, temp7, temp11, temp15)
  126. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  127. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  128. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8),
  129. [temp9]"=&r"(temp9), [temp10]"=&r"(temp10), [temp11]"=&r"(temp11),
  130. [temp12]"=&r"(temp12), [temp13]"=&r"(temp13), [temp14]"=&r"(temp14),
  131. [temp15]"=&r"(temp15), [temp16]"=&r"(temp16), [temp17]"=&r"(temp17),
  132. [temp18]"=&r"(temp18), [temp19]"=&r"(temp19), [temp20]"=&r"(temp20)
  133. : [args]"r"(args), [kC1]"r"(kC1), [kC2]"r"(kC2)
  134. : "memory", "hi", "lo"
  135. );
  136. }
  137. static void ITransform_MIPS32(const uint8_t* ref, const int16_t* in,
  138. uint8_t* dst, int do_two) {
  139. ITransformOne_MIPS32(ref, in, dst);
  140. if (do_two) {
  141. ITransformOne_MIPS32(ref + 4, in + 16, dst + 4);
  142. }
  143. }
  144. #undef VERTICAL_PASS
  145. #undef HORIZONTAL_PASS
  146. // macro for one pass through for loop in QuantizeBlock
  147. // QUANTDIV macro inlined
  148. // J - offset in bytes (kZigzag[n] * 2)
  149. // K - offset in bytes (kZigzag[n] * 4)
  150. // N - offset in bytes (n * 2)
  151. #define QUANTIZE_ONE(J, K, N) \
  152. "lh %[temp0], " #J "(%[ppin]) \n\t" \
  153. "lhu %[temp1], " #J "(%[ppsharpen]) \n\t" \
  154. "lw %[temp2], " #K "(%[ppzthresh]) \n\t" \
  155. "sra %[sign], %[temp0], 15 \n\t" \
  156. "xor %[coeff], %[temp0], %[sign] \n\t" \
  157. "subu %[coeff], %[coeff], %[sign] \n\t" \
  158. "addu %[coeff], %[coeff], %[temp1] \n\t" \
  159. "slt %[temp4], %[temp2], %[coeff] \n\t" \
  160. "addiu %[temp5], $zero, 0 \n\t" \
  161. "addiu %[level], $zero, 0 \n\t" \
  162. "beqz %[temp4], 2f \n\t" \
  163. "lhu %[temp1], " #J "(%[ppiq]) \n\t" \
  164. "lw %[temp2], " #K "(%[ppbias]) \n\t" \
  165. "lhu %[temp3], " #J "(%[ppq]) \n\t" \
  166. "mul %[level], %[coeff], %[temp1] \n\t" \
  167. "addu %[level], %[level], %[temp2] \n\t" \
  168. "sra %[level], %[level], 17 \n\t" \
  169. "slt %[temp4], %[max_level], %[level] \n\t" \
  170. "movn %[level], %[max_level], %[temp4] \n\t" \
  171. "xor %[level], %[level], %[sign] \n\t" \
  172. "subu %[level], %[level], %[sign] \n\t" \
  173. "mul %[temp5], %[level], %[temp3] \n\t" \
  174. "2: \n\t" \
  175. "sh %[temp5], " #J "(%[ppin]) \n\t" \
  176. "sh %[level], " #N "(%[pout]) \n\t"
  177. static int QuantizeBlock_MIPS32(int16_t in[16], int16_t out[16],
  178. const VP8Matrix* const mtx) {
  179. int temp0, temp1, temp2, temp3, temp4, temp5;
  180. int sign, coeff, level, i;
  181. int max_level = MAX_LEVEL;
  182. int16_t* ppin = &in[0];
  183. int16_t* pout = &out[0];
  184. const uint16_t* ppsharpen = &mtx->sharpen_[0];
  185. const uint32_t* ppzthresh = &mtx->zthresh_[0];
  186. const uint16_t* ppq = &mtx->q_[0];
  187. const uint16_t* ppiq = &mtx->iq_[0];
  188. const uint32_t* ppbias = &mtx->bias_[0];
  189. __asm__ volatile(
  190. QUANTIZE_ONE( 0, 0, 0)
  191. QUANTIZE_ONE( 2, 4, 2)
  192. QUANTIZE_ONE( 8, 16, 4)
  193. QUANTIZE_ONE(16, 32, 6)
  194. QUANTIZE_ONE(10, 20, 8)
  195. QUANTIZE_ONE( 4, 8, 10)
  196. QUANTIZE_ONE( 6, 12, 12)
  197. QUANTIZE_ONE(12, 24, 14)
  198. QUANTIZE_ONE(18, 36, 16)
  199. QUANTIZE_ONE(24, 48, 18)
  200. QUANTIZE_ONE(26, 52, 20)
  201. QUANTIZE_ONE(20, 40, 22)
  202. QUANTIZE_ONE(14, 28, 24)
  203. QUANTIZE_ONE(22, 44, 26)
  204. QUANTIZE_ONE(28, 56, 28)
  205. QUANTIZE_ONE(30, 60, 30)
  206. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1),
  207. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3),
  208. [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  209. [sign]"=&r"(sign), [coeff]"=&r"(coeff),
  210. [level]"=&r"(level)
  211. : [pout]"r"(pout), [ppin]"r"(ppin),
  212. [ppiq]"r"(ppiq), [max_level]"r"(max_level),
  213. [ppbias]"r"(ppbias), [ppzthresh]"r"(ppzthresh),
  214. [ppsharpen]"r"(ppsharpen), [ppq]"r"(ppq)
  215. : "memory", "hi", "lo"
  216. );
  217. // moved out from macro to increase possibility for earlier breaking
  218. for (i = 15; i >= 0; i--) {
  219. if (out[i]) return 1;
  220. }
  221. return 0;
  222. }
  223. static int Quantize2Blocks_MIPS32(int16_t in[32], int16_t out[32],
  224. const VP8Matrix* const mtx) {
  225. int nz;
  226. nz = QuantizeBlock_MIPS32(in + 0 * 16, out + 0 * 16, mtx) << 0;
  227. nz |= QuantizeBlock_MIPS32(in + 1 * 16, out + 1 * 16, mtx) << 1;
  228. return nz;
  229. }
  230. #undef QUANTIZE_ONE
  231. // macro for one horizontal pass in Disto4x4 (TTransform)
  232. // two calls of function TTransform are merged into single one
  233. // A - offset in bytes to load from a and b buffers
  234. // E..H - offsets in bytes to store first results to tmp buffer
  235. // E1..H1 - offsets in bytes to store second results to tmp buffer
  236. #define HORIZONTAL_PASS(A, E, F, G, H, E1, F1, G1, H1) \
  237. "lbu %[temp0], 0+" XSTR(BPS) "*" #A "(%[a]) \n\t" \
  238. "lbu %[temp1], 1+" XSTR(BPS) "*" #A "(%[a]) \n\t" \
  239. "lbu %[temp2], 2+" XSTR(BPS) "*" #A "(%[a]) \n\t" \
  240. "lbu %[temp3], 3+" XSTR(BPS) "*" #A "(%[a]) \n\t" \
  241. "lbu %[temp4], 0+" XSTR(BPS) "*" #A "(%[b]) \n\t" \
  242. "lbu %[temp5], 1+" XSTR(BPS) "*" #A "(%[b]) \n\t" \
  243. "lbu %[temp6], 2+" XSTR(BPS) "*" #A "(%[b]) \n\t" \
  244. "lbu %[temp7], 3+" XSTR(BPS) "*" #A "(%[b]) \n\t" \
  245. "addu %[temp8], %[temp0], %[temp2] \n\t" \
  246. "subu %[temp0], %[temp0], %[temp2] \n\t" \
  247. "addu %[temp2], %[temp1], %[temp3] \n\t" \
  248. "subu %[temp1], %[temp1], %[temp3] \n\t" \
  249. "addu %[temp3], %[temp4], %[temp6] \n\t" \
  250. "subu %[temp4], %[temp4], %[temp6] \n\t" \
  251. "addu %[temp6], %[temp5], %[temp7] \n\t" \
  252. "subu %[temp5], %[temp5], %[temp7] \n\t" \
  253. "addu %[temp7], %[temp8], %[temp2] \n\t" \
  254. "subu %[temp2], %[temp8], %[temp2] \n\t" \
  255. "addu %[temp8], %[temp0], %[temp1] \n\t" \
  256. "subu %[temp0], %[temp0], %[temp1] \n\t" \
  257. "addu %[temp1], %[temp3], %[temp6] \n\t" \
  258. "subu %[temp3], %[temp3], %[temp6] \n\t" \
  259. "addu %[temp6], %[temp4], %[temp5] \n\t" \
  260. "subu %[temp4], %[temp4], %[temp5] \n\t" \
  261. "sw %[temp7], " #E "(%[tmp]) \n\t" \
  262. "sw %[temp2], " #H "(%[tmp]) \n\t" \
  263. "sw %[temp8], " #F "(%[tmp]) \n\t" \
  264. "sw %[temp0], " #G "(%[tmp]) \n\t" \
  265. "sw %[temp1], " #E1 "(%[tmp]) \n\t" \
  266. "sw %[temp3], " #H1 "(%[tmp]) \n\t" \
  267. "sw %[temp6], " #F1 "(%[tmp]) \n\t" \
  268. "sw %[temp4], " #G1 "(%[tmp]) \n\t"
  269. // macro for one vertical pass in Disto4x4 (TTransform)
  270. // two calls of function TTransform are merged into single one
  271. // since only one accu is available in mips32r1 instruction set
  272. // first is done second call of function TTransform and after
  273. // that first one.
  274. // const int sum1 = TTransform(a, w);
  275. // const int sum2 = TTransform(b, w);
  276. // return abs(sum2 - sum1) >> 5;
  277. // (sum2 - sum1) is calculated with madds (sub2) and msubs (sub1)
  278. // A..D - offsets in bytes to load first results from tmp buffer
  279. // A1..D1 - offsets in bytes to load second results from tmp buffer
  280. // E..H - offsets in bytes to load from w buffer
  281. #define VERTICAL_PASS(A, B, C, D, A1, B1, C1, D1, E, F, G, H) \
  282. "lw %[temp0], " #A1 "(%[tmp]) \n\t" \
  283. "lw %[temp1], " #C1 "(%[tmp]) \n\t" \
  284. "lw %[temp2], " #B1 "(%[tmp]) \n\t" \
  285. "lw %[temp3], " #D1 "(%[tmp]) \n\t" \
  286. "addu %[temp8], %[temp0], %[temp1] \n\t" \
  287. "subu %[temp0], %[temp0], %[temp1] \n\t" \
  288. "addu %[temp1], %[temp2], %[temp3] \n\t" \
  289. "subu %[temp2], %[temp2], %[temp3] \n\t" \
  290. "addu %[temp3], %[temp8], %[temp1] \n\t" \
  291. "subu %[temp8], %[temp8], %[temp1] \n\t" \
  292. "addu %[temp1], %[temp0], %[temp2] \n\t" \
  293. "subu %[temp0], %[temp0], %[temp2] \n\t" \
  294. "sra %[temp4], %[temp3], 31 \n\t" \
  295. "sra %[temp5], %[temp1], 31 \n\t" \
  296. "sra %[temp6], %[temp0], 31 \n\t" \
  297. "sra %[temp7], %[temp8], 31 \n\t" \
  298. "xor %[temp3], %[temp3], %[temp4] \n\t" \
  299. "xor %[temp1], %[temp1], %[temp5] \n\t" \
  300. "xor %[temp0], %[temp0], %[temp6] \n\t" \
  301. "xor %[temp8], %[temp8], %[temp7] \n\t" \
  302. "subu %[temp3], %[temp3], %[temp4] \n\t" \
  303. "subu %[temp1], %[temp1], %[temp5] \n\t" \
  304. "subu %[temp0], %[temp0], %[temp6] \n\t" \
  305. "subu %[temp8], %[temp8], %[temp7] \n\t" \
  306. "lhu %[temp4], " #E "(%[w]) \n\t" \
  307. "lhu %[temp5], " #F "(%[w]) \n\t" \
  308. "lhu %[temp6], " #G "(%[w]) \n\t" \
  309. "lhu %[temp7], " #H "(%[w]) \n\t" \
  310. "madd %[temp4], %[temp3] \n\t" \
  311. "madd %[temp5], %[temp1] \n\t" \
  312. "madd %[temp6], %[temp0] \n\t" \
  313. "madd %[temp7], %[temp8] \n\t" \
  314. "lw %[temp0], " #A "(%[tmp]) \n\t" \
  315. "lw %[temp1], " #C "(%[tmp]) \n\t" \
  316. "lw %[temp2], " #B "(%[tmp]) \n\t" \
  317. "lw %[temp3], " #D "(%[tmp]) \n\t" \
  318. "addu %[temp8], %[temp0], %[temp1] \n\t" \
  319. "subu %[temp0], %[temp0], %[temp1] \n\t" \
  320. "addu %[temp1], %[temp2], %[temp3] \n\t" \
  321. "subu %[temp2], %[temp2], %[temp3] \n\t" \
  322. "addu %[temp3], %[temp8], %[temp1] \n\t" \
  323. "subu %[temp1], %[temp8], %[temp1] \n\t" \
  324. "addu %[temp8], %[temp0], %[temp2] \n\t" \
  325. "subu %[temp0], %[temp0], %[temp2] \n\t" \
  326. "sra %[temp2], %[temp3], 31 \n\t" \
  327. "xor %[temp3], %[temp3], %[temp2] \n\t" \
  328. "subu %[temp3], %[temp3], %[temp2] \n\t" \
  329. "msub %[temp4], %[temp3] \n\t" \
  330. "sra %[temp2], %[temp8], 31 \n\t" \
  331. "sra %[temp3], %[temp0], 31 \n\t" \
  332. "sra %[temp4], %[temp1], 31 \n\t" \
  333. "xor %[temp8], %[temp8], %[temp2] \n\t" \
  334. "xor %[temp0], %[temp0], %[temp3] \n\t" \
  335. "xor %[temp1], %[temp1], %[temp4] \n\t" \
  336. "subu %[temp8], %[temp8], %[temp2] \n\t" \
  337. "subu %[temp0], %[temp0], %[temp3] \n\t" \
  338. "subu %[temp1], %[temp1], %[temp4] \n\t" \
  339. "msub %[temp5], %[temp8] \n\t" \
  340. "msub %[temp6], %[temp0] \n\t" \
  341. "msub %[temp7], %[temp1] \n\t"
  342. static int Disto4x4_MIPS32(const uint8_t* const a, const uint8_t* const b,
  343. const uint16_t* const w) {
  344. int tmp[32];
  345. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
  346. __asm__ volatile(
  347. HORIZONTAL_PASS(0, 0, 4, 8, 12, 64, 68, 72, 76)
  348. HORIZONTAL_PASS(1, 16, 20, 24, 28, 80, 84, 88, 92)
  349. HORIZONTAL_PASS(2, 32, 36, 40, 44, 96, 100, 104, 108)
  350. HORIZONTAL_PASS(3, 48, 52, 56, 60, 112, 116, 120, 124)
  351. "mthi $zero \n\t"
  352. "mtlo $zero \n\t"
  353. VERTICAL_PASS( 0, 16, 32, 48, 64, 80, 96, 112, 0, 8, 16, 24)
  354. VERTICAL_PASS( 4, 20, 36, 52, 68, 84, 100, 116, 2, 10, 18, 26)
  355. VERTICAL_PASS( 8, 24, 40, 56, 72, 88, 104, 120, 4, 12, 20, 28)
  356. VERTICAL_PASS(12, 28, 44, 60, 76, 92, 108, 124, 6, 14, 22, 30)
  357. "mflo %[temp0] \n\t"
  358. "sra %[temp1], %[temp0], 31 \n\t"
  359. "xor %[temp0], %[temp0], %[temp1] \n\t"
  360. "subu %[temp0], %[temp0], %[temp1] \n\t"
  361. "sra %[temp0], %[temp0], 5 \n\t"
  362. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  363. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  364. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8)
  365. : [a]"r"(a), [b]"r"(b), [w]"r"(w), [tmp]"r"(tmp)
  366. : "memory", "hi", "lo"
  367. );
  368. return temp0;
  369. }
  370. #undef VERTICAL_PASS
  371. #undef HORIZONTAL_PASS
  372. static int Disto16x16_MIPS32(const uint8_t* const a, const uint8_t* const b,
  373. const uint16_t* const w) {
  374. int D = 0;
  375. int x, y;
  376. for (y = 0; y < 16 * BPS; y += 4 * BPS) {
  377. for (x = 0; x < 16; x += 4) {
  378. D += Disto4x4_MIPS32(a + x + y, b + x + y, w);
  379. }
  380. }
  381. return D;
  382. }
  383. // macro for one horizontal pass in FTransform
  384. // temp0..temp15 holds tmp[0]..tmp[15]
  385. // A - offset in bytes to load from src and ref buffers
  386. // TEMP0..TEMP3 - registers for corresponding tmp elements
  387. #define HORIZONTAL_PASS(A, TEMP0, TEMP1, TEMP2, TEMP3) \
  388. "lw %[" #TEMP1 "], 0(%[args]) \n\t" \
  389. "lw %[" #TEMP2 "], 4(%[args]) \n\t" \
  390. "lbu %[temp16], 0+" XSTR(BPS) "*" #A "(%[" #TEMP1 "]) \n\t" \
  391. "lbu %[temp17], 0+" XSTR(BPS) "*" #A "(%[" #TEMP2 "]) \n\t" \
  392. "lbu %[temp18], 1+" XSTR(BPS) "*" #A "(%[" #TEMP1 "]) \n\t" \
  393. "lbu %[temp19], 1+" XSTR(BPS) "*" #A "(%[" #TEMP2 "]) \n\t" \
  394. "subu %[temp20], %[temp16], %[temp17] \n\t" \
  395. "lbu %[temp16], 2+" XSTR(BPS) "*" #A "(%[" #TEMP1 "]) \n\t" \
  396. "lbu %[temp17], 2+" XSTR(BPS) "*" #A "(%[" #TEMP2 "]) \n\t" \
  397. "subu %[" #TEMP0 "], %[temp18], %[temp19] \n\t" \
  398. "lbu %[temp18], 3+" XSTR(BPS) "*" #A "(%[" #TEMP1 "]) \n\t" \
  399. "lbu %[temp19], 3+" XSTR(BPS) "*" #A "(%[" #TEMP2 "]) \n\t" \
  400. "subu %[" #TEMP1 "], %[temp16], %[temp17] \n\t" \
  401. "subu %[" #TEMP2 "], %[temp18], %[temp19] \n\t" \
  402. "addu %[" #TEMP3 "], %[temp20], %[" #TEMP2 "] \n\t" \
  403. "subu %[" #TEMP2 "], %[temp20], %[" #TEMP2 "] \n\t" \
  404. "addu %[temp20], %[" #TEMP0 "], %[" #TEMP1 "] \n\t" \
  405. "subu %[" #TEMP0 "], %[" #TEMP0 "], %[" #TEMP1 "] \n\t" \
  406. "mul %[temp16], %[" #TEMP2 "], %[c5352] \n\t" \
  407. "mul %[temp17], %[" #TEMP2 "], %[c2217] \n\t" \
  408. "mul %[temp18], %[" #TEMP0 "], %[c5352] \n\t" \
  409. "mul %[temp19], %[" #TEMP0 "], %[c2217] \n\t" \
  410. "addu %[" #TEMP1 "], %[" #TEMP3 "], %[temp20] \n\t" \
  411. "subu %[temp20], %[" #TEMP3 "], %[temp20] \n\t" \
  412. "sll %[" #TEMP0 "], %[" #TEMP1 "], 3 \n\t" \
  413. "sll %[" #TEMP2 "], %[temp20], 3 \n\t" \
  414. "addiu %[temp16], %[temp16], 1812 \n\t" \
  415. "addiu %[temp17], %[temp17], 937 \n\t" \
  416. "addu %[temp16], %[temp16], %[temp19] \n\t" \
  417. "subu %[temp17], %[temp17], %[temp18] \n\t" \
  418. "sra %[" #TEMP1 "], %[temp16], 9 \n\t" \
  419. "sra %[" #TEMP3 "], %[temp17], 9 \n\t"
  420. // macro for one vertical pass in FTransform
  421. // temp0..temp15 holds tmp[0]..tmp[15]
  422. // A..D - offsets in bytes to store to out buffer
  423. // TEMP0, TEMP4, TEMP8 and TEMP12 - registers for corresponding tmp elements
  424. #define VERTICAL_PASS(A, B, C, D, TEMP0, TEMP4, TEMP8, TEMP12) \
  425. "addu %[temp16], %[" #TEMP0 "], %[" #TEMP12 "] \n\t" \
  426. "subu %[temp19], %[" #TEMP0 "], %[" #TEMP12 "] \n\t" \
  427. "addu %[temp17], %[" #TEMP4 "], %[" #TEMP8 "] \n\t" \
  428. "subu %[temp18], %[" #TEMP4 "], %[" #TEMP8 "] \n\t" \
  429. "mul %[" #TEMP8 "], %[temp19], %[c2217] \n\t" \
  430. "mul %[" #TEMP12 "], %[temp18], %[c2217] \n\t" \
  431. "mul %[" #TEMP4 "], %[temp19], %[c5352] \n\t" \
  432. "mul %[temp18], %[temp18], %[c5352] \n\t" \
  433. "addiu %[temp16], %[temp16], 7 \n\t" \
  434. "addu %[" #TEMP0 "], %[temp16], %[temp17] \n\t" \
  435. "sra %[" #TEMP0 "], %[" #TEMP0 "], 4 \n\t" \
  436. "addu %[" #TEMP12 "], %[" #TEMP12 "], %[" #TEMP4 "] \n\t" \
  437. "subu %[" #TEMP4 "], %[temp16], %[temp17] \n\t" \
  438. "sra %[" #TEMP4 "], %[" #TEMP4 "], 4 \n\t" \
  439. "addiu %[" #TEMP8 "], %[" #TEMP8 "], 30000 \n\t" \
  440. "addiu %[" #TEMP12 "], %[" #TEMP12 "], 12000 \n\t" \
  441. "addiu %[" #TEMP8 "], %[" #TEMP8 "], 21000 \n\t" \
  442. "subu %[" #TEMP8 "], %[" #TEMP8 "], %[temp18] \n\t" \
  443. "sra %[" #TEMP12 "], %[" #TEMP12 "], 16 \n\t" \
  444. "sra %[" #TEMP8 "], %[" #TEMP8 "], 16 \n\t" \
  445. "addiu %[temp16], %[" #TEMP12 "], 1 \n\t" \
  446. "movn %[" #TEMP12 "], %[temp16], %[temp19] \n\t" \
  447. "sh %[" #TEMP0 "], " #A "(%[temp20]) \n\t" \
  448. "sh %[" #TEMP4 "], " #C "(%[temp20]) \n\t" \
  449. "sh %[" #TEMP8 "], " #D "(%[temp20]) \n\t" \
  450. "sh %[" #TEMP12 "], " #B "(%[temp20]) \n\t"
  451. static void FTransform_MIPS32(const uint8_t* src, const uint8_t* ref,
  452. int16_t* out) {
  453. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
  454. int temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16;
  455. int temp17, temp18, temp19, temp20;
  456. const int c2217 = 2217;
  457. const int c5352 = 5352;
  458. const int* const args[3] =
  459. { (const int*)src, (const int*)ref, (const int*)out };
  460. __asm__ volatile(
  461. HORIZONTAL_PASS(0, temp0, temp1, temp2, temp3)
  462. HORIZONTAL_PASS(1, temp4, temp5, temp6, temp7)
  463. HORIZONTAL_PASS(2, temp8, temp9, temp10, temp11)
  464. HORIZONTAL_PASS(3, temp12, temp13, temp14, temp15)
  465. "lw %[temp20], 8(%[args]) \n\t"
  466. VERTICAL_PASS(0, 8, 16, 24, temp0, temp4, temp8, temp12)
  467. VERTICAL_PASS(2, 10, 18, 26, temp1, temp5, temp9, temp13)
  468. VERTICAL_PASS(4, 12, 20, 28, temp2, temp6, temp10, temp14)
  469. VERTICAL_PASS(6, 14, 22, 30, temp3, temp7, temp11, temp15)
  470. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  471. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  472. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8),
  473. [temp9]"=&r"(temp9), [temp10]"=&r"(temp10), [temp11]"=&r"(temp11),
  474. [temp12]"=&r"(temp12), [temp13]"=&r"(temp13), [temp14]"=&r"(temp14),
  475. [temp15]"=&r"(temp15), [temp16]"=&r"(temp16), [temp17]"=&r"(temp17),
  476. [temp18]"=&r"(temp18), [temp19]"=&r"(temp19), [temp20]"=&r"(temp20)
  477. : [args]"r"(args), [c2217]"r"(c2217), [c5352]"r"(c5352)
  478. : "memory", "hi", "lo"
  479. );
  480. }
  481. #undef VERTICAL_PASS
  482. #undef HORIZONTAL_PASS
  483. #if !defined(WORK_AROUND_GCC)
  484. #define GET_SSE_INNER(A, B, C, D) \
  485. "lbu %[temp0], " #A "(%[a]) \n\t" \
  486. "lbu %[temp1], " #A "(%[b]) \n\t" \
  487. "lbu %[temp2], " #B "(%[a]) \n\t" \
  488. "lbu %[temp3], " #B "(%[b]) \n\t" \
  489. "lbu %[temp4], " #C "(%[a]) \n\t" \
  490. "lbu %[temp5], " #C "(%[b]) \n\t" \
  491. "lbu %[temp6], " #D "(%[a]) \n\t" \
  492. "lbu %[temp7], " #D "(%[b]) \n\t" \
  493. "subu %[temp0], %[temp0], %[temp1] \n\t" \
  494. "subu %[temp2], %[temp2], %[temp3] \n\t" \
  495. "subu %[temp4], %[temp4], %[temp5] \n\t" \
  496. "subu %[temp6], %[temp6], %[temp7] \n\t" \
  497. "madd %[temp0], %[temp0] \n\t" \
  498. "madd %[temp2], %[temp2] \n\t" \
  499. "madd %[temp4], %[temp4] \n\t" \
  500. "madd %[temp6], %[temp6] \n\t"
  501. #define GET_SSE(A, B, C, D) \
  502. GET_SSE_INNER(A, A + 1, A + 2, A + 3) \
  503. GET_SSE_INNER(B, B + 1, B + 2, B + 3) \
  504. GET_SSE_INNER(C, C + 1, C + 2, C + 3) \
  505. GET_SSE_INNER(D, D + 1, D + 2, D + 3)
  506. static int SSE16x16_MIPS32(const uint8_t* a, const uint8_t* b) {
  507. int count;
  508. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
  509. __asm__ volatile(
  510. "mult $zero, $zero \n\t"
  511. GET_SSE( 0 * BPS, 4 + 0 * BPS, 8 + 0 * BPS, 12 + 0 * BPS)
  512. GET_SSE( 1 * BPS, 4 + 1 * BPS, 8 + 1 * BPS, 12 + 1 * BPS)
  513. GET_SSE( 2 * BPS, 4 + 2 * BPS, 8 + 2 * BPS, 12 + 2 * BPS)
  514. GET_SSE( 3 * BPS, 4 + 3 * BPS, 8 + 3 * BPS, 12 + 3 * BPS)
  515. GET_SSE( 4 * BPS, 4 + 4 * BPS, 8 + 4 * BPS, 12 + 4 * BPS)
  516. GET_SSE( 5 * BPS, 4 + 5 * BPS, 8 + 5 * BPS, 12 + 5 * BPS)
  517. GET_SSE( 6 * BPS, 4 + 6 * BPS, 8 + 6 * BPS, 12 + 6 * BPS)
  518. GET_SSE( 7 * BPS, 4 + 7 * BPS, 8 + 7 * BPS, 12 + 7 * BPS)
  519. GET_SSE( 8 * BPS, 4 + 8 * BPS, 8 + 8 * BPS, 12 + 8 * BPS)
  520. GET_SSE( 9 * BPS, 4 + 9 * BPS, 8 + 9 * BPS, 12 + 9 * BPS)
  521. GET_SSE(10 * BPS, 4 + 10 * BPS, 8 + 10 * BPS, 12 + 10 * BPS)
  522. GET_SSE(11 * BPS, 4 + 11 * BPS, 8 + 11 * BPS, 12 + 11 * BPS)
  523. GET_SSE(12 * BPS, 4 + 12 * BPS, 8 + 12 * BPS, 12 + 12 * BPS)
  524. GET_SSE(13 * BPS, 4 + 13 * BPS, 8 + 13 * BPS, 12 + 13 * BPS)
  525. GET_SSE(14 * BPS, 4 + 14 * BPS, 8 + 14 * BPS, 12 + 14 * BPS)
  526. GET_SSE(15 * BPS, 4 + 15 * BPS, 8 + 15 * BPS, 12 + 15 * BPS)
  527. "mflo %[count] \n\t"
  528. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  529. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  530. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [count]"=&r"(count)
  531. : [a]"r"(a), [b]"r"(b)
  532. : "memory", "hi", "lo"
  533. );
  534. return count;
  535. }
  536. static int SSE16x8_MIPS32(const uint8_t* a, const uint8_t* b) {
  537. int count;
  538. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
  539. __asm__ volatile(
  540. "mult $zero, $zero \n\t"
  541. GET_SSE( 0 * BPS, 4 + 0 * BPS, 8 + 0 * BPS, 12 + 0 * BPS)
  542. GET_SSE( 1 * BPS, 4 + 1 * BPS, 8 + 1 * BPS, 12 + 1 * BPS)
  543. GET_SSE( 2 * BPS, 4 + 2 * BPS, 8 + 2 * BPS, 12 + 2 * BPS)
  544. GET_SSE( 3 * BPS, 4 + 3 * BPS, 8 + 3 * BPS, 12 + 3 * BPS)
  545. GET_SSE( 4 * BPS, 4 + 4 * BPS, 8 + 4 * BPS, 12 + 4 * BPS)
  546. GET_SSE( 5 * BPS, 4 + 5 * BPS, 8 + 5 * BPS, 12 + 5 * BPS)
  547. GET_SSE( 6 * BPS, 4 + 6 * BPS, 8 + 6 * BPS, 12 + 6 * BPS)
  548. GET_SSE( 7 * BPS, 4 + 7 * BPS, 8 + 7 * BPS, 12 + 7 * BPS)
  549. "mflo %[count] \n\t"
  550. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  551. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  552. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [count]"=&r"(count)
  553. : [a]"r"(a), [b]"r"(b)
  554. : "memory", "hi", "lo"
  555. );
  556. return count;
  557. }
  558. static int SSE8x8_MIPS32(const uint8_t* a, const uint8_t* b) {
  559. int count;
  560. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
  561. __asm__ volatile(
  562. "mult $zero, $zero \n\t"
  563. GET_SSE(0 * BPS, 4 + 0 * BPS, 1 * BPS, 4 + 1 * BPS)
  564. GET_SSE(2 * BPS, 4 + 2 * BPS, 3 * BPS, 4 + 3 * BPS)
  565. GET_SSE(4 * BPS, 4 + 4 * BPS, 5 * BPS, 4 + 5 * BPS)
  566. GET_SSE(6 * BPS, 4 + 6 * BPS, 7 * BPS, 4 + 7 * BPS)
  567. "mflo %[count] \n\t"
  568. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  569. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  570. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [count]"=&r"(count)
  571. : [a]"r"(a), [b]"r"(b)
  572. : "memory", "hi", "lo"
  573. );
  574. return count;
  575. }
  576. static int SSE4x4_MIPS32(const uint8_t* a, const uint8_t* b) {
  577. int count;
  578. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
  579. __asm__ volatile(
  580. "mult $zero, $zero \n\t"
  581. GET_SSE(0 * BPS, 1 * BPS, 2 * BPS, 3 * BPS)
  582. "mflo %[count] \n\t"
  583. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  584. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  585. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [count]"=&r"(count)
  586. : [a]"r"(a), [b]"r"(b)
  587. : "memory", "hi", "lo"
  588. );
  589. return count;
  590. }
  591. #undef GET_SSE
  592. #undef GET_SSE_INNER
  593. #endif // !WORK_AROUND_GCC
  594. //------------------------------------------------------------------------------
  595. // Entry point
  596. extern void VP8EncDspInitMIPS32(void);
  597. WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInitMIPS32(void) {
  598. VP8ITransform = ITransform_MIPS32;
  599. VP8FTransform = FTransform_MIPS32;
  600. VP8EncQuantizeBlock = QuantizeBlock_MIPS32;
  601. VP8EncQuantize2Blocks = Quantize2Blocks_MIPS32;
  602. VP8TDisto4x4 = Disto4x4_MIPS32;
  603. VP8TDisto16x16 = Disto16x16_MIPS32;
  604. #if !defined(WORK_AROUND_GCC)
  605. VP8SSE16x16 = SSE16x16_MIPS32;
  606. VP8SSE8x8 = SSE8x8_MIPS32;
  607. VP8SSE16x8 = SSE16x8_MIPS32;
  608. VP8SSE4x4 = SSE4x4_MIPS32;
  609. #endif
  610. }
  611. #else // !WEBP_USE_MIPS32
  612. WEBP_DSP_INIT_STUB(VP8EncDspInitMIPS32)
  613. #endif // WEBP_USE_MIPS32