Instructions.cs 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280
  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. case Bits bits when bits == "00":
  1468. comparison = CompareOp.CompareOp_GT;
  1469. break;
  1470. case Bits bits when bits == "01":
  1471. comparison = CompareOp.CompareOp_GE;
  1472. break;
  1473. default:
  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. case CompareOp.CompareOp_GT:
  1493. test_passed = (element > (BigInteger)0);
  1494. break;
  1495. case CompareOp.CompareOp_GE:
  1496. test_passed = (element >= (BigInteger)0);
  1497. break;
  1498. default:
  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. case Bits bits when bits == "00":
  1529. comparison = CompareOp.CompareOp_GT;
  1530. break;
  1531. case Bits bits when bits == "01":
  1532. comparison = CompareOp.CompareOp_GE;
  1533. break;
  1534. default:
  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. case CompareOp.CompareOp_GT:
  1554. test_passed = (element > (BigInteger)0);
  1555. break;
  1556. case CompareOp.CompareOp_GE:
  1557. test_passed = (element >= (BigInteger)0);
  1558. break;
  1559. default:
  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. case Bits bits when bits == "00":
  1590. comparison = CompareOp.CompareOp_GT;
  1591. break;
  1592. default:
  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. case CompareOp.CompareOp_GT:
  1615. test_passed = (element > (BigInteger)0);
  1616. break;
  1617. default:
  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. case Bits bits when bits == "00":
  1651. comparison = CompareOp.CompareOp_GT;
  1652. break;
  1653. default:
  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. case CompareOp.CompareOp_GT:
  1676. test_passed = (element > (BigInteger)0);
  1677. break;
  1678. default:
  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. case Bits bits when bits == "00":
  1834. comparison = CompareOp.CompareOp_GT;
  1835. break;
  1836. case Bits bits when bits == "01":
  1837. comparison = CompareOp.CompareOp_GE;
  1838. break;
  1839. case Bits bits when bits == "10":
  1840. comparison = CompareOp.CompareOp_EQ;
  1841. break;
  1842. default:
  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. case CompareOp.CompareOp_GT:
  1859. test_passed = (element > (BigInteger)0);
  1860. break;
  1861. case CompareOp.CompareOp_GE:
  1862. test_passed = (element >= (BigInteger)0);
  1863. break;
  1864. case CompareOp.CompareOp_EQ:
  1865. test_passed = (element == (BigInteger)0);
  1866. break;
  1867. default:
  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. case Bits bits when bits == "00":
  1895. comparison = CompareOp.CompareOp_GT;
  1896. break;
  1897. case Bits bits when bits == "01":
  1898. comparison = CompareOp.CompareOp_GE;
  1899. break;
  1900. case Bits bits when bits == "10":
  1901. comparison = CompareOp.CompareOp_EQ;
  1902. break;
  1903. default:
  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. case CompareOp.CompareOp_GT:
  1920. test_passed = (element > (BigInteger)0);
  1921. break;
  1922. case CompareOp.CompareOp_GE:
  1923. test_passed = (element >= (BigInteger)0);
  1924. break;
  1925. case CompareOp.CompareOp_EQ:
  1926. test_passed = (element == (BigInteger)0);
  1927. break;
  1928. default:
  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. case CompareOp.CompareOp_GT:
  1963. test_passed = (element > (BigInteger)0);
  1964. break;
  1965. case CompareOp.CompareOp_GE:
  1966. test_passed = (element >= (BigInteger)0);
  1967. break;
  1968. case CompareOp.CompareOp_EQ:
  1969. test_passed = (element == (BigInteger)0);
  1970. break;
  1971. case CompareOp.CompareOp_LE:
  1972. test_passed = (element <= (BigInteger)0);
  1973. break;
  1974. default:
  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. case CompareOp.CompareOp_GT:
  2006. test_passed = (element > (BigInteger)0);
  2007. break;
  2008. case CompareOp.CompareOp_GE:
  2009. test_passed = (element >= (BigInteger)0);
  2010. break;
  2011. case CompareOp.CompareOp_EQ:
  2012. test_passed = (element == (BigInteger)0);
  2013. break;
  2014. case CompareOp.CompareOp_LE:
  2015. test_passed = (element <= (BigInteger)0);
  2016. break;
  2017. default:
  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. // rbit_advsimd.html
  2134. public static void Rbit_V(bool Q, Bits Rn, Bits Rd)
  2135. {
  2136. /* Decode Vector */
  2137. int d = (int)UInt(Rd);
  2138. int n = (int)UInt(Rn);
  2139. int esize = 8;
  2140. int datasize = (Q ? 128 : 64);
  2141. int elements = datasize / 8;
  2142. /* Operation */
  2143. /* CheckFPAdvSIMDEnabled64(); */
  2144. Bits result = new Bits(datasize);
  2145. Bits operand = V(datasize, n);
  2146. Bits element;
  2147. Bits rev = new Bits(esize);
  2148. for (int e = 0; e <= elements - 1; e++)
  2149. {
  2150. element = Elem(operand, e, esize);
  2151. for (int i = 0; i <= esize - 1; i++)
  2152. {
  2153. rev[esize - 1 - i] = element[i];
  2154. }
  2155. Elem(result, e, esize, rev);
  2156. }
  2157. V(d, result);
  2158. }
  2159. // rev16_advsimd.html
  2160. public static void Rev16_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2161. {
  2162. const bool U = false;
  2163. const bool o0 = true;
  2164. /* Decode Vector */
  2165. int d = (int)UInt(Rd);
  2166. int n = (int)UInt(Rn);
  2167. // size=esize: B(0), H(1), S(1), D(S)
  2168. int esize = 8 << (int)UInt(size);
  2169. int datasize = (Q ? 128 : 64);
  2170. // op=REVx: 64(0), 32(1), 16(2)
  2171. Bits op = Bits.Concat(o0, U);
  2172. // => op+size:
  2173. // 64+B = 0, 64+H = 1, 64+S = 2, 64+D = X
  2174. // 32+B = 1, 32+H = 2, 32+S = X, 32+D = X
  2175. // 16+B = 2, 16+H = X, 16+S = X, 16+D = X
  2176. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2177. // => 3-(op+size) (index bits in group)
  2178. // 64/B = 3, 64+H = 2, 64+S = 1, 64+D = X
  2179. // 32+B = 2, 32+H = 1, 32+S = X, 32+D = X
  2180. // 16+B = 1, 16+H = X, 16+S = X, 16+D = X
  2181. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2182. // index bits within group: 1, 2, 3
  2183. /* if UInt(op) + UInt(size) >= 3 then UnallocatedEncoding(); */
  2184. int container_size;
  2185. switch (op)
  2186. {
  2187. default:
  2188. case Bits bits when bits == "10":
  2189. container_size = 16;
  2190. break;
  2191. case Bits bits when bits == "01":
  2192. container_size = 32;
  2193. break;
  2194. case Bits bits when bits == "00":
  2195. container_size = 64;
  2196. break;
  2197. }
  2198. int containers = datasize / container_size;
  2199. int elements_per_container = container_size / esize;
  2200. /* Operation */
  2201. /* CheckFPAdvSIMDEnabled64(); */
  2202. Bits result = new Bits(datasize);
  2203. Bits operand = V(datasize, n);
  2204. int element = 0;
  2205. int rev_element;
  2206. for (int c = 0; c <= containers - 1; c++)
  2207. {
  2208. rev_element = element + elements_per_container - 1;
  2209. for (int e = 0; e <= elements_per_container - 1; e++)
  2210. {
  2211. Elem(result, rev_element, esize, Elem(operand, element, esize));
  2212. element = element + 1;
  2213. rev_element = rev_element - 1;
  2214. }
  2215. }
  2216. V(d, result);
  2217. }
  2218. // rev32_advsimd.html
  2219. public static void Rev32_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2220. {
  2221. const bool U = true;
  2222. const bool o0 = false;
  2223. /* Decode Vector */
  2224. int d = (int)UInt(Rd);
  2225. int n = (int)UInt(Rn);
  2226. // size=esize: B(0), H(1), S(1), D(S)
  2227. int esize = 8 << (int)UInt(size);
  2228. int datasize = (Q ? 128 : 64);
  2229. // op=REVx: 64(0), 32(1), 16(2)
  2230. Bits op = Bits.Concat(o0, U);
  2231. // => op+size:
  2232. // 64+B = 0, 64+H = 1, 64+S = 2, 64+D = X
  2233. // 32+B = 1, 32+H = 2, 32+S = X, 32+D = X
  2234. // 16+B = 2, 16+H = X, 16+S = X, 16+D = X
  2235. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2236. // => 3-(op+size) (index bits in group)
  2237. // 64/B = 3, 64+H = 2, 64+S = 1, 64+D = X
  2238. // 32+B = 2, 32+H = 1, 32+S = X, 32+D = X
  2239. // 16+B = 1, 16+H = X, 16+S = X, 16+D = X
  2240. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2241. // index bits within group: 1, 2, 3
  2242. /* if UInt(op) + UInt(size) >= 3 then UnallocatedEncoding(); */
  2243. int container_size;
  2244. switch (op)
  2245. {
  2246. case Bits bits when bits == "10":
  2247. container_size = 16;
  2248. break;
  2249. default:
  2250. case Bits bits when bits == "01":
  2251. container_size = 32;
  2252. break;
  2253. case Bits bits when bits == "00":
  2254. container_size = 64;
  2255. break;
  2256. }
  2257. int containers = datasize / container_size;
  2258. int elements_per_container = container_size / esize;
  2259. /* Operation */
  2260. /* CheckFPAdvSIMDEnabled64(); */
  2261. Bits result = new Bits(datasize);
  2262. Bits operand = V(datasize, n);
  2263. int element = 0;
  2264. int rev_element;
  2265. for (int c = 0; c <= containers - 1; c++)
  2266. {
  2267. rev_element = element + elements_per_container - 1;
  2268. for (int e = 0; e <= elements_per_container - 1; e++)
  2269. {
  2270. Elem(result, rev_element, esize, Elem(operand, element, esize));
  2271. element = element + 1;
  2272. rev_element = rev_element - 1;
  2273. }
  2274. }
  2275. V(d, result);
  2276. }
  2277. // rev64_advsimd.html
  2278. public static void Rev64_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2279. {
  2280. const bool U = false;
  2281. const bool o0 = false;
  2282. /* Decode Vector */
  2283. int d = (int)UInt(Rd);
  2284. int n = (int)UInt(Rn);
  2285. // size=esize: B(0), H(1), S(1), D(S)
  2286. int esize = 8 << (int)UInt(size);
  2287. int datasize = (Q ? 128 : 64);
  2288. // op=REVx: 64(0), 32(1), 16(2)
  2289. Bits op = Bits.Concat(o0, U);
  2290. // => op+size:
  2291. // 64+B = 0, 64+H = 1, 64+S = 2, 64+D = X
  2292. // 32+B = 1, 32+H = 2, 32+S = X, 32+D = X
  2293. // 16+B = 2, 16+H = X, 16+S = X, 16+D = X
  2294. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2295. // => 3-(op+size) (index bits in group)
  2296. // 64/B = 3, 64+H = 2, 64+S = 1, 64+D = X
  2297. // 32+B = 2, 32+H = 1, 32+S = X, 32+D = X
  2298. // 16+B = 1, 16+H = X, 16+S = X, 16+D = X
  2299. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2300. // index bits within group: 1, 2, 3
  2301. /* if UInt(op) + UInt(size) >= 3 then UnallocatedEncoding(); */
  2302. int container_size;
  2303. switch (op)
  2304. {
  2305. case Bits bits when bits == "10":
  2306. container_size = 16;
  2307. break;
  2308. case Bits bits when bits == "01":
  2309. container_size = 32;
  2310. break;
  2311. default:
  2312. case Bits bits when bits == "00":
  2313. container_size = 64;
  2314. break;
  2315. }
  2316. int containers = datasize / container_size;
  2317. int elements_per_container = container_size / esize;
  2318. /* Operation */
  2319. /* CheckFPAdvSIMDEnabled64(); */
  2320. Bits result = new Bits(datasize);
  2321. Bits operand = V(datasize, n);
  2322. int element = 0;
  2323. int rev_element;
  2324. for (int c = 0; c <= containers - 1; c++)
  2325. {
  2326. rev_element = element + elements_per_container - 1;
  2327. for (int e = 0; e <= elements_per_container - 1; e++)
  2328. {
  2329. Elem(result, rev_element, esize, Elem(operand, element, esize));
  2330. element = element + 1;
  2331. rev_element = rev_element - 1;
  2332. }
  2333. }
  2334. V(d, result);
  2335. }
  2336. // sqxtn_advsimd.html#SQXTN_asisdmisc_N
  2337. public static void Sqxtn_S(Bits size, Bits Rn, Bits Rd)
  2338. {
  2339. const bool U = false;
  2340. /* Decode Scalar */
  2341. int d = (int)UInt(Rd);
  2342. int n = (int)UInt(Rn);
  2343. /* if size == '11' then ReservedValue(); */
  2344. int esize = 8 << (int)UInt(size);
  2345. int datasize = esize;
  2346. int part = 0;
  2347. int elements = 1;
  2348. bool unsigned = (U == true);
  2349. /* Operation */
  2350. /* CheckFPAdvSIMDEnabled64(); */
  2351. Bits result = new Bits(datasize);
  2352. Bits operand = V(2 * datasize, n);
  2353. Bits element;
  2354. bool sat;
  2355. for (int e = 0; e <= elements - 1; e++)
  2356. {
  2357. element = Elem(operand, e, 2 * esize);
  2358. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2359. Elem(result, e, esize, _result);
  2360. sat = _sat;
  2361. if (sat)
  2362. {
  2363. /* FPSR.QC = '1'; */
  2364. FPSR[27] = true; // TODO: Add named fields.
  2365. }
  2366. }
  2367. Vpart(d, part, result);
  2368. }
  2369. // sqxtn_advsimd.html#SQXTN_asimdmisc_N
  2370. public static void Sqxtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2371. {
  2372. const bool U = false;
  2373. /* Decode Vector */
  2374. int d = (int)UInt(Rd);
  2375. int n = (int)UInt(Rn);
  2376. /* if size == '11' then ReservedValue(); */
  2377. int esize = 8 << (int)UInt(size);
  2378. int datasize = 64;
  2379. int part = (int)UInt(Q);
  2380. int elements = datasize / esize;
  2381. bool unsigned = (U == true);
  2382. /* Operation */
  2383. /* CheckFPAdvSIMDEnabled64(); */
  2384. Bits result = new Bits(datasize);
  2385. Bits operand = V(2 * datasize, n);
  2386. Bits element;
  2387. bool sat;
  2388. for (int e = 0; e <= elements - 1; e++)
  2389. {
  2390. element = Elem(operand, e, 2 * esize);
  2391. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2392. Elem(result, e, esize, _result);
  2393. sat = _sat;
  2394. if (sat)
  2395. {
  2396. /* FPSR.QC = '1'; */
  2397. FPSR[27] = true; // TODO: Add named fields.
  2398. }
  2399. }
  2400. Vpart(d, part, result);
  2401. }
  2402. // sqxtun_advsimd.html#SQXTUN_asisdmisc_N
  2403. public static void Sqxtun_S(Bits size, Bits Rn, Bits Rd)
  2404. {
  2405. /* Decode Scalar */
  2406. int d = (int)UInt(Rd);
  2407. int n = (int)UInt(Rn);
  2408. /* if size == '11' then ReservedValue(); */
  2409. int esize = 8 << (int)UInt(size);
  2410. int datasize = esize;
  2411. int part = 0;
  2412. int elements = 1;
  2413. /* Operation */
  2414. /* CheckFPAdvSIMDEnabled64(); */
  2415. Bits result = new Bits(datasize);
  2416. Bits operand = V(2 * datasize, n);
  2417. Bits element;
  2418. bool sat;
  2419. for (int e = 0; e <= elements - 1; e++)
  2420. {
  2421. element = Elem(operand, e, 2 * esize);
  2422. (Bits _result, bool _sat) = UnsignedSatQ(SInt(element), esize);
  2423. Elem(result, e, esize, _result);
  2424. sat = _sat;
  2425. if (sat)
  2426. {
  2427. /* FPSR.QC = '1'; */
  2428. FPSR[27] = true; // TODO: Add named fields.
  2429. }
  2430. }
  2431. Vpart(d, part, result);
  2432. }
  2433. // sqxtun_advsimd.html#SQXTUN_asimdmisc_N
  2434. public static void Sqxtun_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2435. {
  2436. /* Decode Vector */
  2437. int d = (int)UInt(Rd);
  2438. int n = (int)UInt(Rn);
  2439. /* if size == '11' then ReservedValue(); */
  2440. int esize = 8 << (int)UInt(size);
  2441. int datasize = 64;
  2442. int part = (int)UInt(Q);
  2443. int elements = datasize / esize;
  2444. /* Operation */
  2445. /* CheckFPAdvSIMDEnabled64(); */
  2446. Bits result = new Bits(datasize);
  2447. Bits operand = V(2 * datasize, n);
  2448. Bits element;
  2449. bool sat;
  2450. for (int e = 0; e <= elements - 1; e++)
  2451. {
  2452. element = Elem(operand, e, 2 * esize);
  2453. (Bits _result, bool _sat) = UnsignedSatQ(SInt(element), esize);
  2454. Elem(result, e, esize, _result);
  2455. sat = _sat;
  2456. if (sat)
  2457. {
  2458. /* FPSR.QC = '1'; */
  2459. FPSR[27] = true; // TODO: Add named fields.
  2460. }
  2461. }
  2462. Vpart(d, part, result);
  2463. }
  2464. // uqxtn_advsimd.html#UQXTN_asisdmisc_N
  2465. public static void Uqxtn_S(Bits size, Bits Rn, Bits Rd)
  2466. {
  2467. const bool U = true;
  2468. /* Decode Scalar */
  2469. int d = (int)UInt(Rd);
  2470. int n = (int)UInt(Rn);
  2471. /* if size == '11' then ReservedValue(); */
  2472. int esize = 8 << (int)UInt(size);
  2473. int datasize = esize;
  2474. int part = 0;
  2475. int elements = 1;
  2476. bool unsigned = (U == true);
  2477. /* Operation */
  2478. /* CheckFPAdvSIMDEnabled64(); */
  2479. Bits result = new Bits(datasize);
  2480. Bits operand = V(2 * datasize, n);
  2481. Bits element;
  2482. bool sat;
  2483. for (int e = 0; e <= elements - 1; e++)
  2484. {
  2485. element = Elem(operand, e, 2 * esize);
  2486. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2487. Elem(result, e, esize, _result);
  2488. sat = _sat;
  2489. if (sat)
  2490. {
  2491. /* FPSR.QC = '1'; */
  2492. FPSR[27] = true; // TODO: Add named fields.
  2493. }
  2494. }
  2495. Vpart(d, part, result);
  2496. }
  2497. // uqxtn_advsimd.html#UQXTN_asimdmisc_N
  2498. public static void Uqxtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2499. {
  2500. const bool U = true;
  2501. /* Decode Vector */
  2502. int d = (int)UInt(Rd);
  2503. int n = (int)UInt(Rn);
  2504. /* if size == '11' then ReservedValue(); */
  2505. int esize = 8 << (int)UInt(size);
  2506. int datasize = 64;
  2507. int part = (int)UInt(Q);
  2508. int elements = datasize / esize;
  2509. bool unsigned = (U == true);
  2510. /* Operation */
  2511. /* CheckFPAdvSIMDEnabled64(); */
  2512. Bits result = new Bits(datasize);
  2513. Bits operand = V(2 * datasize, n);
  2514. Bits element;
  2515. bool sat;
  2516. for (int e = 0; e <= elements - 1; e++)
  2517. {
  2518. element = Elem(operand, e, 2 * esize);
  2519. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2520. Elem(result, e, esize, _result);
  2521. sat = _sat;
  2522. if (sat)
  2523. {
  2524. /* FPSR.QC = '1'; */
  2525. FPSR[27] = true; // TODO: Add named fields.
  2526. }
  2527. }
  2528. Vpart(d, part, result);
  2529. }
  2530. // xtn_advsimd.html
  2531. public static void Xtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2532. {
  2533. /* Decode Vector */
  2534. int d = (int)UInt(Rd);
  2535. int n = (int)UInt(Rn);
  2536. /* if size == '11' then ReservedValue(); */
  2537. int esize = 8 << (int)UInt(size);
  2538. int datasize = 64;
  2539. int part = (int)UInt(Q);
  2540. int elements = datasize / esize;
  2541. /* Operation */
  2542. /* CheckFPAdvSIMDEnabled64(); */
  2543. Bits result = new Bits(datasize);
  2544. Bits operand = V(2 * datasize, n);
  2545. Bits element;
  2546. for (int e = 0; e <= elements - 1; e++)
  2547. {
  2548. element = Elem(operand, e, 2 * esize);
  2549. Elem(result, e, esize, element[esize - 1, 0]);
  2550. }
  2551. Vpart(d, part, result);
  2552. }
  2553. #endregion
  2554. #region "SimdReg"
  2555. // add_advsimd.html#ADD_asisdsame_only
  2556. public static void Add_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2557. {
  2558. const bool U = false;
  2559. /* Decode Scalar */
  2560. int d = (int)UInt(Rd);
  2561. int n = (int)UInt(Rn);
  2562. int m = (int)UInt(Rm);
  2563. /* if size != '11' then ReservedValue(); */
  2564. int esize = 8 << (int)UInt(size);
  2565. int datasize = esize;
  2566. int elements = 1;
  2567. bool sub_op = (U == true);
  2568. /* Operation */
  2569. /* CheckFPAdvSIMDEnabled64(); */
  2570. Bits result = new Bits(datasize);
  2571. Bits operand1 = V(datasize, n);
  2572. Bits operand2 = V(datasize, m);
  2573. Bits element1;
  2574. Bits element2;
  2575. for (int e = 0; e <= elements - 1; e++)
  2576. {
  2577. element1 = Elem(operand1, e, esize);
  2578. element2 = Elem(operand2, e, esize);
  2579. if (sub_op)
  2580. {
  2581. Elem(result, e, esize, element1 - element2);
  2582. }
  2583. else
  2584. {
  2585. Elem(result, e, esize, element1 + element2);
  2586. }
  2587. }
  2588. V(d, result);
  2589. }
  2590. // add_advsimd.html#ADD_asimdsame_only
  2591. public static void Add_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2592. {
  2593. const bool U = false;
  2594. /* Decode Vector */
  2595. int d = (int)UInt(Rd);
  2596. int n = (int)UInt(Rn);
  2597. int m = (int)UInt(Rm);
  2598. /* if size:Q == '110' then ReservedValue(); */
  2599. int esize = 8 << (int)UInt(size);
  2600. int datasize = (Q ? 128 : 64);
  2601. int elements = datasize / esize;
  2602. bool sub_op = (U == true);
  2603. /* Operation */
  2604. /* CheckFPAdvSIMDEnabled64(); */
  2605. Bits result = new Bits(datasize);
  2606. Bits operand1 = V(datasize, n);
  2607. Bits operand2 = V(datasize, m);
  2608. Bits element1;
  2609. Bits element2;
  2610. for (int e = 0; e <= elements - 1; e++)
  2611. {
  2612. element1 = Elem(operand1, e, esize);
  2613. element2 = Elem(operand2, e, esize);
  2614. if (sub_op)
  2615. {
  2616. Elem(result, e, esize, element1 - element2);
  2617. }
  2618. else
  2619. {
  2620. Elem(result, e, esize, element1 + element2);
  2621. }
  2622. }
  2623. V(d, result);
  2624. }
  2625. // addhn_advsimd.html
  2626. public static void Addhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2627. {
  2628. const bool U = false;
  2629. const bool o1 = false;
  2630. /* Decode */
  2631. int d = (int)UInt(Rd);
  2632. int n = (int)UInt(Rn);
  2633. int m = (int)UInt(Rm);
  2634. /* if size == '11' then ReservedValue(); */
  2635. int esize = 8 << (int)UInt(size);
  2636. int datasize = 64;
  2637. int part = (int)UInt(Q);
  2638. int elements = datasize / esize;
  2639. bool sub_op = (o1 == true);
  2640. bool round = (U == true);
  2641. /* Operation */
  2642. /* CheckFPAdvSIMDEnabled64(); */
  2643. Bits result = new Bits(datasize);
  2644. Bits operand1 = V(2 * datasize, n);
  2645. Bits operand2 = V(2 * datasize, m);
  2646. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  2647. Bits sum;
  2648. Bits element1;
  2649. Bits element2;
  2650. for (int e = 0; e <= elements - 1; e++)
  2651. {
  2652. element1 = Elem(operand1, e, 2 * esize);
  2653. element2 = Elem(operand2, e, 2 * esize);
  2654. if (sub_op)
  2655. {
  2656. sum = element1 - element2;
  2657. }
  2658. else
  2659. {
  2660. sum = element1 + element2;
  2661. }
  2662. sum = sum + round_const;
  2663. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  2664. }
  2665. Vpart(d, part, result);
  2666. }
  2667. // addp_advsimd_vec.html
  2668. public static void Addp_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2669. {
  2670. /* Decode */
  2671. int d = (int)UInt(Rd);
  2672. int n = (int)UInt(Rn);
  2673. int m = (int)UInt(Rm);
  2674. /* if size:Q == '110' then ReservedValue(); */
  2675. int esize = 8 << (int)UInt(size);
  2676. int datasize = (Q ? 128 : 64);
  2677. int elements = datasize / esize;
  2678. /* Operation */
  2679. /* CheckFPAdvSIMDEnabled64(); */
  2680. Bits result = new Bits(datasize);
  2681. Bits operand1 = V(datasize, n);
  2682. Bits operand2 = V(datasize, m);
  2683. Bits concat = Bits.Concat(operand2, operand1);
  2684. Bits element1;
  2685. Bits element2;
  2686. for (int e = 0; e <= elements - 1; e++)
  2687. {
  2688. element1 = Elem(concat, 2 * e, esize);
  2689. element2 = Elem(concat, (2 * e) + 1, esize);
  2690. Elem(result, e, esize, element1 + element2);
  2691. }
  2692. V(d, result);
  2693. }
  2694. // and_advsimd.html
  2695. public static void And_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2696. {
  2697. /* Decode */
  2698. int d = (int)UInt(Rd);
  2699. int n = (int)UInt(Rn);
  2700. int m = (int)UInt(Rm);
  2701. int datasize = (Q ? 128 : 64);
  2702. /* Operation */
  2703. /* CheckFPAdvSIMDEnabled64(); */
  2704. Bits operand1 = V(datasize, n);
  2705. Bits operand2 = V(datasize, m);
  2706. Bits result = AND(operand1, operand2);
  2707. V(d, result);
  2708. }
  2709. // bic_advsimd_reg.html
  2710. public static void Bic_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2711. {
  2712. /* Decode */
  2713. int d = (int)UInt(Rd);
  2714. int n = (int)UInt(Rn);
  2715. int m = (int)UInt(Rm);
  2716. int datasize = (Q ? 128 : 64);
  2717. /* Operation */
  2718. /* CheckFPAdvSIMDEnabled64(); */
  2719. Bits operand1 = V(datasize, n);
  2720. Bits operand2 = V(datasize, m);
  2721. operand2 = NOT(operand2);
  2722. Bits result = AND(operand1, operand2);
  2723. V(d, result);
  2724. }
  2725. // bif_advsimd.html
  2726. public static void Bif_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2727. {
  2728. /* Decode */
  2729. int d = (int)UInt(Rd);
  2730. int n = (int)UInt(Rn);
  2731. int m = (int)UInt(Rm);
  2732. int datasize = (Q ? 128 : 64);
  2733. /* Operation */
  2734. /* CheckFPAdvSIMDEnabled64(); */
  2735. Bits operand1;
  2736. Bits operand3;
  2737. Bits operand4 = V(datasize, n);
  2738. operand1 = V(datasize, d);
  2739. operand3 = NOT(V(datasize, m));
  2740. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2741. }
  2742. // bit_advsimd.html
  2743. public static void Bit_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2744. {
  2745. /* Decode */
  2746. int d = (int)UInt(Rd);
  2747. int n = (int)UInt(Rn);
  2748. int m = (int)UInt(Rm);
  2749. int datasize = (Q ? 128 : 64);
  2750. /* Operation */
  2751. /* CheckFPAdvSIMDEnabled64(); */
  2752. Bits operand1;
  2753. Bits operand3;
  2754. Bits operand4 = V(datasize, n);
  2755. operand1 = V(datasize, d);
  2756. operand3 = V(datasize, m);
  2757. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2758. }
  2759. // bsl_advsimd.html
  2760. public static void Bsl_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2761. {
  2762. /* Decode */
  2763. int d = (int)UInt(Rd);
  2764. int n = (int)UInt(Rn);
  2765. int m = (int)UInt(Rm);
  2766. int datasize = (Q ? 128 : 64);
  2767. /* Operation */
  2768. /* CheckFPAdvSIMDEnabled64(); */
  2769. Bits operand1;
  2770. Bits operand3;
  2771. Bits operand4 = V(datasize, n);
  2772. operand1 = V(datasize, m);
  2773. operand3 = V(datasize, d);
  2774. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2775. }
  2776. // cmeq_advsimd_reg.html#CMEQ_asisdsame_only
  2777. public static void Cmeq_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2778. {
  2779. const bool U = true;
  2780. /* Decode Scalar */
  2781. int d = (int)UInt(Rd);
  2782. int n = (int)UInt(Rn);
  2783. int m = (int)UInt(Rm);
  2784. /* if size != '11' then ReservedValue(); */
  2785. int esize = 8 << (int)UInt(size);
  2786. int datasize = esize;
  2787. int elements = 1;
  2788. bool and_test = (U == false);
  2789. /* Operation */
  2790. /* CheckFPAdvSIMDEnabled64(); */
  2791. Bits result = new Bits(datasize);
  2792. Bits operand1 = V(datasize, n);
  2793. Bits operand2 = V(datasize, m);
  2794. Bits element1;
  2795. Bits element2;
  2796. bool test_passed;
  2797. for (int e = 0; e <= elements - 1; e++)
  2798. {
  2799. element1 = Elem(operand1, e, esize);
  2800. element2 = Elem(operand2, e, esize);
  2801. if (and_test)
  2802. {
  2803. test_passed = !IsZero(AND(element1, element2));
  2804. }
  2805. else
  2806. {
  2807. test_passed = (element1 == element2);
  2808. }
  2809. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2810. }
  2811. V(d, result);
  2812. }
  2813. // cmeq_advsimd_reg.html#CMEQ_asimdsame_only
  2814. public static void Cmeq_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2815. {
  2816. const bool U = true;
  2817. /* Decode Vector */
  2818. int d = (int)UInt(Rd);
  2819. int n = (int)UInt(Rn);
  2820. int m = (int)UInt(Rm);
  2821. /* if size:Q == '110' then ReservedValue(); */
  2822. int esize = 8 << (int)UInt(size);
  2823. int datasize = (Q ? 128 : 64);
  2824. int elements = datasize / esize;
  2825. bool and_test = (U == false);
  2826. /* Operation */
  2827. /* CheckFPAdvSIMDEnabled64(); */
  2828. Bits result = new Bits(datasize);
  2829. Bits operand1 = V(datasize, n);
  2830. Bits operand2 = V(datasize, m);
  2831. Bits element1;
  2832. Bits element2;
  2833. bool test_passed;
  2834. for (int e = 0; e <= elements - 1; e++)
  2835. {
  2836. element1 = Elem(operand1, e, esize);
  2837. element2 = Elem(operand2, e, esize);
  2838. if (and_test)
  2839. {
  2840. test_passed = !IsZero(AND(element1, element2));
  2841. }
  2842. else
  2843. {
  2844. test_passed = (element1 == element2);
  2845. }
  2846. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2847. }
  2848. V(d, result);
  2849. }
  2850. // cmge_advsimd_reg.html#CMGE_asisdsame_only
  2851. public static void Cmge_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2852. {
  2853. const bool U = false;
  2854. const bool eq = true;
  2855. /* Decode Scalar */
  2856. int d = (int)UInt(Rd);
  2857. int n = (int)UInt(Rn);
  2858. int m = (int)UInt(Rm);
  2859. /* if size != '11' then ReservedValue(); */
  2860. int esize = 8 << (int)UInt(size);
  2861. int datasize = esize;
  2862. int elements = 1;
  2863. bool unsigned = (U == true);
  2864. bool cmp_eq = (eq == true);
  2865. /* Operation */
  2866. /* CheckFPAdvSIMDEnabled64(); */
  2867. Bits result = new Bits(datasize);
  2868. Bits operand1 = V(datasize, n);
  2869. Bits operand2 = V(datasize, m);
  2870. BigInteger element1;
  2871. BigInteger element2;
  2872. bool test_passed;
  2873. for (int e = 0; e <= elements - 1; e++)
  2874. {
  2875. element1 = Int(Elem(operand1, e, esize), unsigned);
  2876. element2 = Int(Elem(operand2, e, esize), unsigned);
  2877. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2878. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2879. }
  2880. V(d, result);
  2881. }
  2882. // cmge_advsimd_reg.html#CMGE_asimdsame_only
  2883. public static void Cmge_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2884. {
  2885. const bool U = false;
  2886. const bool eq = true;
  2887. /* Decode Vector */
  2888. int d = (int)UInt(Rd);
  2889. int n = (int)UInt(Rn);
  2890. int m = (int)UInt(Rm);
  2891. /* if size:Q == '110' then ReservedValue(); */
  2892. int esize = 8 << (int)UInt(size);
  2893. int datasize = (Q ? 128 : 64);
  2894. int elements = datasize / esize;
  2895. bool unsigned = (U == true);
  2896. bool cmp_eq = (eq == true);
  2897. /* Operation */
  2898. /* CheckFPAdvSIMDEnabled64(); */
  2899. Bits result = new Bits(datasize);
  2900. Bits operand1 = V(datasize, n);
  2901. Bits operand2 = V(datasize, m);
  2902. BigInteger element1;
  2903. BigInteger element2;
  2904. bool test_passed;
  2905. for (int e = 0; e <= elements - 1; e++)
  2906. {
  2907. element1 = Int(Elem(operand1, e, esize), unsigned);
  2908. element2 = Int(Elem(operand2, e, esize), unsigned);
  2909. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2910. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2911. }
  2912. V(d, result);
  2913. }
  2914. // cmgt_advsimd_reg.html#CMGT_asisdsame_only
  2915. public static void Cmgt_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2916. {
  2917. const bool U = false;
  2918. const bool eq = false;
  2919. /* Decode Scalar */
  2920. int d = (int)UInt(Rd);
  2921. int n = (int)UInt(Rn);
  2922. int m = (int)UInt(Rm);
  2923. /* if size != '11' then ReservedValue(); */
  2924. int esize = 8 << (int)UInt(size);
  2925. int datasize = esize;
  2926. int elements = 1;
  2927. bool unsigned = (U == true);
  2928. bool cmp_eq = (eq == true);
  2929. /* Operation */
  2930. /* CheckFPAdvSIMDEnabled64(); */
  2931. Bits result = new Bits(datasize);
  2932. Bits operand1 = V(datasize, n);
  2933. Bits operand2 = V(datasize, m);
  2934. BigInteger element1;
  2935. BigInteger element2;
  2936. bool test_passed;
  2937. for (int e = 0; e <= elements - 1; e++)
  2938. {
  2939. element1 = Int(Elem(operand1, e, esize), unsigned);
  2940. element2 = Int(Elem(operand2, e, esize), unsigned);
  2941. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2942. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2943. }
  2944. V(d, result);
  2945. }
  2946. // cmgt_advsimd_reg.html#CMGT_asimdsame_only
  2947. public static void Cmgt_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2948. {
  2949. const bool U = false;
  2950. const bool eq = false;
  2951. /* Decode Vector */
  2952. int d = (int)UInt(Rd);
  2953. int n = (int)UInt(Rn);
  2954. int m = (int)UInt(Rm);
  2955. /* if size:Q == '110' then ReservedValue(); */
  2956. int esize = 8 << (int)UInt(size);
  2957. int datasize = (Q ? 128 : 64);
  2958. int elements = datasize / esize;
  2959. bool unsigned = (U == true);
  2960. bool cmp_eq = (eq == true);
  2961. /* Operation */
  2962. /* CheckFPAdvSIMDEnabled64(); */
  2963. Bits result = new Bits(datasize);
  2964. Bits operand1 = V(datasize, n);
  2965. Bits operand2 = V(datasize, m);
  2966. BigInteger element1;
  2967. BigInteger element2;
  2968. bool test_passed;
  2969. for (int e = 0; e <= elements - 1; e++)
  2970. {
  2971. element1 = Int(Elem(operand1, e, esize), unsigned);
  2972. element2 = Int(Elem(operand2, e, esize), unsigned);
  2973. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2974. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2975. }
  2976. V(d, result);
  2977. }
  2978. // cmhi_advsimd.html#CMHI_asisdsame_only
  2979. public static void Cmhi_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2980. {
  2981. const bool U = true;
  2982. const bool eq = false;
  2983. /* Decode Scalar */
  2984. int d = (int)UInt(Rd);
  2985. int n = (int)UInt(Rn);
  2986. int m = (int)UInt(Rm);
  2987. /* if size != '11' then ReservedValue(); */
  2988. int esize = 8 << (int)UInt(size);
  2989. int datasize = esize;
  2990. int elements = 1;
  2991. bool unsigned = (U == true);
  2992. bool cmp_eq = (eq == true);
  2993. /* Operation */
  2994. /* CheckFPAdvSIMDEnabled64(); */
  2995. Bits result = new Bits(datasize);
  2996. Bits operand1 = V(datasize, n);
  2997. Bits operand2 = V(datasize, m);
  2998. BigInteger element1;
  2999. BigInteger element2;
  3000. bool test_passed;
  3001. for (int e = 0; e <= elements - 1; e++)
  3002. {
  3003. element1 = Int(Elem(operand1, e, esize), unsigned);
  3004. element2 = Int(Elem(operand2, e, esize), unsigned);
  3005. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3006. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3007. }
  3008. V(d, result);
  3009. }
  3010. // cmhi_advsimd.html#CMHI_asimdsame_only
  3011. public static void Cmhi_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3012. {
  3013. const bool U = true;
  3014. const bool eq = false;
  3015. /* Decode Vector */
  3016. int d = (int)UInt(Rd);
  3017. int n = (int)UInt(Rn);
  3018. int m = (int)UInt(Rm);
  3019. /* if size:Q == '110' then ReservedValue(); */
  3020. int esize = 8 << (int)UInt(size);
  3021. int datasize = (Q ? 128 : 64);
  3022. int elements = datasize / esize;
  3023. bool unsigned = (U == true);
  3024. bool cmp_eq = (eq == true);
  3025. /* Operation */
  3026. /* CheckFPAdvSIMDEnabled64(); */
  3027. Bits result = new Bits(datasize);
  3028. Bits operand1 = V(datasize, n);
  3029. Bits operand2 = V(datasize, m);
  3030. BigInteger element1;
  3031. BigInteger element2;
  3032. bool test_passed;
  3033. for (int e = 0; e <= elements - 1; e++)
  3034. {
  3035. element1 = Int(Elem(operand1, e, esize), unsigned);
  3036. element2 = Int(Elem(operand2, e, esize), unsigned);
  3037. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3038. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3039. }
  3040. V(d, result);
  3041. }
  3042. // cmhs_advsimd.html#CMHS_asisdsame_only
  3043. public static void Cmhs_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3044. {
  3045. const bool U = true;
  3046. const bool eq = true;
  3047. /* Decode Scalar */
  3048. int d = (int)UInt(Rd);
  3049. int n = (int)UInt(Rn);
  3050. int m = (int)UInt(Rm);
  3051. /* if size != '11' then ReservedValue(); */
  3052. int esize = 8 << (int)UInt(size);
  3053. int datasize = esize;
  3054. int elements = 1;
  3055. bool unsigned = (U == true);
  3056. bool cmp_eq = (eq == true);
  3057. /* Operation */
  3058. /* CheckFPAdvSIMDEnabled64(); */
  3059. Bits result = new Bits(datasize);
  3060. Bits operand1 = V(datasize, n);
  3061. Bits operand2 = V(datasize, m);
  3062. BigInteger element1;
  3063. BigInteger element2;
  3064. bool test_passed;
  3065. for (int e = 0; e <= elements - 1; e++)
  3066. {
  3067. element1 = Int(Elem(operand1, e, esize), unsigned);
  3068. element2 = Int(Elem(operand2, e, esize), unsigned);
  3069. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3070. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3071. }
  3072. V(d, result);
  3073. }
  3074. // cmhs_advsimd.html#CMHS_asimdsame_only
  3075. public static void Cmhs_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3076. {
  3077. const bool U = true;
  3078. const bool eq = true;
  3079. /* Decode Vector */
  3080. int d = (int)UInt(Rd);
  3081. int n = (int)UInt(Rn);
  3082. int m = (int)UInt(Rm);
  3083. /* if size:Q == '110' then ReservedValue(); */
  3084. int esize = 8 << (int)UInt(size);
  3085. int datasize = (Q ? 128 : 64);
  3086. int elements = datasize / esize;
  3087. bool unsigned = (U == true);
  3088. bool cmp_eq = (eq == true);
  3089. /* Operation */
  3090. /* CheckFPAdvSIMDEnabled64(); */
  3091. Bits result = new Bits(datasize);
  3092. Bits operand1 = V(datasize, n);
  3093. Bits operand2 = V(datasize, m);
  3094. BigInteger element1;
  3095. BigInteger element2;
  3096. bool test_passed;
  3097. for (int e = 0; e <= elements - 1; e++)
  3098. {
  3099. element1 = Int(Elem(operand1, e, esize), unsigned);
  3100. element2 = Int(Elem(operand2, e, esize), unsigned);
  3101. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3102. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3103. }
  3104. V(d, result);
  3105. }
  3106. // cmtst_advsimd.html#CMTST_asisdsame_only
  3107. public static void Cmtst_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3108. {
  3109. const bool U = false;
  3110. /* Decode Scalar */
  3111. int d = (int)UInt(Rd);
  3112. int n = (int)UInt(Rn);
  3113. int m = (int)UInt(Rm);
  3114. /* if size != '11' then ReservedValue(); */
  3115. int esize = 8 << (int)UInt(size);
  3116. int datasize = esize;
  3117. int elements = 1;
  3118. bool and_test = (U == false);
  3119. /* Operation */
  3120. /* CheckFPAdvSIMDEnabled64(); */
  3121. Bits result = new Bits(datasize);
  3122. Bits operand1 = V(datasize, n);
  3123. Bits operand2 = V(datasize, m);
  3124. Bits element1;
  3125. Bits element2;
  3126. bool test_passed;
  3127. for (int e = 0; e <= elements - 1; e++)
  3128. {
  3129. element1 = Elem(operand1, e, esize);
  3130. element2 = Elem(operand2, e, esize);
  3131. if (and_test)
  3132. {
  3133. test_passed = !IsZero(AND(element1, element2));
  3134. }
  3135. else
  3136. {
  3137. test_passed = (element1 == element2);
  3138. }
  3139. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3140. }
  3141. V(d, result);
  3142. }
  3143. // cmtst_advsimd.html#CMTST_asimdsame_only
  3144. public static void Cmtst_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3145. {
  3146. const bool U = false;
  3147. /* Decode Vector */
  3148. int d = (int)UInt(Rd);
  3149. int n = (int)UInt(Rn);
  3150. int m = (int)UInt(Rm);
  3151. /* if size:Q == '110' then ReservedValue(); */
  3152. int esize = 8 << (int)UInt(size);
  3153. int datasize = (Q ? 128 : 64);
  3154. int elements = datasize / esize;
  3155. bool and_test = (U == false);
  3156. /* Operation */
  3157. /* CheckFPAdvSIMDEnabled64(); */
  3158. Bits result = new Bits(datasize);
  3159. Bits operand1 = V(datasize, n);
  3160. Bits operand2 = V(datasize, m);
  3161. Bits element1;
  3162. Bits element2;
  3163. bool test_passed;
  3164. for (int e = 0; e <= elements - 1; e++)
  3165. {
  3166. element1 = Elem(operand1, e, esize);
  3167. element2 = Elem(operand2, e, esize);
  3168. if (and_test)
  3169. {
  3170. test_passed = !IsZero(AND(element1, element2));
  3171. }
  3172. else
  3173. {
  3174. test_passed = (element1 == element2);
  3175. }
  3176. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3177. }
  3178. V(d, result);
  3179. }
  3180. // eor_advsimd.html
  3181. public static void Eor_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3182. {
  3183. /* Decode */
  3184. int d = (int)UInt(Rd);
  3185. int n = (int)UInt(Rn);
  3186. int m = (int)UInt(Rm);
  3187. int datasize = (Q ? 128 : 64);
  3188. /* Operation */
  3189. /* CheckFPAdvSIMDEnabled64(); */
  3190. Bits operand1 = V(datasize, m);
  3191. Bits operand2 = Zeros(datasize);
  3192. Bits operand3 = Ones(datasize);
  3193. Bits operand4 = V(datasize, n);
  3194. Bits result = EOR(operand1, AND(EOR(operand2, operand4), operand3));
  3195. V(d, result);
  3196. }
  3197. // orn_advsimd.html
  3198. public static void Orn_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3199. {
  3200. /* Decode */
  3201. int d = (int)UInt(Rd);
  3202. int n = (int)UInt(Rn);
  3203. int m = (int)UInt(Rm);
  3204. int datasize = (Q ? 128 : 64);
  3205. /* Operation */
  3206. /* CheckFPAdvSIMDEnabled64(); */
  3207. Bits operand1 = V(datasize, n);
  3208. Bits operand2 = V(datasize, m);
  3209. operand2 = NOT(operand2);
  3210. Bits result = OR(operand1, operand2);
  3211. V(d, result);
  3212. }
  3213. // orr_advsimd_reg.html
  3214. public static void Orr_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3215. {
  3216. /* Decode */
  3217. int d = (int)UInt(Rd);
  3218. int n = (int)UInt(Rn);
  3219. int m = (int)UInt(Rm);
  3220. int datasize = (Q ? 128 : 64);
  3221. /* Operation */
  3222. /* CheckFPAdvSIMDEnabled64(); */
  3223. Bits operand1 = V(datasize, n);
  3224. Bits operand2 = V(datasize, m);
  3225. Bits result = OR(operand1, operand2);
  3226. V(d, result);
  3227. }
  3228. // raddhn_advsimd.html
  3229. public static void Raddhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3230. {
  3231. const bool U = true;
  3232. const bool o1 = false;
  3233. /* Decode */
  3234. int d = (int)UInt(Rd);
  3235. int n = (int)UInt(Rn);
  3236. int m = (int)UInt(Rm);
  3237. /* if size == '11' then ReservedValue(); */
  3238. int esize = 8 << (int)UInt(size);
  3239. int datasize = 64;
  3240. int part = (int)UInt(Q);
  3241. int elements = datasize / esize;
  3242. bool sub_op = (o1 == true);
  3243. bool round = (U == true);
  3244. /* Operation */
  3245. /* CheckFPAdvSIMDEnabled64(); */
  3246. Bits result = new Bits(datasize);
  3247. Bits operand1 = V(2 * datasize, n);
  3248. Bits operand2 = V(2 * datasize, m);
  3249. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3250. Bits sum;
  3251. Bits element1;
  3252. Bits element2;
  3253. for (int e = 0; e <= elements - 1; e++)
  3254. {
  3255. element1 = Elem(operand1, e, 2 * esize);
  3256. element2 = Elem(operand2, e, 2 * esize);
  3257. if (sub_op)
  3258. {
  3259. sum = element1 - element2;
  3260. }
  3261. else
  3262. {
  3263. sum = element1 + element2;
  3264. }
  3265. sum = sum + round_const;
  3266. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3267. }
  3268. Vpart(d, part, result);
  3269. }
  3270. // rsubhn_advsimd.html
  3271. public static void Rsubhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3272. {
  3273. const bool U = true;
  3274. const bool o1 = true;
  3275. /* Decode */
  3276. int d = (int)UInt(Rd);
  3277. int n = (int)UInt(Rn);
  3278. int m = (int)UInt(Rm);
  3279. /* if size == '11' then ReservedValue(); */
  3280. int esize = 8 << (int)UInt(size);
  3281. int datasize = 64;
  3282. int part = (int)UInt(Q);
  3283. int elements = datasize / esize;
  3284. bool sub_op = (o1 == true);
  3285. bool round = (U == true);
  3286. /* Operation */
  3287. /* CheckFPAdvSIMDEnabled64(); */
  3288. Bits result = new Bits(datasize);
  3289. Bits operand1 = V(2 * datasize, n);
  3290. Bits operand2 = V(2 * datasize, m);
  3291. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3292. Bits sum;
  3293. Bits element1;
  3294. Bits element2;
  3295. for (int e = 0; e <= elements - 1; e++)
  3296. {
  3297. element1 = Elem(operand1, e, 2 * esize);
  3298. element2 = Elem(operand2, e, 2 * esize);
  3299. if (sub_op)
  3300. {
  3301. sum = element1 - element2;
  3302. }
  3303. else
  3304. {
  3305. sum = element1 + element2;
  3306. }
  3307. sum = sum + round_const;
  3308. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3309. }
  3310. Vpart(d, part, result);
  3311. }
  3312. // saba_advsimd.html
  3313. public static void Saba_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3314. {
  3315. const bool U = false;
  3316. const bool ac = true;
  3317. /* Decode */
  3318. int d = (int)UInt(Rd);
  3319. int n = (int)UInt(Rn);
  3320. int m = (int)UInt(Rm);
  3321. /* if size == '11' then ReservedValue(); */
  3322. int esize = 8 << (int)UInt(size);
  3323. int datasize = (Q ? 128 : 64);
  3324. int elements = datasize / esize;
  3325. bool unsigned = (U == true);
  3326. bool accumulate = (ac == true);
  3327. /* Operation */
  3328. /* CheckFPAdvSIMDEnabled64(); */
  3329. Bits operand1 = V(datasize, n);
  3330. Bits operand2 = V(datasize, m);
  3331. BigInteger element1;
  3332. BigInteger element2;
  3333. Bits absdiff;
  3334. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3335. for (int e = 0; e <= elements - 1; e++)
  3336. {
  3337. element1 = Int(Elem(operand1, e, esize), unsigned);
  3338. element2 = Int(Elem(operand2, e, esize), unsigned);
  3339. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3340. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3341. }
  3342. V(d, result);
  3343. }
  3344. // sabal_advsimd.html
  3345. public static void Sabal_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3346. {
  3347. const bool U = false;
  3348. const bool op = false;
  3349. /* Decode */
  3350. int d = (int)UInt(Rd);
  3351. int n = (int)UInt(Rn);
  3352. int m = (int)UInt(Rm);
  3353. /* if size == '11' then ReservedValue(); */
  3354. int esize = 8 << (int)UInt(size);
  3355. int datasize = 64;
  3356. int part = (int)UInt(Q);
  3357. int elements = datasize / esize;
  3358. bool accumulate = (op == false);
  3359. bool unsigned = (U == true);
  3360. /* Operation */
  3361. /* CheckFPAdvSIMDEnabled64(); */
  3362. Bits operand1 = Vpart(datasize, n, part);
  3363. Bits operand2 = Vpart(datasize, m, part);
  3364. BigInteger element1;
  3365. BigInteger element2;
  3366. Bits absdiff;
  3367. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3368. for (int e = 0; e <= elements - 1; e++)
  3369. {
  3370. element1 = Int(Elem(operand1, e, esize), unsigned);
  3371. element2 = Int(Elem(operand2, e, esize), unsigned);
  3372. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3373. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3374. }
  3375. V(d, result);
  3376. }
  3377. // sabd_advsimd.html
  3378. public static void Sabd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3379. {
  3380. const bool U = false;
  3381. const bool ac = false;
  3382. /* Decode */
  3383. int d = (int)UInt(Rd);
  3384. int n = (int)UInt(Rn);
  3385. int m = (int)UInt(Rm);
  3386. /* if size == '11' then ReservedValue(); */
  3387. int esize = 8 << (int)UInt(size);
  3388. int datasize = (Q ? 128 : 64);
  3389. int elements = datasize / esize;
  3390. bool unsigned = (U == true);
  3391. bool accumulate = (ac == true);
  3392. /* Operation */
  3393. /* CheckFPAdvSIMDEnabled64(); */
  3394. Bits operand1 = V(datasize, n);
  3395. Bits operand2 = V(datasize, m);
  3396. BigInteger element1;
  3397. BigInteger element2;
  3398. Bits absdiff;
  3399. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3400. for (int e = 0; e <= elements - 1; e++)
  3401. {
  3402. element1 = Int(Elem(operand1, e, esize), unsigned);
  3403. element2 = Int(Elem(operand2, e, esize), unsigned);
  3404. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3405. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3406. }
  3407. V(d, result);
  3408. }
  3409. // sabdl_advsimd.html
  3410. public static void Sabdl_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3411. {
  3412. const bool U = false;
  3413. const bool op = true;
  3414. /* Decode */
  3415. int d = (int)UInt(Rd);
  3416. int n = (int)UInt(Rn);
  3417. int m = (int)UInt(Rm);
  3418. /* if size == '11' then ReservedValue(); */
  3419. int esize = 8 << (int)UInt(size);
  3420. int datasize = 64;
  3421. int part = (int)UInt(Q);
  3422. int elements = datasize / esize;
  3423. bool accumulate = (op == false);
  3424. bool unsigned = (U == true);
  3425. /* Operation */
  3426. /* CheckFPAdvSIMDEnabled64(); */
  3427. Bits operand1 = Vpart(datasize, n, part);
  3428. Bits operand2 = Vpart(datasize, m, part);
  3429. BigInteger element1;
  3430. BigInteger element2;
  3431. Bits absdiff;
  3432. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3433. for (int e = 0; e <= elements - 1; e++)
  3434. {
  3435. element1 = Int(Elem(operand1, e, esize), unsigned);
  3436. element2 = Int(Elem(operand2, e, esize), unsigned);
  3437. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3438. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3439. }
  3440. V(d, result);
  3441. }
  3442. // saddw_advsimd.html
  3443. public static void Saddw_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3444. {
  3445. const bool U = false;
  3446. const bool o1 = false;
  3447. /* Decode */
  3448. int d = (int)UInt(Rd);
  3449. int n = (int)UInt(Rn);
  3450. int m = (int)UInt(Rm);
  3451. /* if size == '11' then ReservedValue(); */
  3452. int esize = 8 << (int)UInt(size);
  3453. int datasize = 64;
  3454. int part = (int)UInt(Q);
  3455. int elements = datasize / esize;
  3456. bool sub_op = (o1 == true);
  3457. bool unsigned = (U == true);
  3458. /* Operation */
  3459. /* CheckFPAdvSIMDEnabled64(); */
  3460. Bits result = new Bits(2 * datasize);
  3461. Bits operand1 = V(2 * datasize, n);
  3462. Bits operand2 = Vpart(datasize, m, part);
  3463. BigInteger element1;
  3464. BigInteger element2;
  3465. BigInteger sum;
  3466. for (int e = 0; e <= elements - 1; e++)
  3467. {
  3468. element1 = Int(Elem(operand1, e, 2 * esize), unsigned);
  3469. element2 = Int(Elem(operand2, e, esize), unsigned);
  3470. if (sub_op)
  3471. {
  3472. sum = element1 - element2;
  3473. }
  3474. else
  3475. {
  3476. sum = element1 + element2;
  3477. }
  3478. Elem(result, e, 2 * esize, sum.SubBigInteger(2 * esize - 1, 0));
  3479. }
  3480. V(d, result);
  3481. }
  3482. // ssubw_advsimd.html
  3483. public static void Ssubw_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3484. {
  3485. const bool U = false;
  3486. const bool o1 = true;
  3487. /* Decode */
  3488. int d = (int)UInt(Rd);
  3489. int n = (int)UInt(Rn);
  3490. int m = (int)UInt(Rm);
  3491. /* if size == '11' then ReservedValue(); */
  3492. int esize = 8 << (int)UInt(size);
  3493. int datasize = 64;
  3494. int part = (int)UInt(Q);
  3495. int elements = datasize / esize;
  3496. bool sub_op = (o1 == true);
  3497. bool unsigned = (U == true);
  3498. /* Operation */
  3499. /* CheckFPAdvSIMDEnabled64(); */
  3500. Bits result = new Bits(2 * datasize);
  3501. Bits operand1 = V(2 * datasize, n);
  3502. Bits operand2 = Vpart(datasize, m, part);
  3503. BigInteger element1;
  3504. BigInteger element2;
  3505. BigInteger sum;
  3506. for (int e = 0; e <= elements - 1; e++)
  3507. {
  3508. element1 = Int(Elem(operand1, e, 2 * esize), unsigned);
  3509. element2 = Int(Elem(operand2, e, esize), unsigned);
  3510. if (sub_op)
  3511. {
  3512. sum = element1 - element2;
  3513. }
  3514. else
  3515. {
  3516. sum = element1 + element2;
  3517. }
  3518. Elem(result, e, 2 * esize, sum.SubBigInteger(2 * esize - 1, 0));
  3519. }
  3520. V(d, result);
  3521. }
  3522. // sub_advsimd.html#SUB_asisdsame_only
  3523. public static void Sub_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3524. {
  3525. const bool U = true;
  3526. /* Decode Scalar */
  3527. int d = (int)UInt(Rd);
  3528. int n = (int)UInt(Rn);
  3529. int m = (int)UInt(Rm);
  3530. /* if size != '11' then ReservedValue(); */
  3531. int esize = 8 << (int)UInt(size);
  3532. int datasize = esize;
  3533. int elements = 1;
  3534. bool sub_op = (U == true);
  3535. /* Operation */
  3536. /* CheckFPAdvSIMDEnabled64(); */
  3537. Bits result = new Bits(datasize);
  3538. Bits operand1 = V(datasize, n);
  3539. Bits operand2 = V(datasize, m);
  3540. Bits element1;
  3541. Bits element2;
  3542. for (int e = 0; e <= elements - 1; e++)
  3543. {
  3544. element1 = Elem(operand1, e, esize);
  3545. element2 = Elem(operand2, e, esize);
  3546. if (sub_op)
  3547. {
  3548. Elem(result, e, esize, element1 - element2);
  3549. }
  3550. else
  3551. {
  3552. Elem(result, e, esize, element1 + element2);
  3553. }
  3554. }
  3555. V(d, result);
  3556. }
  3557. // sub_advsimd.html#SUB_asimdsame_only
  3558. public static void Sub_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3559. {
  3560. const bool U = true;
  3561. /* Decode Vector */
  3562. int d = (int)UInt(Rd);
  3563. int n = (int)UInt(Rn);
  3564. int m = (int)UInt(Rm);
  3565. /* if size:Q == '110' then ReservedValue(); */
  3566. int esize = 8 << (int)UInt(size);
  3567. int datasize = (Q ? 128 : 64);
  3568. int elements = datasize / esize;
  3569. bool sub_op = (U == true);
  3570. /* Operation */
  3571. /* CheckFPAdvSIMDEnabled64(); */
  3572. Bits result = new Bits(datasize);
  3573. Bits operand1 = V(datasize, n);
  3574. Bits operand2 = V(datasize, m);
  3575. Bits element1;
  3576. Bits element2;
  3577. for (int e = 0; e <= elements - 1; e++)
  3578. {
  3579. element1 = Elem(operand1, e, esize);
  3580. element2 = Elem(operand2, e, esize);
  3581. if (sub_op)
  3582. {
  3583. Elem(result, e, esize, element1 - element2);
  3584. }
  3585. else
  3586. {
  3587. Elem(result, e, esize, element1 + element2);
  3588. }
  3589. }
  3590. V(d, result);
  3591. }
  3592. // subhn_advsimd.html
  3593. public static void Subhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3594. {
  3595. const bool U = false;
  3596. const bool o1 = true;
  3597. /* Decode */
  3598. int d = (int)UInt(Rd);
  3599. int n = (int)UInt(Rn);
  3600. int m = (int)UInt(Rm);
  3601. /* if size == '11' then ReservedValue(); */
  3602. int esize = 8 << (int)UInt(size);
  3603. int datasize = 64;
  3604. int part = (int)UInt(Q);
  3605. int elements = datasize / esize;
  3606. bool sub_op = (o1 == true);
  3607. bool round = (U == true);
  3608. /* Operation */
  3609. /* CheckFPAdvSIMDEnabled64(); */
  3610. Bits result = new Bits(datasize);
  3611. Bits operand1 = V(2 * datasize, n);
  3612. Bits operand2 = V(2 * datasize, m);
  3613. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3614. Bits sum;
  3615. Bits element1;
  3616. Bits element2;
  3617. for (int e = 0; e <= elements - 1; e++)
  3618. {
  3619. element1 = Elem(operand1, e, 2 * esize);
  3620. element2 = Elem(operand2, e, 2 * esize);
  3621. if (sub_op)
  3622. {
  3623. sum = element1 - element2;
  3624. }
  3625. else
  3626. {
  3627. sum = element1 + element2;
  3628. }
  3629. sum = sum + round_const;
  3630. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3631. }
  3632. Vpart(d, part, result);
  3633. }
  3634. // trn1_advsimd.html
  3635. public static void Trn1_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3636. {
  3637. const bool op = false;
  3638. /* Decode */
  3639. int d = (int)UInt(Rd);
  3640. int n = (int)UInt(Rn);
  3641. int m = (int)UInt(Rm);
  3642. /* if size:Q == '110' then ReservedValue(); */
  3643. int esize = 8 << (int)UInt(size);
  3644. int datasize = (Q ? 128 : 64);
  3645. int elements = datasize / esize;
  3646. int part = (int)UInt(op);
  3647. int pairs = elements / 2;
  3648. /* Operation */
  3649. /* CheckFPAdvSIMDEnabled64(); */
  3650. Bits result = new Bits(datasize);
  3651. Bits operand1 = V(datasize, n);
  3652. Bits operand2 = V(datasize, m);
  3653. for (int p = 0; p <= pairs - 1; p++)
  3654. {
  3655. Elem(result, 2 * p + 0, esize, Elem(operand1, 2 * p + part, esize));
  3656. Elem(result, 2 * p + 1, esize, Elem(operand2, 2 * p + part, esize));
  3657. }
  3658. V(d, result);
  3659. }
  3660. // trn2_advsimd.html
  3661. public static void Trn2_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3662. {
  3663. const bool op = true;
  3664. /* Decode */
  3665. int d = (int)UInt(Rd);
  3666. int n = (int)UInt(Rn);
  3667. int m = (int)UInt(Rm);
  3668. /* if size:Q == '110' then ReservedValue(); */
  3669. int esize = 8 << (int)UInt(size);
  3670. int datasize = (Q ? 128 : 64);
  3671. int elements = datasize / esize;
  3672. int part = (int)UInt(op);
  3673. int pairs = elements / 2;
  3674. /* Operation */
  3675. /* CheckFPAdvSIMDEnabled64(); */
  3676. Bits result = new Bits(datasize);
  3677. Bits operand1 = V(datasize, n);
  3678. Bits operand2 = V(datasize, m);
  3679. for (int p = 0; p <= pairs - 1; p++)
  3680. {
  3681. Elem(result, 2 * p + 0, esize, Elem(operand1, 2 * p + part, esize));
  3682. Elem(result, 2 * p + 1, esize, Elem(operand2, 2 * p + part, esize));
  3683. }
  3684. V(d, result);
  3685. }
  3686. // uaba_advsimd.html
  3687. public static void Uaba_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3688. {
  3689. const bool U = true;
  3690. const bool ac = true;
  3691. /* Decode */
  3692. int d = (int)UInt(Rd);
  3693. int n = (int)UInt(Rn);
  3694. int m = (int)UInt(Rm);
  3695. /* if size == '11' then ReservedValue(); */
  3696. int esize = 8 << (int)UInt(size);
  3697. int datasize = (Q ? 128 : 64);
  3698. int elements = datasize / esize;
  3699. bool unsigned = (U == true);
  3700. bool accumulate = (ac == true);
  3701. /* Operation */
  3702. /* CheckFPAdvSIMDEnabled64(); */
  3703. Bits operand1 = V(datasize, n);
  3704. Bits operand2 = V(datasize, m);
  3705. BigInteger element1;
  3706. BigInteger element2;
  3707. Bits absdiff;
  3708. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3709. for (int e = 0; e <= elements - 1; e++)
  3710. {
  3711. element1 = Int(Elem(operand1, e, esize), unsigned);
  3712. element2 = Int(Elem(operand2, e, esize), unsigned);
  3713. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3714. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3715. }
  3716. V(d, result);
  3717. }
  3718. // uabal_advsimd.html
  3719. public static void Uabal_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3720. {
  3721. const bool U = true;
  3722. const bool op = false;
  3723. /* Decode */
  3724. int d = (int)UInt(Rd);
  3725. int n = (int)UInt(Rn);
  3726. int m = (int)UInt(Rm);
  3727. /* if size == '11' then ReservedValue(); */
  3728. int esize = 8 << (int)UInt(size);
  3729. int datasize = 64;
  3730. int part = (int)UInt(Q);
  3731. int elements = datasize / esize;
  3732. bool accumulate = (op == false);
  3733. bool unsigned = (U == true);
  3734. /* Operation */
  3735. /* CheckFPAdvSIMDEnabled64(); */
  3736. Bits operand1 = Vpart(datasize, n, part);
  3737. Bits operand2 = Vpart(datasize, m, part);
  3738. BigInteger element1;
  3739. BigInteger element2;
  3740. Bits absdiff;
  3741. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3742. for (int e = 0; e <= elements - 1; e++)
  3743. {
  3744. element1 = Int(Elem(operand1, e, esize), unsigned);
  3745. element2 = Int(Elem(operand2, e, esize), unsigned);
  3746. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3747. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3748. }
  3749. V(d, result);
  3750. }
  3751. // uabd_advsimd.html
  3752. public static void Uabd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3753. {
  3754. const bool U = true;
  3755. const bool ac = false;
  3756. /* Decode */
  3757. int d = (int)UInt(Rd);
  3758. int n = (int)UInt(Rn);
  3759. int m = (int)UInt(Rm);
  3760. /* if size == '11' then ReservedValue(); */
  3761. int esize = 8 << (int)UInt(size);
  3762. int datasize = (Q ? 128 : 64);
  3763. int elements = datasize / esize;
  3764. bool unsigned = (U == true);
  3765. bool accumulate = (ac == true);
  3766. /* Operation */
  3767. /* CheckFPAdvSIMDEnabled64(); */
  3768. Bits operand1 = V(datasize, n);
  3769. Bits operand2 = V(datasize, m);
  3770. BigInteger element1;
  3771. BigInteger element2;
  3772. Bits absdiff;
  3773. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3774. for (int e = 0; e <= elements - 1; e++)
  3775. {
  3776. element1 = Int(Elem(operand1, e, esize), unsigned);
  3777. element2 = Int(Elem(operand2, e, esize), unsigned);
  3778. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3779. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3780. }
  3781. V(d, result);
  3782. }
  3783. // uabdl_advsimd.html
  3784. public static void Uabdl_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3785. {
  3786. const bool U = true;
  3787. const bool op = true;
  3788. /* Decode */
  3789. int d = (int)UInt(Rd);
  3790. int n = (int)UInt(Rn);
  3791. int m = (int)UInt(Rm);
  3792. /* if size == '11' then ReservedValue(); */
  3793. int esize = 8 << (int)UInt(size);
  3794. int datasize = 64;
  3795. int part = (int)UInt(Q);
  3796. int elements = datasize / esize;
  3797. bool accumulate = (op == false);
  3798. bool unsigned = (U == true);
  3799. /* Operation */
  3800. /* CheckFPAdvSIMDEnabled64(); */
  3801. Bits operand1 = Vpart(datasize, n, part);
  3802. Bits operand2 = Vpart(datasize, m, part);
  3803. BigInteger element1;
  3804. BigInteger element2;
  3805. Bits absdiff;
  3806. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3807. for (int e = 0; e <= elements - 1; e++)
  3808. {
  3809. element1 = Int(Elem(operand1, e, esize), unsigned);
  3810. element2 = Int(Elem(operand2, e, esize), unsigned);
  3811. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3812. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3813. }
  3814. V(d, result);
  3815. }
  3816. // uaddw_advsimd.html
  3817. public static void Uaddw_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3818. {
  3819. const bool U = true;
  3820. const bool o1 = false;
  3821. /* Decode */
  3822. int d = (int)UInt(Rd);
  3823. int n = (int)UInt(Rn);
  3824. int m = (int)UInt(Rm);
  3825. /* if size == '11' then ReservedValue(); */
  3826. int esize = 8 << (int)UInt(size);
  3827. int datasize = 64;
  3828. int part = (int)UInt(Q);
  3829. int elements = datasize / esize;
  3830. bool sub_op = (o1 == true);
  3831. bool unsigned = (U == true);
  3832. /* Operation */
  3833. /* CheckFPAdvSIMDEnabled64(); */
  3834. Bits result = new Bits(2 * datasize);
  3835. Bits operand1 = V(2 * datasize, n);
  3836. Bits operand2 = Vpart(datasize, m, part);
  3837. BigInteger element1;
  3838. BigInteger element2;
  3839. BigInteger sum;
  3840. for (int e = 0; e <= elements - 1; e++)
  3841. {
  3842. element1 = Int(Elem(operand1, e, 2 * esize), unsigned);
  3843. element2 = Int(Elem(operand2, e, esize), unsigned);
  3844. if (sub_op)
  3845. {
  3846. sum = element1 - element2;
  3847. }
  3848. else
  3849. {
  3850. sum = element1 + element2;
  3851. }
  3852. Elem(result, e, 2 * esize, sum.SubBigInteger(2 * esize - 1, 0));
  3853. }
  3854. V(d, result);
  3855. }
  3856. // usubw_advsimd.html
  3857. public static void Usubw_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3858. {
  3859. const bool U = true;
  3860. const bool o1 = true;
  3861. /* Decode */
  3862. int d = (int)UInt(Rd);
  3863. int n = (int)UInt(Rn);
  3864. int m = (int)UInt(Rm);
  3865. /* if size == '11' then ReservedValue(); */
  3866. int esize = 8 << (int)UInt(size);
  3867. int datasize = 64;
  3868. int part = (int)UInt(Q);
  3869. int elements = datasize / esize;
  3870. bool sub_op = (o1 == true);
  3871. bool unsigned = (U == true);
  3872. /* Operation */
  3873. /* CheckFPAdvSIMDEnabled64(); */
  3874. Bits result = new Bits(2 * datasize);
  3875. Bits operand1 = V(2 * datasize, n);
  3876. Bits operand2 = Vpart(datasize, m, part);
  3877. BigInteger element1;
  3878. BigInteger element2;
  3879. BigInteger sum;
  3880. for (int e = 0; e <= elements - 1; e++)
  3881. {
  3882. element1 = Int(Elem(operand1, e, 2 * esize), unsigned);
  3883. element2 = Int(Elem(operand2, e, esize), unsigned);
  3884. if (sub_op)
  3885. {
  3886. sum = element1 - element2;
  3887. }
  3888. else
  3889. {
  3890. sum = element1 + element2;
  3891. }
  3892. Elem(result, e, 2 * esize, sum.SubBigInteger(2 * esize - 1, 0));
  3893. }
  3894. V(d, result);
  3895. }
  3896. // uzp1_advsimd.html
  3897. public static void Uzp1_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3898. {
  3899. const bool op = false;
  3900. /* Decode */
  3901. int d = (int)UInt(Rd);
  3902. int n = (int)UInt(Rn);
  3903. int m = (int)UInt(Rm);
  3904. /* if size:Q == '110' then ReservedValue(); */
  3905. int esize = 8 << (int)UInt(size);
  3906. int datasize = (Q ? 128 : 64);
  3907. int elements = datasize / esize;
  3908. int part = (int)UInt(op);
  3909. /* Operation */
  3910. /* CheckFPAdvSIMDEnabled64(); */
  3911. Bits result = new Bits(datasize);
  3912. Bits operandl = V(datasize, n);
  3913. Bits operandh = V(datasize, m);
  3914. Bits zipped = Bits.Concat(operandh, operandl);
  3915. for (int e = 0; e <= elements - 1; e++)
  3916. {
  3917. Elem(result, e, esize, Elem(zipped, 2 * e + part, esize));
  3918. }
  3919. V(d, result);
  3920. }
  3921. // uzp2_advsimd.html
  3922. public static void Uzp2_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3923. {
  3924. const bool op = true;
  3925. /* Decode */
  3926. int d = (int)UInt(Rd);
  3927. int n = (int)UInt(Rn);
  3928. int m = (int)UInt(Rm);
  3929. /* if size:Q == '110' then ReservedValue(); */
  3930. int esize = 8 << (int)UInt(size);
  3931. int datasize = (Q ? 128 : 64);
  3932. int elements = datasize / esize;
  3933. int part = (int)UInt(op);
  3934. /* Operation */
  3935. /* CheckFPAdvSIMDEnabled64(); */
  3936. Bits result = new Bits(datasize);
  3937. Bits operandl = V(datasize, n);
  3938. Bits operandh = V(datasize, m);
  3939. Bits zipped = Bits.Concat(operandh, operandl);
  3940. for (int e = 0; e <= elements - 1; e++)
  3941. {
  3942. Elem(result, e, esize, Elem(zipped, 2 * e + part, esize));
  3943. }
  3944. V(d, result);
  3945. }
  3946. // zip1_advsimd.html
  3947. public static void Zip1_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3948. {
  3949. const bool op = false;
  3950. /* Decode */
  3951. int d = (int)UInt(Rd);
  3952. int n = (int)UInt(Rn);
  3953. int m = (int)UInt(Rm);
  3954. /* if size:Q == '110' then ReservedValue(); */
  3955. int esize = 8 << (int)UInt(size);
  3956. int datasize = (Q ? 128 : 64);
  3957. int elements = datasize / esize;
  3958. int part = (int)UInt(op);
  3959. int pairs = elements / 2;
  3960. /* Operation */
  3961. /* CheckFPAdvSIMDEnabled64(); */
  3962. Bits result = new Bits(datasize);
  3963. Bits operand1 = V(datasize, n);
  3964. Bits operand2 = V(datasize, m);
  3965. int @base = part * pairs;
  3966. for (int p = 0; p <= pairs - 1; p++)
  3967. {
  3968. Elem(result, 2 * p + 0, esize, Elem(operand1, @base + p, esize));
  3969. Elem(result, 2 * p + 1, esize, Elem(operand2, @base + p, esize));
  3970. }
  3971. V(d, result);
  3972. }
  3973. // zip2_advsimd.html
  3974. public static void Zip2_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3975. {
  3976. const bool op = true;
  3977. /* Decode */
  3978. int d = (int)UInt(Rd);
  3979. int n = (int)UInt(Rn);
  3980. int m = (int)UInt(Rm);
  3981. /* if size:Q == '110' then ReservedValue(); */
  3982. int esize = 8 << (int)UInt(size);
  3983. int datasize = (Q ? 128 : 64);
  3984. int elements = datasize / esize;
  3985. int part = (int)UInt(op);
  3986. int pairs = elements / 2;
  3987. /* Operation */
  3988. /* CheckFPAdvSIMDEnabled64(); */
  3989. Bits result = new Bits(datasize);
  3990. Bits operand1 = V(datasize, n);
  3991. Bits operand2 = V(datasize, m);
  3992. int @base = part * pairs;
  3993. for (int p = 0; p <= pairs - 1; p++)
  3994. {
  3995. Elem(result, 2 * p + 0, esize, Elem(operand1, @base + p, esize));
  3996. Elem(result, 2 * p + 1, esize, Elem(operand2, @base + p, esize));
  3997. }
  3998. V(d, result);
  3999. }
  4000. #endregion
  4001. }
  4002. }