Instructions.cs 138 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837
  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. #endregion
  2531. #region "SimdReg"
  2532. // add_advsimd.html#ADD_asisdsame_only
  2533. public static void Add_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2534. {
  2535. const bool U = false;
  2536. /* Decode Scalar */
  2537. int d = (int)UInt(Rd);
  2538. int n = (int)UInt(Rn);
  2539. int m = (int)UInt(Rm);
  2540. /* if size != '11' then ReservedValue(); */
  2541. int esize = 8 << (int)UInt(size);
  2542. int datasize = esize;
  2543. int elements = 1;
  2544. bool sub_op = (U == true);
  2545. /* Operation */
  2546. /* CheckFPAdvSIMDEnabled64(); */
  2547. Bits result = new Bits(datasize);
  2548. Bits operand1 = V(datasize, n);
  2549. Bits operand2 = V(datasize, m);
  2550. Bits element1;
  2551. Bits element2;
  2552. for (int e = 0; e <= elements - 1; e++)
  2553. {
  2554. element1 = Elem(operand1, e, esize);
  2555. element2 = Elem(operand2, e, esize);
  2556. if (sub_op)
  2557. {
  2558. Elem(result, e, esize, element1 - element2);
  2559. }
  2560. else
  2561. {
  2562. Elem(result, e, esize, element1 + element2);
  2563. }
  2564. }
  2565. V(d, result);
  2566. }
  2567. // add_advsimd.html#ADD_asimdsame_only
  2568. public static void Add_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2569. {
  2570. const bool U = false;
  2571. /* Decode Vector */
  2572. int d = (int)UInt(Rd);
  2573. int n = (int)UInt(Rn);
  2574. int m = (int)UInt(Rm);
  2575. /* if size:Q == '110' then ReservedValue(); */
  2576. int esize = 8 << (int)UInt(size);
  2577. int datasize = (Q ? 128 : 64);
  2578. int elements = datasize / esize;
  2579. bool sub_op = (U == true);
  2580. /* Operation */
  2581. /* CheckFPAdvSIMDEnabled64(); */
  2582. Bits result = new Bits(datasize);
  2583. Bits operand1 = V(datasize, n);
  2584. Bits operand2 = V(datasize, m);
  2585. Bits element1;
  2586. Bits element2;
  2587. for (int e = 0; e <= elements - 1; e++)
  2588. {
  2589. element1 = Elem(operand1, e, esize);
  2590. element2 = Elem(operand2, e, esize);
  2591. if (sub_op)
  2592. {
  2593. Elem(result, e, esize, element1 - element2);
  2594. }
  2595. else
  2596. {
  2597. Elem(result, e, esize, element1 + element2);
  2598. }
  2599. }
  2600. V(d, result);
  2601. }
  2602. // addhn_advsimd.html
  2603. public static void Addhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2604. {
  2605. const bool U = false;
  2606. const bool o1 = false;
  2607. /* Decode */
  2608. int d = (int)UInt(Rd);
  2609. int n = (int)UInt(Rn);
  2610. int m = (int)UInt(Rm);
  2611. /* if size == '11' then ReservedValue(); */
  2612. int esize = 8 << (int)UInt(size);
  2613. int datasize = 64;
  2614. int part = (int)UInt(Q);
  2615. int elements = datasize / esize;
  2616. bool sub_op = (o1 == true);
  2617. bool round = (U == true);
  2618. /* Operation */
  2619. /* CheckFPAdvSIMDEnabled64(); */
  2620. Bits result = new Bits(datasize);
  2621. Bits operand1 = V(2 * datasize, n);
  2622. Bits operand2 = V(2 * datasize, m);
  2623. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  2624. Bits sum;
  2625. Bits element1;
  2626. Bits element2;
  2627. for (int e = 0; e <= elements - 1; e++)
  2628. {
  2629. element1 = Elem(operand1, e, 2 * esize);
  2630. element2 = Elem(operand2, e, 2 * esize);
  2631. if (sub_op)
  2632. {
  2633. sum = element1 - element2;
  2634. }
  2635. else
  2636. {
  2637. sum = element1 + element2;
  2638. }
  2639. sum = sum + round_const;
  2640. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  2641. }
  2642. Vpart(d, part, result);
  2643. }
  2644. // addp_advsimd_vec.html
  2645. public static void Addp_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2646. {
  2647. /* Decode */
  2648. int d = (int)UInt(Rd);
  2649. int n = (int)UInt(Rn);
  2650. int m = (int)UInt(Rm);
  2651. /* if size:Q == '110' then ReservedValue(); */
  2652. int esize = 8 << (int)UInt(size);
  2653. int datasize = (Q ? 128 : 64);
  2654. int elements = datasize / esize;
  2655. /* Operation */
  2656. /* CheckFPAdvSIMDEnabled64(); */
  2657. Bits result = new Bits(datasize);
  2658. Bits operand1 = V(datasize, n);
  2659. Bits operand2 = V(datasize, m);
  2660. Bits concat = Bits.Concat(operand2, operand1);
  2661. Bits element1;
  2662. Bits element2;
  2663. for (int e = 0; e <= elements - 1; e++)
  2664. {
  2665. element1 = Elem(concat, 2 * e, esize);
  2666. element2 = Elem(concat, (2 * e) + 1, esize);
  2667. Elem(result, e, esize, element1 + element2);
  2668. }
  2669. V(d, result);
  2670. }
  2671. // and_advsimd.html
  2672. public static void And_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2673. {
  2674. /* Decode */
  2675. int d = (int)UInt(Rd);
  2676. int n = (int)UInt(Rn);
  2677. int m = (int)UInt(Rm);
  2678. int datasize = (Q ? 128 : 64);
  2679. /* Operation */
  2680. /* CheckFPAdvSIMDEnabled64(); */
  2681. Bits operand1 = V(datasize, n);
  2682. Bits operand2 = V(datasize, m);
  2683. Bits result = AND(operand1, operand2);
  2684. V(d, result);
  2685. }
  2686. // bic_advsimd_reg.html
  2687. public static void Bic_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2688. {
  2689. /* Decode */
  2690. int d = (int)UInt(Rd);
  2691. int n = (int)UInt(Rn);
  2692. int m = (int)UInt(Rm);
  2693. int datasize = (Q ? 128 : 64);
  2694. /* Operation */
  2695. /* CheckFPAdvSIMDEnabled64(); */
  2696. Bits operand1 = V(datasize, n);
  2697. Bits operand2 = V(datasize, m);
  2698. operand2 = NOT(operand2);
  2699. Bits result = AND(operand1, operand2);
  2700. V(d, result);
  2701. }
  2702. // bif_advsimd.html
  2703. public static void Bif_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2704. {
  2705. /* Decode */
  2706. int d = (int)UInt(Rd);
  2707. int n = (int)UInt(Rn);
  2708. int m = (int)UInt(Rm);
  2709. int datasize = (Q ? 128 : 64);
  2710. /* Operation */
  2711. /* CheckFPAdvSIMDEnabled64(); */
  2712. Bits operand1;
  2713. Bits operand3;
  2714. Bits operand4 = V(datasize, n);
  2715. operand1 = V(datasize, d);
  2716. operand3 = NOT(V(datasize, m));
  2717. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2718. }
  2719. // bit_advsimd.html
  2720. public static void Bit_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2721. {
  2722. /* Decode */
  2723. int d = (int)UInt(Rd);
  2724. int n = (int)UInt(Rn);
  2725. int m = (int)UInt(Rm);
  2726. int datasize = (Q ? 128 : 64);
  2727. /* Operation */
  2728. /* CheckFPAdvSIMDEnabled64(); */
  2729. Bits operand1;
  2730. Bits operand3;
  2731. Bits operand4 = V(datasize, n);
  2732. operand1 = V(datasize, d);
  2733. operand3 = V(datasize, m);
  2734. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2735. }
  2736. // bsl_advsimd.html
  2737. public static void Bsl_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2738. {
  2739. /* Decode */
  2740. int d = (int)UInt(Rd);
  2741. int n = (int)UInt(Rn);
  2742. int m = (int)UInt(Rm);
  2743. int datasize = (Q ? 128 : 64);
  2744. /* Operation */
  2745. /* CheckFPAdvSIMDEnabled64(); */
  2746. Bits operand1;
  2747. Bits operand3;
  2748. Bits operand4 = V(datasize, n);
  2749. operand1 = V(datasize, m);
  2750. operand3 = V(datasize, d);
  2751. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2752. }
  2753. // cmeq_advsimd_reg.html#CMEQ_asisdsame_only
  2754. public static void Cmeq_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2755. {
  2756. const bool U = true;
  2757. /* Decode Scalar */
  2758. int d = (int)UInt(Rd);
  2759. int n = (int)UInt(Rn);
  2760. int m = (int)UInt(Rm);
  2761. /* if size != '11' then ReservedValue(); */
  2762. int esize = 8 << (int)UInt(size);
  2763. int datasize = esize;
  2764. int elements = 1;
  2765. bool and_test = (U == false);
  2766. /* Operation */
  2767. /* CheckFPAdvSIMDEnabled64(); */
  2768. Bits result = new Bits(datasize);
  2769. Bits operand1 = V(datasize, n);
  2770. Bits operand2 = V(datasize, m);
  2771. Bits element1;
  2772. Bits element2;
  2773. bool test_passed;
  2774. for (int e = 0; e <= elements - 1; e++)
  2775. {
  2776. element1 = Elem(operand1, e, esize);
  2777. element2 = Elem(operand2, e, esize);
  2778. if (and_test)
  2779. {
  2780. test_passed = !IsZero(AND(element1, element2));
  2781. }
  2782. else
  2783. {
  2784. test_passed = (element1 == element2);
  2785. }
  2786. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2787. }
  2788. V(d, result);
  2789. }
  2790. // cmeq_advsimd_reg.html#CMEQ_asimdsame_only
  2791. public static void Cmeq_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2792. {
  2793. const bool U = true;
  2794. /* Decode Vector */
  2795. int d = (int)UInt(Rd);
  2796. int n = (int)UInt(Rn);
  2797. int m = (int)UInt(Rm);
  2798. /* if size:Q == '110' then ReservedValue(); */
  2799. int esize = 8 << (int)UInt(size);
  2800. int datasize = (Q ? 128 : 64);
  2801. int elements = datasize / esize;
  2802. bool and_test = (U == false);
  2803. /* Operation */
  2804. /* CheckFPAdvSIMDEnabled64(); */
  2805. Bits result = new Bits(datasize);
  2806. Bits operand1 = V(datasize, n);
  2807. Bits operand2 = V(datasize, m);
  2808. Bits element1;
  2809. Bits element2;
  2810. bool test_passed;
  2811. for (int e = 0; e <= elements - 1; e++)
  2812. {
  2813. element1 = Elem(operand1, e, esize);
  2814. element2 = Elem(operand2, e, esize);
  2815. if (and_test)
  2816. {
  2817. test_passed = !IsZero(AND(element1, element2));
  2818. }
  2819. else
  2820. {
  2821. test_passed = (element1 == element2);
  2822. }
  2823. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2824. }
  2825. V(d, result);
  2826. }
  2827. // cmge_advsimd_reg.html#CMGE_asisdsame_only
  2828. public static void Cmge_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2829. {
  2830. const bool U = false;
  2831. const bool eq = true;
  2832. /* Decode Scalar */
  2833. int d = (int)UInt(Rd);
  2834. int n = (int)UInt(Rn);
  2835. int m = (int)UInt(Rm);
  2836. /* if size != '11' then ReservedValue(); */
  2837. int esize = 8 << (int)UInt(size);
  2838. int datasize = esize;
  2839. int elements = 1;
  2840. bool unsigned = (U == true);
  2841. bool cmp_eq = (eq == true);
  2842. /* Operation */
  2843. /* CheckFPAdvSIMDEnabled64(); */
  2844. Bits result = new Bits(datasize);
  2845. Bits operand1 = V(datasize, n);
  2846. Bits operand2 = V(datasize, m);
  2847. BigInteger element1;
  2848. BigInteger element2;
  2849. bool test_passed;
  2850. for (int e = 0; e <= elements - 1; e++)
  2851. {
  2852. element1 = Int(Elem(operand1, e, esize), unsigned);
  2853. element2 = Int(Elem(operand2, e, esize), unsigned);
  2854. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2855. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2856. }
  2857. V(d, result);
  2858. }
  2859. // cmge_advsimd_reg.html#CMGE_asimdsame_only
  2860. public static void Cmge_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2861. {
  2862. const bool U = false;
  2863. const bool eq = true;
  2864. /* Decode Vector */
  2865. int d = (int)UInt(Rd);
  2866. int n = (int)UInt(Rn);
  2867. int m = (int)UInt(Rm);
  2868. /* if size:Q == '110' then ReservedValue(); */
  2869. int esize = 8 << (int)UInt(size);
  2870. int datasize = (Q ? 128 : 64);
  2871. int elements = datasize / esize;
  2872. bool unsigned = (U == true);
  2873. bool cmp_eq = (eq == true);
  2874. /* Operation */
  2875. /* CheckFPAdvSIMDEnabled64(); */
  2876. Bits result = new Bits(datasize);
  2877. Bits operand1 = V(datasize, n);
  2878. Bits operand2 = V(datasize, m);
  2879. BigInteger element1;
  2880. BigInteger element2;
  2881. bool test_passed;
  2882. for (int e = 0; e <= elements - 1; e++)
  2883. {
  2884. element1 = Int(Elem(operand1, e, esize), unsigned);
  2885. element2 = Int(Elem(operand2, e, esize), unsigned);
  2886. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2887. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2888. }
  2889. V(d, result);
  2890. }
  2891. // cmgt_advsimd_reg.html#CMGT_asisdsame_only
  2892. public static void Cmgt_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2893. {
  2894. const bool U = false;
  2895. const bool eq = false;
  2896. /* Decode Scalar */
  2897. int d = (int)UInt(Rd);
  2898. int n = (int)UInt(Rn);
  2899. int m = (int)UInt(Rm);
  2900. /* if size != '11' then ReservedValue(); */
  2901. int esize = 8 << (int)UInt(size);
  2902. int datasize = esize;
  2903. int elements = 1;
  2904. bool unsigned = (U == true);
  2905. bool cmp_eq = (eq == true);
  2906. /* Operation */
  2907. /* CheckFPAdvSIMDEnabled64(); */
  2908. Bits result = new Bits(datasize);
  2909. Bits operand1 = V(datasize, n);
  2910. Bits operand2 = V(datasize, m);
  2911. BigInteger element1;
  2912. BigInteger element2;
  2913. bool test_passed;
  2914. for (int e = 0; e <= elements - 1; e++)
  2915. {
  2916. element1 = Int(Elem(operand1, e, esize), unsigned);
  2917. element2 = Int(Elem(operand2, e, esize), unsigned);
  2918. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2919. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2920. }
  2921. V(d, result);
  2922. }
  2923. // cmgt_advsimd_reg.html#CMGT_asimdsame_only
  2924. public static void Cmgt_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2925. {
  2926. const bool U = false;
  2927. const bool eq = false;
  2928. /* Decode Vector */
  2929. int d = (int)UInt(Rd);
  2930. int n = (int)UInt(Rn);
  2931. int m = (int)UInt(Rm);
  2932. /* if size:Q == '110' then ReservedValue(); */
  2933. int esize = 8 << (int)UInt(size);
  2934. int datasize = (Q ? 128 : 64);
  2935. int elements = datasize / esize;
  2936. bool unsigned = (U == true);
  2937. bool cmp_eq = (eq == true);
  2938. /* Operation */
  2939. /* CheckFPAdvSIMDEnabled64(); */
  2940. Bits result = new Bits(datasize);
  2941. Bits operand1 = V(datasize, n);
  2942. Bits operand2 = V(datasize, m);
  2943. BigInteger element1;
  2944. BigInteger element2;
  2945. bool test_passed;
  2946. for (int e = 0; e <= elements - 1; e++)
  2947. {
  2948. element1 = Int(Elem(operand1, e, esize), unsigned);
  2949. element2 = Int(Elem(operand2, e, esize), unsigned);
  2950. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2951. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2952. }
  2953. V(d, result);
  2954. }
  2955. // cmhi_advsimd.html#CMHI_asisdsame_only
  2956. public static void Cmhi_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2957. {
  2958. const bool U = true;
  2959. const bool eq = false;
  2960. /* Decode Scalar */
  2961. int d = (int)UInt(Rd);
  2962. int n = (int)UInt(Rn);
  2963. int m = (int)UInt(Rm);
  2964. /* if size != '11' then ReservedValue(); */
  2965. int esize = 8 << (int)UInt(size);
  2966. int datasize = esize;
  2967. int elements = 1;
  2968. bool unsigned = (U == true);
  2969. bool cmp_eq = (eq == true);
  2970. /* Operation */
  2971. /* CheckFPAdvSIMDEnabled64(); */
  2972. Bits result = new Bits(datasize);
  2973. Bits operand1 = V(datasize, n);
  2974. Bits operand2 = V(datasize, m);
  2975. BigInteger element1;
  2976. BigInteger element2;
  2977. bool test_passed;
  2978. for (int e = 0; e <= elements - 1; e++)
  2979. {
  2980. element1 = Int(Elem(operand1, e, esize), unsigned);
  2981. element2 = Int(Elem(operand2, e, esize), unsigned);
  2982. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2983. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2984. }
  2985. V(d, result);
  2986. }
  2987. // cmhi_advsimd.html#CMHI_asimdsame_only
  2988. public static void Cmhi_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2989. {
  2990. const bool U = true;
  2991. const bool eq = false;
  2992. /* Decode Vector */
  2993. int d = (int)UInt(Rd);
  2994. int n = (int)UInt(Rn);
  2995. int m = (int)UInt(Rm);
  2996. /* if size:Q == '110' then ReservedValue(); */
  2997. int esize = 8 << (int)UInt(size);
  2998. int datasize = (Q ? 128 : 64);
  2999. int elements = datasize / esize;
  3000. bool unsigned = (U == true);
  3001. bool cmp_eq = (eq == true);
  3002. /* Operation */
  3003. /* CheckFPAdvSIMDEnabled64(); */
  3004. Bits result = new Bits(datasize);
  3005. Bits operand1 = V(datasize, n);
  3006. Bits operand2 = V(datasize, m);
  3007. BigInteger element1;
  3008. BigInteger element2;
  3009. bool test_passed;
  3010. for (int e = 0; e <= elements - 1; e++)
  3011. {
  3012. element1 = Int(Elem(operand1, e, esize), unsigned);
  3013. element2 = Int(Elem(operand2, e, esize), unsigned);
  3014. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3015. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3016. }
  3017. V(d, result);
  3018. }
  3019. // cmhs_advsimd.html#CMHS_asisdsame_only
  3020. public static void Cmhs_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3021. {
  3022. const bool U = true;
  3023. const bool eq = true;
  3024. /* Decode Scalar */
  3025. int d = (int)UInt(Rd);
  3026. int n = (int)UInt(Rn);
  3027. int m = (int)UInt(Rm);
  3028. /* if size != '11' then ReservedValue(); */
  3029. int esize = 8 << (int)UInt(size);
  3030. int datasize = esize;
  3031. int elements = 1;
  3032. bool unsigned = (U == true);
  3033. bool cmp_eq = (eq == true);
  3034. /* Operation */
  3035. /* CheckFPAdvSIMDEnabled64(); */
  3036. Bits result = new Bits(datasize);
  3037. Bits operand1 = V(datasize, n);
  3038. Bits operand2 = V(datasize, m);
  3039. BigInteger element1;
  3040. BigInteger element2;
  3041. bool test_passed;
  3042. for (int e = 0; e <= elements - 1; e++)
  3043. {
  3044. element1 = Int(Elem(operand1, e, esize), unsigned);
  3045. element2 = Int(Elem(operand2, e, esize), unsigned);
  3046. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3047. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3048. }
  3049. V(d, result);
  3050. }
  3051. // cmhs_advsimd.html#CMHS_asimdsame_only
  3052. public static void Cmhs_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3053. {
  3054. const bool U = true;
  3055. const bool eq = true;
  3056. /* Decode Vector */
  3057. int d = (int)UInt(Rd);
  3058. int n = (int)UInt(Rn);
  3059. int m = (int)UInt(Rm);
  3060. /* if size:Q == '110' then ReservedValue(); */
  3061. int esize = 8 << (int)UInt(size);
  3062. int datasize = (Q ? 128 : 64);
  3063. int elements = datasize / esize;
  3064. bool unsigned = (U == true);
  3065. bool cmp_eq = (eq == true);
  3066. /* Operation */
  3067. /* CheckFPAdvSIMDEnabled64(); */
  3068. Bits result = new Bits(datasize);
  3069. Bits operand1 = V(datasize, n);
  3070. Bits operand2 = V(datasize, m);
  3071. BigInteger element1;
  3072. BigInteger element2;
  3073. bool test_passed;
  3074. for (int e = 0; e <= elements - 1; e++)
  3075. {
  3076. element1 = Int(Elem(operand1, e, esize), unsigned);
  3077. element2 = Int(Elem(operand2, e, esize), unsigned);
  3078. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3079. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3080. }
  3081. V(d, result);
  3082. }
  3083. // cmtst_advsimd.html#CMTST_asisdsame_only
  3084. public static void Cmtst_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3085. {
  3086. const bool U = false;
  3087. /* Decode Scalar */
  3088. int d = (int)UInt(Rd);
  3089. int n = (int)UInt(Rn);
  3090. int m = (int)UInt(Rm);
  3091. /* if size != '11' then ReservedValue(); */
  3092. int esize = 8 << (int)UInt(size);
  3093. int datasize = esize;
  3094. int elements = 1;
  3095. bool and_test = (U == false);
  3096. /* Operation */
  3097. /* CheckFPAdvSIMDEnabled64(); */
  3098. Bits result = new Bits(datasize);
  3099. Bits operand1 = V(datasize, n);
  3100. Bits operand2 = V(datasize, m);
  3101. Bits element1;
  3102. Bits element2;
  3103. bool test_passed;
  3104. for (int e = 0; e <= elements - 1; e++)
  3105. {
  3106. element1 = Elem(operand1, e, esize);
  3107. element2 = Elem(operand2, e, esize);
  3108. if (and_test)
  3109. {
  3110. test_passed = !IsZero(AND(element1, element2));
  3111. }
  3112. else
  3113. {
  3114. test_passed = (element1 == element2);
  3115. }
  3116. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3117. }
  3118. V(d, result);
  3119. }
  3120. // cmtst_advsimd.html#CMTST_asimdsame_only
  3121. public static void Cmtst_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3122. {
  3123. const bool U = false;
  3124. /* Decode Vector */
  3125. int d = (int)UInt(Rd);
  3126. int n = (int)UInt(Rn);
  3127. int m = (int)UInt(Rm);
  3128. /* if size:Q == '110' then ReservedValue(); */
  3129. int esize = 8 << (int)UInt(size);
  3130. int datasize = (Q ? 128 : 64);
  3131. int elements = datasize / esize;
  3132. bool and_test = (U == false);
  3133. /* Operation */
  3134. /* CheckFPAdvSIMDEnabled64(); */
  3135. Bits result = new Bits(datasize);
  3136. Bits operand1 = V(datasize, n);
  3137. Bits operand2 = V(datasize, m);
  3138. Bits element1;
  3139. Bits element2;
  3140. bool test_passed;
  3141. for (int e = 0; e <= elements - 1; e++)
  3142. {
  3143. element1 = Elem(operand1, e, esize);
  3144. element2 = Elem(operand2, e, esize);
  3145. if (and_test)
  3146. {
  3147. test_passed = !IsZero(AND(element1, element2));
  3148. }
  3149. else
  3150. {
  3151. test_passed = (element1 == element2);
  3152. }
  3153. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3154. }
  3155. V(d, result);
  3156. }
  3157. // eor_advsimd.html
  3158. public static void Eor_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3159. {
  3160. /* Decode */
  3161. int d = (int)UInt(Rd);
  3162. int n = (int)UInt(Rn);
  3163. int m = (int)UInt(Rm);
  3164. int datasize = (Q ? 128 : 64);
  3165. /* Operation */
  3166. /* CheckFPAdvSIMDEnabled64(); */
  3167. Bits operand1 = V(datasize, m);
  3168. Bits operand2 = Zeros(datasize);
  3169. Bits operand3 = Ones(datasize);
  3170. Bits operand4 = V(datasize, n);
  3171. Bits result = EOR(operand1, AND(EOR(operand2, operand4), operand3));
  3172. V(d, result);
  3173. }
  3174. // orn_advsimd.html
  3175. public static void Orn_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3176. {
  3177. /* Decode */
  3178. int d = (int)UInt(Rd);
  3179. int n = (int)UInt(Rn);
  3180. int m = (int)UInt(Rm);
  3181. int datasize = (Q ? 128 : 64);
  3182. /* Operation */
  3183. /* CheckFPAdvSIMDEnabled64(); */
  3184. Bits operand1 = V(datasize, n);
  3185. Bits operand2 = V(datasize, m);
  3186. operand2 = NOT(operand2);
  3187. Bits result = OR(operand1, operand2);
  3188. V(d, result);
  3189. }
  3190. // orr_advsimd_reg.html
  3191. public static void Orr_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3192. {
  3193. /* Decode */
  3194. int d = (int)UInt(Rd);
  3195. int n = (int)UInt(Rn);
  3196. int m = (int)UInt(Rm);
  3197. int datasize = (Q ? 128 : 64);
  3198. /* Operation */
  3199. /* CheckFPAdvSIMDEnabled64(); */
  3200. Bits operand1 = V(datasize, n);
  3201. Bits operand2 = V(datasize, m);
  3202. Bits result = OR(operand1, operand2);
  3203. V(d, result);
  3204. }
  3205. // raddhn_advsimd.html
  3206. public static void Raddhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3207. {
  3208. const bool U = true;
  3209. const bool o1 = false;
  3210. /* Decode */
  3211. int d = (int)UInt(Rd);
  3212. int n = (int)UInt(Rn);
  3213. int m = (int)UInt(Rm);
  3214. /* if size == '11' then ReservedValue(); */
  3215. int esize = 8 << (int)UInt(size);
  3216. int datasize = 64;
  3217. int part = (int)UInt(Q);
  3218. int elements = datasize / esize;
  3219. bool sub_op = (o1 == true);
  3220. bool round = (U == true);
  3221. /* Operation */
  3222. /* CheckFPAdvSIMDEnabled64(); */
  3223. Bits result = new Bits(datasize);
  3224. Bits operand1 = V(2 * datasize, n);
  3225. Bits operand2 = V(2 * datasize, m);
  3226. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3227. Bits sum;
  3228. Bits element1;
  3229. Bits element2;
  3230. for (int e = 0; e <= elements - 1; e++)
  3231. {
  3232. element1 = Elem(operand1, e, 2 * esize);
  3233. element2 = Elem(operand2, e, 2 * esize);
  3234. if (sub_op)
  3235. {
  3236. sum = element1 - element2;
  3237. }
  3238. else
  3239. {
  3240. sum = element1 + element2;
  3241. }
  3242. sum = sum + round_const;
  3243. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3244. }
  3245. Vpart(d, part, result);
  3246. }
  3247. // rsubhn_advsimd.html
  3248. public static void Rsubhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3249. {
  3250. const bool U = true;
  3251. const bool o1 = true;
  3252. /* Decode */
  3253. int d = (int)UInt(Rd);
  3254. int n = (int)UInt(Rn);
  3255. int m = (int)UInt(Rm);
  3256. /* if size == '11' then ReservedValue(); */
  3257. int esize = 8 << (int)UInt(size);
  3258. int datasize = 64;
  3259. int part = (int)UInt(Q);
  3260. int elements = datasize / esize;
  3261. bool sub_op = (o1 == true);
  3262. bool round = (U == true);
  3263. /* Operation */
  3264. /* CheckFPAdvSIMDEnabled64(); */
  3265. Bits result = new Bits(datasize);
  3266. Bits operand1 = V(2 * datasize, n);
  3267. Bits operand2 = V(2 * datasize, m);
  3268. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3269. Bits sum;
  3270. Bits element1;
  3271. Bits element2;
  3272. for (int e = 0; e <= elements - 1; e++)
  3273. {
  3274. element1 = Elem(operand1, e, 2 * esize);
  3275. element2 = Elem(operand2, e, 2 * esize);
  3276. if (sub_op)
  3277. {
  3278. sum = element1 - element2;
  3279. }
  3280. else
  3281. {
  3282. sum = element1 + element2;
  3283. }
  3284. sum = sum + round_const;
  3285. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3286. }
  3287. Vpart(d, part, result);
  3288. }
  3289. // saba_advsimd.html
  3290. public static void Saba_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3291. {
  3292. const bool U = false;
  3293. const bool ac = true;
  3294. /* Decode */
  3295. int d = (int)UInt(Rd);
  3296. int n = (int)UInt(Rn);
  3297. int m = (int)UInt(Rm);
  3298. /* if size == '11' then ReservedValue(); */
  3299. int esize = 8 << (int)UInt(size);
  3300. int datasize = (Q ? 128 : 64);
  3301. int elements = datasize / esize;
  3302. bool unsigned = (U == true);
  3303. bool accumulate = (ac == true);
  3304. /* Operation */
  3305. /* CheckFPAdvSIMDEnabled64(); */
  3306. Bits operand1 = V(datasize, n);
  3307. Bits operand2 = V(datasize, m);
  3308. BigInteger element1;
  3309. BigInteger element2;
  3310. Bits absdiff;
  3311. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3312. for (int e = 0; e <= elements - 1; e++)
  3313. {
  3314. element1 = Int(Elem(operand1, e, esize), unsigned);
  3315. element2 = Int(Elem(operand2, e, esize), unsigned);
  3316. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3317. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3318. }
  3319. V(d, result);
  3320. }
  3321. // sabal_advsimd.html
  3322. public static void Sabal_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3323. {
  3324. const bool U = false;
  3325. const bool op = false;
  3326. /* Decode */
  3327. int d = (int)UInt(Rd);
  3328. int n = (int)UInt(Rn);
  3329. int m = (int)UInt(Rm);
  3330. /* if size == '11' then ReservedValue(); */
  3331. int esize = 8 << (int)UInt(size);
  3332. int datasize = 64;
  3333. int part = (int)UInt(Q);
  3334. int elements = datasize / esize;
  3335. bool unsigned = (U == true);
  3336. bool accumulate = (op == false);
  3337. /* Operation */
  3338. /* CheckFPAdvSIMDEnabled64(); */
  3339. Bits operand1 = Vpart(datasize, n, part);
  3340. Bits operand2 = Vpart(datasize, m, part);
  3341. BigInteger element1;
  3342. BigInteger element2;
  3343. Bits absdiff;
  3344. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3345. for (int e = 0; e <= elements - 1; e++)
  3346. {
  3347. element1 = Int(Elem(operand1, e, esize), unsigned);
  3348. element2 = Int(Elem(operand2, e, esize), unsigned);
  3349. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3350. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3351. }
  3352. V(d, result);
  3353. }
  3354. // sabd_advsimd.html
  3355. public static void Sabd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3356. {
  3357. const bool U = false;
  3358. const bool ac = false;
  3359. /* Decode */
  3360. int d = (int)UInt(Rd);
  3361. int n = (int)UInt(Rn);
  3362. int m = (int)UInt(Rm);
  3363. /* if size == '11' then ReservedValue(); */
  3364. int esize = 8 << (int)UInt(size);
  3365. int datasize = (Q ? 128 : 64);
  3366. int elements = datasize / esize;
  3367. bool unsigned = (U == true);
  3368. bool accumulate = (ac == true);
  3369. /* Operation */
  3370. /* CheckFPAdvSIMDEnabled64(); */
  3371. Bits operand1 = V(datasize, n);
  3372. Bits operand2 = V(datasize, m);
  3373. BigInteger element1;
  3374. BigInteger element2;
  3375. Bits absdiff;
  3376. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3377. for (int e = 0; e <= elements - 1; e++)
  3378. {
  3379. element1 = Int(Elem(operand1, e, esize), unsigned);
  3380. element2 = Int(Elem(operand2, e, esize), unsigned);
  3381. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3382. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3383. }
  3384. V(d, result);
  3385. }
  3386. // sabdl_advsimd.html
  3387. public static void Sabdl_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3388. {
  3389. const bool U = false;
  3390. const bool op = true;
  3391. /* Decode */
  3392. int d = (int)UInt(Rd);
  3393. int n = (int)UInt(Rn);
  3394. int m = (int)UInt(Rm);
  3395. /* if size == '11' then ReservedValue(); */
  3396. int esize = 8 << (int)UInt(size);
  3397. int datasize = 64;
  3398. int part = (int)UInt(Q);
  3399. int elements = datasize / esize;
  3400. bool unsigned = (U == true);
  3401. bool accumulate = (op == false);
  3402. /* Operation */
  3403. /* CheckFPAdvSIMDEnabled64(); */
  3404. Bits operand1 = Vpart(datasize, n, part);
  3405. Bits operand2 = Vpart(datasize, m, part);
  3406. BigInteger element1;
  3407. BigInteger element2;
  3408. Bits absdiff;
  3409. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3410. for (int e = 0; e <= elements - 1; e++)
  3411. {
  3412. element1 = Int(Elem(operand1, e, esize), unsigned);
  3413. element2 = Int(Elem(operand2, e, esize), unsigned);
  3414. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3415. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3416. }
  3417. V(d, result);
  3418. }
  3419. // sub_advsimd.html#SUB_asisdsame_only
  3420. public static void Sub_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3421. {
  3422. const bool U = true;
  3423. /* Decode Scalar */
  3424. int d = (int)UInt(Rd);
  3425. int n = (int)UInt(Rn);
  3426. int m = (int)UInt(Rm);
  3427. /* if size != '11' then ReservedValue(); */
  3428. int esize = 8 << (int)UInt(size);
  3429. int datasize = esize;
  3430. int elements = 1;
  3431. bool sub_op = (U == true);
  3432. /* Operation */
  3433. /* CheckFPAdvSIMDEnabled64(); */
  3434. Bits result = new Bits(datasize);
  3435. Bits operand1 = V(datasize, n);
  3436. Bits operand2 = V(datasize, m);
  3437. Bits element1;
  3438. Bits element2;
  3439. for (int e = 0; e <= elements - 1; e++)
  3440. {
  3441. element1 = Elem(operand1, e, esize);
  3442. element2 = Elem(operand2, e, esize);
  3443. if (sub_op)
  3444. {
  3445. Elem(result, e, esize, element1 - element2);
  3446. }
  3447. else
  3448. {
  3449. Elem(result, e, esize, element1 + element2);
  3450. }
  3451. }
  3452. V(d, result);
  3453. }
  3454. // sub_advsimd.html#SUB_asimdsame_only
  3455. public static void Sub_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3456. {
  3457. const bool U = true;
  3458. /* Decode Vector */
  3459. int d = (int)UInt(Rd);
  3460. int n = (int)UInt(Rn);
  3461. int m = (int)UInt(Rm);
  3462. /* if size:Q == '110' then ReservedValue(); */
  3463. int esize = 8 << (int)UInt(size);
  3464. int datasize = (Q ? 128 : 64);
  3465. int elements = datasize / esize;
  3466. bool sub_op = (U == true);
  3467. /* Operation */
  3468. /* CheckFPAdvSIMDEnabled64(); */
  3469. Bits result = new Bits(datasize);
  3470. Bits operand1 = V(datasize, n);
  3471. Bits operand2 = V(datasize, m);
  3472. Bits element1;
  3473. Bits element2;
  3474. for (int e = 0; e <= elements - 1; e++)
  3475. {
  3476. element1 = Elem(operand1, e, esize);
  3477. element2 = Elem(operand2, e, esize);
  3478. if (sub_op)
  3479. {
  3480. Elem(result, e, esize, element1 - element2);
  3481. }
  3482. else
  3483. {
  3484. Elem(result, e, esize, element1 + element2);
  3485. }
  3486. }
  3487. V(d, result);
  3488. }
  3489. // subhn_advsimd.html
  3490. public static void Subhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3491. {
  3492. const bool U = false;
  3493. const bool o1 = true;
  3494. /* Decode */
  3495. int d = (int)UInt(Rd);
  3496. int n = (int)UInt(Rn);
  3497. int m = (int)UInt(Rm);
  3498. /* if size == '11' then ReservedValue(); */
  3499. int esize = 8 << (int)UInt(size);
  3500. int datasize = 64;
  3501. int part = (int)UInt(Q);
  3502. int elements = datasize / esize;
  3503. bool sub_op = (o1 == true);
  3504. bool round = (U == true);
  3505. /* Operation */
  3506. /* CheckFPAdvSIMDEnabled64(); */
  3507. Bits result = new Bits(datasize);
  3508. Bits operand1 = V(2 * datasize, n);
  3509. Bits operand2 = V(2 * datasize, m);
  3510. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3511. Bits sum;
  3512. Bits element1;
  3513. Bits element2;
  3514. for (int e = 0; e <= elements - 1; e++)
  3515. {
  3516. element1 = Elem(operand1, e, 2 * esize);
  3517. element2 = Elem(operand2, e, 2 * esize);
  3518. if (sub_op)
  3519. {
  3520. sum = element1 - element2;
  3521. }
  3522. else
  3523. {
  3524. sum = element1 + element2;
  3525. }
  3526. sum = sum + round_const;
  3527. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3528. }
  3529. Vpart(d, part, result);
  3530. }
  3531. // uaba_advsimd.html
  3532. public static void Uaba_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3533. {
  3534. const bool U = true;
  3535. const bool ac = true;
  3536. /* Decode */
  3537. int d = (int)UInt(Rd);
  3538. int n = (int)UInt(Rn);
  3539. int m = (int)UInt(Rm);
  3540. /* if size == '11' then ReservedValue(); */
  3541. int esize = 8 << (int)UInt(size);
  3542. int datasize = (Q ? 128 : 64);
  3543. int elements = datasize / esize;
  3544. bool unsigned = (U == true);
  3545. bool accumulate = (ac == true);
  3546. /* Operation */
  3547. /* CheckFPAdvSIMDEnabled64(); */
  3548. Bits operand1 = V(datasize, n);
  3549. Bits operand2 = V(datasize, m);
  3550. BigInteger element1;
  3551. BigInteger element2;
  3552. Bits absdiff;
  3553. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3554. for (int e = 0; e <= elements - 1; e++)
  3555. {
  3556. element1 = Int(Elem(operand1, e, esize), unsigned);
  3557. element2 = Int(Elem(operand2, e, esize), unsigned);
  3558. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3559. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3560. }
  3561. V(d, result);
  3562. }
  3563. // uabal_advsimd.html
  3564. public static void Uabal_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3565. {
  3566. const bool U = true;
  3567. const bool op = false;
  3568. /* Decode */
  3569. int d = (int)UInt(Rd);
  3570. int n = (int)UInt(Rn);
  3571. int m = (int)UInt(Rm);
  3572. /* if size == '11' then ReservedValue(); */
  3573. int esize = 8 << (int)UInt(size);
  3574. int datasize = 64;
  3575. int part = (int)UInt(Q);
  3576. int elements = datasize / esize;
  3577. bool unsigned = (U == true);
  3578. bool accumulate = (op == false);
  3579. /* Operation */
  3580. /* CheckFPAdvSIMDEnabled64(); */
  3581. Bits operand1 = Vpart(datasize, n, part);
  3582. Bits operand2 = Vpart(datasize, m, part);
  3583. BigInteger element1;
  3584. BigInteger element2;
  3585. Bits absdiff;
  3586. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3587. for (int e = 0; e <= elements - 1; e++)
  3588. {
  3589. element1 = Int(Elem(operand1, e, esize), unsigned);
  3590. element2 = Int(Elem(operand2, e, esize), unsigned);
  3591. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3592. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3593. }
  3594. V(d, result);
  3595. }
  3596. // uabd_advsimd.html
  3597. public static void Uabd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3598. {
  3599. const bool U = true;
  3600. const bool ac = false;
  3601. /* Decode */
  3602. int d = (int)UInt(Rd);
  3603. int n = (int)UInt(Rn);
  3604. int m = (int)UInt(Rm);
  3605. /* if size == '11' then ReservedValue(); */
  3606. int esize = 8 << (int)UInt(size);
  3607. int datasize = (Q ? 128 : 64);
  3608. int elements = datasize / esize;
  3609. bool unsigned = (U == true);
  3610. bool accumulate = (ac == true);
  3611. /* Operation */
  3612. /* CheckFPAdvSIMDEnabled64(); */
  3613. Bits operand1 = V(datasize, n);
  3614. Bits operand2 = V(datasize, m);
  3615. BigInteger element1;
  3616. BigInteger element2;
  3617. Bits absdiff;
  3618. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3619. for (int e = 0; e <= elements - 1; e++)
  3620. {
  3621. element1 = Int(Elem(operand1, e, esize), unsigned);
  3622. element2 = Int(Elem(operand2, e, esize), unsigned);
  3623. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3624. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3625. }
  3626. V(d, result);
  3627. }
  3628. // uabdl_advsimd.html
  3629. public static void Uabdl_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3630. {
  3631. const bool U = true;
  3632. const bool op = true;
  3633. /* Decode */
  3634. int d = (int)UInt(Rd);
  3635. int n = (int)UInt(Rn);
  3636. int m = (int)UInt(Rm);
  3637. /* if size == '11' then ReservedValue(); */
  3638. int esize = 8 << (int)UInt(size);
  3639. int datasize = 64;
  3640. int part = (int)UInt(Q);
  3641. int elements = datasize / esize;
  3642. bool unsigned = (U == true);
  3643. bool accumulate = (op == false);
  3644. /* Operation */
  3645. /* CheckFPAdvSIMDEnabled64(); */
  3646. Bits operand1 = Vpart(datasize, n, part);
  3647. Bits operand2 = Vpart(datasize, m, part);
  3648. BigInteger element1;
  3649. BigInteger element2;
  3650. Bits absdiff;
  3651. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3652. for (int e = 0; e <= elements - 1; e++)
  3653. {
  3654. element1 = Int(Elem(operand1, e, esize), unsigned);
  3655. element2 = Int(Elem(operand2, e, esize), unsigned);
  3656. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3657. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3658. }
  3659. V(d, result);
  3660. }
  3661. #endregion
  3662. }
  3663. }