jsimd_arm64_neon.S 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429
  1. #ifdef __LP64__ // ESENTHEL CHANGED
  2. /*
  3. * ARMv8 NEON optimizations for libjpeg-turbo
  4. *
  5. * Copyright (C) 2009-2011, Nokia Corporation and/or its subsidiary(-ies).
  6. * All Rights Reserved.
  7. * Author: Siarhei Siamashka <[email protected]>
  8. * Copyright (C) 2013-2014, Linaro Limited. All Rights Reserved.
  9. * Author: Ragesh Radhakrishnan <[email protected]>
  10. * Copyright (C) 2014-2016, D. R. Commander. All Rights Reserved.
  11. * Copyright (C) 2015-2016, Matthieu Darbois. All Rights Reserved.
  12. * Copyright (C) 2016, Siarhei Siamashka. All Rights Reserved.
  13. *
  14. * This software is provided 'as-is', without any express or implied
  15. * warranty. In no event will the authors be held liable for any damages
  16. * arising from the use of this software.
  17. *
  18. * Permission is granted to anyone to use this software for any purpose,
  19. * including commercial applications, and to alter it and redistribute it
  20. * freely, subject to the following restrictions:
  21. *
  22. * 1. The origin of this software must not be misrepresented; you must not
  23. * claim that you wrote the original software. If you use this software
  24. * in a product, an acknowledgment in the product documentation would be
  25. * appreciated but is not required.
  26. * 2. Altered source versions must be plainly marked as such, and must not be
  27. * misrepresented as being the original software.
  28. * 3. This notice may not be removed or altered from any source distribution.
  29. */
  30. #if defined(__linux__) && defined(__ELF__)
  31. .section .note.GNU-stack, "", %progbits /* mark stack as non-executable */
  32. #endif
  33. .text
  34. #define RESPECT_STRICT_ALIGNMENT 1
  35. /*****************************************************************************/
  36. /* Supplementary macro for setting function attributes */
  37. .macro asm_function fname
  38. #ifdef __APPLE__
  39. .globl _\fname
  40. _\fname:
  41. #else
  42. .global \fname
  43. #ifdef __ELF__
  44. .hidden \fname
  45. .type \fname, %function
  46. #endif
  47. \fname:
  48. #endif
  49. .endm
  50. /* Transpose elements of single 128 bit registers */
  51. .macro transpose_single x0, x1, xi, xilen, literal
  52. ins \xi\xilen[0], \x0\xilen[0]
  53. ins \x1\xilen[0], \x0\xilen[1]
  54. trn1 \x0\literal, \x0\literal, \x1\literal
  55. trn2 \x1\literal, \xi\literal, \x1\literal
  56. .endm
  57. /* Transpose elements of 2 differnet registers */
  58. .macro transpose x0, x1, xi, xilen, literal
  59. mov \xi\xilen, \x0\xilen
  60. trn1 \x0\literal, \x0\literal, \x1\literal
  61. trn2 \x1\literal, \xi\literal, \x1\literal
  62. .endm
  63. /* Transpose a block of 4x4 coefficients in four 64-bit registers */
  64. .macro transpose_4x4_32 x0, x0len, x1, x1len, x2, x2len, x3, x3len, xi, xilen
  65. mov \xi\xilen, \x0\xilen
  66. trn1 \x0\x0len, \x0\x0len, \x2\x2len
  67. trn2 \x2\x2len, \xi\x0len, \x2\x2len
  68. mov \xi\xilen, \x1\xilen
  69. trn1 \x1\x1len, \x1\x1len, \x3\x3len
  70. trn2 \x3\x3len, \xi\x1len, \x3\x3len
  71. .endm
  72. .macro transpose_4x4_16 x0, x0len, x1, x1len, x2, x2len, x3, x3len, xi, xilen
  73. mov \xi\xilen, \x0\xilen
  74. trn1 \x0\x0len, \x0\x0len, \x1\x1len
  75. trn2 \x1\x2len, \xi\x0len, \x1\x2len
  76. mov \xi\xilen, \x2\xilen
  77. trn1 \x2\x2len, \x2\x2len, \x3\x3len
  78. trn2 \x3\x2len, \xi\x1len, \x3\x3len
  79. .endm
  80. .macro transpose_4x4 x0, x1, x2, x3, x5
  81. transpose_4x4_16 \x0, .4h, \x1, .4h, \x2, .4h, \x3, .4h, \x5, .16b
  82. transpose_4x4_32 \x0, .2s, \x1, .2s, \x2, .2s, \x3, .2s, \x5, .16b
  83. .endm
  84. .macro transpose_8x8 l0, l1, l2, l3, l4, l5, l6, l7, t0, t1, t2, t3
  85. trn1 \t0\().8h, \l0\().8h, \l1\().8h
  86. trn1 \t1\().8h, \l2\().8h, \l3\().8h
  87. trn1 \t2\().8h, \l4\().8h, \l5\().8h
  88. trn1 \t3\().8h, \l6\().8h, \l7\().8h
  89. trn2 \l1\().8h, \l0\().8h, \l1\().8h
  90. trn2 \l3\().8h, \l2\().8h, \l3\().8h
  91. trn2 \l5\().8h, \l4\().8h, \l5\().8h
  92. trn2 \l7\().8h, \l6\().8h, \l7\().8h
  93. trn1 \l4\().4s, \t2\().4s, \t3\().4s
  94. trn2 \t3\().4s, \t2\().4s, \t3\().4s
  95. trn1 \t2\().4s, \t0\().4s, \t1\().4s
  96. trn2 \l2\().4s, \t0\().4s, \t1\().4s
  97. trn1 \t0\().4s, \l1\().4s, \l3\().4s
  98. trn2 \l3\().4s, \l1\().4s, \l3\().4s
  99. trn2 \t1\().4s, \l5\().4s, \l7\().4s
  100. trn1 \l5\().4s, \l5\().4s, \l7\().4s
  101. trn2 \l6\().2d, \l2\().2d, \t3\().2d
  102. trn1 \l0\().2d, \t2\().2d, \l4\().2d
  103. trn1 \l1\().2d, \t0\().2d, \l5\().2d
  104. trn2 \l7\().2d, \l3\().2d, \t1\().2d
  105. trn1 \l2\().2d, \l2\().2d, \t3\().2d
  106. trn2 \l4\().2d, \t2\().2d, \l4\().2d
  107. trn1 \l3\().2d, \l3\().2d, \t1\().2d
  108. trn2 \l5\().2d, \t0\().2d, \l5\().2d
  109. .endm
  110. #define CENTERJSAMPLE 128
  111. /*****************************************************************************/
  112. /*
  113. * Perform dequantization and inverse DCT on one block of coefficients.
  114. *
  115. * GLOBAL(void)
  116. * jsimd_idct_islow_neon (void *dct_table, JCOEFPTR coef_block,
  117. * JSAMPARRAY output_buf, JDIMENSION output_col)
  118. */
  119. #define CONST_BITS 13
  120. #define PASS1_BITS 2
  121. #define F_0_298 2446 /* FIX(0.298631336) */
  122. #define F_0_390 3196 /* FIX(0.390180644) */
  123. #define F_0_541 4433 /* FIX(0.541196100) */
  124. #define F_0_765 6270 /* FIX(0.765366865) */
  125. #define F_0_899 7373 /* FIX(0.899976223) */
  126. #define F_1_175 9633 /* FIX(1.175875602) */
  127. #define F_1_501 12299 /* FIX(1.501321110) */
  128. #define F_1_847 15137 /* FIX(1.847759065) */
  129. #define F_1_961 16069 /* FIX(1.961570560) */
  130. #define F_2_053 16819 /* FIX(2.053119869) */
  131. #define F_2_562 20995 /* FIX(2.562915447) */
  132. #define F_3_072 25172 /* FIX(3.072711026) */
  133. .balign 16
  134. Ljsimd_idct_islow_neon_consts:
  135. .short F_0_298
  136. .short -F_0_390
  137. .short F_0_541
  138. .short F_0_765
  139. .short - F_0_899
  140. .short F_1_175
  141. .short F_1_501
  142. .short - F_1_847
  143. .short - F_1_961
  144. .short F_2_053
  145. .short - F_2_562
  146. .short F_3_072
  147. .short 0 /* padding */
  148. .short 0
  149. .short 0
  150. .short 0
  151. #undef F_0_298
  152. #undef F_0_390
  153. #undef F_0_541
  154. #undef F_0_765
  155. #undef F_0_899
  156. #undef F_1_175
  157. #undef F_1_501
  158. #undef F_1_847
  159. #undef F_1_961
  160. #undef F_2_053
  161. #undef F_2_562
  162. #undef F_3_072
  163. #define XFIX_P_0_298 v0.h[0]
  164. #define XFIX_N_0_390 v0.h[1]
  165. #define XFIX_P_0_541 v0.h[2]
  166. #define XFIX_P_0_765 v0.h[3]
  167. #define XFIX_N_0_899 v0.h[4]
  168. #define XFIX_P_1_175 v0.h[5]
  169. #define XFIX_P_1_501 v0.h[6]
  170. #define XFIX_N_1_847 v0.h[7]
  171. #define XFIX_N_1_961 v1.h[0]
  172. #define XFIX_P_2_053 v1.h[1]
  173. #define XFIX_N_2_562 v1.h[2]
  174. #define XFIX_P_3_072 v1.h[3]
  175. asm_function jsimd_idct_islow_neon
  176. DCT_TABLE .req x0
  177. COEF_BLOCK .req x1
  178. OUTPUT_BUF .req x2
  179. OUTPUT_COL .req x3
  180. TMP1 .req x0
  181. TMP2 .req x1
  182. TMP3 .req x9
  183. TMP4 .req x10
  184. TMP5 .req x11
  185. TMP6 .req x12
  186. TMP7 .req x13
  187. TMP8 .req x14
  188. /* OUTPUT_COL is a JDIMENSION (unsigned int) argument, so the ABI doesn't
  189. guarantee that the upper (unused) 32 bits of x3 are valid. This
  190. instruction ensures that those bits are set to zero. */
  191. uxtw x3, w3
  192. sub sp, sp, #64
  193. adr x15, Ljsimd_idct_islow_neon_consts
  194. mov x10, sp
  195. st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x10], #32
  196. st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x10], #32
  197. ld1 {v0.8h, v1.8h}, [x15]
  198. ld1 {v2.8h, v3.8h, v4.8h, v5.8h}, [COEF_BLOCK], #64
  199. ld1 {v18.8h, v19.8h, v20.8h, v21.8h}, [DCT_TABLE], #64
  200. ld1 {v6.8h, v7.8h, v8.8h, v9.8h}, [COEF_BLOCK], #64
  201. ld1 {v22.8h, v23.8h, v24.8h, v25.8h}, [DCT_TABLE], #64
  202. cmeq v16.8h, v3.8h, #0
  203. cmeq v26.8h, v4.8h, #0
  204. cmeq v27.8h, v5.8h, #0
  205. cmeq v28.8h, v6.8h, #0
  206. cmeq v29.8h, v7.8h, #0
  207. cmeq v30.8h, v8.8h, #0
  208. cmeq v31.8h, v9.8h, #0
  209. and v10.16b, v16.16b, v26.16b
  210. and v11.16b, v27.16b, v28.16b
  211. and v12.16b, v29.16b, v30.16b
  212. and v13.16b, v31.16b, v10.16b
  213. and v14.16b, v11.16b, v12.16b
  214. mul v2.8h, v2.8h, v18.8h
  215. and v15.16b, v13.16b, v14.16b
  216. shl v10.8h, v2.8h, #(PASS1_BITS)
  217. sqxtn v16.8b, v15.8h
  218. mov TMP1, v16.d[0]
  219. mvn TMP2, TMP1
  220. cbnz TMP2, 2f
  221. /* case all AC coeffs are zeros */
  222. dup v2.2d, v10.d[0]
  223. dup v6.2d, v10.d[1]
  224. mov v3.16b, v2.16b
  225. mov v7.16b, v6.16b
  226. mov v4.16b, v2.16b
  227. mov v8.16b, v6.16b
  228. mov v5.16b, v2.16b
  229. mov v9.16b, v6.16b
  230. 1:
  231. /* for this transpose, we should organise data like this:
  232. * 00, 01, 02, 03, 40, 41, 42, 43
  233. * 10, 11, 12, 13, 50, 51, 52, 53
  234. * 20, 21, 22, 23, 60, 61, 62, 63
  235. * 30, 31, 32, 33, 70, 71, 72, 73
  236. * 04, 05, 06, 07, 44, 45, 46, 47
  237. * 14, 15, 16, 17, 54, 55, 56, 57
  238. * 24, 25, 26, 27, 64, 65, 66, 67
  239. * 34, 35, 36, 37, 74, 75, 76, 77
  240. */
  241. trn1 v28.8h, v2.8h, v3.8h
  242. trn1 v29.8h, v4.8h, v5.8h
  243. trn1 v30.8h, v6.8h, v7.8h
  244. trn1 v31.8h, v8.8h, v9.8h
  245. trn2 v16.8h, v2.8h, v3.8h
  246. trn2 v17.8h, v4.8h, v5.8h
  247. trn2 v18.8h, v6.8h, v7.8h
  248. trn2 v19.8h, v8.8h, v9.8h
  249. trn1 v2.4s, v28.4s, v29.4s
  250. trn1 v6.4s, v30.4s, v31.4s
  251. trn1 v3.4s, v16.4s, v17.4s
  252. trn1 v7.4s, v18.4s, v19.4s
  253. trn2 v4.4s, v28.4s, v29.4s
  254. trn2 v8.4s, v30.4s, v31.4s
  255. trn2 v5.4s, v16.4s, v17.4s
  256. trn2 v9.4s, v18.4s, v19.4s
  257. /* Even part: reverse the even part of the forward DCT. */
  258. add v18.8h, v4.8h, v8.8h /* z2 + z3 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]) + DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]) */
  259. add v22.8h, v2.8h, v6.8h /* z2 + z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) + DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]) */
  260. smull2 v19.4s, v18.8h, XFIX_P_0_541 /* z1h z1 = MULTIPLY(z2 + z3, FIX_0_541196100); */
  261. sub v26.8h, v2.8h, v6.8h /* z2 - z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) - DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]) */
  262. smull v18.4s, v18.4h, XFIX_P_0_541 /* z1l z1 = MULTIPLY(z2 + z3, FIX_0_541196100); */
  263. sshll2 v23.4s, v22.8h, #(CONST_BITS) /* tmp0h tmp0 = LEFT_SHIFT(z2 + z3, CONST_BITS); */
  264. mov v21.16b, v19.16b /* tmp3 = z1 */
  265. mov v20.16b, v18.16b /* tmp3 = z1 */
  266. smlal2 v19.4s, v8.8h, XFIX_N_1_847 /* tmp2h tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); */
  267. smlal v18.4s, v8.4h, XFIX_N_1_847 /* tmp2l tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); */
  268. sshll2 v27.4s, v26.8h, #(CONST_BITS) /* tmp1h tmp1 = LEFT_SHIFT(z2 - z3, CONST_BITS); */
  269. smlal2 v21.4s, v4.8h, XFIX_P_0_765 /* tmp3h tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); */
  270. smlal v20.4s, v4.4h, XFIX_P_0_765 /* tmp3l tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); */
  271. sshll v22.4s, v22.4h, #(CONST_BITS) /* tmp0l tmp0 = LEFT_SHIFT(z2 + z3, CONST_BITS); */
  272. sshll v26.4s, v26.4h, #(CONST_BITS) /* tmp1l tmp1 = LEFT_SHIFT(z2 - z3, CONST_BITS); */
  273. add v2.4s, v22.4s, v20.4s /* tmp10l tmp10 = tmp0 + tmp3; */
  274. sub v6.4s, v22.4s, v20.4s /* tmp13l tmp13 = tmp0 - tmp3; */
  275. add v8.4s, v26.4s, v18.4s /* tmp11l tmp11 = tmp1 + tmp2; */
  276. sub v4.4s, v26.4s, v18.4s /* tmp12l tmp12 = tmp1 - tmp2; */
  277. add v28.4s, v23.4s, v21.4s /* tmp10h tmp10 = tmp0 + tmp3; */
  278. sub v31.4s, v23.4s, v21.4s /* tmp13h tmp13 = tmp0 - tmp3; */
  279. add v29.4s, v27.4s, v19.4s /* tmp11h tmp11 = tmp1 + tmp2; */
  280. sub v30.4s, v27.4s, v19.4s /* tmp12h tmp12 = tmp1 - tmp2; */
  281. /* Odd part per figure 8; the matrix is unitary and hence its
  282. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  283. */
  284. add v22.8h, v9.8h, v5.8h /* z3 = tmp0 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]) + DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]) */
  285. add v24.8h, v7.8h, v3.8h /* z4 = tmp1 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]) + DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]) */
  286. add v18.8h, v9.8h, v3.8h /* z1 = tmp0 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]) + DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]) */
  287. add v20.8h, v7.8h, v5.8h /* z2 = tmp1 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]) + DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]) */
  288. add v26.8h, v22.8h, v24.8h /* z5 = z3 + z4 */
  289. smull2 v11.4s, v9.8h, XFIX_P_0_298 /* tmp0 = MULTIPLY(tmp0, FIX_0_298631336) */
  290. smull2 v13.4s, v7.8h, XFIX_P_2_053 /* tmp1 = MULTIPLY(tmp1, FIX_2_053119869) */
  291. smull2 v15.4s, v5.8h, XFIX_P_3_072 /* tmp2 = MULTIPLY(tmp2, FIX_3_072711026) */
  292. smull2 v17.4s, v3.8h, XFIX_P_1_501 /* tmp3 = MULTIPLY(tmp3, FIX_1_501321110) */
  293. smull2 v27.4s, v26.8h, XFIX_P_1_175 /* z5h z5 = MULTIPLY(z3 + z4, FIX_1_175875602) */
  294. smull2 v23.4s, v22.8h, XFIX_N_1_961 /* z3 = MULTIPLY(z3, - FIX_1_961570560) */
  295. smull2 v25.4s, v24.8h, XFIX_N_0_390 /* z4 = MULTIPLY(z4, - FIX_0_390180644) */
  296. smull2 v19.4s, v18.8h, XFIX_N_0_899 /* z1 = MULTIPLY(z1, - FIX_0_899976223) */
  297. smull2 v21.4s, v20.8h, XFIX_N_2_562 /* z2 = MULTIPLY(z2, - FIX_2_562915447) */
  298. smull v10.4s, v9.4h, XFIX_P_0_298 /* tmp0 = MULTIPLY(tmp0, FIX_0_298631336) */
  299. smull v12.4s, v7.4h, XFIX_P_2_053 /* tmp1 = MULTIPLY(tmp1, FIX_2_053119869) */
  300. smull v14.4s, v5.4h, XFIX_P_3_072 /* tmp2 = MULTIPLY(tmp2, FIX_3_072711026) */
  301. smull v16.4s, v3.4h, XFIX_P_1_501 /* tmp3 = MULTIPLY(tmp3, FIX_1_501321110) */
  302. smull v26.4s, v26.4h, XFIX_P_1_175 /* z5l z5 = MULTIPLY(z3 + z4, FIX_1_175875602) */
  303. smull v22.4s, v22.4h, XFIX_N_1_961 /* z3 = MULTIPLY(z3, - FIX_1_961570560) */
  304. smull v24.4s, v24.4h, XFIX_N_0_390 /* z4 = MULTIPLY(z4, - FIX_0_390180644) */
  305. smull v18.4s, v18.4h, XFIX_N_0_899 /* z1 = MULTIPLY(z1, - FIX_0_899976223) */
  306. smull v20.4s, v20.4h, XFIX_N_2_562 /* z2 = MULTIPLY(z2, - FIX_2_562915447) */
  307. add v23.4s, v23.4s, v27.4s /* z3 += z5 */
  308. add v22.4s, v22.4s, v26.4s /* z3 += z5 */
  309. add v25.4s, v25.4s, v27.4s /* z4 += z5 */
  310. add v24.4s, v24.4s, v26.4s /* z4 += z5 */
  311. add v11.4s, v11.4s, v19.4s /* tmp0 += z1 */
  312. add v10.4s, v10.4s, v18.4s /* tmp0 += z1 */
  313. add v13.4s, v13.4s, v21.4s /* tmp1 += z2 */
  314. add v12.4s, v12.4s, v20.4s /* tmp1 += z2 */
  315. add v15.4s, v15.4s, v21.4s /* tmp2 += z2 */
  316. add v14.4s, v14.4s, v20.4s /* tmp2 += z2 */
  317. add v17.4s, v17.4s, v19.4s /* tmp3 += z1 */
  318. add v16.4s, v16.4s, v18.4s /* tmp3 += z1 */
  319. add v11.4s, v11.4s, v23.4s /* tmp0 += z3 */
  320. add v10.4s, v10.4s, v22.4s /* tmp0 += z3 */
  321. add v13.4s, v13.4s, v25.4s /* tmp1 += z4 */
  322. add v12.4s, v12.4s, v24.4s /* tmp1 += z4 */
  323. add v17.4s, v17.4s, v25.4s /* tmp3 += z4 */
  324. add v16.4s, v16.4s, v24.4s /* tmp3 += z4 */
  325. add v15.4s, v15.4s, v23.4s /* tmp2 += z3 */
  326. add v14.4s, v14.4s, v22.4s /* tmp2 += z3 */
  327. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  328. add v18.4s, v2.4s, v16.4s /* tmp10 + tmp3 */
  329. add v19.4s, v28.4s, v17.4s /* tmp10 + tmp3 */
  330. sub v20.4s, v2.4s, v16.4s /* tmp10 - tmp3 */
  331. sub v21.4s, v28.4s, v17.4s /* tmp10 - tmp3 */
  332. add v22.4s, v8.4s, v14.4s /* tmp11 + tmp2 */
  333. add v23.4s, v29.4s, v15.4s /* tmp11 + tmp2 */
  334. sub v24.4s, v8.4s, v14.4s /* tmp11 - tmp2 */
  335. sub v25.4s, v29.4s, v15.4s /* tmp11 - tmp2 */
  336. add v26.4s, v4.4s, v12.4s /* tmp12 + tmp1 */
  337. add v27.4s, v30.4s, v13.4s /* tmp12 + tmp1 */
  338. sub v28.4s, v4.4s, v12.4s /* tmp12 - tmp1 */
  339. sub v29.4s, v30.4s, v13.4s /* tmp12 - tmp1 */
  340. add v14.4s, v6.4s, v10.4s /* tmp13 + tmp0 */
  341. add v15.4s, v31.4s, v11.4s /* tmp13 + tmp0 */
  342. sub v16.4s, v6.4s, v10.4s /* tmp13 - tmp0 */
  343. sub v17.4s, v31.4s, v11.4s /* tmp13 - tmp0 */
  344. shrn v2.4h, v18.4s, #16 /* wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS+PASS1_BITS+3) */
  345. shrn v9.4h, v20.4s, #16 /* wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS+PASS1_BITS+3) */
  346. shrn v3.4h, v22.4s, #16 /* wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS+PASS1_BITS+3) */
  347. shrn v8.4h, v24.4s, #16 /* wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS+PASS1_BITS+3) */
  348. shrn v4.4h, v26.4s, #16 /* wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS+PASS1_BITS+3) */
  349. shrn v7.4h, v28.4s, #16 /* wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS+PASS1_BITS+3) */
  350. shrn v5.4h, v14.4s, #16 /* wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS+PASS1_BITS+3) */
  351. shrn v6.4h, v16.4s, #16 /* wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS+PASS1_BITS+3) */
  352. shrn2 v2.8h, v19.4s, #16 /* wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS+PASS1_BITS+3) */
  353. shrn2 v9.8h, v21.4s, #16 /* wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS+PASS1_BITS+3) */
  354. shrn2 v3.8h, v23.4s, #16 /* wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS+PASS1_BITS+3) */
  355. shrn2 v8.8h, v25.4s, #16 /* wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS+PASS1_BITS+3) */
  356. shrn2 v4.8h, v27.4s, #16 /* wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS+PASS1_BITS+3) */
  357. shrn2 v7.8h, v29.4s, #16 /* wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS+PASS1_BITS+3) */
  358. shrn2 v5.8h, v15.4s, #16 /* wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS+PASS1_BITS+3) */
  359. shrn2 v6.8h, v17.4s, #16 /* wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS+PASS1_BITS+3) */
  360. movi v0.16b, #(CENTERJSAMPLE)
  361. /* Prepare pointers (dual-issue with NEON instructions) */
  362. ldp TMP1, TMP2, [OUTPUT_BUF], 16
  363. sqrshrn v28.8b, v2.8h, #(CONST_BITS+PASS1_BITS+3-16)
  364. ldp TMP3, TMP4, [OUTPUT_BUF], 16
  365. sqrshrn v29.8b, v3.8h, #(CONST_BITS+PASS1_BITS+3-16)
  366. add TMP1, TMP1, OUTPUT_COL
  367. sqrshrn v30.8b, v4.8h, #(CONST_BITS+PASS1_BITS+3-16)
  368. add TMP2, TMP2, OUTPUT_COL
  369. sqrshrn v31.8b, v5.8h, #(CONST_BITS+PASS1_BITS+3-16)
  370. add TMP3, TMP3, OUTPUT_COL
  371. sqrshrn2 v28.16b, v6.8h, #(CONST_BITS+PASS1_BITS+3-16)
  372. add TMP4, TMP4, OUTPUT_COL
  373. sqrshrn2 v29.16b, v7.8h, #(CONST_BITS+PASS1_BITS+3-16)
  374. ldp TMP5, TMP6, [OUTPUT_BUF], 16
  375. sqrshrn2 v30.16b, v8.8h, #(CONST_BITS+PASS1_BITS+3-16)
  376. ldp TMP7, TMP8, [OUTPUT_BUF], 16
  377. sqrshrn2 v31.16b, v9.8h, #(CONST_BITS+PASS1_BITS+3-16)
  378. add TMP5, TMP5, OUTPUT_COL
  379. add v16.16b, v28.16b, v0.16b
  380. add TMP6, TMP6, OUTPUT_COL
  381. add v18.16b, v29.16b, v0.16b
  382. add TMP7, TMP7, OUTPUT_COL
  383. add v20.16b, v30.16b, v0.16b
  384. add TMP8, TMP8, OUTPUT_COL
  385. add v22.16b, v31.16b, v0.16b
  386. /* Transpose the final 8-bit samples */
  387. trn1 v28.16b, v16.16b, v18.16b
  388. trn1 v30.16b, v20.16b, v22.16b
  389. trn2 v29.16b, v16.16b, v18.16b
  390. trn2 v31.16b, v20.16b, v22.16b
  391. trn1 v16.8h, v28.8h, v30.8h
  392. trn2 v18.8h, v28.8h, v30.8h
  393. trn1 v20.8h, v29.8h, v31.8h
  394. trn2 v22.8h, v29.8h, v31.8h
  395. uzp1 v28.4s, v16.4s, v18.4s
  396. uzp2 v30.4s, v16.4s, v18.4s
  397. uzp1 v29.4s, v20.4s, v22.4s
  398. uzp2 v31.4s, v20.4s, v22.4s
  399. /* Store results to the output buffer */
  400. st1 {v28.d}[0], [TMP1]
  401. st1 {v29.d}[0], [TMP2]
  402. st1 {v28.d}[1], [TMP3]
  403. st1 {v29.d}[1], [TMP4]
  404. st1 {v30.d}[0], [TMP5]
  405. st1 {v31.d}[0], [TMP6]
  406. st1 {v30.d}[1], [TMP7]
  407. st1 {v31.d}[1], [TMP8]
  408. ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [sp], #32
  409. ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [sp], #32
  410. blr x30
  411. .balign 16
  412. 2:
  413. mul v3.8h, v3.8h, v19.8h
  414. mul v4.8h, v4.8h, v20.8h
  415. mul v5.8h, v5.8h, v21.8h
  416. add TMP4, xzr, TMP2, LSL #32
  417. mul v6.8h, v6.8h, v22.8h
  418. mul v7.8h, v7.8h, v23.8h
  419. adds TMP3, xzr, TMP2, LSR #32
  420. mul v8.8h, v8.8h, v24.8h
  421. mul v9.8h, v9.8h, v25.8h
  422. b.ne 3f
  423. /* Right AC coef is zero */
  424. dup v15.2d, v10.d[1]
  425. /* Even part: reverse the even part of the forward DCT. */
  426. add v18.4h, v4.4h, v8.4h /* z2 + z3 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]) + DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]) */
  427. add v22.4h, v2.4h, v6.4h /* z2 + z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) + DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]) */
  428. sub v26.4h, v2.4h, v6.4h /* z2 - z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) - DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]) */
  429. smull v18.4s, v18.4h, XFIX_P_0_541 /* z1l z1 = MULTIPLY(z2 + z3, FIX_0_541196100); */
  430. sshll v22.4s, v22.4h, #(CONST_BITS) /* tmp0l tmp0 = LEFT_SHIFT(z2 + z3, CONST_BITS); */
  431. mov v20.16b, v18.16b /* tmp3 = z1 */
  432. sshll v26.4s, v26.4h, #(CONST_BITS) /* tmp1l tmp1 = LEFT_SHIFT(z2 - z3, CONST_BITS); */
  433. smlal v18.4s, v8.4h, XFIX_N_1_847 /* tmp2l tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); */
  434. smlal v20.4s, v4.4h, XFIX_P_0_765 /* tmp3l tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); */
  435. add v2.4s, v22.4s, v20.4s /* tmp10l tmp10 = tmp0 + tmp3; */
  436. sub v6.4s, v22.4s, v20.4s /* tmp13l tmp13 = tmp0 - tmp3; */
  437. add v8.4s, v26.4s, v18.4s /* tmp11l tmp11 = tmp1 + tmp2; */
  438. sub v4.4s, v26.4s, v18.4s /* tmp12l tmp12 = tmp1 - tmp2; */
  439. /* Odd part per figure 8; the matrix is unitary and hence its
  440. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  441. */
  442. add v22.4h, v9.4h, v5.4h /* z3 = tmp0 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]) + DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]) */
  443. add v24.4h, v7.4h, v3.4h /* z4 = tmp1 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]) + DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]) */
  444. add v18.4h, v9.4h, v3.4h /* z1 = tmp0 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]) + DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]) */
  445. add v20.4h, v7.4h, v5.4h /* z2 = tmp1 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]) + DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]) */
  446. add v26.4h, v22.4h, v24.4h /* z5 = z3 + z4 */
  447. smull v10.4s, v9.4h, XFIX_P_0_298 /* tmp0 = MULTIPLY(tmp0, FIX_0_298631336) */
  448. smull v12.4s, v7.4h, XFIX_P_2_053 /* tmp1 = MULTIPLY(tmp1, FIX_2_053119869) */
  449. smull v14.4s, v5.4h, XFIX_P_3_072 /* tmp2 = MULTIPLY(tmp2, FIX_3_072711026) */
  450. smull v16.4s, v3.4h, XFIX_P_1_501 /* tmp3 = MULTIPLY(tmp3, FIX_1_501321110) */
  451. smull v26.4s, v26.4h, XFIX_P_1_175 /* z5l z5 = MULTIPLY(z3 + z4, FIX_1_175875602) */
  452. smull v22.4s, v22.4h, XFIX_N_1_961 /* z3 = MULTIPLY(z3, - FIX_1_961570560) */
  453. smull v24.4s, v24.4h, XFIX_N_0_390 /* z4 = MULTIPLY(z4, - FIX_0_390180644) */
  454. smull v18.4s, v18.4h, XFIX_N_0_899 /* z1 = MULTIPLY(z1, - FIX_0_899976223) */
  455. smull v20.4s, v20.4h, XFIX_N_2_562 /* z2 = MULTIPLY(z2, - FIX_2_562915447) */
  456. add v22.4s, v22.4s, v26.4s /* z3 += z5 */
  457. add v24.4s, v24.4s, v26.4s /* z4 += z5 */
  458. add v10.4s, v10.4s, v18.4s /* tmp0 += z1 */
  459. add v12.4s, v12.4s, v20.4s /* tmp1 += z2 */
  460. add v14.4s, v14.4s, v20.4s /* tmp2 += z2 */
  461. add v16.4s, v16.4s, v18.4s /* tmp3 += z1 */
  462. add v10.4s, v10.4s, v22.4s /* tmp0 += z3 */
  463. add v12.4s, v12.4s, v24.4s /* tmp1 += z4 */
  464. add v16.4s, v16.4s, v24.4s /* tmp3 += z4 */
  465. add v14.4s, v14.4s, v22.4s /* tmp2 += z3 */
  466. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  467. add v18.4s, v2.4s, v16.4s /* tmp10 + tmp3 */
  468. sub v20.4s, v2.4s, v16.4s /* tmp10 - tmp3 */
  469. add v22.4s, v8.4s, v14.4s /* tmp11 + tmp2 */
  470. sub v24.4s, v8.4s, v14.4s /* tmp11 - tmp2 */
  471. add v26.4s, v4.4s, v12.4s /* tmp12 + tmp1 */
  472. sub v28.4s, v4.4s, v12.4s /* tmp12 - tmp1 */
  473. add v14.4s, v6.4s, v10.4s /* tmp13 + tmp0 */
  474. sub v16.4s, v6.4s, v10.4s /* tmp13 - tmp0 */
  475. rshrn v2.4h, v18.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS) */
  476. rshrn v3.4h, v22.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS) */
  477. rshrn v4.4h, v26.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS) */
  478. rshrn v5.4h, v14.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS) */
  479. rshrn2 v2.8h, v16.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS) */
  480. rshrn2 v3.8h, v28.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS) */
  481. rshrn2 v4.8h, v24.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS) */
  482. rshrn2 v5.8h, v20.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS) */
  483. mov v6.16b, v15.16b
  484. mov v7.16b, v15.16b
  485. mov v8.16b, v15.16b
  486. mov v9.16b, v15.16b
  487. b 1b
  488. .balign 16
  489. 3:
  490. cbnz TMP4, 4f
  491. /* Left AC coef is zero */
  492. dup v14.2d, v10.d[0]
  493. /* Even part: reverse the even part of the forward DCT. */
  494. add v18.8h, v4.8h, v8.8h /* z2 + z3 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]) + DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]) */
  495. add v22.8h, v2.8h, v6.8h /* z2 + z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) + DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]) */
  496. smull2 v19.4s, v18.8h, XFIX_P_0_541 /* z1h z1 = MULTIPLY(z2 + z3, FIX_0_541196100); */
  497. sub v26.8h, v2.8h, v6.8h /* z2 - z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) - DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]) */
  498. sshll2 v23.4s, v22.8h, #(CONST_BITS) /* tmp0h tmp0 = LEFT_SHIFT(z2 + z3, CONST_BITS); */
  499. mov v21.16b, v19.16b /* tmp3 = z1 */
  500. smlal2 v19.4s, v8.8h, XFIX_N_1_847 /* tmp2h tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); */
  501. sshll2 v27.4s, v26.8h, #(CONST_BITS) /* tmp1h tmp1 = LEFT_SHIFT(z2 - z3, CONST_BITS); */
  502. smlal2 v21.4s, v4.8h, XFIX_P_0_765 /* tmp3h tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); */
  503. add v28.4s, v23.4s, v21.4s /* tmp10h tmp10 = tmp0 + tmp3; */
  504. sub v31.4s, v23.4s, v21.4s /* tmp13h tmp13 = tmp0 - tmp3; */
  505. add v29.4s, v27.4s, v19.4s /* tmp11h tmp11 = tmp1 + tmp2; */
  506. sub v30.4s, v27.4s, v19.4s /* tmp12h tmp12 = tmp1 - tmp2; */
  507. /* Odd part per figure 8; the matrix is unitary and hence its
  508. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  509. */
  510. add v22.8h, v9.8h, v5.8h /* z3 = tmp0 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]) + DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]) */
  511. add v24.8h, v7.8h, v3.8h /* z4 = tmp1 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]) + DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]) */
  512. add v18.8h, v9.8h, v3.8h /* z1 = tmp0 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]) + DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]) */
  513. add v20.8h, v7.8h, v5.8h /* z2 = tmp1 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]) + DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]) */
  514. add v26.8h, v22.8h, v24.8h /* z5 = z3 + z4 */
  515. smull2 v11.4s, v9.8h, XFIX_P_0_298 /* tmp0 = MULTIPLY(tmp0, FIX_0_298631336) */
  516. smull2 v13.4s, v7.8h, XFIX_P_2_053 /* tmp1 = MULTIPLY(tmp1, FIX_2_053119869) */
  517. smull2 v15.4s, v5.8h, XFIX_P_3_072 /* tmp2 = MULTIPLY(tmp2, FIX_3_072711026) */
  518. smull2 v17.4s, v3.8h, XFIX_P_1_501 /* tmp3 = MULTIPLY(tmp3, FIX_1_501321110) */
  519. smull2 v27.4s, v26.8h, XFIX_P_1_175 /* z5h z5 = MULTIPLY(z3 + z4, FIX_1_175875602) */
  520. smull2 v23.4s, v22.8h, XFIX_N_1_961 /* z3 = MULTIPLY(z3, - FIX_1_961570560) */
  521. smull2 v25.4s, v24.8h, XFIX_N_0_390 /* z4 = MULTIPLY(z4, - FIX_0_390180644) */
  522. smull2 v19.4s, v18.8h, XFIX_N_0_899 /* z1 = MULTIPLY(z1, - FIX_0_899976223) */
  523. smull2 v21.4s, v20.8h, XFIX_N_2_562 /* z2 = MULTIPLY(z2, - FIX_2_562915447) */
  524. add v23.4s, v23.4s, v27.4s /* z3 += z5 */
  525. add v22.4s, v22.4s, v26.4s /* z3 += z5 */
  526. add v25.4s, v25.4s, v27.4s /* z4 += z5 */
  527. add v24.4s, v24.4s, v26.4s /* z4 += z5 */
  528. add v11.4s, v11.4s, v19.4s /* tmp0 += z1 */
  529. add v13.4s, v13.4s, v21.4s /* tmp1 += z2 */
  530. add v15.4s, v15.4s, v21.4s /* tmp2 += z2 */
  531. add v17.4s, v17.4s, v19.4s /* tmp3 += z1 */
  532. add v11.4s, v11.4s, v23.4s /* tmp0 += z3 */
  533. add v13.4s, v13.4s, v25.4s /* tmp1 += z4 */
  534. add v17.4s, v17.4s, v25.4s /* tmp3 += z4 */
  535. add v15.4s, v15.4s, v23.4s /* tmp2 += z3 */
  536. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  537. add v19.4s, v28.4s, v17.4s /* tmp10 + tmp3 */
  538. sub v21.4s, v28.4s, v17.4s /* tmp10 - tmp3 */
  539. add v23.4s, v29.4s, v15.4s /* tmp11 + tmp2 */
  540. sub v25.4s, v29.4s, v15.4s /* tmp11 - tmp2 */
  541. add v27.4s, v30.4s, v13.4s /* tmp12 + tmp1 */
  542. sub v29.4s, v30.4s, v13.4s /* tmp12 - tmp1 */
  543. add v15.4s, v31.4s, v11.4s /* tmp13 + tmp0 */
  544. sub v17.4s, v31.4s, v11.4s /* tmp13 - tmp0 */
  545. mov v2.16b, v14.16b
  546. mov v3.16b, v14.16b
  547. mov v4.16b, v14.16b
  548. mov v5.16b, v14.16b
  549. rshrn v6.4h, v19.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS) */
  550. rshrn v7.4h, v23.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS) */
  551. rshrn v8.4h, v27.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS) */
  552. rshrn v9.4h, v15.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS) */
  553. rshrn2 v6.8h, v17.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS) */
  554. rshrn2 v7.8h, v29.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS) */
  555. rshrn2 v8.8h, v25.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS) */
  556. rshrn2 v9.8h, v21.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS) */
  557. b 1b
  558. .balign 16
  559. 4:
  560. /* "No" AC coef is zero */
  561. /* Even part: reverse the even part of the forward DCT. */
  562. add v18.8h, v4.8h, v8.8h /* z2 + z3 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]) + DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]) */
  563. add v22.8h, v2.8h, v6.8h /* z2 + z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) + DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]) */
  564. smull2 v19.4s, v18.8h, XFIX_P_0_541 /* z1h z1 = MULTIPLY(z2 + z3, FIX_0_541196100); */
  565. sub v26.8h, v2.8h, v6.8h /* z2 - z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) - DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]) */
  566. smull v18.4s, v18.4h, XFIX_P_0_541 /* z1l z1 = MULTIPLY(z2 + z3, FIX_0_541196100); */
  567. sshll2 v23.4s, v22.8h, #(CONST_BITS) /* tmp0h tmp0 = LEFT_SHIFT(z2 + z3, CONST_BITS); */
  568. mov v21.16b, v19.16b /* tmp3 = z1 */
  569. mov v20.16b, v18.16b /* tmp3 = z1 */
  570. smlal2 v19.4s, v8.8h, XFIX_N_1_847 /* tmp2h tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); */
  571. smlal v18.4s, v8.4h, XFIX_N_1_847 /* tmp2l tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065); */
  572. sshll2 v27.4s, v26.8h, #(CONST_BITS) /* tmp1h tmp1 = LEFT_SHIFT(z2 - z3, CONST_BITS); */
  573. smlal2 v21.4s, v4.8h, XFIX_P_0_765 /* tmp3h tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); */
  574. smlal v20.4s, v4.4h, XFIX_P_0_765 /* tmp3l tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865); */
  575. sshll v22.4s, v22.4h, #(CONST_BITS) /* tmp0l tmp0 = LEFT_SHIFT(z2 + z3, CONST_BITS); */
  576. sshll v26.4s, v26.4h, #(CONST_BITS) /* tmp1l tmp1 = LEFT_SHIFT(z2 - z3, CONST_BITS); */
  577. add v2.4s, v22.4s, v20.4s /* tmp10l tmp10 = tmp0 + tmp3; */
  578. sub v6.4s, v22.4s, v20.4s /* tmp13l tmp13 = tmp0 - tmp3; */
  579. add v8.4s, v26.4s, v18.4s /* tmp11l tmp11 = tmp1 + tmp2; */
  580. sub v4.4s, v26.4s, v18.4s /* tmp12l tmp12 = tmp1 - tmp2; */
  581. add v28.4s, v23.4s, v21.4s /* tmp10h tmp10 = tmp0 + tmp3; */
  582. sub v31.4s, v23.4s, v21.4s /* tmp13h tmp13 = tmp0 - tmp3; */
  583. add v29.4s, v27.4s, v19.4s /* tmp11h tmp11 = tmp1 + tmp2; */
  584. sub v30.4s, v27.4s, v19.4s /* tmp12h tmp12 = tmp1 - tmp2; */
  585. /* Odd part per figure 8; the matrix is unitary and hence its
  586. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
  587. */
  588. add v22.8h, v9.8h, v5.8h /* z3 = tmp0 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]) + DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]) */
  589. add v24.8h, v7.8h, v3.8h /* z4 = tmp1 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]) + DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]) */
  590. add v18.8h, v9.8h, v3.8h /* z1 = tmp0 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]) + DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]) */
  591. add v20.8h, v7.8h, v5.8h /* z2 = tmp1 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]) + DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]) */
  592. add v26.8h, v22.8h, v24.8h /* z5 = z3 + z4 */
  593. smull2 v11.4s, v9.8h, XFIX_P_0_298 /* tmp0 = MULTIPLY(tmp0, FIX_0_298631336) */
  594. smull2 v13.4s, v7.8h, XFIX_P_2_053 /* tmp1 = MULTIPLY(tmp1, FIX_2_053119869) */
  595. smull2 v15.4s, v5.8h, XFIX_P_3_072 /* tmp2 = MULTIPLY(tmp2, FIX_3_072711026) */
  596. smull2 v17.4s, v3.8h, XFIX_P_1_501 /* tmp3 = MULTIPLY(tmp3, FIX_1_501321110) */
  597. smull2 v27.4s, v26.8h, XFIX_P_1_175 /* z5h z5 = MULTIPLY(z3 + z4, FIX_1_175875602) */
  598. smull2 v23.4s, v22.8h, XFIX_N_1_961 /* z3 = MULTIPLY(z3, - FIX_1_961570560) */
  599. smull2 v25.4s, v24.8h, XFIX_N_0_390 /* z4 = MULTIPLY(z4, - FIX_0_390180644) */
  600. smull2 v19.4s, v18.8h, XFIX_N_0_899 /* z1 = MULTIPLY(z1, - FIX_0_899976223) */
  601. smull2 v21.4s, v20.8h, XFIX_N_2_562 /* z2 = MULTIPLY(z2, - FIX_2_562915447) */
  602. smull v10.4s, v9.4h, XFIX_P_0_298 /* tmp0 = MULTIPLY(tmp0, FIX_0_298631336) */
  603. smull v12.4s, v7.4h, XFIX_P_2_053 /* tmp1 = MULTIPLY(tmp1, FIX_2_053119869) */
  604. smull v14.4s, v5.4h, XFIX_P_3_072 /* tmp2 = MULTIPLY(tmp2, FIX_3_072711026) */
  605. smull v16.4s, v3.4h, XFIX_P_1_501 /* tmp3 = MULTIPLY(tmp3, FIX_1_501321110) */
  606. smull v26.4s, v26.4h, XFIX_P_1_175 /* z5l z5 = MULTIPLY(z3 + z4, FIX_1_175875602) */
  607. smull v22.4s, v22.4h, XFIX_N_1_961 /* z3 = MULTIPLY(z3, - FIX_1_961570560) */
  608. smull v24.4s, v24.4h, XFIX_N_0_390 /* z4 = MULTIPLY(z4, - FIX_0_390180644) */
  609. smull v18.4s, v18.4h, XFIX_N_0_899 /* z1 = MULTIPLY(z1, - FIX_0_899976223) */
  610. smull v20.4s, v20.4h, XFIX_N_2_562 /* z2 = MULTIPLY(z2, - FIX_2_562915447) */
  611. add v23.4s, v23.4s, v27.4s /* z3 += z5 */
  612. add v22.4s, v22.4s, v26.4s /* z3 += z5 */
  613. add v25.4s, v25.4s, v27.4s /* z4 += z5 */
  614. add v24.4s, v24.4s, v26.4s /* z4 += z5 */
  615. add v11.4s, v11.4s, v19.4s /* tmp0 += z1 */
  616. add v10.4s, v10.4s, v18.4s /* tmp0 += z1 */
  617. add v13.4s, v13.4s, v21.4s /* tmp1 += z2 */
  618. add v12.4s, v12.4s, v20.4s /* tmp1 += z2 */
  619. add v15.4s, v15.4s, v21.4s /* tmp2 += z2 */
  620. add v14.4s, v14.4s, v20.4s /* tmp2 += z2 */
  621. add v17.4s, v17.4s, v19.4s /* tmp3 += z1 */
  622. add v16.4s, v16.4s, v18.4s /* tmp3 += z1 */
  623. add v11.4s, v11.4s, v23.4s /* tmp0 += z3 */
  624. add v10.4s, v10.4s, v22.4s /* tmp0 += z3 */
  625. add v13.4s, v13.4s, v25.4s /* tmp1 += z4 */
  626. add v12.4s, v12.4s, v24.4s /* tmp1 += z4 */
  627. add v17.4s, v17.4s, v25.4s /* tmp3 += z4 */
  628. add v16.4s, v16.4s, v24.4s /* tmp3 += z4 */
  629. add v15.4s, v15.4s, v23.4s /* tmp2 += z3 */
  630. add v14.4s, v14.4s, v22.4s /* tmp2 += z3 */
  631. /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  632. add v18.4s, v2.4s, v16.4s /* tmp10 + tmp3 */
  633. add v19.4s, v28.4s, v17.4s /* tmp10 + tmp3 */
  634. sub v20.4s, v2.4s, v16.4s /* tmp10 - tmp3 */
  635. sub v21.4s, v28.4s, v17.4s /* tmp10 - tmp3 */
  636. add v22.4s, v8.4s, v14.4s /* tmp11 + tmp2 */
  637. add v23.4s, v29.4s, v15.4s /* tmp11 + tmp2 */
  638. sub v24.4s, v8.4s, v14.4s /* tmp11 - tmp2 */
  639. sub v25.4s, v29.4s, v15.4s /* tmp11 - tmp2 */
  640. add v26.4s, v4.4s, v12.4s /* tmp12 + tmp1 */
  641. add v27.4s, v30.4s, v13.4s /* tmp12 + tmp1 */
  642. sub v28.4s, v4.4s, v12.4s /* tmp12 - tmp1 */
  643. sub v29.4s, v30.4s, v13.4s /* tmp12 - tmp1 */
  644. add v14.4s, v6.4s, v10.4s /* tmp13 + tmp0 */
  645. add v15.4s, v31.4s, v11.4s /* tmp13 + tmp0 */
  646. sub v16.4s, v6.4s, v10.4s /* tmp13 - tmp0 */
  647. sub v17.4s, v31.4s, v11.4s /* tmp13 - tmp0 */
  648. rshrn v2.4h, v18.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS) */
  649. rshrn v3.4h, v22.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS) */
  650. rshrn v4.4h, v26.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS) */
  651. rshrn v5.4h, v14.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS) */
  652. rshrn v6.4h, v19.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS) */
  653. rshrn v7.4h, v23.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS) */
  654. rshrn v8.4h, v27.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS) */
  655. rshrn v9.4h, v15.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS) */
  656. rshrn2 v2.8h, v16.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS) */
  657. rshrn2 v3.8h, v28.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS) */
  658. rshrn2 v4.8h, v24.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS) */
  659. rshrn2 v5.8h, v20.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS) */
  660. rshrn2 v6.8h, v17.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS) */
  661. rshrn2 v7.8h, v29.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS) */
  662. rshrn2 v8.8h, v25.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS) */
  663. rshrn2 v9.8h, v21.4s, #(CONST_BITS-PASS1_BITS) /* wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS) */
  664. b 1b
  665. .unreq DCT_TABLE
  666. .unreq COEF_BLOCK
  667. .unreq OUTPUT_BUF
  668. .unreq OUTPUT_COL
  669. .unreq TMP1
  670. .unreq TMP2
  671. .unreq TMP3
  672. .unreq TMP4
  673. .unreq TMP5
  674. .unreq TMP6
  675. .unreq TMP7
  676. .unreq TMP8
  677. #undef CENTERJSAMPLE
  678. #undef CONST_BITS
  679. #undef PASS1_BITS
  680. #undef XFIX_P_0_298
  681. #undef XFIX_N_0_390
  682. #undef XFIX_P_0_541
  683. #undef XFIX_P_0_765
  684. #undef XFIX_N_0_899
  685. #undef XFIX_P_1_175
  686. #undef XFIX_P_1_501
  687. #undef XFIX_N_1_847
  688. #undef XFIX_N_1_961
  689. #undef XFIX_P_2_053
  690. #undef XFIX_N_2_562
  691. #undef XFIX_P_3_072
  692. /*****************************************************************************/
  693. /*
  694. * jsimd_idct_ifast_neon
  695. *
  696. * This function contains a fast, not so accurate integer implementation of
  697. * the inverse DCT (Discrete Cosine Transform). It uses the same calculations
  698. * and produces exactly the same output as IJG's original 'jpeg_idct_ifast'
  699. * function from jidctfst.c
  700. *
  701. * Normally 1-D AAN DCT needs 5 multiplications and 29 additions.
  702. * But in ARM NEON case some extra additions are required because VQDMULH
  703. * instruction can't handle the constants larger than 1. So the expressions
  704. * like "x * 1.082392200" have to be converted to "x * 0.082392200 + x",
  705. * which introduces an extra addition. Overall, there are 6 extra additions
  706. * per 1-D IDCT pass, totalling to 5 VQDMULH and 35 VADD/VSUB instructions.
  707. */
  708. #define XFIX_1_082392200 v0.h[0]
  709. #define XFIX_1_414213562 v0.h[1]
  710. #define XFIX_1_847759065 v0.h[2]
  711. #define XFIX_2_613125930 v0.h[3]
  712. .balign 16
  713. Ljsimd_idct_ifast_neon_consts:
  714. .short (277 * 128 - 256 * 128) /* XFIX_1_082392200 */
  715. .short (362 * 128 - 256 * 128) /* XFIX_1_414213562 */
  716. .short (473 * 128 - 256 * 128) /* XFIX_1_847759065 */
  717. .short (669 * 128 - 512 * 128) /* XFIX_2_613125930 */
  718. asm_function jsimd_idct_ifast_neon
  719. DCT_TABLE .req x0
  720. COEF_BLOCK .req x1
  721. OUTPUT_BUF .req x2
  722. OUTPUT_COL .req x3
  723. TMP1 .req x0
  724. TMP2 .req x1
  725. TMP3 .req x9
  726. TMP4 .req x10
  727. TMP5 .req x11
  728. TMP6 .req x12
  729. TMP7 .req x13
  730. TMP8 .req x14
  731. /* OUTPUT_COL is a JDIMENSION (unsigned int) argument, so the ABI doesn't
  732. guarantee that the upper (unused) 32 bits of x3 are valid. This
  733. instruction ensures that those bits are set to zero. */
  734. uxtw x3, w3
  735. /* Load and dequantize coefficients into NEON registers
  736. * with the following allocation:
  737. * 0 1 2 3 | 4 5 6 7
  738. * ---------+--------
  739. * 0 | d16 | d17 ( v16.8h )
  740. * 1 | d18 | d19 ( v17.8h )
  741. * 2 | d20 | d21 ( v18.8h )
  742. * 3 | d22 | d23 ( v19.8h )
  743. * 4 | d24 | d25 ( v20.8h )
  744. * 5 | d26 | d27 ( v21.8h )
  745. * 6 | d28 | d29 ( v22.8h )
  746. * 7 | d30 | d31 ( v23.8h )
  747. */
  748. /* Save NEON registers used in fast IDCT */
  749. adr TMP5, Ljsimd_idct_ifast_neon_consts
  750. ld1 {v16.8h, v17.8h}, [COEF_BLOCK], 32
  751. ld1 {v0.8h, v1.8h}, [DCT_TABLE], 32
  752. ld1 {v18.8h, v19.8h}, [COEF_BLOCK], 32
  753. mul v16.8h, v16.8h, v0.8h
  754. ld1 {v2.8h, v3.8h}, [DCT_TABLE], 32
  755. mul v17.8h, v17.8h, v1.8h
  756. ld1 {v20.8h, v21.8h}, [COEF_BLOCK], 32
  757. mul v18.8h, v18.8h, v2.8h
  758. ld1 {v0.8h, v1.8h}, [DCT_TABLE], 32
  759. mul v19.8h, v19.8h, v3.8h
  760. ld1 {v22.8h, v23.8h}, [COEF_BLOCK], 32
  761. mul v20.8h, v20.8h, v0.8h
  762. ld1 {v2.8h, v3.8h}, [DCT_TABLE], 32
  763. mul v22.8h, v22.8h, v2.8h
  764. mul v21.8h, v21.8h, v1.8h
  765. ld1 {v0.4h}, [TMP5] /* load constants */
  766. mul v23.8h, v23.8h, v3.8h
  767. /* 1-D IDCT, pass 1 */
  768. sub v2.8h, v18.8h, v22.8h
  769. add v22.8h, v18.8h, v22.8h
  770. sub v1.8h, v19.8h, v21.8h
  771. add v21.8h, v19.8h, v21.8h
  772. sub v5.8h, v17.8h, v23.8h
  773. add v23.8h, v17.8h, v23.8h
  774. sqdmulh v4.8h, v2.8h, XFIX_1_414213562
  775. sqdmulh v6.8h, v1.8h, XFIX_2_613125930
  776. add v3.8h, v1.8h, v1.8h
  777. sub v1.8h, v5.8h, v1.8h
  778. add v18.8h, v2.8h, v4.8h
  779. sqdmulh v4.8h, v1.8h, XFIX_1_847759065
  780. sub v2.8h, v23.8h, v21.8h
  781. add v3.8h, v3.8h, v6.8h
  782. sqdmulh v6.8h, v2.8h, XFIX_1_414213562
  783. add v1.8h, v1.8h, v4.8h
  784. sqdmulh v4.8h, v5.8h, XFIX_1_082392200
  785. sub v18.8h, v18.8h, v22.8h
  786. add v2.8h, v2.8h, v6.8h
  787. sub v6.8h, v16.8h, v20.8h
  788. add v20.8h, v16.8h, v20.8h
  789. add v17.8h, v5.8h, v4.8h
  790. add v5.8h, v6.8h, v18.8h
  791. sub v18.8h, v6.8h, v18.8h
  792. add v6.8h, v23.8h, v21.8h
  793. add v16.8h, v20.8h, v22.8h
  794. sub v3.8h, v6.8h, v3.8h
  795. sub v20.8h, v20.8h, v22.8h
  796. sub v3.8h, v3.8h, v1.8h
  797. sub v1.8h, v17.8h, v1.8h
  798. add v2.8h, v3.8h, v2.8h
  799. sub v23.8h, v16.8h, v6.8h
  800. add v1.8h, v1.8h, v2.8h
  801. add v16.8h, v16.8h, v6.8h
  802. add v22.8h, v5.8h, v3.8h
  803. sub v17.8h, v5.8h, v3.8h
  804. sub v21.8h, v18.8h, v2.8h
  805. add v18.8h, v18.8h, v2.8h
  806. sub v19.8h, v20.8h, v1.8h
  807. add v20.8h, v20.8h, v1.8h
  808. transpose_8x8 v16, v17, v18, v19, v20, v21, v22, v23, v28, v29, v30, v31
  809. /* 1-D IDCT, pass 2 */
  810. sub v2.8h, v18.8h, v22.8h
  811. add v22.8h, v18.8h, v22.8h
  812. sub v1.8h, v19.8h, v21.8h
  813. add v21.8h, v19.8h, v21.8h
  814. sub v5.8h, v17.8h, v23.8h
  815. add v23.8h, v17.8h, v23.8h
  816. sqdmulh v4.8h, v2.8h, XFIX_1_414213562
  817. sqdmulh v6.8h, v1.8h, XFIX_2_613125930
  818. add v3.8h, v1.8h, v1.8h
  819. sub v1.8h, v5.8h, v1.8h
  820. add v18.8h, v2.8h, v4.8h
  821. sqdmulh v4.8h, v1.8h, XFIX_1_847759065
  822. sub v2.8h, v23.8h, v21.8h
  823. add v3.8h, v3.8h, v6.8h
  824. sqdmulh v6.8h, v2.8h, XFIX_1_414213562
  825. add v1.8h, v1.8h, v4.8h
  826. sqdmulh v4.8h, v5.8h, XFIX_1_082392200
  827. sub v18.8h, v18.8h, v22.8h
  828. add v2.8h, v2.8h, v6.8h
  829. sub v6.8h, v16.8h, v20.8h
  830. add v20.8h, v16.8h, v20.8h
  831. add v17.8h, v5.8h, v4.8h
  832. add v5.8h, v6.8h, v18.8h
  833. sub v18.8h, v6.8h, v18.8h
  834. add v6.8h, v23.8h, v21.8h
  835. add v16.8h, v20.8h, v22.8h
  836. sub v3.8h, v6.8h, v3.8h
  837. sub v20.8h, v20.8h, v22.8h
  838. sub v3.8h, v3.8h, v1.8h
  839. sub v1.8h, v17.8h, v1.8h
  840. add v2.8h, v3.8h, v2.8h
  841. sub v23.8h, v16.8h, v6.8h
  842. add v1.8h, v1.8h, v2.8h
  843. add v16.8h, v16.8h, v6.8h
  844. add v22.8h, v5.8h, v3.8h
  845. sub v17.8h, v5.8h, v3.8h
  846. sub v21.8h, v18.8h, v2.8h
  847. add v18.8h, v18.8h, v2.8h
  848. sub v19.8h, v20.8h, v1.8h
  849. add v20.8h, v20.8h, v1.8h
  850. /* Descale to 8-bit and range limit */
  851. movi v0.16b, #0x80
  852. /* Prepare pointers (dual-issue with NEON instructions) */
  853. ldp TMP1, TMP2, [OUTPUT_BUF], 16
  854. sqshrn v28.8b, v16.8h, #5
  855. ldp TMP3, TMP4, [OUTPUT_BUF], 16
  856. sqshrn v29.8b, v17.8h, #5
  857. add TMP1, TMP1, OUTPUT_COL
  858. sqshrn v30.8b, v18.8h, #5
  859. add TMP2, TMP2, OUTPUT_COL
  860. sqshrn v31.8b, v19.8h, #5
  861. add TMP3, TMP3, OUTPUT_COL
  862. sqshrn2 v28.16b, v20.8h, #5
  863. add TMP4, TMP4, OUTPUT_COL
  864. sqshrn2 v29.16b, v21.8h, #5
  865. ldp TMP5, TMP6, [OUTPUT_BUF], 16
  866. sqshrn2 v30.16b, v22.8h, #5
  867. ldp TMP7, TMP8, [OUTPUT_BUF], 16
  868. sqshrn2 v31.16b, v23.8h, #5
  869. add TMP5, TMP5, OUTPUT_COL
  870. add v16.16b, v28.16b, v0.16b
  871. add TMP6, TMP6, OUTPUT_COL
  872. add v18.16b, v29.16b, v0.16b
  873. add TMP7, TMP7, OUTPUT_COL
  874. add v20.16b, v30.16b, v0.16b
  875. add TMP8, TMP8, OUTPUT_COL
  876. add v22.16b, v31.16b, v0.16b
  877. /* Transpose the final 8-bit samples */
  878. trn1 v28.16b, v16.16b, v18.16b
  879. trn1 v30.16b, v20.16b, v22.16b
  880. trn2 v29.16b, v16.16b, v18.16b
  881. trn2 v31.16b, v20.16b, v22.16b
  882. trn1 v16.8h, v28.8h, v30.8h
  883. trn2 v18.8h, v28.8h, v30.8h
  884. trn1 v20.8h, v29.8h, v31.8h
  885. trn2 v22.8h, v29.8h, v31.8h
  886. uzp1 v28.4s, v16.4s, v18.4s
  887. uzp2 v30.4s, v16.4s, v18.4s
  888. uzp1 v29.4s, v20.4s, v22.4s
  889. uzp2 v31.4s, v20.4s, v22.4s
  890. /* Store results to the output buffer */
  891. st1 {v28.d}[0], [TMP1]
  892. st1 {v29.d}[0], [TMP2]
  893. st1 {v28.d}[1], [TMP3]
  894. st1 {v29.d}[1], [TMP4]
  895. st1 {v30.d}[0], [TMP5]
  896. st1 {v31.d}[0], [TMP6]
  897. st1 {v30.d}[1], [TMP7]
  898. st1 {v31.d}[1], [TMP8]
  899. blr x30
  900. .unreq DCT_TABLE
  901. .unreq COEF_BLOCK
  902. .unreq OUTPUT_BUF
  903. .unreq OUTPUT_COL
  904. .unreq TMP1
  905. .unreq TMP2
  906. .unreq TMP3
  907. .unreq TMP4
  908. .unreq TMP5
  909. .unreq TMP6
  910. .unreq TMP7
  911. .unreq TMP8
  912. /*****************************************************************************/
  913. /*
  914. * jsimd_idct_4x4_neon
  915. *
  916. * This function contains inverse-DCT code for getting reduced-size
  917. * 4x4 pixels output from an 8x8 DCT block. It uses the same calculations
  918. * and produces exactly the same output as IJG's original 'jpeg_idct_4x4'
  919. * function from jpeg-6b (jidctred.c).
  920. *
  921. * NOTE: jpeg-8 has an improved implementation of 4x4 inverse-DCT, which
  922. * requires much less arithmetic operations and hence should be faster.
  923. * The primary purpose of this particular NEON optimized function is
  924. * bit exact compatibility with jpeg-6b.
  925. *
  926. * TODO: a bit better instructions scheduling can be achieved by expanding
  927. * idct_helper/transpose_4x4 macros and reordering instructions,
  928. * but readability will suffer somewhat.
  929. */
  930. #define CONST_BITS 13
  931. #define FIX_0_211164243 (1730) /* FIX(0.211164243) */
  932. #define FIX_0_509795579 (4176) /* FIX(0.509795579) */
  933. #define FIX_0_601344887 (4926) /* FIX(0.601344887) */
  934. #define FIX_0_720959822 (5906) /* FIX(0.720959822) */
  935. #define FIX_0_765366865 (6270) /* FIX(0.765366865) */
  936. #define FIX_0_850430095 (6967) /* FIX(0.850430095) */
  937. #define FIX_0_899976223 (7373) /* FIX(0.899976223) */
  938. #define FIX_1_061594337 (8697) /* FIX(1.061594337) */
  939. #define FIX_1_272758580 (10426) /* FIX(1.272758580) */
  940. #define FIX_1_451774981 (11893) /* FIX(1.451774981) */
  941. #define FIX_1_847759065 (15137) /* FIX(1.847759065) */
  942. #define FIX_2_172734803 (17799) /* FIX(2.172734803) */
  943. #define FIX_2_562915447 (20995) /* FIX(2.562915447) */
  944. #define FIX_3_624509785 (29692) /* FIX(3.624509785) */
  945. .balign 16
  946. Ljsimd_idct_4x4_neon_consts:
  947. .short FIX_1_847759065 /* v0.h[0] */
  948. .short -FIX_0_765366865 /* v0.h[1] */
  949. .short -FIX_0_211164243 /* v0.h[2] */
  950. .short FIX_1_451774981 /* v0.h[3] */
  951. .short -FIX_2_172734803 /* d1[0] */
  952. .short FIX_1_061594337 /* d1[1] */
  953. .short -FIX_0_509795579 /* d1[2] */
  954. .short -FIX_0_601344887 /* d1[3] */
  955. .short FIX_0_899976223 /* v2.h[0] */
  956. .short FIX_2_562915447 /* v2.h[1] */
  957. .short 1 << (CONST_BITS+1) /* v2.h[2] */
  958. .short 0 /* v2.h[3] */
  959. .macro idct_helper x4, x6, x8, x10, x12, x14, x16, shift, y26, y27, y28, y29
  960. smull v28.4s, \x4, v2.h[2]
  961. smlal v28.4s, \x8, v0.h[0]
  962. smlal v28.4s, \x14, v0.h[1]
  963. smull v26.4s, \x16, v1.h[2]
  964. smlal v26.4s, \x12, v1.h[3]
  965. smlal v26.4s, \x10, v2.h[0]
  966. smlal v26.4s, \x6, v2.h[1]
  967. smull v30.4s, \x4, v2.h[2]
  968. smlsl v30.4s, \x8, v0.h[0]
  969. smlsl v30.4s, \x14, v0.h[1]
  970. smull v24.4s, \x16, v0.h[2]
  971. smlal v24.4s, \x12, v0.h[3]
  972. smlal v24.4s, \x10, v1.h[0]
  973. smlal v24.4s, \x6, v1.h[1]
  974. add v20.4s, v28.4s, v26.4s
  975. sub v28.4s, v28.4s, v26.4s
  976. .if \shift > 16
  977. srshr v20.4s, v20.4s, #\shift
  978. srshr v28.4s, v28.4s, #\shift
  979. xtn \y26, v20.4s
  980. xtn \y29, v28.4s
  981. .else
  982. rshrn \y26, v20.4s, #\shift
  983. rshrn \y29, v28.4s, #\shift
  984. .endif
  985. add v20.4s, v30.4s, v24.4s
  986. sub v30.4s, v30.4s, v24.4s
  987. .if \shift > 16
  988. srshr v20.4s, v20.4s, #\shift
  989. srshr v30.4s, v30.4s, #\shift
  990. xtn \y27, v20.4s
  991. xtn \y28, v30.4s
  992. .else
  993. rshrn \y27, v20.4s, #\shift
  994. rshrn \y28, v30.4s, #\shift
  995. .endif
  996. .endm
  997. asm_function jsimd_idct_4x4_neon
  998. DCT_TABLE .req x0
  999. COEF_BLOCK .req x1
  1000. OUTPUT_BUF .req x2
  1001. OUTPUT_COL .req x3
  1002. TMP1 .req x0
  1003. TMP2 .req x1
  1004. TMP3 .req x2
  1005. TMP4 .req x15
  1006. /* OUTPUT_COL is a JDIMENSION (unsigned int) argument, so the ABI doesn't
  1007. guarantee that the upper (unused) 32 bits of x3 are valid. This
  1008. instruction ensures that those bits are set to zero. */
  1009. uxtw x3, w3
  1010. /* Save all used NEON registers */
  1011. sub sp, sp, 64
  1012. mov x9, sp
  1013. /* Load constants (v3.4h is just used for padding) */
  1014. adr TMP4, Ljsimd_idct_4x4_neon_consts
  1015. st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x9], 32
  1016. st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x9], 32
  1017. ld1 {v0.4h, v1.4h, v2.4h, v3.4h}, [TMP4]
  1018. /* Load all COEF_BLOCK into NEON registers with the following allocation:
  1019. * 0 1 2 3 | 4 5 6 7
  1020. * ---------+--------
  1021. * 0 | v4.4h | v5.4h
  1022. * 1 | v6.4h | v7.4h
  1023. * 2 | v8.4h | v9.4h
  1024. * 3 | v10.4h | v11.4h
  1025. * 4 | - | -
  1026. * 5 | v12.4h | v13.4h
  1027. * 6 | v14.4h | v15.4h
  1028. * 7 | v16.4h | v17.4h
  1029. */
  1030. ld1 {v4.4h, v5.4h, v6.4h, v7.4h}, [COEF_BLOCK], 32
  1031. ld1 {v8.4h, v9.4h, v10.4h, v11.4h}, [COEF_BLOCK], 32
  1032. add COEF_BLOCK, COEF_BLOCK, #16
  1033. ld1 {v12.4h, v13.4h, v14.4h, v15.4h}, [COEF_BLOCK], 32
  1034. ld1 {v16.4h, v17.4h}, [COEF_BLOCK], 16
  1035. /* dequantize */
  1036. ld1 {v18.4h, v19.4h, v20.4h, v21.4h}, [DCT_TABLE], 32
  1037. mul v4.4h, v4.4h, v18.4h
  1038. mul v5.4h, v5.4h, v19.4h
  1039. ins v4.d[1], v5.d[0] /* 128 bit q4 */
  1040. ld1 {v22.4h, v23.4h, v24.4h, v25.4h}, [DCT_TABLE], 32
  1041. mul v6.4h, v6.4h, v20.4h
  1042. mul v7.4h, v7.4h, v21.4h
  1043. ins v6.d[1], v7.d[0] /* 128 bit q6 */
  1044. mul v8.4h, v8.4h, v22.4h
  1045. mul v9.4h, v9.4h, v23.4h
  1046. ins v8.d[1], v9.d[0] /* 128 bit q8 */
  1047. add DCT_TABLE, DCT_TABLE, #16
  1048. ld1 {v26.4h, v27.4h, v28.4h, v29.4h}, [DCT_TABLE], 32
  1049. mul v10.4h, v10.4h, v24.4h
  1050. mul v11.4h, v11.4h, v25.4h
  1051. ins v10.d[1], v11.d[0] /* 128 bit q10 */
  1052. mul v12.4h, v12.4h, v26.4h
  1053. mul v13.4h, v13.4h, v27.4h
  1054. ins v12.d[1], v13.d[0] /* 128 bit q12 */
  1055. ld1 {v30.4h, v31.4h}, [DCT_TABLE], 16
  1056. mul v14.4h, v14.4h, v28.4h
  1057. mul v15.4h, v15.4h, v29.4h
  1058. ins v14.d[1], v15.d[0] /* 128 bit q14 */
  1059. mul v16.4h, v16.4h, v30.4h
  1060. mul v17.4h, v17.4h, v31.4h
  1061. ins v16.d[1], v17.d[0] /* 128 bit q16 */
  1062. /* Pass 1 */
  1063. idct_helper v4.4h, v6.4h, v8.4h, v10.4h, v12.4h, v14.4h, v16.4h, 12, \
  1064. v4.4h, v6.4h, v8.4h, v10.4h
  1065. transpose_4x4 v4, v6, v8, v10, v3
  1066. ins v10.d[1], v11.d[0]
  1067. idct_helper v5.4h, v7.4h, v9.4h, v11.4h, v13.4h, v15.4h, v17.4h, 12, \
  1068. v5.4h, v7.4h, v9.4h, v11.4h
  1069. transpose_4x4 v5, v7, v9, v11, v3
  1070. ins v10.d[1], v11.d[0]
  1071. /* Pass 2 */
  1072. idct_helper v4.4h, v6.4h, v8.4h, v10.4h, v7.4h, v9.4h, v11.4h, 19, \
  1073. v26.4h, v27.4h, v28.4h, v29.4h
  1074. transpose_4x4 v26, v27, v28, v29, v3
  1075. /* Range limit */
  1076. movi v30.8h, #0x80
  1077. ins v26.d[1], v27.d[0]
  1078. ins v28.d[1], v29.d[0]
  1079. add v26.8h, v26.8h, v30.8h
  1080. add v28.8h, v28.8h, v30.8h
  1081. sqxtun v26.8b, v26.8h
  1082. sqxtun v27.8b, v28.8h
  1083. /* Store results to the output buffer */
  1084. ldp TMP1, TMP2, [OUTPUT_BUF], 16
  1085. ldp TMP3, TMP4, [OUTPUT_BUF]
  1086. add TMP1, TMP1, OUTPUT_COL
  1087. add TMP2, TMP2, OUTPUT_COL
  1088. add TMP3, TMP3, OUTPUT_COL
  1089. add TMP4, TMP4, OUTPUT_COL
  1090. #if defined(__ARMEL__) && !RESPECT_STRICT_ALIGNMENT
  1091. /* We can use much less instructions on little endian systems if the
  1092. * OS kernel is not configured to trap unaligned memory accesses
  1093. */
  1094. st1 {v26.s}[0], [TMP1], 4
  1095. st1 {v27.s}[0], [TMP3], 4
  1096. st1 {v26.s}[1], [TMP2], 4
  1097. st1 {v27.s}[1], [TMP4], 4
  1098. #else
  1099. st1 {v26.b}[0], [TMP1], 1
  1100. st1 {v27.b}[0], [TMP3], 1
  1101. st1 {v26.b}[1], [TMP1], 1
  1102. st1 {v27.b}[1], [TMP3], 1
  1103. st1 {v26.b}[2], [TMP1], 1
  1104. st1 {v27.b}[2], [TMP3], 1
  1105. st1 {v26.b}[3], [TMP1], 1
  1106. st1 {v27.b}[3], [TMP3], 1
  1107. st1 {v26.b}[4], [TMP2], 1
  1108. st1 {v27.b}[4], [TMP4], 1
  1109. st1 {v26.b}[5], [TMP2], 1
  1110. st1 {v27.b}[5], [TMP4], 1
  1111. st1 {v26.b}[6], [TMP2], 1
  1112. st1 {v27.b}[6], [TMP4], 1
  1113. st1 {v26.b}[7], [TMP2], 1
  1114. st1 {v27.b}[7], [TMP4], 1
  1115. #endif
  1116. /* vpop {v8.4h - v15.4h} ;not available */
  1117. ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [sp], 32
  1118. ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [sp], 32
  1119. blr x30
  1120. .unreq DCT_TABLE
  1121. .unreq COEF_BLOCK
  1122. .unreq OUTPUT_BUF
  1123. .unreq OUTPUT_COL
  1124. .unreq TMP1
  1125. .unreq TMP2
  1126. .unreq TMP3
  1127. .unreq TMP4
  1128. .purgem idct_helper
  1129. /*****************************************************************************/
  1130. /*
  1131. * jsimd_idct_2x2_neon
  1132. *
  1133. * This function contains inverse-DCT code for getting reduced-size
  1134. * 2x2 pixels output from an 8x8 DCT block. It uses the same calculations
  1135. * and produces exactly the same output as IJG's original 'jpeg_idct_2x2'
  1136. * function from jpeg-6b (jidctred.c).
  1137. *
  1138. * NOTE: jpeg-8 has an improved implementation of 2x2 inverse-DCT, which
  1139. * requires much less arithmetic operations and hence should be faster.
  1140. * The primary purpose of this particular NEON optimized function is
  1141. * bit exact compatibility with jpeg-6b.
  1142. */
  1143. .balign 8
  1144. Ljsimd_idct_2x2_neon_consts:
  1145. .short -FIX_0_720959822 /* v14[0] */
  1146. .short FIX_0_850430095 /* v14[1] */
  1147. .short -FIX_1_272758580 /* v14[2] */
  1148. .short FIX_3_624509785 /* v14[3] */
  1149. .macro idct_helper x4, x6, x10, x12, x16, shift, y26, y27
  1150. sshll v15.4s, \x4, #15
  1151. smull v26.4s, \x6, v14.h[3]
  1152. smlal v26.4s, \x10, v14.h[2]
  1153. smlal v26.4s, \x12, v14.h[1]
  1154. smlal v26.4s, \x16, v14.h[0]
  1155. add v20.4s, v15.4s, v26.4s
  1156. sub v15.4s, v15.4s, v26.4s
  1157. .if \shift > 16
  1158. srshr v20.4s, v20.4s, #\shift
  1159. srshr v15.4s, v15.4s, #\shift
  1160. xtn \y26, v20.4s
  1161. xtn \y27, v15.4s
  1162. .else
  1163. rshrn \y26, v20.4s, #\shift
  1164. rshrn \y27, v15.4s, #\shift
  1165. .endif
  1166. .endm
  1167. asm_function jsimd_idct_2x2_neon
  1168. DCT_TABLE .req x0
  1169. COEF_BLOCK .req x1
  1170. OUTPUT_BUF .req x2
  1171. OUTPUT_COL .req x3
  1172. TMP1 .req x0
  1173. TMP2 .req x15
  1174. /* OUTPUT_COL is a JDIMENSION (unsigned int) argument, so the ABI doesn't
  1175. guarantee that the upper (unused) 32 bits of x3 are valid. This
  1176. instruction ensures that those bits are set to zero. */
  1177. uxtw x3, w3
  1178. /* vpush {v8.4h - v15.4h} ; not available */
  1179. sub sp, sp, 64
  1180. mov x9, sp
  1181. /* Load constants */
  1182. adr TMP2, Ljsimd_idct_2x2_neon_consts
  1183. st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x9], 32
  1184. st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x9], 32
  1185. ld1 {v14.4h}, [TMP2]
  1186. /* Load all COEF_BLOCK into NEON registers with the following allocation:
  1187. * 0 1 2 3 | 4 5 6 7
  1188. * ---------+--------
  1189. * 0 | v4.4h | v5.4h
  1190. * 1 | v6.4h | v7.4h
  1191. * 2 | - | -
  1192. * 3 | v10.4h | v11.4h
  1193. * 4 | - | -
  1194. * 5 | v12.4h | v13.4h
  1195. * 6 | - | -
  1196. * 7 | v16.4h | v17.4h
  1197. */
  1198. ld1 {v4.4h, v5.4h, v6.4h, v7.4h}, [COEF_BLOCK], 32
  1199. add COEF_BLOCK, COEF_BLOCK, #16
  1200. ld1 {v10.4h, v11.4h}, [COEF_BLOCK], 16
  1201. add COEF_BLOCK, COEF_BLOCK, #16
  1202. ld1 {v12.4h, v13.4h}, [COEF_BLOCK], 16
  1203. add COEF_BLOCK, COEF_BLOCK, #16
  1204. ld1 {v16.4h, v17.4h}, [COEF_BLOCK], 16
  1205. /* Dequantize */
  1206. ld1 {v18.4h, v19.4h, v20.4h, v21.4h}, [DCT_TABLE], 32
  1207. mul v4.4h, v4.4h, v18.4h
  1208. mul v5.4h, v5.4h, v19.4h
  1209. ins v4.d[1], v5.d[0]
  1210. mul v6.4h, v6.4h, v20.4h
  1211. mul v7.4h, v7.4h, v21.4h
  1212. ins v6.d[1], v7.d[0]
  1213. add DCT_TABLE, DCT_TABLE, #16
  1214. ld1 {v24.4h, v25.4h}, [DCT_TABLE], 16
  1215. mul v10.4h, v10.4h, v24.4h
  1216. mul v11.4h, v11.4h, v25.4h
  1217. ins v10.d[1], v11.d[0]
  1218. add DCT_TABLE, DCT_TABLE, #16
  1219. ld1 {v26.4h, v27.4h}, [DCT_TABLE], 16
  1220. mul v12.4h, v12.4h, v26.4h
  1221. mul v13.4h, v13.4h, v27.4h
  1222. ins v12.d[1], v13.d[0]
  1223. add DCT_TABLE, DCT_TABLE, #16
  1224. ld1 {v30.4h, v31.4h}, [DCT_TABLE], 16
  1225. mul v16.4h, v16.4h, v30.4h
  1226. mul v17.4h, v17.4h, v31.4h
  1227. ins v16.d[1], v17.d[0]
  1228. /* Pass 1 */
  1229. #if 0
  1230. idct_helper v4.4h, v6.4h, v10.4h, v12.4h, v16.4h, 13, v4.4h, v6.4h
  1231. transpose_4x4 v4.4h, v6.4h, v8.4h, v10.4h
  1232. idct_helper v5.4h, v7.4h, v11.4h, v13.4h, v17.4h, 13, v5.4h, v7.4h
  1233. transpose_4x4 v5.4h, v7.4h, v9.4h, v11.4h
  1234. #else
  1235. smull v26.4s, v6.4h, v14.h[3]
  1236. smlal v26.4s, v10.4h, v14.h[2]
  1237. smlal v26.4s, v12.4h, v14.h[1]
  1238. smlal v26.4s, v16.4h, v14.h[0]
  1239. smull v24.4s, v7.4h, v14.h[3]
  1240. smlal v24.4s, v11.4h, v14.h[2]
  1241. smlal v24.4s, v13.4h, v14.h[1]
  1242. smlal v24.4s, v17.4h, v14.h[0]
  1243. sshll v15.4s, v4.4h, #15
  1244. sshll v30.4s, v5.4h, #15
  1245. add v20.4s, v15.4s, v26.4s
  1246. sub v15.4s, v15.4s, v26.4s
  1247. rshrn v4.4h, v20.4s, #13
  1248. rshrn v6.4h, v15.4s, #13
  1249. add v20.4s, v30.4s, v24.4s
  1250. sub v15.4s, v30.4s, v24.4s
  1251. rshrn v5.4h, v20.4s, #13
  1252. rshrn v7.4h, v15.4s, #13
  1253. ins v4.d[1], v5.d[0]
  1254. ins v6.d[1], v7.d[0]
  1255. transpose v4, v6, v3, .16b, .8h
  1256. transpose v6, v10, v3, .16b, .4s
  1257. ins v11.d[0], v10.d[1]
  1258. ins v7.d[0], v6.d[1]
  1259. #endif
  1260. /* Pass 2 */
  1261. idct_helper v4.4h, v6.4h, v10.4h, v7.4h, v11.4h, 20, v26.4h, v27.4h
  1262. /* Range limit */
  1263. movi v30.8h, #0x80
  1264. ins v26.d[1], v27.d[0]
  1265. add v26.8h, v26.8h, v30.8h
  1266. sqxtun v30.8b, v26.8h
  1267. ins v26.d[0], v30.d[0]
  1268. sqxtun v27.8b, v26.8h
  1269. /* Store results to the output buffer */
  1270. ldp TMP1, TMP2, [OUTPUT_BUF]
  1271. add TMP1, TMP1, OUTPUT_COL
  1272. add TMP2, TMP2, OUTPUT_COL
  1273. st1 {v26.b}[0], [TMP1], 1
  1274. st1 {v27.b}[4], [TMP1], 1
  1275. st1 {v26.b}[1], [TMP2], 1
  1276. st1 {v27.b}[5], [TMP2], 1
  1277. ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [sp], 32
  1278. ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [sp], 32
  1279. blr x30
  1280. .unreq DCT_TABLE
  1281. .unreq COEF_BLOCK
  1282. .unreq OUTPUT_BUF
  1283. .unreq OUTPUT_COL
  1284. .unreq TMP1
  1285. .unreq TMP2
  1286. .purgem idct_helper
  1287. /*****************************************************************************/
  1288. /*
  1289. * jsimd_ycc_extrgb_convert_neon
  1290. * jsimd_ycc_extbgr_convert_neon
  1291. * jsimd_ycc_extrgbx_convert_neon
  1292. * jsimd_ycc_extbgrx_convert_neon
  1293. * jsimd_ycc_extxbgr_convert_neon
  1294. * jsimd_ycc_extxrgb_convert_neon
  1295. *
  1296. * Colorspace conversion YCbCr -> RGB
  1297. */
  1298. .macro do_load size
  1299. .if \size == 8
  1300. ld1 {v4.8b}, [U], 8
  1301. ld1 {v5.8b}, [V], 8
  1302. ld1 {v0.8b}, [Y], 8
  1303. prfm pldl1keep, [U, #64]
  1304. prfm pldl1keep, [V, #64]
  1305. prfm pldl1keep, [Y, #64]
  1306. .elseif \size == 4
  1307. ld1 {v4.b}[0], [U], 1
  1308. ld1 {v4.b}[1], [U], 1
  1309. ld1 {v4.b}[2], [U], 1
  1310. ld1 {v4.b}[3], [U], 1
  1311. ld1 {v5.b}[0], [V], 1
  1312. ld1 {v5.b}[1], [V], 1
  1313. ld1 {v5.b}[2], [V], 1
  1314. ld1 {v5.b}[3], [V], 1
  1315. ld1 {v0.b}[0], [Y], 1
  1316. ld1 {v0.b}[1], [Y], 1
  1317. ld1 {v0.b}[2], [Y], 1
  1318. ld1 {v0.b}[3], [Y], 1
  1319. .elseif \size == 2
  1320. ld1 {v4.b}[4], [U], 1
  1321. ld1 {v4.b}[5], [U], 1
  1322. ld1 {v5.b}[4], [V], 1
  1323. ld1 {v5.b}[5], [V], 1
  1324. ld1 {v0.b}[4], [Y], 1
  1325. ld1 {v0.b}[5], [Y], 1
  1326. .elseif \size == 1
  1327. ld1 {v4.b}[6], [U], 1
  1328. ld1 {v5.b}[6], [V], 1
  1329. ld1 {v0.b}[6], [Y], 1
  1330. .else
  1331. .error unsupported macroblock size
  1332. .endif
  1333. .endm
  1334. .macro do_store bpp, size, fast_st3
  1335. .if \bpp == 24
  1336. .if \size == 8
  1337. .if \fast_st3 == 1
  1338. st3 {v10.8b, v11.8b, v12.8b}, [RGB], 24
  1339. .else
  1340. st1 {v10.b}[0], [RGB], #1
  1341. st1 {v11.b}[0], [RGB], #1
  1342. st1 {v12.b}[0], [RGB], #1
  1343. st1 {v10.b}[1], [RGB], #1
  1344. st1 {v11.b}[1], [RGB], #1
  1345. st1 {v12.b}[1], [RGB], #1
  1346. st1 {v10.b}[2], [RGB], #1
  1347. st1 {v11.b}[2], [RGB], #1
  1348. st1 {v12.b}[2], [RGB], #1
  1349. st1 {v10.b}[3], [RGB], #1
  1350. st1 {v11.b}[3], [RGB], #1
  1351. st1 {v12.b}[3], [RGB], #1
  1352. st1 {v10.b}[4], [RGB], #1
  1353. st1 {v11.b}[4], [RGB], #1
  1354. st1 {v12.b}[4], [RGB], #1
  1355. st1 {v10.b}[5], [RGB], #1
  1356. st1 {v11.b}[5], [RGB], #1
  1357. st1 {v12.b}[5], [RGB], #1
  1358. st1 {v10.b}[6], [RGB], #1
  1359. st1 {v11.b}[6], [RGB], #1
  1360. st1 {v12.b}[6], [RGB], #1
  1361. st1 {v10.b}[7], [RGB], #1
  1362. st1 {v11.b}[7], [RGB], #1
  1363. st1 {v12.b}[7], [RGB], #1
  1364. .endif
  1365. .elseif \size == 4
  1366. st3 {v10.b, v11.b, v12.b}[0], [RGB], 3
  1367. st3 {v10.b, v11.b, v12.b}[1], [RGB], 3
  1368. st3 {v10.b, v11.b, v12.b}[2], [RGB], 3
  1369. st3 {v10.b, v11.b, v12.b}[3], [RGB], 3
  1370. .elseif \size == 2
  1371. st3 {v10.b, v11.b, v12.b}[4], [RGB], 3
  1372. st3 {v10.b, v11.b, v12.b}[5], [RGB], 3
  1373. .elseif \size == 1
  1374. st3 {v10.b, v11.b, v12.b}[6], [RGB], 3
  1375. .else
  1376. .error unsupported macroblock size
  1377. .endif
  1378. .elseif \bpp == 32
  1379. .if \size == 8
  1380. st4 {v10.8b, v11.8b, v12.8b, v13.8b}, [RGB], 32
  1381. .elseif \size == 4
  1382. st4 {v10.b, v11.b, v12.b, v13.b}[0], [RGB], 4
  1383. st4 {v10.b, v11.b, v12.b, v13.b}[1], [RGB], 4
  1384. st4 {v10.b, v11.b, v12.b, v13.b}[2], [RGB], 4
  1385. st4 {v10.b, v11.b, v12.b, v13.b}[3], [RGB], 4
  1386. .elseif \size == 2
  1387. st4 {v10.b, v11.b, v12.b, v13.b}[4], [RGB], 4
  1388. st4 {v10.b, v11.b, v12.b, v13.b}[5], [RGB], 4
  1389. .elseif \size == 1
  1390. st4 {v10.b, v11.b, v12.b, v13.b}[6], [RGB], 4
  1391. .else
  1392. .error unsupported macroblock size
  1393. .endif
  1394. .elseif \bpp==16
  1395. .if \size == 8
  1396. st1 {v25.8h}, [RGB], 16
  1397. .elseif \size == 4
  1398. st1 {v25.4h}, [RGB], 8
  1399. .elseif \size == 2
  1400. st1 {v25.h}[4], [RGB], 2
  1401. st1 {v25.h}[5], [RGB], 2
  1402. .elseif \size == 1
  1403. st1 {v25.h}[6], [RGB], 2
  1404. .else
  1405. .error unsupported macroblock size
  1406. .endif
  1407. .else
  1408. .error unsupported bpp
  1409. .endif
  1410. .endm
  1411. .macro generate_jsimd_ycc_rgb_convert_neon colorid, bpp, r_offs, rsize, \
  1412. g_offs, gsize, b_offs, bsize, \
  1413. defsize, fast_st3
  1414. /*
  1415. * 2-stage pipelined YCbCr->RGB conversion
  1416. */
  1417. .macro do_yuv_to_rgb_stage1
  1418. uaddw v6.8h, v2.8h, v4.8b /* q3 = u - 128 */
  1419. uaddw v8.8h, v2.8h, v5.8b /* q2 = v - 128 */
  1420. smull v20.4s, v6.4h, v1.h[1] /* multiply by -11277 */
  1421. smlal v20.4s, v8.4h, v1.h[2] /* multiply by -23401 */
  1422. smull2 v22.4s, v6.8h, v1.h[1] /* multiply by -11277 */
  1423. smlal2 v22.4s, v8.8h, v1.h[2] /* multiply by -23401 */
  1424. smull v24.4s, v8.4h, v1.h[0] /* multiply by 22971 */
  1425. smull2 v26.4s, v8.8h, v1.h[0] /* multiply by 22971 */
  1426. smull v28.4s, v6.4h, v1.h[3] /* multiply by 29033 */
  1427. smull2 v30.4s, v6.8h, v1.h[3] /* multiply by 29033 */
  1428. .endm
  1429. .macro do_yuv_to_rgb_stage2
  1430. rshrn v20.4h, v20.4s, #15
  1431. rshrn2 v20.8h, v22.4s, #15
  1432. rshrn v24.4h, v24.4s, #14
  1433. rshrn2 v24.8h, v26.4s, #14
  1434. rshrn v28.4h, v28.4s, #14
  1435. rshrn2 v28.8h, v30.4s, #14
  1436. uaddw v20.8h, v20.8h, v0.8b
  1437. uaddw v24.8h, v24.8h, v0.8b
  1438. uaddw v28.8h, v28.8h, v0.8b
  1439. .if \bpp != 16
  1440. sqxtun v1\g_offs\defsize, v20.8h
  1441. sqxtun v1\r_offs\defsize, v24.8h
  1442. sqxtun v1\b_offs\defsize, v28.8h
  1443. .else
  1444. sqshlu v21.8h, v20.8h, #8
  1445. sqshlu v25.8h, v24.8h, #8
  1446. sqshlu v29.8h, v28.8h, #8
  1447. sri v25.8h, v21.8h, #5
  1448. sri v25.8h, v29.8h, #11
  1449. .endif
  1450. .endm
  1451. .macro do_yuv_to_rgb_stage2_store_load_stage1 fast_st3
  1452. rshrn v20.4h, v20.4s, #15
  1453. rshrn v24.4h, v24.4s, #14
  1454. rshrn v28.4h, v28.4s, #14
  1455. ld1 {v4.8b}, [U], 8
  1456. rshrn2 v20.8h, v22.4s, #15
  1457. rshrn2 v24.8h, v26.4s, #14
  1458. rshrn2 v28.8h, v30.4s, #14
  1459. ld1 {v5.8b}, [V], 8
  1460. uaddw v20.8h, v20.8h, v0.8b
  1461. uaddw v24.8h, v24.8h, v0.8b
  1462. uaddw v28.8h, v28.8h, v0.8b
  1463. .if \bpp != 16 /**************** rgb24/rgb32 ******************************/
  1464. sqxtun v1\g_offs\defsize, v20.8h
  1465. ld1 {v0.8b}, [Y], 8
  1466. sqxtun v1\r_offs\defsize, v24.8h
  1467. prfm pldl1keep, [U, #64]
  1468. prfm pldl1keep, [V, #64]
  1469. prfm pldl1keep, [Y, #64]
  1470. sqxtun v1\b_offs\defsize, v28.8h
  1471. uaddw v6.8h, v2.8h, v4.8b /* v6.16b = u - 128 */
  1472. uaddw v8.8h, v2.8h, v5.8b /* q2 = v - 128 */
  1473. smull v20.4s, v6.4h, v1.h[1] /* multiply by -11277 */
  1474. smlal v20.4s, v8.4h, v1.h[2] /* multiply by -23401 */
  1475. smull2 v22.4s, v6.8h, v1.h[1] /* multiply by -11277 */
  1476. smlal2 v22.4s, v8.8h, v1.h[2] /* multiply by -23401 */
  1477. smull v24.4s, v8.4h, v1.h[0] /* multiply by 22971 */
  1478. smull2 v26.4s, v8.8h, v1.h[0] /* multiply by 22971 */
  1479. .else /**************************** rgb565 ********************************/
  1480. sqshlu v21.8h, v20.8h, #8
  1481. sqshlu v25.8h, v24.8h, #8
  1482. sqshlu v29.8h, v28.8h, #8
  1483. uaddw v6.8h, v2.8h, v4.8b /* v6.16b = u - 128 */
  1484. uaddw v8.8h, v2.8h, v5.8b /* q2 = v - 128 */
  1485. ld1 {v0.8b}, [Y], 8
  1486. smull v20.4s, v6.4h, v1.h[1] /* multiply by -11277 */
  1487. smlal v20.4s, v8.4h, v1.h[2] /* multiply by -23401 */
  1488. smull2 v22.4s, v6.8h, v1.h[1] /* multiply by -11277 */
  1489. smlal2 v22.4s, v8.8h, v1.h[2] /* multiply by -23401 */
  1490. sri v25.8h, v21.8h, #5
  1491. smull v24.4s, v8.4h, v1.h[0] /* multiply by 22971 */
  1492. smull2 v26.4s, v8.8h, v1.h[0] /* multiply by 22971 */
  1493. prfm pldl1keep, [U, #64]
  1494. prfm pldl1keep, [V, #64]
  1495. prfm pldl1keep, [Y, #64]
  1496. sri v25.8h, v29.8h, #11
  1497. .endif
  1498. do_store \bpp, 8, \fast_st3
  1499. smull v28.4s, v6.4h, v1.h[3] /* multiply by 29033 */
  1500. smull2 v30.4s, v6.8h, v1.h[3] /* multiply by 29033 */
  1501. .endm
  1502. .macro do_yuv_to_rgb
  1503. do_yuv_to_rgb_stage1
  1504. do_yuv_to_rgb_stage2
  1505. .endm
  1506. /* Apple gas crashes on adrl, work around that by using adr.
  1507. * But this requires a copy of these constants for each function.
  1508. */
  1509. .balign 16
  1510. .if \fast_st3 == 1
  1511. Ljsimd_ycc_\colorid\()_neon_consts:
  1512. .else
  1513. Ljsimd_ycc_\colorid\()_neon_slowst3_consts:
  1514. .endif
  1515. .short 0, 0, 0, 0
  1516. .short 22971, -11277, -23401, 29033
  1517. .short -128, -128, -128, -128
  1518. .short -128, -128, -128, -128
  1519. .if \fast_st3 == 1
  1520. asm_function jsimd_ycc_\colorid\()_convert_neon
  1521. .else
  1522. asm_function jsimd_ycc_\colorid\()_convert_neon_slowst3
  1523. .endif
  1524. OUTPUT_WIDTH .req w0
  1525. INPUT_BUF .req x1
  1526. INPUT_ROW .req w2
  1527. OUTPUT_BUF .req x3
  1528. NUM_ROWS .req w4
  1529. INPUT_BUF0 .req x5
  1530. INPUT_BUF1 .req x6
  1531. INPUT_BUF2 .req x1
  1532. RGB .req x7
  1533. Y .req x9
  1534. U .req x10
  1535. V .req x11
  1536. N .req w15
  1537. sub sp, sp, 64
  1538. mov x9, sp
  1539. /* Load constants to d1, d2, d3 (v0.4h is just used for padding) */
  1540. .if \fast_st3 == 1
  1541. adr x15, Ljsimd_ycc_\colorid\()_neon_consts
  1542. .else
  1543. adr x15, Ljsimd_ycc_\colorid\()_neon_slowst3_consts
  1544. .endif
  1545. /* Save NEON registers */
  1546. st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x9], 32
  1547. st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x9], 32
  1548. ld1 {v0.4h, v1.4h}, [x15], 16
  1549. ld1 {v2.8h}, [x15]
  1550. ldr INPUT_BUF0, [INPUT_BUF]
  1551. ldr INPUT_BUF1, [INPUT_BUF, #8]
  1552. ldr INPUT_BUF2, [INPUT_BUF, #16]
  1553. .unreq INPUT_BUF
  1554. /* Initially set v10, v11.4h, v12.8b, d13 to 0xFF */
  1555. movi v10.16b, #255
  1556. movi v13.16b, #255
  1557. /* Outer loop over scanlines */
  1558. cmp NUM_ROWS, #1
  1559. b.lt 9f
  1560. 0:
  1561. ldr Y, [INPUT_BUF0, INPUT_ROW, uxtw #3]
  1562. ldr U, [INPUT_BUF1, INPUT_ROW, uxtw #3]
  1563. mov N, OUTPUT_WIDTH
  1564. ldr V, [INPUT_BUF2, INPUT_ROW, uxtw #3]
  1565. add INPUT_ROW, INPUT_ROW, #1
  1566. ldr RGB, [OUTPUT_BUF], #8
  1567. /* Inner loop over pixels */
  1568. subs N, N, #8
  1569. b.lt 3f
  1570. do_load 8
  1571. do_yuv_to_rgb_stage1
  1572. subs N, N, #8
  1573. b.lt 2f
  1574. 1:
  1575. do_yuv_to_rgb_stage2_store_load_stage1 \fast_st3
  1576. subs N, N, #8
  1577. b.ge 1b
  1578. 2:
  1579. do_yuv_to_rgb_stage2
  1580. do_store \bpp, 8, \fast_st3
  1581. tst N, #7
  1582. b.eq 8f
  1583. 3:
  1584. tst N, #4
  1585. b.eq 3f
  1586. do_load 4
  1587. 3:
  1588. tst N, #2
  1589. b.eq 4f
  1590. do_load 2
  1591. 4:
  1592. tst N, #1
  1593. b.eq 5f
  1594. do_load 1
  1595. 5:
  1596. do_yuv_to_rgb
  1597. tst N, #4
  1598. b.eq 6f
  1599. do_store \bpp, 4, \fast_st3
  1600. 6:
  1601. tst N, #2
  1602. b.eq 7f
  1603. do_store \bpp, 2, \fast_st3
  1604. 7:
  1605. tst N, #1
  1606. b.eq 8f
  1607. do_store \bpp, 1, \fast_st3
  1608. 8:
  1609. subs NUM_ROWS, NUM_ROWS, #1
  1610. b.gt 0b
  1611. 9:
  1612. /* Restore all registers and return */
  1613. ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [sp], 32
  1614. ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [sp], 32
  1615. br x30
  1616. .unreq OUTPUT_WIDTH
  1617. .unreq INPUT_ROW
  1618. .unreq OUTPUT_BUF
  1619. .unreq NUM_ROWS
  1620. .unreq INPUT_BUF0
  1621. .unreq INPUT_BUF1
  1622. .unreq INPUT_BUF2
  1623. .unreq RGB
  1624. .unreq Y
  1625. .unreq U
  1626. .unreq V
  1627. .unreq N
  1628. .purgem do_yuv_to_rgb
  1629. .purgem do_yuv_to_rgb_stage1
  1630. .purgem do_yuv_to_rgb_stage2
  1631. .purgem do_yuv_to_rgb_stage2_store_load_stage1
  1632. .endm
  1633. /*--------------------------------- id ----- bpp R rsize G gsize B bsize defsize fast_st3*/
  1634. generate_jsimd_ycc_rgb_convert_neon extrgb, 24, 0, .4h, 1, .4h, 2, .4h, .8b, 1
  1635. generate_jsimd_ycc_rgb_convert_neon extbgr, 24, 2, .4h, 1, .4h, 0, .4h, .8b, 1
  1636. generate_jsimd_ycc_rgb_convert_neon extrgbx, 32, 0, .4h, 1, .4h, 2, .4h, .8b, 1
  1637. generate_jsimd_ycc_rgb_convert_neon extbgrx, 32, 2, .4h, 1, .4h, 0, .4h, .8b, 1
  1638. generate_jsimd_ycc_rgb_convert_neon extxbgr, 32, 3, .4h, 2, .4h, 1, .4h, .8b, 1
  1639. generate_jsimd_ycc_rgb_convert_neon extxrgb, 32, 1, .4h, 2, .4h, 3, .4h, .8b, 1
  1640. generate_jsimd_ycc_rgb_convert_neon rgb565, 16, 0, .4h, 0, .4h, 0, .4h, .8b, 1
  1641. generate_jsimd_ycc_rgb_convert_neon extrgb, 24, 0, .4h, 1, .4h, 2, .4h, .8b, 0
  1642. generate_jsimd_ycc_rgb_convert_neon extbgr, 24, 2, .4h, 1, .4h, 0, .4h, .8b, 0
  1643. .purgem do_load
  1644. .purgem do_store
  1645. /*****************************************************************************/
  1646. /*
  1647. * jsimd_extrgb_ycc_convert_neon
  1648. * jsimd_extbgr_ycc_convert_neon
  1649. * jsimd_extrgbx_ycc_convert_neon
  1650. * jsimd_extbgrx_ycc_convert_neon
  1651. * jsimd_extxbgr_ycc_convert_neon
  1652. * jsimd_extxrgb_ycc_convert_neon
  1653. *
  1654. * Colorspace conversion RGB -> YCbCr
  1655. */
  1656. .macro do_store size
  1657. .if \size == 8
  1658. st1 {v20.8b}, [Y], #8
  1659. st1 {v21.8b}, [U], #8
  1660. st1 {v22.8b}, [V], #8
  1661. .elseif \size == 4
  1662. st1 {v20.b}[0], [Y], #1
  1663. st1 {v20.b}[1], [Y], #1
  1664. st1 {v20.b}[2], [Y], #1
  1665. st1 {v20.b}[3], [Y], #1
  1666. st1 {v21.b}[0], [U], #1
  1667. st1 {v21.b}[1], [U], #1
  1668. st1 {v21.b}[2], [U], #1
  1669. st1 {v21.b}[3], [U], #1
  1670. st1 {v22.b}[0], [V], #1
  1671. st1 {v22.b}[1], [V], #1
  1672. st1 {v22.b}[2], [V], #1
  1673. st1 {v22.b}[3], [V], #1
  1674. .elseif \size == 2
  1675. st1 {v20.b}[4], [Y], #1
  1676. st1 {v20.b}[5], [Y], #1
  1677. st1 {v21.b}[4], [U], #1
  1678. st1 {v21.b}[5], [U], #1
  1679. st1 {v22.b}[4], [V], #1
  1680. st1 {v22.b}[5], [V], #1
  1681. .elseif \size == 1
  1682. st1 {v20.b}[6], [Y], #1
  1683. st1 {v21.b}[6], [U], #1
  1684. st1 {v22.b}[6], [V], #1
  1685. .else
  1686. .error unsupported macroblock size
  1687. .endif
  1688. .endm
  1689. .macro do_load bpp, size, fast_ld3
  1690. .if \bpp == 24
  1691. .if \size == 8
  1692. .if \fast_ld3 == 1
  1693. ld3 {v10.8b, v11.8b, v12.8b}, [RGB], #24
  1694. .else
  1695. ld1 {v10.b}[0], [RGB], #1
  1696. ld1 {v11.b}[0], [RGB], #1
  1697. ld1 {v12.b}[0], [RGB], #1
  1698. ld1 {v10.b}[1], [RGB], #1
  1699. ld1 {v11.b}[1], [RGB], #1
  1700. ld1 {v12.b}[1], [RGB], #1
  1701. ld1 {v10.b}[2], [RGB], #1
  1702. ld1 {v11.b}[2], [RGB], #1
  1703. ld1 {v12.b}[2], [RGB], #1
  1704. ld1 {v10.b}[3], [RGB], #1
  1705. ld1 {v11.b}[3], [RGB], #1
  1706. ld1 {v12.b}[3], [RGB], #1
  1707. ld1 {v10.b}[4], [RGB], #1
  1708. ld1 {v11.b}[4], [RGB], #1
  1709. ld1 {v12.b}[4], [RGB], #1
  1710. ld1 {v10.b}[5], [RGB], #1
  1711. ld1 {v11.b}[5], [RGB], #1
  1712. ld1 {v12.b}[5], [RGB], #1
  1713. ld1 {v10.b}[6], [RGB], #1
  1714. ld1 {v11.b}[6], [RGB], #1
  1715. ld1 {v12.b}[6], [RGB], #1
  1716. ld1 {v10.b}[7], [RGB], #1
  1717. ld1 {v11.b}[7], [RGB], #1
  1718. ld1 {v12.b}[7], [RGB], #1
  1719. .endif
  1720. prfm pldl1keep, [RGB, #128]
  1721. .elseif \size == 4
  1722. ld3 {v10.b, v11.b, v12.b}[0], [RGB], #3
  1723. ld3 {v10.b, v11.b, v12.b}[1], [RGB], #3
  1724. ld3 {v10.b, v11.b, v12.b}[2], [RGB], #3
  1725. ld3 {v10.b, v11.b, v12.b}[3], [RGB], #3
  1726. .elseif \size == 2
  1727. ld3 {v10.b, v11.b, v12.b}[4], [RGB], #3
  1728. ld3 {v10.b, v11.b, v12.b}[5], [RGB], #3
  1729. .elseif \size == 1
  1730. ld3 {v10.b, v11.b, v12.b}[6], [RGB], #3
  1731. .else
  1732. .error unsupported macroblock size
  1733. .endif
  1734. .elseif \bpp == 32
  1735. .if \size == 8
  1736. ld4 {v10.8b, v11.8b, v12.8b, v13.8b}, [RGB], #32
  1737. prfm pldl1keep, [RGB, #128]
  1738. .elseif \size == 4
  1739. ld4 {v10.b, v11.b, v12.b, v13.b}[0], [RGB], #4
  1740. ld4 {v10.b, v11.b, v12.b, v13.b}[1], [RGB], #4
  1741. ld4 {v10.b, v11.b, v12.b, v13.b}[2], [RGB], #4
  1742. ld4 {v10.b, v11.b, v12.b, v13.b}[3], [RGB], #4
  1743. .elseif \size == 2
  1744. ld4 {v10.b, v11.b, v12.b, v13.b}[4], [RGB], #4
  1745. ld4 {v10.b, v11.b, v12.b, v13.b}[5], [RGB], #4
  1746. .elseif \size == 1
  1747. ld4 {v10.b, v11.b, v12.b, v13.b}[6], [RGB], #4
  1748. .else
  1749. .error unsupported macroblock size
  1750. .endif
  1751. .else
  1752. .error unsupported bpp
  1753. .endif
  1754. .endm
  1755. .macro generate_jsimd_rgb_ycc_convert_neon colorid, bpp, r_offs, g_offs, \
  1756. b_offs, fast_ld3
  1757. /*
  1758. * 2-stage pipelined RGB->YCbCr conversion
  1759. */
  1760. .macro do_rgb_to_yuv_stage1
  1761. ushll v4.8h, v1\r_offs\().8b, #0 /* r = v4 */
  1762. ushll v6.8h, v1\g_offs\().8b, #0 /* g = v6 */
  1763. ushll v8.8h, v1\b_offs\().8b, #0 /* b = v8 */
  1764. rev64 v18.4s, v1.4s
  1765. rev64 v26.4s, v1.4s
  1766. rev64 v28.4s, v1.4s
  1767. rev64 v30.4s, v1.4s
  1768. umull v14.4s, v4.4h, v0.h[0]
  1769. umull2 v16.4s, v4.8h, v0.h[0]
  1770. umlsl v18.4s, v4.4h, v0.h[3]
  1771. umlsl2 v26.4s, v4.8h, v0.h[3]
  1772. umlal v28.4s, v4.4h, v0.h[5]
  1773. umlal2 v30.4s, v4.8h, v0.h[5]
  1774. umlal v14.4s, v6.4h, v0.h[1]
  1775. umlal2 v16.4s, v6.8h, v0.h[1]
  1776. umlsl v18.4s, v6.4h, v0.h[4]
  1777. umlsl2 v26.4s, v6.8h, v0.h[4]
  1778. umlsl v28.4s, v6.4h, v0.h[6]
  1779. umlsl2 v30.4s, v6.8h, v0.h[6]
  1780. umlal v14.4s, v8.4h, v0.h[2]
  1781. umlal2 v16.4s, v8.8h, v0.h[2]
  1782. umlal v18.4s, v8.4h, v0.h[5]
  1783. umlal2 v26.4s, v8.8h, v0.h[5]
  1784. umlsl v28.4s, v8.4h, v0.h[7]
  1785. umlsl2 v30.4s, v8.8h, v0.h[7]
  1786. .endm
  1787. .macro do_rgb_to_yuv_stage2
  1788. rshrn v20.4h, v14.4s, #16
  1789. shrn v22.4h, v18.4s, #16
  1790. shrn v24.4h, v28.4s, #16
  1791. rshrn2 v20.8h, v16.4s, #16
  1792. shrn2 v22.8h, v26.4s, #16
  1793. shrn2 v24.8h, v30.4s, #16
  1794. xtn v20.8b, v20.8h /* v20 = y */
  1795. xtn v21.8b, v22.8h /* v21 = u */
  1796. xtn v22.8b, v24.8h /* v22 = v */
  1797. .endm
  1798. .macro do_rgb_to_yuv
  1799. do_rgb_to_yuv_stage1
  1800. do_rgb_to_yuv_stage2
  1801. .endm
  1802. /* TODO: expand macros and interleave instructions if some in-order
  1803. * ARM64 processor actually can dual-issue LOAD/STORE with ALU */
  1804. .macro do_rgb_to_yuv_stage2_store_load_stage1 fast_ld3
  1805. do_rgb_to_yuv_stage2
  1806. do_load \bpp, 8, \fast_ld3
  1807. st1 {v20.8b}, [Y], #8
  1808. st1 {v21.8b}, [U], #8
  1809. st1 {v22.8b}, [V], #8
  1810. do_rgb_to_yuv_stage1
  1811. .endm
  1812. .balign 16
  1813. .if \fast_ld3 == 1
  1814. Ljsimd_\colorid\()_ycc_neon_consts:
  1815. .else
  1816. Ljsimd_\colorid\()_ycc_neon_slowld3_consts:
  1817. .endif
  1818. .short 19595, 38470, 7471, 11059
  1819. .short 21709, 32768, 27439, 5329
  1820. .short 32767, 128, 32767, 128
  1821. .short 32767, 128, 32767, 128
  1822. .if \fast_ld3 == 1
  1823. asm_function jsimd_\colorid\()_ycc_convert_neon
  1824. .else
  1825. asm_function jsimd_\colorid\()_ycc_convert_neon_slowld3
  1826. .endif
  1827. OUTPUT_WIDTH .req w0
  1828. INPUT_BUF .req x1
  1829. OUTPUT_BUF .req x2
  1830. OUTPUT_ROW .req w3
  1831. NUM_ROWS .req w4
  1832. OUTPUT_BUF0 .req x5
  1833. OUTPUT_BUF1 .req x6
  1834. OUTPUT_BUF2 .req x2 /* OUTPUT_BUF */
  1835. RGB .req x7
  1836. Y .req x9
  1837. U .req x10
  1838. V .req x11
  1839. N .req w12
  1840. /* Load constants to d0, d1, d2, d3 */
  1841. .if \fast_ld3 == 1
  1842. adr x13, Ljsimd_\colorid\()_ycc_neon_consts
  1843. .else
  1844. adr x13, Ljsimd_\colorid\()_ycc_neon_slowld3_consts
  1845. .endif
  1846. ld1 {v0.8h, v1.8h}, [x13]
  1847. ldr OUTPUT_BUF0, [OUTPUT_BUF]
  1848. ldr OUTPUT_BUF1, [OUTPUT_BUF, #8]
  1849. ldr OUTPUT_BUF2, [OUTPUT_BUF, #16]
  1850. .unreq OUTPUT_BUF
  1851. /* Save NEON registers */
  1852. sub sp, sp, #64
  1853. mov x9, sp
  1854. st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x9], 32
  1855. st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x9], 32
  1856. /* Outer loop over scanlines */
  1857. cmp NUM_ROWS, #1
  1858. b.lt 9f
  1859. 0:
  1860. ldr Y, [OUTPUT_BUF0, OUTPUT_ROW, uxtw #3]
  1861. ldr U, [OUTPUT_BUF1, OUTPUT_ROW, uxtw #3]
  1862. mov N, OUTPUT_WIDTH
  1863. ldr V, [OUTPUT_BUF2, OUTPUT_ROW, uxtw #3]
  1864. add OUTPUT_ROW, OUTPUT_ROW, #1
  1865. ldr RGB, [INPUT_BUF], #8
  1866. /* Inner loop over pixels */
  1867. subs N, N, #8
  1868. b.lt 3f
  1869. do_load \bpp, 8, \fast_ld3
  1870. do_rgb_to_yuv_stage1
  1871. subs N, N, #8
  1872. b.lt 2f
  1873. 1:
  1874. do_rgb_to_yuv_stage2_store_load_stage1 \fast_ld3
  1875. subs N, N, #8
  1876. b.ge 1b
  1877. 2:
  1878. do_rgb_to_yuv_stage2
  1879. do_store 8
  1880. tst N, #7
  1881. b.eq 8f
  1882. 3:
  1883. tbz N, #2, 3f
  1884. do_load \bpp, 4, \fast_ld3
  1885. 3:
  1886. tbz N, #1, 4f
  1887. do_load \bpp, 2, \fast_ld3
  1888. 4:
  1889. tbz N, #0, 5f
  1890. do_load \bpp, 1, \fast_ld3
  1891. 5:
  1892. do_rgb_to_yuv
  1893. tbz N, #2, 6f
  1894. do_store 4
  1895. 6:
  1896. tbz N, #1, 7f
  1897. do_store 2
  1898. 7:
  1899. tbz N, #0, 8f
  1900. do_store 1
  1901. 8:
  1902. subs NUM_ROWS, NUM_ROWS, #1
  1903. b.gt 0b
  1904. 9:
  1905. /* Restore all registers and return */
  1906. ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [sp], 32
  1907. ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [sp], 32
  1908. br x30
  1909. .unreq OUTPUT_WIDTH
  1910. .unreq OUTPUT_ROW
  1911. .unreq INPUT_BUF
  1912. .unreq NUM_ROWS
  1913. .unreq OUTPUT_BUF0
  1914. .unreq OUTPUT_BUF1
  1915. .unreq OUTPUT_BUF2
  1916. .unreq RGB
  1917. .unreq Y
  1918. .unreq U
  1919. .unreq V
  1920. .unreq N
  1921. .purgem do_rgb_to_yuv
  1922. .purgem do_rgb_to_yuv_stage1
  1923. .purgem do_rgb_to_yuv_stage2
  1924. .purgem do_rgb_to_yuv_stage2_store_load_stage1
  1925. .endm
  1926. /*--------------------------------- id ----- bpp R G B Fast LD3 */
  1927. generate_jsimd_rgb_ycc_convert_neon extrgb, 24, 0, 1, 2, 1
  1928. generate_jsimd_rgb_ycc_convert_neon extbgr, 24, 2, 1, 0, 1
  1929. generate_jsimd_rgb_ycc_convert_neon extrgbx, 32, 0, 1, 2, 1
  1930. generate_jsimd_rgb_ycc_convert_neon extbgrx, 32, 2, 1, 0, 1
  1931. generate_jsimd_rgb_ycc_convert_neon extxbgr, 32, 3, 2, 1, 1
  1932. generate_jsimd_rgb_ycc_convert_neon extxrgb, 32, 1, 2, 3, 1
  1933. generate_jsimd_rgb_ycc_convert_neon extrgb, 24, 0, 1, 2, 0
  1934. generate_jsimd_rgb_ycc_convert_neon extbgr, 24, 2, 1, 0, 0
  1935. .purgem do_load
  1936. .purgem do_store
  1937. /*****************************************************************************/
  1938. /*
  1939. * Load data into workspace, applying unsigned->signed conversion
  1940. *
  1941. * TODO: can be combined with 'jsimd_fdct_ifast_neon' to get
  1942. * rid of VST1.16 instructions
  1943. */
  1944. asm_function jsimd_convsamp_neon
  1945. SAMPLE_DATA .req x0
  1946. START_COL .req x1
  1947. WORKSPACE .req x2
  1948. TMP1 .req x9
  1949. TMP2 .req x10
  1950. TMP3 .req x11
  1951. TMP4 .req x12
  1952. TMP5 .req x13
  1953. TMP6 .req x14
  1954. TMP7 .req x15
  1955. TMP8 .req x4
  1956. TMPDUP .req w3
  1957. /* START_COL is a JDIMENSION (unsigned int) argument, so the ABI doesn't
  1958. guarantee that the upper (unused) 32 bits of x1 are valid. This
  1959. instruction ensures that those bits are set to zero. */
  1960. uxtw x1, w1
  1961. mov TMPDUP, #128
  1962. ldp TMP1, TMP2, [SAMPLE_DATA], 16
  1963. ldp TMP3, TMP4, [SAMPLE_DATA], 16
  1964. dup v0.8b, TMPDUP
  1965. add TMP1, TMP1, START_COL
  1966. add TMP2, TMP2, START_COL
  1967. ldp TMP5, TMP6, [SAMPLE_DATA], 16
  1968. add TMP3, TMP3, START_COL
  1969. add TMP4, TMP4, START_COL
  1970. ldp TMP7, TMP8, [SAMPLE_DATA], 16
  1971. add TMP5, TMP5, START_COL
  1972. add TMP6, TMP6, START_COL
  1973. ld1 {v16.8b}, [TMP1]
  1974. add TMP7, TMP7, START_COL
  1975. add TMP8, TMP8, START_COL
  1976. ld1 {v17.8b}, [TMP2]
  1977. usubl v16.8h, v16.8b, v0.8b
  1978. ld1 {v18.8b}, [TMP3]
  1979. usubl v17.8h, v17.8b, v0.8b
  1980. ld1 {v19.8b}, [TMP4]
  1981. usubl v18.8h, v18.8b, v0.8b
  1982. ld1 {v20.8b}, [TMP5]
  1983. usubl v19.8h, v19.8b, v0.8b
  1984. ld1 {v21.8b}, [TMP6]
  1985. st1 {v16.8h, v17.8h, v18.8h, v19.8h}, [WORKSPACE], 64
  1986. usubl v20.8h, v20.8b, v0.8b
  1987. ld1 {v22.8b}, [TMP7]
  1988. usubl v21.8h, v21.8b, v0.8b
  1989. ld1 {v23.8b}, [TMP8]
  1990. usubl v22.8h, v22.8b, v0.8b
  1991. usubl v23.8h, v23.8b, v0.8b
  1992. st1 {v20.8h, v21.8h, v22.8h, v23.8h}, [WORKSPACE], 64
  1993. br x30
  1994. .unreq SAMPLE_DATA
  1995. .unreq START_COL
  1996. .unreq WORKSPACE
  1997. .unreq TMP1
  1998. .unreq TMP2
  1999. .unreq TMP3
  2000. .unreq TMP4
  2001. .unreq TMP5
  2002. .unreq TMP6
  2003. .unreq TMP7
  2004. .unreq TMP8
  2005. .unreq TMPDUP
  2006. /*****************************************************************************/
  2007. /*
  2008. * jsimd_fdct_islow_neon
  2009. *
  2010. * This file contains a slow-but-accurate integer implementation of the
  2011. * forward DCT (Discrete Cosine Transform). The following code is based
  2012. * directly on the IJG''s original jfdctint.c; see the jfdctint.c for
  2013. * more details.
  2014. *
  2015. * TODO: can be combined with 'jsimd_convsamp_neon' to get
  2016. * rid of a bunch of VLD1.16 instructions
  2017. */
  2018. #define CONST_BITS 13
  2019. #define PASS1_BITS 2
  2020. #define DESCALE_P1 (CONST_BITS-PASS1_BITS)
  2021. #define DESCALE_P2 (CONST_BITS+PASS1_BITS)
  2022. #define F_0_298 2446 /* FIX(0.298631336) */
  2023. #define F_0_390 3196 /* FIX(0.390180644) */
  2024. #define F_0_541 4433 /* FIX(0.541196100) */
  2025. #define F_0_765 6270 /* FIX(0.765366865) */
  2026. #define F_0_899 7373 /* FIX(0.899976223) */
  2027. #define F_1_175 9633 /* FIX(1.175875602) */
  2028. #define F_1_501 12299 /* FIX(1.501321110) */
  2029. #define F_1_847 15137 /* FIX(1.847759065) */
  2030. #define F_1_961 16069 /* FIX(1.961570560) */
  2031. #define F_2_053 16819 /* FIX(2.053119869) */
  2032. #define F_2_562 20995 /* FIX(2.562915447) */
  2033. #define F_3_072 25172 /* FIX(3.072711026) */
  2034. .balign 16
  2035. Ljsimd_fdct_islow_neon_consts:
  2036. .short F_0_298
  2037. .short -F_0_390
  2038. .short F_0_541
  2039. .short F_0_765
  2040. .short - F_0_899
  2041. .short F_1_175
  2042. .short F_1_501
  2043. .short - F_1_847
  2044. .short - F_1_961
  2045. .short F_2_053
  2046. .short - F_2_562
  2047. .short F_3_072
  2048. .short 0 /* padding */
  2049. .short 0
  2050. .short 0
  2051. .short 0
  2052. #undef F_0_298
  2053. #undef F_0_390
  2054. #undef F_0_541
  2055. #undef F_0_765
  2056. #undef F_0_899
  2057. #undef F_1_175
  2058. #undef F_1_501
  2059. #undef F_1_847
  2060. #undef F_1_961
  2061. #undef F_2_053
  2062. #undef F_2_562
  2063. #undef F_3_072
  2064. #define XFIX_P_0_298 v0.h[0]
  2065. #define XFIX_N_0_390 v0.h[1]
  2066. #define XFIX_P_0_541 v0.h[2]
  2067. #define XFIX_P_0_765 v0.h[3]
  2068. #define XFIX_N_0_899 v0.h[4]
  2069. #define XFIX_P_1_175 v0.h[5]
  2070. #define XFIX_P_1_501 v0.h[6]
  2071. #define XFIX_N_1_847 v0.h[7]
  2072. #define XFIX_N_1_961 v1.h[0]
  2073. #define XFIX_P_2_053 v1.h[1]
  2074. #define XFIX_N_2_562 v1.h[2]
  2075. #define XFIX_P_3_072 v1.h[3]
  2076. asm_function jsimd_fdct_islow_neon
  2077. DATA .req x0
  2078. TMP .req x9
  2079. /* Load constants */
  2080. adr TMP, Ljsimd_fdct_islow_neon_consts
  2081. ld1 {v0.8h, v1.8h}, [TMP]
  2082. /* Save NEON registers */
  2083. sub sp, sp, #64
  2084. mov x10, sp
  2085. st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x10], 32
  2086. st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x10], 32
  2087. /* Load all DATA into NEON registers with the following allocation:
  2088. * 0 1 2 3 | 4 5 6 7
  2089. * ---------+--------
  2090. * 0 | d16 | d17 | v16.8h
  2091. * 1 | d18 | d19 | v17.8h
  2092. * 2 | d20 | d21 | v18.8h
  2093. * 3 | d22 | d23 | v19.8h
  2094. * 4 | d24 | d25 | v20.8h
  2095. * 5 | d26 | d27 | v21.8h
  2096. * 6 | d28 | d29 | v22.8h
  2097. * 7 | d30 | d31 | v23.8h
  2098. */
  2099. ld1 {v16.8h, v17.8h, v18.8h, v19.8h}, [DATA], 64
  2100. ld1 {v20.8h, v21.8h, v22.8h, v23.8h}, [DATA]
  2101. sub DATA, DATA, #64
  2102. /* Transpose */
  2103. transpose_8x8 v16, v17, v18, v19, v20, v21, v22, v23, v31, v2, v3, v4
  2104. /* 1-D FDCT */
  2105. add v24.8h, v16.8h, v23.8h /* tmp0 = dataptr[0] + dataptr[7]; */
  2106. sub v31.8h, v16.8h, v23.8h /* tmp7 = dataptr[0] - dataptr[7]; */
  2107. add v25.8h, v17.8h, v22.8h /* tmp1 = dataptr[1] + dataptr[6]; */
  2108. sub v30.8h, v17.8h, v22.8h /* tmp6 = dataptr[1] - dataptr[6]; */
  2109. add v26.8h, v18.8h, v21.8h /* tmp2 = dataptr[2] + dataptr[5]; */
  2110. sub v29.8h, v18.8h, v21.8h /* tmp5 = dataptr[2] - dataptr[5]; */
  2111. add v27.8h, v19.8h, v20.8h /* tmp3 = dataptr[3] + dataptr[4]; */
  2112. sub v28.8h, v19.8h, v20.8h /* tmp4 = dataptr[3] - dataptr[4]; */
  2113. /* even part */
  2114. add v8.8h, v24.8h, v27.8h /* tmp10 = tmp0 + tmp3; */
  2115. sub v9.8h, v24.8h, v27.8h /* tmp13 = tmp0 - tmp3; */
  2116. add v10.8h, v25.8h, v26.8h /* tmp11 = tmp1 + tmp2; */
  2117. sub v11.8h, v25.8h, v26.8h /* tmp12 = tmp1 - tmp2; */
  2118. add v16.8h, v8.8h, v10.8h /* tmp10 + tmp11 */
  2119. sub v20.8h, v8.8h, v10.8h /* tmp10 - tmp11 */
  2120. add v18.8h, v11.8h, v9.8h /* tmp12 + tmp13 */
  2121. shl v16.8h, v16.8h, #PASS1_BITS /* dataptr[0] = (DCTELEM) LEFT_SHIFT(tmp10 + tmp11, PASS1_BITS); */
  2122. shl v20.8h, v20.8h, #PASS1_BITS /* dataptr[4] = (DCTELEM) LEFT_SHIFT(tmp10 - tmp11, PASS1_BITS); */
  2123. smull2 v24.4s, v18.8h, XFIX_P_0_541 /* z1 hi = MULTIPLY(tmp12 + tmp13, XFIX_P_0_541); */
  2124. smull v18.4s, v18.4h, XFIX_P_0_541 /* z1 lo = MULTIPLY(tmp12 + tmp13, XFIX_P_0_541); */
  2125. mov v22.16b, v18.16b
  2126. mov v25.16b, v24.16b
  2127. smlal v18.4s, v9.4h, XFIX_P_0_765 /* lo z1 + MULTIPLY(tmp13, XFIX_P_0_765) */
  2128. smlal2 v24.4s, v9.8h, XFIX_P_0_765 /* hi z1 + MULTIPLY(tmp13, XFIX_P_0_765) */
  2129. smlal v22.4s, v11.4h, XFIX_N_1_847 /* lo z1 + MULTIPLY(tmp12, XFIX_N_1_847) */
  2130. smlal2 v25.4s, v11.8h, XFIX_N_1_847 /* hi z1 + MULTIPLY(tmp12, XFIX_N_1_847) */
  2131. rshrn v18.4h, v18.4s, #DESCALE_P1
  2132. rshrn v22.4h, v22.4s, #DESCALE_P1
  2133. rshrn2 v18.8h, v24.4s, #DESCALE_P1 /* dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, XFIX_P_0_765), CONST_BITS-PASS1_BITS); */
  2134. rshrn2 v22.8h, v25.4s, #DESCALE_P1 /* dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, XFIX_N_1_847), CONST_BITS-PASS1_BITS); */
  2135. /* Odd part */
  2136. add v8.8h, v28.8h, v31.8h /* z1 = tmp4 + tmp7; */
  2137. add v9.8h, v29.8h, v30.8h /* z2 = tmp5 + tmp6; */
  2138. add v10.8h, v28.8h, v30.8h /* z3 = tmp4 + tmp6; */
  2139. add v11.8h, v29.8h, v31.8h /* z4 = tmp5 + tmp7; */
  2140. smull v4.4s, v10.4h, XFIX_P_1_175 /* z5 lo = z3 lo * XFIX_P_1_175 */
  2141. smull2 v5.4s, v10.8h, XFIX_P_1_175
  2142. smlal v4.4s, v11.4h, XFIX_P_1_175 /* z5 = MULTIPLY(z3 + z4, FIX_1_175875602); */
  2143. smlal2 v5.4s, v11.8h, XFIX_P_1_175
  2144. smull2 v24.4s, v28.8h, XFIX_P_0_298
  2145. smull2 v25.4s, v29.8h, XFIX_P_2_053
  2146. smull2 v26.4s, v30.8h, XFIX_P_3_072
  2147. smull2 v27.4s, v31.8h, XFIX_P_1_501
  2148. smull v28.4s, v28.4h, XFIX_P_0_298 /* tmp4 = MULTIPLY(tmp4, FIX_0_298631336); */
  2149. smull v29.4s, v29.4h, XFIX_P_2_053 /* tmp5 = MULTIPLY(tmp5, FIX_2_053119869); */
  2150. smull v30.4s, v30.4h, XFIX_P_3_072 /* tmp6 = MULTIPLY(tmp6, FIX_3_072711026); */
  2151. smull v31.4s, v31.4h, XFIX_P_1_501 /* tmp7 = MULTIPLY(tmp7, FIX_1_501321110); */
  2152. smull2 v12.4s, v8.8h, XFIX_N_0_899
  2153. smull2 v13.4s, v9.8h, XFIX_N_2_562
  2154. smull2 v14.4s, v10.8h, XFIX_N_1_961
  2155. smull2 v15.4s, v11.8h, XFIX_N_0_390
  2156. smull v8.4s, v8.4h, XFIX_N_0_899 /* z1 = MULTIPLY(z1, - FIX_0_899976223); */
  2157. smull v9.4s, v9.4h, XFIX_N_2_562 /* z2 = MULTIPLY(z2, - FIX_2_562915447); */
  2158. smull v10.4s, v10.4h, XFIX_N_1_961 /* z3 = MULTIPLY(z3, - FIX_1_961570560); */
  2159. smull v11.4s, v11.4h, XFIX_N_0_390 /* z4 = MULTIPLY(z4, - FIX_0_390180644); */
  2160. add v10.4s, v10.4s, v4.4s /* z3 += z5 */
  2161. add v14.4s, v14.4s, v5.4s
  2162. add v11.4s, v11.4s, v4.4s /* z4 += z5 */
  2163. add v15.4s, v15.4s, v5.4s
  2164. add v28.4s, v28.4s, v8.4s /* tmp4 += z1 */
  2165. add v24.4s, v24.4s, v12.4s
  2166. add v29.4s, v29.4s, v9.4s /* tmp5 += z2 */
  2167. add v25.4s, v25.4s, v13.4s
  2168. add v30.4s, v30.4s, v10.4s /* tmp6 += z3 */
  2169. add v26.4s, v26.4s, v14.4s
  2170. add v31.4s, v31.4s, v11.4s /* tmp7 += z4 */
  2171. add v27.4s, v27.4s, v15.4s
  2172. add v28.4s, v28.4s, v10.4s /* tmp4 += z3 */
  2173. add v24.4s, v24.4s, v14.4s
  2174. add v29.4s, v29.4s, v11.4s /* tmp5 += z4 */
  2175. add v25.4s, v25.4s, v15.4s
  2176. add v30.4s, v30.4s, v9.4s /* tmp6 += z2 */
  2177. add v26.4s, v26.4s, v13.4s
  2178. add v31.4s, v31.4s, v8.4s /* tmp7 += z1 */
  2179. add v27.4s, v27.4s, v12.4s
  2180. rshrn v23.4h, v28.4s, #DESCALE_P1
  2181. rshrn v21.4h, v29.4s, #DESCALE_P1
  2182. rshrn v19.4h, v30.4s, #DESCALE_P1
  2183. rshrn v17.4h, v31.4s, #DESCALE_P1
  2184. rshrn2 v23.8h, v24.4s, #DESCALE_P1 /* dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); */
  2185. rshrn2 v21.8h, v25.4s, #DESCALE_P1 /* dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); */
  2186. rshrn2 v19.8h, v26.4s, #DESCALE_P1 /* dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); */
  2187. rshrn2 v17.8h, v27.4s, #DESCALE_P1 /* dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); */
  2188. /* Transpose */
  2189. transpose_8x8 v16, v17, v18, v19, v20, v21, v22, v23, v31, v2, v3, v4
  2190. /* 1-D FDCT */
  2191. add v24.8h, v16.8h, v23.8h /* tmp0 = dataptr[0] + dataptr[7]; */
  2192. sub v31.8h, v16.8h, v23.8h /* tmp7 = dataptr[0] - dataptr[7]; */
  2193. add v25.8h, v17.8h, v22.8h /* tmp1 = dataptr[1] + dataptr[6]; */
  2194. sub v30.8h, v17.8h, v22.8h /* tmp6 = dataptr[1] - dataptr[6]; */
  2195. add v26.8h, v18.8h, v21.8h /* tmp2 = dataptr[2] + dataptr[5]; */
  2196. sub v29.8h, v18.8h, v21.8h /* tmp5 = dataptr[2] - dataptr[5]; */
  2197. add v27.8h, v19.8h, v20.8h /* tmp3 = dataptr[3] + dataptr[4]; */
  2198. sub v28.8h, v19.8h, v20.8h /* tmp4 = dataptr[3] - dataptr[4]; */
  2199. /* even part */
  2200. add v8.8h, v24.8h, v27.8h /* tmp10 = tmp0 + tmp3; */
  2201. sub v9.8h, v24.8h, v27.8h /* tmp13 = tmp0 - tmp3; */
  2202. add v10.8h, v25.8h, v26.8h /* tmp11 = tmp1 + tmp2; */
  2203. sub v11.8h, v25.8h, v26.8h /* tmp12 = tmp1 - tmp2; */
  2204. add v16.8h, v8.8h, v10.8h /* tmp10 + tmp11 */
  2205. sub v20.8h, v8.8h, v10.8h /* tmp10 - tmp11 */
  2206. add v18.8h, v11.8h, v9.8h /* tmp12 + tmp13 */
  2207. srshr v16.8h, v16.8h, #PASS1_BITS /* dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); */
  2208. srshr v20.8h, v20.8h, #PASS1_BITS /* dataptr[4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); */
  2209. smull2 v24.4s, v18.8h, XFIX_P_0_541 /* z1 hi = MULTIPLY(tmp12 + tmp13, XFIX_P_0_541); */
  2210. smull v18.4s, v18.4h, XFIX_P_0_541 /* z1 lo = MULTIPLY(tmp12 + tmp13, XFIX_P_0_541); */
  2211. mov v22.16b, v18.16b
  2212. mov v25.16b, v24.16b
  2213. smlal v18.4s, v9.4h, XFIX_P_0_765 /* lo z1 + MULTIPLY(tmp13, XFIX_P_0_765) */
  2214. smlal2 v24.4s, v9.8h, XFIX_P_0_765 /* hi z1 + MULTIPLY(tmp13, XFIX_P_0_765) */
  2215. smlal v22.4s, v11.4h, XFIX_N_1_847 /* lo z1 + MULTIPLY(tmp12, XFIX_N_1_847) */
  2216. smlal2 v25.4s, v11.8h, XFIX_N_1_847 /* hi z1 + MULTIPLY(tmp12, XFIX_N_1_847) */
  2217. rshrn v18.4h, v18.4s, #DESCALE_P2
  2218. rshrn v22.4h, v22.4s, #DESCALE_P2
  2219. rshrn2 v18.8h, v24.4s, #DESCALE_P2 /* dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, XFIX_P_0_765), CONST_BITS-PASS1_BITS); */
  2220. rshrn2 v22.8h, v25.4s, #DESCALE_P2 /* dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, XFIX_N_1_847), CONST_BITS-PASS1_BITS); */
  2221. /* Odd part */
  2222. add v8.8h, v28.8h, v31.8h /* z1 = tmp4 + tmp7; */
  2223. add v9.8h, v29.8h, v30.8h /* z2 = tmp5 + tmp6; */
  2224. add v10.8h, v28.8h, v30.8h /* z3 = tmp4 + tmp6; */
  2225. add v11.8h, v29.8h, v31.8h /* z4 = tmp5 + tmp7; */
  2226. smull v4.4s, v10.4h, XFIX_P_1_175 /* z5 lo = z3 lo * XFIX_P_1_175 */
  2227. smull2 v5.4s, v10.8h, XFIX_P_1_175
  2228. smlal v4.4s, v11.4h, XFIX_P_1_175 /* z5 = MULTIPLY(z3 + z4, FIX_1_175875602); */
  2229. smlal2 v5.4s, v11.8h, XFIX_P_1_175
  2230. smull2 v24.4s, v28.8h, XFIX_P_0_298
  2231. smull2 v25.4s, v29.8h, XFIX_P_2_053
  2232. smull2 v26.4s, v30.8h, XFIX_P_3_072
  2233. smull2 v27.4s, v31.8h, XFIX_P_1_501
  2234. smull v28.4s, v28.4h, XFIX_P_0_298 /* tmp4 = MULTIPLY(tmp4, FIX_0_298631336); */
  2235. smull v29.4s, v29.4h, XFIX_P_2_053 /* tmp5 = MULTIPLY(tmp5, FIX_2_053119869); */
  2236. smull v30.4s, v30.4h, XFIX_P_3_072 /* tmp6 = MULTIPLY(tmp6, FIX_3_072711026); */
  2237. smull v31.4s, v31.4h, XFIX_P_1_501 /* tmp7 = MULTIPLY(tmp7, FIX_1_501321110); */
  2238. smull2 v12.4s, v8.8h, XFIX_N_0_899
  2239. smull2 v13.4s, v9.8h, XFIX_N_2_562
  2240. smull2 v14.4s, v10.8h, XFIX_N_1_961
  2241. smull2 v15.4s, v11.8h, XFIX_N_0_390
  2242. smull v8.4s, v8.4h, XFIX_N_0_899 /* z1 = MULTIPLY(z1, - FIX_0_899976223); */
  2243. smull v9.4s, v9.4h, XFIX_N_2_562 /* z2 = MULTIPLY(z2, - FIX_2_562915447); */
  2244. smull v10.4s, v10.4h, XFIX_N_1_961 /* z3 = MULTIPLY(z3, - FIX_1_961570560); */
  2245. smull v11.4s, v11.4h, XFIX_N_0_390 /* z4 = MULTIPLY(z4, - FIX_0_390180644); */
  2246. add v10.4s, v10.4s, v4.4s
  2247. add v14.4s, v14.4s, v5.4s
  2248. add v11.4s, v11.4s, v4.4s
  2249. add v15.4s, v15.4s, v5.4s
  2250. add v28.4s, v28.4s, v8.4s /* tmp4 += z1 */
  2251. add v24.4s, v24.4s, v12.4s
  2252. add v29.4s, v29.4s, v9.4s /* tmp5 += z2 */
  2253. add v25.4s, v25.4s, v13.4s
  2254. add v30.4s, v30.4s, v10.4s /* tmp6 += z3 */
  2255. add v26.4s, v26.4s, v14.4s
  2256. add v31.4s, v31.4s, v11.4s /* tmp7 += z4 */
  2257. add v27.4s, v27.4s, v15.4s
  2258. add v28.4s, v28.4s, v10.4s /* tmp4 += z3 */
  2259. add v24.4s, v24.4s, v14.4s
  2260. add v29.4s, v29.4s, v11.4s /* tmp5 += z4 */
  2261. add v25.4s, v25.4s, v15.4s
  2262. add v30.4s, v30.4s, v9.4s /* tmp6 += z2 */
  2263. add v26.4s, v26.4s, v13.4s
  2264. add v31.4s, v31.4s, v8.4s /* tmp7 += z1 */
  2265. add v27.4s, v27.4s, v12.4s
  2266. rshrn v23.4h, v28.4s, #DESCALE_P2
  2267. rshrn v21.4h, v29.4s, #DESCALE_P2
  2268. rshrn v19.4h, v30.4s, #DESCALE_P2
  2269. rshrn v17.4h, v31.4s, #DESCALE_P2
  2270. rshrn2 v23.8h, v24.4s, #DESCALE_P2 /* dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); */
  2271. rshrn2 v21.8h, v25.4s, #DESCALE_P2 /* dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); */
  2272. rshrn2 v19.8h, v26.4s, #DESCALE_P2 /* dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); */
  2273. rshrn2 v17.8h, v27.4s, #DESCALE_P2 /* dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); */
  2274. /* store results */
  2275. st1 {v16.8h, v17.8h, v18.8h, v19.8h}, [DATA], 64
  2276. st1 {v20.8h, v21.8h, v22.8h, v23.8h}, [DATA]
  2277. /* Restore NEON registers */
  2278. ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [sp], 32
  2279. ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [sp], 32
  2280. br x30
  2281. .unreq DATA
  2282. .unreq TMP
  2283. #undef XFIX_P_0_298
  2284. #undef XFIX_N_0_390
  2285. #undef XFIX_P_0_541
  2286. #undef XFIX_P_0_765
  2287. #undef XFIX_N_0_899
  2288. #undef XFIX_P_1_175
  2289. #undef XFIX_P_1_501
  2290. #undef XFIX_N_1_847
  2291. #undef XFIX_N_1_961
  2292. #undef XFIX_P_2_053
  2293. #undef XFIX_N_2_562
  2294. #undef XFIX_P_3_072
  2295. /*****************************************************************************/
  2296. /*
  2297. * jsimd_fdct_ifast_neon
  2298. *
  2299. * This function contains a fast, not so accurate integer implementation of
  2300. * the forward DCT (Discrete Cosine Transform). It uses the same calculations
  2301. * and produces exactly the same output as IJG's original 'jpeg_fdct_ifast'
  2302. * function from jfdctfst.c
  2303. *
  2304. * TODO: can be combined with 'jsimd_convsamp_neon' to get
  2305. * rid of a bunch of VLD1.16 instructions
  2306. */
  2307. #undef XFIX_0_541196100
  2308. #define XFIX_0_382683433 v0.h[0]
  2309. #define XFIX_0_541196100 v0.h[1]
  2310. #define XFIX_0_707106781 v0.h[2]
  2311. #define XFIX_1_306562965 v0.h[3]
  2312. .balign 16
  2313. Ljsimd_fdct_ifast_neon_consts:
  2314. .short (98 * 128) /* XFIX_0_382683433 */
  2315. .short (139 * 128) /* XFIX_0_541196100 */
  2316. .short (181 * 128) /* XFIX_0_707106781 */
  2317. .short (334 * 128 - 256 * 128) /* XFIX_1_306562965 */
  2318. asm_function jsimd_fdct_ifast_neon
  2319. DATA .req x0
  2320. TMP .req x9
  2321. /* Load constants */
  2322. adr TMP, Ljsimd_fdct_ifast_neon_consts
  2323. ld1 {v0.4h}, [TMP]
  2324. /* Load all DATA into NEON registers with the following allocation:
  2325. * 0 1 2 3 | 4 5 6 7
  2326. * ---------+--------
  2327. * 0 | d16 | d17 | v0.8h
  2328. * 1 | d18 | d19 | q9
  2329. * 2 | d20 | d21 | q10
  2330. * 3 | d22 | d23 | q11
  2331. * 4 | d24 | d25 | q12
  2332. * 5 | d26 | d27 | q13
  2333. * 6 | d28 | d29 | q14
  2334. * 7 | d30 | d31 | q15
  2335. */
  2336. ld1 {v16.8h, v17.8h, v18.8h, v19.8h}, [DATA], 64
  2337. ld1 {v20.8h, v21.8h, v22.8h, v23.8h}, [DATA]
  2338. mov TMP, #2
  2339. sub DATA, DATA, #64
  2340. 1:
  2341. /* Transpose */
  2342. transpose_8x8 v16, v17, v18, v19, v20, v21, v22, v23, v1, v2, v3, v4
  2343. subs TMP, TMP, #1
  2344. /* 1-D FDCT */
  2345. add v4.8h, v19.8h, v20.8h
  2346. sub v20.8h, v19.8h, v20.8h
  2347. sub v28.8h, v18.8h, v21.8h
  2348. add v18.8h, v18.8h, v21.8h
  2349. sub v29.8h, v17.8h, v22.8h
  2350. add v17.8h, v17.8h, v22.8h
  2351. sub v21.8h, v16.8h, v23.8h
  2352. add v16.8h, v16.8h, v23.8h
  2353. sub v6.8h, v17.8h, v18.8h
  2354. sub v7.8h, v16.8h, v4.8h
  2355. add v5.8h, v17.8h, v18.8h
  2356. add v6.8h, v6.8h, v7.8h
  2357. add v4.8h, v16.8h, v4.8h
  2358. sqdmulh v6.8h, v6.8h, XFIX_0_707106781
  2359. add v19.8h, v20.8h, v28.8h
  2360. add v16.8h, v4.8h, v5.8h
  2361. sub v20.8h, v4.8h, v5.8h
  2362. add v5.8h, v28.8h, v29.8h
  2363. add v29.8h, v29.8h, v21.8h
  2364. sqdmulh v5.8h, v5.8h, XFIX_0_707106781
  2365. sub v28.8h, v19.8h, v29.8h
  2366. add v18.8h, v7.8h, v6.8h
  2367. sqdmulh v28.8h, v28.8h, XFIX_0_382683433
  2368. sub v22.8h, v7.8h, v6.8h
  2369. sqdmulh v19.8h, v19.8h, XFIX_0_541196100
  2370. sqdmulh v7.8h, v29.8h, XFIX_1_306562965
  2371. add v6.8h, v21.8h, v5.8h
  2372. sub v5.8h, v21.8h, v5.8h
  2373. add v29.8h, v29.8h, v28.8h
  2374. add v19.8h, v19.8h, v28.8h
  2375. add v29.8h, v29.8h, v7.8h
  2376. add v21.8h, v5.8h, v19.8h
  2377. sub v19.8h, v5.8h, v19.8h
  2378. add v17.8h, v6.8h, v29.8h
  2379. sub v23.8h, v6.8h, v29.8h
  2380. b.ne 1b
  2381. /* store results */
  2382. st1 {v16.8h, v17.8h, v18.8h, v19.8h}, [DATA], 64
  2383. st1 {v20.8h, v21.8h, v22.8h, v23.8h}, [DATA]
  2384. br x30
  2385. .unreq DATA
  2386. .unreq TMP
  2387. #undef XFIX_0_382683433
  2388. #undef XFIX_0_541196100
  2389. #undef XFIX_0_707106781
  2390. #undef XFIX_1_306562965
  2391. /*****************************************************************************/
  2392. /*
  2393. * GLOBAL(void)
  2394. * jsimd_quantize_neon (JCOEFPTR coef_block, DCTELEM *divisors,
  2395. * DCTELEM *workspace);
  2396. *
  2397. */
  2398. asm_function jsimd_quantize_neon
  2399. COEF_BLOCK .req x0
  2400. DIVISORS .req x1
  2401. WORKSPACE .req x2
  2402. RECIPROCAL .req DIVISORS
  2403. CORRECTION .req x9
  2404. SHIFT .req x10
  2405. LOOP_COUNT .req x11
  2406. mov LOOP_COUNT, #2
  2407. add CORRECTION, DIVISORS, #(64 * 2)
  2408. add SHIFT, DIVISORS, #(64 * 6)
  2409. 1:
  2410. subs LOOP_COUNT, LOOP_COUNT, #1
  2411. ld1 {v0.8h, v1.8h, v2.8h, v3.8h}, [WORKSPACE], 64
  2412. ld1 {v4.8h, v5.8h, v6.8h, v7.8h}, [CORRECTION], 64
  2413. abs v20.8h, v0.8h
  2414. abs v21.8h, v1.8h
  2415. abs v22.8h, v2.8h
  2416. abs v23.8h, v3.8h
  2417. ld1 {v28.8h, v29.8h, v30.8h, v31.8h}, [RECIPROCAL], 64
  2418. add v20.8h, v20.8h, v4.8h /* add correction */
  2419. add v21.8h, v21.8h, v5.8h
  2420. add v22.8h, v22.8h, v6.8h
  2421. add v23.8h, v23.8h, v7.8h
  2422. umull v4.4s, v20.4h, v28.4h /* multiply by reciprocal */
  2423. umull2 v16.4s, v20.8h, v28.8h
  2424. umull v5.4s, v21.4h, v29.4h
  2425. umull2 v17.4s, v21.8h, v29.8h
  2426. umull v6.4s, v22.4h, v30.4h /* multiply by reciprocal */
  2427. umull2 v18.4s, v22.8h, v30.8h
  2428. umull v7.4s, v23.4h, v31.4h
  2429. umull2 v19.4s, v23.8h, v31.8h
  2430. ld1 {v24.8h, v25.8h, v26.8h, v27.8h}, [SHIFT], 64
  2431. shrn v4.4h, v4.4s, #16
  2432. shrn v5.4h, v5.4s, #16
  2433. shrn v6.4h, v6.4s, #16
  2434. shrn v7.4h, v7.4s, #16
  2435. shrn2 v4.8h, v16.4s, #16
  2436. shrn2 v5.8h, v17.4s, #16
  2437. shrn2 v6.8h, v18.4s, #16
  2438. shrn2 v7.8h, v19.4s, #16
  2439. neg v24.8h, v24.8h
  2440. neg v25.8h, v25.8h
  2441. neg v26.8h, v26.8h
  2442. neg v27.8h, v27.8h
  2443. sshr v0.8h, v0.8h, #15 /* extract sign */
  2444. sshr v1.8h, v1.8h, #15
  2445. sshr v2.8h, v2.8h, #15
  2446. sshr v3.8h, v3.8h, #15
  2447. ushl v4.8h, v4.8h, v24.8h /* shift */
  2448. ushl v5.8h, v5.8h, v25.8h
  2449. ushl v6.8h, v6.8h, v26.8h
  2450. ushl v7.8h, v7.8h, v27.8h
  2451. eor v4.16b, v4.16b, v0.16b /* restore sign */
  2452. eor v5.16b, v5.16b, v1.16b
  2453. eor v6.16b, v6.16b, v2.16b
  2454. eor v7.16b, v7.16b, v3.16b
  2455. sub v4.8h, v4.8h, v0.8h
  2456. sub v5.8h, v5.8h, v1.8h
  2457. sub v6.8h, v6.8h, v2.8h
  2458. sub v7.8h, v7.8h, v3.8h
  2459. st1 {v4.8h, v5.8h, v6.8h, v7.8h}, [COEF_BLOCK], 64
  2460. b.ne 1b
  2461. br x30 /* return */
  2462. .unreq COEF_BLOCK
  2463. .unreq DIVISORS
  2464. .unreq WORKSPACE
  2465. .unreq RECIPROCAL
  2466. .unreq CORRECTION
  2467. .unreq SHIFT
  2468. .unreq LOOP_COUNT
  2469. /*****************************************************************************/
  2470. /*
  2471. * Downsample pixel values of a single component.
  2472. * This version handles the common case of 2:1 horizontal and 1:1 vertical,
  2473. * without smoothing.
  2474. *
  2475. * GLOBAL(void)
  2476. * jsimd_h2v1_downsample_neon (JDIMENSION image_width, int max_v_samp_factor,
  2477. * JDIMENSION v_samp_factor,
  2478. * JDIMENSION width_blocks, JSAMPARRAY input_data,
  2479. * JSAMPARRAY output_data);
  2480. */
  2481. .balign 16
  2482. Ljsimd_h2_downsample_neon_consts:
  2483. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2484. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F /* diff 0 */
  2485. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2486. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0E /* diff 1 */
  2487. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2488. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0D, 0x0D /* diff 2 */
  2489. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2490. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0C, 0x0C, 0x0C /* diff 3 */
  2491. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2492. 0x08, 0x09, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B /* diff 4 */
  2493. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2494. 0x08, 0x09, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A /* diff 5 */
  2495. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2496. 0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09 /* diff 6 */
  2497. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2498. 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 /* diff 7 */
  2499. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
  2500. 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 /* diff 8 */
  2501. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x06, \
  2502. 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06 /* diff 9 */
  2503. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x05, \
  2504. 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05 /* diff 10 */
  2505. .byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x04, 0x04, \
  2506. 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 /* diff 11 */
  2507. .byte 0x00, 0x01, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, \
  2508. 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 /* diff 12 */
  2509. .byte 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, \
  2510. 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 /* diff 13 */
  2511. .byte 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, \
  2512. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 /* diff 14 */
  2513. .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  2514. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* diff 15 */
  2515. asm_function jsimd_h2v1_downsample_neon
  2516. IMAGE_WIDTH .req x0
  2517. MAX_V_SAMP .req x1
  2518. V_SAMP .req x2
  2519. BLOCK_WIDTH .req x3
  2520. INPUT_DATA .req x4
  2521. OUTPUT_DATA .req x5
  2522. OUTPTR .req x9
  2523. INPTR .req x10
  2524. TMP1 .req x11
  2525. TMP2 .req x12
  2526. TMP3 .req x13
  2527. TMPDUP .req w15
  2528. mov TMPDUP, #0x10000
  2529. lsl TMP2, BLOCK_WIDTH, #4
  2530. sub TMP2, TMP2, IMAGE_WIDTH
  2531. adr TMP3, Ljsimd_h2_downsample_neon_consts
  2532. add TMP3, TMP3, TMP2, lsl #4
  2533. dup v16.4s, TMPDUP
  2534. ld1 {v18.16b}, [TMP3]
  2535. 1: /* row loop */
  2536. ldr INPTR, [INPUT_DATA], #8
  2537. ldr OUTPTR, [OUTPUT_DATA], #8
  2538. subs TMP1, BLOCK_WIDTH, #1
  2539. b.eq 3f
  2540. 2: /* columns */
  2541. ld1 {v0.16b}, [INPTR], #16
  2542. mov v4.16b, v16.16b
  2543. subs TMP1, TMP1, #1
  2544. uadalp v4.8h, v0.16b
  2545. shrn v6.8b, v4.8h, #1
  2546. st1 {v6.8b}, [OUTPTR], #8
  2547. b.ne 2b
  2548. 3: /* last columns */
  2549. ld1 {v0.16b}, [INPTR]
  2550. mov v4.16b, v16.16b
  2551. subs V_SAMP, V_SAMP, #1
  2552. /* expand right */
  2553. tbl v2.16b, {v0.16b}, v18.16b
  2554. uadalp v4.8h, v2.16b
  2555. shrn v6.8b, v4.8h, #1
  2556. st1 {v6.8b}, [OUTPTR], #8
  2557. b.ne 1b
  2558. br x30
  2559. .unreq IMAGE_WIDTH
  2560. .unreq MAX_V_SAMP
  2561. .unreq V_SAMP
  2562. .unreq BLOCK_WIDTH
  2563. .unreq INPUT_DATA
  2564. .unreq OUTPUT_DATA
  2565. .unreq OUTPTR
  2566. .unreq INPTR
  2567. .unreq TMP1
  2568. .unreq TMP2
  2569. .unreq TMP3
  2570. .unreq TMPDUP
  2571. /*****************************************************************************/
  2572. /*
  2573. * Downsample pixel values of a single component.
  2574. * This version handles the common case of 2:1 horizontal and 2:1 vertical,
  2575. * without smoothing.
  2576. *
  2577. * GLOBAL(void)
  2578. * jsimd_h2v2_downsample_neon (JDIMENSION image_width, int max_v_samp_factor,
  2579. * JDIMENSION v_samp_factor, JDIMENSION width_blocks,
  2580. * JSAMPARRAY input_data, JSAMPARRAY output_data);
  2581. */
  2582. .balign 16
  2583. asm_function jsimd_h2v2_downsample_neon
  2584. IMAGE_WIDTH .req x0
  2585. MAX_V_SAMP .req x1
  2586. V_SAMP .req x2
  2587. BLOCK_WIDTH .req x3
  2588. INPUT_DATA .req x4
  2589. OUTPUT_DATA .req x5
  2590. OUTPTR .req x9
  2591. INPTR0 .req x10
  2592. INPTR1 .req x14
  2593. TMP1 .req x11
  2594. TMP2 .req x12
  2595. TMP3 .req x13
  2596. TMPDUP .req w15
  2597. mov TMPDUP, #1
  2598. lsl TMP2, BLOCK_WIDTH, #4
  2599. lsl TMPDUP, TMPDUP, #17
  2600. sub TMP2, TMP2, IMAGE_WIDTH
  2601. adr TMP3, Ljsimd_h2_downsample_neon_consts
  2602. orr TMPDUP, TMPDUP, #1
  2603. add TMP3, TMP3, TMP2, lsl #4
  2604. dup v16.4s, TMPDUP
  2605. ld1 {v18.16b}, [TMP3]
  2606. 1: /* row loop */
  2607. ldr INPTR0, [INPUT_DATA], #8
  2608. ldr OUTPTR, [OUTPUT_DATA], #8
  2609. ldr INPTR1, [INPUT_DATA], #8
  2610. subs TMP1, BLOCK_WIDTH, #1
  2611. b.eq 3f
  2612. 2: /* columns */
  2613. ld1 {v0.16b}, [INPTR0], #16
  2614. ld1 {v1.16b}, [INPTR1], #16
  2615. mov v4.16b, v16.16b
  2616. subs TMP1, TMP1, #1
  2617. uadalp v4.8h, v0.16b
  2618. uadalp v4.8h, v1.16b
  2619. shrn v6.8b, v4.8h, #2
  2620. st1 {v6.8b}, [OUTPTR], #8
  2621. b.ne 2b
  2622. 3: /* last columns */
  2623. ld1 {v0.16b}, [INPTR0], #16
  2624. ld1 {v1.16b}, [INPTR1], #16
  2625. mov v4.16b, v16.16b
  2626. subs V_SAMP, V_SAMP, #1
  2627. /* expand right */
  2628. tbl v2.16b, {v0.16b}, v18.16b
  2629. tbl v3.16b, {v1.16b}, v18.16b
  2630. uadalp v4.8h, v2.16b
  2631. uadalp v4.8h, v3.16b
  2632. shrn v6.8b, v4.8h, #2
  2633. st1 {v6.8b}, [OUTPTR], #8
  2634. b.ne 1b
  2635. br x30
  2636. .unreq IMAGE_WIDTH
  2637. .unreq MAX_V_SAMP
  2638. .unreq V_SAMP
  2639. .unreq BLOCK_WIDTH
  2640. .unreq INPUT_DATA
  2641. .unreq OUTPUT_DATA
  2642. .unreq OUTPTR
  2643. .unreq INPTR0
  2644. .unreq INPTR1
  2645. .unreq TMP1
  2646. .unreq TMP2
  2647. .unreq TMP3
  2648. .unreq TMPDUP
  2649. /*****************************************************************************/
  2650. /*
  2651. * GLOBAL(JOCTET*)
  2652. * jsimd_huff_encode_one_block (working_state *state, JOCTET *buffer,
  2653. * JCOEFPTR block, int last_dc_val,
  2654. * c_derived_tbl *dctbl, c_derived_tbl *actbl)
  2655. *
  2656. */
  2657. BUFFER .req x1
  2658. PUT_BUFFER .req x6
  2659. PUT_BITS .req x7
  2660. PUT_BITSw .req w7
  2661. .macro emit_byte
  2662. sub PUT_BITS, PUT_BITS, #0x8
  2663. lsr x19, PUT_BUFFER, PUT_BITS
  2664. uxtb w19, w19
  2665. strb w19, [BUFFER, #1]!
  2666. cmp w19, #0xff
  2667. b.ne 14f
  2668. strb wzr, [BUFFER, #1]!
  2669. 14:
  2670. .endm
  2671. .macro put_bits CODE, SIZE
  2672. lsl PUT_BUFFER, PUT_BUFFER, \SIZE
  2673. add PUT_BITS, PUT_BITS, \SIZE
  2674. orr PUT_BUFFER, PUT_BUFFER, \CODE
  2675. .endm
  2676. .macro checkbuf31
  2677. cmp PUT_BITS, #0x20
  2678. b.lt 31f
  2679. emit_byte
  2680. emit_byte
  2681. emit_byte
  2682. emit_byte
  2683. 31:
  2684. .endm
  2685. .macro checkbuf47
  2686. cmp PUT_BITS, #0x30
  2687. b.lt 47f
  2688. emit_byte
  2689. emit_byte
  2690. emit_byte
  2691. emit_byte
  2692. emit_byte
  2693. emit_byte
  2694. 47:
  2695. .endm
  2696. .macro generate_jsimd_huff_encode_one_block fast_tbl
  2697. .balign 16
  2698. .if \fast_tbl == 1
  2699. Ljsimd_huff_encode_one_block_neon_consts:
  2700. .else
  2701. Ljsimd_huff_encode_one_block_neon_slowtbl_consts:
  2702. .endif
  2703. .byte 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, \
  2704. 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
  2705. .if \fast_tbl == 1
  2706. .byte 0, 1, 2, 3, 16, 17, 32, 33, \
  2707. 18, 19, 4, 5, 6, 7, 20, 21 /* L0 => L3 : 4 lines OK */
  2708. .byte 34, 35, 48, 49, 255, 255, 50, 51, \
  2709. 36, 37, 22, 23, 8, 9, 10, 11 /* L0 => L3 : 4 lines OK */
  2710. .byte 8, 9, 22, 23, 36, 37, 50, 51, \
  2711. 255, 255, 255, 255, 255, 255, 52, 53 /* L1 => L4 : 4 lines OK */
  2712. .byte 54, 55, 40, 41, 26, 27, 12, 13, \
  2713. 14, 15, 28, 29, 42, 43, 56, 57 /* L0 => L3 : 4 lines OK */
  2714. .byte 6, 7, 20, 21, 34, 35, 48, 49, \
  2715. 50, 51, 36, 37, 22, 23, 8, 9 /* L4 => L7 : 4 lines OK */
  2716. .byte 42, 43, 28, 29, 14, 15, 30, 31, \
  2717. 44, 45, 58, 59, 255, 255, 255, 255 /* L1 => L4 : 4 lines OK */
  2718. .byte 255, 255, 255, 255, 56, 57, 42, 43, \
  2719. 28, 29, 14, 15, 30, 31, 44, 45 /* L3 => L6 : 4 lines OK */
  2720. .byte 26, 27, 40, 41, 42, 43, 28, 29, \
  2721. 14, 15, 30, 31, 44, 45, 46, 47 /* L5 => L7 : 3 lines OK */
  2722. .byte 255, 255, 255, 255, 0, 1, 255, 255, \
  2723. 255, 255, 255, 255, 255, 255, 255, 255 /* L4 : 1 lines OK */
  2724. .byte 255, 255, 255, 255, 255, 255, 255, 255, \
  2725. 0, 1, 16, 17, 2, 3, 255, 255 /* L5 => L6 : 2 lines OK */
  2726. .byte 255, 255, 255, 255, 255, 255, 255, 255, \
  2727. 255, 255, 255, 255, 8, 9, 22, 23 /* L5 => L6 : 2 lines OK */
  2728. .byte 4, 5, 6, 7, 255, 255, 255, 255, \
  2729. 255, 255, 255, 255, 255, 255, 255, 255 /* L7 : 1 line OK */
  2730. .endif
  2731. .if \fast_tbl == 1
  2732. asm_function jsimd_huff_encode_one_block_neon
  2733. .else
  2734. asm_function jsimd_huff_encode_one_block_neon_slowtbl
  2735. .endif
  2736. sub sp, sp, 272
  2737. sub BUFFER, BUFFER, #0x1 /* BUFFER=buffer-- */
  2738. /* Save ARM registers */
  2739. stp x19, x20, [sp]
  2740. .if \fast_tbl == 1
  2741. adr x15, Ljsimd_huff_encode_one_block_neon_consts
  2742. .else
  2743. adr x15, Ljsimd_huff_encode_one_block_neon_slowtbl_consts
  2744. .endif
  2745. ldr PUT_BUFFER, [x0, #0x10]
  2746. ldr PUT_BITSw, [x0, #0x18]
  2747. ldrsh w12, [x2] /* load DC coeff in w12 */
  2748. /* prepare data */
  2749. .if \fast_tbl == 1
  2750. ld1 {v23.16b}, [x15], #16
  2751. ld1 {v0.16b, v1.16b, v2.16b, v3.16b}, [x15], #64
  2752. ld1 {v4.16b, v5.16b, v6.16b, v7.16b}, [x15], #64
  2753. ld1 {v16.16b, v17.16b, v18.16b, v19.16b}, [x15], #64
  2754. ld1 {v24.16b, v25.16b, v26.16b, v27.16b}, [x2], #64
  2755. ld1 {v28.16b, v29.16b, v30.16b, v31.16b}, [x2], #64
  2756. sub w12, w12, w3 /* last_dc_val, not used afterwards */
  2757. /* ZigZag 8x8 */
  2758. tbl v0.16b, {v24.16b, v25.16b, v26.16b, v27.16b}, v0.16b
  2759. tbl v1.16b, {v24.16b, v25.16b, v26.16b, v27.16b}, v1.16b
  2760. tbl v2.16b, {v25.16b, v26.16b, v27.16b, v28.16b}, v2.16b
  2761. tbl v3.16b, {v24.16b, v25.16b, v26.16b, v27.16b}, v3.16b
  2762. tbl v4.16b, {v28.16b, v29.16b, v30.16b, v31.16b}, v4.16b
  2763. tbl v5.16b, {v25.16b, v26.16b, v27.16b, v28.16b}, v5.16b
  2764. tbl v6.16b, {v27.16b, v28.16b, v29.16b, v30.16b}, v6.16b
  2765. tbl v7.16b, {v29.16b, v30.16b, v31.16b}, v7.16b
  2766. ins v0.h[0], w12
  2767. tbx v1.16b, {v28.16b}, v16.16b
  2768. tbx v2.16b, {v29.16b, v30.16b}, v17.16b
  2769. tbx v5.16b, {v29.16b, v30.16b}, v18.16b
  2770. tbx v6.16b, {v31.16b}, v19.16b
  2771. .else
  2772. add x13, x2, #0x22
  2773. sub w12, w12, w3 /* last_dc_val, not used afterwards */
  2774. ld1 {v23.16b}, [x15]
  2775. add x14, x2, #0x18
  2776. add x3, x2, #0x36
  2777. ins v0.h[0], w12
  2778. add x9, x2, #0x2
  2779. ld1 {v1.h}[0], [x13]
  2780. add x15, x2, #0x30
  2781. ld1 {v2.h}[0], [x14]
  2782. add x19, x2, #0x26
  2783. ld1 {v3.h}[0], [x3]
  2784. add x20, x2, #0x28
  2785. ld1 {v0.h}[1], [x9]
  2786. add x12, x2, #0x10
  2787. ld1 {v1.h}[1], [x15]
  2788. add x13, x2, #0x40
  2789. ld1 {v2.h}[1], [x19]
  2790. add x14, x2, #0x34
  2791. ld1 {v3.h}[1], [x20]
  2792. add x3, x2, #0x1a
  2793. ld1 {v0.h}[2], [x12]
  2794. add x9, x2, #0x20
  2795. ld1 {v1.h}[2], [x13]
  2796. add x15, x2, #0x32
  2797. ld1 {v2.h}[2], [x14]
  2798. add x19, x2, #0x42
  2799. ld1 {v3.h}[2], [x3]
  2800. add x20, x2, #0xc
  2801. ld1 {v0.h}[3], [x9]
  2802. add x12, x2, #0x12
  2803. ld1 {v1.h}[3], [x15]
  2804. add x13, x2, #0x24
  2805. ld1 {v2.h}[3], [x19]
  2806. add x14, x2, #0x50
  2807. ld1 {v3.h}[3], [x20]
  2808. add x3, x2, #0xe
  2809. ld1 {v0.h}[4], [x12]
  2810. add x9, x2, #0x4
  2811. ld1 {v1.h}[4], [x13]
  2812. add x15, x2, #0x16
  2813. ld1 {v2.h}[4], [x14]
  2814. add x19, x2, #0x60
  2815. ld1 {v3.h}[4], [x3]
  2816. add x20, x2, #0x1c
  2817. ld1 {v0.h}[5], [x9]
  2818. add x12, x2, #0x6
  2819. ld1 {v1.h}[5], [x15]
  2820. add x13, x2, #0x8
  2821. ld1 {v2.h}[5], [x19]
  2822. add x14, x2, #0x52
  2823. ld1 {v3.h}[5], [x20]
  2824. add x3, x2, #0x2a
  2825. ld1 {v0.h}[6], [x12]
  2826. add x9, x2, #0x14
  2827. ld1 {v1.h}[6], [x13]
  2828. add x15, x2, #0xa
  2829. ld1 {v2.h}[6], [x14]
  2830. add x19, x2, #0x44
  2831. ld1 {v3.h}[6], [x3]
  2832. add x20, x2, #0x38
  2833. ld1 {v0.h}[7], [x9]
  2834. add x12, x2, #0x46
  2835. ld1 {v1.h}[7], [x15]
  2836. add x13, x2, #0x3a
  2837. ld1 {v2.h}[7], [x19]
  2838. add x14, x2, #0x74
  2839. ld1 {v3.h}[7], [x20]
  2840. add x3, x2, #0x6a
  2841. ld1 {v4.h}[0], [x12]
  2842. add x9, x2, #0x54
  2843. ld1 {v5.h}[0], [x13]
  2844. add x15, x2, #0x2c
  2845. ld1 {v6.h}[0], [x14]
  2846. add x19, x2, #0x76
  2847. ld1 {v7.h}[0], [x3]
  2848. add x20, x2, #0x78
  2849. ld1 {v4.h}[1], [x9]
  2850. add x12, x2, #0x62
  2851. ld1 {v5.h}[1], [x15]
  2852. add x13, x2, #0x1e
  2853. ld1 {v6.h}[1], [x19]
  2854. add x14, x2, #0x68
  2855. ld1 {v7.h}[1], [x20]
  2856. add x3, x2, #0x7a
  2857. ld1 {v4.h}[2], [x12]
  2858. add x9, x2, #0x70
  2859. ld1 {v5.h}[2], [x13]
  2860. add x15, x2, #0x2e
  2861. ld1 {v6.h}[2], [x14]
  2862. add x19, x2, #0x5a
  2863. ld1 {v7.h}[2], [x3]
  2864. add x20, x2, #0x6c
  2865. ld1 {v4.h}[3], [x9]
  2866. add x12, x2, #0x72
  2867. ld1 {v5.h}[3], [x15]
  2868. add x13, x2, #0x3c
  2869. ld1 {v6.h}[3], [x19]
  2870. add x14, x2, #0x4c
  2871. ld1 {v7.h}[3], [x20]
  2872. add x3, x2, #0x5e
  2873. ld1 {v4.h}[4], [x12]
  2874. add x9, x2, #0x64
  2875. ld1 {v5.h}[4], [x13]
  2876. add x15, x2, #0x4a
  2877. ld1 {v6.h}[4], [x14]
  2878. add x19, x2, #0x3e
  2879. ld1 {v7.h}[4], [x3]
  2880. add x20, x2, #0x6e
  2881. ld1 {v4.h}[5], [x9]
  2882. add x12, x2, #0x56
  2883. ld1 {v5.h}[5], [x15]
  2884. add x13, x2, #0x58
  2885. ld1 {v6.h}[5], [x19]
  2886. add x14, x2, #0x4e
  2887. ld1 {v7.h}[5], [x20]
  2888. add x3, x2, #0x7c
  2889. ld1 {v4.h}[6], [x12]
  2890. add x9, x2, #0x48
  2891. ld1 {v5.h}[6], [x13]
  2892. add x15, x2, #0x66
  2893. ld1 {v6.h}[6], [x14]
  2894. add x19, x2, #0x5c
  2895. ld1 {v7.h}[6], [x3]
  2896. add x20, x2, #0x7e
  2897. ld1 {v4.h}[7], [x9]
  2898. ld1 {v5.h}[7], [x15]
  2899. ld1 {v6.h}[7], [x19]
  2900. ld1 {v7.h}[7], [x20]
  2901. .endif
  2902. cmlt v24.8h, v0.8h, #0
  2903. cmlt v25.8h, v1.8h, #0
  2904. cmlt v26.8h, v2.8h, #0
  2905. cmlt v27.8h, v3.8h, #0
  2906. cmlt v28.8h, v4.8h, #0
  2907. cmlt v29.8h, v5.8h, #0
  2908. cmlt v30.8h, v6.8h, #0
  2909. cmlt v31.8h, v7.8h, #0
  2910. abs v0.8h, v0.8h
  2911. abs v1.8h, v1.8h
  2912. abs v2.8h, v2.8h
  2913. abs v3.8h, v3.8h
  2914. abs v4.8h, v4.8h
  2915. abs v5.8h, v5.8h
  2916. abs v6.8h, v6.8h
  2917. abs v7.8h, v7.8h
  2918. eor v24.16b, v24.16b, v0.16b
  2919. eor v25.16b, v25.16b, v1.16b
  2920. eor v26.16b, v26.16b, v2.16b
  2921. eor v27.16b, v27.16b, v3.16b
  2922. eor v28.16b, v28.16b, v4.16b
  2923. eor v29.16b, v29.16b, v5.16b
  2924. eor v30.16b, v30.16b, v6.16b
  2925. eor v31.16b, v31.16b, v7.16b
  2926. cmeq v16.8h, v0.8h, #0
  2927. cmeq v17.8h, v1.8h, #0
  2928. cmeq v18.8h, v2.8h, #0
  2929. cmeq v19.8h, v3.8h, #0
  2930. cmeq v20.8h, v4.8h, #0
  2931. cmeq v21.8h, v5.8h, #0
  2932. cmeq v22.8h, v6.8h, #0
  2933. xtn v16.8b, v16.8h
  2934. xtn v18.8b, v18.8h
  2935. xtn v20.8b, v20.8h
  2936. xtn v22.8b, v22.8h
  2937. umov w14, v0.h[0]
  2938. xtn2 v16.16b, v17.8h
  2939. umov w13, v24.h[0]
  2940. xtn2 v18.16b, v19.8h
  2941. clz w14, w14
  2942. xtn2 v20.16b, v21.8h
  2943. lsl w13, w13, w14
  2944. cmeq v17.8h, v7.8h, #0
  2945. sub w12, w14, #32
  2946. xtn2 v22.16b, v17.8h
  2947. lsr w13, w13, w14
  2948. and v16.16b, v16.16b, v23.16b
  2949. neg w12, w12
  2950. and v18.16b, v18.16b, v23.16b
  2951. add x3, x4, #0x400 /* r1 = dctbl->ehufsi */
  2952. and v20.16b, v20.16b, v23.16b
  2953. add x15, sp, #0x90 /* x15 = t2 */
  2954. and v22.16b, v22.16b, v23.16b
  2955. ldr w10, [x4, x12, lsl #2]
  2956. addp v16.16b, v16.16b, v18.16b
  2957. ldrb w11, [x3, x12]
  2958. addp v20.16b, v20.16b, v22.16b
  2959. checkbuf47
  2960. addp v16.16b, v16.16b, v20.16b
  2961. put_bits x10, x11
  2962. addp v16.16b, v16.16b, v18.16b
  2963. checkbuf47
  2964. umov x9,v16.D[0]
  2965. put_bits x13, x12
  2966. cnt v17.8b, v16.8b
  2967. mvn x9, x9
  2968. addv B18, v17.8b
  2969. add x4, x5, #0x400 /* x4 = actbl->ehufsi */
  2970. umov w12, v18.b[0]
  2971. lsr x9, x9, #0x1 /* clear AC coeff */
  2972. ldr w13, [x5, #0x3c0] /* x13 = actbl->ehufco[0xf0] */
  2973. rbit x9, x9 /* x9 = index0 */
  2974. ldrb w14, [x4, #0xf0] /* x14 = actbl->ehufsi[0xf0] */
  2975. cmp w12, #(64-8)
  2976. add x11, sp, #16
  2977. b.lt 4f
  2978. cbz x9, 6f
  2979. st1 {v0.8h, v1.8h, v2.8h, v3.8h}, [x11], #64
  2980. st1 {v4.8h, v5.8h, v6.8h, v7.8h}, [x11], #64
  2981. st1 {v24.8h, v25.8h, v26.8h, v27.8h}, [x11], #64
  2982. st1 {v28.8h, v29.8h, v30.8h, v31.8h}, [x11], #64
  2983. 1:
  2984. clz x2, x9
  2985. add x15, x15, x2, lsl #1
  2986. lsl x9, x9, x2
  2987. ldrh w20, [x15, #-126]
  2988. 2:
  2989. cmp x2, #0x10
  2990. b.lt 3f
  2991. sub x2, x2, #0x10
  2992. checkbuf47
  2993. put_bits x13, x14
  2994. b 2b
  2995. 3:
  2996. clz w20, w20
  2997. ldrh w3, [x15, #2]!
  2998. sub w11, w20, #32
  2999. lsl w3, w3, w20
  3000. neg w11, w11
  3001. lsr w3, w3, w20
  3002. add x2, x11, x2, lsl #4
  3003. lsl x9, x9, #0x1
  3004. ldr w12, [x5, x2, lsl #2]
  3005. ldrb w10, [x4, x2]
  3006. checkbuf31
  3007. put_bits x12, x10
  3008. put_bits x3, x11
  3009. cbnz x9, 1b
  3010. b 6f
  3011. 4:
  3012. movi v21.8h, #0x0010
  3013. clz v0.8h, v0.8h
  3014. clz v1.8h, v1.8h
  3015. clz v2.8h, v2.8h
  3016. clz v3.8h, v3.8h
  3017. clz v4.8h, v4.8h
  3018. clz v5.8h, v5.8h
  3019. clz v6.8h, v6.8h
  3020. clz v7.8h, v7.8h
  3021. ushl v24.8h, v24.8h, v0.8h
  3022. ushl v25.8h, v25.8h, v1.8h
  3023. ushl v26.8h, v26.8h, v2.8h
  3024. ushl v27.8h, v27.8h, v3.8h
  3025. ushl v28.8h, v28.8h, v4.8h
  3026. ushl v29.8h, v29.8h, v5.8h
  3027. ushl v30.8h, v30.8h, v6.8h
  3028. ushl v31.8h, v31.8h, v7.8h
  3029. neg v0.8h, v0.8h
  3030. neg v1.8h, v1.8h
  3031. neg v2.8h, v2.8h
  3032. neg v3.8h, v3.8h
  3033. neg v4.8h, v4.8h
  3034. neg v5.8h, v5.8h
  3035. neg v6.8h, v6.8h
  3036. neg v7.8h, v7.8h
  3037. ushl v24.8h, v24.8h, v0.8h
  3038. ushl v25.8h, v25.8h, v1.8h
  3039. ushl v26.8h, v26.8h, v2.8h
  3040. ushl v27.8h, v27.8h, v3.8h
  3041. ushl v28.8h, v28.8h, v4.8h
  3042. ushl v29.8h, v29.8h, v5.8h
  3043. ushl v30.8h, v30.8h, v6.8h
  3044. ushl v31.8h, v31.8h, v7.8h
  3045. add v0.8h, v21.8h, v0.8h
  3046. add v1.8h, v21.8h, v1.8h
  3047. add v2.8h, v21.8h, v2.8h
  3048. add v3.8h, v21.8h, v3.8h
  3049. add v4.8h, v21.8h, v4.8h
  3050. add v5.8h, v21.8h, v5.8h
  3051. add v6.8h, v21.8h, v6.8h
  3052. add v7.8h, v21.8h, v7.8h
  3053. st1 {v0.8h, v1.8h, v2.8h, v3.8h}, [x11], #64
  3054. st1 {v4.8h, v5.8h, v6.8h, v7.8h}, [x11], #64
  3055. st1 {v24.8h, v25.8h, v26.8h, v27.8h}, [x11], #64
  3056. st1 {v28.8h, v29.8h, v30.8h, v31.8h}, [x11], #64
  3057. 1:
  3058. clz x2, x9
  3059. add x15, x15, x2, lsl #1
  3060. lsl x9, x9, x2
  3061. ldrh w11, [x15, #-126]
  3062. 2:
  3063. cmp x2, #0x10
  3064. b.lt 3f
  3065. sub x2, x2, #0x10
  3066. checkbuf47
  3067. put_bits x13, x14
  3068. b 2b
  3069. 3:
  3070. ldrh w3, [x15, #2]!
  3071. add x2, x11, x2, lsl #4
  3072. lsl x9, x9, #0x1
  3073. ldr w12, [x5, x2, lsl #2]
  3074. ldrb w10, [x4, x2]
  3075. checkbuf31
  3076. put_bits x12, x10
  3077. put_bits x3, x11
  3078. cbnz x9, 1b
  3079. 6:
  3080. add x13, sp, #0x10e
  3081. cmp x15, x13
  3082. b.hs 1f
  3083. ldr w12, [x5]
  3084. ldrb w14, [x4]
  3085. checkbuf47
  3086. put_bits x12, x14
  3087. 1:
  3088. str PUT_BUFFER, [x0, #0x10]
  3089. str PUT_BITSw, [x0, #0x18]
  3090. ldp x19, x20, [sp], 16
  3091. add x0, BUFFER, #0x1
  3092. add sp, sp, 256
  3093. br x30
  3094. .endm
  3095. generate_jsimd_huff_encode_one_block 1
  3096. generate_jsimd_huff_encode_one_block 0
  3097. .unreq BUFFER
  3098. .unreq PUT_BUFFER
  3099. .unreq PUT_BITS
  3100. .unreq PUT_BITSw
  3101. .purgem emit_byte
  3102. .purgem put_bits
  3103. .purgem checkbuf31
  3104. .purgem checkbuf47
  3105. #endif // ESENTHEL CHANGED