enc_mips_dsp_r2.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  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): Darko Laus (darko.laus@imgtec.com)
  13. // Mirko Raus (mirko.raus@imgtec.com)
  14. #include "./dsp.h"
  15. #if defined(WEBP_USE_MIPS_DSP_R2)
  16. #include "./mips_macro.h"
  17. #include "../enc/cost_enc.h"
  18. #include "../enc/vp8i_enc.h"
  19. static const int kC1 = 20091 + (1 << 16);
  20. static const int kC2 = 35468;
  21. // O - output
  22. // I - input (macro doesn't change it)
  23. #define ADD_SUB_HALVES_X4(O0, O1, O2, O3, O4, O5, O6, O7, \
  24. I0, I1, I2, I3, I4, I5, I6, I7) \
  25. "addq.ph %[" #O0 "], %[" #I0 "], %[" #I1 "] \n\t" \
  26. "subq.ph %[" #O1 "], %[" #I0 "], %[" #I1 "] \n\t" \
  27. "addq.ph %[" #O2 "], %[" #I2 "], %[" #I3 "] \n\t" \
  28. "subq.ph %[" #O3 "], %[" #I2 "], %[" #I3 "] \n\t" \
  29. "addq.ph %[" #O4 "], %[" #I4 "], %[" #I5 "] \n\t" \
  30. "subq.ph %[" #O5 "], %[" #I4 "], %[" #I5 "] \n\t" \
  31. "addq.ph %[" #O6 "], %[" #I6 "], %[" #I7 "] \n\t" \
  32. "subq.ph %[" #O7 "], %[" #I6 "], %[" #I7 "] \n\t"
  33. // IO - input/output
  34. #define ABS_X8(IO0, IO1, IO2, IO3, IO4, IO5, IO6, IO7) \
  35. "absq_s.ph %[" #IO0 "], %[" #IO0 "] \n\t" \
  36. "absq_s.ph %[" #IO1 "], %[" #IO1 "] \n\t" \
  37. "absq_s.ph %[" #IO2 "], %[" #IO2 "] \n\t" \
  38. "absq_s.ph %[" #IO3 "], %[" #IO3 "] \n\t" \
  39. "absq_s.ph %[" #IO4 "], %[" #IO4 "] \n\t" \
  40. "absq_s.ph %[" #IO5 "], %[" #IO5 "] \n\t" \
  41. "absq_s.ph %[" #IO6 "], %[" #IO6 "] \n\t" \
  42. "absq_s.ph %[" #IO7 "], %[" #IO7 "] \n\t"
  43. // dpa.w.ph $ac0 temp0 ,temp1
  44. // $ac += temp0[31..16] * temp1[31..16] + temp0[15..0] * temp1[15..0]
  45. // dpax.w.ph $ac0 temp0 ,temp1
  46. // $ac += temp0[31..16] * temp1[15..0] + temp0[15..0] * temp1[31..16]
  47. // O - output
  48. // I - input (macro doesn't change it)
  49. #define MUL_HALF(O0, I0, I1, I2, I3, I4, I5, I6, I7, \
  50. I8, I9, I10, I11, I12, I13, I14, I15) \
  51. "mult $ac0, $zero, $zero \n\t" \
  52. "dpa.w.ph $ac0, %[" #I2 "], %[" #I0 "] \n\t" \
  53. "dpax.w.ph $ac0, %[" #I5 "], %[" #I6 "] \n\t" \
  54. "dpa.w.ph $ac0, %[" #I8 "], %[" #I9 "] \n\t" \
  55. "dpax.w.ph $ac0, %[" #I11 "], %[" #I4 "] \n\t" \
  56. "dpa.w.ph $ac0, %[" #I12 "], %[" #I7 "] \n\t" \
  57. "dpax.w.ph $ac0, %[" #I13 "], %[" #I1 "] \n\t" \
  58. "dpa.w.ph $ac0, %[" #I14 "], %[" #I3 "] \n\t" \
  59. "dpax.w.ph $ac0, %[" #I15 "], %[" #I10 "] \n\t" \
  60. "mflo %[" #O0 "], $ac0 \n\t"
  61. #define OUTPUT_EARLY_CLOBBER_REGS_17() \
  62. OUTPUT_EARLY_CLOBBER_REGS_10(), \
  63. [temp11]"=&r"(temp11), [temp12]"=&r"(temp12), [temp13]"=&r"(temp13), \
  64. [temp14]"=&r"(temp14), [temp15]"=&r"(temp15), [temp16]"=&r"(temp16), \
  65. [temp17]"=&r"(temp17)
  66. // macro for one horizontal pass in FTransform
  67. // temp0..temp15 holds tmp[0]..tmp[15]
  68. // A - offset in bytes to load from src and ref buffers
  69. // TEMP0..TEMP3 - registers for corresponding tmp elements
  70. #define HORIZONTAL_PASS(A, TEMP0, TEMP1, TEMP2, TEMP3) \
  71. "lw %[" #TEMP0 "], 0(%[args]) \n\t" \
  72. "lw %[" #TEMP1 "], 4(%[args]) \n\t" \
  73. "lw %[" #TEMP2 "], " XSTR(BPS) "*" #A "(%[" #TEMP0 "]) \n\t" \
  74. "lw %[" #TEMP3 "], " XSTR(BPS) "*" #A "(%[" #TEMP1 "]) \n\t" \
  75. "preceu.ph.qbl %[" #TEMP0 "], %[" #TEMP2 "] \n\t" \
  76. "preceu.ph.qbl %[" #TEMP1 "], %[" #TEMP3 "] \n\t" \
  77. "preceu.ph.qbr %[" #TEMP2 "], %[" #TEMP2 "] \n\t" \
  78. "preceu.ph.qbr %[" #TEMP3 "], %[" #TEMP3 "] \n\t" \
  79. "subq.ph %[" #TEMP0 "], %[" #TEMP0 "], %[" #TEMP1 "] \n\t" \
  80. "subq.ph %[" #TEMP2 "], %[" #TEMP2 "], %[" #TEMP3 "] \n\t" \
  81. "rotr %[" #TEMP0 "], %[" #TEMP0 "], 16 \n\t" \
  82. "addq.ph %[" #TEMP1 "], %[" #TEMP2 "], %[" #TEMP0 "] \n\t" \
  83. "subq.ph %[" #TEMP3 "], %[" #TEMP2 "], %[" #TEMP0 "] \n\t" \
  84. "seh %[" #TEMP0 "], %[" #TEMP1 "] \n\t" \
  85. "sra %[temp16], %[" #TEMP1 "], 16 \n\t" \
  86. "seh %[temp19], %[" #TEMP3 "] \n\t" \
  87. "sra %[" #TEMP3 "], %[" #TEMP3 "], 16 \n\t" \
  88. "subu %[" #TEMP2 "], %[" #TEMP0 "], %[temp16] \n\t" \
  89. "addu %[" #TEMP0 "], %[" #TEMP0 "], %[temp16] \n\t" \
  90. "mul %[temp17], %[temp19], %[c2217] \n\t" \
  91. "mul %[temp18], %[" #TEMP3 "], %[c5352] \n\t" \
  92. "mul %[" #TEMP1 "], %[temp19], %[c5352] \n\t" \
  93. "mul %[temp16], %[" #TEMP3 "], %[c2217] \n\t" \
  94. "sll %[" #TEMP2 "], %[" #TEMP2 "], 3 \n\t" \
  95. "sll %[" #TEMP0 "], %[" #TEMP0 "], 3 \n\t" \
  96. "subu %[" #TEMP3 "], %[temp17], %[temp18] \n\t" \
  97. "addu %[" #TEMP1 "], %[temp16], %[" #TEMP1 "] \n\t" \
  98. "addiu %[" #TEMP3 "], %[" #TEMP3 "], 937 \n\t" \
  99. "addiu %[" #TEMP1 "], %[" #TEMP1 "], 1812 \n\t" \
  100. "sra %[" #TEMP3 "], %[" #TEMP3 "], 9 \n\t" \
  101. "sra %[" #TEMP1 "], %[" #TEMP1 "], 9 \n\t"
  102. // macro for one vertical pass in FTransform
  103. // temp0..temp15 holds tmp[0]..tmp[15]
  104. // A..D - offsets in bytes to store to out buffer
  105. // TEMP0, TEMP4, TEMP8 and TEMP12 - registers for corresponding tmp elements
  106. #define VERTICAL_PASS(A, B, C, D, TEMP0, TEMP4, TEMP8, TEMP12) \
  107. "addu %[temp16], %[" #TEMP0 "], %[" #TEMP12 "] \n\t" \
  108. "subu %[temp19], %[" #TEMP0 "], %[" #TEMP12 "] \n\t" \
  109. "addu %[temp17], %[" #TEMP4 "], %[" #TEMP8 "] \n\t" \
  110. "subu %[temp18], %[" #TEMP4 "], %[" #TEMP8 "] \n\t" \
  111. "mul %[" #TEMP8 "], %[temp19], %[c2217] \n\t" \
  112. "mul %[" #TEMP12 "], %[temp18], %[c2217] \n\t" \
  113. "mul %[" #TEMP4 "], %[temp19], %[c5352] \n\t" \
  114. "mul %[temp18], %[temp18], %[c5352] \n\t" \
  115. "addiu %[temp16], %[temp16], 7 \n\t" \
  116. "addu %[" #TEMP0 "], %[temp16], %[temp17] \n\t" \
  117. "sra %[" #TEMP0 "], %[" #TEMP0 "], 4 \n\t" \
  118. "addu %[" #TEMP12 "], %[" #TEMP12 "], %[" #TEMP4 "] \n\t" \
  119. "subu %[" #TEMP4 "], %[temp16], %[temp17] \n\t" \
  120. "sra %[" #TEMP4 "], %[" #TEMP4 "], 4 \n\t" \
  121. "addiu %[" #TEMP8 "], %[" #TEMP8 "], 30000 \n\t" \
  122. "addiu %[" #TEMP12 "], %[" #TEMP12 "], 12000 \n\t" \
  123. "addiu %[" #TEMP8 "], %[" #TEMP8 "], 21000 \n\t" \
  124. "subu %[" #TEMP8 "], %[" #TEMP8 "], %[temp18] \n\t" \
  125. "sra %[" #TEMP12 "], %[" #TEMP12 "], 16 \n\t" \
  126. "sra %[" #TEMP8 "], %[" #TEMP8 "], 16 \n\t" \
  127. "addiu %[temp16], %[" #TEMP12 "], 1 \n\t" \
  128. "movn %[" #TEMP12 "], %[temp16], %[temp19] \n\t" \
  129. "sh %[" #TEMP0 "], " #A "(%[temp20]) \n\t" \
  130. "sh %[" #TEMP4 "], " #C "(%[temp20]) \n\t" \
  131. "sh %[" #TEMP8 "], " #D "(%[temp20]) \n\t" \
  132. "sh %[" #TEMP12 "], " #B "(%[temp20]) \n\t"
  133. static void FTransform_MIPSdspR2(const uint8_t* src, const uint8_t* ref,
  134. int16_t* out) {
  135. const int c2217 = 2217;
  136. const int c5352 = 5352;
  137. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
  138. int temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16;
  139. int temp17, temp18, temp19, temp20;
  140. const int* const args[3] =
  141. { (const int*)src, (const int*)ref, (const int*)out };
  142. __asm__ volatile (
  143. HORIZONTAL_PASS(0, temp0, temp1, temp2, temp3)
  144. HORIZONTAL_PASS(1, temp4, temp5, temp6, temp7)
  145. HORIZONTAL_PASS(2, temp8, temp9, temp10, temp11)
  146. HORIZONTAL_PASS(3, temp12, temp13, temp14, temp15)
  147. "lw %[temp20], 8(%[args]) \n\t"
  148. VERTICAL_PASS(0, 8, 16, 24, temp0, temp4, temp8, temp12)
  149. VERTICAL_PASS(2, 10, 18, 26, temp1, temp5, temp9, temp13)
  150. VERTICAL_PASS(4, 12, 20, 28, temp2, temp6, temp10, temp14)
  151. VERTICAL_PASS(6, 14, 22, 30, temp3, temp7, temp11, temp15)
  152. OUTPUT_EARLY_CLOBBER_REGS_18(),
  153. [temp0]"=&r"(temp0), [temp19]"=&r"(temp19), [temp20]"=&r"(temp20)
  154. : [args]"r"(args), [c2217]"r"(c2217), [c5352]"r"(c5352)
  155. : "memory", "hi", "lo"
  156. );
  157. }
  158. #undef VERTICAL_PASS
  159. #undef HORIZONTAL_PASS
  160. static WEBP_INLINE void ITransformOne(const uint8_t* ref, const int16_t* in,
  161. uint8_t* dst) {
  162. int temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9;
  163. int temp10, temp11, temp12, temp13, temp14, temp15, temp16, temp17, temp18;
  164. __asm__ volatile (
  165. "ulw %[temp1], 0(%[in]) \n\t"
  166. "ulw %[temp2], 16(%[in]) \n\t"
  167. LOAD_IN_X2(temp5, temp6, 24, 26)
  168. ADD_SUB_HALVES(temp3, temp4, temp1, temp2)
  169. LOAD_IN_X2(temp1, temp2, 8, 10)
  170. MUL_SHIFT_SUM(temp7, temp8, temp9, temp10, temp11, temp12, temp13, temp14,
  171. temp10, temp8, temp9, temp7, temp1, temp2, temp5, temp6,
  172. temp13, temp11, temp14, temp12)
  173. INSERT_HALF_X2(temp8, temp7, temp10, temp9)
  174. "ulw %[temp17], 4(%[in]) \n\t"
  175. "ulw %[temp18], 20(%[in]) \n\t"
  176. ADD_SUB_HALVES(temp1, temp2, temp3, temp8)
  177. ADD_SUB_HALVES(temp5, temp6, temp4, temp7)
  178. ADD_SUB_HALVES(temp7, temp8, temp17, temp18)
  179. LOAD_IN_X2(temp17, temp18, 12, 14)
  180. LOAD_IN_X2(temp9, temp10, 28, 30)
  181. MUL_SHIFT_SUM(temp11, temp12, temp13, temp14, temp15, temp16, temp4, temp17,
  182. temp12, temp14, temp11, temp13, temp17, temp18, temp9, temp10,
  183. temp15, temp4, temp16, temp17)
  184. INSERT_HALF_X2(temp11, temp12, temp13, temp14)
  185. ADD_SUB_HALVES(temp17, temp8, temp8, temp11)
  186. ADD_SUB_HALVES(temp3, temp4, temp7, temp12)
  187. // horizontal
  188. SRA_16(temp9, temp10, temp11, temp12, temp1, temp2, temp5, temp6)
  189. INSERT_HALF_X2(temp1, temp6, temp5, temp2)
  190. SRA_16(temp13, temp14, temp15, temp16, temp3, temp4, temp17, temp8)
  191. "repl.ph %[temp2], 0x4 \n\t"
  192. INSERT_HALF_X2(temp3, temp8, temp17, temp4)
  193. "addq.ph %[temp1], %[temp1], %[temp2] \n\t"
  194. "addq.ph %[temp6], %[temp6], %[temp2] \n\t"
  195. ADD_SUB_HALVES(temp2, temp4, temp1, temp3)
  196. ADD_SUB_HALVES(temp5, temp7, temp6, temp8)
  197. MUL_SHIFT_SUM(temp1, temp3, temp6, temp8, temp9, temp13, temp17, temp18,
  198. temp3, temp13, temp1, temp9, temp9, temp13, temp11, temp15,
  199. temp6, temp17, temp8, temp18)
  200. MUL_SHIFT_SUM(temp6, temp8, temp18, temp17, temp11, temp15, temp12, temp16,
  201. temp8, temp15, temp6, temp11, temp12, temp16, temp10, temp14,
  202. temp18, temp12, temp17, temp16)
  203. INSERT_HALF_X2(temp1, temp3, temp9, temp13)
  204. INSERT_HALF_X2(temp6, temp8, temp11, temp15)
  205. SHIFT_R_SUM_X2(temp9, temp10, temp11, temp12, temp13, temp14, temp15,
  206. temp16, temp2, temp4, temp5, temp7, temp3, temp1, temp8,
  207. temp6)
  208. PACK_2_HALVES_TO_WORD(temp1, temp2, temp3, temp4, temp9, temp12, temp13,
  209. temp16, temp11, temp10, temp15, temp14)
  210. LOAD_WITH_OFFSET_X4(temp10, temp11, temp14, temp15, ref,
  211. 0, 0, 0, 0,
  212. 0, 1, 2, 3,
  213. BPS)
  214. CONVERT_2_BYTES_TO_HALF(temp5, temp6, temp7, temp8, temp17, temp18, temp10,
  215. temp11, temp10, temp11, temp14, temp15)
  216. STORE_SAT_SUM_X2(temp5, temp6, temp7, temp8, temp17, temp18, temp10, temp11,
  217. temp9, temp12, temp1, temp2, temp13, temp16, temp3, temp4,
  218. dst, 0, 1, 2, 3, BPS)
  219. OUTPUT_EARLY_CLOBBER_REGS_18()
  220. : [dst]"r"(dst), [in]"r"(in), [kC1]"r"(kC1), [kC2]"r"(kC2), [ref]"r"(ref)
  221. : "memory", "hi", "lo"
  222. );
  223. }
  224. static void ITransform_MIPSdspR2(const uint8_t* ref, const int16_t* in,
  225. uint8_t* dst, int do_two) {
  226. ITransformOne(ref, in, dst);
  227. if (do_two) {
  228. ITransformOne(ref + 4, in + 16, dst + 4);
  229. }
  230. }
  231. static int Disto4x4_MIPSdspR2(const uint8_t* const a, const uint8_t* const b,
  232. const uint16_t* const w) {
  233. int temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9;
  234. int temp10, temp11, temp12, temp13, temp14, temp15, temp16, temp17;
  235. __asm__ volatile (
  236. LOAD_WITH_OFFSET_X4(temp1, temp2, temp3, temp4, a,
  237. 0, 0, 0, 0,
  238. 0, 1, 2, 3,
  239. BPS)
  240. CONVERT_2_BYTES_TO_HALF(temp5, temp6, temp7, temp8, temp9,temp10, temp11,
  241. temp12, temp1, temp2, temp3, temp4)
  242. ADD_SUB_HALVES_X4(temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8,
  243. temp5, temp6, temp7, temp8, temp9, temp10, temp11, temp12)
  244. PACK_2_HALVES_TO_WORD(temp9, temp10, temp11, temp12, temp1, temp3, temp5,
  245. temp7, temp2, temp4, temp6, temp8)
  246. ADD_SUB_HALVES_X4(temp2, temp4, temp6, temp8, temp9, temp1, temp3, temp10,
  247. temp1, temp9, temp3, temp10, temp5, temp11, temp7, temp12)
  248. ADD_SUB_HALVES_X4(temp5, temp11, temp7, temp2, temp9, temp3, temp6, temp12,
  249. temp2, temp9, temp6, temp3, temp4, temp1, temp8, temp10)
  250. ADD_SUB_HALVES_X4(temp1, temp4, temp10, temp8, temp7, temp11, temp5, temp2,
  251. temp5, temp7, temp11, temp2, temp9, temp6, temp3, temp12)
  252. ABS_X8(temp1, temp4, temp10, temp8, temp7, temp11, temp5, temp2)
  253. LOAD_WITH_OFFSET_X4(temp3, temp6, temp9, temp12, w,
  254. 0, 4, 8, 12,
  255. 0, 0, 0, 0,
  256. 0)
  257. LOAD_WITH_OFFSET_X4(temp13, temp14, temp15, temp16, w,
  258. 0, 4, 8, 12,
  259. 1, 1, 1, 1,
  260. 16)
  261. MUL_HALF(temp17, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8,
  262. temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16)
  263. LOAD_WITH_OFFSET_X4(temp1, temp2, temp3, temp4, b,
  264. 0, 0, 0, 0,
  265. 0, 1, 2, 3,
  266. BPS)
  267. CONVERT_2_BYTES_TO_HALF(temp5,temp6, temp7, temp8, temp9,temp10, temp11,
  268. temp12, temp1, temp2, temp3, temp4)
  269. ADD_SUB_HALVES_X4(temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8,
  270. temp5, temp6, temp7, temp8, temp9, temp10, temp11, temp12)
  271. PACK_2_HALVES_TO_WORD(temp9, temp10, temp11, temp12, temp1, temp3, temp5,
  272. temp7, temp2, temp4, temp6, temp8)
  273. ADD_SUB_HALVES_X4(temp2, temp4, temp6, temp8, temp9, temp1, temp3, temp10,
  274. temp1, temp9, temp3, temp10, temp5, temp11, temp7, temp12)
  275. ADD_SUB_HALVES_X4(temp5, temp11, temp7, temp2, temp9, temp3, temp6, temp12,
  276. temp2, temp9, temp6, temp3, temp4, temp1, temp8, temp10)
  277. ADD_SUB_HALVES_X4(temp1, temp4, temp10, temp8, temp7, temp11, temp5, temp2,
  278. temp5, temp7, temp11, temp2, temp9, temp6, temp3, temp12)
  279. ABS_X8(temp1, temp4, temp10, temp8, temp7, temp11, temp5, temp2)
  280. LOAD_WITH_OFFSET_X4(temp3, temp6, temp9, temp12, w,
  281. 0, 4, 8, 12,
  282. 0, 0, 0, 0,
  283. 0)
  284. LOAD_WITH_OFFSET_X4(temp13, temp14, temp15, temp16, w,
  285. 0, 4, 8, 12,
  286. 1, 1, 1, 1,
  287. 16)
  288. MUL_HALF(temp3, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8,
  289. temp9, temp10, temp11, temp12, temp13, temp14, temp15, temp16)
  290. OUTPUT_EARLY_CLOBBER_REGS_17()
  291. : [a]"r"(a), [b]"r"(b), [w]"r"(w)
  292. : "memory", "hi", "lo"
  293. );
  294. return abs(temp3 - temp17) >> 5;
  295. }
  296. static int Disto16x16_MIPSdspR2(const uint8_t* const a,
  297. const uint8_t* const b,
  298. const uint16_t* const w) {
  299. int D = 0;
  300. int x, y;
  301. for (y = 0; y < 16 * BPS; y += 4 * BPS) {
  302. for (x = 0; x < 16; x += 4) {
  303. D += Disto4x4_MIPSdspR2(a + x + y, b + x + y, w);
  304. }
  305. }
  306. return D;
  307. }
  308. //------------------------------------------------------------------------------
  309. // Intra predictions
  310. #define FILL_PART(J, SIZE) \
  311. "usw %[value], 0+" #J "*" XSTR(BPS) "(%[dst]) \n\t" \
  312. "usw %[value], 4+" #J "*" XSTR(BPS) "(%[dst]) \n\t" \
  313. ".if " #SIZE " == 16 \n\t" \
  314. "usw %[value], 8+" #J "*" XSTR(BPS) "(%[dst]) \n\t" \
  315. "usw %[value], 12+" #J "*" XSTR(BPS) "(%[dst]) \n\t" \
  316. ".endif \n\t"
  317. #define FILL_8_OR_16(DST, VALUE, SIZE) do { \
  318. int value = (VALUE); \
  319. __asm__ volatile ( \
  320. "replv.qb %[value], %[value] \n\t" \
  321. FILL_PART( 0, SIZE) \
  322. FILL_PART( 1, SIZE) \
  323. FILL_PART( 2, SIZE) \
  324. FILL_PART( 3, SIZE) \
  325. FILL_PART( 4, SIZE) \
  326. FILL_PART( 5, SIZE) \
  327. FILL_PART( 6, SIZE) \
  328. FILL_PART( 7, SIZE) \
  329. ".if " #SIZE " == 16 \n\t" \
  330. FILL_PART( 8, 16) \
  331. FILL_PART( 9, 16) \
  332. FILL_PART(10, 16) \
  333. FILL_PART(11, 16) \
  334. FILL_PART(12, 16) \
  335. FILL_PART(13, 16) \
  336. FILL_PART(14, 16) \
  337. FILL_PART(15, 16) \
  338. ".endif \n\t" \
  339. : [value]"+&r"(value) \
  340. : [dst]"r"((DST)) \
  341. : "memory" \
  342. ); \
  343. } while (0)
  344. #define VERTICAL_PRED(DST, TOP, SIZE) \
  345. static WEBP_INLINE void VerticalPred##SIZE(uint8_t* (DST), \
  346. const uint8_t* (TOP)) { \
  347. int j; \
  348. if ((TOP)) { \
  349. for (j = 0; j < (SIZE); ++j) memcpy((DST) + j * BPS, (TOP), (SIZE)); \
  350. } else { \
  351. FILL_8_OR_16((DST), 127, (SIZE)); \
  352. } \
  353. }
  354. VERTICAL_PRED(dst, top, 8)
  355. VERTICAL_PRED(dst, top, 16)
  356. #undef VERTICAL_PRED
  357. #define HORIZONTAL_PRED(DST, LEFT, SIZE) \
  358. static WEBP_INLINE void HorizontalPred##SIZE(uint8_t* (DST), \
  359. const uint8_t* (LEFT)) { \
  360. if (LEFT) { \
  361. int j; \
  362. for (j = 0; j < (SIZE); ++j) { \
  363. memset((DST) + j * BPS, (LEFT)[j], (SIZE)); \
  364. } \
  365. } else { \
  366. FILL_8_OR_16((DST), 129, (SIZE)); \
  367. } \
  368. }
  369. HORIZONTAL_PRED(dst, left, 8)
  370. HORIZONTAL_PRED(dst, left, 16)
  371. #undef HORIZONTAL_PRED
  372. #define CLIPPING() \
  373. "preceu.ph.qbl %[temp2], %[temp0] \n\t" \
  374. "preceu.ph.qbr %[temp0], %[temp0] \n\t" \
  375. "preceu.ph.qbl %[temp3], %[temp1] \n\t" \
  376. "preceu.ph.qbr %[temp1], %[temp1] \n\t" \
  377. "addu.ph %[temp2], %[temp2], %[leftY_1] \n\t" \
  378. "addu.ph %[temp0], %[temp0], %[leftY_1] \n\t" \
  379. "addu.ph %[temp3], %[temp3], %[leftY_1] \n\t" \
  380. "addu.ph %[temp1], %[temp1], %[leftY_1] \n\t" \
  381. "shll_s.ph %[temp2], %[temp2], 7 \n\t" \
  382. "shll_s.ph %[temp0], %[temp0], 7 \n\t" \
  383. "shll_s.ph %[temp3], %[temp3], 7 \n\t" \
  384. "shll_s.ph %[temp1], %[temp1], 7 \n\t" \
  385. "precrqu_s.qb.ph %[temp0], %[temp2], %[temp0] \n\t" \
  386. "precrqu_s.qb.ph %[temp1], %[temp3], %[temp1] \n\t"
  387. #define CLIP_8B_TO_DST(DST, LEFT, TOP, SIZE) do { \
  388. int leftY_1 = ((int)(LEFT)[y] << 16) + (LEFT)[y]; \
  389. int temp0, temp1, temp2, temp3; \
  390. __asm__ volatile ( \
  391. "replv.ph %[leftY_1], %[leftY_1] \n\t" \
  392. "ulw %[temp0], 0(%[top]) \n\t" \
  393. "ulw %[temp1], 4(%[top]) \n\t" \
  394. "subu.ph %[leftY_1], %[leftY_1], %[left_1] \n\t" \
  395. CLIPPING() \
  396. "usw %[temp0], 0(%[dst]) \n\t" \
  397. "usw %[temp1], 4(%[dst]) \n\t" \
  398. ".if " #SIZE " == 16 \n\t" \
  399. "ulw %[temp0], 8(%[top]) \n\t" \
  400. "ulw %[temp1], 12(%[top]) \n\t" \
  401. CLIPPING() \
  402. "usw %[temp0], 8(%[dst]) \n\t" \
  403. "usw %[temp1], 12(%[dst]) \n\t" \
  404. ".endif \n\t" \
  405. : [leftY_1]"+&r"(leftY_1), [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), \
  406. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3) \
  407. : [left_1]"r"(left_1), [top]"r"((TOP)), [dst]"r"((DST)) \
  408. : "memory" \
  409. ); \
  410. } while (0)
  411. #define CLIP_TO_DST(DST, LEFT, TOP, SIZE) do { \
  412. int y; \
  413. const int left_1 = ((int)(LEFT)[-1] << 16) + (LEFT)[-1]; \
  414. for (y = 0; y < (SIZE); ++y) { \
  415. CLIP_8B_TO_DST((DST), (LEFT), (TOP), (SIZE)); \
  416. (DST) += BPS; \
  417. } \
  418. } while (0)
  419. #define TRUE_MOTION(DST, LEFT, TOP, SIZE) \
  420. static WEBP_INLINE void TrueMotion##SIZE(uint8_t* (DST), const uint8_t* (LEFT),\
  421. const uint8_t* (TOP)) { \
  422. if ((LEFT) != NULL) { \
  423. if ((TOP) != NULL) { \
  424. CLIP_TO_DST((DST), (LEFT), (TOP), (SIZE)); \
  425. } else { \
  426. HorizontalPred##SIZE((DST), (LEFT)); \
  427. } \
  428. } else { \
  429. /* true motion without left samples (hence: with default 129 value) */ \
  430. /* is equivalent to VE prediction where you just copy the top samples. */ \
  431. /* Note that if top samples are not available, the default value is */ \
  432. /* then 129, and not 127 as in the VerticalPred case. */ \
  433. if ((TOP) != NULL) { \
  434. VerticalPred##SIZE((DST), (TOP)); \
  435. } else { \
  436. FILL_8_OR_16((DST), 129, (SIZE)); \
  437. } \
  438. } \
  439. }
  440. TRUE_MOTION(dst, left, top, 8)
  441. TRUE_MOTION(dst, left, top, 16)
  442. #undef TRUE_MOTION
  443. #undef CLIP_TO_DST
  444. #undef CLIP_8B_TO_DST
  445. #undef CLIPPING
  446. static WEBP_INLINE void DCMode16(uint8_t* dst, const uint8_t* left,
  447. const uint8_t* top) {
  448. int DC, DC1;
  449. int temp0, temp1, temp2, temp3;
  450. __asm__ volatile(
  451. "beqz %[top], 2f \n\t"
  452. LOAD_WITH_OFFSET_X4(temp0, temp1, temp2, temp3, top,
  453. 0, 4, 8, 12,
  454. 0, 0, 0, 0,
  455. 0)
  456. "raddu.w.qb %[temp0], %[temp0] \n\t"
  457. "raddu.w.qb %[temp1], %[temp1] \n\t"
  458. "raddu.w.qb %[temp2], %[temp2] \n\t"
  459. "raddu.w.qb %[temp3], %[temp3] \n\t"
  460. "addu %[temp0], %[temp0], %[temp1] \n\t"
  461. "addu %[temp2], %[temp2], %[temp3] \n\t"
  462. "addu %[DC], %[temp0], %[temp2] \n\t"
  463. "move %[DC1], %[DC] \n\t"
  464. "beqz %[left], 1f \n\t"
  465. LOAD_WITH_OFFSET_X4(temp0, temp1, temp2, temp3, left,
  466. 0, 4, 8, 12,
  467. 0, 0, 0, 0,
  468. 0)
  469. "raddu.w.qb %[temp0], %[temp0] \n\t"
  470. "raddu.w.qb %[temp1], %[temp1] \n\t"
  471. "raddu.w.qb %[temp2], %[temp2] \n\t"
  472. "raddu.w.qb %[temp3], %[temp3] \n\t"
  473. "addu %[temp0], %[temp0], %[temp1] \n\t"
  474. "addu %[temp2], %[temp2], %[temp3] \n\t"
  475. "addu %[DC1], %[temp0], %[temp2] \n\t"
  476. "1: \n\t"
  477. "addu %[DC], %[DC], %[DC1] \n\t"
  478. "j 3f \n\t"
  479. "2: \n\t"
  480. "beqz %[left], 4f \n\t"
  481. LOAD_WITH_OFFSET_X4(temp0, temp1, temp2, temp3, left,
  482. 0, 4, 8, 12,
  483. 0, 0, 0, 0,
  484. 0)
  485. "raddu.w.qb %[temp0], %[temp0] \n\t"
  486. "raddu.w.qb %[temp1], %[temp1] \n\t"
  487. "raddu.w.qb %[temp2], %[temp2] \n\t"
  488. "raddu.w.qb %[temp3], %[temp3] \n\t"
  489. "addu %[temp0], %[temp0], %[temp1] \n\t"
  490. "addu %[temp2], %[temp2], %[temp3] \n\t"
  491. "addu %[DC], %[temp0], %[temp2] \n\t"
  492. "addu %[DC], %[DC], %[DC] \n\t"
  493. "3: \n\t"
  494. "shra_r.w %[DC], %[DC], 5 \n\t"
  495. "j 5f \n\t"
  496. "4: \n\t"
  497. "li %[DC], 0x80 \n\t"
  498. "5: \n\t"
  499. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [DC]"=&r"(DC),
  500. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), [DC1]"=&r"(DC1)
  501. : [left]"r"(left), [top]"r"(top)
  502. : "memory"
  503. );
  504. FILL_8_OR_16(dst, DC, 16);
  505. }
  506. static WEBP_INLINE void DCMode8(uint8_t* dst, const uint8_t* left,
  507. const uint8_t* top) {
  508. int DC, DC1;
  509. int temp0, temp1, temp2, temp3;
  510. __asm__ volatile(
  511. "beqz %[top], 2f \n\t"
  512. "ulw %[temp0], 0(%[top]) \n\t"
  513. "ulw %[temp1], 4(%[top]) \n\t"
  514. "raddu.w.qb %[temp0], %[temp0] \n\t"
  515. "raddu.w.qb %[temp1], %[temp1] \n\t"
  516. "addu %[DC], %[temp0], %[temp1] \n\t"
  517. "move %[DC1], %[DC] \n\t"
  518. "beqz %[left], 1f \n\t"
  519. "ulw %[temp2], 0(%[left]) \n\t"
  520. "ulw %[temp3], 4(%[left]) \n\t"
  521. "raddu.w.qb %[temp2], %[temp2] \n\t"
  522. "raddu.w.qb %[temp3], %[temp3] \n\t"
  523. "addu %[DC1], %[temp2], %[temp3] \n\t"
  524. "1: \n\t"
  525. "addu %[DC], %[DC], %[DC1] \n\t"
  526. "j 3f \n\t"
  527. "2: \n\t"
  528. "beqz %[left], 4f \n\t"
  529. "ulw %[temp2], 0(%[left]) \n\t"
  530. "ulw %[temp3], 4(%[left]) \n\t"
  531. "raddu.w.qb %[temp2], %[temp2] \n\t"
  532. "raddu.w.qb %[temp3], %[temp3] \n\t"
  533. "addu %[DC], %[temp2], %[temp3] \n\t"
  534. "addu %[DC], %[DC], %[DC] \n\t"
  535. "3: \n\t"
  536. "shra_r.w %[DC], %[DC], 4 \n\t"
  537. "j 5f \n\t"
  538. "4: \n\t"
  539. "li %[DC], 0x80 \n\t"
  540. "5: \n\t"
  541. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [DC]"=&r"(DC),
  542. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), [DC1]"=&r"(DC1)
  543. : [left]"r"(left), [top]"r"(top)
  544. : "memory"
  545. );
  546. FILL_8_OR_16(dst, DC, 8);
  547. }
  548. static void DC4(uint8_t* dst, const uint8_t* top) {
  549. int temp0, temp1;
  550. __asm__ volatile(
  551. "ulw %[temp0], 0(%[top]) \n\t"
  552. "ulw %[temp1], -5(%[top]) \n\t"
  553. "raddu.w.qb %[temp0], %[temp0] \n\t"
  554. "raddu.w.qb %[temp1], %[temp1] \n\t"
  555. "addu %[temp0], %[temp0], %[temp1] \n\t"
  556. "addiu %[temp0], %[temp0], 4 \n\t"
  557. "srl %[temp0], %[temp0], 3 \n\t"
  558. "replv.qb %[temp0], %[temp0] \n\t"
  559. "usw %[temp0], 0*" XSTR(BPS) "(%[dst]) \n\t"
  560. "usw %[temp0], 1*" XSTR(BPS) "(%[dst]) \n\t"
  561. "usw %[temp0], 2*" XSTR(BPS) "(%[dst]) \n\t"
  562. "usw %[temp0], 3*" XSTR(BPS) "(%[dst]) \n\t"
  563. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1)
  564. : [top]"r"(top), [dst]"r"(dst)
  565. : "memory"
  566. );
  567. }
  568. static void TM4(uint8_t* dst, const uint8_t* top) {
  569. int a10, a32, temp0, temp1, temp2, temp3, temp4, temp5;
  570. const int c35 = 0xff00ff;
  571. __asm__ volatile (
  572. "lbu %[temp1], 0(%[top]) \n\t"
  573. "lbu %[a10], 1(%[top]) \n\t"
  574. "lbu %[temp2], 2(%[top]) \n\t"
  575. "lbu %[a32], 3(%[top]) \n\t"
  576. "ulw %[temp0], -5(%[top]) \n\t"
  577. "lbu %[temp4], -1(%[top]) \n\t"
  578. "append %[a10], %[temp1], 16 \n\t"
  579. "append %[a32], %[temp2], 16 \n\t"
  580. "replv.ph %[temp4], %[temp4] \n\t"
  581. "shrl.ph %[temp1], %[temp0], 8 \n\t"
  582. "and %[temp0], %[temp0], %[c35] \n\t"
  583. "subu.ph %[temp1], %[temp1], %[temp4] \n\t"
  584. "subu.ph %[temp0], %[temp0], %[temp4] \n\t"
  585. "srl %[temp2], %[temp1], 16 \n\t"
  586. "srl %[temp3], %[temp0], 16 \n\t"
  587. "replv.ph %[temp2], %[temp2] \n\t"
  588. "replv.ph %[temp3], %[temp3] \n\t"
  589. "replv.ph %[temp4], %[temp1] \n\t"
  590. "replv.ph %[temp5], %[temp0] \n\t"
  591. "addu.ph %[temp0], %[temp3], %[a10] \n\t"
  592. "addu.ph %[temp1], %[temp3], %[a32] \n\t"
  593. "addu.ph %[temp3], %[temp2], %[a10] \n\t"
  594. "addu.ph %[temp2], %[temp2], %[a32] \n\t"
  595. "shll_s.ph %[temp0], %[temp0], 7 \n\t"
  596. "shll_s.ph %[temp1], %[temp1], 7 \n\t"
  597. "shll_s.ph %[temp3], %[temp3], 7 \n\t"
  598. "shll_s.ph %[temp2], %[temp2], 7 \n\t"
  599. "precrqu_s.qb.ph %[temp0], %[temp1], %[temp0] \n\t"
  600. "precrqu_s.qb.ph %[temp1], %[temp2], %[temp3] \n\t"
  601. "addu.ph %[temp2], %[temp5], %[a10] \n\t"
  602. "addu.ph %[temp3], %[temp5], %[a32] \n\t"
  603. "addu.ph %[temp5], %[temp4], %[a10] \n\t"
  604. "addu.ph %[temp4], %[temp4], %[a32] \n\t"
  605. "shll_s.ph %[temp2], %[temp2], 7 \n\t"
  606. "shll_s.ph %[temp3], %[temp3], 7 \n\t"
  607. "shll_s.ph %[temp4], %[temp4], 7 \n\t"
  608. "shll_s.ph %[temp5], %[temp5], 7 \n\t"
  609. "precrqu_s.qb.ph %[temp2], %[temp3], %[temp2] \n\t"
  610. "precrqu_s.qb.ph %[temp3], %[temp4], %[temp5] \n\t"
  611. "usw %[temp1], 0*" XSTR(BPS) "(%[dst]) \n\t"
  612. "usw %[temp0], 1*" XSTR(BPS) "(%[dst]) \n\t"
  613. "usw %[temp3], 2*" XSTR(BPS) "(%[dst]) \n\t"
  614. "usw %[temp2], 3*" XSTR(BPS) "(%[dst]) \n\t"
  615. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  616. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  617. [a10]"=&r"(a10), [a32]"=&r"(a32)
  618. : [c35]"r"(c35), [top]"r"(top), [dst]"r"(dst)
  619. : "memory"
  620. );
  621. }
  622. static void VE4(uint8_t* dst, const uint8_t* top) {
  623. int temp0, temp1, temp2, temp3, temp4, temp5, temp6;
  624. __asm__ volatile(
  625. "ulw %[temp0], -1(%[top]) \n\t"
  626. "ulh %[temp1], 3(%[top]) \n\t"
  627. "preceu.ph.qbr %[temp2], %[temp0] \n\t"
  628. "preceu.ph.qbl %[temp3], %[temp0] \n\t"
  629. "preceu.ph.qbr %[temp4], %[temp1] \n\t"
  630. "packrl.ph %[temp5], %[temp3], %[temp2] \n\t"
  631. "packrl.ph %[temp6], %[temp4], %[temp3] \n\t"
  632. "shll.ph %[temp5], %[temp5], 1 \n\t"
  633. "shll.ph %[temp6], %[temp6], 1 \n\t"
  634. "addq.ph %[temp2], %[temp5], %[temp2] \n\t"
  635. "addq.ph %[temp6], %[temp6], %[temp4] \n\t"
  636. "addq.ph %[temp2], %[temp2], %[temp3] \n\t"
  637. "addq.ph %[temp6], %[temp6], %[temp3] \n\t"
  638. "shra_r.ph %[temp2], %[temp2], 2 \n\t"
  639. "shra_r.ph %[temp6], %[temp6], 2 \n\t"
  640. "precr.qb.ph %[temp4], %[temp6], %[temp2] \n\t"
  641. "usw %[temp4], 0*" XSTR(BPS) "(%[dst]) \n\t"
  642. "usw %[temp4], 1*" XSTR(BPS) "(%[dst]) \n\t"
  643. "usw %[temp4], 2*" XSTR(BPS) "(%[dst]) \n\t"
  644. "usw %[temp4], 3*" XSTR(BPS) "(%[dst]) \n\t"
  645. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  646. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  647. [temp6]"=&r"(temp6)
  648. : [top]"r"(top), [dst]"r"(dst)
  649. : "memory"
  650. );
  651. }
  652. static void HE4(uint8_t* dst, const uint8_t* top) {
  653. int temp0, temp1, temp2, temp3, temp4, temp5, temp6;
  654. __asm__ volatile(
  655. "ulw %[temp0], -4(%[top]) \n\t"
  656. "lbu %[temp1], -5(%[top]) \n\t"
  657. "preceu.ph.qbr %[temp2], %[temp0] \n\t"
  658. "preceu.ph.qbl %[temp3], %[temp0] \n\t"
  659. "replv.ph %[temp4], %[temp1] \n\t"
  660. "packrl.ph %[temp5], %[temp3], %[temp2] \n\t"
  661. "packrl.ph %[temp6], %[temp2], %[temp4] \n\t"
  662. "shll.ph %[temp5], %[temp5], 1 \n\t"
  663. "shll.ph %[temp6], %[temp6], 1 \n\t"
  664. "addq.ph %[temp3], %[temp3], %[temp5] \n\t"
  665. "addq.ph %[temp3], %[temp3], %[temp2] \n\t"
  666. "addq.ph %[temp2], %[temp2], %[temp6] \n\t"
  667. "addq.ph %[temp2], %[temp2], %[temp4] \n\t"
  668. "shra_r.ph %[temp3], %[temp3], 2 \n\t"
  669. "shra_r.ph %[temp2], %[temp2], 2 \n\t"
  670. "replv.qb %[temp0], %[temp3] \n\t"
  671. "replv.qb %[temp1], %[temp2] \n\t"
  672. "srl %[temp3], %[temp3], 16 \n\t"
  673. "srl %[temp2], %[temp2], 16 \n\t"
  674. "replv.qb %[temp3], %[temp3] \n\t"
  675. "replv.qb %[temp2], %[temp2] \n\t"
  676. "usw %[temp3], 0*" XSTR(BPS) "(%[dst]) \n\t"
  677. "usw %[temp0], 1*" XSTR(BPS) "(%[dst]) \n\t"
  678. "usw %[temp2], 2*" XSTR(BPS) "(%[dst]) \n\t"
  679. "usw %[temp1], 3*" XSTR(BPS) "(%[dst]) \n\t"
  680. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  681. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  682. [temp6]"=&r"(temp6)
  683. : [top]"r"(top), [dst]"r"(dst)
  684. : "memory"
  685. );
  686. }
  687. static void RD4(uint8_t* dst, const uint8_t* top) {
  688. int temp0, temp1, temp2, temp3, temp4, temp5;
  689. int temp6, temp7, temp8, temp9, temp10, temp11;
  690. __asm__ volatile(
  691. "ulw %[temp0], -5(%[top]) \n\t"
  692. "ulw %[temp1], -1(%[top]) \n\t"
  693. "preceu.ph.qbl %[temp2], %[temp0] \n\t"
  694. "preceu.ph.qbr %[temp3], %[temp0] \n\t"
  695. "preceu.ph.qbr %[temp4], %[temp1] \n\t"
  696. "preceu.ph.qbl %[temp5], %[temp1] \n\t"
  697. "packrl.ph %[temp6], %[temp2], %[temp3] \n\t"
  698. "packrl.ph %[temp7], %[temp4], %[temp2] \n\t"
  699. "packrl.ph %[temp8], %[temp5], %[temp4] \n\t"
  700. "shll.ph %[temp6], %[temp6], 1 \n\t"
  701. "addq.ph %[temp9], %[temp2], %[temp6] \n\t"
  702. "shll.ph %[temp7], %[temp7], 1 \n\t"
  703. "addq.ph %[temp9], %[temp9], %[temp3] \n\t"
  704. "shll.ph %[temp8], %[temp8], 1 \n\t"
  705. "shra_r.ph %[temp9], %[temp9], 2 \n\t"
  706. "addq.ph %[temp10], %[temp4], %[temp7] \n\t"
  707. "addq.ph %[temp11], %[temp5], %[temp8] \n\t"
  708. "addq.ph %[temp10], %[temp10], %[temp2] \n\t"
  709. "addq.ph %[temp11], %[temp11], %[temp4] \n\t"
  710. "shra_r.ph %[temp10], %[temp10], 2 \n\t"
  711. "shra_r.ph %[temp11], %[temp11], 2 \n\t"
  712. "lbu %[temp0], 3(%[top]) \n\t"
  713. "lbu %[temp1], 2(%[top]) \n\t"
  714. "lbu %[temp2], 1(%[top]) \n\t"
  715. "sll %[temp1], %[temp1], 1 \n\t"
  716. "addu %[temp0], %[temp0], %[temp1] \n\t"
  717. "addu %[temp0], %[temp0], %[temp2] \n\t"
  718. "precr.qb.ph %[temp9], %[temp10], %[temp9] \n\t"
  719. "shra_r.w %[temp0], %[temp0], 2 \n\t"
  720. "precr.qb.ph %[temp10], %[temp11], %[temp10] \n\t"
  721. "usw %[temp9], 3*" XSTR(BPS) "(%[dst]) \n\t"
  722. "usw %[temp10], 1*" XSTR(BPS) "(%[dst]) \n\t"
  723. "prepend %[temp9], %[temp11], 8 \n\t"
  724. "prepend %[temp10], %[temp0], 8 \n\t"
  725. "usw %[temp9], 2*" XSTR(BPS) "(%[dst]) \n\t"
  726. "usw %[temp10], 0*" XSTR(BPS) "(%[dst]) \n\t"
  727. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  728. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  729. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8),
  730. [temp9]"=&r"(temp9), [temp10]"=&r"(temp10), [temp11]"=&r"(temp11)
  731. : [top]"r"(top), [dst]"r"(dst)
  732. : "memory"
  733. );
  734. }
  735. static void VR4(uint8_t* dst, const uint8_t* top) {
  736. int temp0, temp1, temp2, temp3, temp4;
  737. int temp5, temp6, temp7, temp8, temp9;
  738. __asm__ volatile (
  739. "ulw %[temp0], -4(%[top]) \n\t"
  740. "ulw %[temp1], 0(%[top]) \n\t"
  741. "preceu.ph.qbl %[temp2], %[temp0] \n\t"
  742. "preceu.ph.qbr %[temp0], %[temp0] \n\t"
  743. "preceu.ph.qbla %[temp3], %[temp1] \n\t"
  744. "preceu.ph.qbra %[temp1], %[temp1] \n\t"
  745. "packrl.ph %[temp7], %[temp3], %[temp2] \n\t"
  746. "addqh_r.ph %[temp4], %[temp1], %[temp3] \n\t"
  747. "move %[temp6], %[temp1] \n\t"
  748. "append %[temp1], %[temp2], 16 \n\t"
  749. "shll.ph %[temp9], %[temp6], 1 \n\t"
  750. "addqh_r.ph %[temp5], %[temp7], %[temp6] \n\t"
  751. "shll.ph %[temp8], %[temp7], 1 \n\t"
  752. "addu.ph %[temp3], %[temp7], %[temp3] \n\t"
  753. "addu.ph %[temp1], %[temp1], %[temp6] \n\t"
  754. "packrl.ph %[temp7], %[temp2], %[temp0] \n\t"
  755. "addu.ph %[temp6], %[temp0], %[temp2] \n\t"
  756. "addu.ph %[temp3], %[temp3], %[temp9] \n\t"
  757. "addu.ph %[temp1], %[temp1], %[temp8] \n\t"
  758. "shll.ph %[temp7], %[temp7], 1 \n\t"
  759. "shra_r.ph %[temp3], %[temp3], 2 \n\t"
  760. "shra_r.ph %[temp1], %[temp1], 2 \n\t"
  761. "addu.ph %[temp6], %[temp6], %[temp7] \n\t"
  762. "shra_r.ph %[temp6], %[temp6], 2 \n\t"
  763. "precrq.ph.w %[temp8], %[temp4], %[temp5] \n\t"
  764. "append %[temp4], %[temp5], 16 \n\t"
  765. "precrq.ph.w %[temp2], %[temp3], %[temp1] \n\t"
  766. "append %[temp3], %[temp1], 16 \n\t"
  767. "precr.qb.ph %[temp8], %[temp8], %[temp4] \n\t"
  768. "precr.qb.ph %[temp3], %[temp2], %[temp3] \n\t"
  769. "usw %[temp8], 0*" XSTR(BPS) "(%[dst]) \n\t"
  770. "usw %[temp3], 1*" XSTR(BPS) "(%[dst]) \n\t"
  771. "append %[temp3], %[temp6], 8 \n\t"
  772. "srl %[temp6], %[temp6], 16 \n\t"
  773. "append %[temp8], %[temp6], 8 \n\t"
  774. "usw %[temp3], 3*" XSTR(BPS) "(%[dst]) \n\t"
  775. "usw %[temp8], 2*" XSTR(BPS) "(%[dst]) \n\t"
  776. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  777. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  778. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8),
  779. [temp9]"=&r"(temp9)
  780. : [top]"r"(top), [dst]"r"(dst)
  781. : "memory"
  782. );
  783. }
  784. static void LD4(uint8_t* dst, const uint8_t* top) {
  785. int temp0, temp1, temp2, temp3, temp4, temp5;
  786. int temp6, temp7, temp8, temp9, temp10, temp11;
  787. __asm__ volatile(
  788. "ulw %[temp0], 0(%[top]) \n\t"
  789. "ulw %[temp1], 4(%[top]) \n\t"
  790. "preceu.ph.qbl %[temp2], %[temp0] \n\t"
  791. "preceu.ph.qbr %[temp3], %[temp0] \n\t"
  792. "preceu.ph.qbr %[temp4], %[temp1] \n\t"
  793. "preceu.ph.qbl %[temp5], %[temp1] \n\t"
  794. "packrl.ph %[temp6], %[temp2], %[temp3] \n\t"
  795. "packrl.ph %[temp7], %[temp4], %[temp2] \n\t"
  796. "packrl.ph %[temp8], %[temp5], %[temp4] \n\t"
  797. "shll.ph %[temp6], %[temp6], 1 \n\t"
  798. "addq.ph %[temp9], %[temp2], %[temp6] \n\t"
  799. "shll.ph %[temp7], %[temp7], 1 \n\t"
  800. "addq.ph %[temp9], %[temp9], %[temp3] \n\t"
  801. "shll.ph %[temp8], %[temp8], 1 \n\t"
  802. "shra_r.ph %[temp9], %[temp9], 2 \n\t"
  803. "addq.ph %[temp10], %[temp4], %[temp7] \n\t"
  804. "addq.ph %[temp11], %[temp5], %[temp8] \n\t"
  805. "addq.ph %[temp10], %[temp10], %[temp2] \n\t"
  806. "addq.ph %[temp11], %[temp11], %[temp4] \n\t"
  807. "shra_r.ph %[temp10], %[temp10], 2 \n\t"
  808. "shra_r.ph %[temp11], %[temp11], 2 \n\t"
  809. "srl %[temp1], %[temp1], 24 \n\t"
  810. "sll %[temp1], %[temp1], 1 \n\t"
  811. "raddu.w.qb %[temp5], %[temp5] \n\t"
  812. "precr.qb.ph %[temp9], %[temp10], %[temp9] \n\t"
  813. "precr.qb.ph %[temp10], %[temp11], %[temp10] \n\t"
  814. "addu %[temp1], %[temp1], %[temp5] \n\t"
  815. "shra_r.w %[temp1], %[temp1], 2 \n\t"
  816. "usw %[temp9], 0*" XSTR(BPS) "(%[dst]) \n\t"
  817. "usw %[temp10], 2*" XSTR(BPS) "(%[dst]) \n\t"
  818. "prepend %[temp9], %[temp11], 8 \n\t"
  819. "prepend %[temp10], %[temp1], 8 \n\t"
  820. "usw %[temp9], 1*" XSTR(BPS) "(%[dst]) \n\t"
  821. "usw %[temp10], 3*" XSTR(BPS) "(%[dst]) \n\t"
  822. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  823. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  824. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8),
  825. [temp9]"=&r"(temp9), [temp10]"=&r"(temp10), [temp11]"=&r"(temp11)
  826. : [top]"r"(top), [dst]"r"(dst)
  827. : "memory"
  828. );
  829. }
  830. static void VL4(uint8_t* dst, const uint8_t* top) {
  831. int temp0, temp1, temp2, temp3, temp4;
  832. int temp5, temp6, temp7, temp8, temp9;
  833. __asm__ volatile (
  834. "ulw %[temp0], 0(%[top]) \n\t"
  835. "ulw %[temp1], 4(%[top]) \n\t"
  836. "preceu.ph.qbla %[temp2], %[temp0] \n\t"
  837. "preceu.ph.qbra %[temp0], %[temp0] \n\t"
  838. "preceu.ph.qbl %[temp3], %[temp1] \n\t"
  839. "preceu.ph.qbr %[temp1], %[temp1] \n\t"
  840. "addqh_r.ph %[temp4], %[temp0], %[temp2] \n\t"
  841. "packrl.ph %[temp7], %[temp1], %[temp0] \n\t"
  842. "precrq.ph.w %[temp6], %[temp1], %[temp2] \n\t"
  843. "shll.ph %[temp9], %[temp2], 1 \n\t"
  844. "addqh_r.ph %[temp5], %[temp7], %[temp2] \n\t"
  845. "shll.ph %[temp8], %[temp7], 1 \n\t"
  846. "addu.ph %[temp2], %[temp2], %[temp6] \n\t"
  847. "addu.ph %[temp0], %[temp0], %[temp7] \n\t"
  848. "packrl.ph %[temp7], %[temp3], %[temp1] \n\t"
  849. "addu.ph %[temp6], %[temp1], %[temp3] \n\t"
  850. "addu.ph %[temp2], %[temp2], %[temp8] \n\t"
  851. "addu.ph %[temp0], %[temp0], %[temp9] \n\t"
  852. "shll.ph %[temp7], %[temp7], 1 \n\t"
  853. "shra_r.ph %[temp2], %[temp2], 2 \n\t"
  854. "shra_r.ph %[temp0], %[temp0], 2 \n\t"
  855. "addu.ph %[temp6], %[temp6], %[temp7] \n\t"
  856. "shra_r.ph %[temp6], %[temp6], 2 \n\t"
  857. "precrq.ph.w %[temp8], %[temp5], %[temp4] \n\t"
  858. "append %[temp5], %[temp4], 16 \n\t"
  859. "precrq.ph.w %[temp3], %[temp2], %[temp0] \n\t"
  860. "append %[temp2], %[temp0], 16 \n\t"
  861. "precr.qb.ph %[temp8], %[temp8], %[temp5] \n\t"
  862. "precr.qb.ph %[temp3], %[temp3], %[temp2] \n\t"
  863. "usw %[temp8], 0*" XSTR(BPS) "(%[dst]) \n\t"
  864. "prepend %[temp8], %[temp6], 8 \n\t"
  865. "usw %[temp3], 1*" XSTR(BPS) "(%[dst]) \n\t"
  866. "srl %[temp6], %[temp6], 16 \n\t"
  867. "prepend %[temp3], %[temp6], 8 \n\t"
  868. "usw %[temp8], 2*" XSTR(BPS) "(%[dst]) \n\t"
  869. "usw %[temp3], 3*" XSTR(BPS) "(%[dst]) \n\t"
  870. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  871. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  872. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8),
  873. [temp9]"=&r"(temp9)
  874. : [top]"r"(top), [dst]"r"(dst)
  875. : "memory"
  876. );
  877. }
  878. static void HD4(uint8_t* dst, const uint8_t* top) {
  879. int temp0, temp1, temp2, temp3, temp4;
  880. int temp5, temp6, temp7, temp8, temp9;
  881. __asm__ volatile (
  882. "ulw %[temp0], -5(%[top]) \n\t"
  883. "ulw %[temp1], -1(%[top]) \n\t"
  884. "preceu.ph.qbla %[temp2], %[temp0] \n\t"
  885. "preceu.ph.qbra %[temp0], %[temp0] \n\t"
  886. "preceu.ph.qbl %[temp3], %[temp1] \n\t"
  887. "preceu.ph.qbr %[temp1], %[temp1] \n\t"
  888. "addqh_r.ph %[temp4], %[temp0], %[temp2] \n\t"
  889. "packrl.ph %[temp7], %[temp1], %[temp0] \n\t"
  890. "precrq.ph.w %[temp6], %[temp1], %[temp2] \n\t"
  891. "shll.ph %[temp9], %[temp2], 1 \n\t"
  892. "addqh_r.ph %[temp5], %[temp7], %[temp2] \n\t"
  893. "shll.ph %[temp8], %[temp7], 1 \n\t"
  894. "addu.ph %[temp2], %[temp2], %[temp6] \n\t"
  895. "addu.ph %[temp0], %[temp0], %[temp7] \n\t"
  896. "packrl.ph %[temp7], %[temp3], %[temp1] \n\t"
  897. "addu.ph %[temp6], %[temp1], %[temp3] \n\t"
  898. "addu.ph %[temp2], %[temp2], %[temp8] \n\t"
  899. "addu.ph %[temp0], %[temp0], %[temp9] \n\t"
  900. "shll.ph %[temp7], %[temp7], 1 \n\t"
  901. "shra_r.ph %[temp2], %[temp2], 2 \n\t"
  902. "shra_r.ph %[temp0], %[temp0], 2 \n\t"
  903. "addu.ph %[temp6], %[temp6], %[temp7] \n\t"
  904. "shra_r.ph %[temp6], %[temp6], 2 \n\t"
  905. "precrq.ph.w %[temp1], %[temp2], %[temp5] \n\t"
  906. "precrq.ph.w %[temp3], %[temp0], %[temp4] \n\t"
  907. "precr.qb.ph %[temp7], %[temp6], %[temp1] \n\t"
  908. "precr.qb.ph %[temp6], %[temp1], %[temp3] \n\t"
  909. "usw %[temp7], 0*" XSTR(BPS) "(%[dst]) \n\t"
  910. "usw %[temp6], 1*" XSTR(BPS) "(%[dst]) \n\t"
  911. "append %[temp2], %[temp5], 16 \n\t"
  912. "append %[temp0], %[temp4], 16 \n\t"
  913. "precr.qb.ph %[temp5], %[temp3], %[temp2] \n\t"
  914. "precr.qb.ph %[temp4], %[temp2], %[temp0] \n\t"
  915. "usw %[temp5], 2*" XSTR(BPS) "(%[dst]) \n\t"
  916. "usw %[temp4], 3*" XSTR(BPS) "(%[dst]) \n\t"
  917. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  918. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  919. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8),
  920. [temp9]"=&r"(temp9)
  921. : [top]"r"(top), [dst]"r"(dst)
  922. : "memory"
  923. );
  924. }
  925. static void HU4(uint8_t* dst, const uint8_t* top) {
  926. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
  927. __asm__ volatile (
  928. "ulw %[temp0], -5(%[top]) \n\t"
  929. "preceu.ph.qbl %[temp1], %[temp0] \n\t"
  930. "preceu.ph.qbr %[temp2], %[temp0] \n\t"
  931. "packrl.ph %[temp3], %[temp1], %[temp2] \n\t"
  932. "replv.qb %[temp7], %[temp2] \n\t"
  933. "addqh_r.ph %[temp4], %[temp1], %[temp3] \n\t"
  934. "addqh_r.ph %[temp5], %[temp3], %[temp2] \n\t"
  935. "shll.ph %[temp6], %[temp3], 1 \n\t"
  936. "addu.ph %[temp3], %[temp2], %[temp3] \n\t"
  937. "addu.ph %[temp6], %[temp1], %[temp6] \n\t"
  938. "shll.ph %[temp0], %[temp2], 1 \n\t"
  939. "addu.ph %[temp6], %[temp6], %[temp2] \n\t"
  940. "addu.ph %[temp0], %[temp3], %[temp0] \n\t"
  941. "shra_r.ph %[temp6], %[temp6], 2 \n\t"
  942. "shra_r.ph %[temp0], %[temp0], 2 \n\t"
  943. "packrl.ph %[temp3], %[temp6], %[temp5] \n\t"
  944. "precrq.ph.w %[temp2], %[temp6], %[temp4] \n\t"
  945. "append %[temp0], %[temp5], 16 \n\t"
  946. "precr.qb.ph %[temp3], %[temp3], %[temp2] \n\t"
  947. "usw %[temp3], 0*" XSTR(BPS) "(%[dst]) \n\t"
  948. "precr.qb.ph %[temp1], %[temp7], %[temp0] \n\t"
  949. "usw %[temp7], 3*" XSTR(BPS) "(%[dst]) \n\t"
  950. "packrl.ph %[temp2], %[temp1], %[temp3] \n\t"
  951. "usw %[temp1], 2*" XSTR(BPS) "(%[dst]) \n\t"
  952. "usw %[temp2], 1*" XSTR(BPS) "(%[dst]) \n\t"
  953. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  954. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  955. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7)
  956. : [top]"r"(top), [dst]"r"(dst)
  957. : "memory"
  958. );
  959. }
  960. //------------------------------------------------------------------------------
  961. // Chroma 8x8 prediction (paragraph 12.2)
  962. static void IntraChromaPreds_MIPSdspR2(uint8_t* dst, const uint8_t* left,
  963. const uint8_t* top) {
  964. // U block
  965. DCMode8(C8DC8 + dst, left, top);
  966. VerticalPred8(C8VE8 + dst, top);
  967. HorizontalPred8(C8HE8 + dst, left);
  968. TrueMotion8(C8TM8 + dst, left, top);
  969. // V block
  970. dst += 8;
  971. if (top) top += 8;
  972. if (left) left += 16;
  973. DCMode8(C8DC8 + dst, left, top);
  974. VerticalPred8(C8VE8 + dst, top);
  975. HorizontalPred8(C8HE8 + dst, left);
  976. TrueMotion8(C8TM8 + dst, left, top);
  977. }
  978. //------------------------------------------------------------------------------
  979. // luma 16x16 prediction (paragraph 12.3)
  980. static void Intra16Preds_MIPSdspR2(uint8_t* dst,
  981. const uint8_t* left, const uint8_t* top) {
  982. DCMode16(I16DC16 + dst, left, top);
  983. VerticalPred16(I16VE16 + dst, top);
  984. HorizontalPred16(I16HE16 + dst, left);
  985. TrueMotion16(I16TM16 + dst, left, top);
  986. }
  987. // Left samples are top[-5 .. -2], top_left is top[-1], top are
  988. // located at top[0..3], and top right is top[4..7]
  989. static void Intra4Preds_MIPSdspR2(uint8_t* dst, const uint8_t* top) {
  990. DC4(I4DC4 + dst, top);
  991. TM4(I4TM4 + dst, top);
  992. VE4(I4VE4 + dst, top);
  993. HE4(I4HE4 + dst, top);
  994. RD4(I4RD4 + dst, top);
  995. VR4(I4VR4 + dst, top);
  996. LD4(I4LD4 + dst, top);
  997. VL4(I4VL4 + dst, top);
  998. HD4(I4HD4 + dst, top);
  999. HU4(I4HU4 + dst, top);
  1000. }
  1001. //------------------------------------------------------------------------------
  1002. // Metric
  1003. #if !defined(WORK_AROUND_GCC)
  1004. #define GET_SSE_INNER(A) \
  1005. "lw %[temp0], " #A "(%[a]) \n\t" \
  1006. "lw %[temp1], " #A "(%[b]) \n\t" \
  1007. "preceu.ph.qbr %[temp2], %[temp0] \n\t" \
  1008. "preceu.ph.qbl %[temp0], %[temp0] \n\t" \
  1009. "preceu.ph.qbr %[temp3], %[temp1] \n\t" \
  1010. "preceu.ph.qbl %[temp1], %[temp1] \n\t" \
  1011. "subq.ph %[temp2], %[temp2], %[temp3] \n\t" \
  1012. "subq.ph %[temp0], %[temp0], %[temp1] \n\t" \
  1013. "dpa.w.ph $ac0, %[temp2], %[temp2] \n\t" \
  1014. "dpa.w.ph $ac0, %[temp0], %[temp0] \n\t"
  1015. #define GET_SSE(A, B, C, D) \
  1016. GET_SSE_INNER(A) \
  1017. GET_SSE_INNER(B) \
  1018. GET_SSE_INNER(C) \
  1019. GET_SSE_INNER(D)
  1020. static int SSE16x16_MIPSdspR2(const uint8_t* a, const uint8_t* b) {
  1021. int count;
  1022. int temp0, temp1, temp2, temp3;
  1023. __asm__ volatile (
  1024. "mult $zero, $zero \n\t"
  1025. GET_SSE( 0 * BPS, 4 + 0 * BPS, 8 + 0 * BPS, 12 + 0 * BPS)
  1026. GET_SSE( 1 * BPS, 4 + 1 * BPS, 8 + 1 * BPS, 12 + 1 * BPS)
  1027. GET_SSE( 2 * BPS, 4 + 2 * BPS, 8 + 2 * BPS, 12 + 2 * BPS)
  1028. GET_SSE( 3 * BPS, 4 + 3 * BPS, 8 + 3 * BPS, 12 + 3 * BPS)
  1029. GET_SSE( 4 * BPS, 4 + 4 * BPS, 8 + 4 * BPS, 12 + 4 * BPS)
  1030. GET_SSE( 5 * BPS, 4 + 5 * BPS, 8 + 5 * BPS, 12 + 5 * BPS)
  1031. GET_SSE( 6 * BPS, 4 + 6 * BPS, 8 + 6 * BPS, 12 + 6 * BPS)
  1032. GET_SSE( 7 * BPS, 4 + 7 * BPS, 8 + 7 * BPS, 12 + 7 * BPS)
  1033. GET_SSE( 8 * BPS, 4 + 8 * BPS, 8 + 8 * BPS, 12 + 8 * BPS)
  1034. GET_SSE( 9 * BPS, 4 + 9 * BPS, 8 + 9 * BPS, 12 + 9 * BPS)
  1035. GET_SSE(10 * BPS, 4 + 10 * BPS, 8 + 10 * BPS, 12 + 10 * BPS)
  1036. GET_SSE(11 * BPS, 4 + 11 * BPS, 8 + 11 * BPS, 12 + 11 * BPS)
  1037. GET_SSE(12 * BPS, 4 + 12 * BPS, 8 + 12 * BPS, 12 + 12 * BPS)
  1038. GET_SSE(13 * BPS, 4 + 13 * BPS, 8 + 13 * BPS, 12 + 13 * BPS)
  1039. GET_SSE(14 * BPS, 4 + 14 * BPS, 8 + 14 * BPS, 12 + 14 * BPS)
  1040. GET_SSE(15 * BPS, 4 + 15 * BPS, 8 + 15 * BPS, 12 + 15 * BPS)
  1041. "mflo %[count] \n\t"
  1042. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  1043. [temp3]"=&r"(temp3), [count]"=&r"(count)
  1044. : [a]"r"(a), [b]"r"(b)
  1045. : "memory", "hi", "lo"
  1046. );
  1047. return count;
  1048. }
  1049. static int SSE16x8_MIPSdspR2(const uint8_t* a, const uint8_t* b) {
  1050. int count;
  1051. int temp0, temp1, temp2, temp3;
  1052. __asm__ volatile (
  1053. "mult $zero, $zero \n\t"
  1054. GET_SSE( 0 * BPS, 4 + 0 * BPS, 8 + 0 * BPS, 12 + 0 * BPS)
  1055. GET_SSE( 1 * BPS, 4 + 1 * BPS, 8 + 1 * BPS, 12 + 1 * BPS)
  1056. GET_SSE( 2 * BPS, 4 + 2 * BPS, 8 + 2 * BPS, 12 + 2 * BPS)
  1057. GET_SSE( 3 * BPS, 4 + 3 * BPS, 8 + 3 * BPS, 12 + 3 * BPS)
  1058. GET_SSE( 4 * BPS, 4 + 4 * BPS, 8 + 4 * BPS, 12 + 4 * BPS)
  1059. GET_SSE( 5 * BPS, 4 + 5 * BPS, 8 + 5 * BPS, 12 + 5 * BPS)
  1060. GET_SSE( 6 * BPS, 4 + 6 * BPS, 8 + 6 * BPS, 12 + 6 * BPS)
  1061. GET_SSE( 7 * BPS, 4 + 7 * BPS, 8 + 7 * BPS, 12 + 7 * BPS)
  1062. "mflo %[count] \n\t"
  1063. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  1064. [temp3]"=&r"(temp3), [count]"=&r"(count)
  1065. : [a]"r"(a), [b]"r"(b)
  1066. : "memory", "hi", "lo"
  1067. );
  1068. return count;
  1069. }
  1070. static int SSE8x8_MIPSdspR2(const uint8_t* a, const uint8_t* b) {
  1071. int count;
  1072. int temp0, temp1, temp2, temp3;
  1073. __asm__ volatile (
  1074. "mult $zero, $zero \n\t"
  1075. GET_SSE(0 * BPS, 4 + 0 * BPS, 1 * BPS, 4 + 1 * BPS)
  1076. GET_SSE(2 * BPS, 4 + 2 * BPS, 3 * BPS, 4 + 3 * BPS)
  1077. GET_SSE(4 * BPS, 4 + 4 * BPS, 5 * BPS, 4 + 5 * BPS)
  1078. GET_SSE(6 * BPS, 4 + 6 * BPS, 7 * BPS, 4 + 7 * BPS)
  1079. "mflo %[count] \n\t"
  1080. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  1081. [temp3]"=&r"(temp3), [count]"=&r"(count)
  1082. : [a]"r"(a), [b]"r"(b)
  1083. : "memory", "hi", "lo"
  1084. );
  1085. return count;
  1086. }
  1087. static int SSE4x4_MIPSdspR2(const uint8_t* a, const uint8_t* b) {
  1088. int count;
  1089. int temp0, temp1, temp2, temp3;
  1090. __asm__ volatile (
  1091. "mult $zero, $zero \n\t"
  1092. GET_SSE(0 * BPS, 1 * BPS, 2 * BPS, 3 * BPS)
  1093. "mflo %[count] \n\t"
  1094. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  1095. [temp3]"=&r"(temp3), [count]"=&r"(count)
  1096. : [a]"r"(a), [b]"r"(b)
  1097. : "memory", "hi", "lo"
  1098. );
  1099. return count;
  1100. }
  1101. #undef GET_SSE
  1102. #undef GET_SSE_INNER
  1103. #endif // !WORK_AROUND_GCC
  1104. #undef FILL_8_OR_16
  1105. #undef FILL_PART
  1106. #undef OUTPUT_EARLY_CLOBBER_REGS_17
  1107. #undef MUL_HALF
  1108. #undef ABS_X8
  1109. #undef ADD_SUB_HALVES_X4
  1110. //------------------------------------------------------------------------------
  1111. // Quantization
  1112. //
  1113. // macro for one pass through for loop in QuantizeBlock reading 2 values at time
  1114. // QUANTDIV macro inlined
  1115. // J - offset in bytes (kZigzag[n] * 2)
  1116. // K - offset in bytes (kZigzag[n] * 4)
  1117. // N - offset in bytes (n * 2)
  1118. // N1 - offset in bytes ((n + 1) * 2)
  1119. #define QUANTIZE_ONE(J, K, N, N1) \
  1120. "ulw %[temp1], " #J "(%[ppin]) \n\t" \
  1121. "ulw %[temp2], " #J "(%[ppsharpen]) \n\t" \
  1122. "lhu %[temp3], " #K "(%[ppzthresh]) \n\t" \
  1123. "lhu %[temp6], " #K "+4(%[ppzthresh]) \n\t" \
  1124. "absq_s.ph %[temp4], %[temp1] \n\t" \
  1125. "ins %[temp3], %[temp6], 16, 16 \n\t" \
  1126. "addu.ph %[coeff], %[temp4], %[temp2] \n\t" \
  1127. "shra.ph %[sign], %[temp1], 15 \n\t" \
  1128. "li %[level], 0x10001 \n\t" \
  1129. "cmp.lt.ph %[temp3], %[coeff] \n\t" \
  1130. "lhu %[temp1], " #J "(%[ppiq]) \n\t" \
  1131. "pick.ph %[temp5], %[level], $0 \n\t" \
  1132. "lw %[temp2], " #K "(%[ppbias]) \n\t" \
  1133. "beqz %[temp5], 0f \n\t" \
  1134. "lhu %[temp3], " #J "(%[ppq]) \n\t" \
  1135. "beq %[temp5], %[level], 1f \n\t" \
  1136. "andi %[temp5], %[temp5], 0x1 \n\t" \
  1137. "andi %[temp4], %[coeff], 0xffff \n\t" \
  1138. "beqz %[temp5], 2f \n\t" \
  1139. "mul %[level], %[temp4], %[temp1] \n\t" \
  1140. "sh $0, " #J "+2(%[ppin]) \n\t" \
  1141. "sh $0, " #N1 "(%[pout]) \n\t" \
  1142. "addu %[level], %[level], %[temp2] \n\t" \
  1143. "sra %[level], %[level], 17 \n\t" \
  1144. "slt %[temp4], %[max_level], %[level] \n\t" \
  1145. "movn %[level], %[max_level], %[temp4] \n\t" \
  1146. "andi %[temp6], %[sign], 0xffff \n\t" \
  1147. "xor %[level], %[level], %[temp6] \n\t" \
  1148. "subu %[level], %[level], %[temp6] \n\t" \
  1149. "mul %[temp5], %[level], %[temp3] \n\t" \
  1150. "or %[ret], %[ret], %[level] \n\t" \
  1151. "sh %[level], " #N "(%[pout]) \n\t" \
  1152. "sh %[temp5], " #J "(%[ppin]) \n\t" \
  1153. "j 3f \n\t" \
  1154. "2: \n\t" \
  1155. "lhu %[temp1], " #J "+2(%[ppiq]) \n\t" \
  1156. "srl %[temp5], %[coeff], 16 \n\t" \
  1157. "mul %[level], %[temp5], %[temp1] \n\t" \
  1158. "lw %[temp2], " #K "+4(%[ppbias]) \n\t" \
  1159. "lhu %[temp3], " #J "+2(%[ppq]) \n\t" \
  1160. "addu %[level], %[level], %[temp2] \n\t" \
  1161. "sra %[level], %[level], 17 \n\t" \
  1162. "srl %[temp6], %[sign], 16 \n\t" \
  1163. "slt %[temp4], %[max_level], %[level] \n\t" \
  1164. "movn %[level], %[max_level], %[temp4] \n\t" \
  1165. "xor %[level], %[level], %[temp6] \n\t" \
  1166. "subu %[level], %[level], %[temp6] \n\t" \
  1167. "mul %[temp5], %[level], %[temp3] \n\t" \
  1168. "sh $0, " #J "(%[ppin]) \n\t" \
  1169. "sh $0, " #N "(%[pout]) \n\t" \
  1170. "or %[ret], %[ret], %[level] \n\t" \
  1171. "sh %[temp5], " #J "+2(%[ppin]) \n\t" \
  1172. "sh %[level], " #N1 "(%[pout]) \n\t" \
  1173. "j 3f \n\t" \
  1174. "1: \n\t" \
  1175. "lhu %[temp1], " #J "(%[ppiq]) \n\t" \
  1176. "lw %[temp2], " #K "(%[ppbias]) \n\t" \
  1177. "ulw %[temp3], " #J "(%[ppq]) \n\t" \
  1178. "andi %[temp5], %[coeff], 0xffff \n\t" \
  1179. "srl %[temp0], %[coeff], 16 \n\t" \
  1180. "lhu %[temp6], " #J "+2(%[ppiq]) \n\t" \
  1181. "lw %[coeff], " #K "+4(%[ppbias]) \n\t" \
  1182. "mul %[level], %[temp5], %[temp1] \n\t" \
  1183. "mul %[temp4], %[temp0], %[temp6] \n\t" \
  1184. "addu %[level], %[level], %[temp2] \n\t" \
  1185. "addu %[temp4], %[temp4], %[coeff] \n\t" \
  1186. "precrq.ph.w %[level], %[temp4], %[level] \n\t" \
  1187. "shra.ph %[level], %[level], 1 \n\t" \
  1188. "cmp.lt.ph %[max_level1],%[level] \n\t" \
  1189. "pick.ph %[level], %[max_level], %[level] \n\t" \
  1190. "xor %[level], %[level], %[sign] \n\t" \
  1191. "subu.ph %[level], %[level], %[sign] \n\t" \
  1192. "mul.ph %[temp3], %[level], %[temp3] \n\t" \
  1193. "or %[ret], %[ret], %[level] \n\t" \
  1194. "sh %[level], " #N "(%[pout]) \n\t" \
  1195. "srl %[level], %[level], 16 \n\t" \
  1196. "sh %[level], " #N1 "(%[pout]) \n\t" \
  1197. "usw %[temp3], " #J "(%[ppin]) \n\t" \
  1198. "j 3f \n\t" \
  1199. "0: \n\t" \
  1200. "sh $0, " #N "(%[pout]) \n\t" \
  1201. "sh $0, " #N1 "(%[pout]) \n\t" \
  1202. "usw $0, " #J "(%[ppin]) \n\t" \
  1203. "3: \n\t"
  1204. static int QuantizeBlock_MIPSdspR2(int16_t in[16], int16_t out[16],
  1205. const VP8Matrix* const mtx) {
  1206. int temp0, temp1, temp2, temp3, temp4, temp5,temp6;
  1207. int sign, coeff, level;
  1208. int max_level = MAX_LEVEL;
  1209. int max_level1 = max_level << 16 | max_level;
  1210. int ret = 0;
  1211. int16_t* ppin = &in[0];
  1212. int16_t* pout = &out[0];
  1213. const uint16_t* ppsharpen = &mtx->sharpen_[0];
  1214. const uint32_t* ppzthresh = &mtx->zthresh_[0];
  1215. const uint16_t* ppq = &mtx->q_[0];
  1216. const uint16_t* ppiq = &mtx->iq_[0];
  1217. const uint32_t* ppbias = &mtx->bias_[0];
  1218. __asm__ volatile (
  1219. QUANTIZE_ONE( 0, 0, 0, 2)
  1220. QUANTIZE_ONE( 4, 8, 10, 12)
  1221. QUANTIZE_ONE( 8, 16, 4, 8)
  1222. QUANTIZE_ONE(12, 24, 14, 24)
  1223. QUANTIZE_ONE(16, 32, 6, 16)
  1224. QUANTIZE_ONE(20, 40, 22, 26)
  1225. QUANTIZE_ONE(24, 48, 18, 20)
  1226. QUANTIZE_ONE(28, 56, 28, 30)
  1227. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1),
  1228. [temp2]"=&r"(temp2), [temp3]"=&r"(temp3),
  1229. [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  1230. [sign]"=&r"(sign), [coeff]"=&r"(coeff),
  1231. [level]"=&r"(level), [temp6]"=&r"(temp6), [ret]"+&r"(ret)
  1232. : [ppin]"r"(ppin), [pout]"r"(pout), [max_level1]"r"(max_level1),
  1233. [ppiq]"r"(ppiq), [max_level]"r"(max_level),
  1234. [ppbias]"r"(ppbias), [ppzthresh]"r"(ppzthresh),
  1235. [ppsharpen]"r"(ppsharpen), [ppq]"r"(ppq)
  1236. : "memory", "hi", "lo"
  1237. );
  1238. return (ret != 0);
  1239. }
  1240. static int Quantize2Blocks_MIPSdspR2(int16_t in[32], int16_t out[32],
  1241. const VP8Matrix* const mtx) {
  1242. int nz;
  1243. nz = QuantizeBlock_MIPSdspR2(in + 0 * 16, out + 0 * 16, mtx) << 0;
  1244. nz |= QuantizeBlock_MIPSdspR2(in + 1 * 16, out + 1 * 16, mtx) << 1;
  1245. return nz;
  1246. }
  1247. #undef QUANTIZE_ONE
  1248. // macro for one horizontal pass in FTransformWHT
  1249. // temp0..temp7 holds tmp[0]..tmp[15]
  1250. // A, B, C, D - offset in bytes to load from in buffer
  1251. // TEMP0, TEMP1 - registers for corresponding tmp elements
  1252. #define HORIZONTAL_PASS_WHT(A, B, C, D, TEMP0, TEMP1) \
  1253. "lh %[" #TEMP0 "], " #A "(%[in]) \n\t" \
  1254. "lh %[" #TEMP1 "], " #B "(%[in]) \n\t" \
  1255. "lh %[temp8], " #C "(%[in]) \n\t" \
  1256. "lh %[temp9], " #D "(%[in]) \n\t" \
  1257. "ins %[" #TEMP1 "], %[" #TEMP0 "], 16, 16 \n\t" \
  1258. "ins %[temp9], %[temp8], 16, 16 \n\t" \
  1259. "subq.ph %[temp8], %[" #TEMP1 "], %[temp9] \n\t" \
  1260. "addq.ph %[temp9], %[" #TEMP1 "], %[temp9] \n\t" \
  1261. "precrq.ph.w %[" #TEMP0 "], %[temp8], %[temp9] \n\t" \
  1262. "append %[temp8], %[temp9], 16 \n\t" \
  1263. "subq.ph %[" #TEMP1 "], %[" #TEMP0 "], %[temp8] \n\t" \
  1264. "addq.ph %[" #TEMP0 "], %[" #TEMP0 "], %[temp8] \n\t" \
  1265. "rotr %[" #TEMP1 "], %[" #TEMP1 "], 16 \n\t"
  1266. // macro for one vertical pass in FTransformWHT
  1267. // temp0..temp7 holds tmp[0]..tmp[15]
  1268. // A, B, C, D - offsets in bytes to store to out buffer
  1269. // TEMP0, TEMP2, TEMP4 and TEMP6 - registers for corresponding tmp elements
  1270. #define VERTICAL_PASS_WHT(A, B, C, D, TEMP0, TEMP2, TEMP4, TEMP6) \
  1271. "addq.ph %[temp8], %[" #TEMP0 "], %[" #TEMP4 "] \n\t" \
  1272. "addq.ph %[temp9], %[" #TEMP2 "], %[" #TEMP6 "] \n\t" \
  1273. "subq.ph %[" #TEMP2 "], %[" #TEMP2 "], %[" #TEMP6 "] \n\t" \
  1274. "subq.ph %[" #TEMP6 "], %[" #TEMP0 "], %[" #TEMP4 "] \n\t" \
  1275. "addqh.ph %[" #TEMP0 "], %[temp8], %[temp9] \n\t" \
  1276. "subqh.ph %[" #TEMP4 "], %[" #TEMP6 "], %[" #TEMP2 "] \n\t" \
  1277. "addqh.ph %[" #TEMP2 "], %[" #TEMP2 "], %[" #TEMP6 "] \n\t" \
  1278. "subqh.ph %[" #TEMP6 "], %[temp8], %[temp9] \n\t" \
  1279. "usw %[" #TEMP0 "], " #A "(%[out]) \n\t" \
  1280. "usw %[" #TEMP2 "], " #B "(%[out]) \n\t" \
  1281. "usw %[" #TEMP4 "], " #C "(%[out]) \n\t" \
  1282. "usw %[" #TEMP6 "], " #D "(%[out]) \n\t"
  1283. static void FTransformWHT_MIPSdspR2(const int16_t* in, int16_t* out) {
  1284. int temp0, temp1, temp2, temp3, temp4;
  1285. int temp5, temp6, temp7, temp8, temp9;
  1286. __asm__ volatile (
  1287. HORIZONTAL_PASS_WHT( 0, 32, 64, 96, temp0, temp1)
  1288. HORIZONTAL_PASS_WHT(128, 160, 192, 224, temp2, temp3)
  1289. HORIZONTAL_PASS_WHT(256, 288, 320, 352, temp4, temp5)
  1290. HORIZONTAL_PASS_WHT(384, 416, 448, 480, temp6, temp7)
  1291. VERTICAL_PASS_WHT(0, 8, 16, 24, temp0, temp2, temp4, temp6)
  1292. VERTICAL_PASS_WHT(4, 12, 20, 28, temp1, temp3, temp5, temp7)
  1293. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  1294. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  1295. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8),
  1296. [temp9]"=&r"(temp9)
  1297. : [in]"r"(in), [out]"r"(out)
  1298. : "memory"
  1299. );
  1300. }
  1301. #undef VERTICAL_PASS_WHT
  1302. #undef HORIZONTAL_PASS_WHT
  1303. // macro for converting coefficients to bin
  1304. // convert 8 coeffs at time
  1305. // A, B, C, D - offsets in bytes to load from out buffer
  1306. #define CONVERT_COEFFS_TO_BIN(A, B, C, D) \
  1307. "ulw %[temp0], " #A "(%[out]) \n\t" \
  1308. "ulw %[temp1], " #B "(%[out]) \n\t" \
  1309. "ulw %[temp2], " #C "(%[out]) \n\t" \
  1310. "ulw %[temp3], " #D "(%[out]) \n\t" \
  1311. "absq_s.ph %[temp0], %[temp0] \n\t" \
  1312. "absq_s.ph %[temp1], %[temp1] \n\t" \
  1313. "absq_s.ph %[temp2], %[temp2] \n\t" \
  1314. "absq_s.ph %[temp3], %[temp3] \n\t" \
  1315. "shra.ph %[temp0], %[temp0], 3 \n\t" \
  1316. "shra.ph %[temp1], %[temp1], 3 \n\t" \
  1317. "shra.ph %[temp2], %[temp2], 3 \n\t" \
  1318. "shra.ph %[temp3], %[temp3], 3 \n\t" \
  1319. "shll_s.ph %[temp0], %[temp0], 10 \n\t" \
  1320. "shll_s.ph %[temp1], %[temp1], 10 \n\t" \
  1321. "shll_s.ph %[temp2], %[temp2], 10 \n\t" \
  1322. "shll_s.ph %[temp3], %[temp3], 10 \n\t" \
  1323. "shrl.ph %[temp0], %[temp0], 10 \n\t" \
  1324. "shrl.ph %[temp1], %[temp1], 10 \n\t" \
  1325. "shrl.ph %[temp2], %[temp2], 10 \n\t" \
  1326. "shrl.ph %[temp3], %[temp3], 10 \n\t" \
  1327. "shll.ph %[temp0], %[temp0], 2 \n\t" \
  1328. "shll.ph %[temp1], %[temp1], 2 \n\t" \
  1329. "shll.ph %[temp2], %[temp2], 2 \n\t" \
  1330. "shll.ph %[temp3], %[temp3], 2 \n\t" \
  1331. "ext %[temp4], %[temp0], 0, 16 \n\t" \
  1332. "ext %[temp0], %[temp0], 16, 16 \n\t" \
  1333. "addu %[temp4], %[temp4], %[dist] \n\t" \
  1334. "addu %[temp0], %[temp0], %[dist] \n\t" \
  1335. "ext %[temp5], %[temp1], 0, 16 \n\t" \
  1336. "lw %[temp8], 0(%[temp4]) \n\t" \
  1337. "ext %[temp1], %[temp1], 16, 16 \n\t" \
  1338. "addu %[temp5], %[temp5], %[dist] \n\t" \
  1339. "addiu %[temp8], %[temp8], 1 \n\t" \
  1340. "sw %[temp8], 0(%[temp4]) \n\t" \
  1341. "lw %[temp8], 0(%[temp0]) \n\t" \
  1342. "addu %[temp1], %[temp1], %[dist] \n\t" \
  1343. "ext %[temp6], %[temp2], 0, 16 \n\t" \
  1344. "addiu %[temp8], %[temp8], 1 \n\t" \
  1345. "sw %[temp8], 0(%[temp0]) \n\t" \
  1346. "lw %[temp8], 0(%[temp5]) \n\t" \
  1347. "ext %[temp2], %[temp2], 16, 16 \n\t" \
  1348. "addu %[temp6], %[temp6], %[dist] \n\t" \
  1349. "addiu %[temp8], %[temp8], 1 \n\t" \
  1350. "sw %[temp8], 0(%[temp5]) \n\t" \
  1351. "lw %[temp8], 0(%[temp1]) \n\t" \
  1352. "addu %[temp2], %[temp2], %[dist] \n\t" \
  1353. "ext %[temp7], %[temp3], 0, 16 \n\t" \
  1354. "addiu %[temp8], %[temp8], 1 \n\t" \
  1355. "sw %[temp8], 0(%[temp1]) \n\t" \
  1356. "lw %[temp8], 0(%[temp6]) \n\t" \
  1357. "ext %[temp3], %[temp3], 16, 16 \n\t" \
  1358. "addu %[temp7], %[temp7], %[dist] \n\t" \
  1359. "addiu %[temp8], %[temp8], 1 \n\t" \
  1360. "sw %[temp8], 0(%[temp6]) \n\t" \
  1361. "lw %[temp8], 0(%[temp2]) \n\t" \
  1362. "addu %[temp3], %[temp3], %[dist] \n\t" \
  1363. "addiu %[temp8], %[temp8], 1 \n\t" \
  1364. "sw %[temp8], 0(%[temp2]) \n\t" \
  1365. "lw %[temp8], 0(%[temp7]) \n\t" \
  1366. "addiu %[temp8], %[temp8], 1 \n\t" \
  1367. "sw %[temp8], 0(%[temp7]) \n\t" \
  1368. "lw %[temp8], 0(%[temp3]) \n\t" \
  1369. "addiu %[temp8], %[temp8], 1 \n\t" \
  1370. "sw %[temp8], 0(%[temp3]) \n\t"
  1371. static void CollectHistogram_MIPSdspR2(const uint8_t* ref, const uint8_t* pred,
  1372. int start_block, int end_block,
  1373. VP8Histogram* const histo) {
  1374. int j;
  1375. int distribution[MAX_COEFF_THRESH + 1] = { 0 };
  1376. const int max_coeff = (MAX_COEFF_THRESH << 16) + MAX_COEFF_THRESH;
  1377. for (j = start_block; j < end_block; ++j) {
  1378. int16_t out[16];
  1379. int temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
  1380. VP8FTransform(ref + VP8DspScan[j], pred + VP8DspScan[j], out);
  1381. // Convert coefficients to bin.
  1382. __asm__ volatile (
  1383. CONVERT_COEFFS_TO_BIN( 0, 4, 8, 12)
  1384. CONVERT_COEFFS_TO_BIN(16, 20, 24, 28)
  1385. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  1386. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),
  1387. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7), [temp8]"=&r"(temp8)
  1388. : [dist]"r"(distribution), [out]"r"(out), [max_coeff]"r"(max_coeff)
  1389. : "memory"
  1390. );
  1391. }
  1392. VP8SetHistogramData(distribution, histo);
  1393. }
  1394. #undef CONVERT_COEFFS_TO_BIN
  1395. //------------------------------------------------------------------------------
  1396. // Entry point
  1397. extern void VP8EncDspInitMIPSdspR2(void);
  1398. WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInitMIPSdspR2(void) {
  1399. VP8FTransform = FTransform_MIPSdspR2;
  1400. VP8FTransformWHT = FTransformWHT_MIPSdspR2;
  1401. VP8ITransform = ITransform_MIPSdspR2;
  1402. VP8TDisto4x4 = Disto4x4_MIPSdspR2;
  1403. VP8TDisto16x16 = Disto16x16_MIPSdspR2;
  1404. VP8EncPredLuma16 = Intra16Preds_MIPSdspR2;
  1405. VP8EncPredChroma8 = IntraChromaPreds_MIPSdspR2;
  1406. VP8EncPredLuma4 = Intra4Preds_MIPSdspR2;
  1407. #if !defined(WORK_AROUND_GCC)
  1408. VP8SSE16x16 = SSE16x16_MIPSdspR2;
  1409. VP8SSE8x8 = SSE8x8_MIPSdspR2;
  1410. VP8SSE16x8 = SSE16x8_MIPSdspR2;
  1411. VP8SSE4x4 = SSE4x4_MIPSdspR2;
  1412. #endif
  1413. VP8EncQuantizeBlock = QuantizeBlock_MIPSdspR2;
  1414. VP8EncQuantize2Blocks = Quantize2Blocks_MIPSdspR2;
  1415. VP8CollectHistogram = CollectHistogram_MIPSdspR2;
  1416. }
  1417. #else // !WEBP_USE_MIPS_DSP_R2
  1418. WEBP_DSP_INIT_STUB(VP8EncDspInitMIPSdspR2)
  1419. #endif // WEBP_USE_MIPS_DSP_R2