Instructions.cs 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578
  1. // https://github.com/LDj3SNuD/ARM_v8-A_AArch64_Instructions_Tester/blob/master/Tester/Instructions.cs
  2. // https://developer.arm.com/products/architecture/a-profile/exploration-tools
  3. // ..\A64_v83A_ISA_xml_00bet6.1\ISA_v83A_A64_xml_00bet6.1_OPT\xhtml\
  4. using System.Numerics;
  5. namespace Ryujinx.Tests.Cpu.Tester
  6. {
  7. using Types;
  8. using static AArch64;
  9. using static Shared;
  10. // index.html
  11. internal static class Base
  12. {
  13. #region "Alu"
  14. // cls_int.html
  15. public static void Cls(bool sf, Bits Rn, Bits Rd)
  16. {
  17. /* Decode */
  18. int d = (int)UInt(Rd);
  19. int n = (int)UInt(Rn);
  20. int datasize = (sf ? 64 : 32);
  21. /* Operation */
  22. Bits operand1 = X(datasize, n);
  23. BigInteger result = (BigInteger)CountLeadingSignBits(operand1);
  24. X(d, result.SubBigInteger(datasize - 1, 0));
  25. }
  26. // clz_int.html
  27. public static void Clz(bool sf, Bits Rn, Bits Rd)
  28. {
  29. /* Decode */
  30. int d = (int)UInt(Rd);
  31. int n = (int)UInt(Rn);
  32. int datasize = (sf ? 64 : 32);
  33. /* Operation */
  34. Bits operand1 = X(datasize, n);
  35. BigInteger result = (BigInteger)CountLeadingZeroBits(operand1);
  36. X(d, result.SubBigInteger(datasize - 1, 0));
  37. }
  38. // rbit_int.html
  39. public static void Rbit(bool sf, Bits Rn, Bits Rd)
  40. {
  41. /* Decode */
  42. int d = (int)UInt(Rd);
  43. int n = (int)UInt(Rn);
  44. int datasize = (sf ? 64 : 32);
  45. /* Operation */
  46. Bits result = new Bits(datasize);
  47. Bits operand = X(datasize, n);
  48. for (int i = 0; i <= datasize - 1; i++)
  49. {
  50. result[datasize - 1 - i] = operand[i];
  51. }
  52. X(d, result);
  53. }
  54. // rev16_int.html
  55. public static void Rev16(bool sf, Bits Rn, Bits Rd)
  56. {
  57. /* Bits opc = "01"; */
  58. /* Decode */
  59. int d = (int)UInt(Rd);
  60. int n = (int)UInt(Rn);
  61. int datasize = (sf ? 64 : 32);
  62. int container_size = 16;
  63. /* Operation */
  64. Bits result = new Bits(datasize);
  65. Bits operand = X(datasize, n);
  66. int containers = datasize / container_size;
  67. int elements_per_container = container_size / 8;
  68. int index = 0;
  69. int rev_index;
  70. for (int c = 0; c <= containers - 1; c++)
  71. {
  72. rev_index = index + ((elements_per_container - 1) * 8);
  73. for (int e = 0; e <= elements_per_container - 1; e++)
  74. {
  75. result[rev_index + 7, rev_index] = operand[index + 7, index];
  76. index = index + 8;
  77. rev_index = rev_index - 8;
  78. }
  79. }
  80. X(d, result);
  81. }
  82. // rev32_int.html
  83. // (rev.html)
  84. public static void Rev32(bool sf, Bits Rn, Bits Rd)
  85. {
  86. /* Bits opc = "10"; */
  87. /* Decode */
  88. int d = (int)UInt(Rd);
  89. int n = (int)UInt(Rn);
  90. int datasize = (sf ? 64 : 32);
  91. int container_size = 32;
  92. /* Operation */
  93. Bits result = new Bits(datasize);
  94. Bits operand = X(datasize, n);
  95. int containers = datasize / container_size;
  96. int elements_per_container = container_size / 8;
  97. int index = 0;
  98. int rev_index;
  99. for (int c = 0; c <= containers - 1; c++)
  100. {
  101. rev_index = index + ((elements_per_container - 1) * 8);
  102. for (int e = 0; e <= elements_per_container - 1; e++)
  103. {
  104. result[rev_index + 7, rev_index] = operand[index + 7, index];
  105. index = index + 8;
  106. rev_index = rev_index - 8;
  107. }
  108. }
  109. X(d, result);
  110. }
  111. // rev64_rev.html
  112. // (rev.html)
  113. public static void Rev64(Bits Rn, Bits Rd)
  114. {
  115. /* Bits opc = "11"; */
  116. /* Decode */
  117. int d = (int)UInt(Rd);
  118. int n = (int)UInt(Rn);
  119. int container_size = 64;
  120. /* Operation */
  121. Bits result = new Bits(64);
  122. Bits operand = X(64, n);
  123. int containers = 64 / container_size;
  124. int elements_per_container = container_size / 8;
  125. int index = 0;
  126. int rev_index;
  127. for (int c = 0; c <= containers - 1; c++)
  128. {
  129. rev_index = index + ((elements_per_container - 1) * 8);
  130. for (int e = 0; e <= elements_per_container - 1; e++)
  131. {
  132. result[rev_index + 7, rev_index] = operand[index + 7, index];
  133. index = index + 8;
  134. rev_index = rev_index - 8;
  135. }
  136. }
  137. X(d, result);
  138. }
  139. #endregion
  140. #region "AluImm"
  141. // add_addsub_imm.html
  142. public static void Add_Imm(bool sf, Bits shift, Bits imm12, Bits Rn, Bits Rd)
  143. {
  144. /* Decode */
  145. int d = (int)UInt(Rd);
  146. int n = (int)UInt(Rn);
  147. int datasize = (sf ? 64 : 32);
  148. Bits imm;
  149. switch (shift)
  150. {
  151. default:
  152. case Bits bits when bits == "00":
  153. imm = ZeroExtend(imm12, datasize);
  154. break;
  155. case Bits bits when bits == "01":
  156. imm = ZeroExtend(Bits.Concat(imm12, Zeros(12)), datasize);
  157. break;
  158. /* when '1x' ReservedValue(); */
  159. }
  160. /* Operation */
  161. Bits result;
  162. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  163. (result, _) = AddWithCarry(datasize, operand1, imm, false);
  164. if (d == 31)
  165. {
  166. SP(result);
  167. }
  168. else
  169. {
  170. X(d, result);
  171. }
  172. }
  173. // adds_addsub_imm.html
  174. public static void Adds_Imm(bool sf, Bits shift, Bits imm12, Bits Rn, Bits Rd)
  175. {
  176. /* Decode */
  177. int d = (int)UInt(Rd);
  178. int n = (int)UInt(Rn);
  179. int datasize = (sf ? 64 : 32);
  180. Bits imm;
  181. switch (shift)
  182. {
  183. default:
  184. case Bits bits when bits == "00":
  185. imm = ZeroExtend(imm12, datasize);
  186. break;
  187. case Bits bits when bits == "01":
  188. imm = ZeroExtend(Bits.Concat(imm12, Zeros(12)), datasize);
  189. break;
  190. /* when '1x' ReservedValue(); */
  191. }
  192. /* Operation */
  193. Bits result;
  194. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  195. Bits nzcv;
  196. (result, nzcv) = AddWithCarry(datasize, operand1, imm, false);
  197. PSTATE.NZCV(nzcv);
  198. X(d, result);
  199. }
  200. // and_log_imm.html
  201. public static void And_Imm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  202. {
  203. /* Decode */
  204. int d = (int)UInt(Rd);
  205. int n = (int)UInt(Rn);
  206. int datasize = (sf ? 64 : 32);
  207. Bits imm;
  208. /* if sf == '0' && N != '0' then ReservedValue(); */
  209. (imm, _) = DecodeBitMasks(datasize, N, imms, immr, true);
  210. /* Operation */
  211. Bits operand1 = X(datasize, n);
  212. Bits result = AND(operand1, imm);
  213. if (d == 31)
  214. {
  215. SP(result);
  216. }
  217. else
  218. {
  219. X(d, result);
  220. }
  221. }
  222. // ands_log_imm.html
  223. public static void Ands_Imm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  224. {
  225. /* Decode */
  226. int d = (int)UInt(Rd);
  227. int n = (int)UInt(Rn);
  228. int datasize = (sf ? 64 : 32);
  229. Bits imm;
  230. /* if sf == '0' && N != '0' then ReservedValue(); */
  231. (imm, _) = DecodeBitMasks(datasize, N, imms, immr, true);
  232. /* Operation */
  233. Bits operand1 = X(datasize, n);
  234. Bits result = AND(operand1, imm);
  235. PSTATE.NZCV(result[datasize - 1], IsZeroBit(result), false, false);
  236. X(d, result);
  237. }
  238. // eor_log_imm.html
  239. public static void Eor_Imm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  240. {
  241. /* Decode */
  242. int d = (int)UInt(Rd);
  243. int n = (int)UInt(Rn);
  244. int datasize = (sf ? 64 : 32);
  245. Bits imm;
  246. /* if sf == '0' && N != '0' then ReservedValue(); */
  247. (imm, _) = DecodeBitMasks(datasize, N, imms, immr, true);
  248. /* Operation */
  249. Bits operand1 = X(datasize, n);
  250. Bits result = EOR(operand1, imm);
  251. if (d == 31)
  252. {
  253. SP(result);
  254. }
  255. else
  256. {
  257. X(d, result);
  258. }
  259. }
  260. // orr_log_imm.html
  261. public static void Orr_Imm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  262. {
  263. /* Decode */
  264. int d = (int)UInt(Rd);
  265. int n = (int)UInt(Rn);
  266. int datasize = (sf ? 64 : 32);
  267. Bits imm;
  268. /* if sf == '0' && N != '0' then ReservedValue(); */
  269. (imm, _) = DecodeBitMasks(datasize, N, imms, immr, true);
  270. /* Operation */
  271. Bits operand1 = X(datasize, n);
  272. Bits result = OR(operand1, imm);
  273. if (d == 31)
  274. {
  275. SP(result);
  276. }
  277. else
  278. {
  279. X(d, result);
  280. }
  281. }
  282. // sub_addsub_imm.html
  283. public static void Sub_Imm(bool sf, Bits shift, Bits imm12, Bits Rn, Bits Rd)
  284. {
  285. /* Decode */
  286. int d = (int)UInt(Rd);
  287. int n = (int)UInt(Rn);
  288. int datasize = (sf ? 64 : 32);
  289. Bits imm;
  290. switch (shift)
  291. {
  292. default:
  293. case Bits bits when bits == "00":
  294. imm = ZeroExtend(imm12, datasize);
  295. break;
  296. case Bits bits when bits == "01":
  297. imm = ZeroExtend(Bits.Concat(imm12, Zeros(12)), datasize);
  298. break;
  299. /* when '1x' ReservedValue(); */
  300. }
  301. /* Operation */
  302. Bits result;
  303. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  304. Bits operand2 = NOT(imm);
  305. (result, _) = AddWithCarry(datasize, operand1, operand2, true);
  306. if (d == 31)
  307. {
  308. SP(result);
  309. }
  310. else
  311. {
  312. X(d, result);
  313. }
  314. }
  315. // subs_addsub_imm.html
  316. public static void Subs_Imm(bool sf, Bits shift, Bits imm12, Bits Rn, Bits Rd)
  317. {
  318. /* Decode */
  319. int d = (int)UInt(Rd);
  320. int n = (int)UInt(Rn);
  321. int datasize = (sf ? 64 : 32);
  322. Bits imm;
  323. switch (shift)
  324. {
  325. default:
  326. case Bits bits when bits == "00":
  327. imm = ZeroExtend(imm12, datasize);
  328. break;
  329. case Bits bits when bits == "01":
  330. imm = ZeroExtend(Bits.Concat(imm12, Zeros(12)), datasize);
  331. break;
  332. /* when '1x' ReservedValue(); */
  333. }
  334. /* Operation */
  335. Bits result;
  336. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  337. Bits operand2 = NOT(imm);
  338. Bits nzcv;
  339. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, true);
  340. PSTATE.NZCV(nzcv);
  341. X(d, result);
  342. }
  343. #endregion
  344. #region "AluRs"
  345. // adc.html
  346. public static void Adc(bool sf, Bits Rm, Bits Rn, Bits Rd)
  347. {
  348. /* Decode */
  349. int d = (int)UInt(Rd);
  350. int n = (int)UInt(Rn);
  351. int m = (int)UInt(Rm);
  352. int datasize = (sf ? 64 : 32);
  353. /* Operation */
  354. Bits result;
  355. Bits operand1 = X(datasize, n);
  356. Bits operand2 = X(datasize, m);
  357. (result, _) = AddWithCarry(datasize, operand1, operand2, PSTATE.C);
  358. X(d, result);
  359. }
  360. // adcs.html
  361. public static void Adcs(bool sf, Bits Rm, Bits Rn, Bits Rd)
  362. {
  363. /* Decode */
  364. int d = (int)UInt(Rd);
  365. int n = (int)UInt(Rn);
  366. int m = (int)UInt(Rm);
  367. int datasize = (sf ? 64 : 32);
  368. /* Operation */
  369. Bits result;
  370. Bits operand1 = X(datasize, n);
  371. Bits operand2 = X(datasize, m);
  372. Bits nzcv;
  373. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, PSTATE.C);
  374. PSTATE.NZCV(nzcv);
  375. X(d, result);
  376. }
  377. // add_addsub_shift.html
  378. public static void Add_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  379. {
  380. /* Decode */
  381. int d = (int)UInt(Rd);
  382. int n = (int)UInt(Rn);
  383. int m = (int)UInt(Rm);
  384. int datasize = (sf ? 64 : 32);
  385. /* if shift == '11' then ReservedValue(); */
  386. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  387. ShiftType shift_type = DecodeShift(shift);
  388. int shift_amount = (int)UInt(imm6);
  389. /* Operation */
  390. Bits result;
  391. Bits operand1 = X(datasize, n);
  392. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  393. (result, _) = AddWithCarry(datasize, operand1, operand2, false);
  394. X(d, result);
  395. }
  396. // adds_addsub_shift.html
  397. public static void Adds_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  398. {
  399. /* Decode */
  400. int d = (int)UInt(Rd);
  401. int n = (int)UInt(Rn);
  402. int m = (int)UInt(Rm);
  403. int datasize = (sf ? 64 : 32);
  404. /* if shift == '11' then ReservedValue(); */
  405. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  406. ShiftType shift_type = DecodeShift(shift);
  407. int shift_amount = (int)UInt(imm6);
  408. /* Operation */
  409. Bits result;
  410. Bits operand1 = X(datasize, n);
  411. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  412. Bits nzcv;
  413. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, false);
  414. PSTATE.NZCV(nzcv);
  415. X(d, result);
  416. }
  417. // and_log_shift.html
  418. public static void And_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  419. {
  420. /* Decode */
  421. int d = (int)UInt(Rd);
  422. int n = (int)UInt(Rn);
  423. int m = (int)UInt(Rm);
  424. int datasize = (sf ? 64 : 32);
  425. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  426. ShiftType shift_type = DecodeShift(shift);
  427. int shift_amount = (int)UInt(imm6);
  428. /* Operation */
  429. Bits operand1 = X(datasize, n);
  430. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  431. Bits result = AND(operand1, operand2);
  432. X(d, result);
  433. }
  434. // ands_log_shift.html
  435. public static void Ands_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  436. {
  437. /* Decode */
  438. int d = (int)UInt(Rd);
  439. int n = (int)UInt(Rn);
  440. int m = (int)UInt(Rm);
  441. int datasize = (sf ? 64 : 32);
  442. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  443. ShiftType shift_type = DecodeShift(shift);
  444. int shift_amount = (int)UInt(imm6);
  445. /* Operation */
  446. Bits operand1 = X(datasize, n);
  447. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  448. Bits result = AND(operand1, operand2);
  449. PSTATE.NZCV(result[datasize - 1], IsZeroBit(result), false, false);
  450. X(d, result);
  451. }
  452. // asrv.html
  453. public static void Asrv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  454. {
  455. /*readonly */Bits op2 = "10";
  456. /* Decode */
  457. int d = (int)UInt(Rd);
  458. int n = (int)UInt(Rn);
  459. int m = (int)UInt(Rm);
  460. int datasize = (sf ? 64 : 32);
  461. ShiftType shift_type = DecodeShift(op2);
  462. /* Operation */
  463. Bits operand2 = X(datasize, m);
  464. Bits result = ShiftReg(datasize, n, shift_type, (int)(UInt(operand2) % datasize)); // BigInteger.Modulus Operator (BigInteger, BigInteger)
  465. X(d, result);
  466. }
  467. // bic_log_shift.html
  468. public static void Bic(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  469. {
  470. /* Decode */
  471. int d = (int)UInt(Rd);
  472. int n = (int)UInt(Rn);
  473. int m = (int)UInt(Rm);
  474. int datasize = (sf ? 64 : 32);
  475. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  476. ShiftType shift_type = DecodeShift(shift);
  477. int shift_amount = (int)UInt(imm6);
  478. /* Operation */
  479. Bits operand1 = X(datasize, n);
  480. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  481. operand2 = NOT(operand2);
  482. Bits result = AND(operand1, operand2);
  483. X(d, result);
  484. }
  485. // bics.html
  486. public static void Bics(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  487. {
  488. /* Decode */
  489. int d = (int)UInt(Rd);
  490. int n = (int)UInt(Rn);
  491. int m = (int)UInt(Rm);
  492. int datasize = (sf ? 64 : 32);
  493. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  494. ShiftType shift_type = DecodeShift(shift);
  495. int shift_amount = (int)UInt(imm6);
  496. /* Operation */
  497. Bits operand1 = X(datasize, n);
  498. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  499. operand2 = NOT(operand2);
  500. Bits result = AND(operand1, operand2);
  501. PSTATE.NZCV(result[datasize - 1], IsZeroBit(result), false, false);
  502. X(d, result);
  503. }
  504. // crc32.html
  505. public static void Crc32(bool sf, Bits Rm, Bits sz, Bits Rn, Bits Rd)
  506. {
  507. /* Decode */
  508. int d = (int)UInt(Rd);
  509. int n = (int)UInt(Rn);
  510. int m = (int)UInt(Rm);
  511. /* if sf == '1' && sz != '11' then UnallocatedEncoding(); */
  512. /* if sf == '0' && sz == '11' then UnallocatedEncoding(); */
  513. int size = 8 << (int)UInt(sz);
  514. /* Operation */
  515. /* if !HaveCRCExt() then UnallocatedEncoding(); */
  516. Bits acc = X(32, n); // accumulator
  517. Bits val = X(size, m); // input value
  518. Bits poly = new Bits(0x04C11DB7u);
  519. Bits tempacc = Bits.Concat(BitReverse(acc), Zeros(size));
  520. Bits tempval = Bits.Concat(BitReverse(val), Zeros(32));
  521. // Poly32Mod2 on a bitstring does a polynomial Modulus over {0,1} operation
  522. X(d, BitReverse(Poly32Mod2(EOR(tempacc, tempval), poly)));
  523. }
  524. // crc32c.html
  525. public static void Crc32c(bool sf, Bits Rm, Bits sz, Bits Rn, Bits Rd)
  526. {
  527. /* Decode */
  528. int d = (int)UInt(Rd);
  529. int n = (int)UInt(Rn);
  530. int m = (int)UInt(Rm);
  531. /* if sf == '1' && sz != '11' then UnallocatedEncoding(); */
  532. /* if sf == '0' && sz == '11' then UnallocatedEncoding(); */
  533. int size = 8 << (int)UInt(sz);
  534. /* Operation */
  535. /* if !HaveCRCExt() then UnallocatedEncoding(); */
  536. Bits acc = X(32, n); // accumulator
  537. Bits val = X(size, m); // input value
  538. Bits poly = new Bits(0x1EDC6F41u);
  539. Bits tempacc = Bits.Concat(BitReverse(acc), Zeros(size));
  540. Bits tempval = Bits.Concat(BitReverse(val), Zeros(32));
  541. // Poly32Mod2 on a bitstring does a polynomial Modulus over {0,1} operation
  542. X(d, BitReverse(Poly32Mod2(EOR(tempacc, tempval), poly)));
  543. }
  544. // eon.html
  545. public static void Eon(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  546. {
  547. /* Decode */
  548. int d = (int)UInt(Rd);
  549. int n = (int)UInt(Rn);
  550. int m = (int)UInt(Rm);
  551. int datasize = (sf ? 64 : 32);
  552. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  553. ShiftType shift_type = DecodeShift(shift);
  554. int shift_amount = (int)UInt(imm6);
  555. /* Operation */
  556. Bits operand1 = X(datasize, n);
  557. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  558. operand2 = NOT(operand2);
  559. Bits result = EOR(operand1, operand2);
  560. X(d, result);
  561. }
  562. // eor_log_shift.html
  563. public static void Eor_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  564. {
  565. /* Decode */
  566. int d = (int)UInt(Rd);
  567. int n = (int)UInt(Rn);
  568. int m = (int)UInt(Rm);
  569. int datasize = (sf ? 64 : 32);
  570. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  571. ShiftType shift_type = DecodeShift(shift);
  572. int shift_amount = (int)UInt(imm6);
  573. /* Operation */
  574. Bits operand1 = X(datasize, n);
  575. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  576. Bits result = EOR(operand1, operand2);
  577. X(d, result);
  578. }
  579. // extr.html
  580. public static void Extr(bool sf, bool N, Bits Rm, Bits imms, Bits Rn, Bits Rd)
  581. {
  582. /* Decode */
  583. int d = (int)UInt(Rd);
  584. int n = (int)UInt(Rn);
  585. int m = (int)UInt(Rm);
  586. int datasize = (sf ? 64 : 32);
  587. /* if N != sf then UnallocatedEncoding(); */
  588. /* if sf == '0' && imms<5> == '1' then ReservedValue(); */
  589. int lsb = (int)UInt(imms);
  590. /* Operation */
  591. Bits operand1 = X(datasize, n);
  592. Bits operand2 = X(datasize, m);
  593. Bits concat = Bits.Concat(operand1, operand2);
  594. Bits result = concat[lsb + datasize - 1, lsb];
  595. X(d, result);
  596. }
  597. // lslv.html
  598. public static void Lslv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  599. {
  600. /*readonly */Bits op2 = "00";
  601. /* Decode */
  602. int d = (int)UInt(Rd);
  603. int n = (int)UInt(Rn);
  604. int m = (int)UInt(Rm);
  605. int datasize = (sf ? 64 : 32);
  606. ShiftType shift_type = DecodeShift(op2);
  607. /* Operation */
  608. Bits operand2 = X(datasize, m);
  609. Bits result = ShiftReg(datasize, n, shift_type, (int)(UInt(operand2) % datasize)); // BigInteger.Modulus Operator (BigInteger, BigInteger)
  610. X(d, result);
  611. }
  612. // lsrv.html
  613. public static void Lsrv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  614. {
  615. /*readonly */Bits op2 = "01";
  616. /* Decode */
  617. int d = (int)UInt(Rd);
  618. int n = (int)UInt(Rn);
  619. int m = (int)UInt(Rm);
  620. int datasize = (sf ? 64 : 32);
  621. ShiftType shift_type = DecodeShift(op2);
  622. /* Operation */
  623. Bits operand2 = X(datasize, m);
  624. Bits result = ShiftReg(datasize, n, shift_type, (int)(UInt(operand2) % datasize)); // BigInteger.Modulus Operator (BigInteger, BigInteger)
  625. X(d, result);
  626. }
  627. // orn_log_shift.html
  628. public static void Orn(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  629. {
  630. /* Decode */
  631. int d = (int)UInt(Rd);
  632. int n = (int)UInt(Rn);
  633. int m = (int)UInt(Rm);
  634. int datasize = (sf ? 64 : 32);
  635. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  636. ShiftType shift_type = DecodeShift(shift);
  637. int shift_amount = (int)UInt(imm6);
  638. /* Operation */
  639. Bits operand1 = X(datasize, n);
  640. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  641. operand2 = NOT(operand2);
  642. Bits result = OR(operand1, operand2);
  643. X(d, result);
  644. }
  645. // orr_log_shift.html
  646. public static void Orr_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  647. {
  648. /* Decode */
  649. int d = (int)UInt(Rd);
  650. int n = (int)UInt(Rn);
  651. int m = (int)UInt(Rm);
  652. int datasize = (sf ? 64 : 32);
  653. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  654. ShiftType shift_type = DecodeShift(shift);
  655. int shift_amount = (int)UInt(imm6);
  656. /* Operation */
  657. Bits operand1 = X(datasize, n);
  658. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  659. Bits result = OR(operand1, operand2);
  660. X(d, result);
  661. }
  662. // rorv.html
  663. public static void Rorv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  664. {
  665. /*readonly */Bits op2 = "11";
  666. /* Decode */
  667. int d = (int)UInt(Rd);
  668. int n = (int)UInt(Rn);
  669. int m = (int)UInt(Rm);
  670. int datasize = (sf ? 64 : 32);
  671. ShiftType shift_type = DecodeShift(op2);
  672. /* Operation */
  673. Bits operand2 = X(datasize, m);
  674. Bits result = ShiftReg(datasize, n, shift_type, (int)(UInt(operand2) % datasize)); // BigInteger.Modulus Operator (BigInteger, BigInteger)
  675. X(d, result);
  676. }
  677. // sbc.html
  678. public static void Sbc(bool sf, Bits Rm, Bits Rn, Bits Rd)
  679. {
  680. /* Decode */
  681. int d = (int)UInt(Rd);
  682. int n = (int)UInt(Rn);
  683. int m = (int)UInt(Rm);
  684. int datasize = (sf ? 64 : 32);
  685. /* Operation */
  686. Bits result;
  687. Bits operand1 = X(datasize, n);
  688. Bits operand2 = X(datasize, m);
  689. operand2 = NOT(operand2);
  690. (result, _) = AddWithCarry(datasize, operand1, operand2, PSTATE.C);
  691. X(d, result);
  692. }
  693. // sbcs.html
  694. public static void Sbcs(bool sf, Bits Rm, Bits Rn, Bits Rd)
  695. {
  696. /* Decode */
  697. int d = (int)UInt(Rd);
  698. int n = (int)UInt(Rn);
  699. int m = (int)UInt(Rm);
  700. int datasize = (sf ? 64 : 32);
  701. /* Operation */
  702. Bits result;
  703. Bits operand1 = X(datasize, n);
  704. Bits operand2 = X(datasize, m);
  705. Bits nzcv;
  706. operand2 = NOT(operand2);
  707. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, PSTATE.C);
  708. PSTATE.NZCV(nzcv);
  709. X(d, result);
  710. }
  711. // sdiv.html
  712. public static void Sdiv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  713. {
  714. /* Decode */
  715. int d = (int)UInt(Rd);
  716. int n = (int)UInt(Rn);
  717. int m = (int)UInt(Rm);
  718. int datasize = (sf ? 64 : 32);
  719. /* Operation */
  720. BigInteger result;
  721. Bits operand1 = X(datasize, n);
  722. Bits operand2 = X(datasize, m);
  723. if (IsZero(operand2))
  724. {
  725. result = (BigInteger)0m;
  726. }
  727. else
  728. {
  729. result = RoundTowardsZero(Real(Int(operand1, false)) / Real(Int(operand2, false)));
  730. }
  731. X(d, result.SubBigInteger(datasize - 1, 0));
  732. }
  733. // sub_addsub_shift.html
  734. public static void Sub_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  735. {
  736. /* Decode */
  737. int d = (int)UInt(Rd);
  738. int n = (int)UInt(Rn);
  739. int m = (int)UInt(Rm);
  740. int datasize = (sf ? 64 : 32);
  741. /* if shift == '11' then ReservedValue(); */
  742. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  743. ShiftType shift_type = DecodeShift(shift);
  744. int shift_amount = (int)UInt(imm6);
  745. /* Operation */
  746. Bits result;
  747. Bits operand1 = X(datasize, n);
  748. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  749. operand2 = NOT(operand2);
  750. (result, _) = AddWithCarry(datasize, operand1, operand2, true);
  751. X(d, result);
  752. }
  753. // subs_addsub_shift.html
  754. public static void Subs_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  755. {
  756. /* Decode */
  757. int d = (int)UInt(Rd);
  758. int n = (int)UInt(Rn);
  759. int m = (int)UInt(Rm);
  760. int datasize = (sf ? 64 : 32);
  761. /* if shift == '11' then ReservedValue(); */
  762. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  763. ShiftType shift_type = DecodeShift(shift);
  764. int shift_amount = (int)UInt(imm6);
  765. /* Operation */
  766. Bits result;
  767. Bits operand1 = X(datasize, n);
  768. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  769. Bits nzcv;
  770. operand2 = NOT(operand2);
  771. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, true);
  772. PSTATE.NZCV(nzcv);
  773. X(d, result);
  774. }
  775. // udiv.html
  776. public static void Udiv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  777. {
  778. /* Decode */
  779. int d = (int)UInt(Rd);
  780. int n = (int)UInt(Rn);
  781. int m = (int)UInt(Rm);
  782. int datasize = (sf ? 64 : 32);
  783. /* Operation */
  784. BigInteger result;
  785. Bits operand1 = X(datasize, n);
  786. Bits operand2 = X(datasize, m);
  787. if (IsZero(operand2))
  788. {
  789. result = (BigInteger)0m;
  790. }
  791. else
  792. {
  793. result = RoundTowardsZero(Real(Int(operand1, true)) / Real(Int(operand2, true)));
  794. }
  795. X(d, result.SubBigInteger(datasize - 1, 0));
  796. }
  797. #endregion
  798. #region "AluRx"
  799. // add_addsub_ext.html
  800. public static void Add_Rx(bool sf, Bits Rm, Bits option, Bits imm3, Bits Rn, Bits Rd)
  801. {
  802. /* Decode */
  803. int d = (int)UInt(Rd);
  804. int n = (int)UInt(Rn);
  805. int m = (int)UInt(Rm);
  806. int datasize = (sf ? 64 : 32);
  807. ExtendType extend_type = DecodeRegExtend(option);
  808. int shift = (int)UInt(imm3);
  809. /* if shift > 4 then ReservedValue(); */
  810. /* Operation */
  811. Bits result;
  812. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  813. Bits operand2 = ExtendReg(datasize, m, extend_type, shift);
  814. (result, _) = AddWithCarry(datasize, operand1, operand2, false);
  815. if (d == 31)
  816. {
  817. SP(result);
  818. }
  819. else
  820. {
  821. X(d, result);
  822. }
  823. }
  824. // adds_addsub_ext.html
  825. public static void Adds_Rx(bool sf, Bits Rm, Bits option, Bits imm3, Bits Rn, Bits Rd)
  826. {
  827. /* Decode */
  828. int d = (int)UInt(Rd);
  829. int n = (int)UInt(Rn);
  830. int m = (int)UInt(Rm);
  831. int datasize = (sf ? 64 : 32);
  832. ExtendType extend_type = DecodeRegExtend(option);
  833. int shift = (int)UInt(imm3);
  834. /* if shift > 4 then ReservedValue(); */
  835. /* Operation */
  836. Bits result;
  837. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  838. Bits operand2 = ExtendReg(datasize, m, extend_type, shift);
  839. Bits nzcv;
  840. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, false);
  841. PSTATE.NZCV(nzcv);
  842. X(d, result);
  843. }
  844. // sub_addsub_ext.html
  845. public static void Sub_Rx(bool sf, Bits Rm, Bits option, Bits imm3, Bits Rn, Bits Rd)
  846. {
  847. /* Decode */
  848. int d = (int)UInt(Rd);
  849. int n = (int)UInt(Rn);
  850. int m = (int)UInt(Rm);
  851. int datasize = (sf ? 64 : 32);
  852. ExtendType extend_type = DecodeRegExtend(option);
  853. int shift = (int)UInt(imm3);
  854. /* if shift > 4 then ReservedValue(); */
  855. /* Operation */
  856. Bits result;
  857. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  858. Bits operand2 = ExtendReg(datasize, m, extend_type, shift);
  859. operand2 = NOT(operand2);
  860. (result, _) = AddWithCarry(datasize, operand1, operand2, true);
  861. if (d == 31)
  862. {
  863. SP(result);
  864. }
  865. else
  866. {
  867. X(d, result);
  868. }
  869. }
  870. // subs_addsub_ext.html
  871. public static void Subs_Rx(bool sf, Bits Rm, Bits option, Bits imm3, Bits Rn, Bits Rd)
  872. {
  873. /* Decode */
  874. int d = (int)UInt(Rd);
  875. int n = (int)UInt(Rn);
  876. int m = (int)UInt(Rm);
  877. int datasize = (sf ? 64 : 32);
  878. ExtendType extend_type = DecodeRegExtend(option);
  879. int shift = (int)UInt(imm3);
  880. /* if shift > 4 then ReservedValue(); */
  881. /* Operation */
  882. Bits result;
  883. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  884. Bits operand2 = ExtendReg(datasize, m, extend_type, shift);
  885. Bits nzcv;
  886. operand2 = NOT(operand2);
  887. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, true);
  888. PSTATE.NZCV(nzcv);
  889. X(d, result);
  890. }
  891. #endregion
  892. #region "Bfm"
  893. // bfm.html
  894. public static void Bfm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  895. {
  896. /* Decode */
  897. int d = (int)UInt(Rd);
  898. int n = (int)UInt(Rn);
  899. int datasize = (sf ? 64 : 32);
  900. int R;
  901. Bits wmask;
  902. Bits tmask;
  903. /* if sf == '1' && N != '1' then ReservedValue(); */
  904. /* if sf == '0' && (N != '0' || immr<5> != '0' || imms<5> != '0') then ReservedValue(); */
  905. R = (int)UInt(immr);
  906. (wmask, tmask) = DecodeBitMasks(datasize, N, imms, immr, false);
  907. /* Operation */
  908. Bits dst = X(datasize, d);
  909. Bits src = X(datasize, n);
  910. // perform bitfield move on low bits
  911. Bits bot = OR(AND(dst, NOT(wmask)), AND(ROR(src, R), wmask));
  912. // combine extension bits and result bits
  913. X(d, OR(AND(dst, NOT(tmask)), AND(bot, tmask)));
  914. }
  915. // sbfm.html
  916. public static void Sbfm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  917. {
  918. /* Decode */
  919. int d = (int)UInt(Rd);
  920. int n = (int)UInt(Rn);
  921. int datasize = (sf ? 64 : 32);
  922. int R;
  923. int S;
  924. Bits wmask;
  925. Bits tmask;
  926. /* if sf == '1' && N != '1' then ReservedValue(); */
  927. /* if sf == '0' && (N != '0' || immr<5> != '0' || imms<5> != '0') then ReservedValue(); */
  928. R = (int)UInt(immr);
  929. S = (int)UInt(imms);
  930. (wmask, tmask) = DecodeBitMasks(datasize, N, imms, immr, false);
  931. /* Operation */
  932. Bits src = X(datasize, n);
  933. // perform bitfield move on low bits
  934. Bits bot = AND(ROR(src, R), wmask);
  935. // determine extension bits (sign, zero or dest register)
  936. Bits top = Replicate(datasize, src[S]);
  937. // combine extension bits and result bits
  938. X(d, OR(AND(top, NOT(tmask)), AND(bot, tmask)));
  939. }
  940. // ubfm.html
  941. public static void Ubfm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  942. {
  943. /* Decode */
  944. int d = (int)UInt(Rd);
  945. int n = (int)UInt(Rn);
  946. int datasize = (sf ? 64 : 32);
  947. int R;
  948. Bits wmask;
  949. Bits tmask;
  950. /* if sf == '1' && N != '1' then ReservedValue(); */
  951. /* if sf == '0' && (N != '0' || immr<5> != '0' || imms<5> != '0') then ReservedValue(); */
  952. R = (int)UInt(immr);
  953. (wmask, tmask) = DecodeBitMasks(datasize, N, imms, immr, false);
  954. /* Operation */
  955. Bits src = X(datasize, n);
  956. // perform bitfield move on low bits
  957. Bits bot = AND(ROR(src, R), wmask);
  958. // combine extension bits and result bits
  959. X(d, AND(bot, tmask));
  960. }
  961. #endregion
  962. #region "CcmpImm"
  963. // ccmn_imm.html
  964. public static void Ccmn_Imm(bool sf, Bits imm5, Bits cond, Bits Rn, Bits nzcv)
  965. {
  966. /* Decode */
  967. int n = (int)UInt(Rn);
  968. int datasize = (sf ? 64 : 32);
  969. Bits flags = nzcv;
  970. Bits imm = ZeroExtend(imm5, datasize);
  971. /* Operation */
  972. Bits operand1 = X(datasize, n);
  973. if (ConditionHolds(cond))
  974. {
  975. (_, flags) = AddWithCarry(datasize, operand1, imm, false);
  976. }
  977. PSTATE.NZCV(flags);
  978. }
  979. // ccmp_imm.html
  980. public static void Ccmp_Imm(bool sf, Bits imm5, Bits cond, Bits Rn, Bits nzcv)
  981. {
  982. /* Decode */
  983. int n = (int)UInt(Rn);
  984. int datasize = (sf ? 64 : 32);
  985. Bits flags = nzcv;
  986. Bits imm = ZeroExtend(imm5, datasize);
  987. /* Operation */
  988. Bits operand1 = X(datasize, n);
  989. Bits operand2;
  990. if (ConditionHolds(cond))
  991. {
  992. operand2 = NOT(imm);
  993. (_, flags) = AddWithCarry(datasize, operand1, operand2, true);
  994. }
  995. PSTATE.NZCV(flags);
  996. }
  997. #endregion
  998. #region "CcmpReg"
  999. // ccmn_reg.html
  1000. public static void Ccmn_Reg(bool sf, Bits Rm, Bits cond, Bits Rn, Bits nzcv)
  1001. {
  1002. /* Decode */
  1003. int n = (int)UInt(Rn);
  1004. int m = (int)UInt(Rm);
  1005. int datasize = (sf ? 64 : 32);
  1006. Bits flags = nzcv;
  1007. /* Operation */
  1008. Bits operand1 = X(datasize, n);
  1009. Bits operand2 = X(datasize, m);
  1010. if (ConditionHolds(cond))
  1011. {
  1012. (_, flags) = AddWithCarry(datasize, operand1, operand2, false);
  1013. }
  1014. PSTATE.NZCV(flags);
  1015. }
  1016. // ccmp_reg.html
  1017. public static void Ccmp_Reg(bool sf, Bits Rm, Bits cond, Bits Rn, Bits nzcv)
  1018. {
  1019. /* Decode */
  1020. int n = (int)UInt(Rn);
  1021. int m = (int)UInt(Rm);
  1022. int datasize = (sf ? 64 : 32);
  1023. Bits flags = nzcv;
  1024. /* Operation */
  1025. Bits operand1 = X(datasize, n);
  1026. Bits operand2 = X(datasize, m);
  1027. if (ConditionHolds(cond))
  1028. {
  1029. operand2 = NOT(operand2);
  1030. (_, flags) = AddWithCarry(datasize, operand1, operand2, true);
  1031. }
  1032. PSTATE.NZCV(flags);
  1033. }
  1034. #endregion
  1035. #region "Csel"
  1036. // csel.html
  1037. public static void Csel(bool sf, Bits Rm, Bits cond, Bits Rn, Bits Rd)
  1038. {
  1039. /* Decode */
  1040. int d = (int)UInt(Rd);
  1041. int n = (int)UInt(Rn);
  1042. int m = (int)UInt(Rm);
  1043. int datasize = (sf ? 64 : 32);
  1044. /* Operation */
  1045. Bits result;
  1046. Bits operand1 = X(datasize, n);
  1047. Bits operand2 = X(datasize, m);
  1048. if (ConditionHolds(cond))
  1049. {
  1050. result = operand1;
  1051. }
  1052. else
  1053. {
  1054. result = operand2;
  1055. }
  1056. X(d, result);
  1057. }
  1058. // csinc.html
  1059. public static void Csinc(bool sf, Bits Rm, Bits cond, Bits Rn, Bits Rd)
  1060. {
  1061. /* Decode */
  1062. int d = (int)UInt(Rd);
  1063. int n = (int)UInt(Rn);
  1064. int m = (int)UInt(Rm);
  1065. int datasize = (sf ? 64 : 32);
  1066. /* Operation */
  1067. Bits result;
  1068. Bits operand1 = X(datasize, n);
  1069. Bits operand2 = X(datasize, m);
  1070. if (ConditionHolds(cond))
  1071. {
  1072. result = operand1;
  1073. }
  1074. else
  1075. {
  1076. result = operand2 + 1;
  1077. }
  1078. X(d, result);
  1079. }
  1080. // csinv.html
  1081. public static void Csinv(bool sf, Bits Rm, Bits cond, Bits Rn, Bits Rd)
  1082. {
  1083. /* Decode */
  1084. int d = (int)UInt(Rd);
  1085. int n = (int)UInt(Rn);
  1086. int m = (int)UInt(Rm);
  1087. int datasize = (sf ? 64 : 32);
  1088. /* Operation */
  1089. Bits result;
  1090. Bits operand1 = X(datasize, n);
  1091. Bits operand2 = X(datasize, m);
  1092. if (ConditionHolds(cond))
  1093. {
  1094. result = operand1;
  1095. }
  1096. else
  1097. {
  1098. result = NOT(operand2);
  1099. }
  1100. X(d, result);
  1101. }
  1102. // csneg.html
  1103. public static void Csneg(bool sf, Bits Rm, Bits cond, Bits Rn, Bits Rd)
  1104. {
  1105. /* Decode */
  1106. int d = (int)UInt(Rd);
  1107. int n = (int)UInt(Rn);
  1108. int m = (int)UInt(Rm);
  1109. int datasize = (sf ? 64 : 32);
  1110. /* Operation */
  1111. Bits result;
  1112. Bits operand1 = X(datasize, n);
  1113. Bits operand2 = X(datasize, m);
  1114. if (ConditionHolds(cond))
  1115. {
  1116. result = operand1;
  1117. }
  1118. else
  1119. {
  1120. result = NOT(operand2);
  1121. result = result + 1;
  1122. }
  1123. X(d, result);
  1124. }
  1125. #endregion
  1126. #region "Mov"
  1127. // movk.html
  1128. public static void Movk(bool sf, Bits hw, Bits imm16, Bits Rd)
  1129. {
  1130. /* Decode */
  1131. int d = (int)UInt(Rd);
  1132. int datasize = (sf ? 64 : 32);
  1133. /* if sf == '0' && hw<1> == '1' then UnallocatedEncoding(); */
  1134. int pos = (int)UInt(Bits.Concat(hw, "0000"));
  1135. /* Operation */
  1136. Bits result = X(datasize, d);
  1137. result[pos + 15, pos] = imm16;
  1138. X(d, result);
  1139. }
  1140. // movn.html
  1141. public static void Movn(bool sf, Bits hw, Bits imm16, Bits Rd)
  1142. {
  1143. /* Decode */
  1144. int d = (int)UInt(Rd);
  1145. int datasize = (sf ? 64 : 32);
  1146. /* if sf == '0' && hw<1> == '1' then UnallocatedEncoding(); */
  1147. int pos = (int)UInt(Bits.Concat(hw, "0000"));
  1148. /* Operation */
  1149. Bits result = Zeros(datasize);
  1150. result[pos + 15, pos] = imm16;
  1151. result = NOT(result);
  1152. X(d, result);
  1153. }
  1154. // movz.html
  1155. public static void Movz(bool sf, Bits hw, Bits imm16, Bits Rd)
  1156. {
  1157. /* Decode */
  1158. int d = (int)UInt(Rd);
  1159. int datasize = (sf ? 64 : 32);
  1160. /* if sf == '0' && hw<1> == '1' then UnallocatedEncoding(); */
  1161. int pos = (int)UInt(Bits.Concat(hw, "0000"));
  1162. /* Operation */
  1163. Bits result = Zeros(datasize);
  1164. result[pos + 15, pos] = imm16;
  1165. X(d, result);
  1166. }
  1167. #endregion
  1168. #region "Mul"
  1169. // madd.html
  1170. public static void Madd(bool sf, Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1171. {
  1172. /* Decode */
  1173. int d = (int)UInt(Rd);
  1174. int n = (int)UInt(Rn);
  1175. int m = (int)UInt(Rm);
  1176. int a = (int)UInt(Ra);
  1177. int datasize = (sf ? 64 : 32);
  1178. /* Operation */
  1179. Bits operand1 = X(datasize, n);
  1180. Bits operand2 = X(datasize, m);
  1181. Bits operand3 = X(datasize, a);
  1182. BigInteger result = UInt(operand3) + (UInt(operand1) * UInt(operand2));
  1183. X(d, result.SubBigInteger(datasize - 1, 0));
  1184. }
  1185. // msub.html
  1186. public static void Msub(bool sf, Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1187. {
  1188. /* Decode */
  1189. int d = (int)UInt(Rd);
  1190. int n = (int)UInt(Rn);
  1191. int m = (int)UInt(Rm);
  1192. int a = (int)UInt(Ra);
  1193. int datasize = (sf ? 64 : 32);
  1194. /* Operation */
  1195. Bits operand1 = X(datasize, n);
  1196. Bits operand2 = X(datasize, m);
  1197. Bits operand3 = X(datasize, a);
  1198. BigInteger result = UInt(operand3) - (UInt(operand1) * UInt(operand2));
  1199. X(d, result.SubBigInteger(datasize - 1, 0));
  1200. }
  1201. // smaddl.html
  1202. public static void Smaddl(Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1203. {
  1204. /* Decode */
  1205. int d = (int)UInt(Rd);
  1206. int n = (int)UInt(Rn);
  1207. int m = (int)UInt(Rm);
  1208. int a = (int)UInt(Ra);
  1209. /* Operation */
  1210. Bits operand1 = X(32, n);
  1211. Bits operand2 = X(32, m);
  1212. Bits operand3 = X(64, a);
  1213. BigInteger result = Int(operand3, false) + (Int(operand1, false) * Int(operand2, false));
  1214. X(d, result.SubBigInteger(63, 0));
  1215. }
  1216. // umaddl.html
  1217. public static void Umaddl(Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1218. {
  1219. /* Decode */
  1220. int d = (int)UInt(Rd);
  1221. int n = (int)UInt(Rn);
  1222. int m = (int)UInt(Rm);
  1223. int a = (int)UInt(Ra);
  1224. /* Operation */
  1225. Bits operand1 = X(32, n);
  1226. Bits operand2 = X(32, m);
  1227. Bits operand3 = X(64, a);
  1228. BigInteger result = Int(operand3, true) + (Int(operand1, true) * Int(operand2, true));
  1229. X(d, result.SubBigInteger(63, 0));
  1230. }
  1231. // smsubl.html
  1232. public static void Smsubl(Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1233. {
  1234. /* Decode */
  1235. int d = (int)UInt(Rd);
  1236. int n = (int)UInt(Rn);
  1237. int m = (int)UInt(Rm);
  1238. int a = (int)UInt(Ra);
  1239. /* Operation */
  1240. Bits operand1 = X(32, n);
  1241. Bits operand2 = X(32, m);
  1242. Bits operand3 = X(64, a);
  1243. BigInteger result = Int(operand3, false) - (Int(operand1, false) * Int(operand2, false));
  1244. X(d, result.SubBigInteger(63, 0));
  1245. }
  1246. // umsubl.html
  1247. public static void Umsubl(Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1248. {
  1249. /* Decode */
  1250. int d = (int)UInt(Rd);
  1251. int n = (int)UInt(Rn);
  1252. int m = (int)UInt(Rm);
  1253. int a = (int)UInt(Ra);
  1254. /* Operation */
  1255. Bits operand1 = X(32, n);
  1256. Bits operand2 = X(32, m);
  1257. Bits operand3 = X(64, a);
  1258. BigInteger result = Int(operand3, true) - (Int(operand1, true) * Int(operand2, true));
  1259. X(d, result.SubBigInteger(63, 0));
  1260. }
  1261. // smulh.html
  1262. public static void Smulh(Bits Rm, Bits Rn, Bits Rd)
  1263. {
  1264. /* Decode */
  1265. int d = (int)UInt(Rd);
  1266. int n = (int)UInt(Rn);
  1267. int m = (int)UInt(Rm);
  1268. /* Operation */
  1269. Bits operand1 = X(64, n);
  1270. Bits operand2 = X(64, m);
  1271. BigInteger result = Int(operand1, false) * Int(operand2, false);
  1272. X(d, result.SubBigInteger(127, 64));
  1273. }
  1274. // umulh.html
  1275. public static void Umulh(Bits Rm, Bits Rn, Bits Rd)
  1276. {
  1277. /* Decode */
  1278. int d = (int)UInt(Rd);
  1279. int n = (int)UInt(Rn);
  1280. int m = (int)UInt(Rm);
  1281. /* Operation */
  1282. Bits operand1 = X(64, n);
  1283. Bits operand2 = X(64, m);
  1284. BigInteger result = Int(operand1, true) * Int(operand2, true);
  1285. X(d, result.SubBigInteger(127, 64));
  1286. }
  1287. #endregion
  1288. }
  1289. // fpsimdindex.html
  1290. internal static class SimdFp
  1291. {
  1292. #region "Simd"
  1293. // abs_advsimd.html#ABS_asisdmisc_R
  1294. public static void Abs_S(Bits size, Bits Rn, Bits Rd)
  1295. {
  1296. const bool U = false;
  1297. /* Decode Scalar */
  1298. int d = (int)UInt(Rd);
  1299. int n = (int)UInt(Rn);
  1300. /* if size != '11' then ReservedValue(); */
  1301. int esize = 8 << (int)UInt(size);
  1302. int datasize = esize;
  1303. int elements = 1;
  1304. bool neg = (U == true);
  1305. /* Operation */
  1306. /* CheckFPAdvSIMDEnabled64(); */
  1307. Bits result = new Bits(datasize);
  1308. Bits operand = V(datasize, n);
  1309. BigInteger element;
  1310. for (int e = 0; e <= elements - 1; e++)
  1311. {
  1312. element = SInt(Elem(operand, e, esize));
  1313. if (neg)
  1314. {
  1315. element = -element;
  1316. }
  1317. else
  1318. {
  1319. element = Abs(element);
  1320. }
  1321. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  1322. }
  1323. V(d, result);
  1324. }
  1325. // abs_advsimd.html#ABS_asimdmisc_R
  1326. public static void Abs_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1327. {
  1328. const bool U = false;
  1329. /* Decode Vector */
  1330. int d = (int)UInt(Rd);
  1331. int n = (int)UInt(Rn);
  1332. /* if size:Q == '110' then ReservedValue(); */
  1333. int esize = 8 << (int)UInt(size);
  1334. int datasize = (Q ? 128 : 64);
  1335. int elements = datasize / esize;
  1336. bool neg = (U == true);
  1337. /* Operation */
  1338. /* CheckFPAdvSIMDEnabled64(); */
  1339. Bits result = new Bits(datasize);
  1340. Bits operand = V(datasize, n);
  1341. BigInteger element;
  1342. for (int e = 0; e <= elements - 1; e++)
  1343. {
  1344. element = SInt(Elem(operand, e, esize));
  1345. if (neg)
  1346. {
  1347. element = -element;
  1348. }
  1349. else
  1350. {
  1351. element = Abs(element);
  1352. }
  1353. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  1354. }
  1355. V(d, result);
  1356. }
  1357. // addp_advsimd_pair.html
  1358. public static void Addp_S(Bits size, Bits Rn, Bits Rd)
  1359. {
  1360. /* Decode */
  1361. int d = (int)UInt(Rd);
  1362. int n = (int)UInt(Rn);
  1363. /* if size != '11' then ReservedValue(); */
  1364. int esize = 8 << (int)UInt(size);
  1365. int datasize = esize * 2;
  1366. // int elements = 2;
  1367. ReduceOp op = ReduceOp.ReduceOp_ADD;
  1368. /* Operation */
  1369. /* CheckFPAdvSIMDEnabled64(); */
  1370. Bits operand = V(datasize, n);
  1371. V(d, Reduce(op, operand, esize));
  1372. }
  1373. // addv_advsimd.html
  1374. public static void Addv_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1375. {
  1376. /* Decode */
  1377. int d = (int)UInt(Rd);
  1378. int n = (int)UInt(Rn);
  1379. /* if size:Q == '100' then ReservedValue(); */
  1380. /* if size == '11' then ReservedValue(); */
  1381. int esize = 8 << (int)UInt(size);
  1382. int datasize = (Q ? 128 : 64);
  1383. // int elements = datasize / esize;
  1384. ReduceOp op = ReduceOp.ReduceOp_ADD;
  1385. /* Operation */
  1386. /* CheckFPAdvSIMDEnabled64(); */
  1387. Bits operand = V(datasize, n);
  1388. V(d, Reduce(op, operand, esize));
  1389. }
  1390. // cls_advsimd.html
  1391. public static void Cls_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1392. {
  1393. const bool U = false;
  1394. /* Decode Vector */
  1395. int d = (int)UInt(Rd);
  1396. int n = (int)UInt(Rn);
  1397. /* if size == '11' then ReservedValue(); */
  1398. int esize = 8 << (int)UInt(size);
  1399. int datasize = (Q ? 128 : 64);
  1400. int elements = datasize / esize;
  1401. CountOp countop = (U ? CountOp.CountOp_CLZ : CountOp.CountOp_CLS);
  1402. /* Operation */
  1403. /* CheckFPAdvSIMDEnabled64(); */
  1404. Bits result = new Bits(datasize);
  1405. Bits operand = V(datasize, n);
  1406. BigInteger count;
  1407. for (int e = 0; e <= elements - 1; e++)
  1408. {
  1409. if (countop == CountOp.CountOp_CLS)
  1410. {
  1411. count = (BigInteger)CountLeadingSignBits(Elem(operand, e, esize));
  1412. }
  1413. else
  1414. {
  1415. count = (BigInteger)CountLeadingZeroBits(Elem(operand, e, esize));
  1416. }
  1417. Elem(result, e, esize, count.SubBigInteger(esize - 1, 0));
  1418. }
  1419. V(d, result);
  1420. }
  1421. // clz_advsimd.html
  1422. public static void Clz_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1423. {
  1424. const bool U = true;
  1425. /* Decode Vector */
  1426. int d = (int)UInt(Rd);
  1427. int n = (int)UInt(Rn);
  1428. /* if size == '11' then ReservedValue(); */
  1429. int esize = 8 << (int)UInt(size);
  1430. int datasize = (Q ? 128 : 64);
  1431. int elements = datasize / esize;
  1432. CountOp countop = (U ? CountOp.CountOp_CLZ : CountOp.CountOp_CLS);
  1433. /* Operation */
  1434. /* CheckFPAdvSIMDEnabled64(); */
  1435. Bits result = new Bits(datasize);
  1436. Bits operand = V(datasize, n);
  1437. BigInteger count;
  1438. for (int e = 0; e <= elements - 1; e++)
  1439. {
  1440. if (countop == CountOp.CountOp_CLS)
  1441. {
  1442. count = (BigInteger)CountLeadingSignBits(Elem(operand, e, esize));
  1443. }
  1444. else
  1445. {
  1446. count = (BigInteger)CountLeadingZeroBits(Elem(operand, e, esize));
  1447. }
  1448. Elem(result, e, esize, count.SubBigInteger(esize - 1, 0));
  1449. }
  1450. V(d, result);
  1451. }
  1452. // cmeq_advsimd_zero.html#CMEQ_asisdmisc_Z
  1453. public static void Cmeq_Zero_S(Bits size, Bits Rn, Bits Rd)
  1454. {
  1455. const bool U = false;
  1456. const bool op = true;
  1457. /* Decode Scalar */
  1458. int d = (int)UInt(Rd);
  1459. int n = (int)UInt(Rn);
  1460. /* if size != '11' then ReservedValue(); */
  1461. int esize = 8 << (int)UInt(size);
  1462. int datasize = esize;
  1463. int elements = 1;
  1464. CompareOp comparison;
  1465. switch (Bits.Concat(op, U))
  1466. {
  1467. default:
  1468. case Bits bits when bits == "00":
  1469. comparison = CompareOp.CompareOp_GT;
  1470. break;
  1471. case Bits bits when bits == "01":
  1472. comparison = CompareOp.CompareOp_GE;
  1473. break;
  1474. case Bits bits when bits == "10":
  1475. comparison = CompareOp.CompareOp_EQ;
  1476. break;
  1477. case Bits bits when bits == "11":
  1478. comparison = CompareOp.CompareOp_LE;
  1479. break;
  1480. }
  1481. /* Operation */
  1482. /* CheckFPAdvSIMDEnabled64(); */
  1483. Bits result = new Bits(datasize);
  1484. Bits operand = V(datasize, n);
  1485. BigInteger element;
  1486. bool test_passed;
  1487. for (int e = 0; e <= elements - 1; e++)
  1488. {
  1489. element = SInt(Elem(operand, e, esize));
  1490. switch (comparison)
  1491. {
  1492. default:
  1493. case CompareOp.CompareOp_GT:
  1494. test_passed = (element > (BigInteger)0);
  1495. break;
  1496. case CompareOp.CompareOp_GE:
  1497. test_passed = (element >= (BigInteger)0);
  1498. break;
  1499. case CompareOp.CompareOp_EQ:
  1500. test_passed = (element == (BigInteger)0);
  1501. break;
  1502. case CompareOp.CompareOp_LE:
  1503. test_passed = (element <= (BigInteger)0);
  1504. break;
  1505. case CompareOp.CompareOp_LT:
  1506. test_passed = (element < (BigInteger)0);
  1507. break;
  1508. }
  1509. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1510. }
  1511. V(d, result);
  1512. }
  1513. // cmeq_advsimd_zero.html#CMEQ_asimdmisc_Z
  1514. public static void Cmeq_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1515. {
  1516. const bool U = false;
  1517. const bool op = true;
  1518. /* Decode Vector */
  1519. int d = (int)UInt(Rd);
  1520. int n = (int)UInt(Rn);
  1521. /* if size:Q == '110' then ReservedValue(); */
  1522. int esize = 8 << (int)UInt(size);
  1523. int datasize = (Q ? 128 : 64);
  1524. int elements = datasize / esize;
  1525. CompareOp comparison;
  1526. switch (Bits.Concat(op, U))
  1527. {
  1528. default:
  1529. case Bits bits when bits == "00":
  1530. comparison = CompareOp.CompareOp_GT;
  1531. break;
  1532. case Bits bits when bits == "01":
  1533. comparison = CompareOp.CompareOp_GE;
  1534. break;
  1535. case Bits bits when bits == "10":
  1536. comparison = CompareOp.CompareOp_EQ;
  1537. break;
  1538. case Bits bits when bits == "11":
  1539. comparison = CompareOp.CompareOp_LE;
  1540. break;
  1541. }
  1542. /* Operation */
  1543. /* CheckFPAdvSIMDEnabled64(); */
  1544. Bits result = new Bits(datasize);
  1545. Bits operand = V(datasize, n);
  1546. BigInteger element;
  1547. bool test_passed;
  1548. for (int e = 0; e <= elements - 1; e++)
  1549. {
  1550. element = SInt(Elem(operand, e, esize));
  1551. switch (comparison)
  1552. {
  1553. default:
  1554. case CompareOp.CompareOp_GT:
  1555. test_passed = (element > (BigInteger)0);
  1556. break;
  1557. case CompareOp.CompareOp_GE:
  1558. test_passed = (element >= (BigInteger)0);
  1559. break;
  1560. case CompareOp.CompareOp_EQ:
  1561. test_passed = (element == (BigInteger)0);
  1562. break;
  1563. case CompareOp.CompareOp_LE:
  1564. test_passed = (element <= (BigInteger)0);
  1565. break;
  1566. case CompareOp.CompareOp_LT:
  1567. test_passed = (element < (BigInteger)0);
  1568. break;
  1569. }
  1570. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1571. }
  1572. V(d, result);
  1573. }
  1574. // cmge_advsimd_zero.html#CMGE_asisdmisc_Z
  1575. public static void Cmge_Zero_S(Bits size, Bits Rn, Bits Rd)
  1576. {
  1577. const bool U = true;
  1578. const bool op = false;
  1579. /* Decode Scalar */
  1580. int d = (int)UInt(Rd);
  1581. int n = (int)UInt(Rn);
  1582. /* if size != '11' then ReservedValue(); */
  1583. int esize = 8 << (int)UInt(size);
  1584. int datasize = esize;
  1585. int elements = 1;
  1586. CompareOp comparison;
  1587. switch (Bits.Concat(op, U))
  1588. {
  1589. default:
  1590. case Bits bits when bits == "00":
  1591. comparison = CompareOp.CompareOp_GT;
  1592. break;
  1593. case Bits bits when bits == "01":
  1594. comparison = CompareOp.CompareOp_GE;
  1595. break;
  1596. case Bits bits when bits == "10":
  1597. comparison = CompareOp.CompareOp_EQ;
  1598. break;
  1599. case Bits bits when bits == "11":
  1600. comparison = CompareOp.CompareOp_LE;
  1601. break;
  1602. }
  1603. /* Operation */
  1604. /* CheckFPAdvSIMDEnabled64(); */
  1605. Bits result = new Bits(datasize);
  1606. Bits operand = V(datasize, n);
  1607. BigInteger element;
  1608. bool test_passed;
  1609. for (int e = 0; e <= elements - 1; e++)
  1610. {
  1611. element = SInt(Elem(operand, e, esize));
  1612. switch (comparison)
  1613. {
  1614. default:
  1615. case CompareOp.CompareOp_GT:
  1616. test_passed = (element > (BigInteger)0);
  1617. break;
  1618. case CompareOp.CompareOp_GE:
  1619. test_passed = (element >= (BigInteger)0);
  1620. break;
  1621. case CompareOp.CompareOp_EQ:
  1622. test_passed = (element == (BigInteger)0);
  1623. break;
  1624. case CompareOp.CompareOp_LE:
  1625. test_passed = (element <= (BigInteger)0);
  1626. break;
  1627. case CompareOp.CompareOp_LT:
  1628. test_passed = (element < (BigInteger)0);
  1629. break;
  1630. }
  1631. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1632. }
  1633. V(d, result);
  1634. }
  1635. // cmge_advsimd_zero.html#CMGE_asimdmisc_Z
  1636. public static void Cmge_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1637. {
  1638. const bool U = true;
  1639. const bool op = false;
  1640. /* Decode Vector */
  1641. int d = (int)UInt(Rd);
  1642. int n = (int)UInt(Rn);
  1643. /* if size:Q == '110' then ReservedValue(); */
  1644. int esize = 8 << (int)UInt(size);
  1645. int datasize = (Q ? 128 : 64);
  1646. int elements = datasize / esize;
  1647. CompareOp comparison;
  1648. switch (Bits.Concat(op, U))
  1649. {
  1650. default:
  1651. case Bits bits when bits == "00":
  1652. comparison = CompareOp.CompareOp_GT;
  1653. break;
  1654. case Bits bits when bits == "01":
  1655. comparison = CompareOp.CompareOp_GE;
  1656. break;
  1657. case Bits bits when bits == "10":
  1658. comparison = CompareOp.CompareOp_EQ;
  1659. break;
  1660. case Bits bits when bits == "11":
  1661. comparison = CompareOp.CompareOp_LE;
  1662. break;
  1663. }
  1664. /* Operation */
  1665. /* CheckFPAdvSIMDEnabled64(); */
  1666. Bits result = new Bits(datasize);
  1667. Bits operand = V(datasize, n);
  1668. BigInteger element;
  1669. bool test_passed;
  1670. for (int e = 0; e <= elements - 1; e++)
  1671. {
  1672. element = SInt(Elem(operand, e, esize));
  1673. switch (comparison)
  1674. {
  1675. default:
  1676. case CompareOp.CompareOp_GT:
  1677. test_passed = (element > (BigInteger)0);
  1678. break;
  1679. case CompareOp.CompareOp_GE:
  1680. test_passed = (element >= (BigInteger)0);
  1681. break;
  1682. case CompareOp.CompareOp_EQ:
  1683. test_passed = (element == (BigInteger)0);
  1684. break;
  1685. case CompareOp.CompareOp_LE:
  1686. test_passed = (element <= (BigInteger)0);
  1687. break;
  1688. case CompareOp.CompareOp_LT:
  1689. test_passed = (element < (BigInteger)0);
  1690. break;
  1691. }
  1692. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1693. }
  1694. V(d, result);
  1695. }
  1696. // cmgt_advsimd_zero.html#CMGT_asisdmisc_Z
  1697. public static void Cmgt_Zero_S(Bits size, Bits Rn, Bits Rd)
  1698. {
  1699. const bool U = false;
  1700. const bool op = false;
  1701. /* Decode Scalar */
  1702. int d = (int)UInt(Rd);
  1703. int n = (int)UInt(Rn);
  1704. /* if size != '11' then ReservedValue(); */
  1705. int esize = 8 << (int)UInt(size);
  1706. int datasize = esize;
  1707. int elements = 1;
  1708. CompareOp comparison;
  1709. switch (Bits.Concat(op, U))
  1710. {
  1711. default:
  1712. case Bits bits when bits == "00":
  1713. comparison = CompareOp.CompareOp_GT;
  1714. break;
  1715. case Bits bits when bits == "01":
  1716. comparison = CompareOp.CompareOp_GE;
  1717. break;
  1718. case Bits bits when bits == "10":
  1719. comparison = CompareOp.CompareOp_EQ;
  1720. break;
  1721. case Bits bits when bits == "11":
  1722. comparison = CompareOp.CompareOp_LE;
  1723. break;
  1724. }
  1725. /* Operation */
  1726. /* CheckFPAdvSIMDEnabled64(); */
  1727. Bits result = new Bits(datasize);
  1728. Bits operand = V(datasize, n);
  1729. BigInteger element;
  1730. bool test_passed;
  1731. for (int e = 0; e <= elements - 1; e++)
  1732. {
  1733. element = SInt(Elem(operand, e, esize));
  1734. switch (comparison)
  1735. {
  1736. default:
  1737. case CompareOp.CompareOp_GT:
  1738. test_passed = (element > (BigInteger)0);
  1739. break;
  1740. case CompareOp.CompareOp_GE:
  1741. test_passed = (element >= (BigInteger)0);
  1742. break;
  1743. case CompareOp.CompareOp_EQ:
  1744. test_passed = (element == (BigInteger)0);
  1745. break;
  1746. case CompareOp.CompareOp_LE:
  1747. test_passed = (element <= (BigInteger)0);
  1748. break;
  1749. case CompareOp.CompareOp_LT:
  1750. test_passed = (element < (BigInteger)0);
  1751. break;
  1752. }
  1753. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1754. }
  1755. V(d, result);
  1756. }
  1757. // cmgt_advsimd_zero.html#CMGT_asimdmisc_Z
  1758. public static void Cmgt_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1759. {
  1760. const bool U = false;
  1761. const bool op = false;
  1762. /* Decode Vector */
  1763. int d = (int)UInt(Rd);
  1764. int n = (int)UInt(Rn);
  1765. /* if size:Q == '110' then ReservedValue(); */
  1766. int esize = 8 << (int)UInt(size);
  1767. int datasize = (Q ? 128 : 64);
  1768. int elements = datasize / esize;
  1769. CompareOp comparison;
  1770. switch (Bits.Concat(op, U))
  1771. {
  1772. default:
  1773. case Bits bits when bits == "00":
  1774. comparison = CompareOp.CompareOp_GT;
  1775. break;
  1776. case Bits bits when bits == "01":
  1777. comparison = CompareOp.CompareOp_GE;
  1778. break;
  1779. case Bits bits when bits == "10":
  1780. comparison = CompareOp.CompareOp_EQ;
  1781. break;
  1782. case Bits bits when bits == "11":
  1783. comparison = CompareOp.CompareOp_LE;
  1784. break;
  1785. }
  1786. /* Operation */
  1787. /* CheckFPAdvSIMDEnabled64(); */
  1788. Bits result = new Bits(datasize);
  1789. Bits operand = V(datasize, n);
  1790. BigInteger element;
  1791. bool test_passed;
  1792. for (int e = 0; e <= elements - 1; e++)
  1793. {
  1794. element = SInt(Elem(operand, e, esize));
  1795. switch (comparison)
  1796. {
  1797. default:
  1798. case CompareOp.CompareOp_GT:
  1799. test_passed = (element > (BigInteger)0);
  1800. break;
  1801. case CompareOp.CompareOp_GE:
  1802. test_passed = (element >= (BigInteger)0);
  1803. break;
  1804. case CompareOp.CompareOp_EQ:
  1805. test_passed = (element == (BigInteger)0);
  1806. break;
  1807. case CompareOp.CompareOp_LE:
  1808. test_passed = (element <= (BigInteger)0);
  1809. break;
  1810. case CompareOp.CompareOp_LT:
  1811. test_passed = (element < (BigInteger)0);
  1812. break;
  1813. }
  1814. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1815. }
  1816. V(d, result);
  1817. }
  1818. // cmle_advsimd.html#CMLE_asisdmisc_Z
  1819. public static void Cmle_S(Bits size, Bits Rn, Bits Rd)
  1820. {
  1821. const bool U = true;
  1822. const bool op = true;
  1823. /* Decode Scalar */
  1824. int d = (int)UInt(Rd);
  1825. int n = (int)UInt(Rn);
  1826. /* if size != '11' then ReservedValue(); */
  1827. int esize = 8 << (int)UInt(size);
  1828. int datasize = esize;
  1829. int elements = 1;
  1830. CompareOp comparison;
  1831. switch (Bits.Concat(op, U))
  1832. {
  1833. default:
  1834. case Bits bits when bits == "00":
  1835. comparison = CompareOp.CompareOp_GT;
  1836. break;
  1837. case Bits bits when bits == "01":
  1838. comparison = CompareOp.CompareOp_GE;
  1839. break;
  1840. case Bits bits when bits == "10":
  1841. comparison = CompareOp.CompareOp_EQ;
  1842. break;
  1843. case Bits bits when bits == "11":
  1844. comparison = CompareOp.CompareOp_LE;
  1845. break;
  1846. }
  1847. /* Operation */
  1848. /* CheckFPAdvSIMDEnabled64(); */
  1849. Bits result = new Bits(datasize);
  1850. Bits operand = V(datasize, n);
  1851. BigInteger element;
  1852. bool test_passed;
  1853. for (int e = 0; e <= elements - 1; e++)
  1854. {
  1855. element = SInt(Elem(operand, e, esize));
  1856. switch (comparison)
  1857. {
  1858. default:
  1859. case CompareOp.CompareOp_GT:
  1860. test_passed = (element > (BigInteger)0);
  1861. break;
  1862. case CompareOp.CompareOp_GE:
  1863. test_passed = (element >= (BigInteger)0);
  1864. break;
  1865. case CompareOp.CompareOp_EQ:
  1866. test_passed = (element == (BigInteger)0);
  1867. break;
  1868. case CompareOp.CompareOp_LE:
  1869. test_passed = (element <= (BigInteger)0);
  1870. break;
  1871. case CompareOp.CompareOp_LT:
  1872. test_passed = (element < (BigInteger)0);
  1873. break;
  1874. }
  1875. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1876. }
  1877. V(d, result);
  1878. }
  1879. // cmle_advsimd.html#CMLE_asimdmisc_Z
  1880. public static void Cmle_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1881. {
  1882. const bool U = true;
  1883. const bool op = true;
  1884. /* Decode Vector */
  1885. int d = (int)UInt(Rd);
  1886. int n = (int)UInt(Rn);
  1887. /* if size:Q == '110' then ReservedValue(); */
  1888. int esize = 8 << (int)UInt(size);
  1889. int datasize = (Q ? 128 : 64);
  1890. int elements = datasize / esize;
  1891. CompareOp comparison;
  1892. switch (Bits.Concat(op, U))
  1893. {
  1894. default:
  1895. case Bits bits when bits == "00":
  1896. comparison = CompareOp.CompareOp_GT;
  1897. break;
  1898. case Bits bits when bits == "01":
  1899. comparison = CompareOp.CompareOp_GE;
  1900. break;
  1901. case Bits bits when bits == "10":
  1902. comparison = CompareOp.CompareOp_EQ;
  1903. break;
  1904. case Bits bits when bits == "11":
  1905. comparison = CompareOp.CompareOp_LE;
  1906. break;
  1907. }
  1908. /* Operation */
  1909. /* CheckFPAdvSIMDEnabled64(); */
  1910. Bits result = new Bits(datasize);
  1911. Bits operand = V(datasize, n);
  1912. BigInteger element;
  1913. bool test_passed;
  1914. for (int e = 0; e <= elements - 1; e++)
  1915. {
  1916. element = SInt(Elem(operand, e, esize));
  1917. switch (comparison)
  1918. {
  1919. default:
  1920. case CompareOp.CompareOp_GT:
  1921. test_passed = (element > (BigInteger)0);
  1922. break;
  1923. case CompareOp.CompareOp_GE:
  1924. test_passed = (element >= (BigInteger)0);
  1925. break;
  1926. case CompareOp.CompareOp_EQ:
  1927. test_passed = (element == (BigInteger)0);
  1928. break;
  1929. case CompareOp.CompareOp_LE:
  1930. test_passed = (element <= (BigInteger)0);
  1931. break;
  1932. case CompareOp.CompareOp_LT:
  1933. test_passed = (element < (BigInteger)0);
  1934. break;
  1935. }
  1936. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1937. }
  1938. V(d, result);
  1939. }
  1940. // cmlt_advsimd.html#CMLT_asisdmisc_Z
  1941. public static void Cmlt_S(Bits size, Bits Rn, Bits Rd)
  1942. {
  1943. /* Decode Scalar */
  1944. int d = (int)UInt(Rd);
  1945. int n = (int)UInt(Rn);
  1946. /* if size != '11' then ReservedValue(); */
  1947. int esize = 8 << (int)UInt(size);
  1948. int datasize = esize;
  1949. int elements = 1;
  1950. CompareOp comparison = CompareOp.CompareOp_LT;
  1951. /* Operation */
  1952. /* CheckFPAdvSIMDEnabled64(); */
  1953. Bits result = new Bits(datasize);
  1954. Bits operand = V(datasize, n);
  1955. BigInteger element;
  1956. bool test_passed;
  1957. for (int e = 0; e <= elements - 1; e++)
  1958. {
  1959. element = SInt(Elem(operand, e, esize));
  1960. switch (comparison)
  1961. {
  1962. default:
  1963. case CompareOp.CompareOp_GT:
  1964. test_passed = (element > (BigInteger)0);
  1965. break;
  1966. case CompareOp.CompareOp_GE:
  1967. test_passed = (element >= (BigInteger)0);
  1968. break;
  1969. case CompareOp.CompareOp_EQ:
  1970. test_passed = (element == (BigInteger)0);
  1971. break;
  1972. case CompareOp.CompareOp_LE:
  1973. test_passed = (element <= (BigInteger)0);
  1974. break;
  1975. case CompareOp.CompareOp_LT:
  1976. test_passed = (element < (BigInteger)0);
  1977. break;
  1978. }
  1979. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1980. }
  1981. V(d, result);
  1982. }
  1983. // cmlt_advsimd.html#CMLT_asimdmisc_Z
  1984. public static void Cmlt_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1985. {
  1986. /* Decode Vector */
  1987. int d = (int)UInt(Rd);
  1988. int n = (int)UInt(Rn);
  1989. /* if size:Q == '110' then ReservedValue(); */
  1990. int esize = 8 << (int)UInt(size);
  1991. int datasize = (Q ? 128 : 64);
  1992. int elements = datasize / esize;
  1993. CompareOp comparison = CompareOp.CompareOp_LT;
  1994. /* Operation */
  1995. /* CheckFPAdvSIMDEnabled64(); */
  1996. Bits result = new Bits(datasize);
  1997. Bits operand = V(datasize, n);
  1998. BigInteger element;
  1999. bool test_passed;
  2000. for (int e = 0; e <= elements - 1; e++)
  2001. {
  2002. element = SInt(Elem(operand, e, esize));
  2003. switch (comparison)
  2004. {
  2005. default:
  2006. case CompareOp.CompareOp_GT:
  2007. test_passed = (element > (BigInteger)0);
  2008. break;
  2009. case CompareOp.CompareOp_GE:
  2010. test_passed = (element >= (BigInteger)0);
  2011. break;
  2012. case CompareOp.CompareOp_EQ:
  2013. test_passed = (element == (BigInteger)0);
  2014. break;
  2015. case CompareOp.CompareOp_LE:
  2016. test_passed = (element <= (BigInteger)0);
  2017. break;
  2018. case CompareOp.CompareOp_LT:
  2019. test_passed = (element < (BigInteger)0);
  2020. break;
  2021. }
  2022. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2023. }
  2024. V(d, result);
  2025. }
  2026. // cnt_advsimd.html
  2027. public static void Cnt_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2028. {
  2029. /* Decode Vector */
  2030. int d = (int)UInt(Rd);
  2031. int n = (int)UInt(Rn);
  2032. /* if size != '00' then ReservedValue(); */
  2033. int esize = 8;
  2034. int datasize = (Q ? 128 : 64);
  2035. int elements = datasize / 8;
  2036. /* Operation */
  2037. /* CheckFPAdvSIMDEnabled64(); */
  2038. Bits result = new Bits(datasize);
  2039. Bits operand = V(datasize, n);
  2040. BigInteger count;
  2041. for (int e = 0; e <= elements - 1; e++)
  2042. {
  2043. count = (BigInteger)BitCount(Elem(operand, e, esize));
  2044. Elem(result, e, esize, count.SubBigInteger(esize - 1, 0));
  2045. }
  2046. V(d, result);
  2047. }
  2048. // neg_advsimd.html#NEG_asisdmisc_R
  2049. public static void Neg_S(Bits size, Bits Rn, Bits Rd)
  2050. {
  2051. const bool U = true;
  2052. /* Decode Scalar */
  2053. int d = (int)UInt(Rd);
  2054. int n = (int)UInt(Rn);
  2055. /* if size != '11' then ReservedValue(); */
  2056. int esize = 8 << (int)UInt(size);
  2057. int datasize = esize;
  2058. int elements = 1;
  2059. bool neg = (U == true);
  2060. /* Operation */
  2061. /* CheckFPAdvSIMDEnabled64(); */
  2062. Bits result = new Bits(datasize);
  2063. Bits operand = V(datasize, n);
  2064. BigInteger element;
  2065. for (int e = 0; e <= elements - 1; e++)
  2066. {
  2067. element = SInt(Elem(operand, e, esize));
  2068. if (neg)
  2069. {
  2070. element = -element;
  2071. }
  2072. else
  2073. {
  2074. element = Abs(element);
  2075. }
  2076. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  2077. }
  2078. V(d, result);
  2079. }
  2080. // neg_advsimd.html#NEG_asimdmisc_R
  2081. public static void Neg_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2082. {
  2083. const bool U = true;
  2084. /* Decode Vector */
  2085. int d = (int)UInt(Rd);
  2086. int n = (int)UInt(Rn);
  2087. /* if size:Q == '110' then ReservedValue(); */
  2088. int esize = 8 << (int)UInt(size);
  2089. int datasize = (Q ? 128 : 64);
  2090. int elements = datasize / esize;
  2091. bool neg = (U == true);
  2092. /* Operation */
  2093. /* CheckFPAdvSIMDEnabled64(); */
  2094. Bits result = new Bits(datasize);
  2095. Bits operand = V(datasize, n);
  2096. BigInteger element;
  2097. for (int e = 0; e <= elements - 1; e++)
  2098. {
  2099. element = SInt(Elem(operand, e, esize));
  2100. if (neg)
  2101. {
  2102. element = -element;
  2103. }
  2104. else
  2105. {
  2106. element = Abs(element);
  2107. }
  2108. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  2109. }
  2110. V(d, result);
  2111. }
  2112. // not_advsimd.html
  2113. public static void Not_V(bool Q, Bits Rn, Bits Rd)
  2114. {
  2115. /* Decode Vector */
  2116. int d = (int)UInt(Rd);
  2117. int n = (int)UInt(Rn);
  2118. int esize = 8;
  2119. int datasize = (Q ? 128 : 64);
  2120. int elements = datasize / 8;
  2121. /* Operation */
  2122. /* CheckFPAdvSIMDEnabled64(); */
  2123. Bits result = new Bits(datasize);
  2124. Bits operand = V(datasize, n);
  2125. Bits element;
  2126. for (int e = 0; e <= elements - 1; e++)
  2127. {
  2128. element = Elem(operand, e, esize);
  2129. Elem(result, e, esize, NOT(element));
  2130. }
  2131. V(d, result);
  2132. }
  2133. // sqxtn_advsimd.html#SQXTN_asisdmisc_N
  2134. public static void Sqxtn_S(Bits size, Bits Rn, Bits Rd)
  2135. {
  2136. const bool U = false;
  2137. /* Decode Scalar */
  2138. int d = (int)UInt(Rd);
  2139. int n = (int)UInt(Rn);
  2140. /* if size == '11' then ReservedValue(); */
  2141. int esize = 8 << (int)UInt(size);
  2142. int datasize = esize;
  2143. int part = 0;
  2144. int elements = 1;
  2145. bool unsigned = (U == true);
  2146. /* Operation */
  2147. /* CheckFPAdvSIMDEnabled64(); */
  2148. Bits result = new Bits(datasize);
  2149. Bits operand = V(2 * datasize, n);
  2150. Bits element;
  2151. bool sat;
  2152. for (int e = 0; e <= elements - 1; e++)
  2153. {
  2154. element = Elem(operand, e, 2 * esize);
  2155. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2156. Elem(result, e, esize, _result);
  2157. sat = _sat;
  2158. if (sat)
  2159. {
  2160. /* FPSR.QC = '1'; */
  2161. FPSR[27] = true; // TODO: Add named fields.
  2162. }
  2163. }
  2164. Vpart(d, part, result);
  2165. }
  2166. // sqxtn_advsimd.html#SQXTN_asimdmisc_N
  2167. public static void Sqxtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2168. {
  2169. const bool U = false;
  2170. /* Decode Vector */
  2171. int d = (int)UInt(Rd);
  2172. int n = (int)UInt(Rn);
  2173. /* if size == '11' then ReservedValue(); */
  2174. int esize = 8 << (int)UInt(size);
  2175. int datasize = 64;
  2176. int part = (int)UInt(Q);
  2177. int elements = datasize / esize;
  2178. bool unsigned = (U == true);
  2179. /* Operation */
  2180. /* CheckFPAdvSIMDEnabled64(); */
  2181. Bits result = new Bits(datasize);
  2182. Bits operand = V(2 * datasize, n);
  2183. Bits element;
  2184. bool sat;
  2185. for (int e = 0; e <= elements - 1; e++)
  2186. {
  2187. element = Elem(operand, e, 2 * esize);
  2188. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2189. Elem(result, e, esize, _result);
  2190. sat = _sat;
  2191. if (sat)
  2192. {
  2193. /* FPSR.QC = '1'; */
  2194. FPSR[27] = true; // TODO: Add named fields.
  2195. }
  2196. }
  2197. Vpart(d, part, result);
  2198. }
  2199. // sqxtun_advsimd.html#SQXTUN_asisdmisc_N
  2200. public static void Sqxtun_S(Bits size, Bits Rn, Bits Rd)
  2201. {
  2202. /* Decode Scalar */
  2203. int d = (int)UInt(Rd);
  2204. int n = (int)UInt(Rn);
  2205. /* if size == '11' then ReservedValue(); */
  2206. int esize = 8 << (int)UInt(size);
  2207. int datasize = esize;
  2208. int part = 0;
  2209. int elements = 1;
  2210. /* Operation */
  2211. /* CheckFPAdvSIMDEnabled64(); */
  2212. Bits result = new Bits(datasize);
  2213. Bits operand = V(2 * datasize, n);
  2214. Bits element;
  2215. bool sat;
  2216. for (int e = 0; e <= elements - 1; e++)
  2217. {
  2218. element = Elem(operand, e, 2 * esize);
  2219. (Bits _result, bool _sat) = UnsignedSatQ(SInt(element), esize);
  2220. Elem(result, e, esize, _result);
  2221. sat = _sat;
  2222. if (sat)
  2223. {
  2224. /* FPSR.QC = '1'; */
  2225. FPSR[27] = true; // TODO: Add named fields.
  2226. }
  2227. }
  2228. Vpart(d, part, result);
  2229. }
  2230. // sqxtun_advsimd.html#SQXTUN_asimdmisc_N
  2231. public static void Sqxtun_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2232. {
  2233. /* Decode Vector */
  2234. int d = (int)UInt(Rd);
  2235. int n = (int)UInt(Rn);
  2236. /* if size == '11' then ReservedValue(); */
  2237. int esize = 8 << (int)UInt(size);
  2238. int datasize = 64;
  2239. int part = (int)UInt(Q);
  2240. int elements = datasize / esize;
  2241. /* Operation */
  2242. /* CheckFPAdvSIMDEnabled64(); */
  2243. Bits result = new Bits(datasize);
  2244. Bits operand = V(2 * datasize, n);
  2245. Bits element;
  2246. bool sat;
  2247. for (int e = 0; e <= elements - 1; e++)
  2248. {
  2249. element = Elem(operand, e, 2 * esize);
  2250. (Bits _result, bool _sat) = UnsignedSatQ(SInt(element), esize);
  2251. Elem(result, e, esize, _result);
  2252. sat = _sat;
  2253. if (sat)
  2254. {
  2255. /* FPSR.QC = '1'; */
  2256. FPSR[27] = true; // TODO: Add named fields.
  2257. }
  2258. }
  2259. Vpart(d, part, result);
  2260. }
  2261. // uqxtn_advsimd.html#UQXTN_asisdmisc_N
  2262. public static void Uqxtn_S(Bits size, Bits Rn, Bits Rd)
  2263. {
  2264. const bool U = true;
  2265. /* Decode Scalar */
  2266. int d = (int)UInt(Rd);
  2267. int n = (int)UInt(Rn);
  2268. /* if size == '11' then ReservedValue(); */
  2269. int esize = 8 << (int)UInt(size);
  2270. int datasize = esize;
  2271. int part = 0;
  2272. int elements = 1;
  2273. bool unsigned = (U == true);
  2274. /* Operation */
  2275. /* CheckFPAdvSIMDEnabled64(); */
  2276. Bits result = new Bits(datasize);
  2277. Bits operand = V(2 * datasize, n);
  2278. Bits element;
  2279. bool sat;
  2280. for (int e = 0; e <= elements - 1; e++)
  2281. {
  2282. element = Elem(operand, e, 2 * esize);
  2283. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2284. Elem(result, e, esize, _result);
  2285. sat = _sat;
  2286. if (sat)
  2287. {
  2288. /* FPSR.QC = '1'; */
  2289. FPSR[27] = true; // TODO: Add named fields.
  2290. }
  2291. }
  2292. Vpart(d, part, result);
  2293. }
  2294. // uqxtn_advsimd.html#UQXTN_asimdmisc_N
  2295. public static void Uqxtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2296. {
  2297. const bool U = true;
  2298. /* Decode Vector */
  2299. int d = (int)UInt(Rd);
  2300. int n = (int)UInt(Rn);
  2301. /* if size == '11' then ReservedValue(); */
  2302. int esize = 8 << (int)UInt(size);
  2303. int datasize = 64;
  2304. int part = (int)UInt(Q);
  2305. int elements = datasize / esize;
  2306. bool unsigned = (U == true);
  2307. /* Operation */
  2308. /* CheckFPAdvSIMDEnabled64(); */
  2309. Bits result = new Bits(datasize);
  2310. Bits operand = V(2 * datasize, n);
  2311. Bits element;
  2312. bool sat;
  2313. for (int e = 0; e <= elements - 1; e++)
  2314. {
  2315. element = Elem(operand, e, 2 * esize);
  2316. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2317. Elem(result, e, esize, _result);
  2318. sat = _sat;
  2319. if (sat)
  2320. {
  2321. /* FPSR.QC = '1'; */
  2322. FPSR[27] = true; // TODO: Add named fields.
  2323. }
  2324. }
  2325. Vpart(d, part, result);
  2326. }
  2327. #endregion
  2328. #region "SimdReg"
  2329. // add_advsimd.html#ADD_asisdsame_only
  2330. public static void Add_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2331. {
  2332. const bool U = false;
  2333. /* Decode Scalar */
  2334. int d = (int)UInt(Rd);
  2335. int n = (int)UInt(Rn);
  2336. int m = (int)UInt(Rm);
  2337. /* if size != '11' then ReservedValue(); */
  2338. int esize = 8 << (int)UInt(size);
  2339. int datasize = esize;
  2340. int elements = 1;
  2341. bool sub_op = (U == true);
  2342. /* Operation */
  2343. /* CheckFPAdvSIMDEnabled64(); */
  2344. Bits result = new Bits(datasize);
  2345. Bits operand1 = V(datasize, n);
  2346. Bits operand2 = V(datasize, m);
  2347. Bits element1;
  2348. Bits element2;
  2349. for (int e = 0; e <= elements - 1; e++)
  2350. {
  2351. element1 = Elem(operand1, e, esize);
  2352. element2 = Elem(operand2, e, esize);
  2353. if (sub_op)
  2354. {
  2355. Elem(result, e, esize, element1 - element2);
  2356. }
  2357. else
  2358. {
  2359. Elem(result, e, esize, element1 + element2);
  2360. }
  2361. }
  2362. V(d, result);
  2363. }
  2364. // add_advsimd.html#ADD_asimdsame_only
  2365. public static void Add_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2366. {
  2367. const bool U = false;
  2368. /* Decode Vector */
  2369. int d = (int)UInt(Rd);
  2370. int n = (int)UInt(Rn);
  2371. int m = (int)UInt(Rm);
  2372. /* if size:Q == '110' then ReservedValue(); */
  2373. int esize = 8 << (int)UInt(size);
  2374. int datasize = (Q ? 128 : 64);
  2375. int elements = datasize / esize;
  2376. bool sub_op = (U == true);
  2377. /* Operation */
  2378. /* CheckFPAdvSIMDEnabled64(); */
  2379. Bits result = new Bits(datasize);
  2380. Bits operand1 = V(datasize, n);
  2381. Bits operand2 = V(datasize, m);
  2382. Bits element1;
  2383. Bits element2;
  2384. for (int e = 0; e <= elements - 1; e++)
  2385. {
  2386. element1 = Elem(operand1, e, esize);
  2387. element2 = Elem(operand2, e, esize);
  2388. if (sub_op)
  2389. {
  2390. Elem(result, e, esize, element1 - element2);
  2391. }
  2392. else
  2393. {
  2394. Elem(result, e, esize, element1 + element2);
  2395. }
  2396. }
  2397. V(d, result);
  2398. }
  2399. // addhn_advsimd.html
  2400. public static void Addhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2401. {
  2402. const bool U = false;
  2403. const bool o1 = false;
  2404. /* Decode */
  2405. int d = (int)UInt(Rd);
  2406. int n = (int)UInt(Rn);
  2407. int m = (int)UInt(Rm);
  2408. /* if size == '11' then ReservedValue(); */
  2409. int esize = 8 << (int)UInt(size);
  2410. int datasize = 64;
  2411. int part = (int)UInt(Q);
  2412. int elements = datasize / esize;
  2413. bool sub_op = (o1 == true);
  2414. bool round = (U == true);
  2415. /* Operation */
  2416. /* CheckFPAdvSIMDEnabled64(); */
  2417. Bits result = new Bits(datasize);
  2418. Bits operand1 = V(2 * datasize, n);
  2419. Bits operand2 = V(2 * datasize, m);
  2420. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  2421. Bits sum;
  2422. Bits element1;
  2423. Bits element2;
  2424. for (int e = 0; e <= elements - 1; e++)
  2425. {
  2426. element1 = Elem(operand1, e, 2 * esize);
  2427. element2 = Elem(operand2, e, 2 * esize);
  2428. if (sub_op)
  2429. {
  2430. sum = element1 - element2;
  2431. }
  2432. else
  2433. {
  2434. sum = element1 + element2;
  2435. }
  2436. sum = sum + round_const;
  2437. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  2438. }
  2439. Vpart(d, part, result);
  2440. }
  2441. // addp_advsimd_vec.html
  2442. public static void Addp_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2443. {
  2444. /* Decode */
  2445. int d = (int)UInt(Rd);
  2446. int n = (int)UInt(Rn);
  2447. int m = (int)UInt(Rm);
  2448. /* if size:Q == '110' then ReservedValue(); */
  2449. int esize = 8 << (int)UInt(size);
  2450. int datasize = (Q ? 128 : 64);
  2451. int elements = datasize / esize;
  2452. /* Operation */
  2453. /* CheckFPAdvSIMDEnabled64(); */
  2454. Bits result = new Bits(datasize);
  2455. Bits operand1 = V(datasize, n);
  2456. Bits operand2 = V(datasize, m);
  2457. Bits concat = Bits.Concat(operand2, operand1);
  2458. Bits element1;
  2459. Bits element2;
  2460. for (int e = 0; e <= elements - 1; e++)
  2461. {
  2462. element1 = Elem(concat, 2 * e, esize);
  2463. element2 = Elem(concat, (2 * e) + 1, esize);
  2464. Elem(result, e, esize, element1 + element2);
  2465. }
  2466. V(d, result);
  2467. }
  2468. // and_advsimd.html
  2469. public static void And_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2470. {
  2471. /* Decode */
  2472. int d = (int)UInt(Rd);
  2473. int n = (int)UInt(Rn);
  2474. int m = (int)UInt(Rm);
  2475. int datasize = (Q ? 128 : 64);
  2476. /* Operation */
  2477. /* CheckFPAdvSIMDEnabled64(); */
  2478. Bits operand1 = V(datasize, n);
  2479. Bits operand2 = V(datasize, m);
  2480. Bits result = AND(operand1, operand2);
  2481. V(d, result);
  2482. }
  2483. // bic_advsimd_reg.html
  2484. public static void Bic_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2485. {
  2486. /* Decode */
  2487. int d = (int)UInt(Rd);
  2488. int n = (int)UInt(Rn);
  2489. int m = (int)UInt(Rm);
  2490. int datasize = (Q ? 128 : 64);
  2491. /* Operation */
  2492. /* CheckFPAdvSIMDEnabled64(); */
  2493. Bits operand1 = V(datasize, n);
  2494. Bits operand2 = V(datasize, m);
  2495. operand2 = NOT(operand2);
  2496. Bits result = AND(operand1, operand2);
  2497. V(d, result);
  2498. }
  2499. // bif_advsimd.html
  2500. public static void Bif_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2501. {
  2502. /* Decode */
  2503. int d = (int)UInt(Rd);
  2504. int n = (int)UInt(Rn);
  2505. int m = (int)UInt(Rm);
  2506. int datasize = (Q ? 128 : 64);
  2507. /* Operation */
  2508. /* CheckFPAdvSIMDEnabled64(); */
  2509. Bits operand1;
  2510. Bits operand3;
  2511. Bits operand4 = V(datasize, n);
  2512. operand1 = V(datasize, d);
  2513. operand3 = NOT(V(datasize, m));
  2514. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2515. }
  2516. // bit_advsimd.html
  2517. public static void Bit_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2518. {
  2519. /* Decode */
  2520. int d = (int)UInt(Rd);
  2521. int n = (int)UInt(Rn);
  2522. int m = (int)UInt(Rm);
  2523. int datasize = (Q ? 128 : 64);
  2524. /* Operation */
  2525. /* CheckFPAdvSIMDEnabled64(); */
  2526. Bits operand1;
  2527. Bits operand3;
  2528. Bits operand4 = V(datasize, n);
  2529. operand1 = V(datasize, d);
  2530. operand3 = V(datasize, m);
  2531. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2532. }
  2533. // bsl_advsimd.html
  2534. public static void Bsl_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2535. {
  2536. /* Decode */
  2537. int d = (int)UInt(Rd);
  2538. int n = (int)UInt(Rn);
  2539. int m = (int)UInt(Rm);
  2540. int datasize = (Q ? 128 : 64);
  2541. /* Operation */
  2542. /* CheckFPAdvSIMDEnabled64(); */
  2543. Bits operand1;
  2544. Bits operand3;
  2545. Bits operand4 = V(datasize, n);
  2546. operand1 = V(datasize, m);
  2547. operand3 = V(datasize, d);
  2548. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2549. }
  2550. // cmeq_advsimd_reg.html#CMEQ_asisdsame_only
  2551. public static void Cmeq_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2552. {
  2553. const bool U = true;
  2554. /* Decode Scalar */
  2555. int d = (int)UInt(Rd);
  2556. int n = (int)UInt(Rn);
  2557. int m = (int)UInt(Rm);
  2558. /* if size != '11' then ReservedValue(); */
  2559. int esize = 8 << (int)UInt(size);
  2560. int datasize = esize;
  2561. int elements = 1;
  2562. bool and_test = (U == false);
  2563. /* Operation */
  2564. /* CheckFPAdvSIMDEnabled64(); */
  2565. Bits result = new Bits(datasize);
  2566. Bits operand1 = V(datasize, n);
  2567. Bits operand2 = V(datasize, m);
  2568. Bits element1;
  2569. Bits element2;
  2570. bool test_passed;
  2571. for (int e = 0; e <= elements - 1; e++)
  2572. {
  2573. element1 = Elem(operand1, e, esize);
  2574. element2 = Elem(operand2, e, esize);
  2575. if (and_test)
  2576. {
  2577. test_passed = !IsZero(AND(element1, element2));
  2578. }
  2579. else
  2580. {
  2581. test_passed = (element1 == element2);
  2582. }
  2583. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2584. }
  2585. V(d, result);
  2586. }
  2587. // cmeq_advsimd_reg.html#CMEQ_asimdsame_only
  2588. public static void Cmeq_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2589. {
  2590. const bool U = true;
  2591. /* Decode Vector */
  2592. int d = (int)UInt(Rd);
  2593. int n = (int)UInt(Rn);
  2594. int m = (int)UInt(Rm);
  2595. /* if size:Q == '110' then ReservedValue(); */
  2596. int esize = 8 << (int)UInt(size);
  2597. int datasize = (Q ? 128 : 64);
  2598. int elements = datasize / esize;
  2599. bool and_test = (U == false);
  2600. /* Operation */
  2601. /* CheckFPAdvSIMDEnabled64(); */
  2602. Bits result = new Bits(datasize);
  2603. Bits operand1 = V(datasize, n);
  2604. Bits operand2 = V(datasize, m);
  2605. Bits element1;
  2606. Bits element2;
  2607. bool test_passed;
  2608. for (int e = 0; e <= elements - 1; e++)
  2609. {
  2610. element1 = Elem(operand1, e, esize);
  2611. element2 = Elem(operand2, e, esize);
  2612. if (and_test)
  2613. {
  2614. test_passed = !IsZero(AND(element1, element2));
  2615. }
  2616. else
  2617. {
  2618. test_passed = (element1 == element2);
  2619. }
  2620. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2621. }
  2622. V(d, result);
  2623. }
  2624. // cmge_advsimd_reg.html#CMGE_asisdsame_only
  2625. public static void Cmge_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2626. {
  2627. const bool U = false;
  2628. const bool eq = true;
  2629. /* Decode Scalar */
  2630. int d = (int)UInt(Rd);
  2631. int n = (int)UInt(Rn);
  2632. int m = (int)UInt(Rm);
  2633. /* if size != '11' then ReservedValue(); */
  2634. int esize = 8 << (int)UInt(size);
  2635. int datasize = esize;
  2636. int elements = 1;
  2637. bool unsigned = (U == true);
  2638. bool cmp_eq = (eq == true);
  2639. /* Operation */
  2640. /* CheckFPAdvSIMDEnabled64(); */
  2641. Bits result = new Bits(datasize);
  2642. Bits operand1 = V(datasize, n);
  2643. Bits operand2 = V(datasize, m);
  2644. BigInteger element1;
  2645. BigInteger element2;
  2646. bool test_passed;
  2647. for (int e = 0; e <= elements - 1; e++)
  2648. {
  2649. element1 = Int(Elem(operand1, e, esize), unsigned);
  2650. element2 = Int(Elem(operand2, e, esize), unsigned);
  2651. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2652. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2653. }
  2654. V(d, result);
  2655. }
  2656. // cmge_advsimd_reg.html#CMGE_asimdsame_only
  2657. public static void Cmge_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2658. {
  2659. const bool U = false;
  2660. const bool eq = true;
  2661. /* Decode Vector */
  2662. int d = (int)UInt(Rd);
  2663. int n = (int)UInt(Rn);
  2664. int m = (int)UInt(Rm);
  2665. /* if size:Q == '110' then ReservedValue(); */
  2666. int esize = 8 << (int)UInt(size);
  2667. int datasize = (Q ? 128 : 64);
  2668. int elements = datasize / esize;
  2669. bool unsigned = (U == true);
  2670. bool cmp_eq = (eq == true);
  2671. /* Operation */
  2672. /* CheckFPAdvSIMDEnabled64(); */
  2673. Bits result = new Bits(datasize);
  2674. Bits operand1 = V(datasize, n);
  2675. Bits operand2 = V(datasize, m);
  2676. BigInteger element1;
  2677. BigInteger element2;
  2678. bool test_passed;
  2679. for (int e = 0; e <= elements - 1; e++)
  2680. {
  2681. element1 = Int(Elem(operand1, e, esize), unsigned);
  2682. element2 = Int(Elem(operand2, e, esize), unsigned);
  2683. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2684. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2685. }
  2686. V(d, result);
  2687. }
  2688. // cmgt_advsimd_reg.html#CMGT_asisdsame_only
  2689. public static void Cmgt_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2690. {
  2691. const bool U = false;
  2692. const bool eq = false;
  2693. /* Decode Scalar */
  2694. int d = (int)UInt(Rd);
  2695. int n = (int)UInt(Rn);
  2696. int m = (int)UInt(Rm);
  2697. /* if size != '11' then ReservedValue(); */
  2698. int esize = 8 << (int)UInt(size);
  2699. int datasize = esize;
  2700. int elements = 1;
  2701. bool unsigned = (U == true);
  2702. bool cmp_eq = (eq == true);
  2703. /* Operation */
  2704. /* CheckFPAdvSIMDEnabled64(); */
  2705. Bits result = new Bits(datasize);
  2706. Bits operand1 = V(datasize, n);
  2707. Bits operand2 = V(datasize, m);
  2708. BigInteger element1;
  2709. BigInteger element2;
  2710. bool test_passed;
  2711. for (int e = 0; e <= elements - 1; e++)
  2712. {
  2713. element1 = Int(Elem(operand1, e, esize), unsigned);
  2714. element2 = Int(Elem(operand2, e, esize), unsigned);
  2715. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2716. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2717. }
  2718. V(d, result);
  2719. }
  2720. // cmgt_advsimd_reg.html#CMGT_asimdsame_only
  2721. public static void Cmgt_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2722. {
  2723. const bool U = false;
  2724. const bool eq = false;
  2725. /* Decode Vector */
  2726. int d = (int)UInt(Rd);
  2727. int n = (int)UInt(Rn);
  2728. int m = (int)UInt(Rm);
  2729. /* if size:Q == '110' then ReservedValue(); */
  2730. int esize = 8 << (int)UInt(size);
  2731. int datasize = (Q ? 128 : 64);
  2732. int elements = datasize / esize;
  2733. bool unsigned = (U == true);
  2734. bool cmp_eq = (eq == true);
  2735. /* Operation */
  2736. /* CheckFPAdvSIMDEnabled64(); */
  2737. Bits result = new Bits(datasize);
  2738. Bits operand1 = V(datasize, n);
  2739. Bits operand2 = V(datasize, m);
  2740. BigInteger element1;
  2741. BigInteger element2;
  2742. bool test_passed;
  2743. for (int e = 0; e <= elements - 1; e++)
  2744. {
  2745. element1 = Int(Elem(operand1, e, esize), unsigned);
  2746. element2 = Int(Elem(operand2, e, esize), unsigned);
  2747. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2748. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2749. }
  2750. V(d, result);
  2751. }
  2752. // cmhi_advsimd.html#CMHI_asisdsame_only
  2753. public static void Cmhi_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2754. {
  2755. const bool U = true;
  2756. const bool eq = false;
  2757. /* Decode Scalar */
  2758. int d = (int)UInt(Rd);
  2759. int n = (int)UInt(Rn);
  2760. int m = (int)UInt(Rm);
  2761. /* if size != '11' then ReservedValue(); */
  2762. int esize = 8 << (int)UInt(size);
  2763. int datasize = esize;
  2764. int elements = 1;
  2765. bool unsigned = (U == true);
  2766. bool cmp_eq = (eq == true);
  2767. /* Operation */
  2768. /* CheckFPAdvSIMDEnabled64(); */
  2769. Bits result = new Bits(datasize);
  2770. Bits operand1 = V(datasize, n);
  2771. Bits operand2 = V(datasize, m);
  2772. BigInteger element1;
  2773. BigInteger element2;
  2774. bool test_passed;
  2775. for (int e = 0; e <= elements - 1; e++)
  2776. {
  2777. element1 = Int(Elem(operand1, e, esize), unsigned);
  2778. element2 = Int(Elem(operand2, e, esize), unsigned);
  2779. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2780. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2781. }
  2782. V(d, result);
  2783. }
  2784. // cmhi_advsimd.html#CMHI_asimdsame_only
  2785. public static void Cmhi_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2786. {
  2787. const bool U = true;
  2788. const bool eq = false;
  2789. /* Decode Vector */
  2790. int d = (int)UInt(Rd);
  2791. int n = (int)UInt(Rn);
  2792. int m = (int)UInt(Rm);
  2793. /* if size:Q == '110' then ReservedValue(); */
  2794. int esize = 8 << (int)UInt(size);
  2795. int datasize = (Q ? 128 : 64);
  2796. int elements = datasize / esize;
  2797. bool unsigned = (U == true);
  2798. bool cmp_eq = (eq == true);
  2799. /* Operation */
  2800. /* CheckFPAdvSIMDEnabled64(); */
  2801. Bits result = new Bits(datasize);
  2802. Bits operand1 = V(datasize, n);
  2803. Bits operand2 = V(datasize, m);
  2804. BigInteger element1;
  2805. BigInteger element2;
  2806. bool test_passed;
  2807. for (int e = 0; e <= elements - 1; e++)
  2808. {
  2809. element1 = Int(Elem(operand1, e, esize), unsigned);
  2810. element2 = Int(Elem(operand2, e, esize), unsigned);
  2811. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2812. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2813. }
  2814. V(d, result);
  2815. }
  2816. // cmhs_advsimd.html#CMHS_asisdsame_only
  2817. public static void Cmhs_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2818. {
  2819. const bool U = true;
  2820. const bool eq = true;
  2821. /* Decode Scalar */
  2822. int d = (int)UInt(Rd);
  2823. int n = (int)UInt(Rn);
  2824. int m = (int)UInt(Rm);
  2825. /* if size != '11' then ReservedValue(); */
  2826. int esize = 8 << (int)UInt(size);
  2827. int datasize = esize;
  2828. int elements = 1;
  2829. bool unsigned = (U == true);
  2830. bool cmp_eq = (eq == true);
  2831. /* Operation */
  2832. /* CheckFPAdvSIMDEnabled64(); */
  2833. Bits result = new Bits(datasize);
  2834. Bits operand1 = V(datasize, n);
  2835. Bits operand2 = V(datasize, m);
  2836. BigInteger element1;
  2837. BigInteger element2;
  2838. bool test_passed;
  2839. for (int e = 0; e <= elements - 1; e++)
  2840. {
  2841. element1 = Int(Elem(operand1, e, esize), unsigned);
  2842. element2 = Int(Elem(operand2, e, esize), unsigned);
  2843. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2844. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2845. }
  2846. V(d, result);
  2847. }
  2848. // cmhs_advsimd.html#CMHS_asimdsame_only
  2849. public static void Cmhs_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2850. {
  2851. const bool U = true;
  2852. const bool eq = true;
  2853. /* Decode Vector */
  2854. int d = (int)UInt(Rd);
  2855. int n = (int)UInt(Rn);
  2856. int m = (int)UInt(Rm);
  2857. /* if size:Q == '110' then ReservedValue(); */
  2858. int esize = 8 << (int)UInt(size);
  2859. int datasize = (Q ? 128 : 64);
  2860. int elements = datasize / esize;
  2861. bool unsigned = (U == true);
  2862. bool cmp_eq = (eq == true);
  2863. /* Operation */
  2864. /* CheckFPAdvSIMDEnabled64(); */
  2865. Bits result = new Bits(datasize);
  2866. Bits operand1 = V(datasize, n);
  2867. Bits operand2 = V(datasize, m);
  2868. BigInteger element1;
  2869. BigInteger element2;
  2870. bool test_passed;
  2871. for (int e = 0; e <= elements - 1; e++)
  2872. {
  2873. element1 = Int(Elem(operand1, e, esize), unsigned);
  2874. element2 = Int(Elem(operand2, e, esize), unsigned);
  2875. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2876. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2877. }
  2878. V(d, result);
  2879. }
  2880. // cmtst_advsimd.html#CMTST_asisdsame_only
  2881. public static void Cmtst_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2882. {
  2883. const bool U = false;
  2884. /* Decode Scalar */
  2885. int d = (int)UInt(Rd);
  2886. int n = (int)UInt(Rn);
  2887. int m = (int)UInt(Rm);
  2888. /* if size != '11' then ReservedValue(); */
  2889. int esize = 8 << (int)UInt(size);
  2890. int datasize = esize;
  2891. int elements = 1;
  2892. bool and_test = (U == false);
  2893. /* Operation */
  2894. /* CheckFPAdvSIMDEnabled64(); */
  2895. Bits result = new Bits(datasize);
  2896. Bits operand1 = V(datasize, n);
  2897. Bits operand2 = V(datasize, m);
  2898. Bits element1;
  2899. Bits element2;
  2900. bool test_passed;
  2901. for (int e = 0; e <= elements - 1; e++)
  2902. {
  2903. element1 = Elem(operand1, e, esize);
  2904. element2 = Elem(operand2, e, esize);
  2905. if (and_test)
  2906. {
  2907. test_passed = !IsZero(AND(element1, element2));
  2908. }
  2909. else
  2910. {
  2911. test_passed = (element1 == element2);
  2912. }
  2913. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2914. }
  2915. V(d, result);
  2916. }
  2917. // cmtst_advsimd.html#CMTST_asimdsame_only
  2918. public static void Cmtst_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2919. {
  2920. const bool U = false;
  2921. /* Decode Vector */
  2922. int d = (int)UInt(Rd);
  2923. int n = (int)UInt(Rn);
  2924. int m = (int)UInt(Rm);
  2925. /* if size:Q == '110' then ReservedValue(); */
  2926. int esize = 8 << (int)UInt(size);
  2927. int datasize = (Q ? 128 : 64);
  2928. int elements = datasize / esize;
  2929. bool and_test = (U == false);
  2930. /* Operation */
  2931. /* CheckFPAdvSIMDEnabled64(); */
  2932. Bits result = new Bits(datasize);
  2933. Bits operand1 = V(datasize, n);
  2934. Bits operand2 = V(datasize, m);
  2935. Bits element1;
  2936. Bits element2;
  2937. bool test_passed;
  2938. for (int e = 0; e <= elements - 1; e++)
  2939. {
  2940. element1 = Elem(operand1, e, esize);
  2941. element2 = Elem(operand2, e, esize);
  2942. if (and_test)
  2943. {
  2944. test_passed = !IsZero(AND(element1, element2));
  2945. }
  2946. else
  2947. {
  2948. test_passed = (element1 == element2);
  2949. }
  2950. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2951. }
  2952. V(d, result);
  2953. }
  2954. // eor_advsimd.html
  2955. public static void Eor_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2956. {
  2957. /* Decode */
  2958. int d = (int)UInt(Rd);
  2959. int n = (int)UInt(Rn);
  2960. int m = (int)UInt(Rm);
  2961. int datasize = (Q ? 128 : 64);
  2962. /* Operation */
  2963. /* CheckFPAdvSIMDEnabled64(); */
  2964. Bits operand1 = V(datasize, m);
  2965. Bits operand2 = Zeros(datasize);
  2966. Bits operand3 = Ones(datasize);
  2967. Bits operand4 = V(datasize, n);
  2968. Bits result = EOR(operand1, AND(EOR(operand2, operand4), operand3));
  2969. V(d, result);
  2970. }
  2971. // orn_advsimd.html
  2972. public static void Orn_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2973. {
  2974. /* Decode */
  2975. int d = (int)UInt(Rd);
  2976. int n = (int)UInt(Rn);
  2977. int m = (int)UInt(Rm);
  2978. int datasize = (Q ? 128 : 64);
  2979. /* Operation */
  2980. /* CheckFPAdvSIMDEnabled64(); */
  2981. Bits operand1 = V(datasize, n);
  2982. Bits operand2 = V(datasize, m);
  2983. operand2 = NOT(operand2);
  2984. Bits result = OR(operand1, operand2);
  2985. V(d, result);
  2986. }
  2987. // orr_advsimd_reg.html
  2988. public static void Orr_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2989. {
  2990. /* Decode */
  2991. int d = (int)UInt(Rd);
  2992. int n = (int)UInt(Rn);
  2993. int m = (int)UInt(Rm);
  2994. int datasize = (Q ? 128 : 64);
  2995. /* Operation */
  2996. /* CheckFPAdvSIMDEnabled64(); */
  2997. Bits operand1 = V(datasize, n);
  2998. Bits operand2 = V(datasize, m);
  2999. Bits result = OR(operand1, operand2);
  3000. V(d, result);
  3001. }
  3002. // raddhn_advsimd.html
  3003. public static void Raddhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3004. {
  3005. const bool U = true;
  3006. const bool o1 = false;
  3007. /* Decode */
  3008. int d = (int)UInt(Rd);
  3009. int n = (int)UInt(Rn);
  3010. int m = (int)UInt(Rm);
  3011. /* if size == '11' then ReservedValue(); */
  3012. int esize = 8 << (int)UInt(size);
  3013. int datasize = 64;
  3014. int part = (int)UInt(Q);
  3015. int elements = datasize / esize;
  3016. bool sub_op = (o1 == true);
  3017. bool round = (U == true);
  3018. /* Operation */
  3019. /* CheckFPAdvSIMDEnabled64(); */
  3020. Bits result = new Bits(datasize);
  3021. Bits operand1 = V(2 * datasize, n);
  3022. Bits operand2 = V(2 * datasize, m);
  3023. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3024. Bits sum;
  3025. Bits element1;
  3026. Bits element2;
  3027. for (int e = 0; e <= elements - 1; e++)
  3028. {
  3029. element1 = Elem(operand1, e, 2 * esize);
  3030. element2 = Elem(operand2, e, 2 * esize);
  3031. if (sub_op)
  3032. {
  3033. sum = element1 - element2;
  3034. }
  3035. else
  3036. {
  3037. sum = element1 + element2;
  3038. }
  3039. sum = sum + round_const;
  3040. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3041. }
  3042. Vpart(d, part, result);
  3043. }
  3044. // rsubhn_advsimd.html
  3045. public static void Rsubhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3046. {
  3047. const bool U = true;
  3048. const bool o1 = true;
  3049. /* Decode */
  3050. int d = (int)UInt(Rd);
  3051. int n = (int)UInt(Rn);
  3052. int m = (int)UInt(Rm);
  3053. /* if size == '11' then ReservedValue(); */
  3054. int esize = 8 << (int)UInt(size);
  3055. int datasize = 64;
  3056. int part = (int)UInt(Q);
  3057. int elements = datasize / esize;
  3058. bool sub_op = (o1 == true);
  3059. bool round = (U == true);
  3060. /* Operation */
  3061. /* CheckFPAdvSIMDEnabled64(); */
  3062. Bits result = new Bits(datasize);
  3063. Bits operand1 = V(2 * datasize, n);
  3064. Bits operand2 = V(2 * datasize, m);
  3065. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3066. Bits sum;
  3067. Bits element1;
  3068. Bits element2;
  3069. for (int e = 0; e <= elements - 1; e++)
  3070. {
  3071. element1 = Elem(operand1, e, 2 * esize);
  3072. element2 = Elem(operand2, e, 2 * esize);
  3073. if (sub_op)
  3074. {
  3075. sum = element1 - element2;
  3076. }
  3077. else
  3078. {
  3079. sum = element1 + element2;
  3080. }
  3081. sum = sum + round_const;
  3082. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3083. }
  3084. Vpart(d, part, result);
  3085. }
  3086. // saba_advsimd.html
  3087. public static void Saba_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3088. {
  3089. const bool U = false;
  3090. const bool ac = true;
  3091. /* Decode */
  3092. int d = (int)UInt(Rd);
  3093. int n = (int)UInt(Rn);
  3094. int m = (int)UInt(Rm);
  3095. /* if size == '11' then ReservedValue(); */
  3096. int esize = 8 << (int)UInt(size);
  3097. int datasize = (Q ? 128 : 64);
  3098. int elements = datasize / esize;
  3099. bool unsigned = (U == true);
  3100. bool accumulate = (ac == true);
  3101. /* Operation */
  3102. /* CheckFPAdvSIMDEnabled64(); */
  3103. Bits operand1 = V(datasize, n);
  3104. Bits operand2 = V(datasize, m);
  3105. BigInteger element1;
  3106. BigInteger element2;
  3107. Bits absdiff;
  3108. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3109. for (int e = 0; e <= elements - 1; e++)
  3110. {
  3111. element1 = Int(Elem(operand1, e, esize), unsigned);
  3112. element2 = Int(Elem(operand2, e, esize), unsigned);
  3113. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3114. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3115. }
  3116. V(d, result);
  3117. }
  3118. // sabal_advsimd.html
  3119. public static void Sabal_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3120. {
  3121. const bool U = false;
  3122. const bool op = false;
  3123. /* Decode */
  3124. int d = (int)UInt(Rd);
  3125. int n = (int)UInt(Rn);
  3126. int m = (int)UInt(Rm);
  3127. /* if size == '11' then ReservedValue(); */
  3128. int esize = 8 << (int)UInt(size);
  3129. int datasize = 64;
  3130. int part = (int)UInt(Q);
  3131. int elements = datasize / esize;
  3132. bool unsigned = (U == true);
  3133. bool accumulate = (op == false);
  3134. /* Operation */
  3135. /* CheckFPAdvSIMDEnabled64(); */
  3136. Bits operand1 = Vpart(datasize, n, part);
  3137. Bits operand2 = Vpart(datasize, m, part);
  3138. BigInteger element1;
  3139. BigInteger element2;
  3140. Bits absdiff;
  3141. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3142. for (int e = 0; e <= elements - 1; e++)
  3143. {
  3144. element1 = Int(Elem(operand1, e, esize), unsigned);
  3145. element2 = Int(Elem(operand2, e, esize), unsigned);
  3146. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3147. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3148. }
  3149. V(d, result);
  3150. }
  3151. // sabd_advsimd.html
  3152. public static void Sabd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3153. {
  3154. const bool U = false;
  3155. const bool ac = false;
  3156. /* Decode */
  3157. int d = (int)UInt(Rd);
  3158. int n = (int)UInt(Rn);
  3159. int m = (int)UInt(Rm);
  3160. /* if size == '11' then ReservedValue(); */
  3161. int esize = 8 << (int)UInt(size);
  3162. int datasize = (Q ? 128 : 64);
  3163. int elements = datasize / esize;
  3164. bool unsigned = (U == true);
  3165. bool accumulate = (ac == true);
  3166. /* Operation */
  3167. /* CheckFPAdvSIMDEnabled64(); */
  3168. Bits operand1 = V(datasize, n);
  3169. Bits operand2 = V(datasize, m);
  3170. BigInteger element1;
  3171. BigInteger element2;
  3172. Bits absdiff;
  3173. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3174. for (int e = 0; e <= elements - 1; e++)
  3175. {
  3176. element1 = Int(Elem(operand1, e, esize), unsigned);
  3177. element2 = Int(Elem(operand2, e, esize), unsigned);
  3178. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3179. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3180. }
  3181. V(d, result);
  3182. }
  3183. // sabdl_advsimd.html
  3184. public static void Sabdl_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3185. {
  3186. const bool U = false;
  3187. const bool op = true;
  3188. /* Decode */
  3189. int d = (int)UInt(Rd);
  3190. int n = (int)UInt(Rn);
  3191. int m = (int)UInt(Rm);
  3192. /* if size == '11' then ReservedValue(); */
  3193. int esize = 8 << (int)UInt(size);
  3194. int datasize = 64;
  3195. int part = (int)UInt(Q);
  3196. int elements = datasize / esize;
  3197. bool unsigned = (U == true);
  3198. bool accumulate = (op == false);
  3199. /* Operation */
  3200. /* CheckFPAdvSIMDEnabled64(); */
  3201. Bits operand1 = Vpart(datasize, n, part);
  3202. Bits operand2 = Vpart(datasize, m, part);
  3203. BigInteger element1;
  3204. BigInteger element2;
  3205. Bits absdiff;
  3206. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3207. for (int e = 0; e <= elements - 1; e++)
  3208. {
  3209. element1 = Int(Elem(operand1, e, esize), unsigned);
  3210. element2 = Int(Elem(operand2, e, esize), unsigned);
  3211. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3212. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3213. }
  3214. V(d, result);
  3215. }
  3216. // sub_advsimd.html#SUB_asisdsame_only
  3217. public static void Sub_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3218. {
  3219. const bool U = true;
  3220. /* Decode Scalar */
  3221. int d = (int)UInt(Rd);
  3222. int n = (int)UInt(Rn);
  3223. int m = (int)UInt(Rm);
  3224. /* if size != '11' then ReservedValue(); */
  3225. int esize = 8 << (int)UInt(size);
  3226. int datasize = esize;
  3227. int elements = 1;
  3228. bool sub_op = (U == true);
  3229. /* Operation */
  3230. /* CheckFPAdvSIMDEnabled64(); */
  3231. Bits result = new Bits(datasize);
  3232. Bits operand1 = V(datasize, n);
  3233. Bits operand2 = V(datasize, m);
  3234. Bits element1;
  3235. Bits element2;
  3236. for (int e = 0; e <= elements - 1; e++)
  3237. {
  3238. element1 = Elem(operand1, e, esize);
  3239. element2 = Elem(operand2, e, esize);
  3240. if (sub_op)
  3241. {
  3242. Elem(result, e, esize, element1 - element2);
  3243. }
  3244. else
  3245. {
  3246. Elem(result, e, esize, element1 + element2);
  3247. }
  3248. }
  3249. V(d, result);
  3250. }
  3251. // sub_advsimd.html#SUB_asimdsame_only
  3252. public static void Sub_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3253. {
  3254. const bool U = true;
  3255. /* Decode Vector */
  3256. int d = (int)UInt(Rd);
  3257. int n = (int)UInt(Rn);
  3258. int m = (int)UInt(Rm);
  3259. /* if size:Q == '110' then ReservedValue(); */
  3260. int esize = 8 << (int)UInt(size);
  3261. int datasize = (Q ? 128 : 64);
  3262. int elements = datasize / esize;
  3263. bool sub_op = (U == true);
  3264. /* Operation */
  3265. /* CheckFPAdvSIMDEnabled64(); */
  3266. Bits result = new Bits(datasize);
  3267. Bits operand1 = V(datasize, n);
  3268. Bits operand2 = V(datasize, m);
  3269. Bits element1;
  3270. Bits element2;
  3271. for (int e = 0; e <= elements - 1; e++)
  3272. {
  3273. element1 = Elem(operand1, e, esize);
  3274. element2 = Elem(operand2, e, esize);
  3275. if (sub_op)
  3276. {
  3277. Elem(result, e, esize, element1 - element2);
  3278. }
  3279. else
  3280. {
  3281. Elem(result, e, esize, element1 + element2);
  3282. }
  3283. }
  3284. V(d, result);
  3285. }
  3286. // subhn_advsimd.html
  3287. public static void Subhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3288. {
  3289. const bool U = false;
  3290. const bool o1 = true;
  3291. /* Decode */
  3292. int d = (int)UInt(Rd);
  3293. int n = (int)UInt(Rn);
  3294. int m = (int)UInt(Rm);
  3295. /* if size == '11' then ReservedValue(); */
  3296. int esize = 8 << (int)UInt(size);
  3297. int datasize = 64;
  3298. int part = (int)UInt(Q);
  3299. int elements = datasize / esize;
  3300. bool sub_op = (o1 == true);
  3301. bool round = (U == true);
  3302. /* Operation */
  3303. /* CheckFPAdvSIMDEnabled64(); */
  3304. Bits result = new Bits(datasize);
  3305. Bits operand1 = V(2 * datasize, n);
  3306. Bits operand2 = V(2 * datasize, m);
  3307. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3308. Bits sum;
  3309. Bits element1;
  3310. Bits element2;
  3311. for (int e = 0; e <= elements - 1; e++)
  3312. {
  3313. element1 = Elem(operand1, e, 2 * esize);
  3314. element2 = Elem(operand2, e, 2 * esize);
  3315. if (sub_op)
  3316. {
  3317. sum = element1 - element2;
  3318. }
  3319. else
  3320. {
  3321. sum = element1 + element2;
  3322. }
  3323. sum = sum + round_const;
  3324. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3325. }
  3326. Vpart(d, part, result);
  3327. }
  3328. // uaba_advsimd.html
  3329. public static void Uaba_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3330. {
  3331. const bool U = true;
  3332. const bool ac = true;
  3333. /* Decode */
  3334. int d = (int)UInt(Rd);
  3335. int n = (int)UInt(Rn);
  3336. int m = (int)UInt(Rm);
  3337. /* if size == '11' then ReservedValue(); */
  3338. int esize = 8 << (int)UInt(size);
  3339. int datasize = (Q ? 128 : 64);
  3340. int elements = datasize / esize;
  3341. bool unsigned = (U == true);
  3342. bool accumulate = (ac == true);
  3343. /* Operation */
  3344. /* CheckFPAdvSIMDEnabled64(); */
  3345. Bits operand1 = V(datasize, n);
  3346. Bits operand2 = V(datasize, m);
  3347. BigInteger element1;
  3348. BigInteger element2;
  3349. Bits absdiff;
  3350. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3351. for (int e = 0; e <= elements - 1; e++)
  3352. {
  3353. element1 = Int(Elem(operand1, e, esize), unsigned);
  3354. element2 = Int(Elem(operand2, e, esize), unsigned);
  3355. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3356. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3357. }
  3358. V(d, result);
  3359. }
  3360. // uabal_advsimd.html
  3361. public static void Uabal_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3362. {
  3363. const bool U = true;
  3364. const bool op = false;
  3365. /* Decode */
  3366. int d = (int)UInt(Rd);
  3367. int n = (int)UInt(Rn);
  3368. int m = (int)UInt(Rm);
  3369. /* if size == '11' then ReservedValue(); */
  3370. int esize = 8 << (int)UInt(size);
  3371. int datasize = 64;
  3372. int part = (int)UInt(Q);
  3373. int elements = datasize / esize;
  3374. bool unsigned = (U == true);
  3375. bool accumulate = (op == false);
  3376. /* Operation */
  3377. /* CheckFPAdvSIMDEnabled64(); */
  3378. Bits operand1 = Vpart(datasize, n, part);
  3379. Bits operand2 = Vpart(datasize, m, part);
  3380. BigInteger element1;
  3381. BigInteger element2;
  3382. Bits absdiff;
  3383. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3384. for (int e = 0; e <= elements - 1; e++)
  3385. {
  3386. element1 = Int(Elem(operand1, e, esize), unsigned);
  3387. element2 = Int(Elem(operand2, e, esize), unsigned);
  3388. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3389. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3390. }
  3391. V(d, result);
  3392. }
  3393. // uabd_advsimd.html
  3394. public static void Uabd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3395. {
  3396. const bool U = true;
  3397. const bool ac = false;
  3398. /* Decode */
  3399. int d = (int)UInt(Rd);
  3400. int n = (int)UInt(Rn);
  3401. int m = (int)UInt(Rm);
  3402. /* if size == '11' then ReservedValue(); */
  3403. int esize = 8 << (int)UInt(size);
  3404. int datasize = (Q ? 128 : 64);
  3405. int elements = datasize / esize;
  3406. bool unsigned = (U == true);
  3407. bool accumulate = (ac == true);
  3408. /* Operation */
  3409. /* CheckFPAdvSIMDEnabled64(); */
  3410. Bits operand1 = V(datasize, n);
  3411. Bits operand2 = V(datasize, m);
  3412. BigInteger element1;
  3413. BigInteger element2;
  3414. Bits absdiff;
  3415. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3416. for (int e = 0; e <= elements - 1; e++)
  3417. {
  3418. element1 = Int(Elem(operand1, e, esize), unsigned);
  3419. element2 = Int(Elem(operand2, e, esize), unsigned);
  3420. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3421. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3422. }
  3423. V(d, result);
  3424. }
  3425. // uabdl_advsimd.html
  3426. public static void Uabdl_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3427. {
  3428. const bool U = true;
  3429. const bool op = true;
  3430. /* Decode */
  3431. int d = (int)UInt(Rd);
  3432. int n = (int)UInt(Rn);
  3433. int m = (int)UInt(Rm);
  3434. /* if size == '11' then ReservedValue(); */
  3435. int esize = 8 << (int)UInt(size);
  3436. int datasize = 64;
  3437. int part = (int)UInt(Q);
  3438. int elements = datasize / esize;
  3439. bool unsigned = (U == true);
  3440. bool accumulate = (op == false);
  3441. /* Operation */
  3442. /* CheckFPAdvSIMDEnabled64(); */
  3443. Bits operand1 = Vpart(datasize, n, part);
  3444. Bits operand2 = Vpart(datasize, m, part);
  3445. BigInteger element1;
  3446. BigInteger element2;
  3447. Bits absdiff;
  3448. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3449. for (int e = 0; e <= elements - 1; e++)
  3450. {
  3451. element1 = Int(Elem(operand1, e, esize), unsigned);
  3452. element2 = Int(Elem(operand2, e, esize), unsigned);
  3453. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3454. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3455. }
  3456. V(d, result);
  3457. }
  3458. #endregion
  3459. }
  3460. }