aaccoder_mips.c 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498
  1. /*
  2. * Copyright (c) 2012
  3. * MIPS Technologies, Inc., California.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
  14. * contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * Author: Stanislav Ocovaj (socovaj@mips.com)
  30. * Szabolcs Pal (sabolc@mips.com)
  31. *
  32. * AAC coefficients encoder optimized for MIPS floating-point architecture
  33. *
  34. * This file is part of FFmpeg.
  35. *
  36. * FFmpeg is free software; you can redistribute it and/or
  37. * modify it under the terms of the GNU Lesser General Public
  38. * License as published by the Free Software Foundation; either
  39. * version 2.1 of the License, or (at your option) any later version.
  40. *
  41. * FFmpeg is distributed in the hope that it will be useful,
  42. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  44. * Lesser General Public License for more details.
  45. *
  46. * You should have received a copy of the GNU Lesser General Public
  47. * License along with FFmpeg; if not, write to the Free Software
  48. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  49. */
  50. /**
  51. * @file
  52. * Reference: libavcodec/aaccoder.c
  53. */
  54. #include "libavutil/libm.h"
  55. #include <float.h>
  56. #include "libavutil/mathematics.h"
  57. #include "libavcodec/avcodec.h"
  58. #include "libavcodec/put_bits.h"
  59. #include "libavcodec/aac.h"
  60. #include "libavcodec/aacenc.h"
  61. #include "libavcodec/aactab.h"
  62. #if HAVE_INLINE_ASM
  63. typedef struct BandCodingPath {
  64. int prev_idx;
  65. float cost;
  66. int run;
  67. } BandCodingPath;
  68. static const uint8_t run_value_bits_long[64] = {
  69. 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  70. 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10,
  71. 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
  72. 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 15
  73. };
  74. static const uint8_t run_value_bits_short[16] = {
  75. 3, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 9
  76. };
  77. static const uint8_t * const run_value_bits[2] = {
  78. run_value_bits_long, run_value_bits_short
  79. };
  80. static const uint8_t uquad_sign_bits[81] = {
  81. 0, 1, 1, 1, 2, 2, 1, 2, 2,
  82. 1, 2, 2, 2, 3, 3, 2, 3, 3,
  83. 1, 2, 2, 2, 3, 3, 2, 3, 3,
  84. 1, 2, 2, 2, 3, 3, 2, 3, 3,
  85. 2, 3, 3, 3, 4, 4, 3, 4, 4,
  86. 2, 3, 3, 3, 4, 4, 3, 4, 4,
  87. 1, 2, 2, 2, 3, 3, 2, 3, 3,
  88. 2, 3, 3, 3, 4, 4, 3, 4, 4,
  89. 2, 3, 3, 3, 4, 4, 3, 4, 4
  90. };
  91. static const uint8_t upair7_sign_bits[64] = {
  92. 0, 1, 1, 1, 1, 1, 1, 1,
  93. 1, 2, 2, 2, 2, 2, 2, 2,
  94. 1, 2, 2, 2, 2, 2, 2, 2,
  95. 1, 2, 2, 2, 2, 2, 2, 2,
  96. 1, 2, 2, 2, 2, 2, 2, 2,
  97. 1, 2, 2, 2, 2, 2, 2, 2,
  98. 1, 2, 2, 2, 2, 2, 2, 2,
  99. 1, 2, 2, 2, 2, 2, 2, 2,
  100. };
  101. static const uint8_t upair12_sign_bits[169] = {
  102. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  103. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  104. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  105. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  106. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  107. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  108. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  109. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  110. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  111. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  112. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  113. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  114. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
  115. };
  116. static const uint8_t esc_sign_bits[289] = {
  117. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  118. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  119. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  120. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  121. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  122. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  123. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  124. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  125. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  126. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  127. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  128. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  129. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  130. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  131. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  132. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  133. 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
  134. };
  135. static void abs_pow34_v(float *out, const float *in, const int size) {
  136. #ifndef USE_REALLY_FULL_SEARCH
  137. int i;
  138. float a, b, c, d;
  139. float ax, bx, cx, dx;
  140. for (i = 0; i < size; i += 4) {
  141. a = fabsf(in[i ]);
  142. b = fabsf(in[i+1]);
  143. c = fabsf(in[i+2]);
  144. d = fabsf(in[i+3]);
  145. ax = sqrtf(a);
  146. bx = sqrtf(b);
  147. cx = sqrtf(c);
  148. dx = sqrtf(d);
  149. a = a * ax;
  150. b = b * bx;
  151. c = c * cx;
  152. d = d * dx;
  153. out[i ] = sqrtf(a);
  154. out[i+1] = sqrtf(b);
  155. out[i+2] = sqrtf(c);
  156. out[i+3] = sqrtf(d);
  157. }
  158. #endif /* USE_REALLY_FULL_SEARCH */
  159. }
  160. static float find_max_val(int group_len, int swb_size, const float *scaled) {
  161. float maxval = 0.0f;
  162. int w2, i;
  163. for (w2 = 0; w2 < group_len; w2++) {
  164. for (i = 0; i < swb_size; i++) {
  165. maxval = FFMAX(maxval, scaled[w2*128+i]);
  166. }
  167. }
  168. return maxval;
  169. }
  170. static int find_min_book(float maxval, int sf) {
  171. float Q = ff_aac_pow2sf_tab[POW_SF2_ZERO - sf + SCALE_ONE_POS - SCALE_DIV_512];
  172. float Q34 = sqrtf(Q * sqrtf(Q));
  173. int qmaxval, cb;
  174. qmaxval = maxval * Q34 + 0.4054f;
  175. if (qmaxval == 0) cb = 0;
  176. else if (qmaxval == 1) cb = 1;
  177. else if (qmaxval == 2) cb = 3;
  178. else if (qmaxval <= 4) cb = 5;
  179. else if (qmaxval <= 7) cb = 7;
  180. else if (qmaxval <= 12) cb = 9;
  181. else cb = 11;
  182. return cb;
  183. }
  184. /**
  185. * Functions developed from template function and optimized for quantizing and encoding band
  186. */
  187. static void quantize_and_encode_band_cost_SQUAD_mips(struct AACEncContext *s,
  188. PutBitContext *pb, const float *in,
  189. const float *scaled, int size, int scale_idx,
  190. int cb, const float lambda, const float uplim,
  191. int *bits)
  192. {
  193. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  194. int i;
  195. int qc1, qc2, qc3, qc4;
  196. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  197. uint16_t *p_codes = (uint16_t *)ff_aac_spectral_codes[cb-1];
  198. abs_pow34_v(s->scoefs, in, size);
  199. scaled = s->scoefs;
  200. for (i = 0; i < size; i += 4) {
  201. int curidx;
  202. int *in_int = (int *)&in[i];
  203. qc1 = scaled[i ] * Q34 + 0.4054f;
  204. qc2 = scaled[i+1] * Q34 + 0.4054f;
  205. qc3 = scaled[i+2] * Q34 + 0.4054f;
  206. qc4 = scaled[i+3] * Q34 + 0.4054f;
  207. __asm__ volatile (
  208. ".set push \n\t"
  209. ".set noreorder \n\t"
  210. "slt %[qc1], $zero, %[qc1] \n\t"
  211. "slt %[qc2], $zero, %[qc2] \n\t"
  212. "slt %[qc3], $zero, %[qc3] \n\t"
  213. "slt %[qc4], $zero, %[qc4] \n\t"
  214. "lw $t0, 0(%[in_int]) \n\t"
  215. "lw $t1, 4(%[in_int]) \n\t"
  216. "lw $t2, 8(%[in_int]) \n\t"
  217. "lw $t3, 12(%[in_int]) \n\t"
  218. "srl $t0, $t0, 31 \n\t"
  219. "srl $t1, $t1, 31 \n\t"
  220. "srl $t2, $t2, 31 \n\t"
  221. "srl $t3, $t3, 31 \n\t"
  222. "subu $t4, $zero, %[qc1] \n\t"
  223. "subu $t5, $zero, %[qc2] \n\t"
  224. "subu $t6, $zero, %[qc3] \n\t"
  225. "subu $t7, $zero, %[qc4] \n\t"
  226. "movn %[qc1], $t4, $t0 \n\t"
  227. "movn %[qc2], $t5, $t1 \n\t"
  228. "movn %[qc3], $t6, $t2 \n\t"
  229. "movn %[qc4], $t7, $t3 \n\t"
  230. ".set pop \n\t"
  231. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  232. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  233. : [in_int]"r"(in_int)
  234. : "t0", "t1", "t2", "t3",
  235. "t4", "t5", "t6", "t7",
  236. "memory"
  237. );
  238. curidx = qc1;
  239. curidx *= 3;
  240. curidx += qc2;
  241. curidx *= 3;
  242. curidx += qc3;
  243. curidx *= 3;
  244. curidx += qc4;
  245. curidx += 40;
  246. put_bits(pb, p_bits[curidx], p_codes[curidx]);
  247. }
  248. }
  249. static void quantize_and_encode_band_cost_UQUAD_mips(struct AACEncContext *s,
  250. PutBitContext *pb, const float *in,
  251. const float *scaled, int size, int scale_idx,
  252. int cb, const float lambda, const float uplim,
  253. int *bits)
  254. {
  255. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  256. int i;
  257. int qc1, qc2, qc3, qc4;
  258. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  259. uint16_t *p_codes = (uint16_t *)ff_aac_spectral_codes[cb-1];
  260. abs_pow34_v(s->scoefs, in, size);
  261. scaled = s->scoefs;
  262. for (i = 0; i < size; i += 4) {
  263. int curidx, sign, count;
  264. int *in_int = (int *)&in[i];
  265. uint8_t v_bits;
  266. unsigned int v_codes;
  267. qc1 = scaled[i ] * Q34 + 0.4054f;
  268. qc2 = scaled[i+1] * Q34 + 0.4054f;
  269. qc3 = scaled[i+2] * Q34 + 0.4054f;
  270. qc4 = scaled[i+3] * Q34 + 0.4054f;
  271. __asm__ volatile (
  272. ".set push \n\t"
  273. ".set noreorder \n\t"
  274. "ori $t4, $zero, 2 \n\t"
  275. "ori %[sign], $zero, 0 \n\t"
  276. "slt $t0, $t4, %[qc1] \n\t"
  277. "slt $t1, $t4, %[qc2] \n\t"
  278. "slt $t2, $t4, %[qc3] \n\t"
  279. "slt $t3, $t4, %[qc4] \n\t"
  280. "movn %[qc1], $t4, $t0 \n\t"
  281. "movn %[qc2], $t4, $t1 \n\t"
  282. "movn %[qc3], $t4, $t2 \n\t"
  283. "movn %[qc4], $t4, $t3 \n\t"
  284. "lw $t0, 0(%[in_int]) \n\t"
  285. "lw $t1, 4(%[in_int]) \n\t"
  286. "lw $t2, 8(%[in_int]) \n\t"
  287. "lw $t3, 12(%[in_int]) \n\t"
  288. "slt $t0, $t0, $zero \n\t"
  289. "movn %[sign], $t0, %[qc1] \n\t"
  290. "slt $t1, $t1, $zero \n\t"
  291. "slt $t2, $t2, $zero \n\t"
  292. "slt $t3, $t3, $zero \n\t"
  293. "sll $t0, %[sign], 1 \n\t"
  294. "or $t0, $t0, $t1 \n\t"
  295. "movn %[sign], $t0, %[qc2] \n\t"
  296. "slt $t4, $zero, %[qc1] \n\t"
  297. "slt $t1, $zero, %[qc2] \n\t"
  298. "slt %[count], $zero, %[qc3] \n\t"
  299. "sll $t0, %[sign], 1 \n\t"
  300. "or $t0, $t0, $t2 \n\t"
  301. "movn %[sign], $t0, %[qc3] \n\t"
  302. "slt $t2, $zero, %[qc4] \n\t"
  303. "addu %[count], %[count], $t4 \n\t"
  304. "addu %[count], %[count], $t1 \n\t"
  305. "sll $t0, %[sign], 1 \n\t"
  306. "or $t0, $t0, $t3 \n\t"
  307. "movn %[sign], $t0, %[qc4] \n\t"
  308. "addu %[count], %[count], $t2 \n\t"
  309. ".set pop \n\t"
  310. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  311. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  312. [sign]"=&r"(sign), [count]"=&r"(count)
  313. : [in_int]"r"(in_int)
  314. : "t0", "t1", "t2", "t3", "t4",
  315. "memory"
  316. );
  317. curidx = qc1;
  318. curidx *= 3;
  319. curidx += qc2;
  320. curidx *= 3;
  321. curidx += qc3;
  322. curidx *= 3;
  323. curidx += qc4;
  324. v_codes = (p_codes[curidx] << count) | (sign & ((1 << count) - 1));
  325. v_bits = p_bits[curidx] + count;
  326. put_bits(pb, v_bits, v_codes);
  327. }
  328. }
  329. static void quantize_and_encode_band_cost_SPAIR_mips(struct AACEncContext *s,
  330. PutBitContext *pb, const float *in,
  331. const float *scaled, int size, int scale_idx,
  332. int cb, const float lambda, const float uplim,
  333. int *bits)
  334. {
  335. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  336. int i;
  337. int qc1, qc2, qc3, qc4;
  338. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  339. uint16_t *p_codes = (uint16_t *)ff_aac_spectral_codes[cb-1];
  340. abs_pow34_v(s->scoefs, in, size);
  341. scaled = s->scoefs;
  342. for (i = 0; i < size; i += 4) {
  343. int curidx, curidx2;
  344. int *in_int = (int *)&in[i];
  345. uint8_t v_bits;
  346. unsigned int v_codes;
  347. qc1 = scaled[i ] * Q34 + 0.4054f;
  348. qc2 = scaled[i+1] * Q34 + 0.4054f;
  349. qc3 = scaled[i+2] * Q34 + 0.4054f;
  350. qc4 = scaled[i+3] * Q34 + 0.4054f;
  351. __asm__ volatile (
  352. ".set push \n\t"
  353. ".set noreorder \n\t"
  354. "ori $t4, $zero, 4 \n\t"
  355. "slt $t0, $t4, %[qc1] \n\t"
  356. "slt $t1, $t4, %[qc2] \n\t"
  357. "slt $t2, $t4, %[qc3] \n\t"
  358. "slt $t3, $t4, %[qc4] \n\t"
  359. "movn %[qc1], $t4, $t0 \n\t"
  360. "movn %[qc2], $t4, $t1 \n\t"
  361. "movn %[qc3], $t4, $t2 \n\t"
  362. "movn %[qc4], $t4, $t3 \n\t"
  363. "lw $t0, 0(%[in_int]) \n\t"
  364. "lw $t1, 4(%[in_int]) \n\t"
  365. "lw $t2, 8(%[in_int]) \n\t"
  366. "lw $t3, 12(%[in_int]) \n\t"
  367. "srl $t0, $t0, 31 \n\t"
  368. "srl $t1, $t1, 31 \n\t"
  369. "srl $t2, $t2, 31 \n\t"
  370. "srl $t3, $t3, 31 \n\t"
  371. "subu $t4, $zero, %[qc1] \n\t"
  372. "subu $t5, $zero, %[qc2] \n\t"
  373. "subu $t6, $zero, %[qc3] \n\t"
  374. "subu $t7, $zero, %[qc4] \n\t"
  375. "movn %[qc1], $t4, $t0 \n\t"
  376. "movn %[qc2], $t5, $t1 \n\t"
  377. "movn %[qc3], $t6, $t2 \n\t"
  378. "movn %[qc4], $t7, $t3 \n\t"
  379. ".set pop \n\t"
  380. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  381. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  382. : [in_int]"r"(in_int)
  383. : "t0", "t1", "t2", "t3",
  384. "t4", "t5", "t6", "t7",
  385. "memory"
  386. );
  387. curidx = 9 * qc1;
  388. curidx += qc2 + 40;
  389. curidx2 = 9 * qc3;
  390. curidx2 += qc4 + 40;
  391. v_codes = (p_codes[curidx] << p_bits[curidx2]) | (p_codes[curidx2]);
  392. v_bits = p_bits[curidx] + p_bits[curidx2];
  393. put_bits(pb, v_bits, v_codes);
  394. }
  395. }
  396. static void quantize_and_encode_band_cost_UPAIR7_mips(struct AACEncContext *s,
  397. PutBitContext *pb, const float *in,
  398. const float *scaled, int size, int scale_idx,
  399. int cb, const float lambda, const float uplim,
  400. int *bits)
  401. {
  402. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  403. int i;
  404. int qc1, qc2, qc3, qc4;
  405. uint8_t *p_bits = (uint8_t*) ff_aac_spectral_bits[cb-1];
  406. uint16_t *p_codes = (uint16_t*)ff_aac_spectral_codes[cb-1];
  407. abs_pow34_v(s->scoefs, in, size);
  408. scaled = s->scoefs;
  409. for (i = 0; i < size; i += 4) {
  410. int curidx, sign1, count1, sign2, count2;
  411. int *in_int = (int *)&in[i];
  412. uint8_t v_bits;
  413. unsigned int v_codes;
  414. qc1 = scaled[i ] * Q34 + 0.4054f;
  415. qc2 = scaled[i+1] * Q34 + 0.4054f;
  416. qc3 = scaled[i+2] * Q34 + 0.4054f;
  417. qc4 = scaled[i+3] * Q34 + 0.4054f;
  418. __asm__ volatile (
  419. ".set push \n\t"
  420. ".set noreorder \n\t"
  421. "ori $t4, $zero, 7 \n\t"
  422. "ori %[sign1], $zero, 0 \n\t"
  423. "ori %[sign2], $zero, 0 \n\t"
  424. "slt $t0, $t4, %[qc1] \n\t"
  425. "slt $t1, $t4, %[qc2] \n\t"
  426. "slt $t2, $t4, %[qc3] \n\t"
  427. "slt $t3, $t4, %[qc4] \n\t"
  428. "movn %[qc1], $t4, $t0 \n\t"
  429. "movn %[qc2], $t4, $t1 \n\t"
  430. "movn %[qc3], $t4, $t2 \n\t"
  431. "movn %[qc4], $t4, $t3 \n\t"
  432. "lw $t0, 0(%[in_int]) \n\t"
  433. "lw $t1, 4(%[in_int]) \n\t"
  434. "lw $t2, 8(%[in_int]) \n\t"
  435. "lw $t3, 12(%[in_int]) \n\t"
  436. "slt $t0, $t0, $zero \n\t"
  437. "movn %[sign1], $t0, %[qc1] \n\t"
  438. "slt $t2, $t2, $zero \n\t"
  439. "movn %[sign2], $t2, %[qc3] \n\t"
  440. "slt $t1, $t1, $zero \n\t"
  441. "sll $t0, %[sign1], 1 \n\t"
  442. "or $t0, $t0, $t1 \n\t"
  443. "movn %[sign1], $t0, %[qc2] \n\t"
  444. "slt $t3, $t3, $zero \n\t"
  445. "sll $t0, %[sign2], 1 \n\t"
  446. "or $t0, $t0, $t3 \n\t"
  447. "movn %[sign2], $t0, %[qc4] \n\t"
  448. "slt %[count1], $zero, %[qc1] \n\t"
  449. "slt $t1, $zero, %[qc2] \n\t"
  450. "slt %[count2], $zero, %[qc3] \n\t"
  451. "slt $t2, $zero, %[qc4] \n\t"
  452. "addu %[count1], %[count1], $t1 \n\t"
  453. "addu %[count2], %[count2], $t2 \n\t"
  454. ".set pop \n\t"
  455. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  456. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  457. [sign1]"=&r"(sign1), [count1]"=&r"(count1),
  458. [sign2]"=&r"(sign2), [count2]"=&r"(count2)
  459. : [in_int]"r"(in_int)
  460. : "t0", "t1", "t2", "t3", "t4",
  461. "memory"
  462. );
  463. curidx = 8 * qc1;
  464. curidx += qc2;
  465. v_codes = (p_codes[curidx] << count1) | sign1;
  466. v_bits = p_bits[curidx] + count1;
  467. put_bits(pb, v_bits, v_codes);
  468. curidx = 8 * qc3;
  469. curidx += qc4;
  470. v_codes = (p_codes[curidx] << count2) | sign2;
  471. v_bits = p_bits[curidx] + count2;
  472. put_bits(pb, v_bits, v_codes);
  473. }
  474. }
  475. static void quantize_and_encode_band_cost_UPAIR12_mips(struct AACEncContext *s,
  476. PutBitContext *pb, const float *in,
  477. const float *scaled, int size, int scale_idx,
  478. int cb, const float lambda, const float uplim,
  479. int *bits)
  480. {
  481. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  482. int i;
  483. int qc1, qc2, qc3, qc4;
  484. uint8_t *p_bits = (uint8_t*) ff_aac_spectral_bits[cb-1];
  485. uint16_t *p_codes = (uint16_t*)ff_aac_spectral_codes[cb-1];
  486. abs_pow34_v(s->scoefs, in, size);
  487. scaled = s->scoefs;
  488. for (i = 0; i < size; i += 4) {
  489. int curidx, sign1, count1, sign2, count2;
  490. int *in_int = (int *)&in[i];
  491. uint8_t v_bits;
  492. unsigned int v_codes;
  493. qc1 = scaled[i ] * Q34 + 0.4054f;
  494. qc2 = scaled[i+1] * Q34 + 0.4054f;
  495. qc3 = scaled[i+2] * Q34 + 0.4054f;
  496. qc4 = scaled[i+3] * Q34 + 0.4054f;
  497. __asm__ volatile (
  498. ".set push \n\t"
  499. ".set noreorder \n\t"
  500. "ori $t4, $zero, 12 \n\t"
  501. "ori %[sign1], $zero, 0 \n\t"
  502. "ori %[sign2], $zero, 0 \n\t"
  503. "slt $t0, $t4, %[qc1] \n\t"
  504. "slt $t1, $t4, %[qc2] \n\t"
  505. "slt $t2, $t4, %[qc3] \n\t"
  506. "slt $t3, $t4, %[qc4] \n\t"
  507. "movn %[qc1], $t4, $t0 \n\t"
  508. "movn %[qc2], $t4, $t1 \n\t"
  509. "movn %[qc3], $t4, $t2 \n\t"
  510. "movn %[qc4], $t4, $t3 \n\t"
  511. "lw $t0, 0(%[in_int]) \n\t"
  512. "lw $t1, 4(%[in_int]) \n\t"
  513. "lw $t2, 8(%[in_int]) \n\t"
  514. "lw $t3, 12(%[in_int]) \n\t"
  515. "slt $t0, $t0, $zero \n\t"
  516. "movn %[sign1], $t0, %[qc1] \n\t"
  517. "slt $t2, $t2, $zero \n\t"
  518. "movn %[sign2], $t2, %[qc3] \n\t"
  519. "slt $t1, $t1, $zero \n\t"
  520. "sll $t0, %[sign1], 1 \n\t"
  521. "or $t0, $t0, $t1 \n\t"
  522. "movn %[sign1], $t0, %[qc2] \n\t"
  523. "slt $t3, $t3, $zero \n\t"
  524. "sll $t0, %[sign2], 1 \n\t"
  525. "or $t0, $t0, $t3 \n\t"
  526. "movn %[sign2], $t0, %[qc4] \n\t"
  527. "slt %[count1], $zero, %[qc1] \n\t"
  528. "slt $t1, $zero, %[qc2] \n\t"
  529. "slt %[count2], $zero, %[qc3] \n\t"
  530. "slt $t2, $zero, %[qc4] \n\t"
  531. "addu %[count1], %[count1], $t1 \n\t"
  532. "addu %[count2], %[count2], $t2 \n\t"
  533. ".set pop \n\t"
  534. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  535. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  536. [sign1]"=&r"(sign1), [count1]"=&r"(count1),
  537. [sign2]"=&r"(sign2), [count2]"=&r"(count2)
  538. : [in_int]"r"(in_int)
  539. : "t0", "t1", "t2", "t3", "t4",
  540. "memory"
  541. );
  542. curidx = 13 * qc1;
  543. curidx += qc2;
  544. v_codes = (p_codes[curidx] << count1) | sign1;
  545. v_bits = p_bits[curidx] + count1;
  546. put_bits(pb, v_bits, v_codes);
  547. curidx = 13 * qc3;
  548. curidx += qc4;
  549. v_codes = (p_codes[curidx] << count2) | sign2;
  550. v_bits = p_bits[curidx] + count2;
  551. put_bits(pb, v_bits, v_codes);
  552. }
  553. }
  554. static void quantize_and_encode_band_cost_ESC_mips(struct AACEncContext *s,
  555. PutBitContext *pb, const float *in,
  556. const float *scaled, int size, int scale_idx,
  557. int cb, const float lambda, const float uplim,
  558. int *bits)
  559. {
  560. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  561. int i;
  562. int qc1, qc2, qc3, qc4;
  563. uint8_t *p_bits = (uint8_t* )ff_aac_spectral_bits[cb-1];
  564. uint16_t *p_codes = (uint16_t*)ff_aac_spectral_codes[cb-1];
  565. float *p_vectors = (float* )ff_aac_codebook_vectors[cb-1];
  566. abs_pow34_v(s->scoefs, in, size);
  567. scaled = s->scoefs;
  568. if (cb < 11) {
  569. for (i = 0; i < size; i += 4) {
  570. int curidx, curidx2, sign1, count1, sign2, count2;
  571. int *in_int = (int *)&in[i];
  572. uint8_t v_bits;
  573. unsigned int v_codes;
  574. qc1 = scaled[i ] * Q34 + 0.4054f;
  575. qc2 = scaled[i+1] * Q34 + 0.4054f;
  576. qc3 = scaled[i+2] * Q34 + 0.4054f;
  577. qc4 = scaled[i+3] * Q34 + 0.4054f;
  578. __asm__ volatile (
  579. ".set push \n\t"
  580. ".set noreorder \n\t"
  581. "ori $t4, $zero, 16 \n\t"
  582. "ori %[sign1], $zero, 0 \n\t"
  583. "ori %[sign2], $zero, 0 \n\t"
  584. "slt $t0, $t4, %[qc1] \n\t"
  585. "slt $t1, $t4, %[qc2] \n\t"
  586. "slt $t2, $t4, %[qc3] \n\t"
  587. "slt $t3, $t4, %[qc4] \n\t"
  588. "movn %[qc1], $t4, $t0 \n\t"
  589. "movn %[qc2], $t4, $t1 \n\t"
  590. "movn %[qc3], $t4, $t2 \n\t"
  591. "movn %[qc4], $t4, $t3 \n\t"
  592. "lw $t0, 0(%[in_int]) \n\t"
  593. "lw $t1, 4(%[in_int]) \n\t"
  594. "lw $t2, 8(%[in_int]) \n\t"
  595. "lw $t3, 12(%[in_int]) \n\t"
  596. "slt $t0, $t0, $zero \n\t"
  597. "movn %[sign1], $t0, %[qc1] \n\t"
  598. "slt $t2, $t2, $zero \n\t"
  599. "movn %[sign2], $t2, %[qc3] \n\t"
  600. "slt $t1, $t1, $zero \n\t"
  601. "sll $t0, %[sign1], 1 \n\t"
  602. "or $t0, $t0, $t1 \n\t"
  603. "movn %[sign1], $t0, %[qc2] \n\t"
  604. "slt $t3, $t3, $zero \n\t"
  605. "sll $t0, %[sign2], 1 \n\t"
  606. "or $t0, $t0, $t3 \n\t"
  607. "movn %[sign2], $t0, %[qc4] \n\t"
  608. "slt %[count1], $zero, %[qc1] \n\t"
  609. "slt $t1, $zero, %[qc2] \n\t"
  610. "slt %[count2], $zero, %[qc3] \n\t"
  611. "slt $t2, $zero, %[qc4] \n\t"
  612. "addu %[count1], %[count1], $t1 \n\t"
  613. "addu %[count2], %[count2], $t2 \n\t"
  614. ".set pop \n\t"
  615. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  616. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  617. [sign1]"=&r"(sign1), [count1]"=&r"(count1),
  618. [sign2]"=&r"(sign2), [count2]"=&r"(count2)
  619. : [in_int]"r"(in_int)
  620. : "t0", "t1", "t2", "t3", "t4",
  621. "memory"
  622. );
  623. curidx = 17 * qc1;
  624. curidx += qc2;
  625. curidx2 = 17 * qc3;
  626. curidx2 += qc4;
  627. v_codes = (p_codes[curidx] << count1) | sign1;
  628. v_bits = p_bits[curidx] + count1;
  629. put_bits(pb, v_bits, v_codes);
  630. v_codes = (p_codes[curidx2] << count2) | sign2;
  631. v_bits = p_bits[curidx2] + count2;
  632. put_bits(pb, v_bits, v_codes);
  633. }
  634. } else {
  635. for (i = 0; i < size; i += 4) {
  636. int curidx, curidx2, sign1, count1, sign2, count2;
  637. int *in_int = (int *)&in[i];
  638. uint8_t v_bits;
  639. unsigned int v_codes;
  640. int c1, c2, c3, c4;
  641. qc1 = scaled[i ] * Q34 + 0.4054f;
  642. qc2 = scaled[i+1] * Q34 + 0.4054f;
  643. qc3 = scaled[i+2] * Q34 + 0.4054f;
  644. qc4 = scaled[i+3] * Q34 + 0.4054f;
  645. __asm__ volatile (
  646. ".set push \n\t"
  647. ".set noreorder \n\t"
  648. "ori $t4, $zero, 16 \n\t"
  649. "ori %[sign1], $zero, 0 \n\t"
  650. "ori %[sign2], $zero, 0 \n\t"
  651. "shll_s.w %[c1], %[qc1], 18 \n\t"
  652. "shll_s.w %[c2], %[qc2], 18 \n\t"
  653. "shll_s.w %[c3], %[qc3], 18 \n\t"
  654. "shll_s.w %[c4], %[qc4], 18 \n\t"
  655. "srl %[c1], %[c1], 18 \n\t"
  656. "srl %[c2], %[c2], 18 \n\t"
  657. "srl %[c3], %[c3], 18 \n\t"
  658. "srl %[c4], %[c4], 18 \n\t"
  659. "slt $t0, $t4, %[qc1] \n\t"
  660. "slt $t1, $t4, %[qc2] \n\t"
  661. "slt $t2, $t4, %[qc3] \n\t"
  662. "slt $t3, $t4, %[qc4] \n\t"
  663. "movn %[qc1], $t4, $t0 \n\t"
  664. "movn %[qc2], $t4, $t1 \n\t"
  665. "movn %[qc3], $t4, $t2 \n\t"
  666. "movn %[qc4], $t4, $t3 \n\t"
  667. "lw $t0, 0(%[in_int]) \n\t"
  668. "lw $t1, 4(%[in_int]) \n\t"
  669. "lw $t2, 8(%[in_int]) \n\t"
  670. "lw $t3, 12(%[in_int]) \n\t"
  671. "slt $t0, $t0, $zero \n\t"
  672. "movn %[sign1], $t0, %[qc1] \n\t"
  673. "slt $t2, $t2, $zero \n\t"
  674. "movn %[sign2], $t2, %[qc3] \n\t"
  675. "slt $t1, $t1, $zero \n\t"
  676. "sll $t0, %[sign1], 1 \n\t"
  677. "or $t0, $t0, $t1 \n\t"
  678. "movn %[sign1], $t0, %[qc2] \n\t"
  679. "slt $t3, $t3, $zero \n\t"
  680. "sll $t0, %[sign2], 1 \n\t"
  681. "or $t0, $t0, $t3 \n\t"
  682. "movn %[sign2], $t0, %[qc4] \n\t"
  683. "slt %[count1], $zero, %[qc1] \n\t"
  684. "slt $t1, $zero, %[qc2] \n\t"
  685. "slt %[count2], $zero, %[qc3] \n\t"
  686. "slt $t2, $zero, %[qc4] \n\t"
  687. "addu %[count1], %[count1], $t1 \n\t"
  688. "addu %[count2], %[count2], $t2 \n\t"
  689. ".set pop \n\t"
  690. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  691. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  692. [sign1]"=&r"(sign1), [count1]"=&r"(count1),
  693. [sign2]"=&r"(sign2), [count2]"=&r"(count2),
  694. [c1]"=&r"(c1), [c2]"=&r"(c2),
  695. [c3]"=&r"(c3), [c4]"=&r"(c4)
  696. : [in_int]"r"(in_int)
  697. : "t0", "t1", "t2", "t3", "t4",
  698. "memory"
  699. );
  700. curidx = 17 * qc1;
  701. curidx += qc2;
  702. curidx2 = 17 * qc3;
  703. curidx2 += qc4;
  704. v_codes = (p_codes[curidx] << count1) | sign1;
  705. v_bits = p_bits[curidx] + count1;
  706. put_bits(pb, v_bits, v_codes);
  707. if (p_vectors[curidx*2 ] == 64.0f) {
  708. int len = av_log2(c1);
  709. v_codes = (((1 << (len - 3)) - 2) << len) | (c1 & ((1 << len) - 1));
  710. put_bits(pb, len * 2 - 3, v_codes);
  711. }
  712. if (p_vectors[curidx*2+1] == 64.0f) {
  713. int len = av_log2(c2);
  714. v_codes = (((1 << (len - 3)) - 2) << len) | (c2 & ((1 << len) - 1));
  715. put_bits(pb, len*2-3, v_codes);
  716. }
  717. v_codes = (p_codes[curidx2] << count2) | sign2;
  718. v_bits = p_bits[curidx2] + count2;
  719. put_bits(pb, v_bits, v_codes);
  720. if (p_vectors[curidx2*2 ] == 64.0f) {
  721. int len = av_log2(c3);
  722. v_codes = (((1 << (len - 3)) - 2) << len) | (c3 & ((1 << len) - 1));
  723. put_bits(pb, len* 2 - 3, v_codes);
  724. }
  725. if (p_vectors[curidx2*2+1] == 64.0f) {
  726. int len = av_log2(c4);
  727. v_codes = (((1 << (len - 3)) - 2) << len) | (c4 & ((1 << len) - 1));
  728. put_bits(pb, len * 2 - 3, v_codes);
  729. }
  730. }
  731. }
  732. }
  733. static void (*const quantize_and_encode_band_cost_arr[])(struct AACEncContext *s,
  734. PutBitContext *pb, const float *in,
  735. const float *scaled, int size, int scale_idx,
  736. int cb, const float lambda, const float uplim,
  737. int *bits) = {
  738. NULL,
  739. quantize_and_encode_band_cost_SQUAD_mips,
  740. quantize_and_encode_band_cost_SQUAD_mips,
  741. quantize_and_encode_band_cost_UQUAD_mips,
  742. quantize_and_encode_band_cost_UQUAD_mips,
  743. quantize_and_encode_band_cost_SPAIR_mips,
  744. quantize_and_encode_band_cost_SPAIR_mips,
  745. quantize_and_encode_band_cost_UPAIR7_mips,
  746. quantize_and_encode_band_cost_UPAIR7_mips,
  747. quantize_and_encode_band_cost_UPAIR12_mips,
  748. quantize_and_encode_band_cost_UPAIR12_mips,
  749. quantize_and_encode_band_cost_ESC_mips,
  750. };
  751. #define quantize_and_encode_band_cost( \
  752. s, pb, in, scaled, size, scale_idx, cb, \
  753. lambda, uplim, bits) \
  754. quantize_and_encode_band_cost_arr[cb]( \
  755. s, pb, in, scaled, size, scale_idx, cb, \
  756. lambda, uplim, bits)
  757. static void quantize_and_encode_band_mips(struct AACEncContext *s, PutBitContext *pb,
  758. const float *in, int size, int scale_idx,
  759. int cb, const float lambda)
  760. {
  761. quantize_and_encode_band_cost(s, pb, in, NULL, size, scale_idx, cb, lambda,
  762. INFINITY, NULL);
  763. }
  764. /**
  765. * Functions developed from template function and optimized for getting the number of bits
  766. */
  767. static float get_band_numbits_ZERO_mips(struct AACEncContext *s,
  768. PutBitContext *pb, const float *in,
  769. const float *scaled, int size, int scale_idx,
  770. int cb, const float lambda, const float uplim,
  771. int *bits)
  772. {
  773. return 0;
  774. }
  775. static float get_band_numbits_SQUAD_mips(struct AACEncContext *s,
  776. PutBitContext *pb, const float *in,
  777. const float *scaled, int size, int scale_idx,
  778. int cb, const float lambda, const float uplim,
  779. int *bits)
  780. {
  781. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  782. int i;
  783. int qc1, qc2, qc3, qc4;
  784. int curbits = 0;
  785. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  786. for (i = 0; i < size; i += 4) {
  787. int curidx;
  788. int *in_int = (int *)&in[i];
  789. qc1 = scaled[i ] * Q34 + 0.4054f;
  790. qc2 = scaled[i+1] * Q34 + 0.4054f;
  791. qc3 = scaled[i+2] * Q34 + 0.4054f;
  792. qc4 = scaled[i+3] * Q34 + 0.4054f;
  793. __asm__ volatile (
  794. ".set push \n\t"
  795. ".set noreorder \n\t"
  796. "slt %[qc1], $zero, %[qc1] \n\t"
  797. "slt %[qc2], $zero, %[qc2] \n\t"
  798. "slt %[qc3], $zero, %[qc3] \n\t"
  799. "slt %[qc4], $zero, %[qc4] \n\t"
  800. "lw $t0, 0(%[in_int]) \n\t"
  801. "lw $t1, 4(%[in_int]) \n\t"
  802. "lw $t2, 8(%[in_int]) \n\t"
  803. "lw $t3, 12(%[in_int]) \n\t"
  804. "srl $t0, $t0, 31 \n\t"
  805. "srl $t1, $t1, 31 \n\t"
  806. "srl $t2, $t2, 31 \n\t"
  807. "srl $t3, $t3, 31 \n\t"
  808. "subu $t4, $zero, %[qc1] \n\t"
  809. "subu $t5, $zero, %[qc2] \n\t"
  810. "subu $t6, $zero, %[qc3] \n\t"
  811. "subu $t7, $zero, %[qc4] \n\t"
  812. "movn %[qc1], $t4, $t0 \n\t"
  813. "movn %[qc2], $t5, $t1 \n\t"
  814. "movn %[qc3], $t6, $t2 \n\t"
  815. "movn %[qc4], $t7, $t3 \n\t"
  816. ".set pop \n\t"
  817. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  818. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  819. : [in_int]"r"(in_int)
  820. : "t0", "t1", "t2", "t3",
  821. "t4", "t5", "t6", "t7",
  822. "memory"
  823. );
  824. curidx = qc1;
  825. curidx *= 3;
  826. curidx += qc2;
  827. curidx *= 3;
  828. curidx += qc3;
  829. curidx *= 3;
  830. curidx += qc4;
  831. curidx += 40;
  832. curbits += p_bits[curidx];
  833. }
  834. return curbits;
  835. }
  836. static float get_band_numbits_UQUAD_mips(struct AACEncContext *s,
  837. PutBitContext *pb, const float *in,
  838. const float *scaled, int size, int scale_idx,
  839. int cb, const float lambda, const float uplim,
  840. int *bits)
  841. {
  842. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  843. int i;
  844. int curbits = 0;
  845. int qc1, qc2, qc3, qc4;
  846. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  847. for (i = 0; i < size; i += 4) {
  848. int curidx;
  849. qc1 = scaled[i ] * Q34 + 0.4054f;
  850. qc2 = scaled[i+1] * Q34 + 0.4054f;
  851. qc3 = scaled[i+2] * Q34 + 0.4054f;
  852. qc4 = scaled[i+3] * Q34 + 0.4054f;
  853. __asm__ volatile (
  854. ".set push \n\t"
  855. ".set noreorder \n\t"
  856. "ori $t4, $zero, 2 \n\t"
  857. "slt $t0, $t4, %[qc1] \n\t"
  858. "slt $t1, $t4, %[qc2] \n\t"
  859. "slt $t2, $t4, %[qc3] \n\t"
  860. "slt $t3, $t4, %[qc4] \n\t"
  861. "movn %[qc1], $t4, $t0 \n\t"
  862. "movn %[qc2], $t4, $t1 \n\t"
  863. "movn %[qc3], $t4, $t2 \n\t"
  864. "movn %[qc4], $t4, $t3 \n\t"
  865. ".set pop \n\t"
  866. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  867. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  868. :
  869. : "t0", "t1", "t2", "t3", "t4"
  870. );
  871. curidx = qc1;
  872. curidx *= 3;
  873. curidx += qc2;
  874. curidx *= 3;
  875. curidx += qc3;
  876. curidx *= 3;
  877. curidx += qc4;
  878. curbits += p_bits[curidx];
  879. curbits += uquad_sign_bits[curidx];
  880. }
  881. return curbits;
  882. }
  883. static float get_band_numbits_SPAIR_mips(struct AACEncContext *s,
  884. PutBitContext *pb, const float *in,
  885. const float *scaled, int size, int scale_idx,
  886. int cb, const float lambda, const float uplim,
  887. int *bits)
  888. {
  889. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  890. int i;
  891. int qc1, qc2, qc3, qc4;
  892. int curbits = 0;
  893. uint8_t *p_bits = (uint8_t*)ff_aac_spectral_bits[cb-1];
  894. for (i = 0; i < size; i += 4) {
  895. int curidx, curidx2;
  896. int *in_int = (int *)&in[i];
  897. qc1 = scaled[i ] * Q34 + 0.4054f;
  898. qc2 = scaled[i+1] * Q34 + 0.4054f;
  899. qc3 = scaled[i+2] * Q34 + 0.4054f;
  900. qc4 = scaled[i+3] * Q34 + 0.4054f;
  901. __asm__ volatile (
  902. ".set push \n\t"
  903. ".set noreorder \n\t"
  904. "ori $t4, $zero, 4 \n\t"
  905. "slt $t0, $t4, %[qc1] \n\t"
  906. "slt $t1, $t4, %[qc2] \n\t"
  907. "slt $t2, $t4, %[qc3] \n\t"
  908. "slt $t3, $t4, %[qc4] \n\t"
  909. "movn %[qc1], $t4, $t0 \n\t"
  910. "movn %[qc2], $t4, $t1 \n\t"
  911. "movn %[qc3], $t4, $t2 \n\t"
  912. "movn %[qc4], $t4, $t3 \n\t"
  913. "lw $t0, 0(%[in_int]) \n\t"
  914. "lw $t1, 4(%[in_int]) \n\t"
  915. "lw $t2, 8(%[in_int]) \n\t"
  916. "lw $t3, 12(%[in_int]) \n\t"
  917. "srl $t0, $t0, 31 \n\t"
  918. "srl $t1, $t1, 31 \n\t"
  919. "srl $t2, $t2, 31 \n\t"
  920. "srl $t3, $t3, 31 \n\t"
  921. "subu $t4, $zero, %[qc1] \n\t"
  922. "subu $t5, $zero, %[qc2] \n\t"
  923. "subu $t6, $zero, %[qc3] \n\t"
  924. "subu $t7, $zero, %[qc4] \n\t"
  925. "movn %[qc1], $t4, $t0 \n\t"
  926. "movn %[qc2], $t5, $t1 \n\t"
  927. "movn %[qc3], $t6, $t2 \n\t"
  928. "movn %[qc4], $t7, $t3 \n\t"
  929. ".set pop \n\t"
  930. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  931. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  932. : [in_int]"r"(in_int)
  933. : "t0", "t1", "t2", "t3",
  934. "t4", "t5", "t6", "t7",
  935. "memory"
  936. );
  937. curidx = 9 * qc1;
  938. curidx += qc2 + 40;
  939. curidx2 = 9 * qc3;
  940. curidx2 += qc4 + 40;
  941. curbits += p_bits[curidx] + p_bits[curidx2];
  942. }
  943. return curbits;
  944. }
  945. static float get_band_numbits_UPAIR7_mips(struct AACEncContext *s,
  946. PutBitContext *pb, const float *in,
  947. const float *scaled, int size, int scale_idx,
  948. int cb, const float lambda, const float uplim,
  949. int *bits)
  950. {
  951. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  952. int i;
  953. int qc1, qc2, qc3, qc4;
  954. int curbits = 0;
  955. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  956. for (i = 0; i < size; i += 4) {
  957. int curidx, curidx2;
  958. qc1 = scaled[i ] * Q34 + 0.4054f;
  959. qc2 = scaled[i+1] * Q34 + 0.4054f;
  960. qc3 = scaled[i+2] * Q34 + 0.4054f;
  961. qc4 = scaled[i+3] * Q34 + 0.4054f;
  962. __asm__ volatile (
  963. ".set push \n\t"
  964. ".set noreorder \n\t"
  965. "ori $t4, $zero, 7 \n\t"
  966. "slt $t0, $t4, %[qc1] \n\t"
  967. "slt $t1, $t4, %[qc2] \n\t"
  968. "slt $t2, $t4, %[qc3] \n\t"
  969. "slt $t3, $t4, %[qc4] \n\t"
  970. "movn %[qc1], $t4, $t0 \n\t"
  971. "movn %[qc2], $t4, $t1 \n\t"
  972. "movn %[qc3], $t4, $t2 \n\t"
  973. "movn %[qc4], $t4, $t3 \n\t"
  974. ".set pop \n\t"
  975. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  976. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  977. :
  978. : "t0", "t1", "t2", "t3", "t4"
  979. );
  980. curidx = 8 * qc1;
  981. curidx += qc2;
  982. curidx2 = 8 * qc3;
  983. curidx2 += qc4;
  984. curbits += p_bits[curidx] +
  985. upair7_sign_bits[curidx] +
  986. p_bits[curidx2] +
  987. upair7_sign_bits[curidx2];
  988. }
  989. return curbits;
  990. }
  991. static float get_band_numbits_UPAIR12_mips(struct AACEncContext *s,
  992. PutBitContext *pb, const float *in,
  993. const float *scaled, int size, int scale_idx,
  994. int cb, const float lambda, const float uplim,
  995. int *bits)
  996. {
  997. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  998. int i;
  999. int qc1, qc2, qc3, qc4;
  1000. int curbits = 0;
  1001. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  1002. for (i = 0; i < size; i += 4) {
  1003. int curidx, curidx2;
  1004. qc1 = scaled[i ] * Q34 + 0.4054f;
  1005. qc2 = scaled[i+1] * Q34 + 0.4054f;
  1006. qc3 = scaled[i+2] * Q34 + 0.4054f;
  1007. qc4 = scaled[i+3] * Q34 + 0.4054f;
  1008. __asm__ volatile (
  1009. ".set push \n\t"
  1010. ".set noreorder \n\t"
  1011. "ori $t4, $zero, 12 \n\t"
  1012. "slt $t0, $t4, %[qc1] \n\t"
  1013. "slt $t1, $t4, %[qc2] \n\t"
  1014. "slt $t2, $t4, %[qc3] \n\t"
  1015. "slt $t3, $t4, %[qc4] \n\t"
  1016. "movn %[qc1], $t4, $t0 \n\t"
  1017. "movn %[qc2], $t4, $t1 \n\t"
  1018. "movn %[qc3], $t4, $t2 \n\t"
  1019. "movn %[qc4], $t4, $t3 \n\t"
  1020. ".set pop \n\t"
  1021. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  1022. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  1023. :
  1024. : "t0", "t1", "t2", "t3", "t4"
  1025. );
  1026. curidx = 13 * qc1;
  1027. curidx += qc2;
  1028. curidx2 = 13 * qc3;
  1029. curidx2 += qc4;
  1030. curbits += p_bits[curidx] +
  1031. p_bits[curidx2] +
  1032. upair12_sign_bits[curidx] +
  1033. upair12_sign_bits[curidx2];
  1034. }
  1035. return curbits;
  1036. }
  1037. static float get_band_numbits_ESC_mips(struct AACEncContext *s,
  1038. PutBitContext *pb, const float *in,
  1039. const float *scaled, int size, int scale_idx,
  1040. int cb, const float lambda, const float uplim,
  1041. int *bits)
  1042. {
  1043. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  1044. int i;
  1045. int qc1, qc2, qc3, qc4;
  1046. int curbits = 0;
  1047. uint8_t *p_bits = (uint8_t*)ff_aac_spectral_bits[cb-1];
  1048. for (i = 0; i < size; i += 4) {
  1049. int curidx, curidx2;
  1050. int cond0, cond1, cond2, cond3;
  1051. int c1, c2, c3, c4;
  1052. qc1 = scaled[i ] * Q34 + 0.4054f;
  1053. qc2 = scaled[i+1] * Q34 + 0.4054f;
  1054. qc3 = scaled[i+2] * Q34 + 0.4054f;
  1055. qc4 = scaled[i+3] * Q34 + 0.4054f;
  1056. __asm__ volatile (
  1057. ".set push \n\t"
  1058. ".set noreorder \n\t"
  1059. "ori $t4, $zero, 15 \n\t"
  1060. "ori $t5, $zero, 16 \n\t"
  1061. "shll_s.w %[c1], %[qc1], 18 \n\t"
  1062. "shll_s.w %[c2], %[qc2], 18 \n\t"
  1063. "shll_s.w %[c3], %[qc3], 18 \n\t"
  1064. "shll_s.w %[c4], %[qc4], 18 \n\t"
  1065. "srl %[c1], %[c1], 18 \n\t"
  1066. "srl %[c2], %[c2], 18 \n\t"
  1067. "srl %[c3], %[c3], 18 \n\t"
  1068. "srl %[c4], %[c4], 18 \n\t"
  1069. "slt %[cond0], $t4, %[qc1] \n\t"
  1070. "slt %[cond1], $t4, %[qc2] \n\t"
  1071. "slt %[cond2], $t4, %[qc3] \n\t"
  1072. "slt %[cond3], $t4, %[qc4] \n\t"
  1073. "movn %[qc1], $t5, %[cond0] \n\t"
  1074. "movn %[qc2], $t5, %[cond1] \n\t"
  1075. "movn %[qc3], $t5, %[cond2] \n\t"
  1076. "movn %[qc4], $t5, %[cond3] \n\t"
  1077. "ori $t5, $zero, 31 \n\t"
  1078. "clz %[c1], %[c1] \n\t"
  1079. "clz %[c2], %[c2] \n\t"
  1080. "clz %[c3], %[c3] \n\t"
  1081. "clz %[c4], %[c4] \n\t"
  1082. "subu %[c1], $t5, %[c1] \n\t"
  1083. "subu %[c2], $t5, %[c2] \n\t"
  1084. "subu %[c3], $t5, %[c3] \n\t"
  1085. "subu %[c4], $t5, %[c4] \n\t"
  1086. "sll %[c1], %[c1], 1 \n\t"
  1087. "sll %[c2], %[c2], 1 \n\t"
  1088. "sll %[c3], %[c3], 1 \n\t"
  1089. "sll %[c4], %[c4], 1 \n\t"
  1090. "addiu %[c1], %[c1], -3 \n\t"
  1091. "addiu %[c2], %[c2], -3 \n\t"
  1092. "addiu %[c3], %[c3], -3 \n\t"
  1093. "addiu %[c4], %[c4], -3 \n\t"
  1094. "subu %[cond0], $zero, %[cond0] \n\t"
  1095. "subu %[cond1], $zero, %[cond1] \n\t"
  1096. "subu %[cond2], $zero, %[cond2] \n\t"
  1097. "subu %[cond3], $zero, %[cond3] \n\t"
  1098. "and %[c1], %[c1], %[cond0] \n\t"
  1099. "and %[c2], %[c2], %[cond1] \n\t"
  1100. "and %[c3], %[c3], %[cond2] \n\t"
  1101. "and %[c4], %[c4], %[cond3] \n\t"
  1102. ".set pop \n\t"
  1103. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  1104. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  1105. [cond0]"=&r"(cond0), [cond1]"=&r"(cond1),
  1106. [cond2]"=&r"(cond2), [cond3]"=&r"(cond3),
  1107. [c1]"=&r"(c1), [c2]"=&r"(c2),
  1108. [c3]"=&r"(c3), [c4]"=&r"(c4)
  1109. :
  1110. : "t4", "t5"
  1111. );
  1112. curidx = 17 * qc1;
  1113. curidx += qc2;
  1114. curidx2 = 17 * qc3;
  1115. curidx2 += qc4;
  1116. curbits += p_bits[curidx];
  1117. curbits += esc_sign_bits[curidx];
  1118. curbits += p_bits[curidx2];
  1119. curbits += esc_sign_bits[curidx2];
  1120. curbits += c1;
  1121. curbits += c2;
  1122. curbits += c3;
  1123. curbits += c4;
  1124. }
  1125. return curbits;
  1126. }
  1127. static float (*const get_band_numbits_arr[])(struct AACEncContext *s,
  1128. PutBitContext *pb, const float *in,
  1129. const float *scaled, int size, int scale_idx,
  1130. int cb, const float lambda, const float uplim,
  1131. int *bits) = {
  1132. get_band_numbits_ZERO_mips,
  1133. get_band_numbits_SQUAD_mips,
  1134. get_band_numbits_SQUAD_mips,
  1135. get_band_numbits_UQUAD_mips,
  1136. get_band_numbits_UQUAD_mips,
  1137. get_band_numbits_SPAIR_mips,
  1138. get_band_numbits_SPAIR_mips,
  1139. get_band_numbits_UPAIR7_mips,
  1140. get_band_numbits_UPAIR7_mips,
  1141. get_band_numbits_UPAIR12_mips,
  1142. get_band_numbits_UPAIR12_mips,
  1143. get_band_numbits_ESC_mips,
  1144. };
  1145. #define get_band_numbits( \
  1146. s, pb, in, scaled, size, scale_idx, cb, \
  1147. lambda, uplim, bits) \
  1148. get_band_numbits_arr[cb]( \
  1149. s, pb, in, scaled, size, scale_idx, cb, \
  1150. lambda, uplim, bits)
  1151. static float quantize_band_cost_bits(struct AACEncContext *s, const float *in,
  1152. const float *scaled, int size, int scale_idx,
  1153. int cb, const float lambda, const float uplim,
  1154. int *bits)
  1155. {
  1156. return get_band_numbits(s, NULL, in, scaled, size, scale_idx, cb, lambda, uplim, bits);
  1157. }
  1158. /**
  1159. * Functions developed from template function and optimized for getting the band cost
  1160. */
  1161. #if HAVE_MIPSFPU
  1162. static float get_band_cost_ZERO_mips(struct AACEncContext *s,
  1163. PutBitContext *pb, const float *in,
  1164. const float *scaled, int size, int scale_idx,
  1165. int cb, const float lambda, const float uplim,
  1166. int *bits)
  1167. {
  1168. int i;
  1169. float cost = 0;
  1170. for (i = 0; i < size; i += 4) {
  1171. cost += in[i ] * in[i ];
  1172. cost += in[i+1] * in[i+1];
  1173. cost += in[i+2] * in[i+2];
  1174. cost += in[i+3] * in[i+3];
  1175. }
  1176. if (bits)
  1177. *bits = 0;
  1178. return cost * lambda;
  1179. }
  1180. static float get_band_cost_SQUAD_mips(struct AACEncContext *s,
  1181. PutBitContext *pb, const float *in,
  1182. const float *scaled, int size, int scale_idx,
  1183. int cb, const float lambda, const float uplim,
  1184. int *bits)
  1185. {
  1186. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  1187. const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
  1188. int i;
  1189. float cost = 0;
  1190. int qc1, qc2, qc3, qc4;
  1191. int curbits = 0;
  1192. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  1193. float *p_codes = (float *)ff_aac_codebook_vectors[cb-1];
  1194. for (i = 0; i < size; i += 4) {
  1195. const float *vec;
  1196. int curidx;
  1197. int *in_int = (int *)&in[i];
  1198. float *in_pos = (float *)&in[i];
  1199. float di0, di1, di2, di3;
  1200. qc1 = scaled[i ] * Q34 + 0.4054f;
  1201. qc2 = scaled[i+1] * Q34 + 0.4054f;
  1202. qc3 = scaled[i+2] * Q34 + 0.4054f;
  1203. qc4 = scaled[i+3] * Q34 + 0.4054f;
  1204. __asm__ volatile (
  1205. ".set push \n\t"
  1206. ".set noreorder \n\t"
  1207. "slt %[qc1], $zero, %[qc1] \n\t"
  1208. "slt %[qc2], $zero, %[qc2] \n\t"
  1209. "slt %[qc3], $zero, %[qc3] \n\t"
  1210. "slt %[qc4], $zero, %[qc4] \n\t"
  1211. "lw $t0, 0(%[in_int]) \n\t"
  1212. "lw $t1, 4(%[in_int]) \n\t"
  1213. "lw $t2, 8(%[in_int]) \n\t"
  1214. "lw $t3, 12(%[in_int]) \n\t"
  1215. "srl $t0, $t0, 31 \n\t"
  1216. "srl $t1, $t1, 31 \n\t"
  1217. "srl $t2, $t2, 31 \n\t"
  1218. "srl $t3, $t3, 31 \n\t"
  1219. "subu $t4, $zero, %[qc1] \n\t"
  1220. "subu $t5, $zero, %[qc2] \n\t"
  1221. "subu $t6, $zero, %[qc3] \n\t"
  1222. "subu $t7, $zero, %[qc4] \n\t"
  1223. "movn %[qc1], $t4, $t0 \n\t"
  1224. "movn %[qc2], $t5, $t1 \n\t"
  1225. "movn %[qc3], $t6, $t2 \n\t"
  1226. "movn %[qc4], $t7, $t3 \n\t"
  1227. ".set pop \n\t"
  1228. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  1229. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  1230. : [in_int]"r"(in_int)
  1231. : "t0", "t1", "t2", "t3",
  1232. "t4", "t5", "t6", "t7",
  1233. "memory"
  1234. );
  1235. curidx = qc1;
  1236. curidx *= 3;
  1237. curidx += qc2;
  1238. curidx *= 3;
  1239. curidx += qc3;
  1240. curidx *= 3;
  1241. curidx += qc4;
  1242. curidx += 40;
  1243. curbits += p_bits[curidx];
  1244. vec = &p_codes[curidx*4];
  1245. __asm__ volatile (
  1246. ".set push \n\t"
  1247. ".set noreorder \n\t"
  1248. "lwc1 $f0, 0(%[in_pos]) \n\t"
  1249. "lwc1 $f1, 0(%[vec]) \n\t"
  1250. "lwc1 $f2, 4(%[in_pos]) \n\t"
  1251. "lwc1 $f3, 4(%[vec]) \n\t"
  1252. "lwc1 $f4, 8(%[in_pos]) \n\t"
  1253. "lwc1 $f5, 8(%[vec]) \n\t"
  1254. "lwc1 $f6, 12(%[in_pos]) \n\t"
  1255. "lwc1 $f7, 12(%[vec]) \n\t"
  1256. "nmsub.s %[di0], $f0, $f1, %[IQ] \n\t"
  1257. "nmsub.s %[di1], $f2, $f3, %[IQ] \n\t"
  1258. "nmsub.s %[di2], $f4, $f5, %[IQ] \n\t"
  1259. "nmsub.s %[di3], $f6, $f7, %[IQ] \n\t"
  1260. ".set pop \n\t"
  1261. : [di0]"=&f"(di0), [di1]"=&f"(di1),
  1262. [di2]"=&f"(di2), [di3]"=&f"(di3)
  1263. : [in_pos]"r"(in_pos), [vec]"r"(vec),
  1264. [IQ]"f"(IQ)
  1265. : "$f0", "$f1", "$f2", "$f3",
  1266. "$f4", "$f5", "$f6", "$f7",
  1267. "memory"
  1268. );
  1269. cost += di0 * di0 + di1 * di1
  1270. + di2 * di2 + di3 * di3;
  1271. }
  1272. if (bits)
  1273. *bits = curbits;
  1274. return cost * lambda + curbits;
  1275. }
  1276. static float get_band_cost_UQUAD_mips(struct AACEncContext *s,
  1277. PutBitContext *pb, const float *in,
  1278. const float *scaled, int size, int scale_idx,
  1279. int cb, const float lambda, const float uplim,
  1280. int *bits)
  1281. {
  1282. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  1283. const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
  1284. int i;
  1285. float cost = 0;
  1286. int curbits = 0;
  1287. int qc1, qc2, qc3, qc4;
  1288. uint8_t *p_bits = (uint8_t*)ff_aac_spectral_bits[cb-1];
  1289. float *p_codes = (float *)ff_aac_codebook_vectors[cb-1];
  1290. for (i = 0; i < size; i += 4) {
  1291. const float *vec;
  1292. int curidx;
  1293. float *in_pos = (float *)&in[i];
  1294. float di0, di1, di2, di3;
  1295. qc1 = scaled[i ] * Q34 + 0.4054f;
  1296. qc2 = scaled[i+1] * Q34 + 0.4054f;
  1297. qc3 = scaled[i+2] * Q34 + 0.4054f;
  1298. qc4 = scaled[i+3] * Q34 + 0.4054f;
  1299. __asm__ volatile (
  1300. ".set push \n\t"
  1301. ".set noreorder \n\t"
  1302. "ori $t4, $zero, 2 \n\t"
  1303. "slt $t0, $t4, %[qc1] \n\t"
  1304. "slt $t1, $t4, %[qc2] \n\t"
  1305. "slt $t2, $t4, %[qc3] \n\t"
  1306. "slt $t3, $t4, %[qc4] \n\t"
  1307. "movn %[qc1], $t4, $t0 \n\t"
  1308. "movn %[qc2], $t4, $t1 \n\t"
  1309. "movn %[qc3], $t4, $t2 \n\t"
  1310. "movn %[qc4], $t4, $t3 \n\t"
  1311. ".set pop \n\t"
  1312. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  1313. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  1314. :
  1315. : "t0", "t1", "t2", "t3", "t4"
  1316. );
  1317. curidx = qc1;
  1318. curidx *= 3;
  1319. curidx += qc2;
  1320. curidx *= 3;
  1321. curidx += qc3;
  1322. curidx *= 3;
  1323. curidx += qc4;
  1324. curbits += p_bits[curidx];
  1325. curbits += uquad_sign_bits[curidx];
  1326. vec = &p_codes[curidx*4];
  1327. __asm__ volatile (
  1328. ".set push \n\t"
  1329. ".set noreorder \n\t"
  1330. "lwc1 %[di0], 0(%[in_pos]) \n\t"
  1331. "lwc1 %[di1], 4(%[in_pos]) \n\t"
  1332. "lwc1 %[di2], 8(%[in_pos]) \n\t"
  1333. "lwc1 %[di3], 12(%[in_pos]) \n\t"
  1334. "abs.s %[di0], %[di0] \n\t"
  1335. "abs.s %[di1], %[di1] \n\t"
  1336. "abs.s %[di2], %[di2] \n\t"
  1337. "abs.s %[di3], %[di3] \n\t"
  1338. "lwc1 $f0, 0(%[vec]) \n\t"
  1339. "lwc1 $f1, 4(%[vec]) \n\t"
  1340. "lwc1 $f2, 8(%[vec]) \n\t"
  1341. "lwc1 $f3, 12(%[vec]) \n\t"
  1342. "nmsub.s %[di0], %[di0], $f0, %[IQ] \n\t"
  1343. "nmsub.s %[di1], %[di1], $f1, %[IQ] \n\t"
  1344. "nmsub.s %[di2], %[di2], $f2, %[IQ] \n\t"
  1345. "nmsub.s %[di3], %[di3], $f3, %[IQ] \n\t"
  1346. ".set pop \n\t"
  1347. : [di0]"=&f"(di0), [di1]"=&f"(di1),
  1348. [di2]"=&f"(di2), [di3]"=&f"(di3)
  1349. : [in_pos]"r"(in_pos), [vec]"r"(vec),
  1350. [IQ]"f"(IQ)
  1351. : "$f0", "$f1", "$f2", "$f3",
  1352. "memory"
  1353. );
  1354. cost += di0 * di0 + di1 * di1
  1355. + di2 * di2 + di3 * di3;
  1356. }
  1357. if (bits)
  1358. *bits = curbits;
  1359. return cost * lambda + curbits;
  1360. }
  1361. static float get_band_cost_SPAIR_mips(struct AACEncContext *s,
  1362. PutBitContext *pb, const float *in,
  1363. const float *scaled, int size, int scale_idx,
  1364. int cb, const float lambda, const float uplim,
  1365. int *bits)
  1366. {
  1367. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  1368. const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
  1369. int i;
  1370. float cost = 0;
  1371. int qc1, qc2, qc3, qc4;
  1372. int curbits = 0;
  1373. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  1374. float *p_codes = (float *)ff_aac_codebook_vectors[cb-1];
  1375. for (i = 0; i < size; i += 4) {
  1376. const float *vec, *vec2;
  1377. int curidx, curidx2;
  1378. int *in_int = (int *)&in[i];
  1379. float *in_pos = (float *)&in[i];
  1380. float di0, di1, di2, di3;
  1381. qc1 = scaled[i ] * Q34 + 0.4054f;
  1382. qc2 = scaled[i+1] * Q34 + 0.4054f;
  1383. qc3 = scaled[i+2] * Q34 + 0.4054f;
  1384. qc4 = scaled[i+3] * Q34 + 0.4054f;
  1385. __asm__ volatile (
  1386. ".set push \n\t"
  1387. ".set noreorder \n\t"
  1388. "ori $t4, $zero, 4 \n\t"
  1389. "slt $t0, $t4, %[qc1] \n\t"
  1390. "slt $t1, $t4, %[qc2] \n\t"
  1391. "slt $t2, $t4, %[qc3] \n\t"
  1392. "slt $t3, $t4, %[qc4] \n\t"
  1393. "movn %[qc1], $t4, $t0 \n\t"
  1394. "movn %[qc2], $t4, $t1 \n\t"
  1395. "movn %[qc3], $t4, $t2 \n\t"
  1396. "movn %[qc4], $t4, $t3 \n\t"
  1397. "lw $t0, 0(%[in_int]) \n\t"
  1398. "lw $t1, 4(%[in_int]) \n\t"
  1399. "lw $t2, 8(%[in_int]) \n\t"
  1400. "lw $t3, 12(%[in_int]) \n\t"
  1401. "srl $t0, $t0, 31 \n\t"
  1402. "srl $t1, $t1, 31 \n\t"
  1403. "srl $t2, $t2, 31 \n\t"
  1404. "srl $t3, $t3, 31 \n\t"
  1405. "subu $t4, $zero, %[qc1] \n\t"
  1406. "subu $t5, $zero, %[qc2] \n\t"
  1407. "subu $t6, $zero, %[qc3] \n\t"
  1408. "subu $t7, $zero, %[qc4] \n\t"
  1409. "movn %[qc1], $t4, $t0 \n\t"
  1410. "movn %[qc2], $t5, $t1 \n\t"
  1411. "movn %[qc3], $t6, $t2 \n\t"
  1412. "movn %[qc4], $t7, $t3 \n\t"
  1413. ".set pop \n\t"
  1414. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  1415. [qc3]"+r"(qc3), [qc4]"+r"(qc4)
  1416. : [in_int]"r"(in_int)
  1417. : "t0", "t1", "t2", "t3",
  1418. "t4", "t5", "t6", "t7",
  1419. "memory"
  1420. );
  1421. curidx = 9 * qc1;
  1422. curidx += qc2 + 40;
  1423. curidx2 = 9 * qc3;
  1424. curidx2 += qc4 + 40;
  1425. curbits += p_bits[curidx];
  1426. curbits += p_bits[curidx2];
  1427. vec = &p_codes[curidx*2];
  1428. vec2 = &p_codes[curidx2*2];
  1429. __asm__ volatile (
  1430. ".set push \n\t"
  1431. ".set noreorder \n\t"
  1432. "lwc1 $f0, 0(%[in_pos]) \n\t"
  1433. "lwc1 $f1, 0(%[vec]) \n\t"
  1434. "lwc1 $f2, 4(%[in_pos]) \n\t"
  1435. "lwc1 $f3, 4(%[vec]) \n\t"
  1436. "lwc1 $f4, 8(%[in_pos]) \n\t"
  1437. "lwc1 $f5, 0(%[vec2]) \n\t"
  1438. "lwc1 $f6, 12(%[in_pos]) \n\t"
  1439. "lwc1 $f7, 4(%[vec2]) \n\t"
  1440. "nmsub.s %[di0], $f0, $f1, %[IQ] \n\t"
  1441. "nmsub.s %[di1], $f2, $f3, %[IQ] \n\t"
  1442. "nmsub.s %[di2], $f4, $f5, %[IQ] \n\t"
  1443. "nmsub.s %[di3], $f6, $f7, %[IQ] \n\t"
  1444. ".set pop \n\t"
  1445. : [di0]"=&f"(di0), [di1]"=&f"(di1),
  1446. [di2]"=&f"(di2), [di3]"=&f"(di3)
  1447. : [in_pos]"r"(in_pos), [vec]"r"(vec),
  1448. [vec2]"r"(vec2), [IQ]"f"(IQ)
  1449. : "$f0", "$f1", "$f2", "$f3",
  1450. "$f4", "$f5", "$f6", "$f7",
  1451. "memory"
  1452. );
  1453. cost += di0 * di0 + di1 * di1
  1454. + di2 * di2 + di3 * di3;
  1455. }
  1456. if (bits)
  1457. *bits = curbits;
  1458. return cost * lambda + curbits;
  1459. }
  1460. static float get_band_cost_UPAIR7_mips(struct AACEncContext *s,
  1461. PutBitContext *pb, const float *in,
  1462. const float *scaled, int size, int scale_idx,
  1463. int cb, const float lambda, const float uplim,
  1464. int *bits)
  1465. {
  1466. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  1467. const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
  1468. int i;
  1469. float cost = 0;
  1470. int qc1, qc2, qc3, qc4;
  1471. int curbits = 0;
  1472. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  1473. float *p_codes = (float *)ff_aac_codebook_vectors[cb-1];
  1474. for (i = 0; i < size; i += 4) {
  1475. const float *vec, *vec2;
  1476. int curidx, curidx2, sign1, count1, sign2, count2;
  1477. int *in_int = (int *)&in[i];
  1478. float *in_pos = (float *)&in[i];
  1479. float di0, di1, di2, di3;
  1480. qc1 = scaled[i ] * Q34 + 0.4054f;
  1481. qc2 = scaled[i+1] * Q34 + 0.4054f;
  1482. qc3 = scaled[i+2] * Q34 + 0.4054f;
  1483. qc4 = scaled[i+3] * Q34 + 0.4054f;
  1484. __asm__ volatile (
  1485. ".set push \n\t"
  1486. ".set noreorder \n\t"
  1487. "ori $t4, $zero, 7 \n\t"
  1488. "ori %[sign1], $zero, 0 \n\t"
  1489. "ori %[sign2], $zero, 0 \n\t"
  1490. "slt $t0, $t4, %[qc1] \n\t"
  1491. "slt $t1, $t4, %[qc2] \n\t"
  1492. "slt $t2, $t4, %[qc3] \n\t"
  1493. "slt $t3, $t4, %[qc4] \n\t"
  1494. "movn %[qc1], $t4, $t0 \n\t"
  1495. "movn %[qc2], $t4, $t1 \n\t"
  1496. "movn %[qc3], $t4, $t2 \n\t"
  1497. "movn %[qc4], $t4, $t3 \n\t"
  1498. "lw $t0, 0(%[in_int]) \n\t"
  1499. "lw $t1, 4(%[in_int]) \n\t"
  1500. "lw $t2, 8(%[in_int]) \n\t"
  1501. "lw $t3, 12(%[in_int]) \n\t"
  1502. "slt $t0, $t0, $zero \n\t"
  1503. "movn %[sign1], $t0, %[qc1] \n\t"
  1504. "slt $t2, $t2, $zero \n\t"
  1505. "movn %[sign2], $t2, %[qc3] \n\t"
  1506. "slt $t1, $t1, $zero \n\t"
  1507. "sll $t0, %[sign1], 1 \n\t"
  1508. "or $t0, $t0, $t1 \n\t"
  1509. "movn %[sign1], $t0, %[qc2] \n\t"
  1510. "slt $t3, $t3, $zero \n\t"
  1511. "sll $t0, %[sign2], 1 \n\t"
  1512. "or $t0, $t0, $t3 \n\t"
  1513. "movn %[sign2], $t0, %[qc4] \n\t"
  1514. "slt %[count1], $zero, %[qc1] \n\t"
  1515. "slt $t1, $zero, %[qc2] \n\t"
  1516. "slt %[count2], $zero, %[qc3] \n\t"
  1517. "slt $t2, $zero, %[qc4] \n\t"
  1518. "addu %[count1], %[count1], $t1 \n\t"
  1519. "addu %[count2], %[count2], $t2 \n\t"
  1520. ".set pop \n\t"
  1521. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  1522. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  1523. [sign1]"=&r"(sign1), [count1]"=&r"(count1),
  1524. [sign2]"=&r"(sign2), [count2]"=&r"(count2)
  1525. : [in_int]"r"(in_int)
  1526. : "t0", "t1", "t2", "t3", "t4",
  1527. "memory"
  1528. );
  1529. curidx = 8 * qc1;
  1530. curidx += qc2;
  1531. curidx2 = 8 * qc3;
  1532. curidx2 += qc4;
  1533. curbits += p_bits[curidx];
  1534. curbits += upair7_sign_bits[curidx];
  1535. vec = &p_codes[curidx*2];
  1536. curbits += p_bits[curidx2];
  1537. curbits += upair7_sign_bits[curidx2];
  1538. vec2 = &p_codes[curidx2*2];
  1539. __asm__ volatile (
  1540. ".set push \n\t"
  1541. ".set noreorder \n\t"
  1542. "lwc1 %[di0], 0(%[in_pos]) \n\t"
  1543. "lwc1 %[di1], 4(%[in_pos]) \n\t"
  1544. "lwc1 %[di2], 8(%[in_pos]) \n\t"
  1545. "lwc1 %[di3], 12(%[in_pos]) \n\t"
  1546. "abs.s %[di0], %[di0] \n\t"
  1547. "abs.s %[di1], %[di1] \n\t"
  1548. "abs.s %[di2], %[di2] \n\t"
  1549. "abs.s %[di3], %[di3] \n\t"
  1550. "lwc1 $f0, 0(%[vec]) \n\t"
  1551. "lwc1 $f1, 4(%[vec]) \n\t"
  1552. "lwc1 $f2, 0(%[vec2]) \n\t"
  1553. "lwc1 $f3, 4(%[vec2]) \n\t"
  1554. "nmsub.s %[di0], %[di0], $f0, %[IQ] \n\t"
  1555. "nmsub.s %[di1], %[di1], $f1, %[IQ] \n\t"
  1556. "nmsub.s %[di2], %[di2], $f2, %[IQ] \n\t"
  1557. "nmsub.s %[di3], %[di3], $f3, %[IQ] \n\t"
  1558. ".set pop \n\t"
  1559. : [di0]"=&f"(di0), [di1]"=&f"(di1),
  1560. [di2]"=&f"(di2), [di3]"=&f"(di3)
  1561. : [in_pos]"r"(in_pos), [vec]"r"(vec),
  1562. [vec2]"r"(vec2), [IQ]"f"(IQ)
  1563. : "$f0", "$f1", "$f2", "$f3",
  1564. "memory"
  1565. );
  1566. cost += di0 * di0 + di1 * di1
  1567. + di2 * di2 + di3 * di3;
  1568. }
  1569. if (bits)
  1570. *bits = curbits;
  1571. return cost * lambda + curbits;
  1572. }
  1573. static float get_band_cost_UPAIR12_mips(struct AACEncContext *s,
  1574. PutBitContext *pb, const float *in,
  1575. const float *scaled, int size, int scale_idx,
  1576. int cb, const float lambda, const float uplim,
  1577. int *bits)
  1578. {
  1579. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  1580. const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
  1581. int i;
  1582. float cost = 0;
  1583. int qc1, qc2, qc3, qc4;
  1584. int curbits = 0;
  1585. uint8_t *p_bits = (uint8_t *)ff_aac_spectral_bits[cb-1];
  1586. float *p_codes = (float *)ff_aac_codebook_vectors[cb-1];
  1587. for (i = 0; i < size; i += 4) {
  1588. const float *vec, *vec2;
  1589. int curidx, curidx2;
  1590. int sign1, count1, sign2, count2;
  1591. int *in_int = (int *)&in[i];
  1592. float *in_pos = (float *)&in[i];
  1593. float di0, di1, di2, di3;
  1594. qc1 = scaled[i ] * Q34 + 0.4054f;
  1595. qc2 = scaled[i+1] * Q34 + 0.4054f;
  1596. qc3 = scaled[i+2] * Q34 + 0.4054f;
  1597. qc4 = scaled[i+3] * Q34 + 0.4054f;
  1598. __asm__ volatile (
  1599. ".set push \n\t"
  1600. ".set noreorder \n\t"
  1601. "ori $t4, $zero, 12 \n\t"
  1602. "ori %[sign1], $zero, 0 \n\t"
  1603. "ori %[sign2], $zero, 0 \n\t"
  1604. "slt $t0, $t4, %[qc1] \n\t"
  1605. "slt $t1, $t4, %[qc2] \n\t"
  1606. "slt $t2, $t4, %[qc3] \n\t"
  1607. "slt $t3, $t4, %[qc4] \n\t"
  1608. "movn %[qc1], $t4, $t0 \n\t"
  1609. "movn %[qc2], $t4, $t1 \n\t"
  1610. "movn %[qc3], $t4, $t2 \n\t"
  1611. "movn %[qc4], $t4, $t3 \n\t"
  1612. "lw $t0, 0(%[in_int]) \n\t"
  1613. "lw $t1, 4(%[in_int]) \n\t"
  1614. "lw $t2, 8(%[in_int]) \n\t"
  1615. "lw $t3, 12(%[in_int]) \n\t"
  1616. "slt $t0, $t0, $zero \n\t"
  1617. "movn %[sign1], $t0, %[qc1] \n\t"
  1618. "slt $t2, $t2, $zero \n\t"
  1619. "movn %[sign2], $t2, %[qc3] \n\t"
  1620. "slt $t1, $t1, $zero \n\t"
  1621. "sll $t0, %[sign1], 1 \n\t"
  1622. "or $t0, $t0, $t1 \n\t"
  1623. "movn %[sign1], $t0, %[qc2] \n\t"
  1624. "slt $t3, $t3, $zero \n\t"
  1625. "sll $t0, %[sign2], 1 \n\t"
  1626. "or $t0, $t0, $t3 \n\t"
  1627. "movn %[sign2], $t0, %[qc4] \n\t"
  1628. "slt %[count1], $zero, %[qc1] \n\t"
  1629. "slt $t1, $zero, %[qc2] \n\t"
  1630. "slt %[count2], $zero, %[qc3] \n\t"
  1631. "slt $t2, $zero, %[qc4] \n\t"
  1632. "addu %[count1], %[count1], $t1 \n\t"
  1633. "addu %[count2], %[count2], $t2 \n\t"
  1634. ".set pop \n\t"
  1635. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  1636. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  1637. [sign1]"=&r"(sign1), [count1]"=&r"(count1),
  1638. [sign2]"=&r"(sign2), [count2]"=&r"(count2)
  1639. : [in_int]"r"(in_int)
  1640. : "t0", "t1", "t2", "t3", "t4",
  1641. "memory"
  1642. );
  1643. curidx = 13 * qc1;
  1644. curidx += qc2;
  1645. curidx2 = 13 * qc3;
  1646. curidx2 += qc4;
  1647. curbits += p_bits[curidx];
  1648. curbits += p_bits[curidx2];
  1649. curbits += upair12_sign_bits[curidx];
  1650. curbits += upair12_sign_bits[curidx2];
  1651. vec = &p_codes[curidx*2];
  1652. vec2 = &p_codes[curidx2*2];
  1653. __asm__ volatile (
  1654. ".set push \n\t"
  1655. ".set noreorder \n\t"
  1656. "lwc1 %[di0], 0(%[in_pos]) \n\t"
  1657. "lwc1 %[di1], 4(%[in_pos]) \n\t"
  1658. "lwc1 %[di2], 8(%[in_pos]) \n\t"
  1659. "lwc1 %[di3], 12(%[in_pos]) \n\t"
  1660. "abs.s %[di0], %[di0] \n\t"
  1661. "abs.s %[di1], %[di1] \n\t"
  1662. "abs.s %[di2], %[di2] \n\t"
  1663. "abs.s %[di3], %[di3] \n\t"
  1664. "lwc1 $f0, 0(%[vec]) \n\t"
  1665. "lwc1 $f1, 4(%[vec]) \n\t"
  1666. "lwc1 $f2, 0(%[vec2]) \n\t"
  1667. "lwc1 $f3, 4(%[vec2]) \n\t"
  1668. "nmsub.s %[di0], %[di0], $f0, %[IQ] \n\t"
  1669. "nmsub.s %[di1], %[di1], $f1, %[IQ] \n\t"
  1670. "nmsub.s %[di2], %[di2], $f2, %[IQ] \n\t"
  1671. "nmsub.s %[di3], %[di3], $f3, %[IQ] \n\t"
  1672. ".set pop \n\t"
  1673. : [di0]"=&f"(di0), [di1]"=&f"(di1),
  1674. [di2]"=&f"(di2), [di3]"=&f"(di3)
  1675. : [in_pos]"r"(in_pos), [vec]"r"(vec),
  1676. [vec2]"r"(vec2), [IQ]"f"(IQ)
  1677. : "$f0", "$f1", "$f2", "$f3",
  1678. "memory"
  1679. );
  1680. cost += di0 * di0 + di1 * di1
  1681. + di2 * di2 + di3 * di3;
  1682. }
  1683. if (bits)
  1684. *bits = curbits;
  1685. return cost * lambda + curbits;
  1686. }
  1687. static float get_band_cost_ESC_mips(struct AACEncContext *s,
  1688. PutBitContext *pb, const float *in,
  1689. const float *scaled, int size, int scale_idx,
  1690. int cb, const float lambda, const float uplim,
  1691. int *bits)
  1692. {
  1693. const float Q34 = ff_aac_pow34sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
  1694. const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
  1695. const float CLIPPED_ESCAPE = 165140.0f * IQ;
  1696. int i;
  1697. float cost = 0;
  1698. int qc1, qc2, qc3, qc4;
  1699. int curbits = 0;
  1700. uint8_t *p_bits = (uint8_t*)ff_aac_spectral_bits[cb-1];
  1701. float *p_codes = (float* )ff_aac_codebook_vectors[cb-1];
  1702. for (i = 0; i < size; i += 4) {
  1703. const float *vec, *vec2;
  1704. int curidx, curidx2;
  1705. float t1, t2, t3, t4;
  1706. float di1, di2, di3, di4;
  1707. int cond0, cond1, cond2, cond3;
  1708. int c1, c2, c3, c4;
  1709. qc1 = scaled[i ] * Q34 + 0.4054f;
  1710. qc2 = scaled[i+1] * Q34 + 0.4054f;
  1711. qc3 = scaled[i+2] * Q34 + 0.4054f;
  1712. qc4 = scaled[i+3] * Q34 + 0.4054f;
  1713. __asm__ volatile (
  1714. ".set push \n\t"
  1715. ".set noreorder \n\t"
  1716. "ori $t4, $zero, 15 \n\t"
  1717. "ori $t5, $zero, 16 \n\t"
  1718. "shll_s.w %[c1], %[qc1], 18 \n\t"
  1719. "shll_s.w %[c2], %[qc2], 18 \n\t"
  1720. "shll_s.w %[c3], %[qc3], 18 \n\t"
  1721. "shll_s.w %[c4], %[qc4], 18 \n\t"
  1722. "srl %[c1], %[c1], 18 \n\t"
  1723. "srl %[c2], %[c2], 18 \n\t"
  1724. "srl %[c3], %[c3], 18 \n\t"
  1725. "srl %[c4], %[c4], 18 \n\t"
  1726. "slt %[cond0], $t4, %[qc1] \n\t"
  1727. "slt %[cond1], $t4, %[qc2] \n\t"
  1728. "slt %[cond2], $t4, %[qc3] \n\t"
  1729. "slt %[cond3], $t4, %[qc4] \n\t"
  1730. "movn %[qc1], $t5, %[cond0] \n\t"
  1731. "movn %[qc2], $t5, %[cond1] \n\t"
  1732. "movn %[qc3], $t5, %[cond2] \n\t"
  1733. "movn %[qc4], $t5, %[cond3] \n\t"
  1734. ".set pop \n\t"
  1735. : [qc1]"+r"(qc1), [qc2]"+r"(qc2),
  1736. [qc3]"+r"(qc3), [qc4]"+r"(qc4),
  1737. [cond0]"=&r"(cond0), [cond1]"=&r"(cond1),
  1738. [cond2]"=&r"(cond2), [cond3]"=&r"(cond3),
  1739. [c1]"=&r"(c1), [c2]"=&r"(c2),
  1740. [c3]"=&r"(c3), [c4]"=&r"(c4)
  1741. :
  1742. : "t4", "t5"
  1743. );
  1744. curidx = 17 * qc1;
  1745. curidx += qc2;
  1746. curidx2 = 17 * qc3;
  1747. curidx2 += qc4;
  1748. curbits += p_bits[curidx];
  1749. curbits += esc_sign_bits[curidx];
  1750. vec = &p_codes[curidx*2];
  1751. curbits += p_bits[curidx2];
  1752. curbits += esc_sign_bits[curidx2];
  1753. vec2 = &p_codes[curidx2*2];
  1754. curbits += (av_log2(c1) * 2 - 3) & (-cond0);
  1755. curbits += (av_log2(c2) * 2 - 3) & (-cond1);
  1756. curbits += (av_log2(c3) * 2 - 3) & (-cond2);
  1757. curbits += (av_log2(c4) * 2 - 3) & (-cond3);
  1758. t1 = fabsf(in[i ]);
  1759. t2 = fabsf(in[i+1]);
  1760. t3 = fabsf(in[i+2]);
  1761. t4 = fabsf(in[i+3]);
  1762. if (cond0) {
  1763. if (t1 >= CLIPPED_ESCAPE) {
  1764. di1 = t1 - CLIPPED_ESCAPE;
  1765. } else {
  1766. di1 = t1 - c1 * cbrtf(c1) * IQ;
  1767. }
  1768. } else
  1769. di1 = t1 - vec[0] * IQ;
  1770. if (cond1) {
  1771. if (t2 >= CLIPPED_ESCAPE) {
  1772. di2 = t2 - CLIPPED_ESCAPE;
  1773. } else {
  1774. di2 = t2 - c2 * cbrtf(c2) * IQ;
  1775. }
  1776. } else
  1777. di2 = t2 - vec[1] * IQ;
  1778. if (cond2) {
  1779. if (t3 >= CLIPPED_ESCAPE) {
  1780. di3 = t3 - CLIPPED_ESCAPE;
  1781. } else {
  1782. di3 = t3 - c3 * cbrtf(c3) * IQ;
  1783. }
  1784. } else
  1785. di3 = t3 - vec2[0] * IQ;
  1786. if (cond3) {
  1787. if (t4 >= CLIPPED_ESCAPE) {
  1788. di4 = t4 - CLIPPED_ESCAPE;
  1789. } else {
  1790. di4 = t4 - c4 * cbrtf(c4) * IQ;
  1791. }
  1792. } else
  1793. di4 = t4 - vec2[1]*IQ;
  1794. cost += di1 * di1 + di2 * di2
  1795. + di3 * di3 + di4 * di4;
  1796. }
  1797. if (bits)
  1798. *bits = curbits;
  1799. return cost * lambda + curbits;
  1800. }
  1801. static float (*const get_band_cost_arr[])(struct AACEncContext *s,
  1802. PutBitContext *pb, const float *in,
  1803. const float *scaled, int size, int scale_idx,
  1804. int cb, const float lambda, const float uplim,
  1805. int *bits) = {
  1806. get_band_cost_ZERO_mips,
  1807. get_band_cost_SQUAD_mips,
  1808. get_band_cost_SQUAD_mips,
  1809. get_band_cost_UQUAD_mips,
  1810. get_band_cost_UQUAD_mips,
  1811. get_band_cost_SPAIR_mips,
  1812. get_band_cost_SPAIR_mips,
  1813. get_band_cost_UPAIR7_mips,
  1814. get_band_cost_UPAIR7_mips,
  1815. get_band_cost_UPAIR12_mips,
  1816. get_band_cost_UPAIR12_mips,
  1817. get_band_cost_ESC_mips,
  1818. };
  1819. #define get_band_cost( \
  1820. s, pb, in, scaled, size, scale_idx, cb, \
  1821. lambda, uplim, bits) \
  1822. get_band_cost_arr[cb]( \
  1823. s, pb, in, scaled, size, scale_idx, cb, \
  1824. lambda, uplim, bits)
  1825. static float quantize_band_cost(struct AACEncContext *s, const float *in,
  1826. const float *scaled, int size, int scale_idx,
  1827. int cb, const float lambda, const float uplim,
  1828. int *bits)
  1829. {
  1830. return get_band_cost(s, NULL, in, scaled, size, scale_idx, cb, lambda, uplim, bits);
  1831. }
  1832. static void search_for_quantizers_twoloop_mips(AVCodecContext *avctx,
  1833. AACEncContext *s,
  1834. SingleChannelElement *sce,
  1835. const float lambda)
  1836. {
  1837. int start = 0, i, w, w2, g;
  1838. int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels;
  1839. float dists[128] = { 0 }, uplims[128];
  1840. float maxvals[128];
  1841. int fflag, minscaler;
  1842. int its = 0;
  1843. int allz = 0;
  1844. float minthr = INFINITY;
  1845. destbits = FFMIN(destbits, 5800);
  1846. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  1847. for (g = 0; g < sce->ics.num_swb; g++) {
  1848. int nz = 0;
  1849. float uplim = 0.0f;
  1850. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  1851. FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
  1852. uplim += band->threshold;
  1853. if (band->energy <= band->threshold || band->threshold == 0.0f) {
  1854. sce->zeroes[(w+w2)*16+g] = 1;
  1855. continue;
  1856. }
  1857. nz = 1;
  1858. }
  1859. uplims[w*16+g] = uplim *512;
  1860. sce->zeroes[w*16+g] = !nz;
  1861. if (nz)
  1862. minthr = FFMIN(minthr, uplim);
  1863. allz |= nz;
  1864. }
  1865. }
  1866. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  1867. for (g = 0; g < sce->ics.num_swb; g++) {
  1868. if (sce->zeroes[w*16+g]) {
  1869. sce->sf_idx[w*16+g] = SCALE_ONE_POS;
  1870. continue;
  1871. }
  1872. sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59);
  1873. }
  1874. }
  1875. if (!allz)
  1876. return;
  1877. abs_pow34_v(s->scoefs, sce->coeffs, 1024);
  1878. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  1879. start = w*128;
  1880. for (g = 0; g < sce->ics.num_swb; g++) {
  1881. const float *scaled = s->scoefs + start;
  1882. maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);
  1883. start += sce->ics.swb_sizes[g];
  1884. }
  1885. }
  1886. do {
  1887. int tbits, qstep;
  1888. minscaler = sce->sf_idx[0];
  1889. qstep = its ? 1 : 32;
  1890. do {
  1891. int prev = -1;
  1892. tbits = 0;
  1893. fflag = 0;
  1894. if (qstep > 1) {
  1895. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  1896. start = w*128;
  1897. for (g = 0; g < sce->ics.num_swb; g++) {
  1898. const float *coefs = sce->coeffs + start;
  1899. const float *scaled = s->scoefs + start;
  1900. int bits = 0;
  1901. int cb;
  1902. if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) {
  1903. start += sce->ics.swb_sizes[g];
  1904. continue;
  1905. }
  1906. minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
  1907. cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
  1908. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  1909. int b;
  1910. bits += quantize_band_cost_bits(s, coefs + w2*128,
  1911. scaled + w2*128,
  1912. sce->ics.swb_sizes[g],
  1913. sce->sf_idx[w*16+g],
  1914. cb,
  1915. 1.0f,
  1916. INFINITY,
  1917. &b);
  1918. }
  1919. if (prev != -1) {
  1920. bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO];
  1921. }
  1922. tbits += bits;
  1923. start += sce->ics.swb_sizes[g];
  1924. prev = sce->sf_idx[w*16+g];
  1925. }
  1926. }
  1927. }
  1928. else {
  1929. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  1930. start = w*128;
  1931. for (g = 0; g < sce->ics.num_swb; g++) {
  1932. const float *coefs = sce->coeffs + start;
  1933. const float *scaled = s->scoefs + start;
  1934. int bits = 0;
  1935. int cb;
  1936. float dist = 0.0f;
  1937. if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) {
  1938. start += sce->ics.swb_sizes[g];
  1939. continue;
  1940. }
  1941. minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
  1942. cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
  1943. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  1944. int b;
  1945. dist += quantize_band_cost(s, coefs + w2*128,
  1946. scaled + w2*128,
  1947. sce->ics.swb_sizes[g],
  1948. sce->sf_idx[w*16+g],
  1949. cb,
  1950. 1.0f,
  1951. INFINITY,
  1952. &b);
  1953. bits += b;
  1954. }
  1955. dists[w*16+g] = dist - bits;
  1956. if (prev != -1) {
  1957. bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO];
  1958. }
  1959. tbits += bits;
  1960. start += sce->ics.swb_sizes[g];
  1961. prev = sce->sf_idx[w*16+g];
  1962. }
  1963. }
  1964. }
  1965. if (tbits > destbits) {
  1966. for (i = 0; i < 128; i++)
  1967. if (sce->sf_idx[i] < 218 - qstep)
  1968. sce->sf_idx[i] += qstep;
  1969. } else {
  1970. for (i = 0; i < 128; i++)
  1971. if (sce->sf_idx[i] > 60 - qstep)
  1972. sce->sf_idx[i] -= qstep;
  1973. }
  1974. qstep >>= 1;
  1975. if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217)
  1976. qstep = 1;
  1977. } while (qstep);
  1978. fflag = 0;
  1979. minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF);
  1980. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  1981. for (g = 0; g < sce->ics.num_swb; g++) {
  1982. int prevsc = sce->sf_idx[w*16+g];
  1983. if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) {
  1984. if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1))
  1985. sce->sf_idx[w*16+g]--;
  1986. else
  1987. sce->sf_idx[w*16+g]-=2;
  1988. }
  1989. sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF);
  1990. sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219);
  1991. if (sce->sf_idx[w*16+g] != prevsc)
  1992. fflag = 1;
  1993. sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
  1994. }
  1995. }
  1996. its++;
  1997. } while (fflag && its < 10);
  1998. }
  1999. static void search_for_ms_mips(AACEncContext *s, ChannelElement *cpe,
  2000. const float lambda)
  2001. {
  2002. int start = 0, i, w, w2, g;
  2003. float M[128], S[128];
  2004. float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;
  2005. SingleChannelElement *sce0 = &cpe->ch[0];
  2006. SingleChannelElement *sce1 = &cpe->ch[1];
  2007. if (!cpe->common_window)
  2008. return;
  2009. for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {
  2010. for (g = 0; g < sce0->ics.num_swb; g++) {
  2011. if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {
  2012. float dist1 = 0.0f, dist2 = 0.0f;
  2013. for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {
  2014. FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];
  2015. FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];
  2016. float minthr = FFMIN(band0->threshold, band1->threshold);
  2017. float maxthr = FFMAX(band0->threshold, band1->threshold);
  2018. for (i = 0; i < sce0->ics.swb_sizes[g]; i+=4) {
  2019. M[i ] = (sce0->coeffs[start+w2*128+i ]
  2020. + sce1->coeffs[start+w2*128+i ]) * 0.5;
  2021. M[i+1] = (sce0->coeffs[start+w2*128+i+1]
  2022. + sce1->coeffs[start+w2*128+i+1]) * 0.5;
  2023. M[i+2] = (sce0->coeffs[start+w2*128+i+2]
  2024. + sce1->coeffs[start+w2*128+i+2]) * 0.5;
  2025. M[i+3] = (sce0->coeffs[start+w2*128+i+3]
  2026. + sce1->coeffs[start+w2*128+i+3]) * 0.5;
  2027. S[i ] = M[i ]
  2028. - sce1->coeffs[start+w2*128+i ];
  2029. S[i+1] = M[i+1]
  2030. - sce1->coeffs[start+w2*128+i+1];
  2031. S[i+2] = M[i+2]
  2032. - sce1->coeffs[start+w2*128+i+2];
  2033. S[i+3] = M[i+3]
  2034. - sce1->coeffs[start+w2*128+i+3];
  2035. }
  2036. abs_pow34_v(L34, sce0->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);
  2037. abs_pow34_v(R34, sce1->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);
  2038. abs_pow34_v(M34, M, sce0->ics.swb_sizes[g]);
  2039. abs_pow34_v(S34, S, sce0->ics.swb_sizes[g]);
  2040. dist1 += quantize_band_cost(s, sce0->coeffs + start + w2*128,
  2041. L34,
  2042. sce0->ics.swb_sizes[g],
  2043. sce0->sf_idx[(w+w2)*16+g],
  2044. sce0->band_type[(w+w2)*16+g],
  2045. lambda / band0->threshold, INFINITY, NULL);
  2046. dist1 += quantize_band_cost(s, sce1->coeffs + start + w2*128,
  2047. R34,
  2048. sce1->ics.swb_sizes[g],
  2049. sce1->sf_idx[(w+w2)*16+g],
  2050. sce1->band_type[(w+w2)*16+g],
  2051. lambda / band1->threshold, INFINITY, NULL);
  2052. dist2 += quantize_band_cost(s, M,
  2053. M34,
  2054. sce0->ics.swb_sizes[g],
  2055. sce0->sf_idx[(w+w2)*16+g],
  2056. sce0->band_type[(w+w2)*16+g],
  2057. lambda / maxthr, INFINITY, NULL);
  2058. dist2 += quantize_band_cost(s, S,
  2059. S34,
  2060. sce1->ics.swb_sizes[g],
  2061. sce1->sf_idx[(w+w2)*16+g],
  2062. sce1->band_type[(w+w2)*16+g],
  2063. lambda / minthr, INFINITY, NULL);
  2064. }
  2065. cpe->ms_mask[w*16+g] = dist2 < dist1;
  2066. }
  2067. start += sce0->ics.swb_sizes[g];
  2068. }
  2069. }
  2070. }
  2071. #endif /*HAVE_MIPSFPU */
  2072. static void codebook_trellis_rate_mips(AACEncContext *s, SingleChannelElement *sce,
  2073. int win, int group_len, const float lambda)
  2074. {
  2075. BandCodingPath path[120][12];
  2076. int w, swb, cb, start, size;
  2077. int i, j;
  2078. const int max_sfb = sce->ics.max_sfb;
  2079. const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
  2080. const int run_esc = (1 << run_bits) - 1;
  2081. int idx, ppos, count;
  2082. int stackrun[120], stackcb[120], stack_len;
  2083. float next_minbits = INFINITY;
  2084. int next_mincb = 0;
  2085. abs_pow34_v(s->scoefs, sce->coeffs, 1024);
  2086. start = win*128;
  2087. for (cb = 0; cb < 12; cb++) {
  2088. path[0][cb].cost = run_bits+4;
  2089. path[0][cb].prev_idx = -1;
  2090. path[0][cb].run = 0;
  2091. }
  2092. for (swb = 0; swb < max_sfb; swb++) {
  2093. size = sce->ics.swb_sizes[swb];
  2094. if (sce->zeroes[win*16 + swb]) {
  2095. float cost_stay_here = path[swb][0].cost;
  2096. float cost_get_here = next_minbits + run_bits + 4;
  2097. if ( run_value_bits[sce->ics.num_windows == 8][path[swb][0].run]
  2098. != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1])
  2099. cost_stay_here += run_bits;
  2100. if (cost_get_here < cost_stay_here) {
  2101. path[swb+1][0].prev_idx = next_mincb;
  2102. path[swb+1][0].cost = cost_get_here;
  2103. path[swb+1][0].run = 1;
  2104. } else {
  2105. path[swb+1][0].prev_idx = 0;
  2106. path[swb+1][0].cost = cost_stay_here;
  2107. path[swb+1][0].run = path[swb][0].run + 1;
  2108. }
  2109. next_minbits = path[swb+1][0].cost;
  2110. next_mincb = 0;
  2111. for (cb = 1; cb < 12; cb++) {
  2112. path[swb+1][cb].cost = 61450;
  2113. path[swb+1][cb].prev_idx = -1;
  2114. path[swb+1][cb].run = 0;
  2115. }
  2116. } else {
  2117. float minbits = next_minbits;
  2118. int mincb = next_mincb;
  2119. int startcb = sce->band_type[win*16+swb];
  2120. next_minbits = INFINITY;
  2121. next_mincb = 0;
  2122. for (cb = 0; cb < startcb; cb++) {
  2123. path[swb+1][cb].cost = 61450;
  2124. path[swb+1][cb].prev_idx = -1;
  2125. path[swb+1][cb].run = 0;
  2126. }
  2127. for (cb = startcb; cb < 12; cb++) {
  2128. float cost_stay_here, cost_get_here;
  2129. float bits = 0.0f;
  2130. for (w = 0; w < group_len; w++) {
  2131. bits += quantize_band_cost_bits(s, sce->coeffs + start + w*128,
  2132. s->scoefs + start + w*128, size,
  2133. sce->sf_idx[(win+w)*16+swb], cb,
  2134. 0, INFINITY, NULL);
  2135. }
  2136. cost_stay_here = path[swb][cb].cost + bits;
  2137. cost_get_here = minbits + bits + run_bits + 4;
  2138. if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
  2139. != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
  2140. cost_stay_here += run_bits;
  2141. if (cost_get_here < cost_stay_here) {
  2142. path[swb+1][cb].prev_idx = mincb;
  2143. path[swb+1][cb].cost = cost_get_here;
  2144. path[swb+1][cb].run = 1;
  2145. } else {
  2146. path[swb+1][cb].prev_idx = cb;
  2147. path[swb+1][cb].cost = cost_stay_here;
  2148. path[swb+1][cb].run = path[swb][cb].run + 1;
  2149. }
  2150. if (path[swb+1][cb].cost < next_minbits) {
  2151. next_minbits = path[swb+1][cb].cost;
  2152. next_mincb = cb;
  2153. }
  2154. }
  2155. }
  2156. start += sce->ics.swb_sizes[swb];
  2157. }
  2158. stack_len = 0;
  2159. idx = 0;
  2160. for (cb = 1; cb < 12; cb++)
  2161. if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
  2162. idx = cb;
  2163. ppos = max_sfb;
  2164. while (ppos > 0) {
  2165. av_assert1(idx >= 0);
  2166. cb = idx;
  2167. stackrun[stack_len] = path[ppos][cb].run;
  2168. stackcb [stack_len] = cb;
  2169. idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;
  2170. ppos -= path[ppos][cb].run;
  2171. stack_len++;
  2172. }
  2173. start = 0;
  2174. for (i = stack_len - 1; i >= 0; i--) {
  2175. put_bits(&s->pb, 4, stackcb[i]);
  2176. count = stackrun[i];
  2177. memset(sce->zeroes + win*16 + start, !stackcb[i], count);
  2178. for (j = 0; j < count; j++) {
  2179. sce->band_type[win*16 + start] = stackcb[i];
  2180. start++;
  2181. }
  2182. while (count >= run_esc) {
  2183. put_bits(&s->pb, run_bits, run_esc);
  2184. count -= run_esc;
  2185. }
  2186. put_bits(&s->pb, run_bits, count);
  2187. }
  2188. }
  2189. #endif /* HAVE_INLINE_ASM */
  2190. void ff_aac_coder_init_mips(AACEncContext *c) {
  2191. #if HAVE_INLINE_ASM
  2192. AACCoefficientsEncoder *e = c->coder;
  2193. int option = c->options.aac_coder;
  2194. if (option == 2) {
  2195. e->quantize_and_encode_band = quantize_and_encode_band_mips;
  2196. e->encode_window_bands_info = codebook_trellis_rate_mips;
  2197. #if HAVE_MIPSFPU
  2198. e->search_for_quantizers = search_for_quantizers_twoloop_mips;
  2199. e->search_for_ms = search_for_ms_mips;
  2200. #endif /* HAVE_MIPSFPU */
  2201. }
  2202. #endif /* HAVE_INLINE_ASM */
  2203. }