jsimd_neon.S 139 KB

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