enc_mips_dsp_r2.c 80 KB

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