Instructions.cs 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111
  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 Scalar */
  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 */
  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 */
  1426. int d = (int)UInt(Rd);
  1427. int n = (int)UInt(Rn);
  1428. /* if size == '11' then ReservedValue(); */
  1429. int esize = 8 << (int)UInt(size);
  1430. int datasize = (Q ? 128 : 64);
  1431. int elements = datasize / esize;
  1432. CountOp countop = (U ? CountOp.CountOp_CLZ : CountOp.CountOp_CLS);
  1433. /* Operation */
  1434. /* CheckFPAdvSIMDEnabled64(); */
  1435. Bits result = new Bits(datasize);
  1436. Bits operand = V(datasize, n);
  1437. BigInteger count;
  1438. for (int e = 0; e <= elements - 1; e++)
  1439. {
  1440. if (countop == CountOp.CountOp_CLS)
  1441. {
  1442. count = (BigInteger)CountLeadingSignBits(Elem(operand, e, esize));
  1443. }
  1444. else
  1445. {
  1446. count = (BigInteger)CountLeadingZeroBits(Elem(operand, e, esize));
  1447. }
  1448. Elem(result, e, esize, count.SubBigInteger(esize - 1, 0));
  1449. }
  1450. V(d, result);
  1451. }
  1452. // cmeq_advsimd_zero.html#CMEQ_asisdmisc_Z
  1453. public static void Cmeq_Zero_S(Bits size, Bits Rn, Bits Rd)
  1454. {
  1455. const bool U = false;
  1456. const bool op = true;
  1457. /* Decode Scalar */
  1458. int d = (int)UInt(Rd);
  1459. int n = (int)UInt(Rn);
  1460. /* if size != '11' then ReservedValue(); */
  1461. int esize = 8 << (int)UInt(size);
  1462. int datasize = esize;
  1463. int elements = 1;
  1464. CompareOp comparison;
  1465. switch (Bits.Concat(op, U))
  1466. {
  1467. default:
  1468. case Bits bits when bits == "00":
  1469. comparison = CompareOp.CompareOp_GT;
  1470. break;
  1471. case Bits bits when bits == "01":
  1472. comparison = CompareOp.CompareOp_GE;
  1473. break;
  1474. case Bits bits when bits == "10":
  1475. comparison = CompareOp.CompareOp_EQ;
  1476. break;
  1477. case Bits bits when bits == "11":
  1478. comparison = CompareOp.CompareOp_LE;
  1479. break;
  1480. }
  1481. /* Operation */
  1482. /* CheckFPAdvSIMDEnabled64(); */
  1483. Bits result = new Bits(datasize);
  1484. Bits operand = V(datasize, n);
  1485. BigInteger element;
  1486. bool test_passed;
  1487. for (int e = 0; e <= elements - 1; e++)
  1488. {
  1489. element = SInt(Elem(operand, e, esize));
  1490. switch (comparison)
  1491. {
  1492. default:
  1493. case CompareOp.CompareOp_GT:
  1494. test_passed = (element > (BigInteger)0);
  1495. break;
  1496. case CompareOp.CompareOp_GE:
  1497. test_passed = (element >= (BigInteger)0);
  1498. break;
  1499. case CompareOp.CompareOp_EQ:
  1500. test_passed = (element == (BigInteger)0);
  1501. break;
  1502. case CompareOp.CompareOp_LE:
  1503. test_passed = (element <= (BigInteger)0);
  1504. break;
  1505. case CompareOp.CompareOp_LT:
  1506. test_passed = (element < (BigInteger)0);
  1507. break;
  1508. }
  1509. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1510. }
  1511. V(d, result);
  1512. }
  1513. // cmeq_advsimd_zero.html#CMEQ_asimdmisc_Z
  1514. public static void Cmeq_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1515. {
  1516. const bool U = false;
  1517. const bool op = true;
  1518. /* Decode Vector */
  1519. int d = (int)UInt(Rd);
  1520. int n = (int)UInt(Rn);
  1521. /* if size:Q == '110' then ReservedValue(); */
  1522. int esize = 8 << (int)UInt(size);
  1523. int datasize = (Q ? 128 : 64);
  1524. int elements = datasize / esize;
  1525. CompareOp comparison;
  1526. switch (Bits.Concat(op, U))
  1527. {
  1528. default:
  1529. case Bits bits when bits == "00":
  1530. comparison = CompareOp.CompareOp_GT;
  1531. break;
  1532. case Bits bits when bits == "01":
  1533. comparison = CompareOp.CompareOp_GE;
  1534. break;
  1535. case Bits bits when bits == "10":
  1536. comparison = CompareOp.CompareOp_EQ;
  1537. break;
  1538. case Bits bits when bits == "11":
  1539. comparison = CompareOp.CompareOp_LE;
  1540. break;
  1541. }
  1542. /* Operation */
  1543. /* CheckFPAdvSIMDEnabled64(); */
  1544. Bits result = new Bits(datasize);
  1545. Bits operand = V(datasize, n);
  1546. BigInteger element;
  1547. bool test_passed;
  1548. for (int e = 0; e <= elements - 1; e++)
  1549. {
  1550. element = SInt(Elem(operand, e, esize));
  1551. switch (comparison)
  1552. {
  1553. default:
  1554. case CompareOp.CompareOp_GT:
  1555. test_passed = (element > (BigInteger)0);
  1556. break;
  1557. case CompareOp.CompareOp_GE:
  1558. test_passed = (element >= (BigInteger)0);
  1559. break;
  1560. case CompareOp.CompareOp_EQ:
  1561. test_passed = (element == (BigInteger)0);
  1562. break;
  1563. case CompareOp.CompareOp_LE:
  1564. test_passed = (element <= (BigInteger)0);
  1565. break;
  1566. case CompareOp.CompareOp_LT:
  1567. test_passed = (element < (BigInteger)0);
  1568. break;
  1569. }
  1570. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1571. }
  1572. V(d, result);
  1573. }
  1574. // cmge_advsimd_zero.html#CMGE_asisdmisc_Z
  1575. public static void Cmge_Zero_S(Bits size, Bits Rn, Bits Rd)
  1576. {
  1577. const bool U = true;
  1578. const bool op = false;
  1579. /* Decode Scalar */
  1580. int d = (int)UInt(Rd);
  1581. int n = (int)UInt(Rn);
  1582. /* if size != '11' then ReservedValue(); */
  1583. int esize = 8 << (int)UInt(size);
  1584. int datasize = esize;
  1585. int elements = 1;
  1586. CompareOp comparison;
  1587. switch (Bits.Concat(op, U))
  1588. {
  1589. default:
  1590. case Bits bits when bits == "00":
  1591. comparison = CompareOp.CompareOp_GT;
  1592. break;
  1593. case Bits bits when bits == "01":
  1594. comparison = CompareOp.CompareOp_GE;
  1595. break;
  1596. case Bits bits when bits == "10":
  1597. comparison = CompareOp.CompareOp_EQ;
  1598. break;
  1599. case Bits bits when bits == "11":
  1600. comparison = CompareOp.CompareOp_LE;
  1601. break;
  1602. }
  1603. /* Operation */
  1604. /* CheckFPAdvSIMDEnabled64(); */
  1605. Bits result = new Bits(datasize);
  1606. Bits operand = V(datasize, n);
  1607. BigInteger element;
  1608. bool test_passed;
  1609. for (int e = 0; e <= elements - 1; e++)
  1610. {
  1611. element = SInt(Elem(operand, e, esize));
  1612. switch (comparison)
  1613. {
  1614. default:
  1615. case CompareOp.CompareOp_GT:
  1616. test_passed = (element > (BigInteger)0);
  1617. break;
  1618. case CompareOp.CompareOp_GE:
  1619. test_passed = (element >= (BigInteger)0);
  1620. break;
  1621. case CompareOp.CompareOp_EQ:
  1622. test_passed = (element == (BigInteger)0);
  1623. break;
  1624. case CompareOp.CompareOp_LE:
  1625. test_passed = (element <= (BigInteger)0);
  1626. break;
  1627. case CompareOp.CompareOp_LT:
  1628. test_passed = (element < (BigInteger)0);
  1629. break;
  1630. }
  1631. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1632. }
  1633. V(d, result);
  1634. }
  1635. // cmge_advsimd_zero.html#CMGE_asimdmisc_Z
  1636. public static void Cmge_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1637. {
  1638. const bool U = true;
  1639. const bool op = false;
  1640. /* Decode Vector */
  1641. int d = (int)UInt(Rd);
  1642. int n = (int)UInt(Rn);
  1643. /* if size:Q == '110' then ReservedValue(); */
  1644. int esize = 8 << (int)UInt(size);
  1645. int datasize = (Q ? 128 : 64);
  1646. int elements = datasize / esize;
  1647. CompareOp comparison;
  1648. switch (Bits.Concat(op, U))
  1649. {
  1650. default:
  1651. case Bits bits when bits == "00":
  1652. comparison = CompareOp.CompareOp_GT;
  1653. break;
  1654. case Bits bits when bits == "01":
  1655. comparison = CompareOp.CompareOp_GE;
  1656. break;
  1657. case Bits bits when bits == "10":
  1658. comparison = CompareOp.CompareOp_EQ;
  1659. break;
  1660. case Bits bits when bits == "11":
  1661. comparison = CompareOp.CompareOp_LE;
  1662. break;
  1663. }
  1664. /* Operation */
  1665. /* CheckFPAdvSIMDEnabled64(); */
  1666. Bits result = new Bits(datasize);
  1667. Bits operand = V(datasize, n);
  1668. BigInteger element;
  1669. bool test_passed;
  1670. for (int e = 0; e <= elements - 1; e++)
  1671. {
  1672. element = SInt(Elem(operand, e, esize));
  1673. switch (comparison)
  1674. {
  1675. default:
  1676. case CompareOp.CompareOp_GT:
  1677. test_passed = (element > (BigInteger)0);
  1678. break;
  1679. case CompareOp.CompareOp_GE:
  1680. test_passed = (element >= (BigInteger)0);
  1681. break;
  1682. case CompareOp.CompareOp_EQ:
  1683. test_passed = (element == (BigInteger)0);
  1684. break;
  1685. case CompareOp.CompareOp_LE:
  1686. test_passed = (element <= (BigInteger)0);
  1687. break;
  1688. case CompareOp.CompareOp_LT:
  1689. test_passed = (element < (BigInteger)0);
  1690. break;
  1691. }
  1692. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1693. }
  1694. V(d, result);
  1695. }
  1696. // cmgt_advsimd_zero.html#CMGT_asisdmisc_Z
  1697. public static void Cmgt_Zero_S(Bits size, Bits Rn, Bits Rd)
  1698. {
  1699. const bool U = false;
  1700. const bool op = false;
  1701. /* Decode Scalar */
  1702. int d = (int)UInt(Rd);
  1703. int n = (int)UInt(Rn);
  1704. /* if size != '11' then ReservedValue(); */
  1705. int esize = 8 << (int)UInt(size);
  1706. int datasize = esize;
  1707. int elements = 1;
  1708. CompareOp comparison;
  1709. switch (Bits.Concat(op, U))
  1710. {
  1711. default:
  1712. case Bits bits when bits == "00":
  1713. comparison = CompareOp.CompareOp_GT;
  1714. break;
  1715. case Bits bits when bits == "01":
  1716. comparison = CompareOp.CompareOp_GE;
  1717. break;
  1718. case Bits bits when bits == "10":
  1719. comparison = CompareOp.CompareOp_EQ;
  1720. break;
  1721. case Bits bits when bits == "11":
  1722. comparison = CompareOp.CompareOp_LE;
  1723. break;
  1724. }
  1725. /* Operation */
  1726. /* CheckFPAdvSIMDEnabled64(); */
  1727. Bits result = new Bits(datasize);
  1728. Bits operand = V(datasize, n);
  1729. BigInteger element;
  1730. bool test_passed;
  1731. for (int e = 0; e <= elements - 1; e++)
  1732. {
  1733. element = SInt(Elem(operand, e, esize));
  1734. switch (comparison)
  1735. {
  1736. default:
  1737. case CompareOp.CompareOp_GT:
  1738. test_passed = (element > (BigInteger)0);
  1739. break;
  1740. case CompareOp.CompareOp_GE:
  1741. test_passed = (element >= (BigInteger)0);
  1742. break;
  1743. case CompareOp.CompareOp_EQ:
  1744. test_passed = (element == (BigInteger)0);
  1745. break;
  1746. case CompareOp.CompareOp_LE:
  1747. test_passed = (element <= (BigInteger)0);
  1748. break;
  1749. case CompareOp.CompareOp_LT:
  1750. test_passed = (element < (BigInteger)0);
  1751. break;
  1752. }
  1753. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1754. }
  1755. V(d, result);
  1756. }
  1757. // cmgt_advsimd_zero.html#CMGT_asimdmisc_Z
  1758. public static void Cmgt_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1759. {
  1760. const bool U = false;
  1761. const bool op = false;
  1762. /* Decode Vector */
  1763. int d = (int)UInt(Rd);
  1764. int n = (int)UInt(Rn);
  1765. /* if size:Q == '110' then ReservedValue(); */
  1766. int esize = 8 << (int)UInt(size);
  1767. int datasize = (Q ? 128 : 64);
  1768. int elements = datasize / esize;
  1769. CompareOp comparison;
  1770. switch (Bits.Concat(op, U))
  1771. {
  1772. default:
  1773. case Bits bits when bits == "00":
  1774. comparison = CompareOp.CompareOp_GT;
  1775. break;
  1776. case Bits bits when bits == "01":
  1777. comparison = CompareOp.CompareOp_GE;
  1778. break;
  1779. case Bits bits when bits == "10":
  1780. comparison = CompareOp.CompareOp_EQ;
  1781. break;
  1782. case Bits bits when bits == "11":
  1783. comparison = CompareOp.CompareOp_LE;
  1784. break;
  1785. }
  1786. /* Operation */
  1787. /* CheckFPAdvSIMDEnabled64(); */
  1788. Bits result = new Bits(datasize);
  1789. Bits operand = V(datasize, n);
  1790. BigInteger element;
  1791. bool test_passed;
  1792. for (int e = 0; e <= elements - 1; e++)
  1793. {
  1794. element = SInt(Elem(operand, e, esize));
  1795. switch (comparison)
  1796. {
  1797. default:
  1798. case CompareOp.CompareOp_GT:
  1799. test_passed = (element > (BigInteger)0);
  1800. break;
  1801. case CompareOp.CompareOp_GE:
  1802. test_passed = (element >= (BigInteger)0);
  1803. break;
  1804. case CompareOp.CompareOp_EQ:
  1805. test_passed = (element == (BigInteger)0);
  1806. break;
  1807. case CompareOp.CompareOp_LE:
  1808. test_passed = (element <= (BigInteger)0);
  1809. break;
  1810. case CompareOp.CompareOp_LT:
  1811. test_passed = (element < (BigInteger)0);
  1812. break;
  1813. }
  1814. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1815. }
  1816. V(d, result);
  1817. }
  1818. // cmle_advsimd.html#CMLE_asisdmisc_Z
  1819. public static void Cmle_S(Bits size, Bits Rn, Bits Rd)
  1820. {
  1821. const bool U = true;
  1822. const bool op = true;
  1823. /* Decode Scalar */
  1824. int d = (int)UInt(Rd);
  1825. int n = (int)UInt(Rn);
  1826. /* if size != '11' then ReservedValue(); */
  1827. int esize = 8 << (int)UInt(size);
  1828. int datasize = esize;
  1829. int elements = 1;
  1830. CompareOp comparison;
  1831. switch (Bits.Concat(op, U))
  1832. {
  1833. default:
  1834. case Bits bits when bits == "00":
  1835. comparison = CompareOp.CompareOp_GT;
  1836. break;
  1837. case Bits bits when bits == "01":
  1838. comparison = CompareOp.CompareOp_GE;
  1839. break;
  1840. case Bits bits when bits == "10":
  1841. comparison = CompareOp.CompareOp_EQ;
  1842. break;
  1843. case Bits bits when bits == "11":
  1844. comparison = CompareOp.CompareOp_LE;
  1845. break;
  1846. }
  1847. /* Operation */
  1848. /* CheckFPAdvSIMDEnabled64(); */
  1849. Bits result = new Bits(datasize);
  1850. Bits operand = V(datasize, n);
  1851. BigInteger element;
  1852. bool test_passed;
  1853. for (int e = 0; e <= elements - 1; e++)
  1854. {
  1855. element = SInt(Elem(operand, e, esize));
  1856. switch (comparison)
  1857. {
  1858. default:
  1859. case CompareOp.CompareOp_GT:
  1860. test_passed = (element > (BigInteger)0);
  1861. break;
  1862. case CompareOp.CompareOp_GE:
  1863. test_passed = (element >= (BigInteger)0);
  1864. break;
  1865. case CompareOp.CompareOp_EQ:
  1866. test_passed = (element == (BigInteger)0);
  1867. break;
  1868. case CompareOp.CompareOp_LE:
  1869. test_passed = (element <= (BigInteger)0);
  1870. break;
  1871. case CompareOp.CompareOp_LT:
  1872. test_passed = (element < (BigInteger)0);
  1873. break;
  1874. }
  1875. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1876. }
  1877. V(d, result);
  1878. }
  1879. // cmle_advsimd.html#CMLE_asimdmisc_Z
  1880. public static void Cmle_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1881. {
  1882. const bool U = true;
  1883. const bool op = true;
  1884. /* Decode Vector */
  1885. int d = (int)UInt(Rd);
  1886. int n = (int)UInt(Rn);
  1887. /* if size:Q == '110' then ReservedValue(); */
  1888. int esize = 8 << (int)UInt(size);
  1889. int datasize = (Q ? 128 : 64);
  1890. int elements = datasize / esize;
  1891. CompareOp comparison;
  1892. switch (Bits.Concat(op, U))
  1893. {
  1894. default:
  1895. case Bits bits when bits == "00":
  1896. comparison = CompareOp.CompareOp_GT;
  1897. break;
  1898. case Bits bits when bits == "01":
  1899. comparison = CompareOp.CompareOp_GE;
  1900. break;
  1901. case Bits bits when bits == "10":
  1902. comparison = CompareOp.CompareOp_EQ;
  1903. break;
  1904. case Bits bits when bits == "11":
  1905. comparison = CompareOp.CompareOp_LE;
  1906. break;
  1907. }
  1908. /* Operation */
  1909. /* CheckFPAdvSIMDEnabled64(); */
  1910. Bits result = new Bits(datasize);
  1911. Bits operand = V(datasize, n);
  1912. BigInteger element;
  1913. bool test_passed;
  1914. for (int e = 0; e <= elements - 1; e++)
  1915. {
  1916. element = SInt(Elem(operand, e, esize));
  1917. switch (comparison)
  1918. {
  1919. default:
  1920. case CompareOp.CompareOp_GT:
  1921. test_passed = (element > (BigInteger)0);
  1922. break;
  1923. case CompareOp.CompareOp_GE:
  1924. test_passed = (element >= (BigInteger)0);
  1925. break;
  1926. case CompareOp.CompareOp_EQ:
  1927. test_passed = (element == (BigInteger)0);
  1928. break;
  1929. case CompareOp.CompareOp_LE:
  1930. test_passed = (element <= (BigInteger)0);
  1931. break;
  1932. case CompareOp.CompareOp_LT:
  1933. test_passed = (element < (BigInteger)0);
  1934. break;
  1935. }
  1936. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1937. }
  1938. V(d, result);
  1939. }
  1940. // cmlt_advsimd.html#CMLT_asisdmisc_Z
  1941. public static void Cmlt_S(Bits size, Bits Rn, Bits Rd)
  1942. {
  1943. /* Decode Scalar */
  1944. int d = (int)UInt(Rd);
  1945. int n = (int)UInt(Rn);
  1946. /* if size != '11' then ReservedValue(); */
  1947. int esize = 8 << (int)UInt(size);
  1948. int datasize = esize;
  1949. int elements = 1;
  1950. CompareOp comparison = CompareOp.CompareOp_LT;
  1951. /* Operation */
  1952. /* CheckFPAdvSIMDEnabled64(); */
  1953. Bits result = new Bits(datasize);
  1954. Bits operand = V(datasize, n);
  1955. BigInteger element;
  1956. bool test_passed;
  1957. for (int e = 0; e <= elements - 1; e++)
  1958. {
  1959. element = SInt(Elem(operand, e, esize));
  1960. switch (comparison)
  1961. {
  1962. default:
  1963. case CompareOp.CompareOp_GT:
  1964. test_passed = (element > (BigInteger)0);
  1965. break;
  1966. case CompareOp.CompareOp_GE:
  1967. test_passed = (element >= (BigInteger)0);
  1968. break;
  1969. case CompareOp.CompareOp_EQ:
  1970. test_passed = (element == (BigInteger)0);
  1971. break;
  1972. case CompareOp.CompareOp_LE:
  1973. test_passed = (element <= (BigInteger)0);
  1974. break;
  1975. case CompareOp.CompareOp_LT:
  1976. test_passed = (element < (BigInteger)0);
  1977. break;
  1978. }
  1979. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1980. }
  1981. V(d, result);
  1982. }
  1983. // cmlt_advsimd.html#CMLT_asimdmisc_Z
  1984. public static void Cmlt_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1985. {
  1986. /* Decode Vector */
  1987. int d = (int)UInt(Rd);
  1988. int n = (int)UInt(Rn);
  1989. /* if size:Q == '110' then ReservedValue(); */
  1990. int esize = 8 << (int)UInt(size);
  1991. int datasize = (Q ? 128 : 64);
  1992. int elements = datasize / esize;
  1993. CompareOp comparison = CompareOp.CompareOp_LT;
  1994. /* Operation */
  1995. /* CheckFPAdvSIMDEnabled64(); */
  1996. Bits result = new Bits(datasize);
  1997. Bits operand = V(datasize, n);
  1998. BigInteger element;
  1999. bool test_passed;
  2000. for (int e = 0; e <= elements - 1; e++)
  2001. {
  2002. element = SInt(Elem(operand, e, esize));
  2003. switch (comparison)
  2004. {
  2005. default:
  2006. case CompareOp.CompareOp_GT:
  2007. test_passed = (element > (BigInteger)0);
  2008. break;
  2009. case CompareOp.CompareOp_GE:
  2010. test_passed = (element >= (BigInteger)0);
  2011. break;
  2012. case CompareOp.CompareOp_EQ:
  2013. test_passed = (element == (BigInteger)0);
  2014. break;
  2015. case CompareOp.CompareOp_LE:
  2016. test_passed = (element <= (BigInteger)0);
  2017. break;
  2018. case CompareOp.CompareOp_LT:
  2019. test_passed = (element < (BigInteger)0);
  2020. break;
  2021. }
  2022. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2023. }
  2024. V(d, result);
  2025. }
  2026. // neg_advsimd.html#NEG_asisdmisc_R
  2027. public static void Neg_S(Bits size, Bits Rn, Bits Rd)
  2028. {
  2029. const bool U = true;
  2030. /* Decode Scalar */
  2031. int d = (int)UInt(Rd);
  2032. int n = (int)UInt(Rn);
  2033. /* if size != '11' then ReservedValue(); */
  2034. int esize = 8 << (int)UInt(size);
  2035. int datasize = esize;
  2036. int elements = 1;
  2037. bool neg = (U == true);
  2038. /* Operation */
  2039. /* CheckFPAdvSIMDEnabled64(); */
  2040. Bits result = new Bits(datasize);
  2041. Bits operand = V(datasize, n);
  2042. BigInteger element;
  2043. for (int e = 0; e <= elements - 1; e++)
  2044. {
  2045. element = SInt(Elem(operand, e, esize));
  2046. if (neg)
  2047. {
  2048. element = -element;
  2049. }
  2050. else
  2051. {
  2052. element = Abs(element);
  2053. }
  2054. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  2055. }
  2056. V(d, result);
  2057. }
  2058. // neg_advsimd.html#NEG_asimdmisc_R
  2059. public static void Neg_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2060. {
  2061. const bool U = true;
  2062. /* Decode Vector */
  2063. int d = (int)UInt(Rd);
  2064. int n = (int)UInt(Rn);
  2065. /* if size:Q == '110' then ReservedValue(); */
  2066. int esize = 8 << (int)UInt(size);
  2067. int datasize = (Q ? 128 : 64);
  2068. int elements = datasize / esize;
  2069. bool neg = (U == true);
  2070. /* Operation */
  2071. /* CheckFPAdvSIMDEnabled64(); */
  2072. Bits result = new Bits(datasize);
  2073. Bits operand = V(datasize, n);
  2074. BigInteger element;
  2075. for (int e = 0; e <= elements - 1; e++)
  2076. {
  2077. element = SInt(Elem(operand, e, esize));
  2078. if (neg)
  2079. {
  2080. element = -element;
  2081. }
  2082. else
  2083. {
  2084. element = Abs(element);
  2085. }
  2086. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  2087. }
  2088. V(d, result);
  2089. }
  2090. // not_advsimd.html
  2091. public static void Not_V(bool Q, Bits Rn, Bits Rd)
  2092. {
  2093. /* Decode */
  2094. int d = (int)UInt(Rd);
  2095. int n = (int)UInt(Rn);
  2096. int esize = 8;
  2097. int datasize = (Q ? 128 : 64);
  2098. int elements = datasize / 8;
  2099. /* Operation */
  2100. /* CheckFPAdvSIMDEnabled64(); */
  2101. Bits result = new Bits(datasize);
  2102. Bits operand = V(datasize, n);
  2103. Bits element;
  2104. for (int e = 0; e <= elements - 1; e++)
  2105. {
  2106. element = Elem(operand, e, esize);
  2107. Elem(result, e, esize, NOT(element));
  2108. }
  2109. V(d, result);
  2110. }
  2111. // sqxtn_advsimd.html#SQXTN_asisdmisc_N
  2112. public static void Sqxtn_S(Bits size, Bits Rn, Bits Rd)
  2113. {
  2114. const bool U = false;
  2115. /* Decode Scalar */
  2116. int d = (int)UInt(Rd);
  2117. int n = (int)UInt(Rn);
  2118. /* if size == '11' then ReservedValue(); */
  2119. int esize = 8 << (int)UInt(size);
  2120. int datasize = esize;
  2121. int part = 0;
  2122. int elements = 1;
  2123. bool unsigned = (U == true);
  2124. /* Operation */
  2125. /* CheckFPAdvSIMDEnabled64(); */
  2126. Bits result = new Bits(datasize);
  2127. Bits operand = V(2 * datasize, n);
  2128. Bits element;
  2129. bool sat;
  2130. for (int e = 0; e <= elements - 1; e++)
  2131. {
  2132. element = Elem(operand, e, 2 * esize);
  2133. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2134. Elem(result, e, esize, _result);
  2135. sat = _sat;
  2136. if (sat)
  2137. {
  2138. /* FPSR.QC = '1'; */
  2139. FPSR[27] = true; // TODO: Add named fields.
  2140. }
  2141. }
  2142. Vpart(d, part, result);
  2143. }
  2144. // sqxtn_advsimd.html#SQXTN_asimdmisc_N
  2145. public static void Sqxtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2146. {
  2147. const bool U = false;
  2148. /* Decode Vector */
  2149. int d = (int)UInt(Rd);
  2150. int n = (int)UInt(Rn);
  2151. /* if size == '11' then ReservedValue(); */
  2152. int esize = 8 << (int)UInt(size);
  2153. int datasize = 64;
  2154. int part = (int)UInt(Q);
  2155. int elements = datasize / esize;
  2156. bool unsigned = (U == true);
  2157. /* Operation */
  2158. /* CheckFPAdvSIMDEnabled64(); */
  2159. Bits result = new Bits(datasize);
  2160. Bits operand = V(2 * datasize, n);
  2161. Bits element;
  2162. bool sat;
  2163. for (int e = 0; e <= elements - 1; e++)
  2164. {
  2165. element = Elem(operand, e, 2 * esize);
  2166. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2167. Elem(result, e, esize, _result);
  2168. sat = _sat;
  2169. if (sat)
  2170. {
  2171. /* FPSR.QC = '1'; */
  2172. FPSR[27] = true; // TODO: Add named fields.
  2173. }
  2174. }
  2175. Vpart(d, part, result);
  2176. }
  2177. // uqxtn_advsimd.html#UQXTN_asisdmisc_N
  2178. public static void Uqxtn_S(Bits size, Bits Rn, Bits Rd)
  2179. {
  2180. const bool U = true;
  2181. /* Decode Scalar */
  2182. int d = (int)UInt(Rd);
  2183. int n = (int)UInt(Rn);
  2184. /* if size == '11' then ReservedValue(); */
  2185. int esize = 8 << (int)UInt(size);
  2186. int datasize = esize;
  2187. int part = 0;
  2188. int elements = 1;
  2189. bool unsigned = (U == true);
  2190. /* Operation */
  2191. /* CheckFPAdvSIMDEnabled64(); */
  2192. Bits result = new Bits(datasize);
  2193. Bits operand = V(2 * datasize, n);
  2194. Bits element;
  2195. bool sat;
  2196. for (int e = 0; e <= elements - 1; e++)
  2197. {
  2198. element = Elem(operand, e, 2 * esize);
  2199. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2200. Elem(result, e, esize, _result);
  2201. sat = _sat;
  2202. if (sat)
  2203. {
  2204. /* FPSR.QC = '1'; */
  2205. FPSR[27] = true; // TODO: Add named fields.
  2206. }
  2207. }
  2208. Vpart(d, part, result);
  2209. }
  2210. // uqxtn_advsimd.html#UQXTN_asimdmisc_N
  2211. public static void Uqxtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2212. {
  2213. const bool U = true;
  2214. /* Decode Vector */
  2215. int d = (int)UInt(Rd);
  2216. int n = (int)UInt(Rn);
  2217. /* if size == '11' then ReservedValue(); */
  2218. int esize = 8 << (int)UInt(size);
  2219. int datasize = 64;
  2220. int part = (int)UInt(Q);
  2221. int elements = datasize / esize;
  2222. bool unsigned = (U == true);
  2223. /* Operation */
  2224. /* CheckFPAdvSIMDEnabled64(); */
  2225. Bits result = new Bits(datasize);
  2226. Bits operand = V(2 * datasize, n);
  2227. Bits element;
  2228. bool sat;
  2229. for (int e = 0; e <= elements - 1; e++)
  2230. {
  2231. element = Elem(operand, e, 2 * esize);
  2232. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2233. Elem(result, e, esize, _result);
  2234. sat = _sat;
  2235. if (sat)
  2236. {
  2237. /* FPSR.QC = '1'; */
  2238. FPSR[27] = true; // TODO: Add named fields.
  2239. }
  2240. }
  2241. Vpart(d, part, result);
  2242. }
  2243. #endregion
  2244. #region "SimdReg"
  2245. // add_advsimd.html#ADD_asisdsame_only
  2246. public static void Add_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2247. {
  2248. const bool U = false;
  2249. /* Decode Scalar */
  2250. int d = (int)UInt(Rd);
  2251. int n = (int)UInt(Rn);
  2252. int m = (int)UInt(Rm);
  2253. /* if size != '11' then ReservedValue(); */
  2254. int esize = 8 << (int)UInt(size);
  2255. int datasize = esize;
  2256. int elements = 1;
  2257. bool sub_op = (U == true);
  2258. /* Operation */
  2259. /* CheckFPAdvSIMDEnabled64(); */
  2260. Bits result = new Bits(datasize);
  2261. Bits operand1 = V(datasize, n);
  2262. Bits operand2 = V(datasize, m);
  2263. Bits element1;
  2264. Bits element2;
  2265. for (int e = 0; e <= elements - 1; e++)
  2266. {
  2267. element1 = Elem(operand1, e, esize);
  2268. element2 = Elem(operand2, e, esize);
  2269. if (sub_op)
  2270. {
  2271. Elem(result, e, esize, element1 - element2);
  2272. }
  2273. else
  2274. {
  2275. Elem(result, e, esize, element1 + element2);
  2276. }
  2277. }
  2278. V(d, result);
  2279. }
  2280. // add_advsimd.html#ADD_asimdsame_only
  2281. public static void Add_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2282. {
  2283. const bool U = false;
  2284. /* Decode Vector */
  2285. int d = (int)UInt(Rd);
  2286. int n = (int)UInt(Rn);
  2287. int m = (int)UInt(Rm);
  2288. /* if size:Q == '110' then ReservedValue(); */
  2289. int esize = 8 << (int)UInt(size);
  2290. int datasize = (Q ? 128 : 64);
  2291. int elements = datasize / esize;
  2292. bool sub_op = (U == true);
  2293. /* Operation */
  2294. /* CheckFPAdvSIMDEnabled64(); */
  2295. Bits result = new Bits(datasize);
  2296. Bits operand1 = V(datasize, n);
  2297. Bits operand2 = V(datasize, m);
  2298. Bits element1;
  2299. Bits element2;
  2300. for (int e = 0; e <= elements - 1; e++)
  2301. {
  2302. element1 = Elem(operand1, e, esize);
  2303. element2 = Elem(operand2, e, esize);
  2304. if (sub_op)
  2305. {
  2306. Elem(result, e, esize, element1 - element2);
  2307. }
  2308. else
  2309. {
  2310. Elem(result, e, esize, element1 + element2);
  2311. }
  2312. }
  2313. V(d, result);
  2314. }
  2315. // addhn_advsimd.html
  2316. public static void Addhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2317. {
  2318. const bool U = false;
  2319. const bool o1 = false;
  2320. /* Decode */
  2321. int d = (int)UInt(Rd);
  2322. int n = (int)UInt(Rn);
  2323. int m = (int)UInt(Rm);
  2324. /* if size == '11' then ReservedValue(); */
  2325. int esize = 8 << (int)UInt(size);
  2326. int datasize = 64;
  2327. int part = (int)UInt(Q);
  2328. int elements = datasize / esize;
  2329. bool sub_op = (o1 == true);
  2330. bool round = (U == true);
  2331. /* Operation */
  2332. /* CheckFPAdvSIMDEnabled64(); */
  2333. Bits result = new Bits(datasize);
  2334. Bits operand1 = V(2 * datasize, n);
  2335. Bits operand2 = V(2 * datasize, m);
  2336. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  2337. Bits sum;
  2338. Bits element1;
  2339. Bits element2;
  2340. for (int e = 0; e <= elements - 1; e++)
  2341. {
  2342. element1 = Elem(operand1, e, 2 * esize);
  2343. element2 = Elem(operand2, e, 2 * esize);
  2344. if (sub_op)
  2345. {
  2346. sum = element1 - element2;
  2347. }
  2348. else
  2349. {
  2350. sum = element1 + element2;
  2351. }
  2352. sum = sum + round_const;
  2353. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  2354. }
  2355. Vpart(d, part, result);
  2356. }
  2357. // addp_advsimd_vec.html
  2358. public static void Addp_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2359. {
  2360. /* Decode Vector */
  2361. int d = (int)UInt(Rd);
  2362. int n = (int)UInt(Rn);
  2363. int m = (int)UInt(Rm);
  2364. /* if size:Q == '110' then ReservedValue(); */
  2365. int esize = 8 << (int)UInt(size);
  2366. int datasize = (Q ? 128 : 64);
  2367. int elements = datasize / esize;
  2368. /* Operation */
  2369. /* CheckFPAdvSIMDEnabled64(); */
  2370. Bits result = new Bits(datasize);
  2371. Bits operand1 = V(datasize, n);
  2372. Bits operand2 = V(datasize, m);
  2373. Bits concat = Bits.Concat(operand2, operand1);
  2374. Bits element1;
  2375. Bits element2;
  2376. for (int e = 0; e <= elements - 1; e++)
  2377. {
  2378. element1 = Elem(concat, 2 * e, esize);
  2379. element2 = Elem(concat, (2 * e) + 1, esize);
  2380. Elem(result, e, esize, element1 + element2);
  2381. }
  2382. V(d, result);
  2383. }
  2384. // and_advsimd.html
  2385. public static void And_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2386. {
  2387. /* Decode */
  2388. int d = (int)UInt(Rd);
  2389. int n = (int)UInt(Rn);
  2390. int m = (int)UInt(Rm);
  2391. int datasize = (Q ? 128 : 64);
  2392. /* Operation */
  2393. /* CheckFPAdvSIMDEnabled64(); */
  2394. Bits operand1 = V(datasize, n);
  2395. Bits operand2 = V(datasize, m);
  2396. Bits result = AND(operand1, operand2);
  2397. V(d, result);
  2398. }
  2399. // bic_advsimd_reg.html
  2400. public static void Bic_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2401. {
  2402. /* Decode */
  2403. int d = (int)UInt(Rd);
  2404. int n = (int)UInt(Rn);
  2405. int m = (int)UInt(Rm);
  2406. int datasize = (Q ? 128 : 64);
  2407. /* Operation */
  2408. /* CheckFPAdvSIMDEnabled64(); */
  2409. Bits operand1 = V(datasize, n);
  2410. Bits operand2 = V(datasize, m);
  2411. operand2 = NOT(operand2);
  2412. Bits result = AND(operand1, operand2);
  2413. V(d, result);
  2414. }
  2415. // bif_advsimd.html
  2416. public static void Bif_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2417. {
  2418. /* Decode */
  2419. int d = (int)UInt(Rd);
  2420. int n = (int)UInt(Rn);
  2421. int m = (int)UInt(Rm);
  2422. int datasize = (Q ? 128 : 64);
  2423. /* Operation */
  2424. /* CheckFPAdvSIMDEnabled64(); */
  2425. Bits operand1;
  2426. Bits operand3;
  2427. Bits operand4 = V(datasize, n);
  2428. operand1 = V(datasize, d);
  2429. operand3 = NOT(V(datasize, m));
  2430. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2431. }
  2432. // bit_advsimd.html
  2433. public static void Bit_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2434. {
  2435. /* Decode */
  2436. int d = (int)UInt(Rd);
  2437. int n = (int)UInt(Rn);
  2438. int m = (int)UInt(Rm);
  2439. int datasize = (Q ? 128 : 64);
  2440. /* Operation */
  2441. /* CheckFPAdvSIMDEnabled64(); */
  2442. Bits operand1;
  2443. Bits operand3;
  2444. Bits operand4 = V(datasize, n);
  2445. operand1 = V(datasize, d);
  2446. operand3 = V(datasize, m);
  2447. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2448. }
  2449. // bsl_advsimd.html
  2450. public static void Bsl_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2451. {
  2452. /* Decode */
  2453. int d = (int)UInt(Rd);
  2454. int n = (int)UInt(Rn);
  2455. int m = (int)UInt(Rm);
  2456. int datasize = (Q ? 128 : 64);
  2457. /* Operation */
  2458. /* CheckFPAdvSIMDEnabled64(); */
  2459. Bits operand1;
  2460. Bits operand3;
  2461. Bits operand4 = V(datasize, n);
  2462. operand1 = V(datasize, m);
  2463. operand3 = V(datasize, d);
  2464. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  2465. }
  2466. // cmeq_advsimd_reg.html#CMEQ_asisdsame_only
  2467. public static void Cmeq_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2468. {
  2469. const bool U = true;
  2470. /* Decode Scalar */
  2471. int d = (int)UInt(Rd);
  2472. int n = (int)UInt(Rn);
  2473. int m = (int)UInt(Rm);
  2474. /* if size != '11' then ReservedValue(); */
  2475. int esize = 8 << (int)UInt(size);
  2476. int datasize = esize;
  2477. int elements = 1;
  2478. bool and_test = (U == false);
  2479. /* Operation */
  2480. /* CheckFPAdvSIMDEnabled64(); */
  2481. Bits result = new Bits(datasize);
  2482. Bits operand1 = V(datasize, n);
  2483. Bits operand2 = V(datasize, m);
  2484. Bits element1;
  2485. Bits element2;
  2486. bool test_passed;
  2487. for (int e = 0; e <= elements - 1; e++)
  2488. {
  2489. element1 = Elem(operand1, e, esize);
  2490. element2 = Elem(operand2, e, esize);
  2491. if (and_test)
  2492. {
  2493. test_passed = !IsZero(AND(element1, element2));
  2494. }
  2495. else
  2496. {
  2497. test_passed = (element1 == element2);
  2498. }
  2499. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2500. }
  2501. V(d, result);
  2502. }
  2503. // cmeq_advsimd_reg.html#CMEQ_asimdsame_only
  2504. public static void Cmeq_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2505. {
  2506. const bool U = true;
  2507. /* Decode Vector */
  2508. int d = (int)UInt(Rd);
  2509. int n = (int)UInt(Rn);
  2510. int m = (int)UInt(Rm);
  2511. /* if size:Q == '110' then ReservedValue(); */
  2512. int esize = 8 << (int)UInt(size);
  2513. int datasize = (Q ? 128 : 64);
  2514. int elements = datasize / esize;
  2515. bool and_test = (U == false);
  2516. /* Operation */
  2517. /* CheckFPAdvSIMDEnabled64(); */
  2518. Bits result = new Bits(datasize);
  2519. Bits operand1 = V(datasize, n);
  2520. Bits operand2 = V(datasize, m);
  2521. Bits element1;
  2522. Bits element2;
  2523. bool test_passed;
  2524. for (int e = 0; e <= elements - 1; e++)
  2525. {
  2526. element1 = Elem(operand1, e, esize);
  2527. element2 = Elem(operand2, e, esize);
  2528. if (and_test)
  2529. {
  2530. test_passed = !IsZero(AND(element1, element2));
  2531. }
  2532. else
  2533. {
  2534. test_passed = (element1 == element2);
  2535. }
  2536. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2537. }
  2538. V(d, result);
  2539. }
  2540. // cmge_advsimd_reg.html#CMGE_asisdsame_only
  2541. public static void Cmge_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2542. {
  2543. const bool U = false;
  2544. const bool eq = true;
  2545. /* Decode Scalar */
  2546. int d = (int)UInt(Rd);
  2547. int n = (int)UInt(Rn);
  2548. int m = (int)UInt(Rm);
  2549. /* if size != '11' then ReservedValue(); */
  2550. int esize = 8 << (int)UInt(size);
  2551. int datasize = esize;
  2552. int elements = 1;
  2553. bool unsigned = (U == true);
  2554. bool cmp_eq = (eq == true);
  2555. /* Operation */
  2556. /* CheckFPAdvSIMDEnabled64(); */
  2557. Bits result = new Bits(datasize);
  2558. Bits operand1 = V(datasize, n);
  2559. Bits operand2 = V(datasize, m);
  2560. BigInteger element1;
  2561. BigInteger element2;
  2562. bool test_passed;
  2563. for (int e = 0; e <= elements - 1; e++)
  2564. {
  2565. element1 = Int(Elem(operand1, e, esize), unsigned);
  2566. element2 = Int(Elem(operand2, e, esize), unsigned);
  2567. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2568. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2569. }
  2570. V(d, result);
  2571. }
  2572. // cmge_advsimd_reg.html#CMGE_asimdsame_only
  2573. public static void Cmge_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2574. {
  2575. const bool U = false;
  2576. const bool eq = true;
  2577. /* Decode Vector */
  2578. int d = (int)UInt(Rd);
  2579. int n = (int)UInt(Rn);
  2580. int m = (int)UInt(Rm);
  2581. /* if size:Q == '110' then ReservedValue(); */
  2582. int esize = 8 << (int)UInt(size);
  2583. int datasize = (Q ? 128 : 64);
  2584. int elements = datasize / esize;
  2585. bool unsigned = (U == true);
  2586. bool cmp_eq = (eq == true);
  2587. /* Operation */
  2588. /* CheckFPAdvSIMDEnabled64(); */
  2589. Bits result = new Bits(datasize);
  2590. Bits operand1 = V(datasize, n);
  2591. Bits operand2 = V(datasize, m);
  2592. BigInteger element1;
  2593. BigInteger element2;
  2594. bool test_passed;
  2595. for (int e = 0; e <= elements - 1; e++)
  2596. {
  2597. element1 = Int(Elem(operand1, e, esize), unsigned);
  2598. element2 = Int(Elem(operand2, e, esize), unsigned);
  2599. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2600. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2601. }
  2602. V(d, result);
  2603. }
  2604. // cmgt_advsimd_reg.html#CMGT_asisdsame_only
  2605. public static void Cmgt_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2606. {
  2607. const bool U = false;
  2608. const bool eq = false;
  2609. /* Decode Scalar */
  2610. int d = (int)UInt(Rd);
  2611. int n = (int)UInt(Rn);
  2612. int m = (int)UInt(Rm);
  2613. /* if size != '11' then ReservedValue(); */
  2614. int esize = 8 << (int)UInt(size);
  2615. int datasize = esize;
  2616. int elements = 1;
  2617. bool unsigned = (U == true);
  2618. bool cmp_eq = (eq == true);
  2619. /* Operation */
  2620. /* CheckFPAdvSIMDEnabled64(); */
  2621. Bits result = new Bits(datasize);
  2622. Bits operand1 = V(datasize, n);
  2623. Bits operand2 = V(datasize, m);
  2624. BigInteger element1;
  2625. BigInteger element2;
  2626. bool test_passed;
  2627. for (int e = 0; e <= elements - 1; e++)
  2628. {
  2629. element1 = Int(Elem(operand1, e, esize), unsigned);
  2630. element2 = Int(Elem(operand2, e, esize), unsigned);
  2631. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2632. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2633. }
  2634. V(d, result);
  2635. }
  2636. // cmgt_advsimd_reg.html#CMGT_asimdsame_only
  2637. public static void Cmgt_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2638. {
  2639. const bool U = false;
  2640. const bool eq = false;
  2641. /* Decode Vector */
  2642. int d = (int)UInt(Rd);
  2643. int n = (int)UInt(Rn);
  2644. int m = (int)UInt(Rm);
  2645. /* if size:Q == '110' then ReservedValue(); */
  2646. int esize = 8 << (int)UInt(size);
  2647. int datasize = (Q ? 128 : 64);
  2648. int elements = datasize / esize;
  2649. bool unsigned = (U == true);
  2650. bool cmp_eq = (eq == true);
  2651. /* Operation */
  2652. /* CheckFPAdvSIMDEnabled64(); */
  2653. Bits result = new Bits(datasize);
  2654. Bits operand1 = V(datasize, n);
  2655. Bits operand2 = V(datasize, m);
  2656. BigInteger element1;
  2657. BigInteger element2;
  2658. bool test_passed;
  2659. for (int e = 0; e <= elements - 1; e++)
  2660. {
  2661. element1 = Int(Elem(operand1, e, esize), unsigned);
  2662. element2 = Int(Elem(operand2, e, esize), unsigned);
  2663. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2664. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2665. }
  2666. V(d, result);
  2667. }
  2668. // cmhi_advsimd.html#CMHI_asisdsame_only
  2669. public static void Cmhi_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2670. {
  2671. const bool U = true;
  2672. const bool eq = false;
  2673. /* Decode Scalar */
  2674. int d = (int)UInt(Rd);
  2675. int n = (int)UInt(Rn);
  2676. int m = (int)UInt(Rm);
  2677. /* if size != '11' then ReservedValue(); */
  2678. int esize = 8 << (int)UInt(size);
  2679. int datasize = esize;
  2680. int elements = 1;
  2681. bool unsigned = (U == true);
  2682. bool cmp_eq = (eq == true);
  2683. /* Operation */
  2684. /* CheckFPAdvSIMDEnabled64(); */
  2685. Bits result = new Bits(datasize);
  2686. Bits operand1 = V(datasize, n);
  2687. Bits operand2 = V(datasize, m);
  2688. BigInteger element1;
  2689. BigInteger element2;
  2690. bool test_passed;
  2691. for (int e = 0; e <= elements - 1; e++)
  2692. {
  2693. element1 = Int(Elem(operand1, e, esize), unsigned);
  2694. element2 = Int(Elem(operand2, e, esize), unsigned);
  2695. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2696. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2697. }
  2698. V(d, result);
  2699. }
  2700. // cmhi_advsimd.html#CMHI_asimdsame_only
  2701. public static void Cmhi_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2702. {
  2703. const bool U = true;
  2704. const bool eq = false;
  2705. /* Decode Vector */
  2706. int d = (int)UInt(Rd);
  2707. int n = (int)UInt(Rn);
  2708. int m = (int)UInt(Rm);
  2709. /* if size:Q == '110' then ReservedValue(); */
  2710. int esize = 8 << (int)UInt(size);
  2711. int datasize = (Q ? 128 : 64);
  2712. int elements = datasize / esize;
  2713. bool unsigned = (U == true);
  2714. bool cmp_eq = (eq == true);
  2715. /* Operation */
  2716. /* CheckFPAdvSIMDEnabled64(); */
  2717. Bits result = new Bits(datasize);
  2718. Bits operand1 = V(datasize, n);
  2719. Bits operand2 = V(datasize, m);
  2720. BigInteger element1;
  2721. BigInteger element2;
  2722. bool test_passed;
  2723. for (int e = 0; e <= elements - 1; e++)
  2724. {
  2725. element1 = Int(Elem(operand1, e, esize), unsigned);
  2726. element2 = Int(Elem(operand2, e, esize), unsigned);
  2727. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2728. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2729. }
  2730. V(d, result);
  2731. }
  2732. // cmhs_advsimd.html#CMHS_asisdsame_only
  2733. public static void Cmhs_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2734. {
  2735. const bool U = true;
  2736. const bool eq = true;
  2737. /* Decode Scalar */
  2738. int d = (int)UInt(Rd);
  2739. int n = (int)UInt(Rn);
  2740. int m = (int)UInt(Rm);
  2741. /* if size != '11' then ReservedValue(); */
  2742. int esize = 8 << (int)UInt(size);
  2743. int datasize = esize;
  2744. int elements = 1;
  2745. bool unsigned = (U == true);
  2746. bool cmp_eq = (eq == true);
  2747. /* Operation */
  2748. /* CheckFPAdvSIMDEnabled64(); */
  2749. Bits result = new Bits(datasize);
  2750. Bits operand1 = V(datasize, n);
  2751. Bits operand2 = V(datasize, m);
  2752. BigInteger element1;
  2753. BigInteger element2;
  2754. bool test_passed;
  2755. for (int e = 0; e <= elements - 1; e++)
  2756. {
  2757. element1 = Int(Elem(operand1, e, esize), unsigned);
  2758. element2 = Int(Elem(operand2, e, esize), unsigned);
  2759. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2760. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2761. }
  2762. V(d, result);
  2763. }
  2764. // cmhs_advsimd.html#CMHS_asimdsame_only
  2765. public static void Cmhs_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2766. {
  2767. const bool U = true;
  2768. const bool eq = true;
  2769. /* Decode Vector */
  2770. int d = (int)UInt(Rd);
  2771. int n = (int)UInt(Rn);
  2772. int m = (int)UInt(Rm);
  2773. /* if size:Q == '110' then ReservedValue(); */
  2774. int esize = 8 << (int)UInt(size);
  2775. int datasize = (Q ? 128 : 64);
  2776. int elements = datasize / esize;
  2777. bool unsigned = (U == true);
  2778. bool cmp_eq = (eq == true);
  2779. /* Operation */
  2780. /* CheckFPAdvSIMDEnabled64(); */
  2781. Bits result = new Bits(datasize);
  2782. Bits operand1 = V(datasize, n);
  2783. Bits operand2 = V(datasize, m);
  2784. BigInteger element1;
  2785. BigInteger element2;
  2786. bool test_passed;
  2787. for (int e = 0; e <= elements - 1; e++)
  2788. {
  2789. element1 = Int(Elem(operand1, e, esize), unsigned);
  2790. element2 = Int(Elem(operand2, e, esize), unsigned);
  2791. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  2792. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2793. }
  2794. V(d, result);
  2795. }
  2796. // cmtst_advsimd.html#CMTST_asisdsame_only
  2797. public static void Cmtst_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2798. {
  2799. const bool U = false;
  2800. /* Decode Scalar */
  2801. int d = (int)UInt(Rd);
  2802. int n = (int)UInt(Rn);
  2803. int m = (int)UInt(Rm);
  2804. /* if size != '11' then ReservedValue(); */
  2805. int esize = 8 << (int)UInt(size);
  2806. int datasize = esize;
  2807. int elements = 1;
  2808. bool and_test = (U == false);
  2809. /* Operation */
  2810. /* CheckFPAdvSIMDEnabled64(); */
  2811. Bits result = new Bits(datasize);
  2812. Bits operand1 = V(datasize, n);
  2813. Bits operand2 = V(datasize, m);
  2814. Bits element1;
  2815. Bits element2;
  2816. bool test_passed;
  2817. for (int e = 0; e <= elements - 1; e++)
  2818. {
  2819. element1 = Elem(operand1, e, esize);
  2820. element2 = Elem(operand2, e, esize);
  2821. if (and_test)
  2822. {
  2823. test_passed = !IsZero(AND(element1, element2));
  2824. }
  2825. else
  2826. {
  2827. test_passed = (element1 == element2);
  2828. }
  2829. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2830. }
  2831. V(d, result);
  2832. }
  2833. // cmtst_advsimd.html#CMTST_asimdsame_only
  2834. public static void Cmtst_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2835. {
  2836. const bool U = false;
  2837. /* Decode Vector */
  2838. int d = (int)UInt(Rd);
  2839. int n = (int)UInt(Rn);
  2840. int m = (int)UInt(Rm);
  2841. /* if size:Q == '110' then ReservedValue(); */
  2842. int esize = 8 << (int)UInt(size);
  2843. int datasize = (Q ? 128 : 64);
  2844. int elements = datasize / esize;
  2845. bool and_test = (U == false);
  2846. /* Operation */
  2847. /* CheckFPAdvSIMDEnabled64(); */
  2848. Bits result = new Bits(datasize);
  2849. Bits operand1 = V(datasize, n);
  2850. Bits operand2 = V(datasize, m);
  2851. Bits element1;
  2852. Bits element2;
  2853. bool test_passed;
  2854. for (int e = 0; e <= elements - 1; e++)
  2855. {
  2856. element1 = Elem(operand1, e, esize);
  2857. element2 = Elem(operand2, e, esize);
  2858. if (and_test)
  2859. {
  2860. test_passed = !IsZero(AND(element1, element2));
  2861. }
  2862. else
  2863. {
  2864. test_passed = (element1 == element2);
  2865. }
  2866. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2867. }
  2868. V(d, result);
  2869. }
  2870. // eor_advsimd.html
  2871. public static void Eor_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2872. {
  2873. /* Decode */
  2874. int d = (int)UInt(Rd);
  2875. int n = (int)UInt(Rn);
  2876. int m = (int)UInt(Rm);
  2877. int datasize = (Q ? 128 : 64);
  2878. /* Operation */
  2879. /* CheckFPAdvSIMDEnabled64(); */
  2880. Bits operand1 = V(datasize, m);
  2881. Bits operand2 = Zeros(datasize);
  2882. Bits operand3 = Ones(datasize);
  2883. Bits operand4 = V(datasize, n);
  2884. Bits result = EOR(operand1, AND(EOR(operand2, operand4), operand3));
  2885. V(d, result);
  2886. }
  2887. // orn_advsimd.html
  2888. public static void Orn_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2889. {
  2890. /* Decode */
  2891. int d = (int)UInt(Rd);
  2892. int n = (int)UInt(Rn);
  2893. int m = (int)UInt(Rm);
  2894. int datasize = (Q ? 128 : 64);
  2895. /* Operation */
  2896. /* CheckFPAdvSIMDEnabled64(); */
  2897. Bits operand1 = V(datasize, n);
  2898. Bits operand2 = V(datasize, m);
  2899. operand2 = NOT(operand2);
  2900. Bits result = OR(operand1, operand2);
  2901. V(d, result);
  2902. }
  2903. // orr_advsimd_reg.html
  2904. public static void Orr_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2905. {
  2906. /* Decode */
  2907. int d = (int)UInt(Rd);
  2908. int n = (int)UInt(Rn);
  2909. int m = (int)UInt(Rm);
  2910. int datasize = (Q ? 128 : 64);
  2911. /* Operation */
  2912. /* CheckFPAdvSIMDEnabled64(); */
  2913. Bits operand1 = V(datasize, n);
  2914. Bits operand2 = V(datasize, m);
  2915. Bits result = OR(operand1, operand2);
  2916. V(d, result);
  2917. }
  2918. // raddhn_advsimd.html
  2919. public static void Raddhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2920. {
  2921. const bool U = true;
  2922. const bool o1 = false;
  2923. /* Decode */
  2924. int d = (int)UInt(Rd);
  2925. int n = (int)UInt(Rn);
  2926. int m = (int)UInt(Rm);
  2927. /* if size == '11' then ReservedValue(); */
  2928. int esize = 8 << (int)UInt(size);
  2929. int datasize = 64;
  2930. int part = (int)UInt(Q);
  2931. int elements = datasize / esize;
  2932. bool sub_op = (o1 == true);
  2933. bool round = (U == true);
  2934. /* Operation */
  2935. /* CheckFPAdvSIMDEnabled64(); */
  2936. Bits result = new Bits(datasize);
  2937. Bits operand1 = V(2 * datasize, n);
  2938. Bits operand2 = V(2 * datasize, m);
  2939. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  2940. Bits sum;
  2941. Bits element1;
  2942. Bits element2;
  2943. for (int e = 0; e <= elements - 1; e++)
  2944. {
  2945. element1 = Elem(operand1, e, 2 * esize);
  2946. element2 = Elem(operand2, e, 2 * esize);
  2947. if (sub_op)
  2948. {
  2949. sum = element1 - element2;
  2950. }
  2951. else
  2952. {
  2953. sum = element1 + element2;
  2954. }
  2955. sum = sum + round_const;
  2956. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  2957. }
  2958. Vpart(d, part, result);
  2959. }
  2960. // rsubhn_advsimd.html
  2961. public static void Rsubhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2962. {
  2963. const bool U = true;
  2964. const bool o1 = true;
  2965. /* Decode */
  2966. int d = (int)UInt(Rd);
  2967. int n = (int)UInt(Rn);
  2968. int m = (int)UInt(Rm);
  2969. /* if size == '11' then ReservedValue(); */
  2970. int esize = 8 << (int)UInt(size);
  2971. int datasize = 64;
  2972. int part = (int)UInt(Q);
  2973. int elements = datasize / esize;
  2974. bool sub_op = (o1 == true);
  2975. bool round = (U == true);
  2976. /* Operation */
  2977. /* CheckFPAdvSIMDEnabled64(); */
  2978. Bits result = new Bits(datasize);
  2979. Bits operand1 = V(2 * datasize, n);
  2980. Bits operand2 = V(2 * datasize, m);
  2981. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  2982. Bits sum;
  2983. Bits element1;
  2984. Bits element2;
  2985. for (int e = 0; e <= elements - 1; e++)
  2986. {
  2987. element1 = Elem(operand1, e, 2 * esize);
  2988. element2 = Elem(operand2, e, 2 * esize);
  2989. if (sub_op)
  2990. {
  2991. sum = element1 - element2;
  2992. }
  2993. else
  2994. {
  2995. sum = element1 + element2;
  2996. }
  2997. sum = sum + round_const;
  2998. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  2999. }
  3000. Vpart(d, part, result);
  3001. }
  3002. // sub_advsimd.html#SUB_asisdsame_only
  3003. public static void Sub_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3004. {
  3005. const bool U = true;
  3006. /* Decode Scalar */
  3007. int d = (int)UInt(Rd);
  3008. int n = (int)UInt(Rn);
  3009. int m = (int)UInt(Rm);
  3010. /* if size != '11' then ReservedValue(); */
  3011. int esize = 8 << (int)UInt(size);
  3012. int datasize = esize;
  3013. int elements = 1;
  3014. bool sub_op = (U == true);
  3015. /* Operation */
  3016. /* CheckFPAdvSIMDEnabled64(); */
  3017. Bits result = new Bits(datasize);
  3018. Bits operand1 = V(datasize, n);
  3019. Bits operand2 = V(datasize, m);
  3020. Bits element1;
  3021. Bits element2;
  3022. for (int e = 0; e <= elements - 1; e++)
  3023. {
  3024. element1 = Elem(operand1, e, esize);
  3025. element2 = Elem(operand2, e, esize);
  3026. if (sub_op)
  3027. {
  3028. Elem(result, e, esize, element1 - element2);
  3029. }
  3030. else
  3031. {
  3032. Elem(result, e, esize, element1 + element2);
  3033. }
  3034. }
  3035. V(d, result);
  3036. }
  3037. // sub_advsimd.html#SUB_asimdsame_only
  3038. public static void Sub_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3039. {
  3040. const bool U = true;
  3041. /* Decode Vector */
  3042. int d = (int)UInt(Rd);
  3043. int n = (int)UInt(Rn);
  3044. int m = (int)UInt(Rm);
  3045. /* if size:Q == '110' then ReservedValue(); */
  3046. int esize = 8 << (int)UInt(size);
  3047. int datasize = (Q ? 128 : 64);
  3048. int elements = datasize / esize;
  3049. bool sub_op = (U == true);
  3050. /* Operation */
  3051. /* CheckFPAdvSIMDEnabled64(); */
  3052. Bits result = new Bits(datasize);
  3053. Bits operand1 = V(datasize, n);
  3054. Bits operand2 = V(datasize, m);
  3055. Bits element1;
  3056. Bits element2;
  3057. for (int e = 0; e <= elements - 1; e++)
  3058. {
  3059. element1 = Elem(operand1, e, esize);
  3060. element2 = Elem(operand2, e, esize);
  3061. if (sub_op)
  3062. {
  3063. Elem(result, e, esize, element1 - element2);
  3064. }
  3065. else
  3066. {
  3067. Elem(result, e, esize, element1 + element2);
  3068. }
  3069. }
  3070. V(d, result);
  3071. }
  3072. // subhn_advsimd.html
  3073. public static void Subhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3074. {
  3075. const bool U = false;
  3076. const bool o1 = true;
  3077. /* Decode */
  3078. int d = (int)UInt(Rd);
  3079. int n = (int)UInt(Rn);
  3080. int m = (int)UInt(Rm);
  3081. /* if size == '11' then ReservedValue(); */
  3082. int esize = 8 << (int)UInt(size);
  3083. int datasize = 64;
  3084. int part = (int)UInt(Q);
  3085. int elements = datasize / esize;
  3086. bool sub_op = (o1 == true);
  3087. bool round = (U == true);
  3088. /* Operation */
  3089. /* CheckFPAdvSIMDEnabled64(); */
  3090. Bits result = new Bits(datasize);
  3091. Bits operand1 = V(2 * datasize, n);
  3092. Bits operand2 = V(2 * datasize, m);
  3093. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3094. Bits sum;
  3095. Bits element1;
  3096. Bits element2;
  3097. for (int e = 0; e <= elements - 1; e++)
  3098. {
  3099. element1 = Elem(operand1, e, 2 * esize);
  3100. element2 = Elem(operand2, e, 2 * esize);
  3101. if (sub_op)
  3102. {
  3103. sum = element1 - element2;
  3104. }
  3105. else
  3106. {
  3107. sum = element1 + element2;
  3108. }
  3109. sum = sum + round_const;
  3110. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3111. }
  3112. Vpart(d, part, result);
  3113. }
  3114. #endregion
  3115. }
  3116. }