row_neon64.cc 155 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378
  1. /*
  2. * Copyright 2014 The LibYuv Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "libyuv/row.h"
  11. #ifdef __cplusplus
  12. namespace libyuv {
  13. extern "C" {
  14. #endif
  15. // This module is for GCC Neon armv8 64 bit.
  16. #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
  17. // Read 8 Y, 4 U and 4 V from 422
  18. #define READYUV422 \
  19. "ld1 {v0.8b}, [%0], #8 \n" \
  20. "ld1 {v1.s}[0], [%1], #4 \n" \
  21. "ld1 {v1.s}[1], [%2], #4 \n"
  22. // Read 8 Y, 8 U and 8 V from 444
  23. #define READYUV444 \
  24. "ld1 {v0.8b}, [%0], #8 \n" \
  25. "ld1 {v1.d}[0], [%1], #8 \n" \
  26. "ld1 {v1.d}[1], [%2], #8 \n" \
  27. "uaddlp v1.8h, v1.16b \n" \
  28. "rshrn v1.8b, v1.8h, #1 \n"
  29. // Read 8 Y, and set 4 U and 4 V to 128
  30. #define READYUV400 \
  31. "ld1 {v0.8b}, [%0], #8 \n" \
  32. "movi v1.8b , #128 \n"
  33. // Read 8 Y and 4 UV from NV12
  34. #define READNV12 \
  35. "ld1 {v0.8b}, [%0], #8 \n" \
  36. "ld1 {v2.8b}, [%1], #8 \n" \
  37. "uzp1 v1.8b, v2.8b, v2.8b \n" \
  38. "uzp2 v3.8b, v2.8b, v2.8b \n" \
  39. "ins v1.s[1], v3.s[0] \n"
  40. // Read 8 Y and 4 VU from NV21
  41. #define READNV21 \
  42. "ld1 {v0.8b}, [%0], #8 \n" \
  43. "ld1 {v2.8b}, [%1], #8 \n" \
  44. "uzp1 v3.8b, v2.8b, v2.8b \n" \
  45. "uzp2 v1.8b, v2.8b, v2.8b \n" \
  46. "ins v1.s[1], v3.s[0] \n"
  47. // Read 8 YUY2
  48. #define READYUY2 \
  49. "ld2 {v0.8b, v1.8b}, [%0], #16 \n" \
  50. "uzp2 v3.8b, v1.8b, v1.8b \n" \
  51. "uzp1 v1.8b, v1.8b, v1.8b \n" \
  52. "ins v1.s[1], v3.s[0] \n"
  53. // Read 8 UYVY
  54. #define READUYVY \
  55. "ld2 {v2.8b, v3.8b}, [%0], #16 \n" \
  56. "orr v0.8b, v3.8b, v3.8b \n" \
  57. "uzp1 v1.8b, v2.8b, v2.8b \n" \
  58. "uzp2 v3.8b, v2.8b, v2.8b \n" \
  59. "ins v1.s[1], v3.s[0] \n"
  60. #define YUVTORGB_SETUP \
  61. "ld3r {v24.8h, v25.8h, v26.8h}, [%[kUVBiasBGR]] \n" \
  62. "ld1r {v31.4s}, [%[kYToRgb]] \n" \
  63. "ld2 {v27.8h, v28.8h}, [%[kUVToRB]] \n" \
  64. "ld2 {v29.8h, v30.8h}, [%[kUVToG]] \n"
  65. // clang-format off
  66. #define YUVTORGB(vR, vG, vB) \
  67. "uxtl v0.8h, v0.8b \n" /* Extract Y */ \
  68. "shll v2.8h, v1.8b, #8 \n" /* Replicate UV */ \
  69. "ushll2 v3.4s, v0.8h, #0 \n" /* Y */ \
  70. "ushll v0.4s, v0.4h, #0 \n" \
  71. "mul v3.4s, v3.4s, v31.4s \n" \
  72. "mul v0.4s, v0.4s, v31.4s \n" \
  73. "sqshrun v0.4h, v0.4s, #16 \n" \
  74. "sqshrun2 v0.8h, v3.4s, #16 \n" /* Y */ \
  75. "uaddw v1.8h, v2.8h, v1.8b \n" /* Replicate UV */ \
  76. "mov v2.d[0], v1.d[1] \n" /* Extract V */ \
  77. "uxtl v2.8h, v2.8b \n" \
  78. "uxtl v1.8h, v1.8b \n" /* Extract U */ \
  79. "mul v3.8h, v27.8h, v1.8h \n" \
  80. "mul v5.8h, v29.8h, v1.8h \n" \
  81. "mul v6.8h, v30.8h, v2.8h \n" \
  82. "mul v7.8h, v28.8h, v2.8h \n" \
  83. "sqadd v6.8h, v6.8h, v5.8h \n" \
  84. "sqadd " #vB ".8h, v24.8h, v0.8h \n" /* B */ \
  85. "sqadd " #vG ".8h, v25.8h, v0.8h \n" /* G */ \
  86. "sqadd " #vR ".8h, v26.8h, v0.8h \n" /* R */ \
  87. "sqadd " #vB ".8h, " #vB ".8h, v3.8h \n" /* B */ \
  88. "sqsub " #vG ".8h, " #vG ".8h, v6.8h \n" /* G */ \
  89. "sqadd " #vR ".8h, " #vR ".8h, v7.8h \n" /* R */ \
  90. "sqshrun " #vB ".8b, " #vB ".8h, #6 \n" /* B */ \
  91. "sqshrun " #vG ".8b, " #vG ".8h, #6 \n" /* G */ \
  92. "sqshrun " #vR ".8b, " #vR ".8h, #6 \n" /* R */
  93. // clang-format on
  94. void I444ToARGBRow_NEON(const uint8_t* src_y,
  95. const uint8_t* src_u,
  96. const uint8_t* src_v,
  97. uint8_t* dst_argb,
  98. const struct YuvConstants* yuvconstants,
  99. int width) {
  100. asm volatile (
  101. YUVTORGB_SETUP
  102. "movi v23.8b, #255 \n" /* A */
  103. "1: \n"
  104. READYUV444
  105. "prfm pldl1keep, [%0, 448] \n"
  106. YUVTORGB(v22, v21, v20)
  107. "prfm pldl1keep, [%1, 448] \n"
  108. "prfm pldl1keep, [%2, 448] \n"
  109. "subs %w4, %w4, #8 \n"
  110. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%3], #32 \n"
  111. "b.gt 1b \n"
  112. : "+r"(src_y), // %0
  113. "+r"(src_u), // %1
  114. "+r"(src_v), // %2
  115. "+r"(dst_argb), // %3
  116. "+r"(width) // %4
  117. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  118. [kUVToG]"r"(&yuvconstants->kUVToG),
  119. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  120. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  121. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  122. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  123. );
  124. }
  125. void I422ToARGBRow_NEON(const uint8_t* src_y,
  126. const uint8_t* src_u,
  127. const uint8_t* src_v,
  128. uint8_t* dst_argb,
  129. const struct YuvConstants* yuvconstants,
  130. int width) {
  131. asm volatile (
  132. YUVTORGB_SETUP
  133. "movi v23.8b, #255 \n" /* A */
  134. "1: \n"
  135. READYUV422
  136. "prfm pldl1keep, [%0, 448] \n"
  137. YUVTORGB(v22, v21, v20)
  138. "prfm pldl1keep, [%1, 128] \n"
  139. "prfm pldl1keep, [%2, 128] \n"
  140. "subs %w4, %w4, #8 \n"
  141. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%3], #32 \n"
  142. "b.gt 1b \n"
  143. : "+r"(src_y), // %0
  144. "+r"(src_u), // %1
  145. "+r"(src_v), // %2
  146. "+r"(dst_argb), // %3
  147. "+r"(width) // %4
  148. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  149. [kUVToG]"r"(&yuvconstants->kUVToG),
  150. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  151. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  152. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  153. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  154. );
  155. }
  156. void I422AlphaToARGBRow_NEON(const uint8_t* src_y,
  157. const uint8_t* src_u,
  158. const uint8_t* src_v,
  159. const uint8_t* src_a,
  160. uint8_t* dst_argb,
  161. const struct YuvConstants* yuvconstants,
  162. int width) {
  163. asm volatile (
  164. YUVTORGB_SETUP
  165. "1: \n"
  166. READYUV422
  167. "prfm pldl1keep, [%0, 448] \n"
  168. YUVTORGB(v22, v21, v20)
  169. "ld1 {v23.8b}, [%3], #8 \n"
  170. "prfm pldl1keep, [%1, 128] \n"
  171. "prfm pldl1keep, [%2, 128] \n"
  172. "prfm pldl1keep, [%3, 448] \n"
  173. "subs %w5, %w5, #8 \n"
  174. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%4], #32 \n"
  175. "b.gt 1b \n"
  176. : "+r"(src_y), // %0
  177. "+r"(src_u), // %1
  178. "+r"(src_v), // %2
  179. "+r"(src_a), // %3
  180. "+r"(dst_argb), // %4
  181. "+r"(width) // %5
  182. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  183. [kUVToG]"r"(&yuvconstants->kUVToG),
  184. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  185. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  186. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  187. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  188. );
  189. }
  190. void I422ToRGBARow_NEON(const uint8_t* src_y,
  191. const uint8_t* src_u,
  192. const uint8_t* src_v,
  193. uint8_t* dst_rgba,
  194. const struct YuvConstants* yuvconstants,
  195. int width) {
  196. asm volatile (
  197. YUVTORGB_SETUP
  198. "movi v20.8b, #255 \n" /* A */
  199. "1: \n"
  200. READYUV422
  201. "prfm pldl1keep, [%0, 448] \n"
  202. YUVTORGB(v23, v22, v21)
  203. "prfm pldl1keep, [%1, 128] \n"
  204. "prfm pldl1keep, [%2, 128] \n"
  205. "subs %w4, %w4, #8 \n"
  206. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%3], #32 \n"
  207. "b.gt 1b \n"
  208. : "+r"(src_y), // %0
  209. "+r"(src_u), // %1
  210. "+r"(src_v), // %2
  211. "+r"(dst_rgba), // %3
  212. "+r"(width) // %4
  213. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  214. [kUVToG]"r"(&yuvconstants->kUVToG),
  215. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  216. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  217. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  218. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  219. );
  220. }
  221. void I422ToRGB24Row_NEON(const uint8_t* src_y,
  222. const uint8_t* src_u,
  223. const uint8_t* src_v,
  224. uint8_t* dst_rgb24,
  225. const struct YuvConstants* yuvconstants,
  226. int width) {
  227. asm volatile (
  228. YUVTORGB_SETUP
  229. "1: \n"
  230. READYUV422
  231. "prfm pldl1keep, [%0, 448] \n"
  232. YUVTORGB(v22, v21, v20)
  233. "prfm pldl1keep, [%1, 128] \n"
  234. "prfm pldl1keep, [%2, 128] \n"
  235. "subs %w4, %w4, #8 \n"
  236. "st3 {v20.8b,v21.8b,v22.8b}, [%3], #24 \n"
  237. "b.gt 1b \n"
  238. : "+r"(src_y), // %0
  239. "+r"(src_u), // %1
  240. "+r"(src_v), // %2
  241. "+r"(dst_rgb24), // %3
  242. "+r"(width) // %4
  243. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  244. [kUVToG]"r"(&yuvconstants->kUVToG),
  245. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  246. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  247. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  248. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  249. );
  250. }
  251. #define ARGBTORGB565 \
  252. "shll v0.8h, v22.8b, #8 \n" /* R */ \
  253. "shll v21.8h, v21.8b, #8 \n" /* G */ \
  254. "shll v20.8h, v20.8b, #8 \n" /* B */ \
  255. "sri v0.8h, v21.8h, #5 \n" /* RG */ \
  256. "sri v0.8h, v20.8h, #11 \n" /* RGB */
  257. // clang-format off
  258. void I422ToRGB565Row_NEON(const uint8_t* src_y,
  259. const uint8_t* src_u,
  260. const uint8_t* src_v,
  261. uint8_t* dst_rgb565,
  262. const struct YuvConstants* yuvconstants,
  263. int width) {
  264. asm volatile(
  265. YUVTORGB_SETUP
  266. "1: \n"
  267. READYUV422
  268. YUVTORGB(v22, v21, v20)
  269. "prfm pldl1keep, [%0, 448] \n"
  270. "subs %w4, %w4, #8 \n"
  271. ARGBTORGB565
  272. "prfm pldl1keep, [%1, 128] \n"
  273. "prfm pldl1keep, [%2, 128] \n"
  274. "st1 {v0.8h}, [%3], #16 \n" // store 8 pixels RGB565.
  275. "b.gt 1b \n"
  276. : "+r"(src_y), // %0
  277. "+r"(src_u), // %1
  278. "+r"(src_v), // %2
  279. "+r"(dst_rgb565), // %3
  280. "+r"(width) // %4
  281. : [kUVToRB] "r"(&yuvconstants->kUVToRB),
  282. [kUVToG] "r"(&yuvconstants->kUVToG),
  283. [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR),
  284. [kYToRgb] "r"(&yuvconstants->kYToRgb)
  285. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  286. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30");
  287. }
  288. #define ARGBTOARGB1555 \
  289. "shll v0.8h, v23.8b, #8 \n" /* A */ \
  290. "shll v22.8h, v22.8b, #8 \n" /* R */ \
  291. "shll v21.8h, v21.8b, #8 \n" /* G */ \
  292. "shll v20.8h, v20.8b, #8 \n" /* B */ \
  293. "sri v0.8h, v22.8h, #1 \n" /* AR */ \
  294. "sri v0.8h, v21.8h, #6 \n" /* ARG */ \
  295. "sri v0.8h, v20.8h, #11 \n" /* ARGB */
  296. void I422ToARGB1555Row_NEON(const uint8_t* src_y,
  297. const uint8_t* src_u,
  298. const uint8_t* src_v,
  299. uint8_t* dst_argb1555,
  300. const struct YuvConstants* yuvconstants,
  301. int width) {
  302. asm volatile(
  303. YUVTORGB_SETUP
  304. "movi v23.8b, #255 \n"
  305. "1: \n"
  306. READYUV422
  307. YUVTORGB(v22, v21, v20)
  308. "prfm pldl1keep, [%0, 448] \n"
  309. "subs %w4, %w4, #8 \n"
  310. ARGBTOARGB1555
  311. "prfm pldl1keep, [%1, 128] \n"
  312. "prfm pldl1keep, [%2, 128] \n"
  313. "st1 {v0.8h}, [%3], #16 \n" // store 8 pixels RGB565.
  314. "b.gt 1b \n"
  315. : "+r"(src_y), // %0
  316. "+r"(src_u), // %1
  317. "+r"(src_v), // %2
  318. "+r"(dst_argb1555), // %3
  319. "+r"(width) // %4
  320. : [kUVToRB] "r"(&yuvconstants->kUVToRB),
  321. [kUVToG] "r"(&yuvconstants->kUVToG),
  322. [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR),
  323. [kYToRgb] "r"(&yuvconstants->kYToRgb)
  324. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  325. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30");
  326. }
  327. // clang-format on
  328. #define ARGBTOARGB4444 \
  329. /* Input v20.8b<=B, v21.8b<=G, v22.8b<=R, v23.8b<=A, v4.8b<=0x0f */ \
  330. "ushr v20.8b, v20.8b, #4 \n" /* B */ \
  331. "bic v21.8b, v21.8b, v4.8b \n" /* G */ \
  332. "ushr v22.8b, v22.8b, #4 \n" /* R */ \
  333. "bic v23.8b, v23.8b, v4.8b \n" /* A */ \
  334. "orr v0.8b, v20.8b, v21.8b \n" /* BG */ \
  335. "orr v1.8b, v22.8b, v23.8b \n" /* RA */ \
  336. "zip1 v0.16b, v0.16b, v1.16b \n" /* BGRA */
  337. void I422ToARGB4444Row_NEON(const uint8_t* src_y,
  338. const uint8_t* src_u,
  339. const uint8_t* src_v,
  340. uint8_t* dst_argb4444,
  341. const struct YuvConstants* yuvconstants,
  342. int width) {
  343. asm volatile (
  344. YUVTORGB_SETUP
  345. "movi v4.16b, #0x0f \n" // bits to clear with vbic.
  346. "1: \n"
  347. READYUV422
  348. YUVTORGB(v22, v21, v20)
  349. "prfm pldl1keep, [%0, 448] \n"
  350. "subs %w4, %w4, #8 \n"
  351. "movi v23.8b, #255 \n"
  352. ARGBTOARGB4444
  353. "prfm pldl1keep, [%1, 128] \n"
  354. "prfm pldl1keep, [%2, 128] \n"
  355. "st1 {v0.8h}, [%3], #16 \n" // store 8 pixels ARGB4444.
  356. "b.gt 1b \n"
  357. : "+r"(src_y), // %0
  358. "+r"(src_u), // %1
  359. "+r"(src_v), // %2
  360. "+r"(dst_argb4444), // %3
  361. "+r"(width) // %4
  362. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  363. [kUVToG]"r"(&yuvconstants->kUVToG),
  364. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  365. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  366. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  367. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  368. );
  369. }
  370. void I400ToARGBRow_NEON(const uint8_t* src_y,
  371. uint8_t* dst_argb,
  372. const struct YuvConstants* yuvconstants,
  373. int width) {
  374. asm volatile (
  375. YUVTORGB_SETUP
  376. "movi v23.8b, #255 \n"
  377. "1: \n"
  378. READYUV400
  379. YUVTORGB(v22, v21, v20)
  380. "prfm pldl1keep, [%0, 448] \n"
  381. "subs %w2, %w2, #8 \n"
  382. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n"
  383. "b.gt 1b \n"
  384. : "+r"(src_y), // %0
  385. "+r"(dst_argb), // %1
  386. "+r"(width) // %2
  387. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  388. [kUVToG]"r"(&yuvconstants->kUVToG),
  389. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  390. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  391. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  392. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  393. );
  394. }
  395. void J400ToARGBRow_NEON(const uint8_t* src_y, uint8_t* dst_argb, int width) {
  396. asm volatile(
  397. "movi v23.8b, #255 \n"
  398. "1: \n"
  399. "ld1 {v20.8b}, [%0], #8 \n"
  400. "prfm pldl1keep, [%0, 448] \n"
  401. "orr v21.8b, v20.8b, v20.8b \n"
  402. "orr v22.8b, v20.8b, v20.8b \n"
  403. "subs %w2, %w2, #8 \n"
  404. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n"
  405. "b.gt 1b \n"
  406. : "+r"(src_y), // %0
  407. "+r"(dst_argb), // %1
  408. "+r"(width) // %2
  409. :
  410. : "cc", "memory", "v20", "v21", "v22", "v23");
  411. }
  412. void NV12ToARGBRow_NEON(const uint8_t* src_y,
  413. const uint8_t* src_uv,
  414. uint8_t* dst_argb,
  415. const struct YuvConstants* yuvconstants,
  416. int width) {
  417. asm volatile (
  418. YUVTORGB_SETUP
  419. "movi v23.8b, #255 \n"
  420. "1: \n"
  421. READNV12
  422. "prfm pldl1keep, [%0, 448] \n"
  423. YUVTORGB(v22, v21, v20)
  424. "prfm pldl1keep, [%1, 256] \n"
  425. "subs %w3, %w3, #8 \n"
  426. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%2], #32 \n"
  427. "b.gt 1b \n"
  428. : "+r"(src_y), // %0
  429. "+r"(src_uv), // %1
  430. "+r"(dst_argb), // %2
  431. "+r"(width) // %3
  432. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  433. [kUVToG]"r"(&yuvconstants->kUVToG),
  434. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  435. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  436. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  437. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  438. );
  439. }
  440. void NV21ToARGBRow_NEON(const uint8_t* src_y,
  441. const uint8_t* src_vu,
  442. uint8_t* dst_argb,
  443. const struct YuvConstants* yuvconstants,
  444. int width) {
  445. asm volatile (
  446. YUVTORGB_SETUP
  447. "movi v23.8b, #255 \n"
  448. "1: \n"
  449. READNV21
  450. "prfm pldl1keep, [%0, 448] \n"
  451. YUVTORGB(v22, v21, v20)
  452. "prfm pldl1keep, [%1, 256] \n"
  453. "subs %w3, %w3, #8 \n"
  454. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%2], #32 \n"
  455. "b.gt 1b \n"
  456. : "+r"(src_y), // %0
  457. "+r"(src_vu), // %1
  458. "+r"(dst_argb), // %2
  459. "+r"(width) // %3
  460. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  461. [kUVToG]"r"(&yuvconstants->kUVToG),
  462. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  463. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  464. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  465. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  466. );
  467. }
  468. void NV12ToRGB24Row_NEON(const uint8_t* src_y,
  469. const uint8_t* src_uv,
  470. uint8_t* dst_rgb24,
  471. const struct YuvConstants* yuvconstants,
  472. int width) {
  473. asm volatile (
  474. YUVTORGB_SETUP
  475. "1: \n"
  476. READNV12
  477. "prfm pldl1keep, [%0, 448] \n"
  478. YUVTORGB(v22, v21, v20)
  479. "prfm pldl1keep, [%1, 256] \n"
  480. "subs %w3, %w3, #8 \n"
  481. "st3 {v20.8b,v21.8b,v22.8b}, [%2], #24 \n"
  482. "b.gt 1b \n"
  483. : "+r"(src_y), // %0
  484. "+r"(src_uv), // %1
  485. "+r"(dst_rgb24), // %2
  486. "+r"(width) // %3
  487. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  488. [kUVToG]"r"(&yuvconstants->kUVToG),
  489. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  490. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  491. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  492. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  493. );
  494. }
  495. void NV21ToRGB24Row_NEON(const uint8_t* src_y,
  496. const uint8_t* src_vu,
  497. uint8_t* dst_rgb24,
  498. const struct YuvConstants* yuvconstants,
  499. int width) {
  500. asm volatile (
  501. YUVTORGB_SETUP
  502. "1: \n"
  503. READNV21
  504. "prfm pldl1keep, [%0, 448] \n"
  505. YUVTORGB(v22, v21, v20)
  506. "prfm pldl1keep, [%1, 256] \n"
  507. "subs %w3, %w3, #8 \n"
  508. "st3 {v20.8b,v21.8b,v22.8b}, [%2], #24 \n"
  509. "b.gt 1b \n"
  510. : "+r"(src_y), // %0
  511. "+r"(src_vu), // %1
  512. "+r"(dst_rgb24), // %2
  513. "+r"(width) // %3
  514. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  515. [kUVToG]"r"(&yuvconstants->kUVToG),
  516. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  517. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  518. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  519. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  520. );
  521. }
  522. void NV12ToRGB565Row_NEON(const uint8_t* src_y,
  523. const uint8_t* src_uv,
  524. uint8_t* dst_rgb565,
  525. const struct YuvConstants* yuvconstants,
  526. int width) {
  527. asm volatile(
  528. YUVTORGB_SETUP "1: \n" READNV12
  529. "prfm pldl1keep, [%0, 448] \n" YUVTORGB(
  530. v22, v21, v20) ARGBTORGB565
  531. "prfm pldl1keep, [%1, 256] \n"
  532. "subs %w3, %w3, #8 \n"
  533. "st1 {v0.8h}, [%2], 16 \n" // store 8 pixels
  534. "b.gt 1b \n"
  535. : "+r"(src_y), // %0
  536. "+r"(src_uv), // %1
  537. "+r"(dst_rgb565), // %2
  538. "+r"(width) // %3
  539. : [kUVToRB] "r"(&yuvconstants->kUVToRB),
  540. [kUVToG] "r"(&yuvconstants->kUVToG),
  541. [kUVBiasBGR] "r"(&yuvconstants->kUVBiasBGR),
  542. [kYToRgb] "r"(&yuvconstants->kYToRgb)
  543. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  544. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30");
  545. }
  546. void YUY2ToARGBRow_NEON(const uint8_t* src_yuy2,
  547. uint8_t* dst_argb,
  548. const struct YuvConstants* yuvconstants,
  549. int width) {
  550. asm volatile (
  551. YUVTORGB_SETUP
  552. "movi v23.8b, #255 \n"
  553. "1: \n"
  554. READYUY2
  555. "prfm pldl1keep, [%0, 448] \n"
  556. YUVTORGB(v22, v21, v20)
  557. "subs %w2, %w2, #8 \n"
  558. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n"
  559. "b.gt 1b \n"
  560. : "+r"(src_yuy2), // %0
  561. "+r"(dst_argb), // %1
  562. "+r"(width) // %2
  563. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  564. [kUVToG]"r"(&yuvconstants->kUVToG),
  565. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  566. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  567. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  568. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  569. );
  570. }
  571. void UYVYToARGBRow_NEON(const uint8_t* src_uyvy,
  572. uint8_t* dst_argb,
  573. const struct YuvConstants* yuvconstants,
  574. int width) {
  575. asm volatile (
  576. YUVTORGB_SETUP
  577. "movi v23.8b, #255 \n"
  578. "1: \n"
  579. READUYVY
  580. YUVTORGB(v22, v21, v20)
  581. "prfm pldl1keep, [%0, 448] \n"
  582. "subs %w2, %w2, #8 \n"
  583. "st4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], 32 \n"
  584. "b.gt 1b \n"
  585. : "+r"(src_uyvy), // %0
  586. "+r"(dst_argb), // %1
  587. "+r"(width) // %2
  588. : [kUVToRB]"r"(&yuvconstants->kUVToRB),
  589. [kUVToG]"r"(&yuvconstants->kUVToG),
  590. [kUVBiasBGR]"r"(&yuvconstants->kUVBiasBGR),
  591. [kYToRgb]"r"(&yuvconstants->kYToRgb)
  592. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  593. "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30"
  594. );
  595. }
  596. // Reads 16 pairs of UV and write even values to dst_u and odd to dst_v.
  597. void SplitUVRow_NEON(const uint8_t* src_uv,
  598. uint8_t* dst_u,
  599. uint8_t* dst_v,
  600. int width) {
  601. asm volatile(
  602. "1: \n"
  603. "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pairs of UV
  604. "prfm pldl1keep, [%0, 448] \n"
  605. "subs %w3, %w3, #16 \n" // 16 processed per loop
  606. "st1 {v0.16b}, [%1], #16 \n" // store U
  607. "st1 {v1.16b}, [%2], #16 \n" // store V
  608. "b.gt 1b \n"
  609. : "+r"(src_uv), // %0
  610. "+r"(dst_u), // %1
  611. "+r"(dst_v), // %2
  612. "+r"(width) // %3 // Output registers
  613. : // Input registers
  614. : "cc", "memory", "v0", "v1" // Clobber List
  615. );
  616. }
  617. // Reads 16 U's and V's and writes out 16 pairs of UV.
  618. void MergeUVRow_NEON(const uint8_t* src_u,
  619. const uint8_t* src_v,
  620. uint8_t* dst_uv,
  621. int width) {
  622. asm volatile(
  623. "1: \n"
  624. "ld1 {v0.16b}, [%0], #16 \n" // load U
  625. "ld1 {v1.16b}, [%1], #16 \n" // load V
  626. "prfm pldl1keep, [%0, 448] \n"
  627. "prfm pldl1keep, [%1, 448] \n"
  628. "subs %w3, %w3, #16 \n" // 16 processed per loop
  629. "st2 {v0.16b,v1.16b}, [%2], #32 \n" // store 16 pairs of UV
  630. "b.gt 1b \n"
  631. : "+r"(src_u), // %0
  632. "+r"(src_v), // %1
  633. "+r"(dst_uv), // %2
  634. "+r"(width) // %3 // Output registers
  635. : // Input registers
  636. : "cc", "memory", "v0", "v1" // Clobber List
  637. );
  638. }
  639. // Reads 16 packed RGB and write to planar dst_r, dst_g, dst_b.
  640. void SplitRGBRow_NEON(const uint8_t* src_rgb,
  641. uint8_t* dst_r,
  642. uint8_t* dst_g,
  643. uint8_t* dst_b,
  644. int width) {
  645. asm volatile(
  646. "1: \n"
  647. "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 16 RGB
  648. "prfm pldl1keep, [%0, 448] \n"
  649. "subs %w4, %w4, #16 \n" // 16 processed per loop
  650. "st1 {v0.16b}, [%1], #16 \n" // store R
  651. "st1 {v1.16b}, [%2], #16 \n" // store G
  652. "st1 {v2.16b}, [%3], #16 \n" // store B
  653. "b.gt 1b \n"
  654. : "+r"(src_rgb), // %0
  655. "+r"(dst_r), // %1
  656. "+r"(dst_g), // %2
  657. "+r"(dst_b), // %3
  658. "+r"(width) // %4
  659. : // Input registers
  660. : "cc", "memory", "v0", "v1", "v2" // Clobber List
  661. );
  662. }
  663. // Reads 16 planar R's, G's and B's and writes out 16 packed RGB at a time
  664. void MergeRGBRow_NEON(const uint8_t* src_r,
  665. const uint8_t* src_g,
  666. const uint8_t* src_b,
  667. uint8_t* dst_rgb,
  668. int width) {
  669. asm volatile(
  670. "1: \n"
  671. "ld1 {v0.16b}, [%0], #16 \n" // load R
  672. "ld1 {v1.16b}, [%1], #16 \n" // load G
  673. "ld1 {v2.16b}, [%2], #16 \n" // load B
  674. "prfm pldl1keep, [%0, 448] \n"
  675. "prfm pldl1keep, [%1, 448] \n"
  676. "prfm pldl1keep, [%2, 448] \n"
  677. "subs %w4, %w4, #16 \n" // 16 processed per loop
  678. "st3 {v0.16b,v1.16b,v2.16b}, [%3], #48 \n" // store 16 RGB
  679. "prfm pldl1keep, [%0, 448] \n"
  680. "b.gt 1b \n"
  681. : "+r"(src_r), // %0
  682. "+r"(src_g), // %1
  683. "+r"(src_b), // %2
  684. "+r"(dst_rgb), // %3
  685. "+r"(width) // %4
  686. : // Input registers
  687. : "cc", "memory", "v0", "v1", "v2" // Clobber List
  688. );
  689. }
  690. // Copy multiple of 32.
  691. void CopyRow_NEON(const uint8_t* src, uint8_t* dst, int width) {
  692. asm volatile(
  693. "1: \n"
  694. "ldp q0, q1, [%0], #32 \n"
  695. "prfm pldl1keep, [%0, 448] \n"
  696. "subs %w2, %w2, #32 \n" // 32 processed per loop
  697. "stp q0, q1, [%1], #32 \n"
  698. "b.gt 1b \n"
  699. : "+r"(src), // %0
  700. "+r"(dst), // %1
  701. "+r"(width) // %2 // Output registers
  702. : // Input registers
  703. : "cc", "memory", "v0", "v1" // Clobber List
  704. );
  705. }
  706. // SetRow writes 'width' bytes using an 8 bit value repeated.
  707. void SetRow_NEON(uint8_t* dst, uint8_t v8, int width) {
  708. asm volatile(
  709. "dup v0.16b, %w2 \n" // duplicate 16 bytes
  710. "1: \n"
  711. "subs %w1, %w1, #16 \n" // 16 bytes per loop
  712. "st1 {v0.16b}, [%0], #16 \n" // store
  713. "b.gt 1b \n"
  714. : "+r"(dst), // %0
  715. "+r"(width) // %1
  716. : "r"(v8) // %2
  717. : "cc", "memory", "v0");
  718. }
  719. void ARGBSetRow_NEON(uint8_t* dst, uint32_t v32, int width) {
  720. asm volatile(
  721. "dup v0.4s, %w2 \n" // duplicate 4 ints
  722. "1: \n"
  723. "subs %w1, %w1, #4 \n" // 4 ints per loop
  724. "st1 {v0.16b}, [%0], #16 \n" // store
  725. "b.gt 1b \n"
  726. : "+r"(dst), // %0
  727. "+r"(width) // %1
  728. : "r"(v32) // %2
  729. : "cc", "memory", "v0");
  730. }
  731. // Shuffle table for reversing the bytes.
  732. static const uvec8 kShuffleMirror = {15u, 14u, 13u, 12u, 11u, 10u, 9u, 8u,
  733. 7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
  734. void MirrorRow_NEON(const uint8_t* src, uint8_t* dst, int width) {
  735. asm volatile(
  736. // Start at end of source row.
  737. "ld1 {v3.16b}, [%3] \n" // shuffler
  738. "add %0, %0, %w2, sxtw \n"
  739. "sub %0, %0, #32 \n"
  740. "1: \n"
  741. "ldr q2, [%0, 16] \n"
  742. "ldr q1, [%0], -32 \n" // src -= 32
  743. "subs %w2, %w2, #32 \n" // 32 pixels per loop.
  744. "tbl v0.16b, {v2.16b}, v3.16b \n"
  745. "tbl v1.16b, {v1.16b}, v3.16b \n"
  746. "st1 {v0.16b, v1.16b}, [%1], #32 \n" // store 32 pixels
  747. "b.gt 1b \n"
  748. : "+r"(src), // %0
  749. "+r"(dst), // %1
  750. "+r"(width) // %2
  751. : "r"(&kShuffleMirror) // %3
  752. : "cc", "memory", "v0", "v1", "v2", "v3");
  753. }
  754. // Shuffle table for reversing the UV.
  755. static const uvec8 kShuffleMirrorUV = {14u, 15u, 12u, 13u, 10u, 11u, 8u, 9u,
  756. 6u, 7u, 4u, 5u, 2u, 3u, 0u, 1u};
  757. void MirrorUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_uv, int width) {
  758. asm volatile(
  759. // Start at end of source row.
  760. "ld1 {v4.16b}, [%3] \n" // shuffler
  761. "add %0, %0, %w2, sxtw #1 \n"
  762. "sub %0, %0, #32 \n"
  763. "1: \n"
  764. "ldr q1, [%0, 16] \n"
  765. "ldr q0, [%0], -32 \n" // src -= 32
  766. "subs %w2, %w2, #16 \n" // 16 pixels per loop.
  767. "tbl v2.16b, {v1.16b}, v4.16b \n"
  768. "tbl v3.16b, {v0.16b}, v4.16b \n"
  769. "st1 {v2.16b, v3.16b}, [%1], #32 \n" // dst += 32
  770. "b.gt 1b \n"
  771. : "+r"(src_uv), // %0
  772. "+r"(dst_uv), // %1
  773. "+r"(width) // %2
  774. : "r"(&kShuffleMirrorUV) // %3
  775. : "cc", "memory", "v0", "v1", "v2", "v3", "v4");
  776. }
  777. void MirrorSplitUVRow_NEON(const uint8_t* src_uv,
  778. uint8_t* dst_u,
  779. uint8_t* dst_v,
  780. int width) {
  781. asm volatile(
  782. // Start at end of source row.
  783. "ld1 {v4.16b}, [%4] \n" // shuffler
  784. "add %0, %0, %w3, sxtw #1 \n"
  785. "sub %0, %0, #32 \n"
  786. "1: \n"
  787. "ldr q1, [%0, 16] \n"
  788. "ldr q0, [%0], -32 \n" // src -= 32
  789. "subs %w3, %w3, #16 \n" // 16 pixels per loop.
  790. "tbl v2.16b, {v1.16b}, v4.16b \n"
  791. "tbl v3.16b, {v0.16b}, v4.16b \n"
  792. "uzp1 v0.16b, v2.16b, v3.16b \n" // U
  793. "uzp2 v1.16b, v2.16b, v3.16b \n" // V
  794. "st1 {v0.16b}, [%1], #16 \n" // dst += 16
  795. "st1 {v1.16b}, [%2], #16 \n"
  796. "b.gt 1b \n"
  797. : "+r"(src_uv), // %0
  798. "+r"(dst_u), // %1
  799. "+r"(dst_v), // %2
  800. "+r"(width) // %3
  801. : "r"(&kShuffleMirrorUV) // %4
  802. : "cc", "memory", "v0", "v1", "v2", "v3", "v4");
  803. }
  804. // Shuffle table for reversing the ARGB.
  805. static const uvec8 kShuffleMirrorARGB = {12u, 13u, 14u, 15u, 8u, 9u, 10u, 11u,
  806. 4u, 5u, 6u, 7u, 0u, 1u, 2u, 3u};
  807. void ARGBMirrorRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) {
  808. asm volatile(
  809. // Start at end of source row.
  810. "ld1 {v4.16b}, [%3] \n" // shuffler
  811. "add %0, %0, %w2, sxtw #2 \n"
  812. "sub %0, %0, #32 \n"
  813. "1: \n"
  814. "ldr q1, [%0, 16] \n"
  815. "ldr q0, [%0], -32 \n" // src -= 32
  816. "subs %w2, %w2, #8 \n" // 8 pixels per loop.
  817. "tbl v2.16b, {v1.16b}, v4.16b \n"
  818. "tbl v3.16b, {v0.16b}, v4.16b \n"
  819. "st1 {v2.16b, v3.16b}, [%1], #32 \n" // dst += 32
  820. "b.gt 1b \n"
  821. : "+r"(src_argb), // %0
  822. "+r"(dst_argb), // %1
  823. "+r"(width) // %2
  824. : "r"(&kShuffleMirrorARGB) // %3
  825. : "cc", "memory", "v0", "v1", "v2", "v3", "v4");
  826. }
  827. void RGB24MirrorRow_NEON(const uint8_t* src_rgb24,
  828. uint8_t* dst_rgb24,
  829. int width) {
  830. asm volatile(
  831. "ld1 {v3.16b}, [%4] \n" // shuffler
  832. "add %0, %0, %w2, sxtw #1 \n" // Start at end of row.
  833. "add %0, %0, %w2, sxtw \n"
  834. "sub %0, %0, #48 \n"
  835. "1: \n"
  836. "ld3 {v0.16b, v1.16b, v2.16b}, [%0], %3\n" // src -= 48
  837. "subs %w2, %w2, #16 \n" // 16 pixels per loop.
  838. "tbl v0.16b, {v0.16b}, v3.16b \n"
  839. "tbl v1.16b, {v1.16b}, v3.16b \n"
  840. "tbl v2.16b, {v2.16b}, v3.16b \n"
  841. "st3 {v0.16b, v1.16b, v2.16b}, [%1], #48 \n" // dst += 48
  842. "b.gt 1b \n"
  843. : "+r"(src_rgb24), // %0
  844. "+r"(dst_rgb24), // %1
  845. "+r"(width) // %2
  846. : "r"((ptrdiff_t)-48), // %3
  847. "r"(&kShuffleMirror) // %4
  848. : "cc", "memory", "v0", "v1", "v2", "v3");
  849. }
  850. void RGB24ToARGBRow_NEON(const uint8_t* src_rgb24,
  851. uint8_t* dst_argb,
  852. int width) {
  853. asm volatile(
  854. "movi v4.8b, #255 \n" // Alpha
  855. "1: \n"
  856. "ld3 {v1.8b,v2.8b,v3.8b}, [%0], #24 \n" // load 8 pixels of RGB24.
  857. "prfm pldl1keep, [%0, 448] \n"
  858. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  859. "st4 {v1.8b,v2.8b,v3.8b,v4.8b}, [%1], #32 \n" // store 8 ARGB
  860. "b.gt 1b \n"
  861. : "+r"(src_rgb24), // %0
  862. "+r"(dst_argb), // %1
  863. "+r"(width) // %2
  864. :
  865. : "cc", "memory", "v1", "v2", "v3", "v4" // Clobber List
  866. );
  867. }
  868. void RAWToARGBRow_NEON(const uint8_t* src_raw, uint8_t* dst_argb, int width) {
  869. asm volatile(
  870. "movi v5.8b, #255 \n" // Alpha
  871. "1: \n"
  872. "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // read r g b
  873. "prfm pldl1keep, [%0, 448] \n"
  874. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  875. "orr v3.8b, v1.8b, v1.8b \n" // move g
  876. "orr v4.8b, v0.8b, v0.8b \n" // move r
  877. "st4 {v2.8b,v3.8b,v4.8b,v5.8b}, [%1], #32 \n" // store b g r a
  878. "b.gt 1b \n"
  879. : "+r"(src_raw), // %0
  880. "+r"(dst_argb), // %1
  881. "+r"(width) // %2
  882. :
  883. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5" // Clobber List
  884. );
  885. }
  886. void RAWToRGBARow_NEON(const uint8_t* src_raw, uint8_t* dst_rgba, int width) {
  887. asm volatile(
  888. "movi v0.8b, #255 \n" // Alpha
  889. "1: \n"
  890. "ld3 {v3.8b,v4.8b,v5.8b}, [%0], #24 \n" // read r g b
  891. "prfm pldl1keep, [%0, 448] \n"
  892. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  893. "orr v2.8b, v4.8b, v4.8b \n" // move g
  894. "orr v1.8b, v5.8b, v5.8b \n" // move r
  895. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store a b g r
  896. "b.gt 1b \n"
  897. : "+r"(src_raw), // %0
  898. "+r"(dst_rgba), // %1
  899. "+r"(width) // %2
  900. :
  901. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5" // Clobber List
  902. );
  903. }
  904. void RAWToRGB24Row_NEON(const uint8_t* src_raw, uint8_t* dst_rgb24, int width) {
  905. asm volatile(
  906. "1: \n"
  907. "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // read r g b
  908. "prfm pldl1keep, [%0, 448] \n"
  909. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  910. "orr v3.8b, v1.8b, v1.8b \n" // move g
  911. "orr v4.8b, v0.8b, v0.8b \n" // move r
  912. "st3 {v2.8b,v3.8b,v4.8b}, [%1], #24 \n" // store b g r
  913. "b.gt 1b \n"
  914. : "+r"(src_raw), // %0
  915. "+r"(dst_rgb24), // %1
  916. "+r"(width) // %2
  917. :
  918. : "cc", "memory", "v0", "v1", "v2", "v3", "v4" // Clobber List
  919. );
  920. }
  921. #define RGB565TOARGB \
  922. "shrn v6.8b, v0.8h, #5 \n" /* G xxGGGGGG */ \
  923. "shl v6.8b, v6.8b, #2 \n" /* G GGGGGG00 upper 6 */ \
  924. "ushr v4.8b, v6.8b, #6 \n" /* G 000000GG lower 2 */ \
  925. "orr v1.8b, v4.8b, v6.8b \n" /* G */ \
  926. "xtn v2.8b, v0.8h \n" /* B xxxBBBBB */ \
  927. "ushr v0.8h, v0.8h, #11 \n" /* R 000RRRRR */ \
  928. "xtn2 v2.16b,v0.8h \n" /* R in upper part */ \
  929. "shl v2.16b, v2.16b, #3 \n" /* R,B BBBBB000 upper 5 */ \
  930. "ushr v0.16b, v2.16b, #5 \n" /* R,B 00000BBB lower 3 */ \
  931. "orr v0.16b, v0.16b, v2.16b \n" /* R,B */ \
  932. "dup v2.2D, v0.D[1] \n" /* R */
  933. void RGB565ToARGBRow_NEON(const uint8_t* src_rgb565,
  934. uint8_t* dst_argb,
  935. int width) {
  936. asm volatile(
  937. "movi v3.8b, #255 \n" // Alpha
  938. "1: \n"
  939. "ld1 {v0.16b}, [%0], #16 \n" // load 8 RGB565 pixels.
  940. "prfm pldl1keep, [%0, 448] \n"
  941. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  942. RGB565TOARGB
  943. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB
  944. "b.gt 1b \n"
  945. : "+r"(src_rgb565), // %0
  946. "+r"(dst_argb), // %1
  947. "+r"(width) // %2
  948. :
  949. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v6" // Clobber List
  950. );
  951. }
  952. #define ARGB1555TOARGB \
  953. "ushr v2.8h, v0.8h, #10 \n" /* R xxxRRRRR */ \
  954. "shl v2.8h, v2.8h, #3 \n" /* R RRRRR000 upper 5 */ \
  955. "xtn v3.8b, v2.8h \n" /* RRRRR000 AAAAAAAA */ \
  956. \
  957. "sshr v2.8h, v0.8h, #15 \n" /* A AAAAAAAA */ \
  958. "xtn2 v3.16b, v2.8h \n" \
  959. \
  960. "xtn v2.8b, v0.8h \n" /* B xxxBBBBB */ \
  961. "shrn2 v2.16b,v0.8h, #5 \n" /* G xxxGGGGG */ \
  962. \
  963. "ushr v1.16b, v3.16b, #5 \n" /* R,A 00000RRR lower 3 */ \
  964. "shl v0.16b, v2.16b, #3 \n" /* B,G BBBBB000 upper 5 */ \
  965. "ushr v2.16b, v0.16b, #5 \n" /* B,G 00000BBB lower 3 */ \
  966. \
  967. "orr v0.16b, v0.16b, v2.16b \n" /* B,G */ \
  968. "orr v2.16b, v1.16b, v3.16b \n" /* R,A */ \
  969. "dup v1.2D, v0.D[1] \n" \
  970. "dup v3.2D, v2.D[1] \n"
  971. // RGB555TOARGB is same as ARGB1555TOARGB but ignores alpha.
  972. #define RGB555TOARGB \
  973. "ushr v2.8h, v0.8h, #10 \n" /* R xxxRRRRR */ \
  974. "shl v2.8h, v2.8h, #3 \n" /* R RRRRR000 upper 5 */ \
  975. "xtn v3.8b, v2.8h \n" /* RRRRR000 */ \
  976. \
  977. "xtn v2.8b, v0.8h \n" /* B xxxBBBBB */ \
  978. "shrn2 v2.16b,v0.8h, #5 \n" /* G xxxGGGGG */ \
  979. \
  980. "ushr v1.16b, v3.16b, #5 \n" /* R 00000RRR lower 3 */ \
  981. "shl v0.16b, v2.16b, #3 \n" /* B,G BBBBB000 upper 5 */ \
  982. "ushr v2.16b, v0.16b, #5 \n" /* B,G 00000BBB lower 3 */ \
  983. \
  984. "orr v0.16b, v0.16b, v2.16b \n" /* B,G */ \
  985. "orr v2.16b, v1.16b, v3.16b \n" /* R */ \
  986. "dup v1.2D, v0.D[1] \n" /* G */
  987. void ARGB1555ToARGBRow_NEON(const uint8_t* src_argb1555,
  988. uint8_t* dst_argb,
  989. int width) {
  990. asm volatile(
  991. "movi v3.8b, #255 \n" // Alpha
  992. "1: \n"
  993. "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB1555 pixels.
  994. "prfm pldl1keep, [%0, 448] \n"
  995. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  996. ARGB1555TOARGB
  997. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB
  998. "b.gt 1b \n"
  999. : "+r"(src_argb1555), // %0
  1000. "+r"(dst_argb), // %1
  1001. "+r"(width) // %2
  1002. :
  1003. : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List
  1004. );
  1005. }
  1006. // Convert v0.8h to b = v0.8b g = v1.8b r = v2.8b
  1007. // clobbers v3
  1008. #define ARGB4444TOARGB \
  1009. "shrn v1.8b, v0.8h, #8 \n" /* v1(l) AR */ \
  1010. "xtn2 v1.16b, v0.8h \n" /* v1(h) GB */ \
  1011. "shl v2.16b, v1.16b, #4 \n" /* B,R BBBB0000 */ \
  1012. "ushr v3.16b, v1.16b, #4 \n" /* G,A 0000GGGG */ \
  1013. "ushr v0.16b, v2.16b, #4 \n" /* B,R 0000BBBB */ \
  1014. "shl v1.16b, v3.16b, #4 \n" /* G,A GGGG0000 */ \
  1015. "orr v2.16b, v0.16b, v2.16b \n" /* B,R BBBBBBBB */ \
  1016. "orr v3.16b, v1.16b, v3.16b \n" /* G,A GGGGGGGG */ \
  1017. "dup v0.2D, v2.D[1] \n" \
  1018. "dup v1.2D, v3.D[1] \n"
  1019. void ARGB4444ToARGBRow_NEON(const uint8_t* src_argb4444,
  1020. uint8_t* dst_argb,
  1021. int width) {
  1022. asm volatile(
  1023. "1: \n"
  1024. "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB4444 pixels.
  1025. "prfm pldl1keep, [%0, 448] \n"
  1026. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1027. ARGB4444TOARGB
  1028. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB
  1029. "b.gt 1b \n"
  1030. : "+r"(src_argb4444), // %0
  1031. "+r"(dst_argb), // %1
  1032. "+r"(width) // %2
  1033. :
  1034. : "cc", "memory", "v0", "v1", "v2", "v3", "v4" // Clobber List
  1035. );
  1036. }
  1037. void ARGBToRGB24Row_NEON(const uint8_t* src_argb,
  1038. uint8_t* dst_rgb24,
  1039. int width) {
  1040. asm volatile(
  1041. "1: \n"
  1042. "ld4 {v1.8b,v2.8b,v3.8b,v4.8b}, [%0], #32 \n" // load 8 ARGB
  1043. "prfm pldl1keep, [%0, 448] \n"
  1044. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1045. "st3 {v1.8b,v2.8b,v3.8b}, [%1], #24 \n" // store 8 pixels of RGB24
  1046. "b.gt 1b \n"
  1047. : "+r"(src_argb), // %0
  1048. "+r"(dst_rgb24), // %1
  1049. "+r"(width) // %2
  1050. :
  1051. : "cc", "memory", "v1", "v2", "v3", "v4" // Clobber List
  1052. );
  1053. }
  1054. void ARGBToRAWRow_NEON(const uint8_t* src_argb, uint8_t* dst_raw, int width) {
  1055. asm volatile(
  1056. "1: \n"
  1057. "ld4 {v1.8b,v2.8b,v3.8b,v4.8b}, [%0], #32 \n" // load b g r a
  1058. "prfm pldl1keep, [%0, 448] \n"
  1059. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1060. "orr v4.8b, v2.8b, v2.8b \n" // mov g
  1061. "orr v5.8b, v1.8b, v1.8b \n" // mov b
  1062. "st3 {v3.8b,v4.8b,v5.8b}, [%1], #24 \n" // store r g b
  1063. "b.gt 1b \n"
  1064. : "+r"(src_argb), // %0
  1065. "+r"(dst_raw), // %1
  1066. "+r"(width) // %2
  1067. :
  1068. : "cc", "memory", "v1", "v2", "v3", "v4", "v5" // Clobber List
  1069. );
  1070. }
  1071. void YUY2ToYRow_NEON(const uint8_t* src_yuy2, uint8_t* dst_y, int width) {
  1072. asm volatile(
  1073. "1: \n"
  1074. "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pixels of YUY2.
  1075. "prfm pldl1keep, [%0, 448] \n"
  1076. "subs %w2, %w2, #16 \n" // 16 processed per loop.
  1077. "st1 {v0.16b}, [%1], #16 \n" // store 16 pixels of Y.
  1078. "b.gt 1b \n"
  1079. : "+r"(src_yuy2), // %0
  1080. "+r"(dst_y), // %1
  1081. "+r"(width) // %2
  1082. :
  1083. : "cc", "memory", "v0", "v1" // Clobber List
  1084. );
  1085. }
  1086. void UYVYToYRow_NEON(const uint8_t* src_uyvy, uint8_t* dst_y, int width) {
  1087. asm volatile(
  1088. "1: \n"
  1089. "ld2 {v0.16b,v1.16b}, [%0], #32 \n" // load 16 pixels of UYVY.
  1090. "prfm pldl1keep, [%0, 448] \n"
  1091. "subs %w2, %w2, #16 \n" // 16 processed per loop.
  1092. "st1 {v1.16b}, [%1], #16 \n" // store 16 pixels of Y.
  1093. "b.gt 1b \n"
  1094. : "+r"(src_uyvy), // %0
  1095. "+r"(dst_y), // %1
  1096. "+r"(width) // %2
  1097. :
  1098. : "cc", "memory", "v0", "v1" // Clobber List
  1099. );
  1100. }
  1101. void YUY2ToUV422Row_NEON(const uint8_t* src_yuy2,
  1102. uint8_t* dst_u,
  1103. uint8_t* dst_v,
  1104. int width) {
  1105. asm volatile(
  1106. "1: \n"
  1107. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 YUY2
  1108. "prfm pldl1keep, [%0, 448] \n"
  1109. "subs %w3, %w3, #16 \n" // 16 pixels = 8 UVs.
  1110. "st1 {v1.8b}, [%1], #8 \n" // store 8 U.
  1111. "st1 {v3.8b}, [%2], #8 \n" // store 8 V.
  1112. "b.gt 1b \n"
  1113. : "+r"(src_yuy2), // %0
  1114. "+r"(dst_u), // %1
  1115. "+r"(dst_v), // %2
  1116. "+r"(width) // %3
  1117. :
  1118. : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List
  1119. );
  1120. }
  1121. void UYVYToUV422Row_NEON(const uint8_t* src_uyvy,
  1122. uint8_t* dst_u,
  1123. uint8_t* dst_v,
  1124. int width) {
  1125. asm volatile(
  1126. "1: \n"
  1127. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 UYVY
  1128. "prfm pldl1keep, [%0, 448] \n"
  1129. "subs %w3, %w3, #16 \n" // 16 pixels = 8 UVs.
  1130. "st1 {v0.8b}, [%1], #8 \n" // store 8 U.
  1131. "st1 {v2.8b}, [%2], #8 \n" // store 8 V.
  1132. "b.gt 1b \n"
  1133. : "+r"(src_uyvy), // %0
  1134. "+r"(dst_u), // %1
  1135. "+r"(dst_v), // %2
  1136. "+r"(width) // %3
  1137. :
  1138. : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List
  1139. );
  1140. }
  1141. void YUY2ToUVRow_NEON(const uint8_t* src_yuy2,
  1142. int stride_yuy2,
  1143. uint8_t* dst_u,
  1144. uint8_t* dst_v,
  1145. int width) {
  1146. const uint8_t* src_yuy2b = src_yuy2 + stride_yuy2;
  1147. asm volatile(
  1148. "1: \n"
  1149. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 pixels
  1150. "prfm pldl1keep, [%0, 448] \n"
  1151. "subs %w4, %w4, #16 \n" // 16 pixels = 8 UVs.
  1152. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load next row
  1153. "urhadd v1.8b, v1.8b, v5.8b \n" // average rows of U
  1154. "urhadd v3.8b, v3.8b, v7.8b \n" // average rows of V
  1155. "st1 {v1.8b}, [%2], #8 \n" // store 8 U.
  1156. "st1 {v3.8b}, [%3], #8 \n" // store 8 V.
  1157. "b.gt 1b \n"
  1158. : "+r"(src_yuy2), // %0
  1159. "+r"(src_yuy2b), // %1
  1160. "+r"(dst_u), // %2
  1161. "+r"(dst_v), // %3
  1162. "+r"(width) // %4
  1163. :
  1164. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6",
  1165. "v7" // Clobber List
  1166. );
  1167. }
  1168. void UYVYToUVRow_NEON(const uint8_t* src_uyvy,
  1169. int stride_uyvy,
  1170. uint8_t* dst_u,
  1171. uint8_t* dst_v,
  1172. int width) {
  1173. const uint8_t* src_uyvyb = src_uyvy + stride_uyvy;
  1174. asm volatile(
  1175. "1: \n"
  1176. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 16 pixels
  1177. "prfm pldl1keep, [%0, 448] \n"
  1178. "subs %w4, %w4, #16 \n" // 16 pixels = 8 UVs.
  1179. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load next row
  1180. "urhadd v0.8b, v0.8b, v4.8b \n" // average rows of U
  1181. "urhadd v2.8b, v2.8b, v6.8b \n" // average rows of V
  1182. "st1 {v0.8b}, [%2], #8 \n" // store 8 U.
  1183. "st1 {v2.8b}, [%3], #8 \n" // store 8 V.
  1184. "b.gt 1b \n"
  1185. : "+r"(src_uyvy), // %0
  1186. "+r"(src_uyvyb), // %1
  1187. "+r"(dst_u), // %2
  1188. "+r"(dst_v), // %3
  1189. "+r"(width) // %4
  1190. :
  1191. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6",
  1192. "v7" // Clobber List
  1193. );
  1194. }
  1195. // For BGRAToARGB, ABGRToARGB, RGBAToARGB, and ARGBToRGBA.
  1196. void ARGBShuffleRow_NEON(const uint8_t* src_argb,
  1197. uint8_t* dst_argb,
  1198. const uint8_t* shuffler,
  1199. int width) {
  1200. asm volatile(
  1201. "ld1 {v2.16b}, [%3] \n" // shuffler
  1202. "1: \n"
  1203. "ld1 {v0.16b}, [%0], #16 \n" // load 4 pixels.
  1204. "prfm pldl1keep, [%0, 448] \n"
  1205. "subs %w2, %w2, #4 \n" // 4 processed per loop
  1206. "tbl v1.16b, {v0.16b}, v2.16b \n" // look up 4 pixels
  1207. "st1 {v1.16b}, [%1], #16 \n" // store 4.
  1208. "b.gt 1b \n"
  1209. : "+r"(src_argb), // %0
  1210. "+r"(dst_argb), // %1
  1211. "+r"(width) // %2
  1212. : "r"(shuffler) // %3
  1213. : "cc", "memory", "v0", "v1", "v2" // Clobber List
  1214. );
  1215. }
  1216. void I422ToYUY2Row_NEON(const uint8_t* src_y,
  1217. const uint8_t* src_u,
  1218. const uint8_t* src_v,
  1219. uint8_t* dst_yuy2,
  1220. int width) {
  1221. asm volatile(
  1222. "1: \n"
  1223. "ld2 {v0.8b, v1.8b}, [%0], #16 \n" // load 16 Ys
  1224. "prfm pldl1keep, [%0, 448] \n"
  1225. "orr v2.8b, v1.8b, v1.8b \n"
  1226. "ld1 {v1.8b}, [%1], #8 \n" // load 8 Us
  1227. "ld1 {v3.8b}, [%2], #8 \n" // load 8 Vs
  1228. "subs %w4, %w4, #16 \n" // 16 pixels
  1229. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%3], #32 \n" // Store 16 pixels.
  1230. "b.gt 1b \n"
  1231. : "+r"(src_y), // %0
  1232. "+r"(src_u), // %1
  1233. "+r"(src_v), // %2
  1234. "+r"(dst_yuy2), // %3
  1235. "+r"(width) // %4
  1236. :
  1237. : "cc", "memory", "v0", "v1", "v2", "v3");
  1238. }
  1239. void I422ToUYVYRow_NEON(const uint8_t* src_y,
  1240. const uint8_t* src_u,
  1241. const uint8_t* src_v,
  1242. uint8_t* dst_uyvy,
  1243. int width) {
  1244. asm volatile(
  1245. "1: \n"
  1246. "ld2 {v1.8b,v2.8b}, [%0], #16 \n" // load 16 Ys
  1247. "prfm pldl1keep, [%0, 448] \n"
  1248. "orr v3.8b, v2.8b, v2.8b \n"
  1249. "ld1 {v0.8b}, [%1], #8 \n" // load 8 Us
  1250. "ld1 {v2.8b}, [%2], #8 \n" // load 8 Vs
  1251. "subs %w4, %w4, #16 \n" // 16 pixels
  1252. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%3], #32 \n" // Store 16 pixels.
  1253. "b.gt 1b \n"
  1254. : "+r"(src_y), // %0
  1255. "+r"(src_u), // %1
  1256. "+r"(src_v), // %2
  1257. "+r"(dst_uyvy), // %3
  1258. "+r"(width) // %4
  1259. :
  1260. : "cc", "memory", "v0", "v1", "v2", "v3");
  1261. }
  1262. void ARGBToRGB565Row_NEON(const uint8_t* src_argb,
  1263. uint8_t* dst_rgb565,
  1264. int width) {
  1265. asm volatile(
  1266. "1: \n"
  1267. "ld4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%0], #32 \n" // load 8 pixels
  1268. "prfm pldl1keep, [%0, 448] \n"
  1269. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1270. ARGBTORGB565
  1271. "st1 {v0.16b}, [%1], #16 \n" // store 8 pixels RGB565.
  1272. "b.gt 1b \n"
  1273. : "+r"(src_argb), // %0
  1274. "+r"(dst_rgb565), // %1
  1275. "+r"(width) // %2
  1276. :
  1277. : "cc", "memory", "v0", "v20", "v21", "v22", "v23");
  1278. }
  1279. void ARGBToRGB565DitherRow_NEON(const uint8_t* src_argb,
  1280. uint8_t* dst_rgb,
  1281. const uint32_t dither4,
  1282. int width) {
  1283. asm volatile(
  1284. "dup v1.4s, %w2 \n" // dither4
  1285. "1: \n"
  1286. "ld4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%1], #32 \n" // load 8 pixels
  1287. "prfm pldl1keep, [%0, 448] \n"
  1288. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  1289. "uqadd v20.8b, v20.8b, v1.8b \n"
  1290. "uqadd v21.8b, v21.8b, v1.8b \n"
  1291. "uqadd v22.8b, v22.8b, v1.8b \n" ARGBTORGB565
  1292. "st1 {v0.16b}, [%0], #16 \n" // store 8 pixels RGB565.
  1293. "b.gt 1b \n"
  1294. : "+r"(dst_rgb) // %0
  1295. : "r"(src_argb), // %1
  1296. "r"(dither4), // %2
  1297. "r"(width) // %3
  1298. : "cc", "memory", "v0", "v1", "v20", "v21", "v22", "v23");
  1299. }
  1300. void ARGBToARGB1555Row_NEON(const uint8_t* src_argb,
  1301. uint8_t* dst_argb1555,
  1302. int width) {
  1303. asm volatile(
  1304. "1: \n"
  1305. "ld4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%0], #32 \n" // load 8 pixels
  1306. "prfm pldl1keep, [%0, 448] \n"
  1307. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1308. ARGBTOARGB1555
  1309. "st1 {v0.16b}, [%1], #16 \n" // store 8 pixels
  1310. "b.gt 1b \n"
  1311. : "+r"(src_argb), // %0
  1312. "+r"(dst_argb1555), // %1
  1313. "+r"(width) // %2
  1314. :
  1315. : "cc", "memory", "v0", "v20", "v21", "v22", "v23");
  1316. }
  1317. void ARGBToARGB4444Row_NEON(const uint8_t* src_argb,
  1318. uint8_t* dst_argb4444,
  1319. int width) {
  1320. asm volatile(
  1321. "movi v4.16b, #0x0f \n" // bits to clear with
  1322. // vbic.
  1323. "1: \n"
  1324. "ld4 {v20.8b,v21.8b,v22.8b,v23.8b}, [%0], #32 \n" // load 8 pixels
  1325. "prfm pldl1keep, [%0, 448] \n"
  1326. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1327. ARGBTOARGB4444
  1328. "st1 {v0.16b}, [%1], #16 \n" // store 8 pixels
  1329. "b.gt 1b \n"
  1330. : "+r"(src_argb), // %0
  1331. "+r"(dst_argb4444), // %1
  1332. "+r"(width) // %2
  1333. :
  1334. : "cc", "memory", "v0", "v1", "v4", "v20", "v21", "v22", "v23");
  1335. }
  1336. void ARGBToYRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width) {
  1337. asm volatile(
  1338. "movi v4.8b, #25 \n" // B * 0.1016 coefficient
  1339. "movi v5.8b, #129 \n" // G * 0.5078 coefficient
  1340. "movi v6.8b, #66 \n" // R * 0.2578 coefficient
  1341. "movi v7.8b, #16 \n" // Add 16 constant
  1342. "1: \n"
  1343. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB
  1344. "prfm pldl1keep, [%0, 448] \n"
  1345. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1346. "umull v3.8h, v0.8b, v4.8b \n" // B
  1347. "umlal v3.8h, v1.8b, v5.8b \n" // G
  1348. "umlal v3.8h, v2.8b, v6.8b \n" // R
  1349. "uqrshrn v0.8b, v3.8h, #8 \n" // 16 bit to 8 bit Y
  1350. "uqadd v0.8b, v0.8b, v7.8b \n"
  1351. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  1352. "b.gt 1b \n"
  1353. : "+r"(src_argb), // %0
  1354. "+r"(dst_y), // %1
  1355. "+r"(width) // %2
  1356. :
  1357. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  1358. }
  1359. void ARGBExtractAlphaRow_NEON(const uint8_t* src_argb,
  1360. uint8_t* dst_a,
  1361. int width) {
  1362. asm volatile(
  1363. "1: \n"
  1364. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16
  1365. "prfm pldl1keep, [%0, 448] \n"
  1366. "subs %w2, %w2, #16 \n" // 16 processed per loop
  1367. "st1 {v3.16b}, [%1], #16 \n" // store 16 A's.
  1368. "b.gt 1b \n"
  1369. : "+r"(src_argb), // %0
  1370. "+r"(dst_a), // %1
  1371. "+r"(width) // %2
  1372. :
  1373. : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List
  1374. );
  1375. }
  1376. void ARGBToYJRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width) {
  1377. asm volatile(
  1378. "movi v4.8b, #29 \n" // B * 0.1140 coefficient
  1379. "movi v5.8b, #150 \n" // G * 0.5870 coefficient
  1380. "movi v6.8b, #77 \n" // R * 0.2990 coefficient
  1381. "1: \n"
  1382. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB
  1383. "prfm pldl1keep, [%0, 448] \n"
  1384. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1385. "umull v3.8h, v0.8b, v4.8b \n" // B
  1386. "umlal v3.8h, v1.8b, v5.8b \n" // G
  1387. "umlal v3.8h, v2.8b, v6.8b \n" // R
  1388. "uqrshrn v0.8b, v3.8h, #8 \n" // 16 bit to 8 bit Y
  1389. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  1390. "b.gt 1b \n"
  1391. : "+r"(src_argb), // %0
  1392. "+r"(dst_y), // %1
  1393. "+r"(width) // %2
  1394. :
  1395. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6");
  1396. }
  1397. void RGBAToYJRow_NEON(const uint8_t* src_argb, uint8_t* dst_y, int width) {
  1398. asm volatile(
  1399. "movi v4.8b, #29 \n" // B * 0.1140 coefficient
  1400. "movi v5.8b, #150 \n" // G * 0.5870 coefficient
  1401. "movi v6.8b, #77 \n" // R * 0.2990 coefficient
  1402. "1: \n"
  1403. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 RGBA
  1404. "prfm pldl1keep, [%0, 448] \n"
  1405. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1406. "umull v0.8h, v1.8b, v4.8b \n" // B
  1407. "umlal v0.8h, v2.8b, v5.8b \n" // G
  1408. "umlal v0.8h, v3.8b, v6.8b \n" // R
  1409. "uqrshrn v3.8b, v0.8h, #8 \n" // 16 bit to 8 bit Y
  1410. "st1 {v3.8b}, [%1], #8 \n" // store 8 pixels Y.
  1411. "b.gt 1b \n"
  1412. : "+r"(src_argb), // %0
  1413. "+r"(dst_y), // %1
  1414. "+r"(width) // %2
  1415. :
  1416. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6");
  1417. }
  1418. // 8x1 pixels.
  1419. void ARGBToUV444Row_NEON(const uint8_t* src_argb,
  1420. uint8_t* dst_u,
  1421. uint8_t* dst_v,
  1422. int width) {
  1423. asm volatile(
  1424. "movi v24.8b, #112 \n" // UB / VR 0.875
  1425. // coefficient
  1426. "movi v25.8b, #74 \n" // UG -0.5781 coefficient
  1427. "movi v26.8b, #38 \n" // UR -0.2969 coefficient
  1428. "movi v27.8b, #18 \n" // VB -0.1406 coefficient
  1429. "movi v28.8b, #94 \n" // VG -0.7344 coefficient
  1430. "movi v29.16b,#0x80 \n" // 128.5
  1431. "1: \n"
  1432. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB
  1433. "prfm pldl1keep, [%0, 448] \n"
  1434. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  1435. "umull v4.8h, v0.8b, v24.8b \n" // B
  1436. "umlsl v4.8h, v1.8b, v25.8b \n" // G
  1437. "umlsl v4.8h, v2.8b, v26.8b \n" // R
  1438. "add v4.8h, v4.8h, v29.8h \n" // +128 -> unsigned
  1439. "umull v3.8h, v2.8b, v24.8b \n" // R
  1440. "umlsl v3.8h, v1.8b, v28.8b \n" // G
  1441. "umlsl v3.8h, v0.8b, v27.8b \n" // B
  1442. "add v3.8h, v3.8h, v29.8h \n" // +128 -> unsigned
  1443. "uqshrn v0.8b, v4.8h, #8 \n" // 16 bit to 8 bit U
  1444. "uqshrn v1.8b, v3.8h, #8 \n" // 16 bit to 8 bit V
  1445. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels U.
  1446. "st1 {v1.8b}, [%2], #8 \n" // store 8 pixels V.
  1447. "b.gt 1b \n"
  1448. : "+r"(src_argb), // %0
  1449. "+r"(dst_u), // %1
  1450. "+r"(dst_v), // %2
  1451. "+r"(width) // %3
  1452. :
  1453. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v24", "v25", "v26",
  1454. "v27", "v28", "v29");
  1455. }
  1456. #define RGBTOUV_SETUP_REG \
  1457. "movi v20.8h, #56, lsl #0 \n" /* UB/VR coefficient (0.875) / 2 */ \
  1458. "movi v21.8h, #37, lsl #0 \n" /* UG coefficient (-0.5781) / 2 */ \
  1459. "movi v22.8h, #19, lsl #0 \n" /* UR coefficient (-0.2969) / 2 */ \
  1460. "movi v23.8h, #9, lsl #0 \n" /* VB coefficient (-0.1406) / 2 */ \
  1461. "movi v24.8h, #47, lsl #0 \n" /* VG coefficient (-0.7344) / 2 */ \
  1462. "movi v25.16b, #0x80 \n" /* 128.5 (0x8080 in 16-bit) */
  1463. // 16x2 pixels -> 8x1. width is number of argb pixels. e.g. 16.
  1464. // clang-format off
  1465. #define RGBTOUV(QB, QG, QR) \
  1466. "mul v3.8h, " #QB ",v20.8h \n" /* B */ \
  1467. "mul v4.8h, " #QR ",v20.8h \n" /* R */ \
  1468. "mls v3.8h, " #QG ",v21.8h \n" /* G */ \
  1469. "mls v4.8h, " #QG ",v24.8h \n" /* G */ \
  1470. "mls v3.8h, " #QR ",v22.8h \n" /* R */ \
  1471. "mls v4.8h, " #QB ",v23.8h \n" /* B */ \
  1472. "add v3.8h, v3.8h, v25.8h \n" /* +128 -> unsigned */ \
  1473. "add v4.8h, v4.8h, v25.8h \n" /* +128 -> unsigned */ \
  1474. "uqshrn v0.8b, v3.8h, #8 \n" /* 16 bit to 8 bit U */ \
  1475. "uqshrn v1.8b, v4.8h, #8 \n" /* 16 bit to 8 bit V */
  1476. // clang-format on
  1477. // TODO(fbarchard): Consider vhadd vertical, then vpaddl horizontal, avoid shr.
  1478. // TODO(fbarchard): consider ptrdiff_t for all strides.
  1479. void ARGBToUVRow_NEON(const uint8_t* src_argb,
  1480. int src_stride_argb,
  1481. uint8_t* dst_u,
  1482. uint8_t* dst_v,
  1483. int width) {
  1484. const uint8_t* src_argb_1 = src_argb + src_stride_argb;
  1485. asm volatile (
  1486. RGBTOUV_SETUP_REG
  1487. "1: \n"
  1488. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels.
  1489. "prfm pldl1keep, [%0, 448] \n"
  1490. "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts.
  1491. "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts.
  1492. "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts.
  1493. "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16
  1494. "prfm pldl1keep, [%1, 448] \n"
  1495. "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts.
  1496. "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts.
  1497. "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts.
  1498. "urshr v0.8h, v0.8h, #1 \n" // 2x average
  1499. "urshr v1.8h, v1.8h, #1 \n"
  1500. "urshr v2.8h, v2.8h, #1 \n"
  1501. "subs %w4, %w4, #16 \n" // 16 processed per loop.
  1502. RGBTOUV(v0.8h, v1.8h, v2.8h)
  1503. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1504. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1505. "b.gt 1b \n"
  1506. : "+r"(src_argb), // %0
  1507. "+r"(src_argb_1), // %1
  1508. "+r"(dst_u), // %2
  1509. "+r"(dst_v), // %3
  1510. "+r"(width) // %4
  1511. :
  1512. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1513. "v20", "v21", "v22", "v23", "v24", "v25"
  1514. );
  1515. }
  1516. void ARGBToUVJRow_NEON(const uint8_t* src_argb,
  1517. int src_stride_argb,
  1518. uint8_t* dst_u,
  1519. uint8_t* dst_v,
  1520. int width) {
  1521. const uint8_t* src_argb_1 = src_argb + src_stride_argb;
  1522. asm volatile (
  1523. "movi v20.8h, #63, lsl #0 \n" // UB/VR coeff (0.500) / 2
  1524. "movi v21.8h, #42, lsl #0 \n" // UG coeff (-0.33126) / 2
  1525. "movi v22.8h, #21, lsl #0 \n" // UR coeff (-0.16874) / 2
  1526. "movi v23.8h, #10, lsl #0 \n" // VB coeff (-0.08131) / 2
  1527. "movi v24.8h, #53, lsl #0 \n" // VG coeff (-0.41869) / 2
  1528. "movi v25.16b, #0x80 \n" // 128.5 (0x8080 in 16-bit)
  1529. "1: \n"
  1530. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels.
  1531. "prfm pldl1keep, [%0, 448] \n"
  1532. "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts.
  1533. "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts.
  1534. "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts.
  1535. "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16
  1536. "prfm pldl1keep, [%1, 448] \n"
  1537. "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts.
  1538. "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts.
  1539. "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts.
  1540. "urshr v0.8h, v0.8h, #1 \n" // 2x average
  1541. "urshr v1.8h, v1.8h, #1 \n"
  1542. "urshr v2.8h, v2.8h, #1 \n"
  1543. "subs %w4, %w4, #16 \n" // 32 processed per loop.
  1544. RGBTOUV(v0.8h, v1.8h, v2.8h)
  1545. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1546. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1547. "b.gt 1b \n"
  1548. : "+r"(src_argb), // %0
  1549. "+r"(src_argb_1), // %1
  1550. "+r"(dst_u), // %2
  1551. "+r"(dst_v), // %3
  1552. "+r"(width) // %4
  1553. :
  1554. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1555. "v20", "v21", "v22", "v23", "v24", "v25"
  1556. );
  1557. }
  1558. void BGRAToUVRow_NEON(const uint8_t* src_bgra,
  1559. int src_stride_bgra,
  1560. uint8_t* dst_u,
  1561. uint8_t* dst_v,
  1562. int width) {
  1563. const uint8_t* src_bgra_1 = src_bgra + src_stride_bgra;
  1564. asm volatile (
  1565. RGBTOUV_SETUP_REG
  1566. "1: \n"
  1567. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels.
  1568. "prfm pldl1keep, [%0, 448] \n"
  1569. "uaddlp v0.8h, v3.16b \n" // B 16 bytes -> 8 shorts.
  1570. "uaddlp v3.8h, v2.16b \n" // G 16 bytes -> 8 shorts.
  1571. "uaddlp v2.8h, v1.16b \n" // R 16 bytes -> 8 shorts.
  1572. "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load 16 more
  1573. "prfm pldl1keep, [%1, 448] \n"
  1574. "uadalp v0.8h, v7.16b \n" // B 16 bytes -> 8 shorts.
  1575. "uadalp v3.8h, v6.16b \n" // G 16 bytes -> 8 shorts.
  1576. "uadalp v2.8h, v5.16b \n" // R 16 bytes -> 8 shorts.
  1577. "urshr v0.8h, v0.8h, #1 \n" // 2x average
  1578. "urshr v1.8h, v3.8h, #1 \n"
  1579. "urshr v2.8h, v2.8h, #1 \n"
  1580. "subs %w4, %w4, #16 \n" // 32 processed per loop.
  1581. RGBTOUV(v0.8h, v1.8h, v2.8h)
  1582. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1583. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1584. "b.gt 1b \n"
  1585. : "+r"(src_bgra), // %0
  1586. "+r"(src_bgra_1), // %1
  1587. "+r"(dst_u), // %2
  1588. "+r"(dst_v), // %3
  1589. "+r"(width) // %4
  1590. :
  1591. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1592. "v20", "v21", "v22", "v23", "v24", "v25"
  1593. );
  1594. }
  1595. void ABGRToUVRow_NEON(const uint8_t* src_abgr,
  1596. int src_stride_abgr,
  1597. uint8_t* dst_u,
  1598. uint8_t* dst_v,
  1599. int width) {
  1600. const uint8_t* src_abgr_1 = src_abgr + src_stride_abgr;
  1601. asm volatile (
  1602. RGBTOUV_SETUP_REG
  1603. "1: \n"
  1604. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels.
  1605. "prfm pldl1keep, [%0, 448] \n"
  1606. "uaddlp v3.8h, v2.16b \n" // B 16 bytes -> 8 shorts.
  1607. "uaddlp v2.8h, v1.16b \n" // G 16 bytes -> 8 shorts.
  1608. "uaddlp v1.8h, v0.16b \n" // R 16 bytes -> 8 shorts.
  1609. "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load 16 more.
  1610. "prfm pldl1keep, [%1, 448] \n"
  1611. "uadalp v3.8h, v6.16b \n" // B 16 bytes -> 8 shorts.
  1612. "uadalp v2.8h, v5.16b \n" // G 16 bytes -> 8 shorts.
  1613. "uadalp v1.8h, v4.16b \n" // R 16 bytes -> 8 shorts.
  1614. "urshr v0.8h, v3.8h, #1 \n" // 2x average
  1615. "urshr v2.8h, v2.8h, #1 \n"
  1616. "urshr v1.8h, v1.8h, #1 \n"
  1617. "subs %w4, %w4, #16 \n" // 32 processed per loop.
  1618. RGBTOUV(v0.8h, v2.8h, v1.8h)
  1619. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1620. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1621. "b.gt 1b \n"
  1622. : "+r"(src_abgr), // %0
  1623. "+r"(src_abgr_1), // %1
  1624. "+r"(dst_u), // %2
  1625. "+r"(dst_v), // %3
  1626. "+r"(width) // %4
  1627. :
  1628. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1629. "v20", "v21", "v22", "v23", "v24", "v25"
  1630. );
  1631. }
  1632. void RGBAToUVRow_NEON(const uint8_t* src_rgba,
  1633. int src_stride_rgba,
  1634. uint8_t* dst_u,
  1635. uint8_t* dst_v,
  1636. int width) {
  1637. const uint8_t* src_rgba_1 = src_rgba + src_stride_rgba;
  1638. asm volatile (
  1639. RGBTOUV_SETUP_REG
  1640. "1: \n"
  1641. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 pixels.
  1642. "prfm pldl1keep, [%0, 448] \n"
  1643. "uaddlp v0.8h, v1.16b \n" // B 16 bytes -> 8 shorts.
  1644. "uaddlp v1.8h, v2.16b \n" // G 16 bytes -> 8 shorts.
  1645. "uaddlp v2.8h, v3.16b \n" // R 16 bytes -> 8 shorts.
  1646. "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load 16 more.
  1647. "prfm pldl1keep, [%1, 448] \n"
  1648. "uadalp v0.8h, v5.16b \n" // B 16 bytes -> 8 shorts.
  1649. "uadalp v1.8h, v6.16b \n" // G 16 bytes -> 8 shorts.
  1650. "uadalp v2.8h, v7.16b \n" // R 16 bytes -> 8 shorts.
  1651. "urshr v0.8h, v0.8h, #1 \n" // 2x average
  1652. "urshr v1.8h, v1.8h, #1 \n"
  1653. "urshr v2.8h, v2.8h, #1 \n"
  1654. "subs %w4, %w4, #16 \n" // 32 processed per loop.
  1655. RGBTOUV(v0.8h, v1.8h, v2.8h)
  1656. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1657. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1658. "b.gt 1b \n"
  1659. : "+r"(src_rgba), // %0
  1660. "+r"(src_rgba_1), // %1
  1661. "+r"(dst_u), // %2
  1662. "+r"(dst_v), // %3
  1663. "+r"(width) // %4
  1664. :
  1665. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1666. "v20", "v21", "v22", "v23", "v24", "v25"
  1667. );
  1668. }
  1669. void RGB24ToUVRow_NEON(const uint8_t* src_rgb24,
  1670. int src_stride_rgb24,
  1671. uint8_t* dst_u,
  1672. uint8_t* dst_v,
  1673. int width) {
  1674. const uint8_t* src_rgb24_1 = src_rgb24 + src_stride_rgb24;
  1675. asm volatile (
  1676. RGBTOUV_SETUP_REG
  1677. "1: \n"
  1678. "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 16 pixels.
  1679. "prfm pldl1keep, [%0, 448] \n"
  1680. "uaddlp v0.8h, v0.16b \n" // B 16 bytes -> 8 shorts.
  1681. "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts.
  1682. "uaddlp v2.8h, v2.16b \n" // R 16 bytes -> 8 shorts.
  1683. "ld3 {v4.16b,v5.16b,v6.16b}, [%1], #48 \n" // load 16 more.
  1684. "prfm pldl1keep, [%1, 448] \n"
  1685. "uadalp v0.8h, v4.16b \n" // B 16 bytes -> 8 shorts.
  1686. "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts.
  1687. "uadalp v2.8h, v6.16b \n" // R 16 bytes -> 8 shorts.
  1688. "urshr v0.8h, v0.8h, #1 \n" // 2x average
  1689. "urshr v1.8h, v1.8h, #1 \n"
  1690. "urshr v2.8h, v2.8h, #1 \n"
  1691. "subs %w4, %w4, #16 \n" // 32 processed per loop.
  1692. RGBTOUV(v0.8h, v1.8h, v2.8h)
  1693. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1694. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1695. "b.gt 1b \n"
  1696. : "+r"(src_rgb24), // %0
  1697. "+r"(src_rgb24_1), // %1
  1698. "+r"(dst_u), // %2
  1699. "+r"(dst_v), // %3
  1700. "+r"(width) // %4
  1701. :
  1702. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1703. "v20", "v21", "v22", "v23", "v24", "v25"
  1704. );
  1705. }
  1706. void RAWToUVRow_NEON(const uint8_t* src_raw,
  1707. int src_stride_raw,
  1708. uint8_t* dst_u,
  1709. uint8_t* dst_v,
  1710. int width) {
  1711. const uint8_t* src_raw_1 = src_raw + src_stride_raw;
  1712. asm volatile (
  1713. RGBTOUV_SETUP_REG
  1714. "1: \n"
  1715. "ld3 {v0.16b,v1.16b,v2.16b}, [%0], #48 \n" // load 8 RAW pixels.
  1716. "prfm pldl1keep, [%0, 448] \n"
  1717. "uaddlp v2.8h, v2.16b \n" // B 16 bytes -> 8 shorts.
  1718. "uaddlp v1.8h, v1.16b \n" // G 16 bytes -> 8 shorts.
  1719. "uaddlp v0.8h, v0.16b \n" // R 16 bytes -> 8 shorts.
  1720. "ld3 {v4.16b,v5.16b,v6.16b}, [%1], #48 \n" // load 8 more RAW pixels
  1721. "prfm pldl1keep, [%1, 448] \n"
  1722. "uadalp v2.8h, v6.16b \n" // B 16 bytes -> 8 shorts.
  1723. "uadalp v1.8h, v5.16b \n" // G 16 bytes -> 8 shorts.
  1724. "uadalp v0.8h, v4.16b \n" // R 16 bytes -> 8 shorts.
  1725. "urshr v2.8h, v2.8h, #1 \n" // 2x average
  1726. "urshr v1.8h, v1.8h, #1 \n"
  1727. "urshr v0.8h, v0.8h, #1 \n"
  1728. "subs %w4, %w4, #16 \n" // 32 processed per loop.
  1729. RGBTOUV(v2.8h, v1.8h, v0.8h)
  1730. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1731. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1732. "b.gt 1b \n"
  1733. : "+r"(src_raw), // %0
  1734. "+r"(src_raw_1), // %1
  1735. "+r"(dst_u), // %2
  1736. "+r"(dst_v), // %3
  1737. "+r"(width) // %4
  1738. :
  1739. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1740. "v20", "v21", "v22", "v23", "v24", "v25"
  1741. );
  1742. }
  1743. // 16x2 pixels -> 8x1. width is number of rgb pixels. e.g. 16.
  1744. void RGB565ToUVRow_NEON(const uint8_t* src_rgb565,
  1745. int src_stride_rgb565,
  1746. uint8_t* dst_u,
  1747. uint8_t* dst_v,
  1748. int width) {
  1749. const uint8_t* src_rgb565_1 = src_rgb565 + src_stride_rgb565;
  1750. asm volatile(
  1751. RGBTOUV_SETUP_REG
  1752. "1: \n"
  1753. "ld1 {v0.16b}, [%0], #16 \n" // load 8 RGB565 pixels.
  1754. "prfm pldl1keep, [%0, 448] \n"
  1755. RGB565TOARGB
  1756. "uaddlp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1757. "uaddlp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1758. "uaddlp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1759. "ld1 {v0.16b}, [%0], #16 \n" // next 8 RGB565 pixels.
  1760. RGB565TOARGB
  1761. "uaddlp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1762. "uaddlp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1763. "uaddlp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1764. "ld1 {v0.16b}, [%1], #16 \n" // load 8 RGB565 pixels.
  1765. "prfm pldl1keep, [%1, 448] \n"
  1766. RGB565TOARGB
  1767. "uadalp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1768. "uadalp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1769. "uadalp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1770. "ld1 {v0.16b}, [%1], #16 \n" // next 8 RGB565 pixels.
  1771. RGB565TOARGB
  1772. "uadalp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1773. "uadalp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1774. "uadalp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1775. "ins v16.D[1], v26.D[0] \n"
  1776. "ins v17.D[1], v27.D[0] \n"
  1777. "ins v18.D[1], v28.D[0] \n"
  1778. "urshr v0.8h, v16.8h, #1 \n" // 2x average
  1779. "urshr v1.8h, v17.8h, #1 \n"
  1780. "urshr v2.8h, v18.8h, #1 \n"
  1781. "subs %w4, %w4, #16 \n" // 16 processed per loop.
  1782. RGBTOUV(v0.8h, v1.8h, v2.8h)
  1783. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1784. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1785. "b.gt 1b \n"
  1786. : "+r"(src_rgb565), // %0
  1787. "+r"(src_rgb565_1), // %1
  1788. "+r"(dst_u), // %2
  1789. "+r"(dst_v), // %3
  1790. "+r"(width) // %4
  1791. :
  1792. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v16", "v17",
  1793. "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27",
  1794. "v28");
  1795. }
  1796. // 16x2 pixels -> 8x1. width is number of argb pixels. e.g. 16.
  1797. void ARGB1555ToUVRow_NEON(const uint8_t* src_argb1555,
  1798. int src_stride_argb1555,
  1799. uint8_t* dst_u,
  1800. uint8_t* dst_v,
  1801. int width) {
  1802. const uint8_t* src_argb1555_1 = src_argb1555 + src_stride_argb1555;
  1803. asm volatile(
  1804. RGBTOUV_SETUP_REG
  1805. "1: \n"
  1806. "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB1555 pixels.
  1807. "prfm pldl1keep, [%0, 448] \n"
  1808. RGB555TOARGB
  1809. "uaddlp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1810. "uaddlp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1811. "uaddlp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1812. "ld1 {v0.16b}, [%0], #16 \n" // next 8 ARGB1555 pixels.
  1813. RGB555TOARGB
  1814. "uaddlp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1815. "uaddlp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1816. "uaddlp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1817. "ld1 {v0.16b}, [%1], #16 \n" // load 8 ARGB1555 pixels.
  1818. "prfm pldl1keep, [%1, 448] \n"
  1819. RGB555TOARGB
  1820. "uadalp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1821. "uadalp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1822. "uadalp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1823. "ld1 {v0.16b}, [%1], #16 \n" // next 8 ARGB1555 pixels.
  1824. RGB555TOARGB
  1825. "uadalp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1826. "uadalp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1827. "uadalp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1828. "ins v16.D[1], v26.D[0] \n"
  1829. "ins v17.D[1], v27.D[0] \n"
  1830. "ins v18.D[1], v28.D[0] \n"
  1831. "urshr v0.8h, v16.8h, #1 \n" // 2x average
  1832. "urshr v1.8h, v17.8h, #1 \n"
  1833. "urshr v2.8h, v18.8h, #1 \n"
  1834. "subs %w4, %w4, #16 \n" // 16 processed per loop.
  1835. RGBTOUV(v0.8h, v1.8h, v2.8h)
  1836. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1837. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1838. "b.gt 1b \n"
  1839. : "+r"(src_argb1555), // %0
  1840. "+r"(src_argb1555_1), // %1
  1841. "+r"(dst_u), // %2
  1842. "+r"(dst_v), // %3
  1843. "+r"(width) // %4
  1844. :
  1845. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v16", "v17",
  1846. "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27",
  1847. "v28");
  1848. }
  1849. // 16x2 pixels -> 8x1. width is number of argb pixels. e.g. 16.
  1850. void ARGB4444ToUVRow_NEON(const uint8_t* src_argb4444,
  1851. int src_stride_argb4444,
  1852. uint8_t* dst_u,
  1853. uint8_t* dst_v,
  1854. int width) {
  1855. const uint8_t* src_argb4444_1 = src_argb4444 + src_stride_argb4444;
  1856. asm volatile(
  1857. RGBTOUV_SETUP_REG // sets v20-v25
  1858. "1: \n"
  1859. "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB4444 pixels.
  1860. "prfm pldl1keep, [%0, 448] \n"
  1861. ARGB4444TOARGB
  1862. "uaddlp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1863. "uaddlp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1864. "uaddlp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1865. "ld1 {v0.16b}, [%0], #16 \n" // next 8 ARGB4444 pixels.
  1866. ARGB4444TOARGB
  1867. "uaddlp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1868. "uaddlp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1869. "uaddlp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1870. "ld1 {v0.16b}, [%1], #16 \n" // load 8 ARGB4444 pixels.
  1871. "prfm pldl1keep, [%1, 448] \n"
  1872. ARGB4444TOARGB
  1873. "uadalp v16.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1874. "uadalp v17.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1875. "uadalp v18.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1876. "ld1 {v0.16b}, [%1], #16 \n" // next 8 ARGB4444 pixels.
  1877. ARGB4444TOARGB
  1878. "uadalp v26.4h, v0.8b \n" // B 8 bytes -> 4 shorts.
  1879. "uadalp v27.4h, v1.8b \n" // G 8 bytes -> 4 shorts.
  1880. "uadalp v28.4h, v2.8b \n" // R 8 bytes -> 4 shorts.
  1881. "ins v16.D[1], v26.D[0] \n"
  1882. "ins v17.D[1], v27.D[0] \n"
  1883. "ins v18.D[1], v28.D[0] \n"
  1884. "urshr v0.8h, v16.8h, #1 \n" // 2x average
  1885. "urshr v1.8h, v17.8h, #1 \n"
  1886. "urshr v2.8h, v18.8h, #1 \n"
  1887. "subs %w4, %w4, #16 \n" // 16 processed per loop.
  1888. RGBTOUV(v0.8h, v1.8h, v2.8h)
  1889. "st1 {v0.8b}, [%2], #8 \n" // store 8 pixels U.
  1890. "st1 {v1.8b}, [%3], #8 \n" // store 8 pixels V.
  1891. "b.gt 1b \n"
  1892. : "+r"(src_argb4444), // %0
  1893. "+r"(src_argb4444_1), // %1
  1894. "+r"(dst_u), // %2
  1895. "+r"(dst_v), // %3
  1896. "+r"(width) // %4
  1897. :
  1898. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v16", "v17",
  1899. "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27",
  1900. "v28"
  1901. );
  1902. }
  1903. void RGB565ToYRow_NEON(const uint8_t* src_rgb565, uint8_t* dst_y, int width) {
  1904. asm volatile(
  1905. "movi v24.8b, #25 \n" // B * 0.1016 coefficient
  1906. "movi v25.8b, #129 \n" // G * 0.5078 coefficient
  1907. "movi v26.8b, #66 \n" // R * 0.2578 coefficient
  1908. "movi v27.8b, #16 \n" // Add 16 constant
  1909. "1: \n"
  1910. "ld1 {v0.16b}, [%0], #16 \n" // load 8 RGB565 pixels.
  1911. "prfm pldl1keep, [%0, 448] \n"
  1912. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1913. RGB565TOARGB
  1914. "umull v3.8h, v0.8b, v24.8b \n" // B
  1915. "umlal v3.8h, v1.8b, v25.8b \n" // G
  1916. "umlal v3.8h, v2.8b, v26.8b \n" // R
  1917. "uqrshrn v0.8b, v3.8h, #8 \n" // 16 bit to 8 bit Y
  1918. "uqadd v0.8b, v0.8b, v27.8b \n"
  1919. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  1920. "b.gt 1b \n"
  1921. : "+r"(src_rgb565), // %0
  1922. "+r"(dst_y), // %1
  1923. "+r"(width) // %2
  1924. :
  1925. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v6", "v24", "v25", "v26",
  1926. "v27");
  1927. }
  1928. void ARGB1555ToYRow_NEON(const uint8_t* src_argb1555,
  1929. uint8_t* dst_y,
  1930. int width) {
  1931. asm volatile(
  1932. "movi v4.8b, #25 \n" // B * 0.1016 coefficient
  1933. "movi v5.8b, #129 \n" // G * 0.5078 coefficient
  1934. "movi v6.8b, #66 \n" // R * 0.2578 coefficient
  1935. "movi v7.8b, #16 \n" // Add 16 constant
  1936. "1: \n"
  1937. "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB1555 pixels.
  1938. "prfm pldl1keep, [%0, 448] \n"
  1939. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1940. ARGB1555TOARGB
  1941. "umull v3.8h, v0.8b, v4.8b \n" // B
  1942. "umlal v3.8h, v1.8b, v5.8b \n" // G
  1943. "umlal v3.8h, v2.8b, v6.8b \n" // R
  1944. "uqrshrn v0.8b, v3.8h, #8 \n" // 16 bit to 8 bit Y
  1945. "uqadd v0.8b, v0.8b, v7.8b \n"
  1946. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  1947. "b.gt 1b \n"
  1948. : "+r"(src_argb1555), // %0
  1949. "+r"(dst_y), // %1
  1950. "+r"(width) // %2
  1951. :
  1952. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  1953. }
  1954. void ARGB4444ToYRow_NEON(const uint8_t* src_argb4444,
  1955. uint8_t* dst_y,
  1956. int width) {
  1957. asm volatile(
  1958. "movi v24.8b, #25 \n" // B * 0.1016 coefficient
  1959. "movi v25.8b, #129 \n" // G * 0.5078 coefficient
  1960. "movi v26.8b, #66 \n" // R * 0.2578 coefficient
  1961. "movi v27.8b, #16 \n" // Add 16 constant
  1962. "1: \n"
  1963. "ld1 {v0.16b}, [%0], #16 \n" // load 8 ARGB4444 pixels.
  1964. "prfm pldl1keep, [%0, 448] \n"
  1965. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1966. ARGB4444TOARGB
  1967. "umull v3.8h, v0.8b, v24.8b \n" // B
  1968. "umlal v3.8h, v1.8b, v25.8b \n" // G
  1969. "umlal v3.8h, v2.8b, v26.8b \n" // R
  1970. "uqrshrn v0.8b, v3.8h, #8 \n" // 16 bit to 8 bit Y
  1971. "uqadd v0.8b, v0.8b, v27.8b \n"
  1972. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  1973. "b.gt 1b \n"
  1974. : "+r"(src_argb4444), // %0
  1975. "+r"(dst_y), // %1
  1976. "+r"(width) // %2
  1977. :
  1978. : "cc", "memory", "v0", "v1", "v2", "v3", "v24", "v25", "v26", "v27");
  1979. }
  1980. void BGRAToYRow_NEON(const uint8_t* src_bgra, uint8_t* dst_y, int width) {
  1981. asm volatile(
  1982. "movi v4.8b, #66 \n" // R * 0.2578 coefficient
  1983. "movi v5.8b, #129 \n" // G * 0.5078 coefficient
  1984. "movi v6.8b, #25 \n" // B * 0.1016 coefficient
  1985. "movi v7.8b, #16 \n" // Add 16 constant
  1986. "1: \n"
  1987. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 pixels.
  1988. "prfm pldl1keep, [%0, 448] \n"
  1989. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  1990. "umull v16.8h, v1.8b, v4.8b \n" // R
  1991. "umlal v16.8h, v2.8b, v5.8b \n" // G
  1992. "umlal v16.8h, v3.8b, v6.8b \n" // B
  1993. "uqrshrn v0.8b, v16.8h, #8 \n" // 16 bit to 8 bit Y
  1994. "uqadd v0.8b, v0.8b, v7.8b \n"
  1995. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  1996. "b.gt 1b \n"
  1997. : "+r"(src_bgra), // %0
  1998. "+r"(dst_y), // %1
  1999. "+r"(width) // %2
  2000. :
  2001. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16");
  2002. }
  2003. void ABGRToYRow_NEON(const uint8_t* src_abgr, uint8_t* dst_y, int width) {
  2004. asm volatile(
  2005. "movi v6.8b, #25 \n" // B * 0.1016 coefficient
  2006. "movi v5.8b, #129 \n" // G * 0.5078 coefficient
  2007. "movi v4.8b, #66 \n" // R * 0.2578 coefficient
  2008. "movi v7.8b, #16 \n" // Add 16 constant
  2009. "1: \n"
  2010. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 pixels.
  2011. "prfm pldl1keep, [%0, 448] \n"
  2012. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2013. "umull v16.8h, v0.8b, v4.8b \n" // R
  2014. "umlal v16.8h, v1.8b, v5.8b \n" // G
  2015. "umlal v16.8h, v2.8b, v6.8b \n" // B
  2016. "uqrshrn v0.8b, v16.8h, #8 \n" // 16 bit to 8 bit Y
  2017. "uqadd v0.8b, v0.8b, v7.8b \n"
  2018. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  2019. "b.gt 1b \n"
  2020. : "+r"(src_abgr), // %0
  2021. "+r"(dst_y), // %1
  2022. "+r"(width) // %2
  2023. :
  2024. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16");
  2025. }
  2026. void RGBAToYRow_NEON(const uint8_t* src_rgba, uint8_t* dst_y, int width) {
  2027. asm volatile(
  2028. "movi v4.8b, #25 \n" // B * 0.1016 coefficient
  2029. "movi v5.8b, #129 \n" // G * 0.5078 coefficient
  2030. "movi v6.8b, #66 \n" // R * 0.2578 coefficient
  2031. "movi v7.8b, #16 \n" // Add 16 constant
  2032. "1: \n"
  2033. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 pixels.
  2034. "prfm pldl1keep, [%0, 448] \n"
  2035. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2036. "umull v16.8h, v1.8b, v4.8b \n" // B
  2037. "umlal v16.8h, v2.8b, v5.8b \n" // G
  2038. "umlal v16.8h, v3.8b, v6.8b \n" // R
  2039. "uqrshrn v0.8b, v16.8h, #8 \n" // 16 bit to 8 bit Y
  2040. "uqadd v0.8b, v0.8b, v7.8b \n"
  2041. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  2042. "b.gt 1b \n"
  2043. : "+r"(src_rgba), // %0
  2044. "+r"(dst_y), // %1
  2045. "+r"(width) // %2
  2046. :
  2047. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16");
  2048. }
  2049. void RGB24ToYRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_y, int width) {
  2050. asm volatile(
  2051. "movi v4.8b, #25 \n" // B * 0.1016 coefficient
  2052. "movi v5.8b, #129 \n" // G * 0.5078 coefficient
  2053. "movi v6.8b, #66 \n" // R * 0.2578 coefficient
  2054. "movi v7.8b, #16 \n" // Add 16 constant
  2055. "1: \n"
  2056. "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // load 8 pixels.
  2057. "prfm pldl1keep, [%0, 448] \n"
  2058. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2059. "umull v16.8h, v0.8b, v4.8b \n" // B
  2060. "umlal v16.8h, v1.8b, v5.8b \n" // G
  2061. "umlal v16.8h, v2.8b, v6.8b \n" // R
  2062. "uqrshrn v0.8b, v16.8h, #8 \n" // 16 bit to 8 bit Y
  2063. "uqadd v0.8b, v0.8b, v7.8b \n"
  2064. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  2065. "b.gt 1b \n"
  2066. : "+r"(src_rgb24), // %0
  2067. "+r"(dst_y), // %1
  2068. "+r"(width) // %2
  2069. :
  2070. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16");
  2071. }
  2072. void RAWToYRow_NEON(const uint8_t* src_raw, uint8_t* dst_y, int width) {
  2073. asm volatile(
  2074. "movi v6.8b, #25 \n" // B * 0.1016 coefficient
  2075. "movi v5.8b, #129 \n" // G * 0.5078 coefficient
  2076. "movi v4.8b, #66 \n" // R * 0.2578 coefficient
  2077. "movi v7.8b, #16 \n" // Add 16 constant
  2078. "1: \n"
  2079. "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // load 8 pixels.
  2080. "prfm pldl1keep, [%0, 448] \n"
  2081. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2082. "umull v16.8h, v0.8b, v4.8b \n" // B
  2083. "umlal v16.8h, v1.8b, v5.8b \n" // G
  2084. "umlal v16.8h, v2.8b, v6.8b \n" // R
  2085. "uqrshrn v0.8b, v16.8h, #8 \n" // 16 bit to 8 bit Y
  2086. "uqadd v0.8b, v0.8b, v7.8b \n"
  2087. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  2088. "b.gt 1b \n"
  2089. : "+r"(src_raw), // %0
  2090. "+r"(dst_y), // %1
  2091. "+r"(width) // %2
  2092. :
  2093. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16");
  2094. }
  2095. void RGB24ToYJRow_NEON(const uint8_t* src_rgb24, uint8_t* dst_yj, int width) {
  2096. asm volatile(
  2097. "movi v4.8b, #29 \n" // B * 0.1140 coefficient
  2098. "movi v5.8b, #150 \n" // G * 0.5870 coefficient
  2099. "movi v6.8b, #77 \n" // R * 0.2990 coefficient
  2100. "1: \n"
  2101. "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // load 8 pixels.
  2102. "prfm pldl1keep, [%0, 448] \n"
  2103. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2104. "umull v0.8h, v0.8b, v4.8b \n" // B
  2105. "umlal v0.8h, v1.8b, v5.8b \n" // G
  2106. "umlal v0.8h, v2.8b, v6.8b \n" // R
  2107. "uqrshrn v0.8b, v0.8h, #8 \n" // 16 bit to 8 bit Y
  2108. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  2109. "b.gt 1b \n"
  2110. : "+r"(src_rgb24), // %0
  2111. "+r"(dst_yj), // %1
  2112. "+r"(width) // %2
  2113. :
  2114. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6");
  2115. }
  2116. void RAWToYJRow_NEON(const uint8_t* src_raw, uint8_t* dst_yj, int width) {
  2117. asm volatile(
  2118. "movi v6.8b, #29 \n" // B * 0.1140 coefficient
  2119. "movi v5.8b, #150 \n" // G * 0.5870 coefficient
  2120. "movi v4.8b, #77 \n" // R * 0.2990 coefficient
  2121. "1: \n"
  2122. "ld3 {v0.8b,v1.8b,v2.8b}, [%0], #24 \n" // load 8 pixels.
  2123. "prfm pldl1keep, [%0, 448] \n"
  2124. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2125. "umull v0.8h, v0.8b, v4.8b \n" // B
  2126. "umlal v0.8h, v1.8b, v5.8b \n" // G
  2127. "umlal v0.8h, v2.8b, v6.8b \n" // R
  2128. "uqrshrn v0.8b, v0.8h, #8 \n" // 16 bit to 8 bit Y
  2129. "st1 {v0.8b}, [%1], #8 \n" // store 8 pixels Y.
  2130. "b.gt 1b \n"
  2131. : "+r"(src_raw), // %0
  2132. "+r"(dst_yj), // %1
  2133. "+r"(width) // %2
  2134. :
  2135. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6");
  2136. }
  2137. // Bilinear filter 16x2 -> 16x1
  2138. void InterpolateRow_NEON(uint8_t* dst_ptr,
  2139. const uint8_t* src_ptr,
  2140. ptrdiff_t src_stride,
  2141. int dst_width,
  2142. int source_y_fraction) {
  2143. int y1_fraction = source_y_fraction;
  2144. int y0_fraction = 256 - y1_fraction;
  2145. const uint8_t* src_ptr1 = src_ptr + src_stride;
  2146. asm volatile(
  2147. "cmp %w4, #0 \n"
  2148. "b.eq 100f \n"
  2149. "cmp %w4, #128 \n"
  2150. "b.eq 50f \n"
  2151. "dup v5.16b, %w4 \n"
  2152. "dup v4.16b, %w5 \n"
  2153. // General purpose row blend.
  2154. "1: \n"
  2155. "ld1 {v0.16b}, [%1], #16 \n"
  2156. "ld1 {v1.16b}, [%2], #16 \n"
  2157. "prfm pldl1keep, [%1, 448] \n"
  2158. "prfm pldl1keep, [%2, 448] \n"
  2159. "subs %w3, %w3, #16 \n"
  2160. "umull v2.8h, v0.8b, v4.8b \n"
  2161. "umull2 v3.8h, v0.16b, v4.16b \n"
  2162. "umlal v2.8h, v1.8b, v5.8b \n"
  2163. "umlal2 v3.8h, v1.16b, v5.16b \n"
  2164. "rshrn v0.8b, v2.8h, #8 \n"
  2165. "rshrn2 v0.16b, v3.8h, #8 \n"
  2166. "st1 {v0.16b}, [%0], #16 \n"
  2167. "b.gt 1b \n"
  2168. "b 99f \n"
  2169. // Blend 50 / 50.
  2170. "50: \n"
  2171. "ld1 {v0.16b}, [%1], #16 \n"
  2172. "ld1 {v1.16b}, [%2], #16 \n"
  2173. "prfm pldl1keep, [%1, 448] \n"
  2174. "prfm pldl1keep, [%2, 448] \n"
  2175. "subs %w3, %w3, #16 \n"
  2176. "urhadd v0.16b, v0.16b, v1.16b \n"
  2177. "st1 {v0.16b}, [%0], #16 \n"
  2178. "b.gt 50b \n"
  2179. "b 99f \n"
  2180. // Blend 100 / 0 - Copy row unchanged.
  2181. "100: \n"
  2182. "ld1 {v0.16b}, [%1], #16 \n"
  2183. "prfm pldl1keep, [%1, 448] \n"
  2184. "subs %w3, %w3, #16 \n"
  2185. "st1 {v0.16b}, [%0], #16 \n"
  2186. "b.gt 100b \n"
  2187. "99: \n"
  2188. : "+r"(dst_ptr), // %0
  2189. "+r"(src_ptr), // %1
  2190. "+r"(src_ptr1), // %2
  2191. "+r"(dst_width), // %3
  2192. "+r"(y1_fraction), // %4
  2193. "+r"(y0_fraction) // %5
  2194. :
  2195. : "cc", "memory", "v0", "v1", "v3", "v4", "v5");
  2196. }
  2197. // dr * (256 - sa) / 256 + sr = dr - dr * sa / 256 + sr
  2198. void ARGBBlendRow_NEON(const uint8_t* src_argb0,
  2199. const uint8_t* src_argb1,
  2200. uint8_t* dst_argb,
  2201. int width) {
  2202. asm volatile(
  2203. "subs %w3, %w3, #8 \n"
  2204. "b.lt 89f \n"
  2205. // Blend 8 pixels.
  2206. "8: \n"
  2207. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB0
  2208. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 ARGB1
  2209. "prfm pldl1keep, [%0, 448] \n"
  2210. "prfm pldl1keep, [%1, 448] \n"
  2211. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  2212. "umull v16.8h, v4.8b, v3.8b \n" // db * a
  2213. "umull v17.8h, v5.8b, v3.8b \n" // dg * a
  2214. "umull v18.8h, v6.8b, v3.8b \n" // dr * a
  2215. "uqrshrn v16.8b, v16.8h, #8 \n" // db >>= 8
  2216. "uqrshrn v17.8b, v17.8h, #8 \n" // dg >>= 8
  2217. "uqrshrn v18.8b, v18.8h, #8 \n" // dr >>= 8
  2218. "uqsub v4.8b, v4.8b, v16.8b \n" // db - (db * a / 256)
  2219. "uqsub v5.8b, v5.8b, v17.8b \n" // dg - (dg * a / 256)
  2220. "uqsub v6.8b, v6.8b, v18.8b \n" // dr - (dr * a / 256)
  2221. "uqadd v0.8b, v0.8b, v4.8b \n" // + sb
  2222. "uqadd v1.8b, v1.8b, v5.8b \n" // + sg
  2223. "uqadd v2.8b, v2.8b, v6.8b \n" // + sr
  2224. "movi v3.8b, #255 \n" // a = 255
  2225. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB
  2226. // pixels
  2227. "b.ge 8b \n"
  2228. "89: \n"
  2229. "adds %w3, %w3, #8-1 \n"
  2230. "b.lt 99f \n"
  2231. // Blend 1 pixels.
  2232. "1: \n"
  2233. "ld4 {v0.b,v1.b,v2.b,v3.b}[0], [%0], #4 \n" // load 1 pixel ARGB0.
  2234. "ld4 {v4.b,v5.b,v6.b,v7.b}[0], [%1], #4 \n" // load 1 pixel ARGB1.
  2235. "prfm pldl1keep, [%0, 448] \n"
  2236. "prfm pldl1keep, [%1, 448] \n"
  2237. "subs %w3, %w3, #1 \n" // 1 processed per loop.
  2238. "umull v16.8h, v4.8b, v3.8b \n" // db * a
  2239. "umull v17.8h, v5.8b, v3.8b \n" // dg * a
  2240. "umull v18.8h, v6.8b, v3.8b \n" // dr * a
  2241. "uqrshrn v16.8b, v16.8h, #8 \n" // db >>= 8
  2242. "uqrshrn v17.8b, v17.8h, #8 \n" // dg >>= 8
  2243. "uqrshrn v18.8b, v18.8h, #8 \n" // dr >>= 8
  2244. "uqsub v4.8b, v4.8b, v16.8b \n" // db - (db * a / 256)
  2245. "uqsub v5.8b, v5.8b, v17.8b \n" // dg - (dg * a / 256)
  2246. "uqsub v6.8b, v6.8b, v18.8b \n" // dr - (dr * a / 256)
  2247. "uqadd v0.8b, v0.8b, v4.8b \n" // + sb
  2248. "uqadd v1.8b, v1.8b, v5.8b \n" // + sg
  2249. "uqadd v2.8b, v2.8b, v6.8b \n" // + sr
  2250. "movi v3.8b, #255 \n" // a = 255
  2251. "st4 {v0.b,v1.b,v2.b,v3.b}[0], [%2], #4 \n" // store 1 pixel.
  2252. "b.ge 1b \n"
  2253. "99: \n"
  2254. : "+r"(src_argb0), // %0
  2255. "+r"(src_argb1), // %1
  2256. "+r"(dst_argb), // %2
  2257. "+r"(width) // %3
  2258. :
  2259. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16",
  2260. "v17", "v18");
  2261. }
  2262. // Attenuate 8 pixels at a time.
  2263. void ARGBAttenuateRow_NEON(const uint8_t* src_argb,
  2264. uint8_t* dst_argb,
  2265. int width) {
  2266. asm volatile(
  2267. // Attenuate 8 pixels.
  2268. "1: \n"
  2269. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB
  2270. "prfm pldl1keep, [%0, 448] \n"
  2271. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2272. "umull v4.8h, v0.8b, v3.8b \n" // b * a
  2273. "umull v5.8h, v1.8b, v3.8b \n" // g * a
  2274. "umull v6.8h, v2.8b, v3.8b \n" // r * a
  2275. "uqrshrn v0.8b, v4.8h, #8 \n" // b >>= 8
  2276. "uqrshrn v1.8b, v5.8h, #8 \n" // g >>= 8
  2277. "uqrshrn v2.8b, v6.8h, #8 \n" // r >>= 8
  2278. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 ARGB
  2279. "b.gt 1b \n"
  2280. : "+r"(src_argb), // %0
  2281. "+r"(dst_argb), // %1
  2282. "+r"(width) // %2
  2283. :
  2284. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6");
  2285. }
  2286. // Quantize 8 ARGB pixels (32 bytes).
  2287. // dst = (dst * scale >> 16) * interval_size + interval_offset;
  2288. void ARGBQuantizeRow_NEON(uint8_t* dst_argb,
  2289. int scale,
  2290. int interval_size,
  2291. int interval_offset,
  2292. int width) {
  2293. asm volatile(
  2294. "dup v4.8h, %w2 \n"
  2295. "ushr v4.8h, v4.8h, #1 \n" // scale >>= 1
  2296. "dup v5.8h, %w3 \n" // interval multiply.
  2297. "dup v6.8h, %w4 \n" // interval add
  2298. // 8 pixel loop.
  2299. "1: \n"
  2300. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0] \n" // load 8 ARGB.
  2301. "prfm pldl1keep, [%0, 448] \n"
  2302. "subs %w1, %w1, #8 \n" // 8 processed per loop.
  2303. "uxtl v0.8h, v0.8b \n" // b (0 .. 255)
  2304. "uxtl v1.8h, v1.8b \n"
  2305. "uxtl v2.8h, v2.8b \n"
  2306. "sqdmulh v0.8h, v0.8h, v4.8h \n" // b * scale
  2307. "sqdmulh v1.8h, v1.8h, v4.8h \n" // g
  2308. "sqdmulh v2.8h, v2.8h, v4.8h \n" // r
  2309. "mul v0.8h, v0.8h, v5.8h \n" // b * interval_size
  2310. "mul v1.8h, v1.8h, v5.8h \n" // g
  2311. "mul v2.8h, v2.8h, v5.8h \n" // r
  2312. "add v0.8h, v0.8h, v6.8h \n" // b + interval_offset
  2313. "add v1.8h, v1.8h, v6.8h \n" // g
  2314. "add v2.8h, v2.8h, v6.8h \n" // r
  2315. "uqxtn v0.8b, v0.8h \n"
  2316. "uqxtn v1.8b, v1.8h \n"
  2317. "uqxtn v2.8b, v2.8h \n"
  2318. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // store 8 ARGB
  2319. "b.gt 1b \n"
  2320. : "+r"(dst_argb), // %0
  2321. "+r"(width) // %1
  2322. : "r"(scale), // %2
  2323. "r"(interval_size), // %3
  2324. "r"(interval_offset) // %4
  2325. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6");
  2326. }
  2327. // Shade 8 pixels at a time by specified value.
  2328. // NOTE vqrdmulh.s16 q10, q10, d0[0] must use a scaler register from 0 to 8.
  2329. // Rounding in vqrdmulh does +1 to high if high bit of low s16 is set.
  2330. void ARGBShadeRow_NEON(const uint8_t* src_argb,
  2331. uint8_t* dst_argb,
  2332. int width,
  2333. uint32_t value) {
  2334. asm volatile(
  2335. "dup v0.4s, %w3 \n" // duplicate scale value.
  2336. "zip1 v0.8b, v0.8b, v0.8b \n" // v0.8b aarrggbb.
  2337. "ushr v0.8h, v0.8h, #1 \n" // scale / 2.
  2338. // 8 pixel loop.
  2339. "1: \n"
  2340. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%0], #32 \n" // load 8 ARGB
  2341. "prfm pldl1keep, [%0, 448] \n"
  2342. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2343. "uxtl v4.8h, v4.8b \n" // b (0 .. 255)
  2344. "uxtl v5.8h, v5.8b \n"
  2345. "uxtl v6.8h, v6.8b \n"
  2346. "uxtl v7.8h, v7.8b \n"
  2347. "sqrdmulh v4.8h, v4.8h, v0.h[0] \n" // b * scale * 2
  2348. "sqrdmulh v5.8h, v5.8h, v0.h[1] \n" // g
  2349. "sqrdmulh v6.8h, v6.8h, v0.h[2] \n" // r
  2350. "sqrdmulh v7.8h, v7.8h, v0.h[3] \n" // a
  2351. "uqxtn v4.8b, v4.8h \n"
  2352. "uqxtn v5.8b, v5.8h \n"
  2353. "uqxtn v6.8b, v6.8h \n"
  2354. "uqxtn v7.8b, v7.8h \n"
  2355. "st4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // store 8 ARGB
  2356. "b.gt 1b \n"
  2357. : "+r"(src_argb), // %0
  2358. "+r"(dst_argb), // %1
  2359. "+r"(width) // %2
  2360. : "r"(value) // %3
  2361. : "cc", "memory", "v0", "v4", "v5", "v6", "v7");
  2362. }
  2363. // Convert 8 ARGB pixels (64 bytes) to 8 Gray ARGB pixels
  2364. // Similar to ARGBToYJ but stores ARGB.
  2365. // C code is (29 * b + 150 * g + 77 * r + 128) >> 8;
  2366. void ARGBGrayRow_NEON(const uint8_t* src_argb, uint8_t* dst_argb, int width) {
  2367. asm volatile(
  2368. "movi v24.8b, #29 \n" // B * 0.1140 coefficient
  2369. "movi v25.8b, #150 \n" // G * 0.5870 coefficient
  2370. "movi v26.8b, #77 \n" // R * 0.2990 coefficient
  2371. "1: \n"
  2372. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB
  2373. "prfm pldl1keep, [%0, 448] \n"
  2374. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2375. "umull v4.8h, v0.8b, v24.8b \n" // B
  2376. "umlal v4.8h, v1.8b, v25.8b \n" // G
  2377. "umlal v4.8h, v2.8b, v26.8b \n" // R
  2378. "uqrshrn v0.8b, v4.8h, #8 \n" // 16 bit to 8 bit B
  2379. "orr v1.8b, v0.8b, v0.8b \n" // G
  2380. "orr v2.8b, v0.8b, v0.8b \n" // R
  2381. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%1], #32 \n" // store 8 pixels.
  2382. "b.gt 1b \n"
  2383. : "+r"(src_argb), // %0
  2384. "+r"(dst_argb), // %1
  2385. "+r"(width) // %2
  2386. :
  2387. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v24", "v25", "v26");
  2388. }
  2389. // Convert 8 ARGB pixels (32 bytes) to 8 Sepia ARGB pixels.
  2390. // b = (r * 35 + g * 68 + b * 17) >> 7
  2391. // g = (r * 45 + g * 88 + b * 22) >> 7
  2392. // r = (r * 50 + g * 98 + b * 24) >> 7
  2393. void ARGBSepiaRow_NEON(uint8_t* dst_argb, int width) {
  2394. asm volatile(
  2395. "movi v20.8b, #17 \n" // BB coefficient
  2396. "movi v21.8b, #68 \n" // BG coefficient
  2397. "movi v22.8b, #35 \n" // BR coefficient
  2398. "movi v24.8b, #22 \n" // GB coefficient
  2399. "movi v25.8b, #88 \n" // GG coefficient
  2400. "movi v26.8b, #45 \n" // GR coefficient
  2401. "movi v28.8b, #24 \n" // BB coefficient
  2402. "movi v29.8b, #98 \n" // BG coefficient
  2403. "movi v30.8b, #50 \n" // BR coefficient
  2404. "1: \n"
  2405. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0] \n" // load 8 ARGB pixels.
  2406. "prfm pldl1keep, [%0, 448] \n"
  2407. "subs %w1, %w1, #8 \n" // 8 processed per loop.
  2408. "umull v4.8h, v0.8b, v20.8b \n" // B to Sepia B
  2409. "umlal v4.8h, v1.8b, v21.8b \n" // G
  2410. "umlal v4.8h, v2.8b, v22.8b \n" // R
  2411. "umull v5.8h, v0.8b, v24.8b \n" // B to Sepia G
  2412. "umlal v5.8h, v1.8b, v25.8b \n" // G
  2413. "umlal v5.8h, v2.8b, v26.8b \n" // R
  2414. "umull v6.8h, v0.8b, v28.8b \n" // B to Sepia R
  2415. "umlal v6.8h, v1.8b, v29.8b \n" // G
  2416. "umlal v6.8h, v2.8b, v30.8b \n" // R
  2417. "uqshrn v0.8b, v4.8h, #7 \n" // 16 bit to 8 bit B
  2418. "uqshrn v1.8b, v5.8h, #7 \n" // 16 bit to 8 bit G
  2419. "uqshrn v2.8b, v6.8h, #7 \n" // 16 bit to 8 bit R
  2420. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // store 8 pixels.
  2421. "b.gt 1b \n"
  2422. : "+r"(dst_argb), // %0
  2423. "+r"(width) // %1
  2424. :
  2425. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v20",
  2426. "v21", "v22", "v24", "v25", "v26", "v28", "v29", "v30");
  2427. }
  2428. // Tranform 8 ARGB pixels (32 bytes) with color matrix.
  2429. // TODO(fbarchard): Was same as Sepia except matrix is provided. This function
  2430. // needs to saturate. Consider doing a non-saturating version.
  2431. void ARGBColorMatrixRow_NEON(const uint8_t* src_argb,
  2432. uint8_t* dst_argb,
  2433. const int8_t* matrix_argb,
  2434. int width) {
  2435. asm volatile(
  2436. "ld1 {v2.16b}, [%3] \n" // load 3 ARGB vectors.
  2437. "sxtl v0.8h, v2.8b \n" // B,G coefficients s16.
  2438. "sxtl2 v1.8h, v2.16b \n" // R,A coefficients s16.
  2439. "1: \n"
  2440. "ld4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%0], #32 \n" // load 8 ARGB
  2441. "prfm pldl1keep, [%0, 448] \n"
  2442. "subs %w2, %w2, #8 \n" // 8 processed per loop.
  2443. "uxtl v16.8h, v16.8b \n" // b (0 .. 255) 16 bit
  2444. "uxtl v17.8h, v17.8b \n" // g
  2445. "uxtl v18.8h, v18.8b \n" // r
  2446. "uxtl v19.8h, v19.8b \n" // a
  2447. "mul v22.8h, v16.8h, v0.h[0] \n" // B = B * Matrix B
  2448. "mul v23.8h, v16.8h, v0.h[4] \n" // G = B * Matrix G
  2449. "mul v24.8h, v16.8h, v1.h[0] \n" // R = B * Matrix R
  2450. "mul v25.8h, v16.8h, v1.h[4] \n" // A = B * Matrix A
  2451. "mul v4.8h, v17.8h, v0.h[1] \n" // B += G * Matrix B
  2452. "mul v5.8h, v17.8h, v0.h[5] \n" // G += G * Matrix G
  2453. "mul v6.8h, v17.8h, v1.h[1] \n" // R += G * Matrix R
  2454. "mul v7.8h, v17.8h, v1.h[5] \n" // A += G * Matrix A
  2455. "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B
  2456. "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G
  2457. "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R
  2458. "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A
  2459. "mul v4.8h, v18.8h, v0.h[2] \n" // B += R * Matrix B
  2460. "mul v5.8h, v18.8h, v0.h[6] \n" // G += R * Matrix G
  2461. "mul v6.8h, v18.8h, v1.h[2] \n" // R += R * Matrix R
  2462. "mul v7.8h, v18.8h, v1.h[6] \n" // A += R * Matrix A
  2463. "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B
  2464. "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G
  2465. "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R
  2466. "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A
  2467. "mul v4.8h, v19.8h, v0.h[3] \n" // B += A * Matrix B
  2468. "mul v5.8h, v19.8h, v0.h[7] \n" // G += A * Matrix G
  2469. "mul v6.8h, v19.8h, v1.h[3] \n" // R += A * Matrix R
  2470. "mul v7.8h, v19.8h, v1.h[7] \n" // A += A * Matrix A
  2471. "sqadd v22.8h, v22.8h, v4.8h \n" // Accumulate B
  2472. "sqadd v23.8h, v23.8h, v5.8h \n" // Accumulate G
  2473. "sqadd v24.8h, v24.8h, v6.8h \n" // Accumulate R
  2474. "sqadd v25.8h, v25.8h, v7.8h \n" // Accumulate A
  2475. "sqshrun v16.8b, v22.8h, #6 \n" // 16 bit to 8 bit B
  2476. "sqshrun v17.8b, v23.8h, #6 \n" // 16 bit to 8 bit G
  2477. "sqshrun v18.8b, v24.8h, #6 \n" // 16 bit to 8 bit R
  2478. "sqshrun v19.8b, v25.8h, #6 \n" // 16 bit to 8 bit A
  2479. "st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [%1], #32 \n" // store 8 ARGB
  2480. "b.gt 1b \n"
  2481. : "+r"(src_argb), // %0
  2482. "+r"(dst_argb), // %1
  2483. "+r"(width) // %2
  2484. : "r"(matrix_argb) // %3
  2485. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16",
  2486. "v17", "v18", "v19", "v22", "v23", "v24", "v25");
  2487. }
  2488. // TODO(fbarchard): fix vqshrun in ARGBMultiplyRow_NEON and reenable.
  2489. // Multiply 2 rows of ARGB pixels together, 8 pixels at a time.
  2490. void ARGBMultiplyRow_NEON(const uint8_t* src_argb0,
  2491. const uint8_t* src_argb1,
  2492. uint8_t* dst_argb,
  2493. int width) {
  2494. asm volatile(
  2495. // 8 pixel loop.
  2496. "1: \n"
  2497. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB
  2498. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 more
  2499. "prfm pldl1keep, [%0, 448] \n"
  2500. "prfm pldl1keep, [%1, 448] \n"
  2501. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  2502. "umull v0.8h, v0.8b, v4.8b \n" // multiply B
  2503. "umull v1.8h, v1.8b, v5.8b \n" // multiply G
  2504. "umull v2.8h, v2.8b, v6.8b \n" // multiply R
  2505. "umull v3.8h, v3.8b, v7.8b \n" // multiply A
  2506. "rshrn v0.8b, v0.8h, #8 \n" // 16 bit to 8 bit B
  2507. "rshrn v1.8b, v1.8h, #8 \n" // 16 bit to 8 bit G
  2508. "rshrn v2.8b, v2.8h, #8 \n" // 16 bit to 8 bit R
  2509. "rshrn v3.8b, v3.8h, #8 \n" // 16 bit to 8 bit A
  2510. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB
  2511. "b.gt 1b \n"
  2512. : "+r"(src_argb0), // %0
  2513. "+r"(src_argb1), // %1
  2514. "+r"(dst_argb), // %2
  2515. "+r"(width) // %3
  2516. :
  2517. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  2518. }
  2519. // Add 2 rows of ARGB pixels together, 8 pixels at a time.
  2520. void ARGBAddRow_NEON(const uint8_t* src_argb0,
  2521. const uint8_t* src_argb1,
  2522. uint8_t* dst_argb,
  2523. int width) {
  2524. asm volatile(
  2525. // 8 pixel loop.
  2526. "1: \n"
  2527. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB
  2528. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 more
  2529. "prfm pldl1keep, [%0, 448] \n"
  2530. "prfm pldl1keep, [%1, 448] \n"
  2531. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  2532. "uqadd v0.8b, v0.8b, v4.8b \n"
  2533. "uqadd v1.8b, v1.8b, v5.8b \n"
  2534. "uqadd v2.8b, v2.8b, v6.8b \n"
  2535. "uqadd v3.8b, v3.8b, v7.8b \n"
  2536. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB
  2537. "b.gt 1b \n"
  2538. : "+r"(src_argb0), // %0
  2539. "+r"(src_argb1), // %1
  2540. "+r"(dst_argb), // %2
  2541. "+r"(width) // %3
  2542. :
  2543. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  2544. }
  2545. // Subtract 2 rows of ARGB pixels, 8 pixels at a time.
  2546. void ARGBSubtractRow_NEON(const uint8_t* src_argb0,
  2547. const uint8_t* src_argb1,
  2548. uint8_t* dst_argb,
  2549. int width) {
  2550. asm volatile(
  2551. // 8 pixel loop.
  2552. "1: \n"
  2553. "ld4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%0], #32 \n" // load 8 ARGB
  2554. "ld4 {v4.8b,v5.8b,v6.8b,v7.8b}, [%1], #32 \n" // load 8 more
  2555. "prfm pldl1keep, [%0, 448] \n"
  2556. "prfm pldl1keep, [%1, 448] \n"
  2557. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  2558. "uqsub v0.8b, v0.8b, v4.8b \n"
  2559. "uqsub v1.8b, v1.8b, v5.8b \n"
  2560. "uqsub v2.8b, v2.8b, v6.8b \n"
  2561. "uqsub v3.8b, v3.8b, v7.8b \n"
  2562. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB
  2563. "b.gt 1b \n"
  2564. : "+r"(src_argb0), // %0
  2565. "+r"(src_argb1), // %1
  2566. "+r"(dst_argb), // %2
  2567. "+r"(width) // %3
  2568. :
  2569. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  2570. }
  2571. // Adds Sobel X and Sobel Y and stores Sobel into ARGB.
  2572. // A = 255
  2573. // R = Sobel
  2574. // G = Sobel
  2575. // B = Sobel
  2576. void SobelRow_NEON(const uint8_t* src_sobelx,
  2577. const uint8_t* src_sobely,
  2578. uint8_t* dst_argb,
  2579. int width) {
  2580. asm volatile(
  2581. "movi v3.8b, #255 \n" // alpha
  2582. // 8 pixel loop.
  2583. "1: \n"
  2584. "ld1 {v0.8b}, [%0], #8 \n" // load 8 sobelx.
  2585. "ld1 {v1.8b}, [%1], #8 \n" // load 8 sobely.
  2586. "prfm pldl1keep, [%0, 448] \n"
  2587. "prfm pldl1keep, [%1, 448] \n"
  2588. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  2589. "uqadd v0.8b, v0.8b, v1.8b \n" // add
  2590. "orr v1.8b, v0.8b, v0.8b \n"
  2591. "orr v2.8b, v0.8b, v0.8b \n"
  2592. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB
  2593. "b.gt 1b \n"
  2594. : "+r"(src_sobelx), // %0
  2595. "+r"(src_sobely), // %1
  2596. "+r"(dst_argb), // %2
  2597. "+r"(width) // %3
  2598. :
  2599. : "cc", "memory", "v0", "v1", "v2", "v3");
  2600. }
  2601. // Adds Sobel X and Sobel Y and stores Sobel into plane.
  2602. void SobelToPlaneRow_NEON(const uint8_t* src_sobelx,
  2603. const uint8_t* src_sobely,
  2604. uint8_t* dst_y,
  2605. int width) {
  2606. asm volatile(
  2607. // 16 pixel loop.
  2608. "1: \n"
  2609. "ld1 {v0.16b}, [%0], #16 \n" // load 16 sobelx.
  2610. "ld1 {v1.16b}, [%1], #16 \n" // load 16 sobely.
  2611. "prfm pldl1keep, [%0, 448] \n"
  2612. "prfm pldl1keep, [%1, 448] \n"
  2613. "subs %w3, %w3, #16 \n" // 16 processed per loop.
  2614. "uqadd v0.16b, v0.16b, v1.16b \n" // add
  2615. "st1 {v0.16b}, [%2], #16 \n" // store 16 pixels.
  2616. "b.gt 1b \n"
  2617. : "+r"(src_sobelx), // %0
  2618. "+r"(src_sobely), // %1
  2619. "+r"(dst_y), // %2
  2620. "+r"(width) // %3
  2621. :
  2622. : "cc", "memory", "v0", "v1");
  2623. }
  2624. // Mixes Sobel X, Sobel Y and Sobel into ARGB.
  2625. // A = 255
  2626. // R = Sobel X
  2627. // G = Sobel
  2628. // B = Sobel Y
  2629. void SobelXYRow_NEON(const uint8_t* src_sobelx,
  2630. const uint8_t* src_sobely,
  2631. uint8_t* dst_argb,
  2632. int width) {
  2633. asm volatile(
  2634. "movi v3.8b, #255 \n" // alpha
  2635. // 8 pixel loop.
  2636. "1: \n"
  2637. "ld1 {v2.8b}, [%0], #8 \n" // load 8 sobelx.
  2638. "ld1 {v0.8b}, [%1], #8 \n" // load 8 sobely.
  2639. "prfm pldl1keep, [%0, 448] \n"
  2640. "prfm pldl1keep, [%1, 448] \n"
  2641. "subs %w3, %w3, #8 \n" // 8 processed per loop.
  2642. "uqadd v1.8b, v0.8b, v2.8b \n" // add
  2643. "st4 {v0.8b,v1.8b,v2.8b,v3.8b}, [%2], #32 \n" // store 8 ARGB
  2644. "b.gt 1b \n"
  2645. : "+r"(src_sobelx), // %0
  2646. "+r"(src_sobely), // %1
  2647. "+r"(dst_argb), // %2
  2648. "+r"(width) // %3
  2649. :
  2650. : "cc", "memory", "v0", "v1", "v2", "v3");
  2651. }
  2652. // SobelX as a matrix is
  2653. // -1 0 1
  2654. // -2 0 2
  2655. // -1 0 1
  2656. void SobelXRow_NEON(const uint8_t* src_y0,
  2657. const uint8_t* src_y1,
  2658. const uint8_t* src_y2,
  2659. uint8_t* dst_sobelx,
  2660. int width) {
  2661. asm volatile(
  2662. "1: \n"
  2663. "ld1 {v0.8b}, [%0],%5 \n" // top
  2664. "ld1 {v1.8b}, [%0],%6 \n"
  2665. "prfm pldl1keep, [%0, 448] \n"
  2666. "usubl v0.8h, v0.8b, v1.8b \n"
  2667. "ld1 {v2.8b}, [%1],%5 \n" // center * 2
  2668. "ld1 {v3.8b}, [%1],%6 \n"
  2669. "prfm pldl1keep, [%1, 448] \n"
  2670. "usubl v1.8h, v2.8b, v3.8b \n"
  2671. "add v0.8h, v0.8h, v1.8h \n"
  2672. "add v0.8h, v0.8h, v1.8h \n"
  2673. "ld1 {v2.8b}, [%2],%5 \n" // bottom
  2674. "ld1 {v3.8b}, [%2],%6 \n"
  2675. "prfm pldl1keep, [%2, 448] \n"
  2676. "subs %w4, %w4, #8 \n" // 8 pixels
  2677. "usubl v1.8h, v2.8b, v3.8b \n"
  2678. "add v0.8h, v0.8h, v1.8h \n"
  2679. "abs v0.8h, v0.8h \n"
  2680. "uqxtn v0.8b, v0.8h \n"
  2681. "st1 {v0.8b}, [%3], #8 \n" // store 8 sobelx
  2682. "b.gt 1b \n"
  2683. : "+r"(src_y0), // %0
  2684. "+r"(src_y1), // %1
  2685. "+r"(src_y2), // %2
  2686. "+r"(dst_sobelx), // %3
  2687. "+r"(width) // %4
  2688. : "r"(2LL), // %5
  2689. "r"(6LL) // %6
  2690. : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List
  2691. );
  2692. }
  2693. // SobelY as a matrix is
  2694. // -1 -2 -1
  2695. // 0 0 0
  2696. // 1 2 1
  2697. void SobelYRow_NEON(const uint8_t* src_y0,
  2698. const uint8_t* src_y1,
  2699. uint8_t* dst_sobely,
  2700. int width) {
  2701. asm volatile(
  2702. "1: \n"
  2703. "ld1 {v0.8b}, [%0],%4 \n" // left
  2704. "ld1 {v1.8b}, [%1],%4 \n"
  2705. "usubl v0.8h, v0.8b, v1.8b \n"
  2706. "ld1 {v2.8b}, [%0],%4 \n" // center * 2
  2707. "ld1 {v3.8b}, [%1],%4 \n"
  2708. "usubl v1.8h, v2.8b, v3.8b \n"
  2709. "add v0.8h, v0.8h, v1.8h \n"
  2710. "add v0.8h, v0.8h, v1.8h \n"
  2711. "ld1 {v2.8b}, [%0],%5 \n" // right
  2712. "ld1 {v3.8b}, [%1],%5 \n"
  2713. "prfm pldl1keep, [%0, 448] \n"
  2714. "prfm pldl1keep, [%1, 448] \n"
  2715. "subs %w3, %w3, #8 \n" // 8 pixels
  2716. "usubl v1.8h, v2.8b, v3.8b \n"
  2717. "add v0.8h, v0.8h, v1.8h \n"
  2718. "abs v0.8h, v0.8h \n"
  2719. "uqxtn v0.8b, v0.8h \n"
  2720. "st1 {v0.8b}, [%2], #8 \n" // store 8 sobely
  2721. "b.gt 1b \n"
  2722. : "+r"(src_y0), // %0
  2723. "+r"(src_y1), // %1
  2724. "+r"(dst_sobely), // %2
  2725. "+r"(width) // %3
  2726. : "r"(1LL), // %4
  2727. "r"(6LL) // %5
  2728. : "cc", "memory", "v0", "v1", "v2", "v3" // Clobber List
  2729. );
  2730. }
  2731. // Caveat - rounds float to half float whereas scaling version truncates.
  2732. void HalfFloat1Row_NEON(const uint16_t* src,
  2733. uint16_t* dst,
  2734. float /*unused*/,
  2735. int width) {
  2736. asm volatile(
  2737. "1: \n"
  2738. "ld1 {v1.16b}, [%0], #16 \n" // load 8 shorts
  2739. "prfm pldl1keep, [%0, 448] \n"
  2740. "subs %w2, %w2, #8 \n" // 8 pixels per loop
  2741. "uxtl v2.4s, v1.4h \n" // 8 int's
  2742. "uxtl2 v3.4s, v1.8h \n"
  2743. "scvtf v2.4s, v2.4s \n" // 8 floats
  2744. "scvtf v3.4s, v3.4s \n"
  2745. "fcvtn v1.4h, v2.4s \n" // 8 half floats
  2746. "fcvtn2 v1.8h, v3.4s \n"
  2747. "st1 {v1.16b}, [%1], #16 \n" // store 8 shorts
  2748. "b.gt 1b \n"
  2749. : "+r"(src), // %0
  2750. "+r"(dst), // %1
  2751. "+r"(width) // %2
  2752. :
  2753. : "cc", "memory", "v1", "v2", "v3");
  2754. }
  2755. void HalfFloatRow_NEON(const uint16_t* src,
  2756. uint16_t* dst,
  2757. float scale,
  2758. int width) {
  2759. asm volatile(
  2760. "1: \n"
  2761. "ld1 {v1.16b}, [%0], #16 \n" // load 8 shorts
  2762. "prfm pldl1keep, [%0, 448] \n"
  2763. "subs %w2, %w2, #8 \n" // 8 pixels per loop
  2764. "uxtl v2.4s, v1.4h \n" // 8 int's
  2765. "uxtl2 v3.4s, v1.8h \n"
  2766. "scvtf v2.4s, v2.4s \n" // 8 floats
  2767. "scvtf v3.4s, v3.4s \n"
  2768. "fmul v2.4s, v2.4s, %3.s[0] \n" // adjust exponent
  2769. "fmul v3.4s, v3.4s, %3.s[0] \n"
  2770. "uqshrn v1.4h, v2.4s, #13 \n" // isolate halffloat
  2771. "uqshrn2 v1.8h, v3.4s, #13 \n"
  2772. "st1 {v1.16b}, [%1], #16 \n" // store 8 shorts
  2773. "b.gt 1b \n"
  2774. : "+r"(src), // %0
  2775. "+r"(dst), // %1
  2776. "+r"(width) // %2
  2777. : "w"(scale * 1.9259299444e-34f) // %3
  2778. : "cc", "memory", "v1", "v2", "v3");
  2779. }
  2780. void ByteToFloatRow_NEON(const uint8_t* src,
  2781. float* dst,
  2782. float scale,
  2783. int width) {
  2784. asm volatile(
  2785. "1: \n"
  2786. "ld1 {v1.8b}, [%0], #8 \n" // load 8 bytes
  2787. "prfm pldl1keep, [%0, 448] \n"
  2788. "subs %w2, %w2, #8 \n" // 8 pixels per loop
  2789. "uxtl v1.8h, v1.8b \n" // 8 shorts
  2790. "uxtl v2.4s, v1.4h \n" // 8 ints
  2791. "uxtl2 v3.4s, v1.8h \n"
  2792. "scvtf v2.4s, v2.4s \n" // 8 floats
  2793. "scvtf v3.4s, v3.4s \n"
  2794. "fmul v2.4s, v2.4s, %3.s[0] \n" // scale
  2795. "fmul v3.4s, v3.4s, %3.s[0] \n"
  2796. "st1 {v2.16b, v3.16b}, [%1], #32 \n" // store 8 floats
  2797. "b.gt 1b \n"
  2798. : "+r"(src), // %0
  2799. "+r"(dst), // %1
  2800. "+r"(width) // %2
  2801. : "w"(scale) // %3
  2802. : "cc", "memory", "v1", "v2", "v3");
  2803. }
  2804. float ScaleMaxSamples_NEON(const float* src,
  2805. float* dst,
  2806. float scale,
  2807. int width) {
  2808. float fmax;
  2809. asm volatile(
  2810. "movi v5.4s, #0 \n" // max
  2811. "movi v6.4s, #0 \n"
  2812. "1: \n"
  2813. "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples
  2814. "prfm pldl1keep, [%0, 448] \n"
  2815. "subs %w2, %w2, #8 \n" // 8 processed per loop
  2816. "fmul v3.4s, v1.4s, %4.s[0] \n" // scale
  2817. "fmul v4.4s, v2.4s, %4.s[0] \n" // scale
  2818. "fmax v5.4s, v5.4s, v1.4s \n" // max
  2819. "fmax v6.4s, v6.4s, v2.4s \n"
  2820. "st1 {v3.4s, v4.4s}, [%1], #32 \n" // store 8 samples
  2821. "b.gt 1b \n"
  2822. "fmax v5.4s, v5.4s, v6.4s \n" // max
  2823. "fmaxv %s3, v5.4s \n" // signed max acculator
  2824. : "+r"(src), // %0
  2825. "+r"(dst), // %1
  2826. "+r"(width), // %2
  2827. "=w"(fmax) // %3
  2828. : "w"(scale) // %4
  2829. : "cc", "memory", "v1", "v2", "v3", "v4", "v5", "v6");
  2830. return fmax;
  2831. }
  2832. float ScaleSumSamples_NEON(const float* src,
  2833. float* dst,
  2834. float scale,
  2835. int width) {
  2836. float fsum;
  2837. asm volatile(
  2838. "movi v5.4s, #0 \n" // max
  2839. "movi v6.4s, #0 \n" // max
  2840. "1: \n"
  2841. "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples
  2842. "prfm pldl1keep, [%0, 448] \n"
  2843. "subs %w2, %w2, #8 \n" // 8 processed per loop
  2844. "fmul v3.4s, v1.4s, %4.s[0] \n" // scale
  2845. "fmul v4.4s, v2.4s, %4.s[0] \n"
  2846. "fmla v5.4s, v1.4s, v1.4s \n" // sum of squares
  2847. "fmla v6.4s, v2.4s, v2.4s \n"
  2848. "st1 {v3.4s, v4.4s}, [%1], #32 \n" // store 8 samples
  2849. "b.gt 1b \n"
  2850. "faddp v5.4s, v5.4s, v6.4s \n"
  2851. "faddp v5.4s, v5.4s, v5.4s \n"
  2852. "faddp %3.4s, v5.4s, v5.4s \n" // sum
  2853. : "+r"(src), // %0
  2854. "+r"(dst), // %1
  2855. "+r"(width), // %2
  2856. "=w"(fsum) // %3
  2857. : "w"(scale) // %4
  2858. : "cc", "memory", "v1", "v2", "v3", "v4", "v5", "v6");
  2859. return fsum;
  2860. }
  2861. void ScaleSamples_NEON(const float* src, float* dst, float scale, int width) {
  2862. asm volatile(
  2863. "1: \n"
  2864. "ld1 {v1.4s, v2.4s}, [%0], #32 \n" // load 8 samples
  2865. "prfm pldl1keep, [%0, 448] \n"
  2866. "subs %w2, %w2, #8 \n" // 8 processed per loop
  2867. "fmul v1.4s, v1.4s, %3.s[0] \n" // scale
  2868. "fmul v2.4s, v2.4s, %3.s[0] \n" // scale
  2869. "st1 {v1.4s, v2.4s}, [%1], #32 \n" // store 8 samples
  2870. "b.gt 1b \n"
  2871. : "+r"(src), // %0
  2872. "+r"(dst), // %1
  2873. "+r"(width) // %2
  2874. : "w"(scale) // %3
  2875. : "cc", "memory", "v1", "v2");
  2876. }
  2877. // filter 5 rows with 1, 4, 6, 4, 1 coefficients to produce 1 row.
  2878. void GaussCol_NEON(const uint16_t* src0,
  2879. const uint16_t* src1,
  2880. const uint16_t* src2,
  2881. const uint16_t* src3,
  2882. const uint16_t* src4,
  2883. uint32_t* dst,
  2884. int width) {
  2885. asm volatile(
  2886. "movi v6.8h, #4 \n" // constant 4
  2887. "movi v7.8h, #6 \n" // constant 6
  2888. "1: \n"
  2889. "ld1 {v1.8h}, [%0], #16 \n" // load 8 samples, 5 rows
  2890. "ld1 {v2.8h}, [%4], #16 \n"
  2891. "uaddl v0.4s, v1.4h, v2.4h \n" // * 1
  2892. "prfm pldl1keep, [%0, 448] \n"
  2893. "uaddl2 v1.4s, v1.8h, v2.8h \n" // * 1
  2894. "ld1 {v2.8h}, [%1], #16 \n"
  2895. "umlal v0.4s, v2.4h, v6.4h \n" // * 4
  2896. "prfm pldl1keep, [%1, 448] \n"
  2897. "umlal2 v1.4s, v2.8h, v6.8h \n" // * 4
  2898. "ld1 {v2.8h}, [%2], #16 \n"
  2899. "umlal v0.4s, v2.4h, v7.4h \n" // * 6
  2900. "prfm pldl1keep, [%2, 448] \n"
  2901. "umlal2 v1.4s, v2.8h, v7.8h \n" // * 6
  2902. "ld1 {v2.8h}, [%3], #16 \n"
  2903. "umlal v0.4s, v2.4h, v6.4h \n" // * 4
  2904. "prfm pldl1keep, [%3, 448] \n"
  2905. "umlal2 v1.4s, v2.8h, v6.8h \n" // * 4
  2906. "subs %w6, %w6, #8 \n" // 8 processed per loop
  2907. "st1 {v0.4s,v1.4s}, [%5], #32 \n" // store 8 samples
  2908. "prfm pldl1keep, [%4, 448] \n"
  2909. "b.gt 1b \n"
  2910. : "+r"(src0), // %0
  2911. "+r"(src1), // %1
  2912. "+r"(src2), // %2
  2913. "+r"(src3), // %3
  2914. "+r"(src4), // %4
  2915. "+r"(dst), // %5
  2916. "+r"(width) // %6
  2917. :
  2918. : "cc", "memory", "v0", "v1", "v2", "v6", "v7");
  2919. }
  2920. // filter 5 rows with 1, 4, 6, 4, 1 coefficients to produce 1 row.
  2921. void GaussRow_NEON(const uint32_t* src, uint16_t* dst, int width) {
  2922. const uint32_t* src1 = src + 1;
  2923. const uint32_t* src2 = src + 2;
  2924. const uint32_t* src3 = src + 3;
  2925. asm volatile(
  2926. "movi v6.4s, #4 \n" // constant 4
  2927. "movi v7.4s, #6 \n" // constant 6
  2928. "1: \n"
  2929. "ld1 {v0.4s,v1.4s,v2.4s}, [%0], %6 \n" // load 12 source samples
  2930. "add v0.4s, v0.4s, v1.4s \n" // * 1
  2931. "add v1.4s, v1.4s, v2.4s \n" // * 1
  2932. "ld1 {v2.4s,v3.4s}, [%2], #32 \n"
  2933. "mla v0.4s, v2.4s, v7.4s \n" // * 6
  2934. "mla v1.4s, v3.4s, v7.4s \n" // * 6
  2935. "ld1 {v2.4s,v3.4s}, [%1], #32 \n"
  2936. "ld1 {v4.4s,v5.4s}, [%3], #32 \n"
  2937. "add v2.4s, v2.4s, v4.4s \n" // add rows for * 4
  2938. "add v3.4s, v3.4s, v5.4s \n"
  2939. "prfm pldl1keep, [%0, 448] \n"
  2940. "mla v0.4s, v2.4s, v6.4s \n" // * 4
  2941. "mla v1.4s, v3.4s, v6.4s \n" // * 4
  2942. "subs %w5, %w5, #8 \n" // 8 processed per loop
  2943. "uqrshrn v0.4h, v0.4s, #8 \n" // round and pack
  2944. "uqrshrn2 v0.8h, v1.4s, #8 \n"
  2945. "st1 {v0.8h}, [%4], #16 \n" // store 8 samples
  2946. "b.gt 1b \n"
  2947. : "+r"(src), // %0
  2948. "+r"(src1), // %1
  2949. "+r"(src2), // %2
  2950. "+r"(src3), // %3
  2951. "+r"(dst), // %4
  2952. "+r"(width) // %5
  2953. : "r"(32LL) // %6
  2954. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  2955. }
  2956. static const vecf32 kGaussCoefficients = {4.0f, 6.0f, 1.0f / 256.0f, 0.0f};
  2957. // filter 5 rows with 1, 4, 6, 4, 1 coefficients to produce 1 row.
  2958. void GaussCol_F32_NEON(const float* src0,
  2959. const float* src1,
  2960. const float* src2,
  2961. const float* src3,
  2962. const float* src4,
  2963. float* dst,
  2964. int width) {
  2965. asm volatile(
  2966. "ld2r {v6.4s, v7.4s}, [%7] \n" // constants 4 and 6
  2967. "1: \n"
  2968. "ld1 {v0.4s, v1.4s}, [%0], #32 \n" // load 8 samples, 5 rows
  2969. "ld1 {v2.4s, v3.4s}, [%1], #32 \n"
  2970. "fmla v0.4s, v2.4s, v6.4s \n" // * 4
  2971. "ld1 {v4.4s, v5.4s}, [%2], #32 \n"
  2972. "fmla v1.4s, v3.4s, v6.4s \n"
  2973. "prfm pldl1keep, [%0, 448] \n"
  2974. "fmla v0.4s, v4.4s, v7.4s \n" // * 6
  2975. "ld1 {v2.4s, v3.4s}, [%3], #32 \n"
  2976. "fmla v1.4s, v5.4s, v7.4s \n"
  2977. "prfm pldl1keep, [%1, 448] \n"
  2978. "fmla v0.4s, v2.4s, v6.4s \n" // * 4
  2979. "ld1 {v4.4s, v5.4s}, [%4], #32 \n"
  2980. "fmla v1.4s, v3.4s, v6.4s \n"
  2981. "prfm pldl1keep, [%2, 448] \n"
  2982. "fadd v0.4s, v0.4s, v4.4s \n" // * 1
  2983. "prfm pldl1keep, [%3, 448] \n"
  2984. "fadd v1.4s, v1.4s, v5.4s \n"
  2985. "prfm pldl1keep, [%4, 448] \n"
  2986. "subs %w6, %w6, #8 \n" // 8 processed per loop
  2987. "st1 {v0.4s, v1.4s}, [%5], #32 \n" // store 8 samples
  2988. "b.gt 1b \n"
  2989. : "+r"(src0), // %0
  2990. "+r"(src1), // %1
  2991. "+r"(src2), // %2
  2992. "+r"(src3), // %3
  2993. "+r"(src4), // %4
  2994. "+r"(dst), // %5
  2995. "+r"(width) // %6
  2996. : "r"(&kGaussCoefficients) // %7
  2997. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  2998. }
  2999. // filter 5 rows with 1, 4, 6, 4, 1 coefficients to produce 1 row.
  3000. void GaussRow_F32_NEON(const float* src, float* dst, int width) {
  3001. asm volatile(
  3002. "ld3r {v6.4s, v7.4s, v8.4s}, [%3] \n" // constants 4, 6, 1/256
  3003. "1: \n"
  3004. "ld1 {v0.4s, v1.4s, v2.4s}, [%0], %4\n" // load 12 samples, 5 rows
  3005. "fadd v0.4s, v0.4s, v1.4s \n" // * 1
  3006. "ld1 {v4.4s, v5.4s}, [%0], %5 \n"
  3007. "fadd v1.4s, v1.4s, v2.4s \n"
  3008. "fmla v0.4s, v4.4s, v7.4s \n" // * 6
  3009. "ld1 {v2.4s, v3.4s}, [%0], %4 \n"
  3010. "fmla v1.4s, v5.4s, v7.4s \n"
  3011. "ld1 {v4.4s, v5.4s}, [%0], %6 \n"
  3012. "fadd v2.4s, v2.4s, v4.4s \n"
  3013. "fadd v3.4s, v3.4s, v5.4s \n"
  3014. "fmla v0.4s, v2.4s, v6.4s \n" // * 4
  3015. "fmla v1.4s, v3.4s, v6.4s \n"
  3016. "prfm pldl1keep, [%0, 448] \n"
  3017. "fmul v0.4s, v0.4s, v8.4s \n" // / 256
  3018. "fmul v1.4s, v1.4s, v8.4s \n"
  3019. "subs %w2, %w2, #8 \n" // 8 processed per loop
  3020. "st1 {v0.4s, v1.4s}, [%1], #32 \n" // store 8 samples
  3021. "b.gt 1b \n"
  3022. : "+r"(src), // %0
  3023. "+r"(dst), // %1
  3024. "+r"(width) // %2
  3025. : "r"(&kGaussCoefficients), // %3
  3026. "r"(8LL), // %4
  3027. "r"(-4LL), // %5
  3028. "r"(20LL) // %6
  3029. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8");
  3030. }
  3031. // Convert biplanar NV21 to packed YUV24
  3032. void NV21ToYUV24Row_NEON(const uint8_t* src_y,
  3033. const uint8_t* src_vu,
  3034. uint8_t* dst_yuv24,
  3035. int width) {
  3036. asm volatile(
  3037. "1: \n"
  3038. "ld1 {v2.16b}, [%0], #16 \n" // load 16 Y values
  3039. "ld2 {v0.8b, v1.8b}, [%1], #16 \n" // load 8 VU values
  3040. "prfm pldl1keep, [%0, 448] \n"
  3041. "prfm pldl1keep, [%1, 448] \n"
  3042. "zip1 v0.16b, v0.16b, v0.16b \n" // replicate V values
  3043. "zip1 v1.16b, v1.16b, v1.16b \n" // replicate U values
  3044. "subs %w3, %w3, #16 \n" // 16 pixels per loop
  3045. "st3 {v0.16b,v1.16b,v2.16b}, [%2], #48 \n" // store 16 YUV pixels
  3046. "b.gt 1b \n"
  3047. : "+r"(src_y), // %0
  3048. "+r"(src_vu), // %1
  3049. "+r"(dst_yuv24), // %2
  3050. "+r"(width) // %3
  3051. :
  3052. : "cc", "memory", "v0", "v1", "v2");
  3053. }
  3054. void AYUVToUVRow_NEON(const uint8_t* src_ayuv,
  3055. int src_stride_ayuv,
  3056. uint8_t* dst_uv,
  3057. int width) {
  3058. const uint8_t* src_ayuv_1 = src_ayuv + src_stride_ayuv;
  3059. asm volatile(
  3060. "1: \n"
  3061. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 ayuv
  3062. "prfm pldl1keep, [%0, 448] \n"
  3063. "uaddlp v0.8h, v0.16b \n" // V 16 bytes -> 8 shorts.
  3064. "uaddlp v1.8h, v1.16b \n" // U 16 bytes -> 8 shorts.
  3065. "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16
  3066. "prfm pldl1keep, [%1, 448] \n"
  3067. "uadalp v0.8h, v4.16b \n" // V 16 bytes -> 8 shorts.
  3068. "uadalp v1.8h, v5.16b \n" // U 16 bytes -> 8 shorts.
  3069. "uqrshrn v3.8b, v0.8h, #2 \n" // 2x2 average
  3070. "uqrshrn v2.8b, v1.8h, #2 \n"
  3071. "subs %w3, %w3, #16 \n" // 16 processed per loop.
  3072. "st2 {v2.8b,v3.8b}, [%2], #16 \n" // store 8 pixels UV.
  3073. "b.gt 1b \n"
  3074. : "+r"(src_ayuv), // %0
  3075. "+r"(src_ayuv_1), // %1
  3076. "+r"(dst_uv), // %2
  3077. "+r"(width) // %3
  3078. :
  3079. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  3080. }
  3081. void AYUVToVURow_NEON(const uint8_t* src_ayuv,
  3082. int src_stride_ayuv,
  3083. uint8_t* dst_vu,
  3084. int width) {
  3085. const uint8_t* src_ayuv_1 = src_ayuv + src_stride_ayuv;
  3086. asm volatile(
  3087. "1: \n"
  3088. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16 ayuv
  3089. "prfm pldl1keep, [%0, 448] \n"
  3090. "uaddlp v0.8h, v0.16b \n" // V 16 bytes -> 8 shorts.
  3091. "uaddlp v1.8h, v1.16b \n" // U 16 bytes -> 8 shorts.
  3092. "ld4 {v4.16b,v5.16b,v6.16b,v7.16b}, [%1], #64 \n" // load next 16
  3093. "prfm pldl1keep, [%1, 448] \n"
  3094. "uadalp v0.8h, v4.16b \n" // V 16 bytes -> 8 shorts.
  3095. "uadalp v1.8h, v5.16b \n" // U 16 bytes -> 8 shorts.
  3096. "uqrshrn v0.8b, v0.8h, #2 \n" // 2x2 average
  3097. "uqrshrn v1.8b, v1.8h, #2 \n"
  3098. "subs %w3, %w3, #16 \n" // 16 processed per loop.
  3099. "st2 {v0.8b,v1.8b}, [%2], #16 \n" // store 8 pixels VU.
  3100. "b.gt 1b \n"
  3101. : "+r"(src_ayuv), // %0
  3102. "+r"(src_ayuv_1), // %1
  3103. "+r"(dst_vu), // %2
  3104. "+r"(width) // %3
  3105. :
  3106. : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
  3107. }
  3108. // Copy row of AYUV Y's into Y
  3109. void AYUVToYRow_NEON(const uint8_t* src_ayuv, uint8_t* dst_y, int width) {
  3110. asm volatile(
  3111. "1: \n"
  3112. "ld4 {v0.16b,v1.16b,v2.16b,v3.16b}, [%0], #64 \n" // load 16
  3113. "prfm pldl1keep, [%0, 448] \n"
  3114. "subs %w2, %w2, #16 \n" // 16 pixels per loop
  3115. "st1 {v2.16b}, [%1], #16 \n" // store 16 Y pixels
  3116. "b.gt 1b \n"
  3117. : "+r"(src_ayuv), // %0
  3118. "+r"(dst_y), // %1
  3119. "+r"(width) // %2
  3120. :
  3121. : "cc", "memory", "v0", "v1", "v2", "v3");
  3122. }
  3123. // Shuffle table for swapping UV bytes.
  3124. static const uvec8 kShuffleSwapUV = {1u, 0u, 3u, 2u, 5u, 4u, 7u, 6u,
  3125. 9u, 8u, 11u, 10u, 13u, 12u, 15u, 14u};
  3126. // Convert UV plane of NV12 to VU of NV21.
  3127. void SwapUVRow_NEON(const uint8_t* src_uv, uint8_t* dst_vu, int width) {
  3128. asm volatile(
  3129. "ld1 {v2.16b}, [%3] \n" // shuffler
  3130. "1: \n"
  3131. "ld1 {v0.16b}, [%0], 16 \n" // load 16 UV values
  3132. "ld1 {v1.16b}, [%0], 16 \n"
  3133. "prfm pldl1keep, [%0, 448] \n"
  3134. "subs %w2, %w2, #16 \n" // 16 pixels per loop
  3135. "tbl v0.16b, {v0.16b}, v2.16b \n"
  3136. "tbl v1.16b, {v1.16b}, v2.16b \n"
  3137. "stp q0, q1, [%1], 32 \n" // store 16 VU pixels
  3138. "b.gt 1b \n"
  3139. : "+r"(src_uv), // %0
  3140. "+r"(dst_vu), // %1
  3141. "+r"(width) // %2
  3142. : "r"(&kShuffleSwapUV) // %3
  3143. : "cc", "memory", "v0", "v1", "v2");
  3144. }
  3145. void HalfMergeUVRow_NEON(const uint8_t* src_u,
  3146. int src_stride_u,
  3147. const uint8_t* src_v,
  3148. int src_stride_v,
  3149. uint8_t* dst_uv,
  3150. int width) {
  3151. const uint8_t* src_u_1 = src_u + src_stride_u;
  3152. const uint8_t* src_v_1 = src_v + src_stride_v;
  3153. asm volatile(
  3154. "1: \n"
  3155. "ld1 {v0.16b}, [%0], #16 \n" // load 16 U values
  3156. "ld1 {v1.16b}, [%2], #16 \n" // load 16 V values
  3157. "ld1 {v2.16b}, [%1], #16 \n"
  3158. "ld1 {v3.16b}, [%3], #16 \n"
  3159. "uaddlp v0.8h, v0.16b \n" // half size
  3160. "prfm pldl1keep, [%0, 448] \n"
  3161. "uaddlp v1.8h, v1.16b \n"
  3162. "prfm pldl1keep, [%2, 448] \n"
  3163. "uadalp v0.8h, v2.16b \n"
  3164. "prfm pldl1keep, [%1, 448] \n"
  3165. "uadalp v1.8h, v3.16b \n"
  3166. "prfm pldl1keep, [%3, 448] \n"
  3167. "uqrshrn v0.8b, v0.8h, #2 \n"
  3168. "uqrshrn v1.8b, v1.8h, #2 \n"
  3169. "subs %w5, %w5, #16 \n" // 16 src pixels per loop
  3170. "st2 {v0.8b, v1.8b}, [%4], #16 \n" // store 8 UV pixels
  3171. "b.gt 1b \n"
  3172. : "+r"(src_u), // %0
  3173. "+r"(src_u_1), // %1
  3174. "+r"(src_v), // %2
  3175. "+r"(src_v_1), // %3
  3176. "+r"(dst_uv), // %4
  3177. "+r"(width) // %5
  3178. :
  3179. : "cc", "memory", "v0", "v1", "v2", "v3");
  3180. }
  3181. #endif // !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
  3182. #ifdef __cplusplus
  3183. } // extern "C"
  3184. } // namespace libyuv
  3185. #endif