Instructions.cs 173 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056
  1. // https://github.com/LDj3SNuD/ARM_v8-A_AArch64_Instructions_Tester/blob/master/Tester/Instructions.cs
  2. // https://developer.arm.com/products/architecture/a-profile/exploration-tools
  3. // ..\A64_v83A_ISA_xml_00bet6.1\ISA_v83A_A64_xml_00bet6.1_OPT\xhtml\
  4. using System.Numerics;
  5. namespace Ryujinx.Tests.Cpu.Tester
  6. {
  7. using Types;
  8. using static AArch64;
  9. using static Shared;
  10. // index.html
  11. internal static class Base
  12. {
  13. #region "Alu"
  14. // cls_int.html
  15. public static void Cls(bool sf, Bits Rn, Bits Rd)
  16. {
  17. /* Decode */
  18. int d = (int)UInt(Rd);
  19. int n = (int)UInt(Rn);
  20. int datasize = (sf ? 64 : 32);
  21. /* Operation */
  22. Bits operand1 = X(datasize, n);
  23. BigInteger result = (BigInteger)CountLeadingSignBits(operand1);
  24. X(d, result.SubBigInteger(datasize - 1, 0));
  25. }
  26. // clz_int.html
  27. public static void Clz(bool sf, Bits Rn, Bits Rd)
  28. {
  29. /* Decode */
  30. int d = (int)UInt(Rd);
  31. int n = (int)UInt(Rn);
  32. int datasize = (sf ? 64 : 32);
  33. /* Operation */
  34. Bits operand1 = X(datasize, n);
  35. BigInteger result = (BigInteger)CountLeadingZeroBits(operand1);
  36. X(d, result.SubBigInteger(datasize - 1, 0));
  37. }
  38. // rbit_int.html
  39. public static void Rbit(bool sf, Bits Rn, Bits Rd)
  40. {
  41. /* Decode */
  42. int d = (int)UInt(Rd);
  43. int n = (int)UInt(Rn);
  44. int datasize = (sf ? 64 : 32);
  45. /* Operation */
  46. Bits result = new Bits(datasize);
  47. Bits operand = X(datasize, n);
  48. for (int i = 0; i <= datasize - 1; i++)
  49. {
  50. result[datasize - 1 - i] = operand[i];
  51. }
  52. X(d, result);
  53. }
  54. // rev16_int.html
  55. public static void Rev16(bool sf, Bits Rn, Bits Rd)
  56. {
  57. /* Bits opc = "01"; */
  58. /* Decode */
  59. int d = (int)UInt(Rd);
  60. int n = (int)UInt(Rn);
  61. int datasize = (sf ? 64 : 32);
  62. int container_size = 16;
  63. /* Operation */
  64. Bits result = new Bits(datasize);
  65. Bits operand = X(datasize, n);
  66. int containers = datasize / container_size;
  67. int elements_per_container = container_size / 8;
  68. int index = 0;
  69. int rev_index;
  70. for (int c = 0; c <= containers - 1; c++)
  71. {
  72. rev_index = index + ((elements_per_container - 1) * 8);
  73. for (int e = 0; e <= elements_per_container - 1; e++)
  74. {
  75. result[rev_index + 7, rev_index] = operand[index + 7, index];
  76. index = index + 8;
  77. rev_index = rev_index - 8;
  78. }
  79. }
  80. X(d, result);
  81. }
  82. // rev32_int.html
  83. // (rev.html)
  84. public static void Rev32(bool sf, Bits Rn, Bits Rd)
  85. {
  86. /* Bits opc = "10"; */
  87. /* Decode */
  88. int d = (int)UInt(Rd);
  89. int n = (int)UInt(Rn);
  90. int datasize = (sf ? 64 : 32);
  91. int container_size = 32;
  92. /* Operation */
  93. Bits result = new Bits(datasize);
  94. Bits operand = X(datasize, n);
  95. int containers = datasize / container_size;
  96. int elements_per_container = container_size / 8;
  97. int index = 0;
  98. int rev_index;
  99. for (int c = 0; c <= containers - 1; c++)
  100. {
  101. rev_index = index + ((elements_per_container - 1) * 8);
  102. for (int e = 0; e <= elements_per_container - 1; e++)
  103. {
  104. result[rev_index + 7, rev_index] = operand[index + 7, index];
  105. index = index + 8;
  106. rev_index = rev_index - 8;
  107. }
  108. }
  109. X(d, result);
  110. }
  111. // rev64_rev.html
  112. // (rev.html)
  113. public static void Rev64(Bits Rn, Bits Rd)
  114. {
  115. /* Bits opc = "11"; */
  116. /* Decode */
  117. int d = (int)UInt(Rd);
  118. int n = (int)UInt(Rn);
  119. int container_size = 64;
  120. /* Operation */
  121. Bits result = new Bits(64);
  122. Bits operand = X(64, n);
  123. int containers = 64 / container_size;
  124. int elements_per_container = container_size / 8;
  125. int index = 0;
  126. int rev_index;
  127. for (int c = 0; c <= containers - 1; c++)
  128. {
  129. rev_index = index + ((elements_per_container - 1) * 8);
  130. for (int e = 0; e <= elements_per_container - 1; e++)
  131. {
  132. result[rev_index + 7, rev_index] = operand[index + 7, index];
  133. index = index + 8;
  134. rev_index = rev_index - 8;
  135. }
  136. }
  137. X(d, result);
  138. }
  139. #endregion
  140. #region "AluImm"
  141. // add_addsub_imm.html
  142. public static void Add_Imm(bool sf, Bits shift, Bits imm12, Bits Rn, Bits Rd)
  143. {
  144. /* Decode */
  145. int d = (int)UInt(Rd);
  146. int n = (int)UInt(Rn);
  147. int datasize = (sf ? 64 : 32);
  148. Bits imm;
  149. switch (shift)
  150. {
  151. default:
  152. case Bits bits when bits == "00":
  153. imm = ZeroExtend(imm12, datasize);
  154. break;
  155. case Bits bits when bits == "01":
  156. imm = ZeroExtend(Bits.Concat(imm12, Zeros(12)), datasize);
  157. break;
  158. /* when '1x' ReservedValue(); */
  159. }
  160. /* Operation */
  161. Bits result;
  162. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  163. (result, _) = AddWithCarry(datasize, operand1, imm, false);
  164. if (d == 31)
  165. {
  166. SP(result);
  167. }
  168. else
  169. {
  170. X(d, result);
  171. }
  172. }
  173. // adds_addsub_imm.html
  174. public static void Adds_Imm(bool sf, Bits shift, Bits imm12, Bits Rn, Bits Rd)
  175. {
  176. /* Decode */
  177. int d = (int)UInt(Rd);
  178. int n = (int)UInt(Rn);
  179. int datasize = (sf ? 64 : 32);
  180. Bits imm;
  181. switch (shift)
  182. {
  183. default:
  184. case Bits bits when bits == "00":
  185. imm = ZeroExtend(imm12, datasize);
  186. break;
  187. case Bits bits when bits == "01":
  188. imm = ZeroExtend(Bits.Concat(imm12, Zeros(12)), datasize);
  189. break;
  190. /* when '1x' ReservedValue(); */
  191. }
  192. /* Operation */
  193. Bits result;
  194. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  195. Bits nzcv;
  196. (result, nzcv) = AddWithCarry(datasize, operand1, imm, false);
  197. PSTATE.NZCV(nzcv);
  198. X(d, result);
  199. }
  200. // and_log_imm.html
  201. public static void And_Imm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  202. {
  203. /* Decode */
  204. int d = (int)UInt(Rd);
  205. int n = (int)UInt(Rn);
  206. int datasize = (sf ? 64 : 32);
  207. Bits imm;
  208. /* if sf == '0' && N != '0' then ReservedValue(); */
  209. (imm, _) = DecodeBitMasks(datasize, N, imms, immr, true);
  210. /* Operation */
  211. Bits operand1 = X(datasize, n);
  212. Bits result = AND(operand1, imm);
  213. if (d == 31)
  214. {
  215. SP(result);
  216. }
  217. else
  218. {
  219. X(d, result);
  220. }
  221. }
  222. // ands_log_imm.html
  223. public static void Ands_Imm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  224. {
  225. /* Decode */
  226. int d = (int)UInt(Rd);
  227. int n = (int)UInt(Rn);
  228. int datasize = (sf ? 64 : 32);
  229. Bits imm;
  230. /* if sf == '0' && N != '0' then ReservedValue(); */
  231. (imm, _) = DecodeBitMasks(datasize, N, imms, immr, true);
  232. /* Operation */
  233. Bits operand1 = X(datasize, n);
  234. Bits result = AND(operand1, imm);
  235. PSTATE.NZCV(result[datasize - 1], IsZeroBit(result), false, false);
  236. X(d, result);
  237. }
  238. // eor_log_imm.html
  239. public static void Eor_Imm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  240. {
  241. /* Decode */
  242. int d = (int)UInt(Rd);
  243. int n = (int)UInt(Rn);
  244. int datasize = (sf ? 64 : 32);
  245. Bits imm;
  246. /* if sf == '0' && N != '0' then ReservedValue(); */
  247. (imm, _) = DecodeBitMasks(datasize, N, imms, immr, true);
  248. /* Operation */
  249. Bits operand1 = X(datasize, n);
  250. Bits result = EOR(operand1, imm);
  251. if (d == 31)
  252. {
  253. SP(result);
  254. }
  255. else
  256. {
  257. X(d, result);
  258. }
  259. }
  260. // orr_log_imm.html
  261. public static void Orr_Imm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  262. {
  263. /* Decode */
  264. int d = (int)UInt(Rd);
  265. int n = (int)UInt(Rn);
  266. int datasize = (sf ? 64 : 32);
  267. Bits imm;
  268. /* if sf == '0' && N != '0' then ReservedValue(); */
  269. (imm, _) = DecodeBitMasks(datasize, N, imms, immr, true);
  270. /* Operation */
  271. Bits operand1 = X(datasize, n);
  272. Bits result = OR(operand1, imm);
  273. if (d == 31)
  274. {
  275. SP(result);
  276. }
  277. else
  278. {
  279. X(d, result);
  280. }
  281. }
  282. // sub_addsub_imm.html
  283. public static void Sub_Imm(bool sf, Bits shift, Bits imm12, Bits Rn, Bits Rd)
  284. {
  285. /* Decode */
  286. int d = (int)UInt(Rd);
  287. int n = (int)UInt(Rn);
  288. int datasize = (sf ? 64 : 32);
  289. Bits imm;
  290. switch (shift)
  291. {
  292. default:
  293. case Bits bits when bits == "00":
  294. imm = ZeroExtend(imm12, datasize);
  295. break;
  296. case Bits bits when bits == "01":
  297. imm = ZeroExtend(Bits.Concat(imm12, Zeros(12)), datasize);
  298. break;
  299. /* when '1x' ReservedValue(); */
  300. }
  301. /* Operation */
  302. Bits result;
  303. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  304. Bits operand2 = NOT(imm);
  305. (result, _) = AddWithCarry(datasize, operand1, operand2, true);
  306. if (d == 31)
  307. {
  308. SP(result);
  309. }
  310. else
  311. {
  312. X(d, result);
  313. }
  314. }
  315. // subs_addsub_imm.html
  316. public static void Subs_Imm(bool sf, Bits shift, Bits imm12, Bits Rn, Bits Rd)
  317. {
  318. /* Decode */
  319. int d = (int)UInt(Rd);
  320. int n = (int)UInt(Rn);
  321. int datasize = (sf ? 64 : 32);
  322. Bits imm;
  323. switch (shift)
  324. {
  325. default:
  326. case Bits bits when bits == "00":
  327. imm = ZeroExtend(imm12, datasize);
  328. break;
  329. case Bits bits when bits == "01":
  330. imm = ZeroExtend(Bits.Concat(imm12, Zeros(12)), datasize);
  331. break;
  332. /* when '1x' ReservedValue(); */
  333. }
  334. /* Operation */
  335. Bits result;
  336. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  337. Bits operand2 = NOT(imm);
  338. Bits nzcv;
  339. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, true);
  340. PSTATE.NZCV(nzcv);
  341. X(d, result);
  342. }
  343. #endregion
  344. #region "AluRs"
  345. // adc.html
  346. public static void Adc(bool sf, Bits Rm, Bits Rn, Bits Rd)
  347. {
  348. /* Decode */
  349. int d = (int)UInt(Rd);
  350. int n = (int)UInt(Rn);
  351. int m = (int)UInt(Rm);
  352. int datasize = (sf ? 64 : 32);
  353. /* Operation */
  354. Bits result;
  355. Bits operand1 = X(datasize, n);
  356. Bits operand2 = X(datasize, m);
  357. (result, _) = AddWithCarry(datasize, operand1, operand2, PSTATE.C);
  358. X(d, result);
  359. }
  360. // adcs.html
  361. public static void Adcs(bool sf, Bits Rm, Bits Rn, Bits Rd)
  362. {
  363. /* Decode */
  364. int d = (int)UInt(Rd);
  365. int n = (int)UInt(Rn);
  366. int m = (int)UInt(Rm);
  367. int datasize = (sf ? 64 : 32);
  368. /* Operation */
  369. Bits result;
  370. Bits operand1 = X(datasize, n);
  371. Bits operand2 = X(datasize, m);
  372. Bits nzcv;
  373. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, PSTATE.C);
  374. PSTATE.NZCV(nzcv);
  375. X(d, result);
  376. }
  377. // add_addsub_shift.html
  378. public static void Add_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  379. {
  380. /* Decode */
  381. int d = (int)UInt(Rd);
  382. int n = (int)UInt(Rn);
  383. int m = (int)UInt(Rm);
  384. int datasize = (sf ? 64 : 32);
  385. /* if shift == '11' then ReservedValue(); */
  386. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  387. ShiftType shift_type = DecodeShift(shift);
  388. int shift_amount = (int)UInt(imm6);
  389. /* Operation */
  390. Bits result;
  391. Bits operand1 = X(datasize, n);
  392. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  393. (result, _) = AddWithCarry(datasize, operand1, operand2, false);
  394. X(d, result);
  395. }
  396. // adds_addsub_shift.html
  397. public static void Adds_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  398. {
  399. /* Decode */
  400. int d = (int)UInt(Rd);
  401. int n = (int)UInt(Rn);
  402. int m = (int)UInt(Rm);
  403. int datasize = (sf ? 64 : 32);
  404. /* if shift == '11' then ReservedValue(); */
  405. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  406. ShiftType shift_type = DecodeShift(shift);
  407. int shift_amount = (int)UInt(imm6);
  408. /* Operation */
  409. Bits result;
  410. Bits operand1 = X(datasize, n);
  411. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  412. Bits nzcv;
  413. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, false);
  414. PSTATE.NZCV(nzcv);
  415. X(d, result);
  416. }
  417. // and_log_shift.html
  418. public static void And_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  419. {
  420. /* Decode */
  421. int d = (int)UInt(Rd);
  422. int n = (int)UInt(Rn);
  423. int m = (int)UInt(Rm);
  424. int datasize = (sf ? 64 : 32);
  425. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  426. ShiftType shift_type = DecodeShift(shift);
  427. int shift_amount = (int)UInt(imm6);
  428. /* Operation */
  429. Bits operand1 = X(datasize, n);
  430. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  431. Bits result = AND(operand1, operand2);
  432. X(d, result);
  433. }
  434. // ands_log_shift.html
  435. public static void Ands_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  436. {
  437. /* Decode */
  438. int d = (int)UInt(Rd);
  439. int n = (int)UInt(Rn);
  440. int m = (int)UInt(Rm);
  441. int datasize = (sf ? 64 : 32);
  442. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  443. ShiftType shift_type = DecodeShift(shift);
  444. int shift_amount = (int)UInt(imm6);
  445. /* Operation */
  446. Bits operand1 = X(datasize, n);
  447. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  448. Bits result = AND(operand1, operand2);
  449. PSTATE.NZCV(result[datasize - 1], IsZeroBit(result), false, false);
  450. X(d, result);
  451. }
  452. // asrv.html
  453. public static void Asrv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  454. {
  455. /*readonly */Bits op2 = "10";
  456. /* Decode */
  457. int d = (int)UInt(Rd);
  458. int n = (int)UInt(Rn);
  459. int m = (int)UInt(Rm);
  460. int datasize = (sf ? 64 : 32);
  461. ShiftType shift_type = DecodeShift(op2);
  462. /* Operation */
  463. Bits operand2 = X(datasize, m);
  464. Bits result = ShiftReg(datasize, n, shift_type, (int)(UInt(operand2) % datasize)); // BigInteger.Modulus Operator (BigInteger, BigInteger)
  465. X(d, result);
  466. }
  467. // bic_log_shift.html
  468. public static void Bic(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  469. {
  470. /* Decode */
  471. int d = (int)UInt(Rd);
  472. int n = (int)UInt(Rn);
  473. int m = (int)UInt(Rm);
  474. int datasize = (sf ? 64 : 32);
  475. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  476. ShiftType shift_type = DecodeShift(shift);
  477. int shift_amount = (int)UInt(imm6);
  478. /* Operation */
  479. Bits operand1 = X(datasize, n);
  480. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  481. operand2 = NOT(operand2);
  482. Bits result = AND(operand1, operand2);
  483. X(d, result);
  484. }
  485. // bics.html
  486. public static void Bics(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  487. {
  488. /* Decode */
  489. int d = (int)UInt(Rd);
  490. int n = (int)UInt(Rn);
  491. int m = (int)UInt(Rm);
  492. int datasize = (sf ? 64 : 32);
  493. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  494. ShiftType shift_type = DecodeShift(shift);
  495. int shift_amount = (int)UInt(imm6);
  496. /* Operation */
  497. Bits operand1 = X(datasize, n);
  498. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  499. operand2 = NOT(operand2);
  500. Bits result = AND(operand1, operand2);
  501. PSTATE.NZCV(result[datasize - 1], IsZeroBit(result), false, false);
  502. X(d, result);
  503. }
  504. // crc32.html
  505. public static void Crc32(bool sf, Bits Rm, Bits sz, Bits Rn, Bits Rd)
  506. {
  507. /* Decode */
  508. int d = (int)UInt(Rd);
  509. int n = (int)UInt(Rn);
  510. int m = (int)UInt(Rm);
  511. /* if sf == '1' && sz != '11' then UnallocatedEncoding(); */
  512. /* if sf == '0' && sz == '11' then UnallocatedEncoding(); */
  513. int size = 8 << (int)UInt(sz);
  514. /* Operation */
  515. /* if !HaveCRCExt() then UnallocatedEncoding(); */
  516. Bits acc = X(32, n); // accumulator
  517. Bits val = X(size, m); // input value
  518. Bits poly = new Bits(0x04C11DB7u);
  519. Bits tempacc = Bits.Concat(BitReverse(acc), Zeros(size));
  520. Bits tempval = Bits.Concat(BitReverse(val), Zeros(32));
  521. // Poly32Mod2 on a bitstring does a polynomial Modulus over {0,1} operation
  522. X(d, BitReverse(Poly32Mod2(EOR(tempacc, tempval), poly)));
  523. }
  524. // crc32c.html
  525. public static void Crc32c(bool sf, Bits Rm, Bits sz, Bits Rn, Bits Rd)
  526. {
  527. /* Decode */
  528. int d = (int)UInt(Rd);
  529. int n = (int)UInt(Rn);
  530. int m = (int)UInt(Rm);
  531. /* if sf == '1' && sz != '11' then UnallocatedEncoding(); */
  532. /* if sf == '0' && sz == '11' then UnallocatedEncoding(); */
  533. int size = 8 << (int)UInt(sz);
  534. /* Operation */
  535. /* if !HaveCRCExt() then UnallocatedEncoding(); */
  536. Bits acc = X(32, n); // accumulator
  537. Bits val = X(size, m); // input value
  538. Bits poly = new Bits(0x1EDC6F41u);
  539. Bits tempacc = Bits.Concat(BitReverse(acc), Zeros(size));
  540. Bits tempval = Bits.Concat(BitReverse(val), Zeros(32));
  541. // Poly32Mod2 on a bitstring does a polynomial Modulus over {0,1} operation
  542. X(d, BitReverse(Poly32Mod2(EOR(tempacc, tempval), poly)));
  543. }
  544. // eon.html
  545. public static void Eon(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  546. {
  547. /* Decode */
  548. int d = (int)UInt(Rd);
  549. int n = (int)UInt(Rn);
  550. int m = (int)UInt(Rm);
  551. int datasize = (sf ? 64 : 32);
  552. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  553. ShiftType shift_type = DecodeShift(shift);
  554. int shift_amount = (int)UInt(imm6);
  555. /* Operation */
  556. Bits operand1 = X(datasize, n);
  557. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  558. operand2 = NOT(operand2);
  559. Bits result = EOR(operand1, operand2);
  560. X(d, result);
  561. }
  562. // eor_log_shift.html
  563. public static void Eor_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  564. {
  565. /* Decode */
  566. int d = (int)UInt(Rd);
  567. int n = (int)UInt(Rn);
  568. int m = (int)UInt(Rm);
  569. int datasize = (sf ? 64 : 32);
  570. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  571. ShiftType shift_type = DecodeShift(shift);
  572. int shift_amount = (int)UInt(imm6);
  573. /* Operation */
  574. Bits operand1 = X(datasize, n);
  575. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  576. Bits result = EOR(operand1, operand2);
  577. X(d, result);
  578. }
  579. // extr.html
  580. public static void Extr(bool sf, bool N, Bits Rm, Bits imms, Bits Rn, Bits Rd)
  581. {
  582. /* Decode */
  583. int d = (int)UInt(Rd);
  584. int n = (int)UInt(Rn);
  585. int m = (int)UInt(Rm);
  586. int datasize = (sf ? 64 : 32);
  587. /* if N != sf then UnallocatedEncoding(); */
  588. /* if sf == '0' && imms<5> == '1' then ReservedValue(); */
  589. int lsb = (int)UInt(imms);
  590. /* Operation */
  591. Bits operand1 = X(datasize, n);
  592. Bits operand2 = X(datasize, m);
  593. Bits concat = Bits.Concat(operand1, operand2);
  594. Bits result = concat[lsb + datasize - 1, lsb];
  595. X(d, result);
  596. }
  597. // lslv.html
  598. public static void Lslv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  599. {
  600. /*readonly */Bits op2 = "00";
  601. /* Decode */
  602. int d = (int)UInt(Rd);
  603. int n = (int)UInt(Rn);
  604. int m = (int)UInt(Rm);
  605. int datasize = (sf ? 64 : 32);
  606. ShiftType shift_type = DecodeShift(op2);
  607. /* Operation */
  608. Bits operand2 = X(datasize, m);
  609. Bits result = ShiftReg(datasize, n, shift_type, (int)(UInt(operand2) % datasize)); // BigInteger.Modulus Operator (BigInteger, BigInteger)
  610. X(d, result);
  611. }
  612. // lsrv.html
  613. public static void Lsrv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  614. {
  615. /*readonly */Bits op2 = "01";
  616. /* Decode */
  617. int d = (int)UInt(Rd);
  618. int n = (int)UInt(Rn);
  619. int m = (int)UInt(Rm);
  620. int datasize = (sf ? 64 : 32);
  621. ShiftType shift_type = DecodeShift(op2);
  622. /* Operation */
  623. Bits operand2 = X(datasize, m);
  624. Bits result = ShiftReg(datasize, n, shift_type, (int)(UInt(operand2) % datasize)); // BigInteger.Modulus Operator (BigInteger, BigInteger)
  625. X(d, result);
  626. }
  627. // orn_log_shift.html
  628. public static void Orn(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  629. {
  630. /* Decode */
  631. int d = (int)UInt(Rd);
  632. int n = (int)UInt(Rn);
  633. int m = (int)UInt(Rm);
  634. int datasize = (sf ? 64 : 32);
  635. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  636. ShiftType shift_type = DecodeShift(shift);
  637. int shift_amount = (int)UInt(imm6);
  638. /* Operation */
  639. Bits operand1 = X(datasize, n);
  640. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  641. operand2 = NOT(operand2);
  642. Bits result = OR(operand1, operand2);
  643. X(d, result);
  644. }
  645. // orr_log_shift.html
  646. public static void Orr_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  647. {
  648. /* Decode */
  649. int d = (int)UInt(Rd);
  650. int n = (int)UInt(Rn);
  651. int m = (int)UInt(Rm);
  652. int datasize = (sf ? 64 : 32);
  653. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  654. ShiftType shift_type = DecodeShift(shift);
  655. int shift_amount = (int)UInt(imm6);
  656. /* Operation */
  657. Bits operand1 = X(datasize, n);
  658. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  659. Bits result = OR(operand1, operand2);
  660. X(d, result);
  661. }
  662. // rorv.html
  663. public static void Rorv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  664. {
  665. /*readonly */Bits op2 = "11";
  666. /* Decode */
  667. int d = (int)UInt(Rd);
  668. int n = (int)UInt(Rn);
  669. int m = (int)UInt(Rm);
  670. int datasize = (sf ? 64 : 32);
  671. ShiftType shift_type = DecodeShift(op2);
  672. /* Operation */
  673. Bits operand2 = X(datasize, m);
  674. Bits result = ShiftReg(datasize, n, shift_type, (int)(UInt(operand2) % datasize)); // BigInteger.Modulus Operator (BigInteger, BigInteger)
  675. X(d, result);
  676. }
  677. // sbc.html
  678. public static void Sbc(bool sf, Bits Rm, Bits Rn, Bits Rd)
  679. {
  680. /* Decode */
  681. int d = (int)UInt(Rd);
  682. int n = (int)UInt(Rn);
  683. int m = (int)UInt(Rm);
  684. int datasize = (sf ? 64 : 32);
  685. /* Operation */
  686. Bits result;
  687. Bits operand1 = X(datasize, n);
  688. Bits operand2 = X(datasize, m);
  689. operand2 = NOT(operand2);
  690. (result, _) = AddWithCarry(datasize, operand1, operand2, PSTATE.C);
  691. X(d, result);
  692. }
  693. // sbcs.html
  694. public static void Sbcs(bool sf, Bits Rm, Bits Rn, Bits Rd)
  695. {
  696. /* Decode */
  697. int d = (int)UInt(Rd);
  698. int n = (int)UInt(Rn);
  699. int m = (int)UInt(Rm);
  700. int datasize = (sf ? 64 : 32);
  701. /* Operation */
  702. Bits result;
  703. Bits operand1 = X(datasize, n);
  704. Bits operand2 = X(datasize, m);
  705. Bits nzcv;
  706. operand2 = NOT(operand2);
  707. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, PSTATE.C);
  708. PSTATE.NZCV(nzcv);
  709. X(d, result);
  710. }
  711. // sdiv.html
  712. public static void Sdiv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  713. {
  714. /* Decode */
  715. int d = (int)UInt(Rd);
  716. int n = (int)UInt(Rn);
  717. int m = (int)UInt(Rm);
  718. int datasize = (sf ? 64 : 32);
  719. /* Operation */
  720. BigInteger result;
  721. Bits operand1 = X(datasize, n);
  722. Bits operand2 = X(datasize, m);
  723. if (IsZero(operand2))
  724. {
  725. result = (BigInteger)0m;
  726. }
  727. else
  728. {
  729. result = RoundTowardsZero(Real(Int(operand1, false)) / Real(Int(operand2, false)));
  730. }
  731. X(d, result.SubBigInteger(datasize - 1, 0));
  732. }
  733. // sub_addsub_shift.html
  734. public static void Sub_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  735. {
  736. /* Decode */
  737. int d = (int)UInt(Rd);
  738. int n = (int)UInt(Rn);
  739. int m = (int)UInt(Rm);
  740. int datasize = (sf ? 64 : 32);
  741. /* if shift == '11' then ReservedValue(); */
  742. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  743. ShiftType shift_type = DecodeShift(shift);
  744. int shift_amount = (int)UInt(imm6);
  745. /* Operation */
  746. Bits result;
  747. Bits operand1 = X(datasize, n);
  748. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  749. operand2 = NOT(operand2);
  750. (result, _) = AddWithCarry(datasize, operand1, operand2, true);
  751. X(d, result);
  752. }
  753. // subs_addsub_shift.html
  754. public static void Subs_Rs(bool sf, Bits shift, Bits Rm, Bits imm6, Bits Rn, Bits Rd)
  755. {
  756. /* Decode */
  757. int d = (int)UInt(Rd);
  758. int n = (int)UInt(Rn);
  759. int m = (int)UInt(Rm);
  760. int datasize = (sf ? 64 : 32);
  761. /* if shift == '11' then ReservedValue(); */
  762. /* if sf == '0' && imm6<5> == '1' then ReservedValue(); */
  763. ShiftType shift_type = DecodeShift(shift);
  764. int shift_amount = (int)UInt(imm6);
  765. /* Operation */
  766. Bits result;
  767. Bits operand1 = X(datasize, n);
  768. Bits operand2 = ShiftReg(datasize, m, shift_type, shift_amount);
  769. Bits nzcv;
  770. operand2 = NOT(operand2);
  771. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, true);
  772. PSTATE.NZCV(nzcv);
  773. X(d, result);
  774. }
  775. // udiv.html
  776. public static void Udiv(bool sf, Bits Rm, Bits Rn, Bits Rd)
  777. {
  778. /* Decode */
  779. int d = (int)UInt(Rd);
  780. int n = (int)UInt(Rn);
  781. int m = (int)UInt(Rm);
  782. int datasize = (sf ? 64 : 32);
  783. /* Operation */
  784. BigInteger result;
  785. Bits operand1 = X(datasize, n);
  786. Bits operand2 = X(datasize, m);
  787. if (IsZero(operand2))
  788. {
  789. result = (BigInteger)0m;
  790. }
  791. else
  792. {
  793. result = RoundTowardsZero(Real(Int(operand1, true)) / Real(Int(operand2, true)));
  794. }
  795. X(d, result.SubBigInteger(datasize - 1, 0));
  796. }
  797. #endregion
  798. #region "AluRx"
  799. // add_addsub_ext.html
  800. public static void Add_Rx(bool sf, Bits Rm, Bits option, Bits imm3, Bits Rn, Bits Rd)
  801. {
  802. /* Decode */
  803. int d = (int)UInt(Rd);
  804. int n = (int)UInt(Rn);
  805. int m = (int)UInt(Rm);
  806. int datasize = (sf ? 64 : 32);
  807. ExtendType extend_type = DecodeRegExtend(option);
  808. int shift = (int)UInt(imm3);
  809. /* if shift > 4 then ReservedValue(); */
  810. /* Operation */
  811. Bits result;
  812. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  813. Bits operand2 = ExtendReg(datasize, m, extend_type, shift);
  814. (result, _) = AddWithCarry(datasize, operand1, operand2, false);
  815. if (d == 31)
  816. {
  817. SP(result);
  818. }
  819. else
  820. {
  821. X(d, result);
  822. }
  823. }
  824. // adds_addsub_ext.html
  825. public static void Adds_Rx(bool sf, Bits Rm, Bits option, Bits imm3, Bits Rn, Bits Rd)
  826. {
  827. /* Decode */
  828. int d = (int)UInt(Rd);
  829. int n = (int)UInt(Rn);
  830. int m = (int)UInt(Rm);
  831. int datasize = (sf ? 64 : 32);
  832. ExtendType extend_type = DecodeRegExtend(option);
  833. int shift = (int)UInt(imm3);
  834. /* if shift > 4 then ReservedValue(); */
  835. /* Operation */
  836. Bits result;
  837. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  838. Bits operand2 = ExtendReg(datasize, m, extend_type, shift);
  839. Bits nzcv;
  840. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, false);
  841. PSTATE.NZCV(nzcv);
  842. X(d, result);
  843. }
  844. // sub_addsub_ext.html
  845. public static void Sub_Rx(bool sf, Bits Rm, Bits option, Bits imm3, Bits Rn, Bits Rd)
  846. {
  847. /* Decode */
  848. int d = (int)UInt(Rd);
  849. int n = (int)UInt(Rn);
  850. int m = (int)UInt(Rm);
  851. int datasize = (sf ? 64 : 32);
  852. ExtendType extend_type = DecodeRegExtend(option);
  853. int shift = (int)UInt(imm3);
  854. /* if shift > 4 then ReservedValue(); */
  855. /* Operation */
  856. Bits result;
  857. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  858. Bits operand2 = ExtendReg(datasize, m, extend_type, shift);
  859. operand2 = NOT(operand2);
  860. (result, _) = AddWithCarry(datasize, operand1, operand2, true);
  861. if (d == 31)
  862. {
  863. SP(result);
  864. }
  865. else
  866. {
  867. X(d, result);
  868. }
  869. }
  870. // subs_addsub_ext.html
  871. public static void Subs_Rx(bool sf, Bits Rm, Bits option, Bits imm3, Bits Rn, Bits Rd)
  872. {
  873. /* Decode */
  874. int d = (int)UInt(Rd);
  875. int n = (int)UInt(Rn);
  876. int m = (int)UInt(Rm);
  877. int datasize = (sf ? 64 : 32);
  878. ExtendType extend_type = DecodeRegExtend(option);
  879. int shift = (int)UInt(imm3);
  880. /* if shift > 4 then ReservedValue(); */
  881. /* Operation */
  882. Bits result;
  883. Bits operand1 = (n == 31 ? SP(datasize) : X(datasize, n));
  884. Bits operand2 = ExtendReg(datasize, m, extend_type, shift);
  885. Bits nzcv;
  886. operand2 = NOT(operand2);
  887. (result, nzcv) = AddWithCarry(datasize, operand1, operand2, true);
  888. PSTATE.NZCV(nzcv);
  889. X(d, result);
  890. }
  891. #endregion
  892. #region "Bfm"
  893. // bfm.html
  894. public static void Bfm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  895. {
  896. /* Decode */
  897. int d = (int)UInt(Rd);
  898. int n = (int)UInt(Rn);
  899. int datasize = (sf ? 64 : 32);
  900. int R;
  901. Bits wmask;
  902. Bits tmask;
  903. /* if sf == '1' && N != '1' then ReservedValue(); */
  904. /* if sf == '0' && (N != '0' || immr<5> != '0' || imms<5> != '0') then ReservedValue(); */
  905. R = (int)UInt(immr);
  906. (wmask, tmask) = DecodeBitMasks(datasize, N, imms, immr, false);
  907. /* Operation */
  908. Bits dst = X(datasize, d);
  909. Bits src = X(datasize, n);
  910. // perform bitfield move on low bits
  911. Bits bot = OR(AND(dst, NOT(wmask)), AND(ROR(src, R), wmask));
  912. // combine extension bits and result bits
  913. X(d, OR(AND(dst, NOT(tmask)), AND(bot, tmask)));
  914. }
  915. // sbfm.html
  916. public static void Sbfm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  917. {
  918. /* Decode */
  919. int d = (int)UInt(Rd);
  920. int n = (int)UInt(Rn);
  921. int datasize = (sf ? 64 : 32);
  922. int R;
  923. int S;
  924. Bits wmask;
  925. Bits tmask;
  926. /* if sf == '1' && N != '1' then ReservedValue(); */
  927. /* if sf == '0' && (N != '0' || immr<5> != '0' || imms<5> != '0') then ReservedValue(); */
  928. R = (int)UInt(immr);
  929. S = (int)UInt(imms);
  930. (wmask, tmask) = DecodeBitMasks(datasize, N, imms, immr, false);
  931. /* Operation */
  932. Bits src = X(datasize, n);
  933. // perform bitfield move on low bits
  934. Bits bot = AND(ROR(src, R), wmask);
  935. // determine extension bits (sign, zero or dest register)
  936. Bits top = Replicate(datasize, src[S]);
  937. // combine extension bits and result bits
  938. X(d, OR(AND(top, NOT(tmask)), AND(bot, tmask)));
  939. }
  940. // ubfm.html
  941. public static void Ubfm(bool sf, bool N, Bits immr, Bits imms, Bits Rn, Bits Rd)
  942. {
  943. /* Decode */
  944. int d = (int)UInt(Rd);
  945. int n = (int)UInt(Rn);
  946. int datasize = (sf ? 64 : 32);
  947. int R;
  948. Bits wmask;
  949. Bits tmask;
  950. /* if sf == '1' && N != '1' then ReservedValue(); */
  951. /* if sf == '0' && (N != '0' || immr<5> != '0' || imms<5> != '0') then ReservedValue(); */
  952. R = (int)UInt(immr);
  953. (wmask, tmask) = DecodeBitMasks(datasize, N, imms, immr, false);
  954. /* Operation */
  955. Bits src = X(datasize, n);
  956. // perform bitfield move on low bits
  957. Bits bot = AND(ROR(src, R), wmask);
  958. // combine extension bits and result bits
  959. X(d, AND(bot, tmask));
  960. }
  961. #endregion
  962. #region "CcmpImm"
  963. // ccmn_imm.html
  964. public static void Ccmn_Imm(bool sf, Bits imm5, Bits cond, Bits Rn, Bits nzcv)
  965. {
  966. /* Decode */
  967. int n = (int)UInt(Rn);
  968. int datasize = (sf ? 64 : 32);
  969. Bits flags = nzcv;
  970. Bits imm = ZeroExtend(imm5, datasize);
  971. /* Operation */
  972. Bits operand1 = X(datasize, n);
  973. if (ConditionHolds(cond))
  974. {
  975. (_, flags) = AddWithCarry(datasize, operand1, imm, false);
  976. }
  977. PSTATE.NZCV(flags);
  978. }
  979. // ccmp_imm.html
  980. public static void Ccmp_Imm(bool sf, Bits imm5, Bits cond, Bits Rn, Bits nzcv)
  981. {
  982. /* Decode */
  983. int n = (int)UInt(Rn);
  984. int datasize = (sf ? 64 : 32);
  985. Bits flags = nzcv;
  986. Bits imm = ZeroExtend(imm5, datasize);
  987. /* Operation */
  988. Bits operand1 = X(datasize, n);
  989. Bits operand2;
  990. if (ConditionHolds(cond))
  991. {
  992. operand2 = NOT(imm);
  993. (_, flags) = AddWithCarry(datasize, operand1, operand2, true);
  994. }
  995. PSTATE.NZCV(flags);
  996. }
  997. #endregion
  998. #region "CcmpReg"
  999. // ccmn_reg.html
  1000. public static void Ccmn_Reg(bool sf, Bits Rm, Bits cond, Bits Rn, Bits nzcv)
  1001. {
  1002. /* Decode */
  1003. int n = (int)UInt(Rn);
  1004. int m = (int)UInt(Rm);
  1005. int datasize = (sf ? 64 : 32);
  1006. Bits flags = nzcv;
  1007. /* Operation */
  1008. Bits operand1 = X(datasize, n);
  1009. Bits operand2 = X(datasize, m);
  1010. if (ConditionHolds(cond))
  1011. {
  1012. (_, flags) = AddWithCarry(datasize, operand1, operand2, false);
  1013. }
  1014. PSTATE.NZCV(flags);
  1015. }
  1016. // ccmp_reg.html
  1017. public static void Ccmp_Reg(bool sf, Bits Rm, Bits cond, Bits Rn, Bits nzcv)
  1018. {
  1019. /* Decode */
  1020. int n = (int)UInt(Rn);
  1021. int m = (int)UInt(Rm);
  1022. int datasize = (sf ? 64 : 32);
  1023. Bits flags = nzcv;
  1024. /* Operation */
  1025. Bits operand1 = X(datasize, n);
  1026. Bits operand2 = X(datasize, m);
  1027. if (ConditionHolds(cond))
  1028. {
  1029. operand2 = NOT(operand2);
  1030. (_, flags) = AddWithCarry(datasize, operand1, operand2, true);
  1031. }
  1032. PSTATE.NZCV(flags);
  1033. }
  1034. #endregion
  1035. #region "Csel"
  1036. // csel.html
  1037. public static void Csel(bool sf, Bits Rm, Bits cond, Bits Rn, Bits Rd)
  1038. {
  1039. /* Decode */
  1040. int d = (int)UInt(Rd);
  1041. int n = (int)UInt(Rn);
  1042. int m = (int)UInt(Rm);
  1043. int datasize = (sf ? 64 : 32);
  1044. /* Operation */
  1045. Bits result;
  1046. Bits operand1 = X(datasize, n);
  1047. Bits operand2 = X(datasize, m);
  1048. if (ConditionHolds(cond))
  1049. {
  1050. result = operand1;
  1051. }
  1052. else
  1053. {
  1054. result = operand2;
  1055. }
  1056. X(d, result);
  1057. }
  1058. // csinc.html
  1059. public static void Csinc(bool sf, Bits Rm, Bits cond, Bits Rn, Bits Rd)
  1060. {
  1061. /* Decode */
  1062. int d = (int)UInt(Rd);
  1063. int n = (int)UInt(Rn);
  1064. int m = (int)UInt(Rm);
  1065. int datasize = (sf ? 64 : 32);
  1066. /* Operation */
  1067. Bits result;
  1068. Bits operand1 = X(datasize, n);
  1069. Bits operand2 = X(datasize, m);
  1070. if (ConditionHolds(cond))
  1071. {
  1072. result = operand1;
  1073. }
  1074. else
  1075. {
  1076. result = operand2 + 1;
  1077. }
  1078. X(d, result);
  1079. }
  1080. // csinv.html
  1081. public static void Csinv(bool sf, Bits Rm, Bits cond, Bits Rn, Bits Rd)
  1082. {
  1083. /* Decode */
  1084. int d = (int)UInt(Rd);
  1085. int n = (int)UInt(Rn);
  1086. int m = (int)UInt(Rm);
  1087. int datasize = (sf ? 64 : 32);
  1088. /* Operation */
  1089. Bits result;
  1090. Bits operand1 = X(datasize, n);
  1091. Bits operand2 = X(datasize, m);
  1092. if (ConditionHolds(cond))
  1093. {
  1094. result = operand1;
  1095. }
  1096. else
  1097. {
  1098. result = NOT(operand2);
  1099. }
  1100. X(d, result);
  1101. }
  1102. // csneg.html
  1103. public static void Csneg(bool sf, Bits Rm, Bits cond, Bits Rn, Bits Rd)
  1104. {
  1105. /* Decode */
  1106. int d = (int)UInt(Rd);
  1107. int n = (int)UInt(Rn);
  1108. int m = (int)UInt(Rm);
  1109. int datasize = (sf ? 64 : 32);
  1110. /* Operation */
  1111. Bits result;
  1112. Bits operand1 = X(datasize, n);
  1113. Bits operand2 = X(datasize, m);
  1114. if (ConditionHolds(cond))
  1115. {
  1116. result = operand1;
  1117. }
  1118. else
  1119. {
  1120. result = NOT(operand2);
  1121. result = result + 1;
  1122. }
  1123. X(d, result);
  1124. }
  1125. #endregion
  1126. #region "Mov"
  1127. // movk.html
  1128. public static void Movk(bool sf, Bits hw, Bits imm16, Bits Rd)
  1129. {
  1130. /* Decode */
  1131. int d = (int)UInt(Rd);
  1132. int datasize = (sf ? 64 : 32);
  1133. /* if sf == '0' && hw<1> == '1' then UnallocatedEncoding(); */
  1134. int pos = (int)UInt(Bits.Concat(hw, "0000"));
  1135. /* Operation */
  1136. Bits result = X(datasize, d);
  1137. result[pos + 15, pos] = imm16;
  1138. X(d, result);
  1139. }
  1140. // movn.html
  1141. public static void Movn(bool sf, Bits hw, Bits imm16, Bits Rd)
  1142. {
  1143. /* Decode */
  1144. int d = (int)UInt(Rd);
  1145. int datasize = (sf ? 64 : 32);
  1146. /* if sf == '0' && hw<1> == '1' then UnallocatedEncoding(); */
  1147. int pos = (int)UInt(Bits.Concat(hw, "0000"));
  1148. /* Operation */
  1149. Bits result = Zeros(datasize);
  1150. result[pos + 15, pos] = imm16;
  1151. result = NOT(result);
  1152. X(d, result);
  1153. }
  1154. // movz.html
  1155. public static void Movz(bool sf, Bits hw, Bits imm16, Bits Rd)
  1156. {
  1157. /* Decode */
  1158. int d = (int)UInt(Rd);
  1159. int datasize = (sf ? 64 : 32);
  1160. /* if sf == '0' && hw<1> == '1' then UnallocatedEncoding(); */
  1161. int pos = (int)UInt(Bits.Concat(hw, "0000"));
  1162. /* Operation */
  1163. Bits result = Zeros(datasize);
  1164. result[pos + 15, pos] = imm16;
  1165. X(d, result);
  1166. }
  1167. #endregion
  1168. #region "Mul"
  1169. // madd.html
  1170. public static void Madd(bool sf, Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1171. {
  1172. /* Decode */
  1173. int d = (int)UInt(Rd);
  1174. int n = (int)UInt(Rn);
  1175. int m = (int)UInt(Rm);
  1176. int a = (int)UInt(Ra);
  1177. int datasize = (sf ? 64 : 32);
  1178. /* Operation */
  1179. Bits operand1 = X(datasize, n);
  1180. Bits operand2 = X(datasize, m);
  1181. Bits operand3 = X(datasize, a);
  1182. BigInteger result = UInt(operand3) + (UInt(operand1) * UInt(operand2));
  1183. X(d, result.SubBigInteger(datasize - 1, 0));
  1184. }
  1185. // msub.html
  1186. public static void Msub(bool sf, Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1187. {
  1188. /* Decode */
  1189. int d = (int)UInt(Rd);
  1190. int n = (int)UInt(Rn);
  1191. int m = (int)UInt(Rm);
  1192. int a = (int)UInt(Ra);
  1193. int datasize = (sf ? 64 : 32);
  1194. /* Operation */
  1195. Bits operand1 = X(datasize, n);
  1196. Bits operand2 = X(datasize, m);
  1197. Bits operand3 = X(datasize, a);
  1198. BigInteger result = UInt(operand3) - (UInt(operand1) * UInt(operand2));
  1199. X(d, result.SubBigInteger(datasize - 1, 0));
  1200. }
  1201. // smaddl.html
  1202. public static void Smaddl(Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1203. {
  1204. /* Decode */
  1205. int d = (int)UInt(Rd);
  1206. int n = (int)UInt(Rn);
  1207. int m = (int)UInt(Rm);
  1208. int a = (int)UInt(Ra);
  1209. /* Operation */
  1210. Bits operand1 = X(32, n);
  1211. Bits operand2 = X(32, m);
  1212. Bits operand3 = X(64, a);
  1213. BigInteger result = Int(operand3, false) + (Int(operand1, false) * Int(operand2, false));
  1214. X(d, result.SubBigInteger(63, 0));
  1215. }
  1216. // umaddl.html
  1217. public static void Umaddl(Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1218. {
  1219. /* Decode */
  1220. int d = (int)UInt(Rd);
  1221. int n = (int)UInt(Rn);
  1222. int m = (int)UInt(Rm);
  1223. int a = (int)UInt(Ra);
  1224. /* Operation */
  1225. Bits operand1 = X(32, n);
  1226. Bits operand2 = X(32, m);
  1227. Bits operand3 = X(64, a);
  1228. BigInteger result = Int(operand3, true) + (Int(operand1, true) * Int(operand2, true));
  1229. X(d, result.SubBigInteger(63, 0));
  1230. }
  1231. // smsubl.html
  1232. public static void Smsubl(Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1233. {
  1234. /* Decode */
  1235. int d = (int)UInt(Rd);
  1236. int n = (int)UInt(Rn);
  1237. int m = (int)UInt(Rm);
  1238. int a = (int)UInt(Ra);
  1239. /* Operation */
  1240. Bits operand1 = X(32, n);
  1241. Bits operand2 = X(32, m);
  1242. Bits operand3 = X(64, a);
  1243. BigInteger result = Int(operand3, false) - (Int(operand1, false) * Int(operand2, false));
  1244. X(d, result.SubBigInteger(63, 0));
  1245. }
  1246. // umsubl.html
  1247. public static void Umsubl(Bits Rm, Bits Ra, Bits Rn, Bits Rd)
  1248. {
  1249. /* Decode */
  1250. int d = (int)UInt(Rd);
  1251. int n = (int)UInt(Rn);
  1252. int m = (int)UInt(Rm);
  1253. int a = (int)UInt(Ra);
  1254. /* Operation */
  1255. Bits operand1 = X(32, n);
  1256. Bits operand2 = X(32, m);
  1257. Bits operand3 = X(64, a);
  1258. BigInteger result = Int(operand3, true) - (Int(operand1, true) * Int(operand2, true));
  1259. X(d, result.SubBigInteger(63, 0));
  1260. }
  1261. // smulh.html
  1262. public static void Smulh(Bits Rm, Bits Rn, Bits Rd)
  1263. {
  1264. /* Decode */
  1265. int d = (int)UInt(Rd);
  1266. int n = (int)UInt(Rn);
  1267. int m = (int)UInt(Rm);
  1268. /* Operation */
  1269. Bits operand1 = X(64, n);
  1270. Bits operand2 = X(64, m);
  1271. BigInteger result = Int(operand1, false) * Int(operand2, false);
  1272. X(d, result.SubBigInteger(127, 64));
  1273. }
  1274. // umulh.html
  1275. public static void Umulh(Bits Rm, Bits Rn, Bits Rd)
  1276. {
  1277. /* Decode */
  1278. int d = (int)UInt(Rd);
  1279. int n = (int)UInt(Rn);
  1280. int m = (int)UInt(Rm);
  1281. /* Operation */
  1282. Bits operand1 = X(64, n);
  1283. Bits operand2 = X(64, m);
  1284. BigInteger result = Int(operand1, true) * Int(operand2, true);
  1285. X(d, result.SubBigInteger(127, 64));
  1286. }
  1287. #endregion
  1288. }
  1289. // fpsimdindex.html
  1290. internal static class SimdFp
  1291. {
  1292. #region "Simd"
  1293. // abs_advsimd.html#ABS_asisdmisc_R
  1294. public static void Abs_S(Bits size, Bits Rn, Bits Rd)
  1295. {
  1296. const bool U = false;
  1297. /* Decode Scalar */
  1298. int d = (int)UInt(Rd);
  1299. int n = (int)UInt(Rn);
  1300. /* if size != '11' then ReservedValue(); */
  1301. int esize = 8 << (int)UInt(size);
  1302. int datasize = esize;
  1303. int elements = 1;
  1304. bool neg = (U == true);
  1305. /* Operation */
  1306. /* CheckFPAdvSIMDEnabled64(); */
  1307. Bits result = new Bits(datasize);
  1308. Bits operand = V(datasize, n);
  1309. BigInteger element;
  1310. for (int e = 0; e <= elements - 1; e++)
  1311. {
  1312. element = SInt(Elem(operand, e, esize));
  1313. if (neg)
  1314. {
  1315. element = -element;
  1316. }
  1317. else
  1318. {
  1319. element = Abs(element);
  1320. }
  1321. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  1322. }
  1323. V(d, result);
  1324. }
  1325. // abs_advsimd.html#ABS_asimdmisc_R
  1326. public static void Abs_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1327. {
  1328. const bool U = false;
  1329. /* Decode Vector */
  1330. int d = (int)UInt(Rd);
  1331. int n = (int)UInt(Rn);
  1332. /* if size:Q == '110' then ReservedValue(); */
  1333. int esize = 8 << (int)UInt(size);
  1334. int datasize = (Q ? 128 : 64);
  1335. int elements = datasize / esize;
  1336. bool neg = (U == true);
  1337. /* Operation */
  1338. /* CheckFPAdvSIMDEnabled64(); */
  1339. Bits result = new Bits(datasize);
  1340. Bits operand = V(datasize, n);
  1341. BigInteger element;
  1342. for (int e = 0; e <= elements - 1; e++)
  1343. {
  1344. element = SInt(Elem(operand, e, esize));
  1345. if (neg)
  1346. {
  1347. element = -element;
  1348. }
  1349. else
  1350. {
  1351. element = Abs(element);
  1352. }
  1353. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  1354. }
  1355. V(d, result);
  1356. }
  1357. // addp_advsimd_pair.html
  1358. public static void Addp_S(Bits size, Bits Rn, Bits Rd)
  1359. {
  1360. /* Decode */
  1361. int d = (int)UInt(Rd);
  1362. int n = (int)UInt(Rn);
  1363. /* if size != '11' then ReservedValue(); */
  1364. int esize = 8 << (int)UInt(size);
  1365. int datasize = esize * 2;
  1366. // int elements = 2;
  1367. ReduceOp op = ReduceOp.ReduceOp_ADD;
  1368. /* Operation */
  1369. /* CheckFPAdvSIMDEnabled64(); */
  1370. Bits operand = V(datasize, n);
  1371. V(d, Reduce(op, operand, esize));
  1372. }
  1373. // addv_advsimd.html
  1374. public static void Addv_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1375. {
  1376. /* Decode */
  1377. int d = (int)UInt(Rd);
  1378. int n = (int)UInt(Rn);
  1379. /* if size:Q == '100' then ReservedValue(); */
  1380. /* if size == '11' then ReservedValue(); */
  1381. int esize = 8 << (int)UInt(size);
  1382. int datasize = (Q ? 128 : 64);
  1383. // int elements = datasize / esize;
  1384. ReduceOp op = ReduceOp.ReduceOp_ADD;
  1385. /* Operation */
  1386. /* CheckFPAdvSIMDEnabled64(); */
  1387. Bits operand = V(datasize, n);
  1388. V(d, Reduce(op, operand, esize));
  1389. }
  1390. // cls_advsimd.html
  1391. public static void Cls_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1392. {
  1393. const bool U = false;
  1394. /* Decode Vector */
  1395. int d = (int)UInt(Rd);
  1396. int n = (int)UInt(Rn);
  1397. /* if size == '11' then ReservedValue(); */
  1398. int esize = 8 << (int)UInt(size);
  1399. int datasize = (Q ? 128 : 64);
  1400. int elements = datasize / esize;
  1401. CountOp countop = (U ? CountOp.CountOp_CLZ : CountOp.CountOp_CLS);
  1402. /* Operation */
  1403. /* CheckFPAdvSIMDEnabled64(); */
  1404. Bits result = new Bits(datasize);
  1405. Bits operand = V(datasize, n);
  1406. BigInteger count;
  1407. for (int e = 0; e <= elements - 1; e++)
  1408. {
  1409. if (countop == CountOp.CountOp_CLS)
  1410. {
  1411. count = (BigInteger)CountLeadingSignBits(Elem(operand, e, esize));
  1412. }
  1413. else
  1414. {
  1415. count = (BigInteger)CountLeadingZeroBits(Elem(operand, e, esize));
  1416. }
  1417. Elem(result, e, esize, count.SubBigInteger(esize - 1, 0));
  1418. }
  1419. V(d, result);
  1420. }
  1421. // clz_advsimd.html
  1422. public static void Clz_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1423. {
  1424. const bool U = true;
  1425. /* Decode Vector */
  1426. int d = (int)UInt(Rd);
  1427. int n = (int)UInt(Rn);
  1428. /* if size == '11' then ReservedValue(); */
  1429. int esize = 8 << (int)UInt(size);
  1430. int datasize = (Q ? 128 : 64);
  1431. int elements = datasize / esize;
  1432. CountOp countop = (U ? CountOp.CountOp_CLZ : CountOp.CountOp_CLS);
  1433. /* Operation */
  1434. /* CheckFPAdvSIMDEnabled64(); */
  1435. Bits result = new Bits(datasize);
  1436. Bits operand = V(datasize, n);
  1437. BigInteger count;
  1438. for (int e = 0; e <= elements - 1; e++)
  1439. {
  1440. if (countop == CountOp.CountOp_CLS)
  1441. {
  1442. count = (BigInteger)CountLeadingSignBits(Elem(operand, e, esize));
  1443. }
  1444. else
  1445. {
  1446. count = (BigInteger)CountLeadingZeroBits(Elem(operand, e, esize));
  1447. }
  1448. Elem(result, e, esize, count.SubBigInteger(esize - 1, 0));
  1449. }
  1450. V(d, result);
  1451. }
  1452. // cmeq_advsimd_zero.html#CMEQ_asisdmisc_Z
  1453. public static void Cmeq_Zero_S(Bits size, Bits Rn, Bits Rd)
  1454. {
  1455. const bool U = false;
  1456. const bool op = true;
  1457. /* Decode Scalar */
  1458. int d = (int)UInt(Rd);
  1459. int n = (int)UInt(Rn);
  1460. /* if size != '11' then ReservedValue(); */
  1461. int esize = 8 << (int)UInt(size);
  1462. int datasize = esize;
  1463. int elements = 1;
  1464. CompareOp comparison;
  1465. switch (Bits.Concat(op, U))
  1466. {
  1467. case Bits bits when bits == "00":
  1468. comparison = CompareOp.CompareOp_GT;
  1469. break;
  1470. case Bits bits when bits == "01":
  1471. comparison = CompareOp.CompareOp_GE;
  1472. break;
  1473. default:
  1474. case Bits bits when bits == "10":
  1475. comparison = CompareOp.CompareOp_EQ;
  1476. break;
  1477. case Bits bits when bits == "11":
  1478. comparison = CompareOp.CompareOp_LE;
  1479. break;
  1480. }
  1481. /* Operation */
  1482. /* CheckFPAdvSIMDEnabled64(); */
  1483. Bits result = new Bits(datasize);
  1484. Bits operand = V(datasize, n);
  1485. BigInteger element;
  1486. bool test_passed;
  1487. for (int e = 0; e <= elements - 1; e++)
  1488. {
  1489. element = SInt(Elem(operand, e, esize));
  1490. switch (comparison)
  1491. {
  1492. case CompareOp.CompareOp_GT:
  1493. test_passed = (element > (BigInteger)0);
  1494. break;
  1495. case CompareOp.CompareOp_GE:
  1496. test_passed = (element >= (BigInteger)0);
  1497. break;
  1498. default:
  1499. case CompareOp.CompareOp_EQ:
  1500. test_passed = (element == (BigInteger)0);
  1501. break;
  1502. case CompareOp.CompareOp_LE:
  1503. test_passed = (element <= (BigInteger)0);
  1504. break;
  1505. case CompareOp.CompareOp_LT:
  1506. test_passed = (element < (BigInteger)0);
  1507. break;
  1508. }
  1509. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1510. }
  1511. V(d, result);
  1512. }
  1513. // cmeq_advsimd_zero.html#CMEQ_asimdmisc_Z
  1514. public static void Cmeq_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1515. {
  1516. const bool U = false;
  1517. const bool op = true;
  1518. /* Decode Vector */
  1519. int d = (int)UInt(Rd);
  1520. int n = (int)UInt(Rn);
  1521. /* if size:Q == '110' then ReservedValue(); */
  1522. int esize = 8 << (int)UInt(size);
  1523. int datasize = (Q ? 128 : 64);
  1524. int elements = datasize / esize;
  1525. CompareOp comparison;
  1526. switch (Bits.Concat(op, U))
  1527. {
  1528. case Bits bits when bits == "00":
  1529. comparison = CompareOp.CompareOp_GT;
  1530. break;
  1531. case Bits bits when bits == "01":
  1532. comparison = CompareOp.CompareOp_GE;
  1533. break;
  1534. default:
  1535. case Bits bits when bits == "10":
  1536. comparison = CompareOp.CompareOp_EQ;
  1537. break;
  1538. case Bits bits when bits == "11":
  1539. comparison = CompareOp.CompareOp_LE;
  1540. break;
  1541. }
  1542. /* Operation */
  1543. /* CheckFPAdvSIMDEnabled64(); */
  1544. Bits result = new Bits(datasize);
  1545. Bits operand = V(datasize, n);
  1546. BigInteger element;
  1547. bool test_passed;
  1548. for (int e = 0; e <= elements - 1; e++)
  1549. {
  1550. element = SInt(Elem(operand, e, esize));
  1551. switch (comparison)
  1552. {
  1553. case CompareOp.CompareOp_GT:
  1554. test_passed = (element > (BigInteger)0);
  1555. break;
  1556. case CompareOp.CompareOp_GE:
  1557. test_passed = (element >= (BigInteger)0);
  1558. break;
  1559. default:
  1560. case CompareOp.CompareOp_EQ:
  1561. test_passed = (element == (BigInteger)0);
  1562. break;
  1563. case CompareOp.CompareOp_LE:
  1564. test_passed = (element <= (BigInteger)0);
  1565. break;
  1566. case CompareOp.CompareOp_LT:
  1567. test_passed = (element < (BigInteger)0);
  1568. break;
  1569. }
  1570. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1571. }
  1572. V(d, result);
  1573. }
  1574. // cmge_advsimd_zero.html#CMGE_asisdmisc_Z
  1575. public static void Cmge_Zero_S(Bits size, Bits Rn, Bits Rd)
  1576. {
  1577. const bool U = true;
  1578. const bool op = false;
  1579. /* Decode Scalar */
  1580. int d = (int)UInt(Rd);
  1581. int n = (int)UInt(Rn);
  1582. /* if size != '11' then ReservedValue(); */
  1583. int esize = 8 << (int)UInt(size);
  1584. int datasize = esize;
  1585. int elements = 1;
  1586. CompareOp comparison;
  1587. switch (Bits.Concat(op, U))
  1588. {
  1589. case Bits bits when bits == "00":
  1590. comparison = CompareOp.CompareOp_GT;
  1591. break;
  1592. default:
  1593. case Bits bits when bits == "01":
  1594. comparison = CompareOp.CompareOp_GE;
  1595. break;
  1596. case Bits bits when bits == "10":
  1597. comparison = CompareOp.CompareOp_EQ;
  1598. break;
  1599. case Bits bits when bits == "11":
  1600. comparison = CompareOp.CompareOp_LE;
  1601. break;
  1602. }
  1603. /* Operation */
  1604. /* CheckFPAdvSIMDEnabled64(); */
  1605. Bits result = new Bits(datasize);
  1606. Bits operand = V(datasize, n);
  1607. BigInteger element;
  1608. bool test_passed;
  1609. for (int e = 0; e <= elements - 1; e++)
  1610. {
  1611. element = SInt(Elem(operand, e, esize));
  1612. switch (comparison)
  1613. {
  1614. case CompareOp.CompareOp_GT:
  1615. test_passed = (element > (BigInteger)0);
  1616. break;
  1617. default:
  1618. case CompareOp.CompareOp_GE:
  1619. test_passed = (element >= (BigInteger)0);
  1620. break;
  1621. case CompareOp.CompareOp_EQ:
  1622. test_passed = (element == (BigInteger)0);
  1623. break;
  1624. case CompareOp.CompareOp_LE:
  1625. test_passed = (element <= (BigInteger)0);
  1626. break;
  1627. case CompareOp.CompareOp_LT:
  1628. test_passed = (element < (BigInteger)0);
  1629. break;
  1630. }
  1631. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1632. }
  1633. V(d, result);
  1634. }
  1635. // cmge_advsimd_zero.html#CMGE_asimdmisc_Z
  1636. public static void Cmge_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1637. {
  1638. const bool U = true;
  1639. const bool op = false;
  1640. /* Decode Vector */
  1641. int d = (int)UInt(Rd);
  1642. int n = (int)UInt(Rn);
  1643. /* if size:Q == '110' then ReservedValue(); */
  1644. int esize = 8 << (int)UInt(size);
  1645. int datasize = (Q ? 128 : 64);
  1646. int elements = datasize / esize;
  1647. CompareOp comparison;
  1648. switch (Bits.Concat(op, U))
  1649. {
  1650. case Bits bits when bits == "00":
  1651. comparison = CompareOp.CompareOp_GT;
  1652. break;
  1653. default:
  1654. case Bits bits when bits == "01":
  1655. comparison = CompareOp.CompareOp_GE;
  1656. break;
  1657. case Bits bits when bits == "10":
  1658. comparison = CompareOp.CompareOp_EQ;
  1659. break;
  1660. case Bits bits when bits == "11":
  1661. comparison = CompareOp.CompareOp_LE;
  1662. break;
  1663. }
  1664. /* Operation */
  1665. /* CheckFPAdvSIMDEnabled64(); */
  1666. Bits result = new Bits(datasize);
  1667. Bits operand = V(datasize, n);
  1668. BigInteger element;
  1669. bool test_passed;
  1670. for (int e = 0; e <= elements - 1; e++)
  1671. {
  1672. element = SInt(Elem(operand, e, esize));
  1673. switch (comparison)
  1674. {
  1675. case CompareOp.CompareOp_GT:
  1676. test_passed = (element > (BigInteger)0);
  1677. break;
  1678. default:
  1679. case CompareOp.CompareOp_GE:
  1680. test_passed = (element >= (BigInteger)0);
  1681. break;
  1682. case CompareOp.CompareOp_EQ:
  1683. test_passed = (element == (BigInteger)0);
  1684. break;
  1685. case CompareOp.CompareOp_LE:
  1686. test_passed = (element <= (BigInteger)0);
  1687. break;
  1688. case CompareOp.CompareOp_LT:
  1689. test_passed = (element < (BigInteger)0);
  1690. break;
  1691. }
  1692. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1693. }
  1694. V(d, result);
  1695. }
  1696. // cmgt_advsimd_zero.html#CMGT_asisdmisc_Z
  1697. public static void Cmgt_Zero_S(Bits size, Bits Rn, Bits Rd)
  1698. {
  1699. const bool U = false;
  1700. const bool op = false;
  1701. /* Decode Scalar */
  1702. int d = (int)UInt(Rd);
  1703. int n = (int)UInt(Rn);
  1704. /* if size != '11' then ReservedValue(); */
  1705. int esize = 8 << (int)UInt(size);
  1706. int datasize = esize;
  1707. int elements = 1;
  1708. CompareOp comparison;
  1709. switch (Bits.Concat(op, U))
  1710. {
  1711. default:
  1712. case Bits bits when bits == "00":
  1713. comparison = CompareOp.CompareOp_GT;
  1714. break;
  1715. case Bits bits when bits == "01":
  1716. comparison = CompareOp.CompareOp_GE;
  1717. break;
  1718. case Bits bits when bits == "10":
  1719. comparison = CompareOp.CompareOp_EQ;
  1720. break;
  1721. case Bits bits when bits == "11":
  1722. comparison = CompareOp.CompareOp_LE;
  1723. break;
  1724. }
  1725. /* Operation */
  1726. /* CheckFPAdvSIMDEnabled64(); */
  1727. Bits result = new Bits(datasize);
  1728. Bits operand = V(datasize, n);
  1729. BigInteger element;
  1730. bool test_passed;
  1731. for (int e = 0; e <= elements - 1; e++)
  1732. {
  1733. element = SInt(Elem(operand, e, esize));
  1734. switch (comparison)
  1735. {
  1736. default:
  1737. case CompareOp.CompareOp_GT:
  1738. test_passed = (element > (BigInteger)0);
  1739. break;
  1740. case CompareOp.CompareOp_GE:
  1741. test_passed = (element >= (BigInteger)0);
  1742. break;
  1743. case CompareOp.CompareOp_EQ:
  1744. test_passed = (element == (BigInteger)0);
  1745. break;
  1746. case CompareOp.CompareOp_LE:
  1747. test_passed = (element <= (BigInteger)0);
  1748. break;
  1749. case CompareOp.CompareOp_LT:
  1750. test_passed = (element < (BigInteger)0);
  1751. break;
  1752. }
  1753. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1754. }
  1755. V(d, result);
  1756. }
  1757. // cmgt_advsimd_zero.html#CMGT_asimdmisc_Z
  1758. public static void Cmgt_Zero_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1759. {
  1760. const bool U = false;
  1761. const bool op = false;
  1762. /* Decode Vector */
  1763. int d = (int)UInt(Rd);
  1764. int n = (int)UInt(Rn);
  1765. /* if size:Q == '110' then ReservedValue(); */
  1766. int esize = 8 << (int)UInt(size);
  1767. int datasize = (Q ? 128 : 64);
  1768. int elements = datasize / esize;
  1769. CompareOp comparison;
  1770. switch (Bits.Concat(op, U))
  1771. {
  1772. default:
  1773. case Bits bits when bits == "00":
  1774. comparison = CompareOp.CompareOp_GT;
  1775. break;
  1776. case Bits bits when bits == "01":
  1777. comparison = CompareOp.CompareOp_GE;
  1778. break;
  1779. case Bits bits when bits == "10":
  1780. comparison = CompareOp.CompareOp_EQ;
  1781. break;
  1782. case Bits bits when bits == "11":
  1783. comparison = CompareOp.CompareOp_LE;
  1784. break;
  1785. }
  1786. /* Operation */
  1787. /* CheckFPAdvSIMDEnabled64(); */
  1788. Bits result = new Bits(datasize);
  1789. Bits operand = V(datasize, n);
  1790. BigInteger element;
  1791. bool test_passed;
  1792. for (int e = 0; e <= elements - 1; e++)
  1793. {
  1794. element = SInt(Elem(operand, e, esize));
  1795. switch (comparison)
  1796. {
  1797. default:
  1798. case CompareOp.CompareOp_GT:
  1799. test_passed = (element > (BigInteger)0);
  1800. break;
  1801. case CompareOp.CompareOp_GE:
  1802. test_passed = (element >= (BigInteger)0);
  1803. break;
  1804. case CompareOp.CompareOp_EQ:
  1805. test_passed = (element == (BigInteger)0);
  1806. break;
  1807. case CompareOp.CompareOp_LE:
  1808. test_passed = (element <= (BigInteger)0);
  1809. break;
  1810. case CompareOp.CompareOp_LT:
  1811. test_passed = (element < (BigInteger)0);
  1812. break;
  1813. }
  1814. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1815. }
  1816. V(d, result);
  1817. }
  1818. // cmle_advsimd.html#CMLE_asisdmisc_Z
  1819. public static void Cmle_S(Bits size, Bits Rn, Bits Rd)
  1820. {
  1821. const bool U = true;
  1822. const bool op = true;
  1823. /* Decode Scalar */
  1824. int d = (int)UInt(Rd);
  1825. int n = (int)UInt(Rn);
  1826. /* if size != '11' then ReservedValue(); */
  1827. int esize = 8 << (int)UInt(size);
  1828. int datasize = esize;
  1829. int elements = 1;
  1830. CompareOp comparison;
  1831. switch (Bits.Concat(op, U))
  1832. {
  1833. case Bits bits when bits == "00":
  1834. comparison = CompareOp.CompareOp_GT;
  1835. break;
  1836. case Bits bits when bits == "01":
  1837. comparison = CompareOp.CompareOp_GE;
  1838. break;
  1839. case Bits bits when bits == "10":
  1840. comparison = CompareOp.CompareOp_EQ;
  1841. break;
  1842. default:
  1843. case Bits bits when bits == "11":
  1844. comparison = CompareOp.CompareOp_LE;
  1845. break;
  1846. }
  1847. /* Operation */
  1848. /* CheckFPAdvSIMDEnabled64(); */
  1849. Bits result = new Bits(datasize);
  1850. Bits operand = V(datasize, n);
  1851. BigInteger element;
  1852. bool test_passed;
  1853. for (int e = 0; e <= elements - 1; e++)
  1854. {
  1855. element = SInt(Elem(operand, e, esize));
  1856. switch (comparison)
  1857. {
  1858. case CompareOp.CompareOp_GT:
  1859. test_passed = (element > (BigInteger)0);
  1860. break;
  1861. case CompareOp.CompareOp_GE:
  1862. test_passed = (element >= (BigInteger)0);
  1863. break;
  1864. case CompareOp.CompareOp_EQ:
  1865. test_passed = (element == (BigInteger)0);
  1866. break;
  1867. default:
  1868. case CompareOp.CompareOp_LE:
  1869. test_passed = (element <= (BigInteger)0);
  1870. break;
  1871. case CompareOp.CompareOp_LT:
  1872. test_passed = (element < (BigInteger)0);
  1873. break;
  1874. }
  1875. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1876. }
  1877. V(d, result);
  1878. }
  1879. // cmle_advsimd.html#CMLE_asimdmisc_Z
  1880. public static void Cmle_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1881. {
  1882. const bool U = true;
  1883. const bool op = true;
  1884. /* Decode Vector */
  1885. int d = (int)UInt(Rd);
  1886. int n = (int)UInt(Rn);
  1887. /* if size:Q == '110' then ReservedValue(); */
  1888. int esize = 8 << (int)UInt(size);
  1889. int datasize = (Q ? 128 : 64);
  1890. int elements = datasize / esize;
  1891. CompareOp comparison;
  1892. switch (Bits.Concat(op, U))
  1893. {
  1894. case Bits bits when bits == "00":
  1895. comparison = CompareOp.CompareOp_GT;
  1896. break;
  1897. case Bits bits when bits == "01":
  1898. comparison = CompareOp.CompareOp_GE;
  1899. break;
  1900. case Bits bits when bits == "10":
  1901. comparison = CompareOp.CompareOp_EQ;
  1902. break;
  1903. default:
  1904. case Bits bits when bits == "11":
  1905. comparison = CompareOp.CompareOp_LE;
  1906. break;
  1907. }
  1908. /* Operation */
  1909. /* CheckFPAdvSIMDEnabled64(); */
  1910. Bits result = new Bits(datasize);
  1911. Bits operand = V(datasize, n);
  1912. BigInteger element;
  1913. bool test_passed;
  1914. for (int e = 0; e <= elements - 1; e++)
  1915. {
  1916. element = SInt(Elem(operand, e, esize));
  1917. switch (comparison)
  1918. {
  1919. case CompareOp.CompareOp_GT:
  1920. test_passed = (element > (BigInteger)0);
  1921. break;
  1922. case CompareOp.CompareOp_GE:
  1923. test_passed = (element >= (BigInteger)0);
  1924. break;
  1925. case CompareOp.CompareOp_EQ:
  1926. test_passed = (element == (BigInteger)0);
  1927. break;
  1928. default:
  1929. case CompareOp.CompareOp_LE:
  1930. test_passed = (element <= (BigInteger)0);
  1931. break;
  1932. case CompareOp.CompareOp_LT:
  1933. test_passed = (element < (BigInteger)0);
  1934. break;
  1935. }
  1936. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1937. }
  1938. V(d, result);
  1939. }
  1940. // cmlt_advsimd.html#CMLT_asisdmisc_Z
  1941. public static void Cmlt_S(Bits size, Bits Rn, Bits Rd)
  1942. {
  1943. /* Decode Scalar */
  1944. int d = (int)UInt(Rd);
  1945. int n = (int)UInt(Rn);
  1946. /* if size != '11' then ReservedValue(); */
  1947. int esize = 8 << (int)UInt(size);
  1948. int datasize = esize;
  1949. int elements = 1;
  1950. CompareOp comparison = CompareOp.CompareOp_LT;
  1951. /* Operation */
  1952. /* CheckFPAdvSIMDEnabled64(); */
  1953. Bits result = new Bits(datasize);
  1954. Bits operand = V(datasize, n);
  1955. BigInteger element;
  1956. bool test_passed;
  1957. for (int e = 0; e <= elements - 1; e++)
  1958. {
  1959. element = SInt(Elem(operand, e, esize));
  1960. switch (comparison)
  1961. {
  1962. case CompareOp.CompareOp_GT:
  1963. test_passed = (element > (BigInteger)0);
  1964. break;
  1965. case CompareOp.CompareOp_GE:
  1966. test_passed = (element >= (BigInteger)0);
  1967. break;
  1968. case CompareOp.CompareOp_EQ:
  1969. test_passed = (element == (BigInteger)0);
  1970. break;
  1971. case CompareOp.CompareOp_LE:
  1972. test_passed = (element <= (BigInteger)0);
  1973. break;
  1974. default:
  1975. case CompareOp.CompareOp_LT:
  1976. test_passed = (element < (BigInteger)0);
  1977. break;
  1978. }
  1979. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  1980. }
  1981. V(d, result);
  1982. }
  1983. // cmlt_advsimd.html#CMLT_asimdmisc_Z
  1984. public static void Cmlt_V(bool Q, Bits size, Bits Rn, Bits Rd)
  1985. {
  1986. /* Decode Vector */
  1987. int d = (int)UInt(Rd);
  1988. int n = (int)UInt(Rn);
  1989. /* if size:Q == '110' then ReservedValue(); */
  1990. int esize = 8 << (int)UInt(size);
  1991. int datasize = (Q ? 128 : 64);
  1992. int elements = datasize / esize;
  1993. CompareOp comparison = CompareOp.CompareOp_LT;
  1994. /* Operation */
  1995. /* CheckFPAdvSIMDEnabled64(); */
  1996. Bits result = new Bits(datasize);
  1997. Bits operand = V(datasize, n);
  1998. BigInteger element;
  1999. bool test_passed;
  2000. for (int e = 0; e <= elements - 1; e++)
  2001. {
  2002. element = SInt(Elem(operand, e, esize));
  2003. switch (comparison)
  2004. {
  2005. case CompareOp.CompareOp_GT:
  2006. test_passed = (element > (BigInteger)0);
  2007. break;
  2008. case CompareOp.CompareOp_GE:
  2009. test_passed = (element >= (BigInteger)0);
  2010. break;
  2011. case CompareOp.CompareOp_EQ:
  2012. test_passed = (element == (BigInteger)0);
  2013. break;
  2014. case CompareOp.CompareOp_LE:
  2015. test_passed = (element <= (BigInteger)0);
  2016. break;
  2017. default:
  2018. case CompareOp.CompareOp_LT:
  2019. test_passed = (element < (BigInteger)0);
  2020. break;
  2021. }
  2022. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  2023. }
  2024. V(d, result);
  2025. }
  2026. // cnt_advsimd.html
  2027. public static void Cnt_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2028. {
  2029. /* Decode Vector */
  2030. int d = (int)UInt(Rd);
  2031. int n = (int)UInt(Rn);
  2032. /* if size != '00' then ReservedValue(); */
  2033. int esize = 8;
  2034. int datasize = (Q ? 128 : 64);
  2035. int elements = datasize / 8;
  2036. /* Operation */
  2037. /* CheckFPAdvSIMDEnabled64(); */
  2038. Bits result = new Bits(datasize);
  2039. Bits operand = V(datasize, n);
  2040. BigInteger count;
  2041. for (int e = 0; e <= elements - 1; e++)
  2042. {
  2043. count = (BigInteger)BitCount(Elem(operand, e, esize));
  2044. Elem(result, e, esize, count.SubBigInteger(esize - 1, 0));
  2045. }
  2046. V(d, result);
  2047. }
  2048. // neg_advsimd.html#NEG_asisdmisc_R
  2049. public static void Neg_S(Bits size, Bits Rn, Bits Rd)
  2050. {
  2051. const bool U = true;
  2052. /* Decode Scalar */
  2053. int d = (int)UInt(Rd);
  2054. int n = (int)UInt(Rn);
  2055. /* if size != '11' then ReservedValue(); */
  2056. int esize = 8 << (int)UInt(size);
  2057. int datasize = esize;
  2058. int elements = 1;
  2059. bool neg = (U == true);
  2060. /* Operation */
  2061. /* CheckFPAdvSIMDEnabled64(); */
  2062. Bits result = new Bits(datasize);
  2063. Bits operand = V(datasize, n);
  2064. BigInteger element;
  2065. for (int e = 0; e <= elements - 1; e++)
  2066. {
  2067. element = SInt(Elem(operand, e, esize));
  2068. if (neg)
  2069. {
  2070. element = -element;
  2071. }
  2072. else
  2073. {
  2074. element = Abs(element);
  2075. }
  2076. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  2077. }
  2078. V(d, result);
  2079. }
  2080. // neg_advsimd.html#NEG_asimdmisc_R
  2081. public static void Neg_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2082. {
  2083. const bool U = true;
  2084. /* Decode Vector */
  2085. int d = (int)UInt(Rd);
  2086. int n = (int)UInt(Rn);
  2087. /* if size:Q == '110' then ReservedValue(); */
  2088. int esize = 8 << (int)UInt(size);
  2089. int datasize = (Q ? 128 : 64);
  2090. int elements = datasize / esize;
  2091. bool neg = (U == true);
  2092. /* Operation */
  2093. /* CheckFPAdvSIMDEnabled64(); */
  2094. Bits result = new Bits(datasize);
  2095. Bits operand = V(datasize, n);
  2096. BigInteger element;
  2097. for (int e = 0; e <= elements - 1; e++)
  2098. {
  2099. element = SInt(Elem(operand, e, esize));
  2100. if (neg)
  2101. {
  2102. element = -element;
  2103. }
  2104. else
  2105. {
  2106. element = Abs(element);
  2107. }
  2108. Elem(result, e, esize, element.SubBigInteger(esize - 1, 0));
  2109. }
  2110. V(d, result);
  2111. }
  2112. // not_advsimd.html
  2113. public static void Not_V(bool Q, Bits Rn, Bits Rd)
  2114. {
  2115. /* Decode Vector */
  2116. int d = (int)UInt(Rd);
  2117. int n = (int)UInt(Rn);
  2118. int esize = 8;
  2119. int datasize = (Q ? 128 : 64);
  2120. int elements = datasize / 8;
  2121. /* Operation */
  2122. /* CheckFPAdvSIMDEnabled64(); */
  2123. Bits result = new Bits(datasize);
  2124. Bits operand = V(datasize, n);
  2125. Bits element;
  2126. for (int e = 0; e <= elements - 1; e++)
  2127. {
  2128. element = Elem(operand, e, esize);
  2129. Elem(result, e, esize, NOT(element));
  2130. }
  2131. V(d, result);
  2132. }
  2133. // rbit_advsimd.html
  2134. public static void Rbit_V(bool Q, Bits Rn, Bits Rd)
  2135. {
  2136. /* Decode Vector */
  2137. int d = (int)UInt(Rd);
  2138. int n = (int)UInt(Rn);
  2139. int esize = 8;
  2140. int datasize = (Q ? 128 : 64);
  2141. int elements = datasize / 8;
  2142. /* Operation */
  2143. /* CheckFPAdvSIMDEnabled64(); */
  2144. Bits result = new Bits(datasize);
  2145. Bits operand = V(datasize, n);
  2146. Bits element;
  2147. Bits rev = new Bits(esize);
  2148. for (int e = 0; e <= elements - 1; e++)
  2149. {
  2150. element = Elem(operand, e, esize);
  2151. for (int i = 0; i <= esize - 1; i++)
  2152. {
  2153. rev[esize - 1 - i] = element[i];
  2154. }
  2155. Elem(result, e, esize, rev);
  2156. }
  2157. V(d, result);
  2158. }
  2159. // rev16_advsimd.html
  2160. public static void Rev16_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2161. {
  2162. const bool U = false;
  2163. const bool o0 = true;
  2164. /* Decode Vector */
  2165. int d = (int)UInt(Rd);
  2166. int n = (int)UInt(Rn);
  2167. // size=esize: B(0), H(1), S(1), D(S)
  2168. int esize = 8 << (int)UInt(size);
  2169. int datasize = (Q ? 128 : 64);
  2170. // op=REVx: 64(0), 32(1), 16(2)
  2171. Bits op = Bits.Concat(o0, U);
  2172. // => op+size:
  2173. // 64+B = 0, 64+H = 1, 64+S = 2, 64+D = X
  2174. // 32+B = 1, 32+H = 2, 32+S = X, 32+D = X
  2175. // 16+B = 2, 16+H = X, 16+S = X, 16+D = X
  2176. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2177. // => 3-(op+size) (index bits in group)
  2178. // 64/B = 3, 64+H = 2, 64+S = 1, 64+D = X
  2179. // 32+B = 2, 32+H = 1, 32+S = X, 32+D = X
  2180. // 16+B = 1, 16+H = X, 16+S = X, 16+D = X
  2181. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2182. // index bits within group: 1, 2, 3
  2183. /* if UInt(op) + UInt(size) >= 3 then UnallocatedEncoding(); */
  2184. int container_size;
  2185. switch (op)
  2186. {
  2187. default:
  2188. case Bits bits when bits == "10":
  2189. container_size = 16;
  2190. break;
  2191. case Bits bits when bits == "01":
  2192. container_size = 32;
  2193. break;
  2194. case Bits bits when bits == "00":
  2195. container_size = 64;
  2196. break;
  2197. }
  2198. int containers = datasize / container_size;
  2199. int elements_per_container = container_size / esize;
  2200. /* Operation */
  2201. /* CheckFPAdvSIMDEnabled64(); */
  2202. Bits result = new Bits(datasize);
  2203. Bits operand = V(datasize, n);
  2204. int element = 0;
  2205. int rev_element;
  2206. for (int c = 0; c <= containers - 1; c++)
  2207. {
  2208. rev_element = element + elements_per_container - 1;
  2209. for (int e = 0; e <= elements_per_container - 1; e++)
  2210. {
  2211. Elem(result, rev_element, esize, Elem(operand, element, esize));
  2212. element = element + 1;
  2213. rev_element = rev_element - 1;
  2214. }
  2215. }
  2216. V(d, result);
  2217. }
  2218. // rev32_advsimd.html
  2219. public static void Rev32_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2220. {
  2221. const bool U = true;
  2222. const bool o0 = false;
  2223. /* Decode Vector */
  2224. int d = (int)UInt(Rd);
  2225. int n = (int)UInt(Rn);
  2226. // size=esize: B(0), H(1), S(1), D(S)
  2227. int esize = 8 << (int)UInt(size);
  2228. int datasize = (Q ? 128 : 64);
  2229. // op=REVx: 64(0), 32(1), 16(2)
  2230. Bits op = Bits.Concat(o0, U);
  2231. // => op+size:
  2232. // 64+B = 0, 64+H = 1, 64+S = 2, 64+D = X
  2233. // 32+B = 1, 32+H = 2, 32+S = X, 32+D = X
  2234. // 16+B = 2, 16+H = X, 16+S = X, 16+D = X
  2235. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2236. // => 3-(op+size) (index bits in group)
  2237. // 64/B = 3, 64+H = 2, 64+S = 1, 64+D = X
  2238. // 32+B = 2, 32+H = 1, 32+S = X, 32+D = X
  2239. // 16+B = 1, 16+H = X, 16+S = X, 16+D = X
  2240. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2241. // index bits within group: 1, 2, 3
  2242. /* if UInt(op) + UInt(size) >= 3 then UnallocatedEncoding(); */
  2243. int container_size;
  2244. switch (op)
  2245. {
  2246. case Bits bits when bits == "10":
  2247. container_size = 16;
  2248. break;
  2249. default:
  2250. case Bits bits when bits == "01":
  2251. container_size = 32;
  2252. break;
  2253. case Bits bits when bits == "00":
  2254. container_size = 64;
  2255. break;
  2256. }
  2257. int containers = datasize / container_size;
  2258. int elements_per_container = container_size / esize;
  2259. /* Operation */
  2260. /* CheckFPAdvSIMDEnabled64(); */
  2261. Bits result = new Bits(datasize);
  2262. Bits operand = V(datasize, n);
  2263. int element = 0;
  2264. int rev_element;
  2265. for (int c = 0; c <= containers - 1; c++)
  2266. {
  2267. rev_element = element + elements_per_container - 1;
  2268. for (int e = 0; e <= elements_per_container - 1; e++)
  2269. {
  2270. Elem(result, rev_element, esize, Elem(operand, element, esize));
  2271. element = element + 1;
  2272. rev_element = rev_element - 1;
  2273. }
  2274. }
  2275. V(d, result);
  2276. }
  2277. // rev64_advsimd.html
  2278. public static void Rev64_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2279. {
  2280. const bool U = false;
  2281. const bool o0 = false;
  2282. /* Decode Vector */
  2283. int d = (int)UInt(Rd);
  2284. int n = (int)UInt(Rn);
  2285. // size=esize: B(0), H(1), S(1), D(S)
  2286. int esize = 8 << (int)UInt(size);
  2287. int datasize = (Q ? 128 : 64);
  2288. // op=REVx: 64(0), 32(1), 16(2)
  2289. Bits op = Bits.Concat(o0, U);
  2290. // => op+size:
  2291. // 64+B = 0, 64+H = 1, 64+S = 2, 64+D = X
  2292. // 32+B = 1, 32+H = 2, 32+S = X, 32+D = X
  2293. // 16+B = 2, 16+H = X, 16+S = X, 16+D = X
  2294. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2295. // => 3-(op+size) (index bits in group)
  2296. // 64/B = 3, 64+H = 2, 64+S = 1, 64+D = X
  2297. // 32+B = 2, 32+H = 1, 32+S = X, 32+D = X
  2298. // 16+B = 1, 16+H = X, 16+S = X, 16+D = X
  2299. // 8+B = X, 8+H = X, 8+S = X, 8+D = X
  2300. // index bits within group: 1, 2, 3
  2301. /* if UInt(op) + UInt(size) >= 3 then UnallocatedEncoding(); */
  2302. int container_size;
  2303. switch (op)
  2304. {
  2305. case Bits bits when bits == "10":
  2306. container_size = 16;
  2307. break;
  2308. case Bits bits when bits == "01":
  2309. container_size = 32;
  2310. break;
  2311. default:
  2312. case Bits bits when bits == "00":
  2313. container_size = 64;
  2314. break;
  2315. }
  2316. int containers = datasize / container_size;
  2317. int elements_per_container = container_size / esize;
  2318. /* Operation */
  2319. /* CheckFPAdvSIMDEnabled64(); */
  2320. Bits result = new Bits(datasize);
  2321. Bits operand = V(datasize, n);
  2322. int element = 0;
  2323. int rev_element;
  2324. for (int c = 0; c <= containers - 1; c++)
  2325. {
  2326. rev_element = element + elements_per_container - 1;
  2327. for (int e = 0; e <= elements_per_container - 1; e++)
  2328. {
  2329. Elem(result, rev_element, esize, Elem(operand, element, esize));
  2330. element = element + 1;
  2331. rev_element = rev_element - 1;
  2332. }
  2333. }
  2334. V(d, result);
  2335. }
  2336. // sqabs_advsimd.html#SQABS_asisdmisc_R
  2337. public static void Sqabs_S(Bits size, Bits Rn, Bits Rd)
  2338. {
  2339. const bool U = false;
  2340. /* Decode Scalar */
  2341. int d = (int)UInt(Rd);
  2342. int n = (int)UInt(Rn);
  2343. int esize = 8 << (int)UInt(size);
  2344. int datasize = esize;
  2345. int elements = 1;
  2346. bool neg = (U == true);
  2347. /* Operation */
  2348. /* CheckFPAdvSIMDEnabled64(); */
  2349. Bits result = new Bits(datasize);
  2350. Bits operand = V(datasize, n);
  2351. BigInteger element;
  2352. bool sat;
  2353. for (int e = 0; e <= elements - 1; e++)
  2354. {
  2355. element = SInt(Elem(operand, e, esize));
  2356. if (neg)
  2357. {
  2358. element = -element;
  2359. }
  2360. else
  2361. {
  2362. element = Abs(element);
  2363. }
  2364. (Bits _result, bool _sat) = SignedSatQ(element, esize);
  2365. Elem(result, e, esize, _result);
  2366. sat = _sat;
  2367. if (sat)
  2368. {
  2369. /* FPSR.QC = '1'; */
  2370. FPSR[27] = true; // TODO: Add named fields.
  2371. }
  2372. }
  2373. V(d, result);
  2374. }
  2375. // sqabs_advsimd.html#SQABS_asimdmisc_R
  2376. public static void Sqabs_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2377. {
  2378. const bool U = false;
  2379. /* Decode Vector */
  2380. int d = (int)UInt(Rd);
  2381. int n = (int)UInt(Rn);
  2382. /* if size:Q == '110' then ReservedValue(); */
  2383. int esize = 8 << (int)UInt(size);
  2384. int datasize = (Q ? 128 : 64);
  2385. int elements = datasize / esize;
  2386. bool neg = (U == true);
  2387. /* Operation */
  2388. /* CheckFPAdvSIMDEnabled64(); */
  2389. Bits result = new Bits(datasize);
  2390. Bits operand = V(datasize, n);
  2391. BigInteger element;
  2392. bool sat;
  2393. for (int e = 0; e <= elements - 1; e++)
  2394. {
  2395. element = SInt(Elem(operand, e, esize));
  2396. if (neg)
  2397. {
  2398. element = -element;
  2399. }
  2400. else
  2401. {
  2402. element = Abs(element);
  2403. }
  2404. (Bits _result, bool _sat) = SignedSatQ(element, esize);
  2405. Elem(result, e, esize, _result);
  2406. sat = _sat;
  2407. if (sat)
  2408. {
  2409. /* FPSR.QC = '1'; */
  2410. FPSR[27] = true; // TODO: Add named fields.
  2411. }
  2412. }
  2413. V(d, result);
  2414. }
  2415. // sqneg_advsimd.html#SQNEG_asisdmisc_R
  2416. public static void Sqneg_S(Bits size, Bits Rn, Bits Rd)
  2417. {
  2418. const bool U = true;
  2419. /* Decode Scalar */
  2420. int d = (int)UInt(Rd);
  2421. int n = (int)UInt(Rn);
  2422. int esize = 8 << (int)UInt(size);
  2423. int datasize = esize;
  2424. int elements = 1;
  2425. bool neg = (U == true);
  2426. /* Operation */
  2427. /* CheckFPAdvSIMDEnabled64(); */
  2428. Bits result = new Bits(datasize);
  2429. Bits operand = V(datasize, n);
  2430. BigInteger element;
  2431. bool sat;
  2432. for (int e = 0; e <= elements - 1; e++)
  2433. {
  2434. element = SInt(Elem(operand, e, esize));
  2435. if (neg)
  2436. {
  2437. element = -element;
  2438. }
  2439. else
  2440. {
  2441. element = Abs(element);
  2442. }
  2443. (Bits _result, bool _sat) = SignedSatQ(element, esize);
  2444. Elem(result, e, esize, _result);
  2445. sat = _sat;
  2446. if (sat)
  2447. {
  2448. /* FPSR.QC = '1'; */
  2449. FPSR[27] = true; // TODO: Add named fields.
  2450. }
  2451. }
  2452. V(d, result);
  2453. }
  2454. // sqneg_advsimd.html#SQNEG_asimdmisc_R
  2455. public static void Sqneg_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2456. {
  2457. const bool U = true;
  2458. /* Decode Vector */
  2459. int d = (int)UInt(Rd);
  2460. int n = (int)UInt(Rn);
  2461. /* if size:Q == '110' then ReservedValue(); */
  2462. int esize = 8 << (int)UInt(size);
  2463. int datasize = (Q ? 128 : 64);
  2464. int elements = datasize / esize;
  2465. bool neg = (U == true);
  2466. /* Operation */
  2467. /* CheckFPAdvSIMDEnabled64(); */
  2468. Bits result = new Bits(datasize);
  2469. Bits operand = V(datasize, n);
  2470. BigInteger element;
  2471. bool sat;
  2472. for (int e = 0; e <= elements - 1; e++)
  2473. {
  2474. element = SInt(Elem(operand, e, esize));
  2475. if (neg)
  2476. {
  2477. element = -element;
  2478. }
  2479. else
  2480. {
  2481. element = Abs(element);
  2482. }
  2483. (Bits _result, bool _sat) = SignedSatQ(element, esize);
  2484. Elem(result, e, esize, _result);
  2485. sat = _sat;
  2486. if (sat)
  2487. {
  2488. /* FPSR.QC = '1'; */
  2489. FPSR[27] = true; // TODO: Add named fields.
  2490. }
  2491. }
  2492. V(d, result);
  2493. }
  2494. // sqxtn_advsimd.html#SQXTN_asisdmisc_N
  2495. public static void Sqxtn_S(Bits size, Bits Rn, Bits Rd)
  2496. {
  2497. const bool U = false;
  2498. /* Decode Scalar */
  2499. int d = (int)UInt(Rd);
  2500. int n = (int)UInt(Rn);
  2501. /* if size == '11' then ReservedValue(); */
  2502. int esize = 8 << (int)UInt(size);
  2503. int datasize = esize;
  2504. int part = 0;
  2505. int elements = 1;
  2506. bool unsigned = (U == true);
  2507. /* Operation */
  2508. /* CheckFPAdvSIMDEnabled64(); */
  2509. Bits result = new Bits(datasize);
  2510. Bits operand = V(2 * datasize, n);
  2511. Bits element;
  2512. bool sat;
  2513. for (int e = 0; e <= elements - 1; e++)
  2514. {
  2515. element = Elem(operand, e, 2 * esize);
  2516. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2517. Elem(result, e, esize, _result);
  2518. sat = _sat;
  2519. if (sat)
  2520. {
  2521. /* FPSR.QC = '1'; */
  2522. FPSR[27] = true; // TODO: Add named fields.
  2523. }
  2524. }
  2525. Vpart(d, part, result);
  2526. }
  2527. // sqxtn_advsimd.html#SQXTN_asimdmisc_N
  2528. public static void Sqxtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2529. {
  2530. const bool U = false;
  2531. /* Decode Vector */
  2532. int d = (int)UInt(Rd);
  2533. int n = (int)UInt(Rn);
  2534. /* if size == '11' then ReservedValue(); */
  2535. int esize = 8 << (int)UInt(size);
  2536. int datasize = 64;
  2537. int part = (int)UInt(Q);
  2538. int elements = datasize / esize;
  2539. bool unsigned = (U == true);
  2540. /* Operation */
  2541. /* CheckFPAdvSIMDEnabled64(); */
  2542. Bits result = new Bits(datasize);
  2543. Bits operand = V(2 * datasize, n);
  2544. Bits element;
  2545. bool sat;
  2546. for (int e = 0; e <= elements - 1; e++)
  2547. {
  2548. element = Elem(operand, e, 2 * esize);
  2549. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2550. Elem(result, e, esize, _result);
  2551. sat = _sat;
  2552. if (sat)
  2553. {
  2554. /* FPSR.QC = '1'; */
  2555. FPSR[27] = true; // TODO: Add named fields.
  2556. }
  2557. }
  2558. Vpart(d, part, result);
  2559. }
  2560. // sqxtun_advsimd.html#SQXTUN_asisdmisc_N
  2561. public static void Sqxtun_S(Bits size, Bits Rn, Bits Rd)
  2562. {
  2563. /* Decode Scalar */
  2564. int d = (int)UInt(Rd);
  2565. int n = (int)UInt(Rn);
  2566. /* if size == '11' then ReservedValue(); */
  2567. int esize = 8 << (int)UInt(size);
  2568. int datasize = esize;
  2569. int part = 0;
  2570. int elements = 1;
  2571. /* Operation */
  2572. /* CheckFPAdvSIMDEnabled64(); */
  2573. Bits result = new Bits(datasize);
  2574. Bits operand = V(2 * datasize, n);
  2575. Bits element;
  2576. bool sat;
  2577. for (int e = 0; e <= elements - 1; e++)
  2578. {
  2579. element = Elem(operand, e, 2 * esize);
  2580. (Bits _result, bool _sat) = UnsignedSatQ(SInt(element), esize);
  2581. Elem(result, e, esize, _result);
  2582. sat = _sat;
  2583. if (sat)
  2584. {
  2585. /* FPSR.QC = '1'; */
  2586. FPSR[27] = true; // TODO: Add named fields.
  2587. }
  2588. }
  2589. Vpart(d, part, result);
  2590. }
  2591. // sqxtun_advsimd.html#SQXTUN_asimdmisc_N
  2592. public static void Sqxtun_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2593. {
  2594. /* Decode Vector */
  2595. int d = (int)UInt(Rd);
  2596. int n = (int)UInt(Rn);
  2597. /* if size == '11' then ReservedValue(); */
  2598. int esize = 8 << (int)UInt(size);
  2599. int datasize = 64;
  2600. int part = (int)UInt(Q);
  2601. int elements = datasize / esize;
  2602. /* Operation */
  2603. /* CheckFPAdvSIMDEnabled64(); */
  2604. Bits result = new Bits(datasize);
  2605. Bits operand = V(2 * datasize, n);
  2606. Bits element;
  2607. bool sat;
  2608. for (int e = 0; e <= elements - 1; e++)
  2609. {
  2610. element = Elem(operand, e, 2 * esize);
  2611. (Bits _result, bool _sat) = UnsignedSatQ(SInt(element), esize);
  2612. Elem(result, e, esize, _result);
  2613. sat = _sat;
  2614. if (sat)
  2615. {
  2616. /* FPSR.QC = '1'; */
  2617. FPSR[27] = true; // TODO: Add named fields.
  2618. }
  2619. }
  2620. Vpart(d, part, result);
  2621. }
  2622. // suqadd_advsimd.html#SUQADD_asisdmisc_R
  2623. public static void Suqadd_S(Bits size, Bits Rn, Bits Rd)
  2624. {
  2625. const bool U = false;
  2626. /* Decode Scalar */
  2627. int d = (int)UInt(Rd);
  2628. int n = (int)UInt(Rn);
  2629. int esize = 8 << (int)UInt(size);
  2630. int datasize = esize;
  2631. int elements = 1;
  2632. bool unsigned = (U == true);
  2633. /* Operation */
  2634. /* CheckFPAdvSIMDEnabled64(); */
  2635. Bits result = new Bits(datasize);
  2636. Bits operand = V(datasize, n);
  2637. Bits operand2 = V(datasize, d);
  2638. BigInteger op1;
  2639. BigInteger op2;
  2640. bool sat;
  2641. for (int e = 0; e <= elements - 1; e++)
  2642. {
  2643. op1 = Int(Elem(operand, e, esize), !unsigned);
  2644. op2 = Int(Elem(operand2, e, esize), unsigned);
  2645. (Bits _result, bool _sat) = SatQ(op1 + op2, esize, unsigned);
  2646. Elem(result, e, esize, _result);
  2647. sat = _sat;
  2648. if (sat)
  2649. {
  2650. /* FPSR.QC = '1'; */
  2651. FPSR[27] = true; // TODO: Add named fields.
  2652. }
  2653. }
  2654. V(d, result);
  2655. }
  2656. // suqadd_advsimd.html#SUQADD_asimdmisc_R
  2657. public static void Suqadd_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2658. {
  2659. const bool U = false;
  2660. /* Decode Vector */
  2661. int d = (int)UInt(Rd);
  2662. int n = (int)UInt(Rn);
  2663. /* if size:Q == '110' then ReservedValue(); */
  2664. int esize = 8 << (int)UInt(size);
  2665. int datasize = (Q ? 128 : 64);
  2666. int elements = datasize / esize;
  2667. bool unsigned = (U == true);
  2668. /* Operation */
  2669. /* CheckFPAdvSIMDEnabled64(); */
  2670. Bits result = new Bits(datasize);
  2671. Bits operand = V(datasize, n);
  2672. Bits operand2 = V(datasize, d);
  2673. BigInteger op1;
  2674. BigInteger op2;
  2675. bool sat;
  2676. for (int e = 0; e <= elements - 1; e++)
  2677. {
  2678. op1 = Int(Elem(operand, e, esize), !unsigned);
  2679. op2 = Int(Elem(operand2, e, esize), unsigned);
  2680. (Bits _result, bool _sat) = SatQ(op1 + op2, esize, unsigned);
  2681. Elem(result, e, esize, _result);
  2682. sat = _sat;
  2683. if (sat)
  2684. {
  2685. /* FPSR.QC = '1'; */
  2686. FPSR[27] = true; // TODO: Add named fields.
  2687. }
  2688. }
  2689. V(d, result);
  2690. }
  2691. // uqxtn_advsimd.html#UQXTN_asisdmisc_N
  2692. public static void Uqxtn_S(Bits size, Bits Rn, Bits Rd)
  2693. {
  2694. const bool U = true;
  2695. /* Decode Scalar */
  2696. int d = (int)UInt(Rd);
  2697. int n = (int)UInt(Rn);
  2698. /* if size == '11' then ReservedValue(); */
  2699. int esize = 8 << (int)UInt(size);
  2700. int datasize = esize;
  2701. int part = 0;
  2702. int elements = 1;
  2703. bool unsigned = (U == true);
  2704. /* Operation */
  2705. /* CheckFPAdvSIMDEnabled64(); */
  2706. Bits result = new Bits(datasize);
  2707. Bits operand = V(2 * datasize, n);
  2708. Bits element;
  2709. bool sat;
  2710. for (int e = 0; e <= elements - 1; e++)
  2711. {
  2712. element = Elem(operand, e, 2 * esize);
  2713. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2714. Elem(result, e, esize, _result);
  2715. sat = _sat;
  2716. if (sat)
  2717. {
  2718. /* FPSR.QC = '1'; */
  2719. FPSR[27] = true; // TODO: Add named fields.
  2720. }
  2721. }
  2722. Vpart(d, part, result);
  2723. }
  2724. // uqxtn_advsimd.html#UQXTN_asimdmisc_N
  2725. public static void Uqxtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2726. {
  2727. const bool U = true;
  2728. /* Decode Vector */
  2729. int d = (int)UInt(Rd);
  2730. int n = (int)UInt(Rn);
  2731. /* if size == '11' then ReservedValue(); */
  2732. int esize = 8 << (int)UInt(size);
  2733. int datasize = 64;
  2734. int part = (int)UInt(Q);
  2735. int elements = datasize / esize;
  2736. bool unsigned = (U == true);
  2737. /* Operation */
  2738. /* CheckFPAdvSIMDEnabled64(); */
  2739. Bits result = new Bits(datasize);
  2740. Bits operand = V(2 * datasize, n);
  2741. Bits element;
  2742. bool sat;
  2743. for (int e = 0; e <= elements - 1; e++)
  2744. {
  2745. element = Elem(operand, e, 2 * esize);
  2746. (Bits _result, bool _sat) = SatQ(Int(element, unsigned), esize, unsigned);
  2747. Elem(result, e, esize, _result);
  2748. sat = _sat;
  2749. if (sat)
  2750. {
  2751. /* FPSR.QC = '1'; */
  2752. FPSR[27] = true; // TODO: Add named fields.
  2753. }
  2754. }
  2755. Vpart(d, part, result);
  2756. }
  2757. // usqadd_advsimd.html#USQADD_asisdmisc_R
  2758. public static void Usqadd_S(Bits size, Bits Rn, Bits Rd)
  2759. {
  2760. const bool U = true;
  2761. /* Decode Scalar */
  2762. int d = (int)UInt(Rd);
  2763. int n = (int)UInt(Rn);
  2764. int esize = 8 << (int)UInt(size);
  2765. int datasize = esize;
  2766. int elements = 1;
  2767. bool unsigned = (U == true);
  2768. /* Operation */
  2769. /* CheckFPAdvSIMDEnabled64(); */
  2770. Bits result = new Bits(datasize);
  2771. Bits operand = V(datasize, n);
  2772. Bits operand2 = V(datasize, d);
  2773. BigInteger op1;
  2774. BigInteger op2;
  2775. bool sat;
  2776. for (int e = 0; e <= elements - 1; e++)
  2777. {
  2778. op1 = Int(Elem(operand, e, esize), !unsigned);
  2779. op2 = Int(Elem(operand2, e, esize), unsigned);
  2780. (Bits _result, bool _sat) = SatQ(op1 + op2, esize, unsigned);
  2781. Elem(result, e, esize, _result);
  2782. sat = _sat;
  2783. if (sat)
  2784. {
  2785. /* FPSR.QC = '1'; */
  2786. FPSR[27] = true; // TODO: Add named fields.
  2787. }
  2788. }
  2789. V(d, result);
  2790. }
  2791. // usqadd_advsimd.html#USQADD_asimdmisc_R
  2792. public static void Usqadd_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2793. {
  2794. const bool U = true;
  2795. /* Decode Vector */
  2796. int d = (int)UInt(Rd);
  2797. int n = (int)UInt(Rn);
  2798. /* if size:Q == '110' then ReservedValue(); */
  2799. int esize = 8 << (int)UInt(size);
  2800. int datasize = (Q ? 128 : 64);
  2801. int elements = datasize / esize;
  2802. bool unsigned = (U == true);
  2803. /* Operation */
  2804. /* CheckFPAdvSIMDEnabled64(); */
  2805. Bits result = new Bits(datasize);
  2806. Bits operand = V(datasize, n);
  2807. Bits operand2 = V(datasize, d);
  2808. BigInteger op1;
  2809. BigInteger op2;
  2810. bool sat;
  2811. for (int e = 0; e <= elements - 1; e++)
  2812. {
  2813. op1 = Int(Elem(operand, e, esize), !unsigned);
  2814. op2 = Int(Elem(operand2, e, esize), unsigned);
  2815. (Bits _result, bool _sat) = SatQ(op1 + op2, esize, unsigned);
  2816. Elem(result, e, esize, _result);
  2817. sat = _sat;
  2818. if (sat)
  2819. {
  2820. /* FPSR.QC = '1'; */
  2821. FPSR[27] = true; // TODO: Add named fields.
  2822. }
  2823. }
  2824. V(d, result);
  2825. }
  2826. // xtn_advsimd.html
  2827. public static void Xtn_V(bool Q, Bits size, Bits Rn, Bits Rd)
  2828. {
  2829. /* Decode Vector */
  2830. int d = (int)UInt(Rd);
  2831. int n = (int)UInt(Rn);
  2832. /* if size == '11' then ReservedValue(); */
  2833. int esize = 8 << (int)UInt(size);
  2834. int datasize = 64;
  2835. int part = (int)UInt(Q);
  2836. int elements = datasize / esize;
  2837. /* Operation */
  2838. /* CheckFPAdvSIMDEnabled64(); */
  2839. Bits result = new Bits(datasize);
  2840. Bits operand = V(2 * datasize, n);
  2841. Bits element;
  2842. for (int e = 0; e <= elements - 1; e++)
  2843. {
  2844. element = Elem(operand, e, 2 * esize);
  2845. Elem(result, e, esize, element[esize - 1, 0]);
  2846. }
  2847. Vpart(d, part, result);
  2848. }
  2849. #endregion
  2850. #region "SimdReg"
  2851. // add_advsimd.html#ADD_asisdsame_only
  2852. public static void Add_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  2853. {
  2854. const bool U = false;
  2855. /* Decode Scalar */
  2856. int d = (int)UInt(Rd);
  2857. int n = (int)UInt(Rn);
  2858. int m = (int)UInt(Rm);
  2859. /* if size != '11' then ReservedValue(); */
  2860. int esize = 8 << (int)UInt(size);
  2861. int datasize = esize;
  2862. int elements = 1;
  2863. bool sub_op = (U == true);
  2864. /* Operation */
  2865. /* CheckFPAdvSIMDEnabled64(); */
  2866. Bits result = new Bits(datasize);
  2867. Bits operand1 = V(datasize, n);
  2868. Bits operand2 = V(datasize, m);
  2869. Bits element1;
  2870. Bits element2;
  2871. for (int e = 0; e <= elements - 1; e++)
  2872. {
  2873. element1 = Elem(operand1, e, esize);
  2874. element2 = Elem(operand2, e, esize);
  2875. if (sub_op)
  2876. {
  2877. Elem(result, e, esize, element1 - element2);
  2878. }
  2879. else
  2880. {
  2881. Elem(result, e, esize, element1 + element2);
  2882. }
  2883. }
  2884. V(d, result);
  2885. }
  2886. // add_advsimd.html#ADD_asimdsame_only
  2887. public static void Add_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2888. {
  2889. const bool U = false;
  2890. /* Decode Vector */
  2891. int d = (int)UInt(Rd);
  2892. int n = (int)UInt(Rn);
  2893. int m = (int)UInt(Rm);
  2894. /* if size:Q == '110' then ReservedValue(); */
  2895. int esize = 8 << (int)UInt(size);
  2896. int datasize = (Q ? 128 : 64);
  2897. int elements = datasize / esize;
  2898. bool sub_op = (U == true);
  2899. /* Operation */
  2900. /* CheckFPAdvSIMDEnabled64(); */
  2901. Bits result = new Bits(datasize);
  2902. Bits operand1 = V(datasize, n);
  2903. Bits operand2 = V(datasize, m);
  2904. Bits element1;
  2905. Bits element2;
  2906. for (int e = 0; e <= elements - 1; e++)
  2907. {
  2908. element1 = Elem(operand1, e, esize);
  2909. element2 = Elem(operand2, e, esize);
  2910. if (sub_op)
  2911. {
  2912. Elem(result, e, esize, element1 - element2);
  2913. }
  2914. else
  2915. {
  2916. Elem(result, e, esize, element1 + element2);
  2917. }
  2918. }
  2919. V(d, result);
  2920. }
  2921. // addhn_advsimd.html
  2922. public static void Addhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2923. {
  2924. const bool U = false;
  2925. const bool o1 = false;
  2926. /* Decode */
  2927. int d = (int)UInt(Rd);
  2928. int n = (int)UInt(Rn);
  2929. int m = (int)UInt(Rm);
  2930. /* if size == '11' then ReservedValue(); */
  2931. int esize = 8 << (int)UInt(size);
  2932. int datasize = 64;
  2933. int part = (int)UInt(Q);
  2934. int elements = datasize / esize;
  2935. bool sub_op = (o1 == true);
  2936. bool round = (U == true);
  2937. /* Operation */
  2938. /* CheckFPAdvSIMDEnabled64(); */
  2939. Bits result = new Bits(datasize);
  2940. Bits operand1 = V(2 * datasize, n);
  2941. Bits operand2 = V(2 * datasize, m);
  2942. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  2943. Bits sum;
  2944. Bits element1;
  2945. Bits element2;
  2946. for (int e = 0; e <= elements - 1; e++)
  2947. {
  2948. element1 = Elem(operand1, e, 2 * esize);
  2949. element2 = Elem(operand2, e, 2 * esize);
  2950. if (sub_op)
  2951. {
  2952. sum = element1 - element2;
  2953. }
  2954. else
  2955. {
  2956. sum = element1 + element2;
  2957. }
  2958. sum = sum + round_const;
  2959. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  2960. }
  2961. Vpart(d, part, result);
  2962. }
  2963. // addp_advsimd_vec.html
  2964. public static void Addp_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  2965. {
  2966. /* Decode */
  2967. int d = (int)UInt(Rd);
  2968. int n = (int)UInt(Rn);
  2969. int m = (int)UInt(Rm);
  2970. /* if size:Q == '110' then ReservedValue(); */
  2971. int esize = 8 << (int)UInt(size);
  2972. int datasize = (Q ? 128 : 64);
  2973. int elements = datasize / esize;
  2974. /* Operation */
  2975. /* CheckFPAdvSIMDEnabled64(); */
  2976. Bits result = new Bits(datasize);
  2977. Bits operand1 = V(datasize, n);
  2978. Bits operand2 = V(datasize, m);
  2979. Bits concat = Bits.Concat(operand2, operand1);
  2980. Bits element1;
  2981. Bits element2;
  2982. for (int e = 0; e <= elements - 1; e++)
  2983. {
  2984. element1 = Elem(concat, 2 * e, esize);
  2985. element2 = Elem(concat, (2 * e) + 1, esize);
  2986. Elem(result, e, esize, element1 + element2);
  2987. }
  2988. V(d, result);
  2989. }
  2990. // and_advsimd.html
  2991. public static void And_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  2992. {
  2993. /* Decode */
  2994. int d = (int)UInt(Rd);
  2995. int n = (int)UInt(Rn);
  2996. int m = (int)UInt(Rm);
  2997. int datasize = (Q ? 128 : 64);
  2998. /* Operation */
  2999. /* CheckFPAdvSIMDEnabled64(); */
  3000. Bits operand1 = V(datasize, n);
  3001. Bits operand2 = V(datasize, m);
  3002. Bits result = AND(operand1, operand2);
  3003. V(d, result);
  3004. }
  3005. // bic_advsimd_reg.html
  3006. public static void Bic_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3007. {
  3008. /* Decode */
  3009. int d = (int)UInt(Rd);
  3010. int n = (int)UInt(Rn);
  3011. int m = (int)UInt(Rm);
  3012. int datasize = (Q ? 128 : 64);
  3013. /* Operation */
  3014. /* CheckFPAdvSIMDEnabled64(); */
  3015. Bits operand1 = V(datasize, n);
  3016. Bits operand2 = V(datasize, m);
  3017. operand2 = NOT(operand2);
  3018. Bits result = AND(operand1, operand2);
  3019. V(d, result);
  3020. }
  3021. // bif_advsimd.html
  3022. public static void Bif_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3023. {
  3024. /* Decode */
  3025. int d = (int)UInt(Rd);
  3026. int n = (int)UInt(Rn);
  3027. int m = (int)UInt(Rm);
  3028. int datasize = (Q ? 128 : 64);
  3029. /* Operation */
  3030. /* CheckFPAdvSIMDEnabled64(); */
  3031. Bits operand1;
  3032. Bits operand3;
  3033. Bits operand4 = V(datasize, n);
  3034. operand1 = V(datasize, d);
  3035. operand3 = NOT(V(datasize, m));
  3036. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  3037. }
  3038. // bit_advsimd.html
  3039. public static void Bit_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3040. {
  3041. /* Decode */
  3042. int d = (int)UInt(Rd);
  3043. int n = (int)UInt(Rn);
  3044. int m = (int)UInt(Rm);
  3045. int datasize = (Q ? 128 : 64);
  3046. /* Operation */
  3047. /* CheckFPAdvSIMDEnabled64(); */
  3048. Bits operand1;
  3049. Bits operand3;
  3050. Bits operand4 = V(datasize, n);
  3051. operand1 = V(datasize, d);
  3052. operand3 = V(datasize, m);
  3053. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  3054. }
  3055. // bsl_advsimd.html
  3056. public static void Bsl_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3057. {
  3058. /* Decode */
  3059. int d = (int)UInt(Rd);
  3060. int n = (int)UInt(Rn);
  3061. int m = (int)UInt(Rm);
  3062. int datasize = (Q ? 128 : 64);
  3063. /* Operation */
  3064. /* CheckFPAdvSIMDEnabled64(); */
  3065. Bits operand1;
  3066. Bits operand3;
  3067. Bits operand4 = V(datasize, n);
  3068. operand1 = V(datasize, m);
  3069. operand3 = V(datasize, d);
  3070. V(d, EOR(operand1, AND(EOR(operand1, operand4), operand3)));
  3071. }
  3072. // cmeq_advsimd_reg.html#CMEQ_asisdsame_only
  3073. public static void Cmeq_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3074. {
  3075. const bool U = true;
  3076. /* Decode Scalar */
  3077. int d = (int)UInt(Rd);
  3078. int n = (int)UInt(Rn);
  3079. int m = (int)UInt(Rm);
  3080. /* if size != '11' then ReservedValue(); */
  3081. int esize = 8 << (int)UInt(size);
  3082. int datasize = esize;
  3083. int elements = 1;
  3084. bool and_test = (U == false);
  3085. /* Operation */
  3086. /* CheckFPAdvSIMDEnabled64(); */
  3087. Bits result = new Bits(datasize);
  3088. Bits operand1 = V(datasize, n);
  3089. Bits operand2 = V(datasize, m);
  3090. Bits element1;
  3091. Bits element2;
  3092. bool test_passed;
  3093. for (int e = 0; e <= elements - 1; e++)
  3094. {
  3095. element1 = Elem(operand1, e, esize);
  3096. element2 = Elem(operand2, e, esize);
  3097. if (and_test)
  3098. {
  3099. test_passed = !IsZero(AND(element1, element2));
  3100. }
  3101. else
  3102. {
  3103. test_passed = (element1 == element2);
  3104. }
  3105. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3106. }
  3107. V(d, result);
  3108. }
  3109. // cmeq_advsimd_reg.html#CMEQ_asimdsame_only
  3110. public static void Cmeq_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3111. {
  3112. const bool U = true;
  3113. /* Decode Vector */
  3114. int d = (int)UInt(Rd);
  3115. int n = (int)UInt(Rn);
  3116. int m = (int)UInt(Rm);
  3117. /* if size:Q == '110' then ReservedValue(); */
  3118. int esize = 8 << (int)UInt(size);
  3119. int datasize = (Q ? 128 : 64);
  3120. int elements = datasize / esize;
  3121. bool and_test = (U == false);
  3122. /* Operation */
  3123. /* CheckFPAdvSIMDEnabled64(); */
  3124. Bits result = new Bits(datasize);
  3125. Bits operand1 = V(datasize, n);
  3126. Bits operand2 = V(datasize, m);
  3127. Bits element1;
  3128. Bits element2;
  3129. bool test_passed;
  3130. for (int e = 0; e <= elements - 1; e++)
  3131. {
  3132. element1 = Elem(operand1, e, esize);
  3133. element2 = Elem(operand2, e, esize);
  3134. if (and_test)
  3135. {
  3136. test_passed = !IsZero(AND(element1, element2));
  3137. }
  3138. else
  3139. {
  3140. test_passed = (element1 == element2);
  3141. }
  3142. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3143. }
  3144. V(d, result);
  3145. }
  3146. // cmge_advsimd_reg.html#CMGE_asisdsame_only
  3147. public static void Cmge_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3148. {
  3149. const bool U = false;
  3150. const bool eq = true;
  3151. /* Decode Scalar */
  3152. int d = (int)UInt(Rd);
  3153. int n = (int)UInt(Rn);
  3154. int m = (int)UInt(Rm);
  3155. /* if size != '11' then ReservedValue(); */
  3156. int esize = 8 << (int)UInt(size);
  3157. int datasize = esize;
  3158. int elements = 1;
  3159. bool unsigned = (U == true);
  3160. bool cmp_eq = (eq == true);
  3161. /* Operation */
  3162. /* CheckFPAdvSIMDEnabled64(); */
  3163. Bits result = new Bits(datasize);
  3164. Bits operand1 = V(datasize, n);
  3165. Bits operand2 = V(datasize, m);
  3166. BigInteger element1;
  3167. BigInteger element2;
  3168. bool test_passed;
  3169. for (int e = 0; e <= elements - 1; e++)
  3170. {
  3171. element1 = Int(Elem(operand1, e, esize), unsigned);
  3172. element2 = Int(Elem(operand2, e, esize), unsigned);
  3173. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3174. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3175. }
  3176. V(d, result);
  3177. }
  3178. // cmge_advsimd_reg.html#CMGE_asimdsame_only
  3179. public static void Cmge_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3180. {
  3181. const bool U = false;
  3182. const bool eq = true;
  3183. /* Decode Vector */
  3184. int d = (int)UInt(Rd);
  3185. int n = (int)UInt(Rn);
  3186. int m = (int)UInt(Rm);
  3187. /* if size:Q == '110' then ReservedValue(); */
  3188. int esize = 8 << (int)UInt(size);
  3189. int datasize = (Q ? 128 : 64);
  3190. int elements = datasize / esize;
  3191. bool unsigned = (U == true);
  3192. bool cmp_eq = (eq == true);
  3193. /* Operation */
  3194. /* CheckFPAdvSIMDEnabled64(); */
  3195. Bits result = new Bits(datasize);
  3196. Bits operand1 = V(datasize, n);
  3197. Bits operand2 = V(datasize, m);
  3198. BigInteger element1;
  3199. BigInteger element2;
  3200. bool test_passed;
  3201. for (int e = 0; e <= elements - 1; e++)
  3202. {
  3203. element1 = Int(Elem(operand1, e, esize), unsigned);
  3204. element2 = Int(Elem(operand2, e, esize), unsigned);
  3205. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3206. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3207. }
  3208. V(d, result);
  3209. }
  3210. // cmgt_advsimd_reg.html#CMGT_asisdsame_only
  3211. public static void Cmgt_Reg_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3212. {
  3213. const bool U = false;
  3214. const bool eq = false;
  3215. /* Decode Scalar */
  3216. int d = (int)UInt(Rd);
  3217. int n = (int)UInt(Rn);
  3218. int m = (int)UInt(Rm);
  3219. /* if size != '11' then ReservedValue(); */
  3220. int esize = 8 << (int)UInt(size);
  3221. int datasize = esize;
  3222. int elements = 1;
  3223. bool unsigned = (U == true);
  3224. bool cmp_eq = (eq == true);
  3225. /* Operation */
  3226. /* CheckFPAdvSIMDEnabled64(); */
  3227. Bits result = new Bits(datasize);
  3228. Bits operand1 = V(datasize, n);
  3229. Bits operand2 = V(datasize, m);
  3230. BigInteger element1;
  3231. BigInteger element2;
  3232. bool test_passed;
  3233. for (int e = 0; e <= elements - 1; e++)
  3234. {
  3235. element1 = Int(Elem(operand1, e, esize), unsigned);
  3236. element2 = Int(Elem(operand2, e, esize), unsigned);
  3237. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3238. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3239. }
  3240. V(d, result);
  3241. }
  3242. // cmgt_advsimd_reg.html#CMGT_asimdsame_only
  3243. public static void Cmgt_Reg_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3244. {
  3245. const bool U = false;
  3246. const bool eq = false;
  3247. /* Decode Vector */
  3248. int d = (int)UInt(Rd);
  3249. int n = (int)UInt(Rn);
  3250. int m = (int)UInt(Rm);
  3251. /* if size:Q == '110' then ReservedValue(); */
  3252. int esize = 8 << (int)UInt(size);
  3253. int datasize = (Q ? 128 : 64);
  3254. int elements = datasize / esize;
  3255. bool unsigned = (U == true);
  3256. bool cmp_eq = (eq == true);
  3257. /* Operation */
  3258. /* CheckFPAdvSIMDEnabled64(); */
  3259. Bits result = new Bits(datasize);
  3260. Bits operand1 = V(datasize, n);
  3261. Bits operand2 = V(datasize, m);
  3262. BigInteger element1;
  3263. BigInteger element2;
  3264. bool test_passed;
  3265. for (int e = 0; e <= elements - 1; e++)
  3266. {
  3267. element1 = Int(Elem(operand1, e, esize), unsigned);
  3268. element2 = Int(Elem(operand2, e, esize), unsigned);
  3269. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3270. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3271. }
  3272. V(d, result);
  3273. }
  3274. // cmhi_advsimd.html#CMHI_asisdsame_only
  3275. public static void Cmhi_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3276. {
  3277. const bool U = true;
  3278. const bool eq = false;
  3279. /* Decode Scalar */
  3280. int d = (int)UInt(Rd);
  3281. int n = (int)UInt(Rn);
  3282. int m = (int)UInt(Rm);
  3283. /* if size != '11' then ReservedValue(); */
  3284. int esize = 8 << (int)UInt(size);
  3285. int datasize = esize;
  3286. int elements = 1;
  3287. bool unsigned = (U == true);
  3288. bool cmp_eq = (eq == true);
  3289. /* Operation */
  3290. /* CheckFPAdvSIMDEnabled64(); */
  3291. Bits result = new Bits(datasize);
  3292. Bits operand1 = V(datasize, n);
  3293. Bits operand2 = V(datasize, m);
  3294. BigInteger element1;
  3295. BigInteger element2;
  3296. bool test_passed;
  3297. for (int e = 0; e <= elements - 1; e++)
  3298. {
  3299. element1 = Int(Elem(operand1, e, esize), unsigned);
  3300. element2 = Int(Elem(operand2, e, esize), unsigned);
  3301. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3302. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3303. }
  3304. V(d, result);
  3305. }
  3306. // cmhi_advsimd.html#CMHI_asimdsame_only
  3307. public static void Cmhi_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3308. {
  3309. const bool U = true;
  3310. const bool eq = false;
  3311. /* Decode Vector */
  3312. int d = (int)UInt(Rd);
  3313. int n = (int)UInt(Rn);
  3314. int m = (int)UInt(Rm);
  3315. /* if size:Q == '110' then ReservedValue(); */
  3316. int esize = 8 << (int)UInt(size);
  3317. int datasize = (Q ? 128 : 64);
  3318. int elements = datasize / esize;
  3319. bool unsigned = (U == true);
  3320. bool cmp_eq = (eq == true);
  3321. /* Operation */
  3322. /* CheckFPAdvSIMDEnabled64(); */
  3323. Bits result = new Bits(datasize);
  3324. Bits operand1 = V(datasize, n);
  3325. Bits operand2 = V(datasize, m);
  3326. BigInteger element1;
  3327. BigInteger element2;
  3328. bool test_passed;
  3329. for (int e = 0; e <= elements - 1; e++)
  3330. {
  3331. element1 = Int(Elem(operand1, e, esize), unsigned);
  3332. element2 = Int(Elem(operand2, e, esize), unsigned);
  3333. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3334. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3335. }
  3336. V(d, result);
  3337. }
  3338. // cmhs_advsimd.html#CMHS_asisdsame_only
  3339. public static void Cmhs_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3340. {
  3341. const bool U = true;
  3342. const bool eq = true;
  3343. /* Decode Scalar */
  3344. int d = (int)UInt(Rd);
  3345. int n = (int)UInt(Rn);
  3346. int m = (int)UInt(Rm);
  3347. /* if size != '11' then ReservedValue(); */
  3348. int esize = 8 << (int)UInt(size);
  3349. int datasize = esize;
  3350. int elements = 1;
  3351. bool unsigned = (U == true);
  3352. bool cmp_eq = (eq == true);
  3353. /* Operation */
  3354. /* CheckFPAdvSIMDEnabled64(); */
  3355. Bits result = new Bits(datasize);
  3356. Bits operand1 = V(datasize, n);
  3357. Bits operand2 = V(datasize, m);
  3358. BigInteger element1;
  3359. BigInteger element2;
  3360. bool test_passed;
  3361. for (int e = 0; e <= elements - 1; e++)
  3362. {
  3363. element1 = Int(Elem(operand1, e, esize), unsigned);
  3364. element2 = Int(Elem(operand2, e, esize), unsigned);
  3365. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3366. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3367. }
  3368. V(d, result);
  3369. }
  3370. // cmhs_advsimd.html#CMHS_asimdsame_only
  3371. public static void Cmhs_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3372. {
  3373. const bool U = true;
  3374. const bool eq = true;
  3375. /* Decode Vector */
  3376. int d = (int)UInt(Rd);
  3377. int n = (int)UInt(Rn);
  3378. int m = (int)UInt(Rm);
  3379. /* if size:Q == '110' then ReservedValue(); */
  3380. int esize = 8 << (int)UInt(size);
  3381. int datasize = (Q ? 128 : 64);
  3382. int elements = datasize / esize;
  3383. bool unsigned = (U == true);
  3384. bool cmp_eq = (eq == true);
  3385. /* Operation */
  3386. /* CheckFPAdvSIMDEnabled64(); */
  3387. Bits result = new Bits(datasize);
  3388. Bits operand1 = V(datasize, n);
  3389. Bits operand2 = V(datasize, m);
  3390. BigInteger element1;
  3391. BigInteger element2;
  3392. bool test_passed;
  3393. for (int e = 0; e <= elements - 1; e++)
  3394. {
  3395. element1 = Int(Elem(operand1, e, esize), unsigned);
  3396. element2 = Int(Elem(operand2, e, esize), unsigned);
  3397. test_passed = (cmp_eq ? element1 >= element2 : element1 > element2);
  3398. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3399. }
  3400. V(d, result);
  3401. }
  3402. // cmtst_advsimd.html#CMTST_asisdsame_only
  3403. public static void Cmtst_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3404. {
  3405. const bool U = false;
  3406. /* Decode Scalar */
  3407. int d = (int)UInt(Rd);
  3408. int n = (int)UInt(Rn);
  3409. int m = (int)UInt(Rm);
  3410. /* if size != '11' then ReservedValue(); */
  3411. int esize = 8 << (int)UInt(size);
  3412. int datasize = esize;
  3413. int elements = 1;
  3414. bool and_test = (U == false);
  3415. /* Operation */
  3416. /* CheckFPAdvSIMDEnabled64(); */
  3417. Bits result = new Bits(datasize);
  3418. Bits operand1 = V(datasize, n);
  3419. Bits operand2 = V(datasize, m);
  3420. Bits element1;
  3421. Bits element2;
  3422. bool test_passed;
  3423. for (int e = 0; e <= elements - 1; e++)
  3424. {
  3425. element1 = Elem(operand1, e, esize);
  3426. element2 = Elem(operand2, e, esize);
  3427. if (and_test)
  3428. {
  3429. test_passed = !IsZero(AND(element1, element2));
  3430. }
  3431. else
  3432. {
  3433. test_passed = (element1 == element2);
  3434. }
  3435. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3436. }
  3437. V(d, result);
  3438. }
  3439. // cmtst_advsimd.html#CMTST_asimdsame_only
  3440. public static void Cmtst_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3441. {
  3442. const bool U = false;
  3443. /* Decode Vector */
  3444. int d = (int)UInt(Rd);
  3445. int n = (int)UInt(Rn);
  3446. int m = (int)UInt(Rm);
  3447. /* if size:Q == '110' then ReservedValue(); */
  3448. int esize = 8 << (int)UInt(size);
  3449. int datasize = (Q ? 128 : 64);
  3450. int elements = datasize / esize;
  3451. bool and_test = (U == false);
  3452. /* Operation */
  3453. /* CheckFPAdvSIMDEnabled64(); */
  3454. Bits result = new Bits(datasize);
  3455. Bits operand1 = V(datasize, n);
  3456. Bits operand2 = V(datasize, m);
  3457. Bits element1;
  3458. Bits element2;
  3459. bool test_passed;
  3460. for (int e = 0; e <= elements - 1; e++)
  3461. {
  3462. element1 = Elem(operand1, e, esize);
  3463. element2 = Elem(operand2, e, esize);
  3464. if (and_test)
  3465. {
  3466. test_passed = !IsZero(AND(element1, element2));
  3467. }
  3468. else
  3469. {
  3470. test_passed = (element1 == element2);
  3471. }
  3472. Elem(result, e, esize, test_passed ? Ones(esize) : Zeros(esize));
  3473. }
  3474. V(d, result);
  3475. }
  3476. // eor_advsimd.html
  3477. public static void Eor_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3478. {
  3479. /* Decode */
  3480. int d = (int)UInt(Rd);
  3481. int n = (int)UInt(Rn);
  3482. int m = (int)UInt(Rm);
  3483. int datasize = (Q ? 128 : 64);
  3484. /* Operation */
  3485. /* CheckFPAdvSIMDEnabled64(); */
  3486. Bits operand1 = V(datasize, m);
  3487. Bits operand2 = Zeros(datasize);
  3488. Bits operand3 = Ones(datasize);
  3489. Bits operand4 = V(datasize, n);
  3490. Bits result = EOR(operand1, AND(EOR(operand2, operand4), operand3));
  3491. V(d, result);
  3492. }
  3493. // orn_advsimd.html
  3494. public static void Orn_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3495. {
  3496. /* Decode */
  3497. int d = (int)UInt(Rd);
  3498. int n = (int)UInt(Rn);
  3499. int m = (int)UInt(Rm);
  3500. int datasize = (Q ? 128 : 64);
  3501. /* Operation */
  3502. /* CheckFPAdvSIMDEnabled64(); */
  3503. Bits operand1 = V(datasize, n);
  3504. Bits operand2 = V(datasize, m);
  3505. operand2 = NOT(operand2);
  3506. Bits result = OR(operand1, operand2);
  3507. V(d, result);
  3508. }
  3509. // orr_advsimd_reg.html
  3510. public static void Orr_V(bool Q, Bits Rm, Bits Rn, Bits Rd)
  3511. {
  3512. /* Decode */
  3513. int d = (int)UInt(Rd);
  3514. int n = (int)UInt(Rn);
  3515. int m = (int)UInt(Rm);
  3516. int datasize = (Q ? 128 : 64);
  3517. /* Operation */
  3518. /* CheckFPAdvSIMDEnabled64(); */
  3519. Bits operand1 = V(datasize, n);
  3520. Bits operand2 = V(datasize, m);
  3521. Bits result = OR(operand1, operand2);
  3522. V(d, result);
  3523. }
  3524. // raddhn_advsimd.html
  3525. public static void Raddhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3526. {
  3527. const bool U = true;
  3528. const bool o1 = false;
  3529. /* Decode */
  3530. int d = (int)UInt(Rd);
  3531. int n = (int)UInt(Rn);
  3532. int m = (int)UInt(Rm);
  3533. /* if size == '11' then ReservedValue(); */
  3534. int esize = 8 << (int)UInt(size);
  3535. int datasize = 64;
  3536. int part = (int)UInt(Q);
  3537. int elements = datasize / esize;
  3538. bool sub_op = (o1 == true);
  3539. bool round = (U == true);
  3540. /* Operation */
  3541. /* CheckFPAdvSIMDEnabled64(); */
  3542. Bits result = new Bits(datasize);
  3543. Bits operand1 = V(2 * datasize, n);
  3544. Bits operand2 = V(2 * datasize, m);
  3545. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3546. Bits sum;
  3547. Bits element1;
  3548. Bits element2;
  3549. for (int e = 0; e <= elements - 1; e++)
  3550. {
  3551. element1 = Elem(operand1, e, 2 * esize);
  3552. element2 = Elem(operand2, e, 2 * esize);
  3553. if (sub_op)
  3554. {
  3555. sum = element1 - element2;
  3556. }
  3557. else
  3558. {
  3559. sum = element1 + element2;
  3560. }
  3561. sum = sum + round_const;
  3562. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3563. }
  3564. Vpart(d, part, result);
  3565. }
  3566. // rsubhn_advsimd.html
  3567. public static void Rsubhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3568. {
  3569. const bool U = true;
  3570. const bool o1 = true;
  3571. /* Decode */
  3572. int d = (int)UInt(Rd);
  3573. int n = (int)UInt(Rn);
  3574. int m = (int)UInt(Rm);
  3575. /* if size == '11' then ReservedValue(); */
  3576. int esize = 8 << (int)UInt(size);
  3577. int datasize = 64;
  3578. int part = (int)UInt(Q);
  3579. int elements = datasize / esize;
  3580. bool sub_op = (o1 == true);
  3581. bool round = (U == true);
  3582. /* Operation */
  3583. /* CheckFPAdvSIMDEnabled64(); */
  3584. Bits result = new Bits(datasize);
  3585. Bits operand1 = V(2 * datasize, n);
  3586. Bits operand2 = V(2 * datasize, m);
  3587. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  3588. Bits sum;
  3589. Bits element1;
  3590. Bits element2;
  3591. for (int e = 0; e <= elements - 1; e++)
  3592. {
  3593. element1 = Elem(operand1, e, 2 * esize);
  3594. element2 = Elem(operand2, e, 2 * esize);
  3595. if (sub_op)
  3596. {
  3597. sum = element1 - element2;
  3598. }
  3599. else
  3600. {
  3601. sum = element1 + element2;
  3602. }
  3603. sum = sum + round_const;
  3604. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  3605. }
  3606. Vpart(d, part, result);
  3607. }
  3608. // saba_advsimd.html
  3609. public static void Saba_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3610. {
  3611. const bool U = false;
  3612. const bool ac = true;
  3613. /* Decode */
  3614. int d = (int)UInt(Rd);
  3615. int n = (int)UInt(Rn);
  3616. int m = (int)UInt(Rm);
  3617. /* if size == '11' then ReservedValue(); */
  3618. int esize = 8 << (int)UInt(size);
  3619. int datasize = (Q ? 128 : 64);
  3620. int elements = datasize / esize;
  3621. bool unsigned = (U == true);
  3622. bool accumulate = (ac == true);
  3623. /* Operation */
  3624. /* CheckFPAdvSIMDEnabled64(); */
  3625. Bits operand1 = V(datasize, n);
  3626. Bits operand2 = V(datasize, m);
  3627. BigInteger element1;
  3628. BigInteger element2;
  3629. Bits absdiff;
  3630. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3631. for (int e = 0; e <= elements - 1; e++)
  3632. {
  3633. element1 = Int(Elem(operand1, e, esize), unsigned);
  3634. element2 = Int(Elem(operand2, e, esize), unsigned);
  3635. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3636. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3637. }
  3638. V(d, result);
  3639. }
  3640. // sabal_advsimd.html
  3641. public static void Sabal_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3642. {
  3643. const bool U = false;
  3644. const bool op = false;
  3645. /* Decode */
  3646. int d = (int)UInt(Rd);
  3647. int n = (int)UInt(Rn);
  3648. int m = (int)UInt(Rm);
  3649. /* if size == '11' then ReservedValue(); */
  3650. int esize = 8 << (int)UInt(size);
  3651. int datasize = 64;
  3652. int part = (int)UInt(Q);
  3653. int elements = datasize / esize;
  3654. bool accumulate = (op == false);
  3655. bool unsigned = (U == true);
  3656. /* Operation */
  3657. /* CheckFPAdvSIMDEnabled64(); */
  3658. Bits operand1 = Vpart(datasize, n, part);
  3659. Bits operand2 = Vpart(datasize, m, part);
  3660. BigInteger element1;
  3661. BigInteger element2;
  3662. Bits absdiff;
  3663. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3664. for (int e = 0; e <= elements - 1; e++)
  3665. {
  3666. element1 = Int(Elem(operand1, e, esize), unsigned);
  3667. element2 = Int(Elem(operand2, e, esize), unsigned);
  3668. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3669. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3670. }
  3671. V(d, result);
  3672. }
  3673. // sabd_advsimd.html
  3674. public static void Sabd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3675. {
  3676. const bool U = false;
  3677. const bool ac = false;
  3678. /* Decode */
  3679. int d = (int)UInt(Rd);
  3680. int n = (int)UInt(Rn);
  3681. int m = (int)UInt(Rm);
  3682. /* if size == '11' then ReservedValue(); */
  3683. int esize = 8 << (int)UInt(size);
  3684. int datasize = (Q ? 128 : 64);
  3685. int elements = datasize / esize;
  3686. bool unsigned = (U == true);
  3687. bool accumulate = (ac == true);
  3688. /* Operation */
  3689. /* CheckFPAdvSIMDEnabled64(); */
  3690. Bits operand1 = V(datasize, n);
  3691. Bits operand2 = V(datasize, m);
  3692. BigInteger element1;
  3693. BigInteger element2;
  3694. Bits absdiff;
  3695. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  3696. for (int e = 0; e <= elements - 1; e++)
  3697. {
  3698. element1 = Int(Elem(operand1, e, esize), unsigned);
  3699. element2 = Int(Elem(operand2, e, esize), unsigned);
  3700. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  3701. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  3702. }
  3703. V(d, result);
  3704. }
  3705. // sabdl_advsimd.html
  3706. public static void Sabdl_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3707. {
  3708. const bool U = false;
  3709. const bool op = true;
  3710. /* Decode */
  3711. int d = (int)UInt(Rd);
  3712. int n = (int)UInt(Rn);
  3713. int m = (int)UInt(Rm);
  3714. /* if size == '11' then ReservedValue(); */
  3715. int esize = 8 << (int)UInt(size);
  3716. int datasize = 64;
  3717. int part = (int)UInt(Q);
  3718. int elements = datasize / esize;
  3719. bool accumulate = (op == false);
  3720. bool unsigned = (U == true);
  3721. /* Operation */
  3722. /* CheckFPAdvSIMDEnabled64(); */
  3723. Bits operand1 = Vpart(datasize, n, part);
  3724. Bits operand2 = Vpart(datasize, m, part);
  3725. BigInteger element1;
  3726. BigInteger element2;
  3727. Bits absdiff;
  3728. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  3729. for (int e = 0; e <= elements - 1; e++)
  3730. {
  3731. element1 = Int(Elem(operand1, e, esize), unsigned);
  3732. element2 = Int(Elem(operand2, e, esize), unsigned);
  3733. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  3734. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  3735. }
  3736. V(d, result);
  3737. }
  3738. // saddw_advsimd.html
  3739. public static void Saddw_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3740. {
  3741. const bool U = false;
  3742. const bool o1 = false;
  3743. /* Decode */
  3744. int d = (int)UInt(Rd);
  3745. int n = (int)UInt(Rn);
  3746. int m = (int)UInt(Rm);
  3747. /* if size == '11' then ReservedValue(); */
  3748. int esize = 8 << (int)UInt(size);
  3749. int datasize = 64;
  3750. int part = (int)UInt(Q);
  3751. int elements = datasize / esize;
  3752. bool sub_op = (o1 == true);
  3753. bool unsigned = (U == true);
  3754. /* Operation */
  3755. /* CheckFPAdvSIMDEnabled64(); */
  3756. Bits result = new Bits(2 * datasize);
  3757. Bits operand1 = V(2 * datasize, n);
  3758. Bits operand2 = Vpart(datasize, m, part);
  3759. BigInteger element1;
  3760. BigInteger element2;
  3761. BigInteger sum;
  3762. for (int e = 0; e <= elements - 1; e++)
  3763. {
  3764. element1 = Int(Elem(operand1, e, 2 * esize), unsigned);
  3765. element2 = Int(Elem(operand2, e, esize), unsigned);
  3766. if (sub_op)
  3767. {
  3768. sum = element1 - element2;
  3769. }
  3770. else
  3771. {
  3772. sum = element1 + element2;
  3773. }
  3774. Elem(result, e, 2 * esize, sum.SubBigInteger(2 * esize - 1, 0));
  3775. }
  3776. V(d, result);
  3777. }
  3778. // sqadd_advsimd.html#SQADD_asisdsame_only
  3779. public static void Sqadd_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3780. {
  3781. const bool U = false;
  3782. /* Decode Scalar */
  3783. int d = (int)UInt(Rd);
  3784. int n = (int)UInt(Rn);
  3785. int m = (int)UInt(Rm);
  3786. int esize = 8 << (int)UInt(size);
  3787. int datasize = esize;
  3788. int elements = 1;
  3789. bool unsigned = (U == true);
  3790. /* Operation */
  3791. /* CheckFPAdvSIMDEnabled64(); */
  3792. Bits result = new Bits(datasize);
  3793. Bits operand1 = V(datasize, n);
  3794. Bits operand2 = V(datasize, m);
  3795. BigInteger element1;
  3796. BigInteger element2;
  3797. BigInteger sum;
  3798. bool sat;
  3799. for (int e = 0; e <= elements - 1; e++)
  3800. {
  3801. element1 = Int(Elem(operand1, e, esize), unsigned);
  3802. element2 = Int(Elem(operand2, e, esize), unsigned);
  3803. sum = element1 + element2;
  3804. (Bits _result, bool _sat) = SatQ(sum, esize, unsigned);
  3805. Elem(result, e, esize, _result);
  3806. sat = _sat;
  3807. if (sat)
  3808. {
  3809. /* FPSR.QC = '1'; */
  3810. FPSR[27] = true; // TODO: Add named fields.
  3811. }
  3812. }
  3813. V(d, result);
  3814. }
  3815. // sqadd_advsimd.html#SQADD_asimdsame_only
  3816. public static void Sqadd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3817. {
  3818. const bool U = false;
  3819. /* Decode Vector */
  3820. int d = (int)UInt(Rd);
  3821. int n = (int)UInt(Rn);
  3822. int m = (int)UInt(Rm);
  3823. /* if size:Q == '110' then ReservedValue(); */
  3824. int esize = 8 << (int)UInt(size);
  3825. int datasize = (Q ? 128 : 64);
  3826. int elements = datasize / esize;
  3827. bool unsigned = (U == true);
  3828. /* Operation */
  3829. /* CheckFPAdvSIMDEnabled64(); */
  3830. Bits result = new Bits(datasize);
  3831. Bits operand1 = V(datasize, n);
  3832. Bits operand2 = V(datasize, m);
  3833. BigInteger element1;
  3834. BigInteger element2;
  3835. BigInteger sum;
  3836. bool sat;
  3837. for (int e = 0; e <= elements - 1; e++)
  3838. {
  3839. element1 = Int(Elem(operand1, e, esize), unsigned);
  3840. element2 = Int(Elem(operand2, e, esize), unsigned);
  3841. sum = element1 + element2;
  3842. (Bits _result, bool _sat) = SatQ(sum, esize, unsigned);
  3843. Elem(result, e, esize, _result);
  3844. sat = _sat;
  3845. if (sat)
  3846. {
  3847. /* FPSR.QC = '1'; */
  3848. FPSR[27] = true; // TODO: Add named fields.
  3849. }
  3850. }
  3851. V(d, result);
  3852. }
  3853. // sqsub_advsimd.html#SQSUB_asisdsame_only
  3854. public static void Sqsub_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3855. {
  3856. const bool U = false;
  3857. /* Decode Scalar */
  3858. int d = (int)UInt(Rd);
  3859. int n = (int)UInt(Rn);
  3860. int m = (int)UInt(Rm);
  3861. int esize = 8 << (int)UInt(size);
  3862. int datasize = esize;
  3863. int elements = 1;
  3864. bool unsigned = (U == true);
  3865. /* Operation */
  3866. /* CheckFPAdvSIMDEnabled64(); */
  3867. Bits result = new Bits(datasize);
  3868. Bits operand1 = V(datasize, n);
  3869. Bits operand2 = V(datasize, m);
  3870. BigInteger element1;
  3871. BigInteger element2;
  3872. BigInteger diff;
  3873. bool sat;
  3874. for (int e = 0; e <= elements - 1; e++)
  3875. {
  3876. element1 = Int(Elem(operand1, e, esize), unsigned);
  3877. element2 = Int(Elem(operand2, e, esize), unsigned);
  3878. diff = element1 - element2;
  3879. (Bits _result, bool _sat) = SatQ(diff, esize, unsigned);
  3880. Elem(result, e, esize, _result);
  3881. sat = _sat;
  3882. if (sat)
  3883. {
  3884. /* FPSR.QC = '1'; */
  3885. FPSR[27] = true; // TODO: Add named fields.
  3886. }
  3887. }
  3888. V(d, result);
  3889. }
  3890. // sqsub_advsimd.html#SQSUB_asimdsame_only
  3891. public static void Sqsub_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3892. {
  3893. const bool U = false;
  3894. /* Decode Vector */
  3895. int d = (int)UInt(Rd);
  3896. int n = (int)UInt(Rn);
  3897. int m = (int)UInt(Rm);
  3898. /* if size:Q == '110' then ReservedValue(); */
  3899. int esize = 8 << (int)UInt(size);
  3900. int datasize = (Q ? 128 : 64);
  3901. int elements = datasize / esize;
  3902. bool unsigned = (U == true);
  3903. /* Operation */
  3904. /* CheckFPAdvSIMDEnabled64(); */
  3905. Bits result = new Bits(datasize);
  3906. Bits operand1 = V(datasize, n);
  3907. Bits operand2 = V(datasize, m);
  3908. BigInteger element1;
  3909. BigInteger element2;
  3910. BigInteger diff;
  3911. bool sat;
  3912. for (int e = 0; e <= elements - 1; e++)
  3913. {
  3914. element1 = Int(Elem(operand1, e, esize), unsigned);
  3915. element2 = Int(Elem(operand2, e, esize), unsigned);
  3916. diff = element1 - element2;
  3917. (Bits _result, bool _sat) = SatQ(diff, esize, unsigned);
  3918. Elem(result, e, esize, _result);
  3919. sat = _sat;
  3920. if (sat)
  3921. {
  3922. /* FPSR.QC = '1'; */
  3923. FPSR[27] = true; // TODO: Add named fields.
  3924. }
  3925. }
  3926. V(d, result);
  3927. }
  3928. // ssubw_advsimd.html
  3929. public static void Ssubw_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  3930. {
  3931. const bool U = false;
  3932. const bool o1 = true;
  3933. /* Decode */
  3934. int d = (int)UInt(Rd);
  3935. int n = (int)UInt(Rn);
  3936. int m = (int)UInt(Rm);
  3937. /* if size == '11' then ReservedValue(); */
  3938. int esize = 8 << (int)UInt(size);
  3939. int datasize = 64;
  3940. int part = (int)UInt(Q);
  3941. int elements = datasize / esize;
  3942. bool sub_op = (o1 == true);
  3943. bool unsigned = (U == true);
  3944. /* Operation */
  3945. /* CheckFPAdvSIMDEnabled64(); */
  3946. Bits result = new Bits(2 * datasize);
  3947. Bits operand1 = V(2 * datasize, n);
  3948. Bits operand2 = Vpart(datasize, m, part);
  3949. BigInteger element1;
  3950. BigInteger element2;
  3951. BigInteger sum;
  3952. for (int e = 0; e <= elements - 1; e++)
  3953. {
  3954. element1 = Int(Elem(operand1, e, 2 * esize), unsigned);
  3955. element2 = Int(Elem(operand2, e, esize), unsigned);
  3956. if (sub_op)
  3957. {
  3958. sum = element1 - element2;
  3959. }
  3960. else
  3961. {
  3962. sum = element1 + element2;
  3963. }
  3964. Elem(result, e, 2 * esize, sum.SubBigInteger(2 * esize - 1, 0));
  3965. }
  3966. V(d, result);
  3967. }
  3968. // sub_advsimd.html#SUB_asisdsame_only
  3969. public static void Sub_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  3970. {
  3971. const bool U = true;
  3972. /* Decode Scalar */
  3973. int d = (int)UInt(Rd);
  3974. int n = (int)UInt(Rn);
  3975. int m = (int)UInt(Rm);
  3976. /* if size != '11' then ReservedValue(); */
  3977. int esize = 8 << (int)UInt(size);
  3978. int datasize = esize;
  3979. int elements = 1;
  3980. bool sub_op = (U == true);
  3981. /* Operation */
  3982. /* CheckFPAdvSIMDEnabled64(); */
  3983. Bits result = new Bits(datasize);
  3984. Bits operand1 = V(datasize, n);
  3985. Bits operand2 = V(datasize, m);
  3986. Bits element1;
  3987. Bits element2;
  3988. for (int e = 0; e <= elements - 1; e++)
  3989. {
  3990. element1 = Elem(operand1, e, esize);
  3991. element2 = Elem(operand2, e, esize);
  3992. if (sub_op)
  3993. {
  3994. Elem(result, e, esize, element1 - element2);
  3995. }
  3996. else
  3997. {
  3998. Elem(result, e, esize, element1 + element2);
  3999. }
  4000. }
  4001. V(d, result);
  4002. }
  4003. // sub_advsimd.html#SUB_asimdsame_only
  4004. public static void Sub_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4005. {
  4006. const bool U = true;
  4007. /* Decode Vector */
  4008. int d = (int)UInt(Rd);
  4009. int n = (int)UInt(Rn);
  4010. int m = (int)UInt(Rm);
  4011. /* if size:Q == '110' then ReservedValue(); */
  4012. int esize = 8 << (int)UInt(size);
  4013. int datasize = (Q ? 128 : 64);
  4014. int elements = datasize / esize;
  4015. bool sub_op = (U == true);
  4016. /* Operation */
  4017. /* CheckFPAdvSIMDEnabled64(); */
  4018. Bits result = new Bits(datasize);
  4019. Bits operand1 = V(datasize, n);
  4020. Bits operand2 = V(datasize, m);
  4021. Bits element1;
  4022. Bits element2;
  4023. for (int e = 0; e <= elements - 1; e++)
  4024. {
  4025. element1 = Elem(operand1, e, esize);
  4026. element2 = Elem(operand2, e, esize);
  4027. if (sub_op)
  4028. {
  4029. Elem(result, e, esize, element1 - element2);
  4030. }
  4031. else
  4032. {
  4033. Elem(result, e, esize, element1 + element2);
  4034. }
  4035. }
  4036. V(d, result);
  4037. }
  4038. // subhn_advsimd.html
  4039. public static void Subhn_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4040. {
  4041. const bool U = false;
  4042. const bool o1 = true;
  4043. /* Decode */
  4044. int d = (int)UInt(Rd);
  4045. int n = (int)UInt(Rn);
  4046. int m = (int)UInt(Rm);
  4047. /* if size == '11' then ReservedValue(); */
  4048. int esize = 8 << (int)UInt(size);
  4049. int datasize = 64;
  4050. int part = (int)UInt(Q);
  4051. int elements = datasize / esize;
  4052. bool sub_op = (o1 == true);
  4053. bool round = (U == true);
  4054. /* Operation */
  4055. /* CheckFPAdvSIMDEnabled64(); */
  4056. Bits result = new Bits(datasize);
  4057. Bits operand1 = V(2 * datasize, n);
  4058. Bits operand2 = V(2 * datasize, m);
  4059. BigInteger round_const = (round ? (BigInteger)1 << (esize - 1) : 0);
  4060. Bits sum;
  4061. Bits element1;
  4062. Bits element2;
  4063. for (int e = 0; e <= elements - 1; e++)
  4064. {
  4065. element1 = Elem(operand1, e, 2 * esize);
  4066. element2 = Elem(operand2, e, 2 * esize);
  4067. if (sub_op)
  4068. {
  4069. sum = element1 - element2;
  4070. }
  4071. else
  4072. {
  4073. sum = element1 + element2;
  4074. }
  4075. sum = sum + round_const;
  4076. Elem(result, e, esize, sum[2 * esize - 1, esize]);
  4077. }
  4078. Vpart(d, part, result);
  4079. }
  4080. // trn1_advsimd.html
  4081. public static void Trn1_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4082. {
  4083. const bool op = false;
  4084. /* Decode */
  4085. int d = (int)UInt(Rd);
  4086. int n = (int)UInt(Rn);
  4087. int m = (int)UInt(Rm);
  4088. /* if size:Q == '110' then ReservedValue(); */
  4089. int esize = 8 << (int)UInt(size);
  4090. int datasize = (Q ? 128 : 64);
  4091. int elements = datasize / esize;
  4092. int part = (int)UInt(op);
  4093. int pairs = elements / 2;
  4094. /* Operation */
  4095. /* CheckFPAdvSIMDEnabled64(); */
  4096. Bits result = new Bits(datasize);
  4097. Bits operand1 = V(datasize, n);
  4098. Bits operand2 = V(datasize, m);
  4099. for (int p = 0; p <= pairs - 1; p++)
  4100. {
  4101. Elem(result, 2 * p + 0, esize, Elem(operand1, 2 * p + part, esize));
  4102. Elem(result, 2 * p + 1, esize, Elem(operand2, 2 * p + part, esize));
  4103. }
  4104. V(d, result);
  4105. }
  4106. // trn2_advsimd.html
  4107. public static void Trn2_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4108. {
  4109. const bool op = true;
  4110. /* Decode */
  4111. int d = (int)UInt(Rd);
  4112. int n = (int)UInt(Rn);
  4113. int m = (int)UInt(Rm);
  4114. /* if size:Q == '110' then ReservedValue(); */
  4115. int esize = 8 << (int)UInt(size);
  4116. int datasize = (Q ? 128 : 64);
  4117. int elements = datasize / esize;
  4118. int part = (int)UInt(op);
  4119. int pairs = elements / 2;
  4120. /* Operation */
  4121. /* CheckFPAdvSIMDEnabled64(); */
  4122. Bits result = new Bits(datasize);
  4123. Bits operand1 = V(datasize, n);
  4124. Bits operand2 = V(datasize, m);
  4125. for (int p = 0; p <= pairs - 1; p++)
  4126. {
  4127. Elem(result, 2 * p + 0, esize, Elem(operand1, 2 * p + part, esize));
  4128. Elem(result, 2 * p + 1, esize, Elem(operand2, 2 * p + part, esize));
  4129. }
  4130. V(d, result);
  4131. }
  4132. // uaba_advsimd.html
  4133. public static void Uaba_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4134. {
  4135. const bool U = true;
  4136. const bool ac = true;
  4137. /* Decode */
  4138. int d = (int)UInt(Rd);
  4139. int n = (int)UInt(Rn);
  4140. int m = (int)UInt(Rm);
  4141. /* if size == '11' then ReservedValue(); */
  4142. int esize = 8 << (int)UInt(size);
  4143. int datasize = (Q ? 128 : 64);
  4144. int elements = datasize / esize;
  4145. bool unsigned = (U == true);
  4146. bool accumulate = (ac == true);
  4147. /* Operation */
  4148. /* CheckFPAdvSIMDEnabled64(); */
  4149. Bits operand1 = V(datasize, n);
  4150. Bits operand2 = V(datasize, m);
  4151. BigInteger element1;
  4152. BigInteger element2;
  4153. Bits absdiff;
  4154. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  4155. for (int e = 0; e <= elements - 1; e++)
  4156. {
  4157. element1 = Int(Elem(operand1, e, esize), unsigned);
  4158. element2 = Int(Elem(operand2, e, esize), unsigned);
  4159. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  4160. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  4161. }
  4162. V(d, result);
  4163. }
  4164. // uabal_advsimd.html
  4165. public static void Uabal_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4166. {
  4167. const bool U = true;
  4168. const bool op = false;
  4169. /* Decode */
  4170. int d = (int)UInt(Rd);
  4171. int n = (int)UInt(Rn);
  4172. int m = (int)UInt(Rm);
  4173. /* if size == '11' then ReservedValue(); */
  4174. int esize = 8 << (int)UInt(size);
  4175. int datasize = 64;
  4176. int part = (int)UInt(Q);
  4177. int elements = datasize / esize;
  4178. bool accumulate = (op == false);
  4179. bool unsigned = (U == true);
  4180. /* Operation */
  4181. /* CheckFPAdvSIMDEnabled64(); */
  4182. Bits operand1 = Vpart(datasize, n, part);
  4183. Bits operand2 = Vpart(datasize, m, part);
  4184. BigInteger element1;
  4185. BigInteger element2;
  4186. Bits absdiff;
  4187. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  4188. for (int e = 0; e <= elements - 1; e++)
  4189. {
  4190. element1 = Int(Elem(operand1, e, esize), unsigned);
  4191. element2 = Int(Elem(operand2, e, esize), unsigned);
  4192. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  4193. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  4194. }
  4195. V(d, result);
  4196. }
  4197. // uabd_advsimd.html
  4198. public static void Uabd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4199. {
  4200. const bool U = true;
  4201. const bool ac = false;
  4202. /* Decode */
  4203. int d = (int)UInt(Rd);
  4204. int n = (int)UInt(Rn);
  4205. int m = (int)UInt(Rm);
  4206. /* if size == '11' then ReservedValue(); */
  4207. int esize = 8 << (int)UInt(size);
  4208. int datasize = (Q ? 128 : 64);
  4209. int elements = datasize / esize;
  4210. bool unsigned = (U == true);
  4211. bool accumulate = (ac == true);
  4212. /* Operation */
  4213. /* CheckFPAdvSIMDEnabled64(); */
  4214. Bits operand1 = V(datasize, n);
  4215. Bits operand2 = V(datasize, m);
  4216. BigInteger element1;
  4217. BigInteger element2;
  4218. Bits absdiff;
  4219. Bits result = (accumulate ? V(datasize, d) : Zeros(datasize));
  4220. for (int e = 0; e <= elements - 1; e++)
  4221. {
  4222. element1 = Int(Elem(operand1, e, esize), unsigned);
  4223. element2 = Int(Elem(operand2, e, esize), unsigned);
  4224. absdiff = Abs(element1 - element2).SubBigInteger(esize - 1, 0);
  4225. Elem(result, e, esize, Elem(result, e, esize) + absdiff);
  4226. }
  4227. V(d, result);
  4228. }
  4229. // uabdl_advsimd.html
  4230. public static void Uabdl_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4231. {
  4232. const bool U = true;
  4233. const bool op = true;
  4234. /* Decode */
  4235. int d = (int)UInt(Rd);
  4236. int n = (int)UInt(Rn);
  4237. int m = (int)UInt(Rm);
  4238. /* if size == '11' then ReservedValue(); */
  4239. int esize = 8 << (int)UInt(size);
  4240. int datasize = 64;
  4241. int part = (int)UInt(Q);
  4242. int elements = datasize / esize;
  4243. bool accumulate = (op == false);
  4244. bool unsigned = (U == true);
  4245. /* Operation */
  4246. /* CheckFPAdvSIMDEnabled64(); */
  4247. Bits operand1 = Vpart(datasize, n, part);
  4248. Bits operand2 = Vpart(datasize, m, part);
  4249. BigInteger element1;
  4250. BigInteger element2;
  4251. Bits absdiff;
  4252. Bits result = (accumulate ? V(2 * datasize, d) : Zeros(2 * datasize));
  4253. for (int e = 0; e <= elements - 1; e++)
  4254. {
  4255. element1 = Int(Elem(operand1, e, esize), unsigned);
  4256. element2 = Int(Elem(operand2, e, esize), unsigned);
  4257. absdiff = Abs(element1 - element2).SubBigInteger(2 * esize - 1, 0);
  4258. Elem(result, e, 2 * esize, Elem(result, e, 2 * esize) + absdiff);
  4259. }
  4260. V(d, result);
  4261. }
  4262. // uaddw_advsimd.html
  4263. public static void Uaddw_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4264. {
  4265. const bool U = true;
  4266. const bool o1 = false;
  4267. /* Decode */
  4268. int d = (int)UInt(Rd);
  4269. int n = (int)UInt(Rn);
  4270. int m = (int)UInt(Rm);
  4271. /* if size == '11' then ReservedValue(); */
  4272. int esize = 8 << (int)UInt(size);
  4273. int datasize = 64;
  4274. int part = (int)UInt(Q);
  4275. int elements = datasize / esize;
  4276. bool sub_op = (o1 == true);
  4277. bool unsigned = (U == true);
  4278. /* Operation */
  4279. /* CheckFPAdvSIMDEnabled64(); */
  4280. Bits result = new Bits(2 * datasize);
  4281. Bits operand1 = V(2 * datasize, n);
  4282. Bits operand2 = Vpart(datasize, m, part);
  4283. BigInteger element1;
  4284. BigInteger element2;
  4285. BigInteger sum;
  4286. for (int e = 0; e <= elements - 1; e++)
  4287. {
  4288. element1 = Int(Elem(operand1, e, 2 * esize), unsigned);
  4289. element2 = Int(Elem(operand2, e, esize), unsigned);
  4290. if (sub_op)
  4291. {
  4292. sum = element1 - element2;
  4293. }
  4294. else
  4295. {
  4296. sum = element1 + element2;
  4297. }
  4298. Elem(result, e, 2 * esize, sum.SubBigInteger(2 * esize - 1, 0));
  4299. }
  4300. V(d, result);
  4301. }
  4302. // uqadd_advsimd.html#UQADD_asisdsame_only
  4303. public static void Uqadd_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  4304. {
  4305. const bool U = true;
  4306. /* Decode Scalar */
  4307. int d = (int)UInt(Rd);
  4308. int n = (int)UInt(Rn);
  4309. int m = (int)UInt(Rm);
  4310. int esize = 8 << (int)UInt(size);
  4311. int datasize = esize;
  4312. int elements = 1;
  4313. bool unsigned = (U == true);
  4314. /* Operation */
  4315. /* CheckFPAdvSIMDEnabled64(); */
  4316. Bits result = new Bits(datasize);
  4317. Bits operand1 = V(datasize, n);
  4318. Bits operand2 = V(datasize, m);
  4319. BigInteger element1;
  4320. BigInteger element2;
  4321. BigInteger sum;
  4322. bool sat;
  4323. for (int e = 0; e <= elements - 1; e++)
  4324. {
  4325. element1 = Int(Elem(operand1, e, esize), unsigned);
  4326. element2 = Int(Elem(operand2, e, esize), unsigned);
  4327. sum = element1 + element2;
  4328. (Bits _result, bool _sat) = SatQ(sum, esize, unsigned);
  4329. Elem(result, e, esize, _result);
  4330. sat = _sat;
  4331. if (sat)
  4332. {
  4333. /* FPSR.QC = '1'; */
  4334. FPSR[27] = true; // TODO: Add named fields.
  4335. }
  4336. }
  4337. V(d, result);
  4338. }
  4339. // uqadd_advsimd.html#UQADD_asimdsame_only
  4340. public static void Uqadd_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4341. {
  4342. const bool U = true;
  4343. /* Decode Vector */
  4344. int d = (int)UInt(Rd);
  4345. int n = (int)UInt(Rn);
  4346. int m = (int)UInt(Rm);
  4347. /* if size:Q == '110' then ReservedValue(); */
  4348. int esize = 8 << (int)UInt(size);
  4349. int datasize = (Q ? 128 : 64);
  4350. int elements = datasize / esize;
  4351. bool unsigned = (U == true);
  4352. /* Operation */
  4353. /* CheckFPAdvSIMDEnabled64(); */
  4354. Bits result = new Bits(datasize);
  4355. Bits operand1 = V(datasize, n);
  4356. Bits operand2 = V(datasize, m);
  4357. BigInteger element1;
  4358. BigInteger element2;
  4359. BigInteger sum;
  4360. bool sat;
  4361. for (int e = 0; e <= elements - 1; e++)
  4362. {
  4363. element1 = Int(Elem(operand1, e, esize), unsigned);
  4364. element2 = Int(Elem(operand2, e, esize), unsigned);
  4365. sum = element1 + element2;
  4366. (Bits _result, bool _sat) = SatQ(sum, esize, unsigned);
  4367. Elem(result, e, esize, _result);
  4368. sat = _sat;
  4369. if (sat)
  4370. {
  4371. /* FPSR.QC = '1'; */
  4372. FPSR[27] = true; // TODO: Add named fields.
  4373. }
  4374. }
  4375. V(d, result);
  4376. }
  4377. // uqsub_advsimd.html#UQSUB_asisdsame_only
  4378. public static void Uqsub_S(Bits size, Bits Rm, Bits Rn, Bits Rd)
  4379. {
  4380. const bool U = true;
  4381. /* Decode Scalar */
  4382. int d = (int)UInt(Rd);
  4383. int n = (int)UInt(Rn);
  4384. int m = (int)UInt(Rm);
  4385. int esize = 8 << (int)UInt(size);
  4386. int datasize = esize;
  4387. int elements = 1;
  4388. bool unsigned = (U == true);
  4389. /* Operation */
  4390. /* CheckFPAdvSIMDEnabled64(); */
  4391. Bits result = new Bits(datasize);
  4392. Bits operand1 = V(datasize, n);
  4393. Bits operand2 = V(datasize, m);
  4394. BigInteger element1;
  4395. BigInteger element2;
  4396. BigInteger diff;
  4397. bool sat;
  4398. for (int e = 0; e <= elements - 1; e++)
  4399. {
  4400. element1 = Int(Elem(operand1, e, esize), unsigned);
  4401. element2 = Int(Elem(operand2, e, esize), unsigned);
  4402. diff = element1 - element2;
  4403. (Bits _result, bool _sat) = SatQ(diff, esize, unsigned);
  4404. Elem(result, e, esize, _result);
  4405. sat = _sat;
  4406. if (sat)
  4407. {
  4408. /* FPSR.QC = '1'; */
  4409. FPSR[27] = true; // TODO: Add named fields.
  4410. }
  4411. }
  4412. V(d, result);
  4413. }
  4414. // uqsub_advsimd.html#UQSUB_asimdsame_only
  4415. public static void Uqsub_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4416. {
  4417. const bool U = true;
  4418. /* Decode Vector */
  4419. int d = (int)UInt(Rd);
  4420. int n = (int)UInt(Rn);
  4421. int m = (int)UInt(Rm);
  4422. /* if size:Q == '110' then ReservedValue(); */
  4423. int esize = 8 << (int)UInt(size);
  4424. int datasize = (Q ? 128 : 64);
  4425. int elements = datasize / esize;
  4426. bool unsigned = (U == true);
  4427. /* Operation */
  4428. /* CheckFPAdvSIMDEnabled64(); */
  4429. Bits result = new Bits(datasize);
  4430. Bits operand1 = V(datasize, n);
  4431. Bits operand2 = V(datasize, m);
  4432. BigInteger element1;
  4433. BigInteger element2;
  4434. BigInteger diff;
  4435. bool sat;
  4436. for (int e = 0; e <= elements - 1; e++)
  4437. {
  4438. element1 = Int(Elem(operand1, e, esize), unsigned);
  4439. element2 = Int(Elem(operand2, e, esize), unsigned);
  4440. diff = element1 - element2;
  4441. (Bits _result, bool _sat) = SatQ(diff, esize, unsigned);
  4442. Elem(result, e, esize, _result);
  4443. sat = _sat;
  4444. if (sat)
  4445. {
  4446. /* FPSR.QC = '1'; */
  4447. FPSR[27] = true; // TODO: Add named fields.
  4448. }
  4449. }
  4450. V(d, result);
  4451. }
  4452. // usubw_advsimd.html
  4453. public static void Usubw_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4454. {
  4455. const bool U = true;
  4456. const bool o1 = true;
  4457. /* Decode */
  4458. int d = (int)UInt(Rd);
  4459. int n = (int)UInt(Rn);
  4460. int m = (int)UInt(Rm);
  4461. /* if size == '11' then ReservedValue(); */
  4462. int esize = 8 << (int)UInt(size);
  4463. int datasize = 64;
  4464. int part = (int)UInt(Q);
  4465. int elements = datasize / esize;
  4466. bool sub_op = (o1 == true);
  4467. bool unsigned = (U == true);
  4468. /* Operation */
  4469. /* CheckFPAdvSIMDEnabled64(); */
  4470. Bits result = new Bits(2 * datasize);
  4471. Bits operand1 = V(2 * datasize, n);
  4472. Bits operand2 = Vpart(datasize, m, part);
  4473. BigInteger element1;
  4474. BigInteger element2;
  4475. BigInteger sum;
  4476. for (int e = 0; e <= elements - 1; e++)
  4477. {
  4478. element1 = Int(Elem(operand1, e, 2 * esize), unsigned);
  4479. element2 = Int(Elem(operand2, e, esize), unsigned);
  4480. if (sub_op)
  4481. {
  4482. sum = element1 - element2;
  4483. }
  4484. else
  4485. {
  4486. sum = element1 + element2;
  4487. }
  4488. Elem(result, e, 2 * esize, sum.SubBigInteger(2 * esize - 1, 0));
  4489. }
  4490. V(d, result);
  4491. }
  4492. // uzp1_advsimd.html
  4493. public static void Uzp1_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4494. {
  4495. const bool op = false;
  4496. /* Decode */
  4497. int d = (int)UInt(Rd);
  4498. int n = (int)UInt(Rn);
  4499. int m = (int)UInt(Rm);
  4500. /* if size:Q == '110' then ReservedValue(); */
  4501. int esize = 8 << (int)UInt(size);
  4502. int datasize = (Q ? 128 : 64);
  4503. int elements = datasize / esize;
  4504. int part = (int)UInt(op);
  4505. /* Operation */
  4506. /* CheckFPAdvSIMDEnabled64(); */
  4507. Bits result = new Bits(datasize);
  4508. Bits operandl = V(datasize, n);
  4509. Bits operandh = V(datasize, m);
  4510. Bits zipped = Bits.Concat(operandh, operandl);
  4511. for (int e = 0; e <= elements - 1; e++)
  4512. {
  4513. Elem(result, e, esize, Elem(zipped, 2 * e + part, esize));
  4514. }
  4515. V(d, result);
  4516. }
  4517. // uzp2_advsimd.html
  4518. public static void Uzp2_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4519. {
  4520. const bool op = true;
  4521. /* Decode */
  4522. int d = (int)UInt(Rd);
  4523. int n = (int)UInt(Rn);
  4524. int m = (int)UInt(Rm);
  4525. /* if size:Q == '110' then ReservedValue(); */
  4526. int esize = 8 << (int)UInt(size);
  4527. int datasize = (Q ? 128 : 64);
  4528. int elements = datasize / esize;
  4529. int part = (int)UInt(op);
  4530. /* Operation */
  4531. /* CheckFPAdvSIMDEnabled64(); */
  4532. Bits result = new Bits(datasize);
  4533. Bits operandl = V(datasize, n);
  4534. Bits operandh = V(datasize, m);
  4535. Bits zipped = Bits.Concat(operandh, operandl);
  4536. for (int e = 0; e <= elements - 1; e++)
  4537. {
  4538. Elem(result, e, esize, Elem(zipped, 2 * e + part, esize));
  4539. }
  4540. V(d, result);
  4541. }
  4542. // zip1_advsimd.html
  4543. public static void Zip1_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4544. {
  4545. const bool op = false;
  4546. /* Decode */
  4547. int d = (int)UInt(Rd);
  4548. int n = (int)UInt(Rn);
  4549. int m = (int)UInt(Rm);
  4550. /* if size:Q == '110' then ReservedValue(); */
  4551. int esize = 8 << (int)UInt(size);
  4552. int datasize = (Q ? 128 : 64);
  4553. int elements = datasize / esize;
  4554. int part = (int)UInt(op);
  4555. int pairs = elements / 2;
  4556. /* Operation */
  4557. /* CheckFPAdvSIMDEnabled64(); */
  4558. Bits result = new Bits(datasize);
  4559. Bits operand1 = V(datasize, n);
  4560. Bits operand2 = V(datasize, m);
  4561. int @base = part * pairs;
  4562. for (int p = 0; p <= pairs - 1; p++)
  4563. {
  4564. Elem(result, 2 * p + 0, esize, Elem(operand1, @base + p, esize));
  4565. Elem(result, 2 * p + 1, esize, Elem(operand2, @base + p, esize));
  4566. }
  4567. V(d, result);
  4568. }
  4569. // zip2_advsimd.html
  4570. public static void Zip2_V(bool Q, Bits size, Bits Rm, Bits Rn, Bits Rd)
  4571. {
  4572. const bool op = true;
  4573. /* Decode */
  4574. int d = (int)UInt(Rd);
  4575. int n = (int)UInt(Rn);
  4576. int m = (int)UInt(Rm);
  4577. /* if size:Q == '110' then ReservedValue(); */
  4578. int esize = 8 << (int)UInt(size);
  4579. int datasize = (Q ? 128 : 64);
  4580. int elements = datasize / esize;
  4581. int part = (int)UInt(op);
  4582. int pairs = elements / 2;
  4583. /* Operation */
  4584. /* CheckFPAdvSIMDEnabled64(); */
  4585. Bits result = new Bits(datasize);
  4586. Bits operand1 = V(datasize, n);
  4587. Bits operand2 = V(datasize, m);
  4588. int @base = part * pairs;
  4589. for (int p = 0; p <= pairs - 1; p++)
  4590. {
  4591. Elem(result, 2 * p + 0, esize, Elem(operand1, @base + p, esize));
  4592. Elem(result, 2 * p + 1, esize, Elem(operand2, @base + p, esize));
  4593. }
  4594. V(d, result);
  4595. }
  4596. #endregion
  4597. }
  4598. }