vm_rv32gc.cpp 369KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893
  1. /*******************************************************************************
  2. * Copyright (C) 2017, 2018 MINRES Technologies GmbH
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * 3. Neither the name of the copyright holder nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. *******************************************************************************/
  32. #include <iss/arch/rv32gc.h>
  33. #include <iss/arch/riscv_hart_msu_vp.h>
  34. #include <iss/debugger/gdb_session.h>
  35. #include <iss/debugger/server.h>
  36. #include <iss/iss.h>
  37. #include <iss/llvm/vm_base.h>
  38. #include <util/logging.h>
  39. #define FMT_HEADER_ONLY
  40. #include <fmt/format.h>
  41. #include <array>
  42. #include <iss/debugger/riscv_target_adapter.h>
  43. namespace iss {
  44. namespace vm {
  45. namespace fp_impl {
  46. void add_fp_functions_2_module(llvm::Module *, unsigned, unsigned);
  47. }
  48. }
  49. namespace rv32gc {
  50. using namespace iss::arch;
  51. using namespace llvm;
  52. using namespace iss::debugger;
  53. using namespace iss::vm::llvm;
  54. template <typename ARCH> class vm_impl : public vm_base<ARCH> {
  55. public:
  56. using super = typename iss::vm::llvm::vm_base<ARCH>;
  57. using virt_addr_t = typename super::virt_addr_t;
  58. using phys_addr_t = typename super::phys_addr_t;
  59. using code_word_t = typename super::code_word_t;
  60. using addr_t = typename super::addr_t;
  61. vm_impl();
  62. vm_impl(ARCH &core, unsigned core_id = 0, unsigned cluster_id = 0);
  63. void enableDebug(bool enable) { super::sync_exec = super::ALL_SYNC; }
  64. target_adapter_if *accquire_target_adapter(server_if *srv) override {
  65. debugger_if::dbg_enabled = true;
  66. if (vm_base<ARCH>::tgt_adapter == nullptr)
  67. vm_base<ARCH>::tgt_adapter = new riscv_target_adapter<ARCH>(srv, this->get_arch());
  68. return vm_base<ARCH>::tgt_adapter;
  69. }
  70. protected:
  71. using vm_base<ARCH>::get_reg_ptr;
  72. inline const char *name(size_t index){return traits<ARCH>::reg_aliases.at(index);}
  73. template <typename T> inline ConstantInt *size(T type) {
  74. return ConstantInt::get(getContext(), APInt(32, type->getType()->getScalarSizeInBits()));
  75. }
  76. void setup_module(Module* m) override {
  77. super::setup_module(m);
  78. iss::vm::fp_impl::add_fp_functions_2_module(m, traits<ARCH>::FP_REGS_SIZE, traits<ARCH>::XLEN);
  79. }
  80. inline Value *gen_choose(Value *cond, Value *trueVal, Value *falseVal, unsigned size) {
  81. return super::gen_cond_assign(cond, this->gen_ext(trueVal, size), this->gen_ext(falseVal, size));
  82. }
  83. std::tuple<continuation_e, BasicBlock *> gen_single_inst_behavior(virt_addr_t &, unsigned int &, BasicBlock *) override;
  84. void gen_leave_behavior(BasicBlock *leave_blk) override;
  85. void gen_raise_trap(uint16_t trap_id, uint16_t cause);
  86. void gen_leave_trap(unsigned lvl);
  87. void gen_wait(unsigned type);
  88. void gen_trap_behavior(BasicBlock *) override;
  89. void gen_trap_check(BasicBlock *bb);
  90. inline Value *gen_reg_load(unsigned i, unsigned level = 0) {
  91. return this->builder.CreateLoad(get_reg_ptr(i), false);
  92. }
  93. inline void gen_set_pc(virt_addr_t pc, unsigned reg_num) {
  94. Value *next_pc_v = this->builder.CreateSExtOrTrunc(this->gen_const(traits<ARCH>::XLEN, pc.val),
  95. this->get_type(traits<ARCH>::XLEN));
  96. this->builder.CreateStore(next_pc_v, get_reg_ptr(reg_num), true);
  97. }
  98. // some compile time constants
  99. // enum { MASK16 = 0b1111110001100011, MASK32 = 0b11111111111100000111000001111111 };
  100. enum { MASK16 = 0b1111111111111111, MASK32 = 0b11111111111100000111000001111111 };
  101. enum { EXTR_MASK16 = MASK16 >> 2, EXTR_MASK32 = MASK32 >> 2 };
  102. enum { LUT_SIZE = 1 << util::bit_count(EXTR_MASK32), LUT_SIZE_C = 1 << util::bit_count(EXTR_MASK16) };
  103. using this_class = vm_impl<ARCH>;
  104. using compile_func = std::tuple<continuation_e, BasicBlock *> (this_class::*)(virt_addr_t &pc,
  105. code_word_t instr,
  106. BasicBlock *bb);
  107. std::array<compile_func, LUT_SIZE> lut;
  108. std::array<compile_func, LUT_SIZE_C> lut_00, lut_01, lut_10;
  109. std::array<compile_func, LUT_SIZE> lut_11;
  110. std::array<compile_func *, 4> qlut;
  111. std::array<const uint32_t, 4> lutmasks = {{EXTR_MASK16, EXTR_MASK16, EXTR_MASK16, EXTR_MASK32}};
  112. void expand_bit_mask(int pos, uint32_t mask, uint32_t value, uint32_t valid, uint32_t idx, compile_func lut[],
  113. compile_func f) {
  114. if (pos < 0) {
  115. lut[idx] = f;
  116. } else {
  117. auto bitmask = 1UL << pos;
  118. if ((mask & bitmask) == 0) {
  119. expand_bit_mask(pos - 1, mask, value, valid, idx, lut, f);
  120. } else {
  121. if ((valid & bitmask) == 0) {
  122. expand_bit_mask(pos - 1, mask, value, valid, (idx << 1), lut, f);
  123. expand_bit_mask(pos - 1, mask, value, valid, (idx << 1) + 1, lut, f);
  124. } else {
  125. auto new_val = idx << 1;
  126. if ((value & bitmask) != 0) new_val++;
  127. expand_bit_mask(pos - 1, mask, value, valid, new_val, lut, f);
  128. }
  129. }
  130. }
  131. }
  132. inline uint32_t extract_fields(uint32_t val) { return extract_fields(29, val >> 2, lutmasks[val & 0x3], 0); }
  133. uint32_t extract_fields(int pos, uint32_t val, uint32_t mask, uint32_t lut_val) {
  134. if (pos >= 0) {
  135. auto bitmask = 1UL << pos;
  136. if ((mask & bitmask) == 0) {
  137. lut_val = extract_fields(pos - 1, val, mask, lut_val);
  138. } else {
  139. auto new_val = lut_val << 1;
  140. if ((val & bitmask) != 0) new_val++;
  141. lut_val = extract_fields(pos - 1, val, mask, new_val);
  142. }
  143. }
  144. return lut_val;
  145. }
  146. private:
  147. /****************************************************************************
  148. * start opcode definitions
  149. ****************************************************************************/
  150. struct InstructionDesriptor {
  151. size_t length;
  152. uint32_t value;
  153. uint32_t mask;
  154. compile_func op;
  155. };
  156. const std::array<InstructionDesriptor, 159> instr_descr = {{
  157. /* entries are: size, valid value, valid mask, function ptr */
  158. /* instruction JALR */
  159. {32, 0b00000000000000000000000001100111, 0b00000000000000000111000001111111, &this_class::__jalr},
  160. /* instruction C.ADDI4SPN */
  161. {16, 0b0000000000000000, 0b1110000000000011, &this_class::__c_addi4spn},
  162. /* instruction C.LW */
  163. {16, 0b0100000000000000, 0b1110000000000011, &this_class::__c_lw},
  164. /* instruction C.SW */
  165. {16, 0b1100000000000000, 0b1110000000000011, &this_class::__c_sw},
  166. /* instruction C.ADDI */
  167. {16, 0b0000000000000001, 0b1110000000000011, &this_class::__c_addi},
  168. /* instruction C.NOP */
  169. {16, 0b0000000000000001, 0b1111111111111111, &this_class::__c_nop},
  170. /* instruction C.JAL */
  171. {16, 0b0010000000000001, 0b1110000000000011, &this_class::__c_jal},
  172. /* instruction C.LI */
  173. {16, 0b0100000000000001, 0b1110000000000011, &this_class::__c_li},
  174. /* instruction C.LUI */
  175. {16, 0b0110000000000001, 0b1110000000000011, &this_class::__c_lui},
  176. /* instruction C.ADDI16SP */
  177. {16, 0b0110000100000001, 0b1110111110000011, &this_class::__c_addi16sp},
  178. /* instruction C.SRLI */
  179. {16, 0b1000000000000001, 0b1111110000000011, &this_class::__c_srli},
  180. /* instruction C.SRAI */
  181. {16, 0b1000010000000001, 0b1111110000000011, &this_class::__c_srai},
  182. /* instruction C.ANDI */
  183. {16, 0b1000100000000001, 0b1110110000000011, &this_class::__c_andi},
  184. /* instruction C.SUB */
  185. {16, 0b1000110000000001, 0b1111110001100011, &this_class::__c_sub},
  186. /* instruction C.XOR */
  187. {16, 0b1000110000100001, 0b1111110001100011, &this_class::__c_xor},
  188. /* instruction C.OR */
  189. {16, 0b1000110001000001, 0b1111110001100011, &this_class::__c_or},
  190. /* instruction C.AND */
  191. {16, 0b1000110001100001, 0b1111110001100011, &this_class::__c_and},
  192. /* instruction C.J */
  193. {16, 0b1010000000000001, 0b1110000000000011, &this_class::__c_j},
  194. /* instruction C.BEQZ */
  195. {16, 0b1100000000000001, 0b1110000000000011, &this_class::__c_beqz},
  196. /* instruction C.BNEZ */
  197. {16, 0b1110000000000001, 0b1110000000000011, &this_class::__c_bnez},
  198. /* instruction C.SLLI */
  199. {16, 0b0000000000000010, 0b1111000000000011, &this_class::__c_slli},
  200. /* instruction C.LWSP */
  201. {16, 0b0100000000000010, 0b1110000000000011, &this_class::__c_lwsp},
  202. /* instruction C.MV */
  203. {16, 0b1000000000000010, 0b1111000000000011, &this_class::__c_mv},
  204. /* instruction C.JR */
  205. {16, 0b1000000000000010, 0b1111000001111111, &this_class::__c_jr},
  206. /* instruction C.ADD */
  207. {16, 0b1001000000000010, 0b1111000000000011, &this_class::__c_add},
  208. /* instruction C.JALR */
  209. {16, 0b1001000000000010, 0b1111000001111111, &this_class::__c_jalr},
  210. /* instruction C.EBREAK */
  211. {16, 0b1001000000000010, 0b1111111111111111, &this_class::__c_ebreak},
  212. /* instruction C.SWSP */
  213. {16, 0b1100000000000010, 0b1110000000000011, &this_class::__c_swsp},
  214. /* instruction DII */
  215. {16, 0b0000000000000000, 0b1111111111111111, &this_class::__dii},
  216. /* instruction C.FLD */
  217. {16, 0b0010000000000000, 0b1110000000000011, &this_class::__c_fld},
  218. /* instruction C.FSD */
  219. {16, 0b1010000000000000, 0b1110000000000011, &this_class::__c_fsd},
  220. /* instruction C.FLDSP */
  221. {16, 0b0010000000000010, 0b1110000000000011, &this_class::__c_fldsp},
  222. /* instruction C.FSDSP */
  223. {16, 0b1010000000000010, 0b1110000000000011, &this_class::__c_fsdsp},
  224. /* instruction C.FLW */
  225. {16, 0b0110000000000000, 0b1110000000000011, &this_class::__c_flw},
  226. /* instruction C.FSW */
  227. {16, 0b1110000000000000, 0b1110000000000011, &this_class::__c_fsw},
  228. /* instruction C.FLWSP */
  229. {16, 0b0110000000000010, 0b1110000000000011, &this_class::__c_flwsp},
  230. /* instruction C.FSWSP */
  231. {16, 0b1110000000000010, 0b1110000000000011, &this_class::__c_fswsp},
  232. /* instruction FLD */
  233. {32, 0b00000000000000000011000000000111, 0b00000000000000000111000001111111, &this_class::__fld},
  234. /* instruction FSD */
  235. {32, 0b00000000000000000011000000100111, 0b00000000000000000111000001111111, &this_class::__fsd},
  236. /* instruction FMADD.D */
  237. {32, 0b00000010000000000000000001000011, 0b00000110000000000000000001111111, &this_class::__fmadd_d},
  238. /* instruction FMSUB.D */
  239. {32, 0b00000010000000000000000001000111, 0b00000110000000000000000001111111, &this_class::__fmsub_d},
  240. /* instruction FNMADD.D */
  241. {32, 0b00000010000000000000000001001111, 0b00000110000000000000000001111111, &this_class::__fnmadd_d},
  242. /* instruction FNMSUB.D */
  243. {32, 0b00000010000000000000000001001011, 0b00000110000000000000000001111111, &this_class::__fnmsub_d},
  244. /* instruction FADD.D */
  245. {32, 0b00000010000000000000000001010011, 0b11111110000000000000000001111111, &this_class::__fadd_d},
  246. /* instruction FSUB.D */
  247. {32, 0b00001010000000000000000001010011, 0b11111110000000000000000001111111, &this_class::__fsub_d},
  248. /* instruction FMUL.D */
  249. {32, 0b00010010000000000000000001010011, 0b11111110000000000000000001111111, &this_class::__fmul_d},
  250. /* instruction FDIV.D */
  251. {32, 0b00011010000000000000000001010011, 0b11111110000000000000000001111111, &this_class::__fdiv_d},
  252. /* instruction FSQRT.D */
  253. {32, 0b01011010000000000000000001010011, 0b11111111111100000000000001111111, &this_class::__fsqrt_d},
  254. /* instruction FSGNJ.D */
  255. {32, 0b00100010000000000000000001010011, 0b11111110000000000111000001111111, &this_class::__fsgnj_d},
  256. /* instruction FSGNJN.D */
  257. {32, 0b00100010000000000001000001010011, 0b11111110000000000111000001111111, &this_class::__fsgnjn_d},
  258. /* instruction FSGNJX.D */
  259. {32, 0b00100010000000000010000001010011, 0b11111110000000000111000001111111, &this_class::__fsgnjx_d},
  260. /* instruction FMIN.D */
  261. {32, 0b00101010000000000000000001010011, 0b11111110000000000111000001111111, &this_class::__fmin_d},
  262. /* instruction FMAX.D */
  263. {32, 0b00101010000000000001000001010011, 0b11111110000000000111000001111111, &this_class::__fmax_d},
  264. /* instruction FCVT.S.D */
  265. {32, 0b01000000000100000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_s_d},
  266. /* instruction FCVT.D.S */
  267. {32, 0b01000010000000000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_d_s},
  268. /* instruction FEQ.D */
  269. {32, 0b10100010000000000010000001010011, 0b11111110000000000111000001111111, &this_class::__feq_d},
  270. /* instruction FLT.D */
  271. {32, 0b10100010000000000001000001010011, 0b11111110000000000111000001111111, &this_class::__flt_d},
  272. /* instruction FLE.D */
  273. {32, 0b10100010000000000000000001010011, 0b11111110000000000111000001111111, &this_class::__fle_d},
  274. /* instruction FCLASS.D */
  275. {32, 0b11100010000000000001000001010011, 0b11111111111100000111000001111111, &this_class::__fclass_d},
  276. /* instruction FCVT.W.D */
  277. {32, 0b11000010000000000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_w_d},
  278. /* instruction FCVT.WU.D */
  279. {32, 0b11000010000100000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_wu_d},
  280. /* instruction FCVT.D.W */
  281. {32, 0b11010010000000000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_d_w},
  282. /* instruction FCVT.D.WU */
  283. {32, 0b11010010000100000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_d_wu},
  284. /* instruction LUI */
  285. {32, 0b00000000000000000000000000110111, 0b00000000000000000000000001111111, &this_class::__lui},
  286. /* instruction AUIPC */
  287. {32, 0b00000000000000000000000000010111, 0b00000000000000000000000001111111, &this_class::__auipc},
  288. /* instruction JAL */
  289. {32, 0b00000000000000000000000001101111, 0b00000000000000000000000001111111, &this_class::__jal},
  290. /* instruction BEQ */
  291. {32, 0b00000000000000000000000001100011, 0b00000000000000000111000001111111, &this_class::__beq},
  292. /* instruction BNE */
  293. {32, 0b00000000000000000001000001100011, 0b00000000000000000111000001111111, &this_class::__bne},
  294. /* instruction BLT */
  295. {32, 0b00000000000000000100000001100011, 0b00000000000000000111000001111111, &this_class::__blt},
  296. /* instruction BGE */
  297. {32, 0b00000000000000000101000001100011, 0b00000000000000000111000001111111, &this_class::__bge},
  298. /* instruction BLTU */
  299. {32, 0b00000000000000000110000001100011, 0b00000000000000000111000001111111, &this_class::__bltu},
  300. /* instruction BGEU */
  301. {32, 0b00000000000000000111000001100011, 0b00000000000000000111000001111111, &this_class::__bgeu},
  302. /* instruction LB */
  303. {32, 0b00000000000000000000000000000011, 0b00000000000000000111000001111111, &this_class::__lb},
  304. /* instruction LH */
  305. {32, 0b00000000000000000001000000000011, 0b00000000000000000111000001111111, &this_class::__lh},
  306. /* instruction LW */
  307. {32, 0b00000000000000000010000000000011, 0b00000000000000000111000001111111, &this_class::__lw},
  308. /* instruction LBU */
  309. {32, 0b00000000000000000100000000000011, 0b00000000000000000111000001111111, &this_class::__lbu},
  310. /* instruction LHU */
  311. {32, 0b00000000000000000101000000000011, 0b00000000000000000111000001111111, &this_class::__lhu},
  312. /* instruction SB */
  313. {32, 0b00000000000000000000000000100011, 0b00000000000000000111000001111111, &this_class::__sb},
  314. /* instruction SH */
  315. {32, 0b00000000000000000001000000100011, 0b00000000000000000111000001111111, &this_class::__sh},
  316. /* instruction SW */
  317. {32, 0b00000000000000000010000000100011, 0b00000000000000000111000001111111, &this_class::__sw},
  318. /* instruction ADDI */
  319. {32, 0b00000000000000000000000000010011, 0b00000000000000000111000001111111, &this_class::__addi},
  320. /* instruction SLTI */
  321. {32, 0b00000000000000000010000000010011, 0b00000000000000000111000001111111, &this_class::__slti},
  322. /* instruction SLTIU */
  323. {32, 0b00000000000000000011000000010011, 0b00000000000000000111000001111111, &this_class::__sltiu},
  324. /* instruction XORI */
  325. {32, 0b00000000000000000100000000010011, 0b00000000000000000111000001111111, &this_class::__xori},
  326. /* instruction ORI */
  327. {32, 0b00000000000000000110000000010011, 0b00000000000000000111000001111111, &this_class::__ori},
  328. /* instruction ANDI */
  329. {32, 0b00000000000000000111000000010011, 0b00000000000000000111000001111111, &this_class::__andi},
  330. /* instruction SLLI */
  331. {32, 0b00000000000000000001000000010011, 0b11111110000000000111000001111111, &this_class::__slli},
  332. /* instruction SRLI */
  333. {32, 0b00000000000000000101000000010011, 0b11111110000000000111000001111111, &this_class::__srli},
  334. /* instruction SRAI */
  335. {32, 0b01000000000000000101000000010011, 0b11111110000000000111000001111111, &this_class::__srai},
  336. /* instruction ADD */
  337. {32, 0b00000000000000000000000000110011, 0b11111110000000000111000001111111, &this_class::__add},
  338. /* instruction SUB */
  339. {32, 0b01000000000000000000000000110011, 0b11111110000000000111000001111111, &this_class::__sub},
  340. /* instruction SLL */
  341. {32, 0b00000000000000000001000000110011, 0b11111110000000000111000001111111, &this_class::__sll},
  342. /* instruction SLT */
  343. {32, 0b00000000000000000010000000110011, 0b11111110000000000111000001111111, &this_class::__slt},
  344. /* instruction SLTU */
  345. {32, 0b00000000000000000011000000110011, 0b11111110000000000111000001111111, &this_class::__sltu},
  346. /* instruction XOR */
  347. {32, 0b00000000000000000100000000110011, 0b11111110000000000111000001111111, &this_class::__xor},
  348. /* instruction SRL */
  349. {32, 0b00000000000000000101000000110011, 0b11111110000000000111000001111111, &this_class::__srl},
  350. /* instruction SRA */
  351. {32, 0b01000000000000000101000000110011, 0b11111110000000000111000001111111, &this_class::__sra},
  352. /* instruction OR */
  353. {32, 0b00000000000000000110000000110011, 0b11111110000000000111000001111111, &this_class::__or},
  354. /* instruction AND */
  355. {32, 0b00000000000000000111000000110011, 0b11111110000000000111000001111111, &this_class::__and},
  356. /* instruction FENCE */
  357. {32, 0b00000000000000000000000000001111, 0b11110000000000000111000001111111, &this_class::__fence},
  358. /* instruction FENCE_I */
  359. {32, 0b00000000000000000001000000001111, 0b00000000000000000111000001111111, &this_class::__fence_i},
  360. /* instruction ECALL */
  361. {32, 0b00000000000000000000000001110011, 0b11111111111111111111111111111111, &this_class::__ecall},
  362. /* instruction EBREAK */
  363. {32, 0b00000000000100000000000001110011, 0b11111111111111111111111111111111, &this_class::__ebreak},
  364. /* instruction URET */
  365. {32, 0b00000000001000000000000001110011, 0b11111111111111111111111111111111, &this_class::__uret},
  366. /* instruction SRET */
  367. {32, 0b00010000001000000000000001110011, 0b11111111111111111111111111111111, &this_class::__sret},
  368. /* instruction MRET */
  369. {32, 0b00110000001000000000000001110011, 0b11111111111111111111111111111111, &this_class::__mret},
  370. /* instruction WFI */
  371. {32, 0b00010000010100000000000001110011, 0b11111111111111111111111111111111, &this_class::__wfi},
  372. /* instruction SFENCE.VMA */
  373. {32, 0b00010010000000000000000001110011, 0b11111110000000000111111111111111, &this_class::__sfence_vma},
  374. /* instruction CSRRW */
  375. {32, 0b00000000000000000001000001110011, 0b00000000000000000111000001111111, &this_class::__csrrw},
  376. /* instruction CSRRS */
  377. {32, 0b00000000000000000010000001110011, 0b00000000000000000111000001111111, &this_class::__csrrs},
  378. /* instruction CSRRC */
  379. {32, 0b00000000000000000011000001110011, 0b00000000000000000111000001111111, &this_class::__csrrc},
  380. /* instruction CSRRWI */
  381. {32, 0b00000000000000000101000001110011, 0b00000000000000000111000001111111, &this_class::__csrrwi},
  382. /* instruction CSRRSI */
  383. {32, 0b00000000000000000110000001110011, 0b00000000000000000111000001111111, &this_class::__csrrsi},
  384. /* instruction CSRRCI */
  385. {32, 0b00000000000000000111000001110011, 0b00000000000000000111000001111111, &this_class::__csrrci},
  386. /* instruction FLW */
  387. {32, 0b00000000000000000010000000000111, 0b00000000000000000111000001111111, &this_class::__flw},
  388. /* instruction FSW */
  389. {32, 0b00000000000000000010000000100111, 0b00000000000000000111000001111111, &this_class::__fsw},
  390. /* instruction FMADD.S */
  391. {32, 0b00000000000000000000000001000011, 0b00000110000000000000000001111111, &this_class::__fmadd_s},
  392. /* instruction FMSUB.S */
  393. {32, 0b00000000000000000000000001000111, 0b00000110000000000000000001111111, &this_class::__fmsub_s},
  394. /* instruction FNMADD.S */
  395. {32, 0b00000000000000000000000001001111, 0b00000110000000000000000001111111, &this_class::__fnmadd_s},
  396. /* instruction FNMSUB.S */
  397. {32, 0b00000000000000000000000001001011, 0b00000110000000000000000001111111, &this_class::__fnmsub_s},
  398. /* instruction FADD.S */
  399. {32, 0b00000000000000000000000001010011, 0b11111110000000000000000001111111, &this_class::__fadd_s},
  400. /* instruction FSUB.S */
  401. {32, 0b00001000000000000000000001010011, 0b11111110000000000000000001111111, &this_class::__fsub_s},
  402. /* instruction FMUL.S */
  403. {32, 0b00010000000000000000000001010011, 0b11111110000000000000000001111111, &this_class::__fmul_s},
  404. /* instruction FDIV.S */
  405. {32, 0b00011000000000000000000001010011, 0b11111110000000000000000001111111, &this_class::__fdiv_s},
  406. /* instruction FSQRT.S */
  407. {32, 0b01011000000000000000000001010011, 0b11111111111100000000000001111111, &this_class::__fsqrt_s},
  408. /* instruction FSGNJ.S */
  409. {32, 0b00100000000000000000000001010011, 0b11111110000000000111000001111111, &this_class::__fsgnj_s},
  410. /* instruction FSGNJN.S */
  411. {32, 0b00100000000000000001000001010011, 0b11111110000000000111000001111111, &this_class::__fsgnjn_s},
  412. /* instruction FSGNJX.S */
  413. {32, 0b00100000000000000010000001010011, 0b11111110000000000111000001111111, &this_class::__fsgnjx_s},
  414. /* instruction FMIN.S */
  415. {32, 0b00101000000000000000000001010011, 0b11111110000000000111000001111111, &this_class::__fmin_s},
  416. /* instruction FMAX.S */
  417. {32, 0b00101000000000000001000001010011, 0b11111110000000000111000001111111, &this_class::__fmax_s},
  418. /* instruction FCVT.W.S */
  419. {32, 0b11000000000000000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_w_s},
  420. /* instruction FCVT.WU.S */
  421. {32, 0b11000000000100000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_wu_s},
  422. /* instruction FEQ.S */
  423. {32, 0b10100000000000000010000001010011, 0b11111110000000000111000001111111, &this_class::__feq_s},
  424. /* instruction FLT.S */
  425. {32, 0b10100000000000000001000001010011, 0b11111110000000000111000001111111, &this_class::__flt_s},
  426. /* instruction FLE.S */
  427. {32, 0b10100000000000000000000001010011, 0b11111110000000000111000001111111, &this_class::__fle_s},
  428. /* instruction FCLASS.S */
  429. {32, 0b11100000000000000001000001010011, 0b11111111111100000111000001111111, &this_class::__fclass_s},
  430. /* instruction FCVT.S.W */
  431. {32, 0b11010000000000000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_s_w},
  432. /* instruction FCVT.S.WU */
  433. {32, 0b11010000000100000000000001010011, 0b11111111111100000000000001111111, &this_class::__fcvt_s_wu},
  434. /* instruction FMV.X.W */
  435. {32, 0b11100000000000000000000001010011, 0b11111111111100000111000001111111, &this_class::__fmv_x_w},
  436. /* instruction FMV.W.X */
  437. {32, 0b11110000000000000000000001010011, 0b11111111111100000111000001111111, &this_class::__fmv_w_x},
  438. /* instruction LR.W */
  439. {32, 0b00010000000000000010000000101111, 0b11111001111100000111000001111111, &this_class::__lr_w},
  440. /* instruction SC.W */
  441. {32, 0b00011000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__sc_w},
  442. /* instruction AMOSWAP.W */
  443. {32, 0b00001000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amoswap_w},
  444. /* instruction AMOADD.W */
  445. {32, 0b00000000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amoadd_w},
  446. /* instruction AMOXOR.W */
  447. {32, 0b00100000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amoxor_w},
  448. /* instruction AMOAND.W */
  449. {32, 0b01100000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amoand_w},
  450. /* instruction AMOOR.W */
  451. {32, 0b01000000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amoor_w},
  452. /* instruction AMOMIN.W */
  453. {32, 0b10000000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amomin_w},
  454. /* instruction AMOMAX.W */
  455. {32, 0b10100000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amomax_w},
  456. /* instruction AMOMINU.W */
  457. {32, 0b11000000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amominu_w},
  458. /* instruction AMOMAXU.W */
  459. {32, 0b11100000000000000010000000101111, 0b11111000000000000111000001111111, &this_class::__amomaxu_w},
  460. /* instruction MUL */
  461. {32, 0b00000010000000000000000000110011, 0b11111110000000000111000001111111, &this_class::__mul},
  462. /* instruction MULH */
  463. {32, 0b00000010000000000001000000110011, 0b11111110000000000111000001111111, &this_class::__mulh},
  464. /* instruction MULHSU */
  465. {32, 0b00000010000000000010000000110011, 0b11111110000000000111000001111111, &this_class::__mulhsu},
  466. /* instruction MULHU */
  467. {32, 0b00000010000000000011000000110011, 0b11111110000000000111000001111111, &this_class::__mulhu},
  468. /* instruction DIV */
  469. {32, 0b00000010000000000100000000110011, 0b11111110000000000111000001111111, &this_class::__div},
  470. /* instruction DIVU */
  471. {32, 0b00000010000000000101000000110011, 0b11111110000000000111000001111111, &this_class::__divu},
  472. /* instruction REM */
  473. {32, 0b00000010000000000110000000110011, 0b11111110000000000111000001111111, &this_class::__rem},
  474. /* instruction REMU */
  475. {32, 0b00000010000000000111000000110011, 0b11111110000000000111000001111111, &this_class::__remu},
  476. }};
  477. /* instruction definitions */
  478. /* instruction 0: JALR */
  479. std::tuple<continuation_e, BasicBlock*> __jalr(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  480. bb->setName("JALR");
  481. this->gen_sync(PRE_SYNC, 0);
  482. uint8_t rd = ((bit_sub<7,5>(instr)));
  483. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  484. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  485. if(this->disass_enabled){
  486. /* generate console output when executing the command */
  487. auto mnemonic = fmt::format(
  488. "{mnemonic:10} {rd}, {rs1}, {imm:#0x}", fmt::arg("mnemonic", "jalr"),
  489. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
  490. std::vector<Value*> args {
  491. this->core_ptr,
  492. this->gen_const(64, pc.val),
  493. this->builder.CreateGlobalStringPtr(mnemonic),
  494. };
  495. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  496. }
  497. Value* cur_pc_val = this->gen_const(32, pc.val);
  498. pc=pc+4;
  499. Value* new_pc_val = this->builder.CreateAdd(
  500. this->gen_ext(
  501. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  502. 32, true),
  503. this->gen_const(32U, imm));
  504. Value* align_val = this->builder.CreateAnd(
  505. new_pc_val,
  506. this->gen_const(32U, 0x2));
  507. {
  508. BasicBlock* bbnext = BasicBlock::Create(this->mod->getContext(), "endif", this->func, this->leave_blk);
  509. BasicBlock* bb_then = BasicBlock::Create(this->mod->getContext(), "thenbr", this->func, bbnext);
  510. BasicBlock* bb_else = BasicBlock::Create(this->mod->getContext(), "elsebr", this->func, bbnext);
  511. // this->builder.SetInsertPoint(bb);
  512. this->gen_cond_branch(this->builder.CreateICmp(
  513. ICmpInst::ICMP_NE,
  514. align_val,
  515. this->gen_const(32U, 0)),
  516. bb_then,
  517. bb_else);
  518. this->builder.SetInsertPoint(bb_then);
  519. {
  520. this->gen_raise_trap(0, 0);
  521. }
  522. this->builder.CreateBr(bbnext);
  523. this->builder.SetInsertPoint(bb_else);
  524. {
  525. if(rd != 0){
  526. Value* Xtmp0_val = this->builder.CreateAdd(
  527. cur_pc_val,
  528. this->gen_const(32U, 4));
  529. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  530. }
  531. Value* PC_val = this->builder.CreateAnd(
  532. new_pc_val,
  533. this->builder.CreateNot(this->gen_const(32U, 0x1)));
  534. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  535. this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  536. }
  537. this->builder.CreateBr(bbnext);
  538. bb=bbnext;
  539. }
  540. this->builder.SetInsertPoint(bb);
  541. this->gen_sync(POST_SYNC, 0);
  542. this->gen_trap_check(this->leave_blk);
  543. return std::make_tuple(BRANCH, nullptr);
  544. }
  545. /* instruction 1: C.ADDI4SPN */
  546. std::tuple<continuation_e, BasicBlock*> __c_addi4spn(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  547. bb->setName("C.ADDI4SPN");
  548. this->gen_sync(PRE_SYNC, 1);
  549. uint8_t rd = ((bit_sub<2,3>(instr)));
  550. uint16_t imm = ((bit_sub<5,1>(instr) << 3) | (bit_sub<6,1>(instr) << 2) | (bit_sub<7,4>(instr) << 6) | (bit_sub<11,2>(instr) << 4));
  551. if(this->disass_enabled){
  552. /* generate console output when executing the command */
  553. auto mnemonic = fmt::format(
  554. "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.addi4spn"),
  555. fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
  556. std::vector<Value*> args {
  557. this->core_ptr,
  558. this->gen_const(64, pc.val),
  559. this->builder.CreateGlobalStringPtr(mnemonic),
  560. };
  561. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  562. }
  563. Value* cur_pc_val = this->gen_const(32, pc.val);
  564. pc=pc+2;
  565. if(imm == 0){
  566. this->gen_raise_trap(0, 2);
  567. }
  568. Value* Xtmp0_val = this->builder.CreateAdd(
  569. this->gen_reg_load(2 + traits<ARCH>::X0, 0),
  570. this->gen_const(32U, imm));
  571. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + 8 + traits<ARCH>::X0), false);
  572. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  573. this->gen_sync(POST_SYNC, 1);
  574. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  575. this->gen_trap_check(bb);
  576. return std::make_tuple(CONT, bb);
  577. }
  578. /* instruction 2: C.LW */
  579. std::tuple<continuation_e, BasicBlock*> __c_lw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  580. bb->setName("C.LW");
  581. this->gen_sync(PRE_SYNC, 2);
  582. uint8_t rd = ((bit_sub<2,3>(instr)));
  583. uint8_t uimm = ((bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 2) | (bit_sub<10,3>(instr) << 3));
  584. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  585. if(this->disass_enabled){
  586. /* generate console output when executing the command */
  587. auto mnemonic = fmt::format(
  588. "{mnemonic:10} {rd}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c.lw"),
  589. fmt::arg("rd", name(8+rd)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
  590. std::vector<Value*> args {
  591. this->core_ptr,
  592. this->gen_const(64, pc.val),
  593. this->builder.CreateGlobalStringPtr(mnemonic),
  594. };
  595. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  596. }
  597. Value* cur_pc_val = this->gen_const(32, pc.val);
  598. pc=pc+2;
  599. Value* offs_val = this->builder.CreateAdd(
  600. this->gen_reg_load(rs1 + 8 + traits<ARCH>::X0, 0),
  601. this->gen_const(32U, uimm));
  602. Value* Xtmp0_val = this->gen_ext(
  603. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  604. 32,
  605. true);
  606. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + 8 + traits<ARCH>::X0), false);
  607. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  608. this->gen_sync(POST_SYNC, 2);
  609. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  610. this->gen_trap_check(bb);
  611. return std::make_tuple(CONT, bb);
  612. }
  613. /* instruction 3: C.SW */
  614. std::tuple<continuation_e, BasicBlock*> __c_sw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  615. bb->setName("C.SW");
  616. this->gen_sync(PRE_SYNC, 3);
  617. uint8_t rs2 = ((bit_sub<2,3>(instr)));
  618. uint8_t uimm = ((bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 2) | (bit_sub<10,3>(instr) << 3));
  619. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  620. if(this->disass_enabled){
  621. /* generate console output when executing the command */
  622. auto mnemonic = fmt::format(
  623. "{mnemonic:10} {rs2}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c.sw"),
  624. fmt::arg("rs2", name(8+rs2)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
  625. std::vector<Value*> args {
  626. this->core_ptr,
  627. this->gen_const(64, pc.val),
  628. this->builder.CreateGlobalStringPtr(mnemonic),
  629. };
  630. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  631. }
  632. Value* cur_pc_val = this->gen_const(32, pc.val);
  633. pc=pc+2;
  634. Value* offs_val = this->builder.CreateAdd(
  635. this->gen_reg_load(rs1 + 8 + traits<ARCH>::X0, 0),
  636. this->gen_const(32U, uimm));
  637. Value* MEMtmp0_val = this->gen_reg_load(rs2 + 8 + traits<ARCH>::X0, 0);
  638. this->gen_write_mem(
  639. traits<ARCH>::MEM,
  640. offs_val,
  641. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(32)));
  642. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  643. this->gen_sync(POST_SYNC, 3);
  644. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  645. this->gen_trap_check(bb);
  646. return std::make_tuple(CONT, bb);
  647. }
  648. /* instruction 4: C.ADDI */
  649. std::tuple<continuation_e, BasicBlock*> __c_addi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  650. bb->setName("C.ADDI");
  651. this->gen_sync(PRE_SYNC, 4);
  652. int8_t imm = signextend<int8_t,6>((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
  653. uint8_t rs1 = ((bit_sub<7,5>(instr)));
  654. if(this->disass_enabled){
  655. /* generate console output when executing the command */
  656. auto mnemonic = fmt::format(
  657. "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.addi"),
  658. fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
  659. std::vector<Value*> args {
  660. this->core_ptr,
  661. this->gen_const(64, pc.val),
  662. this->builder.CreateGlobalStringPtr(mnemonic),
  663. };
  664. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  665. }
  666. Value* cur_pc_val = this->gen_const(32, pc.val);
  667. pc=pc+2;
  668. Value* Xtmp0_val = this->builder.CreateAdd(
  669. this->gen_ext(
  670. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  671. 32, true),
  672. this->gen_const(32U, imm));
  673. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rs1 + traits<ARCH>::X0), false);
  674. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  675. this->gen_sync(POST_SYNC, 4);
  676. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  677. this->gen_trap_check(bb);
  678. return std::make_tuple(CONT, bb);
  679. }
  680. /* instruction 5: C.NOP */
  681. std::tuple<continuation_e, BasicBlock*> __c_nop(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  682. bb->setName("C.NOP");
  683. this->gen_sync(PRE_SYNC, 5);
  684. if(this->disass_enabled){
  685. /* generate console output when executing the command */
  686. std::vector<Value*> args {
  687. this->core_ptr,
  688. this->gen_const(64, pc.val),
  689. this->builder.CreateGlobalStringPtr("c.nop"),
  690. };
  691. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  692. }
  693. Value* cur_pc_val = this->gen_const(32, pc.val);
  694. pc=pc+2;
  695. /* TODO: describe operations for C.NOP ! */
  696. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  697. this->gen_sync(POST_SYNC, 5);
  698. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  699. this->gen_trap_check(bb);
  700. return std::make_tuple(CONT, bb);
  701. }
  702. /* instruction 6: C.JAL */
  703. std::tuple<continuation_e, BasicBlock*> __c_jal(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  704. bb->setName("C.JAL");
  705. this->gen_sync(PRE_SYNC, 6);
  706. int16_t imm = signextend<int16_t,12>((bit_sub<2,1>(instr) << 5) | (bit_sub<3,3>(instr) << 1) | (bit_sub<6,1>(instr) << 7) | (bit_sub<7,1>(instr) << 6) | (bit_sub<8,1>(instr) << 10) | (bit_sub<9,2>(instr) << 8) | (bit_sub<11,1>(instr) << 4) | (bit_sub<12,1>(instr) << 11));
  707. if(this->disass_enabled){
  708. /* generate console output when executing the command */
  709. auto mnemonic = fmt::format(
  710. "{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c.jal"),
  711. fmt::arg("imm", imm));
  712. std::vector<Value*> args {
  713. this->core_ptr,
  714. this->gen_const(64, pc.val),
  715. this->builder.CreateGlobalStringPtr(mnemonic),
  716. };
  717. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  718. }
  719. Value* cur_pc_val = this->gen_const(32, pc.val);
  720. pc=pc+2;
  721. Value* Xtmp0_val = this->builder.CreateAdd(
  722. cur_pc_val,
  723. this->gen_const(32U, 2));
  724. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(1 + traits<ARCH>::X0), false);
  725. Value* PC_val = this->builder.CreateAdd(
  726. this->gen_ext(
  727. cur_pc_val,
  728. 32, true),
  729. this->gen_const(32U, imm));
  730. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  731. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  732. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  733. this->gen_sync(POST_SYNC, 6);
  734. this->gen_trap_check(this->leave_blk);
  735. return std::make_tuple(BRANCH, nullptr);
  736. }
  737. /* instruction 7: C.LI */
  738. std::tuple<continuation_e, BasicBlock*> __c_li(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  739. bb->setName("C.LI");
  740. this->gen_sync(PRE_SYNC, 7);
  741. int8_t imm = signextend<int8_t,6>((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
  742. uint8_t rd = ((bit_sub<7,5>(instr)));
  743. if(this->disass_enabled){
  744. /* generate console output when executing the command */
  745. auto mnemonic = fmt::format(
  746. "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.li"),
  747. fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
  748. std::vector<Value*> args {
  749. this->core_ptr,
  750. this->gen_const(64, pc.val),
  751. this->builder.CreateGlobalStringPtr(mnemonic),
  752. };
  753. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  754. }
  755. Value* cur_pc_val = this->gen_const(32, pc.val);
  756. pc=pc+2;
  757. if(rd == 0){
  758. this->gen_raise_trap(0, 2);
  759. }
  760. Value* Xtmp0_val = this->gen_const(32U, imm);
  761. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  762. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  763. this->gen_sync(POST_SYNC, 7);
  764. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  765. this->gen_trap_check(bb);
  766. return std::make_tuple(CONT, bb);
  767. }
  768. /* instruction 8: C.LUI */
  769. std::tuple<continuation_e, BasicBlock*> __c_lui(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  770. bb->setName("C.LUI");
  771. this->gen_sync(PRE_SYNC, 8);
  772. int32_t imm = signextend<int32_t,18>((bit_sub<2,5>(instr) << 12) | (bit_sub<12,1>(instr) << 17));
  773. uint8_t rd = ((bit_sub<7,5>(instr)));
  774. if(this->disass_enabled){
  775. /* generate console output when executing the command */
  776. auto mnemonic = fmt::format(
  777. "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.lui"),
  778. fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
  779. std::vector<Value*> args {
  780. this->core_ptr,
  781. this->gen_const(64, pc.val),
  782. this->builder.CreateGlobalStringPtr(mnemonic),
  783. };
  784. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  785. }
  786. Value* cur_pc_val = this->gen_const(32, pc.val);
  787. pc=pc+2;
  788. if(rd == 0){
  789. this->gen_raise_trap(0, 2);
  790. }
  791. if(imm == 0){
  792. this->gen_raise_trap(0, 2);
  793. }
  794. Value* Xtmp0_val = this->gen_const(32U, imm);
  795. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  796. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  797. this->gen_sync(POST_SYNC, 8);
  798. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  799. this->gen_trap_check(bb);
  800. return std::make_tuple(CONT, bb);
  801. }
  802. /* instruction 9: C.ADDI16SP */
  803. std::tuple<continuation_e, BasicBlock*> __c_addi16sp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  804. bb->setName("C.ADDI16SP");
  805. this->gen_sync(PRE_SYNC, 9);
  806. int16_t imm = signextend<int16_t,10>((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 7) | (bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 4) | (bit_sub<12,1>(instr) << 9));
  807. if(this->disass_enabled){
  808. /* generate console output when executing the command */
  809. auto mnemonic = fmt::format(
  810. "{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c.addi16sp"),
  811. fmt::arg("imm", imm));
  812. std::vector<Value*> args {
  813. this->core_ptr,
  814. this->gen_const(64, pc.val),
  815. this->builder.CreateGlobalStringPtr(mnemonic),
  816. };
  817. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  818. }
  819. Value* cur_pc_val = this->gen_const(32, pc.val);
  820. pc=pc+2;
  821. Value* Xtmp0_val = this->builder.CreateAdd(
  822. this->gen_ext(
  823. this->gen_reg_load(2 + traits<ARCH>::X0, 0),
  824. 32, true),
  825. this->gen_const(32U, imm));
  826. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(2 + traits<ARCH>::X0), false);
  827. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  828. this->gen_sync(POST_SYNC, 9);
  829. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  830. this->gen_trap_check(bb);
  831. return std::make_tuple(CONT, bb);
  832. }
  833. /* instruction 10: C.SRLI */
  834. std::tuple<continuation_e, BasicBlock*> __c_srli(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  835. bb->setName("C.SRLI");
  836. this->gen_sync(PRE_SYNC, 10);
  837. uint8_t shamt = ((bit_sub<2,5>(instr)));
  838. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  839. if(this->disass_enabled){
  840. /* generate console output when executing the command */
  841. auto mnemonic = fmt::format(
  842. "{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c.srli"),
  843. fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt));
  844. std::vector<Value*> args {
  845. this->core_ptr,
  846. this->gen_const(64, pc.val),
  847. this->builder.CreateGlobalStringPtr(mnemonic),
  848. };
  849. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  850. }
  851. Value* cur_pc_val = this->gen_const(32, pc.val);
  852. pc=pc+2;
  853. uint8_t rs1_idx_val = rs1 + 8;
  854. Value* Xtmp0_val = this->builder.CreateLShr(
  855. this->gen_reg_load(rs1_idx_val + traits<ARCH>::X0, 0),
  856. this->gen_const(32U, shamt));
  857. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rs1_idx_val + traits<ARCH>::X0), false);
  858. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  859. this->gen_sync(POST_SYNC, 10);
  860. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  861. this->gen_trap_check(bb);
  862. return std::make_tuple(CONT, bb);
  863. }
  864. /* instruction 11: C.SRAI */
  865. std::tuple<continuation_e, BasicBlock*> __c_srai(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  866. bb->setName("C.SRAI");
  867. this->gen_sync(PRE_SYNC, 11);
  868. uint8_t shamt = ((bit_sub<2,5>(instr)));
  869. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  870. if(this->disass_enabled){
  871. /* generate console output when executing the command */
  872. auto mnemonic = fmt::format(
  873. "{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c.srai"),
  874. fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt));
  875. std::vector<Value*> args {
  876. this->core_ptr,
  877. this->gen_const(64, pc.val),
  878. this->builder.CreateGlobalStringPtr(mnemonic),
  879. };
  880. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  881. }
  882. Value* cur_pc_val = this->gen_const(32, pc.val);
  883. pc=pc+2;
  884. uint8_t rs1_idx_val = rs1 + 8;
  885. Value* Xtmp0_val = this->builder.CreateAShr(
  886. this->gen_reg_load(rs1_idx_val + traits<ARCH>::X0, 0),
  887. this->gen_const(32U, shamt));
  888. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rs1_idx_val + traits<ARCH>::X0), false);
  889. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  890. this->gen_sync(POST_SYNC, 11);
  891. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  892. this->gen_trap_check(bb);
  893. return std::make_tuple(CONT, bb);
  894. }
  895. /* instruction 12: C.ANDI */
  896. std::tuple<continuation_e, BasicBlock*> __c_andi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  897. bb->setName("C.ANDI");
  898. this->gen_sync(PRE_SYNC, 12);
  899. int8_t imm = signextend<int8_t,6>((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
  900. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  901. if(this->disass_enabled){
  902. /* generate console output when executing the command */
  903. auto mnemonic = fmt::format(
  904. "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.andi"),
  905. fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
  906. std::vector<Value*> args {
  907. this->core_ptr,
  908. this->gen_const(64, pc.val),
  909. this->builder.CreateGlobalStringPtr(mnemonic),
  910. };
  911. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  912. }
  913. Value* cur_pc_val = this->gen_const(32, pc.val);
  914. pc=pc+2;
  915. uint8_t rs1_idx_val = rs1 + 8;
  916. Value* Xtmp0_val = this->builder.CreateAnd(
  917. this->gen_ext(
  918. this->gen_reg_load(rs1_idx_val + traits<ARCH>::X0, 0),
  919. 32, true),
  920. this->gen_const(32U, imm));
  921. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rs1_idx_val + traits<ARCH>::X0), false);
  922. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  923. this->gen_sync(POST_SYNC, 12);
  924. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  925. this->gen_trap_check(bb);
  926. return std::make_tuple(CONT, bb);
  927. }
  928. /* instruction 13: C.SUB */
  929. std::tuple<continuation_e, BasicBlock*> __c_sub(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  930. bb->setName("C.SUB");
  931. this->gen_sync(PRE_SYNC, 13);
  932. uint8_t rs2 = ((bit_sub<2,3>(instr)));
  933. uint8_t rd = ((bit_sub<7,3>(instr)));
  934. if(this->disass_enabled){
  935. /* generate console output when executing the command */
  936. auto mnemonic = fmt::format(
  937. "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.sub"),
  938. fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
  939. std::vector<Value*> args {
  940. this->core_ptr,
  941. this->gen_const(64, pc.val),
  942. this->builder.CreateGlobalStringPtr(mnemonic),
  943. };
  944. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  945. }
  946. Value* cur_pc_val = this->gen_const(32, pc.val);
  947. pc=pc+2;
  948. uint8_t rd_idx_val = rd + 8;
  949. Value* Xtmp0_val = this->builder.CreateSub(
  950. this->gen_reg_load(rd_idx_val + traits<ARCH>::X0, 0),
  951. this->gen_reg_load(rs2 + 8 + traits<ARCH>::X0, 0));
  952. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd_idx_val + traits<ARCH>::X0), false);
  953. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  954. this->gen_sync(POST_SYNC, 13);
  955. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  956. this->gen_trap_check(bb);
  957. return std::make_tuple(CONT, bb);
  958. }
  959. /* instruction 14: C.XOR */
  960. std::tuple<continuation_e, BasicBlock*> __c_xor(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  961. bb->setName("C.XOR");
  962. this->gen_sync(PRE_SYNC, 14);
  963. uint8_t rs2 = ((bit_sub<2,3>(instr)));
  964. uint8_t rd = ((bit_sub<7,3>(instr)));
  965. if(this->disass_enabled){
  966. /* generate console output when executing the command */
  967. auto mnemonic = fmt::format(
  968. "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.xor"),
  969. fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
  970. std::vector<Value*> args {
  971. this->core_ptr,
  972. this->gen_const(64, pc.val),
  973. this->builder.CreateGlobalStringPtr(mnemonic),
  974. };
  975. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  976. }
  977. Value* cur_pc_val = this->gen_const(32, pc.val);
  978. pc=pc+2;
  979. uint8_t rd_idx_val = rd + 8;
  980. Value* Xtmp0_val = this->builder.CreateXor(
  981. this->gen_reg_load(rd_idx_val + traits<ARCH>::X0, 0),
  982. this->gen_reg_load(rs2 + 8 + traits<ARCH>::X0, 0));
  983. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd_idx_val + traits<ARCH>::X0), false);
  984. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  985. this->gen_sync(POST_SYNC, 14);
  986. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  987. this->gen_trap_check(bb);
  988. return std::make_tuple(CONT, bb);
  989. }
  990. /* instruction 15: C.OR */
  991. std::tuple<continuation_e, BasicBlock*> __c_or(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  992. bb->setName("C.OR");
  993. this->gen_sync(PRE_SYNC, 15);
  994. uint8_t rs2 = ((bit_sub<2,3>(instr)));
  995. uint8_t rd = ((bit_sub<7,3>(instr)));
  996. if(this->disass_enabled){
  997. /* generate console output when executing the command */
  998. auto mnemonic = fmt::format(
  999. "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.or"),
  1000. fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
  1001. std::vector<Value*> args {
  1002. this->core_ptr,
  1003. this->gen_const(64, pc.val),
  1004. this->builder.CreateGlobalStringPtr(mnemonic),
  1005. };
  1006. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1007. }
  1008. Value* cur_pc_val = this->gen_const(32, pc.val);
  1009. pc=pc+2;
  1010. uint8_t rd_idx_val = rd + 8;
  1011. Value* Xtmp0_val = this->builder.CreateOr(
  1012. this->gen_reg_load(rd_idx_val + traits<ARCH>::X0, 0),
  1013. this->gen_reg_load(rs2 + 8 + traits<ARCH>::X0, 0));
  1014. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd_idx_val + traits<ARCH>::X0), false);
  1015. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1016. this->gen_sync(POST_SYNC, 15);
  1017. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1018. this->gen_trap_check(bb);
  1019. return std::make_tuple(CONT, bb);
  1020. }
  1021. /* instruction 16: C.AND */
  1022. std::tuple<continuation_e, BasicBlock*> __c_and(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1023. bb->setName("C.AND");
  1024. this->gen_sync(PRE_SYNC, 16);
  1025. uint8_t rs2 = ((bit_sub<2,3>(instr)));
  1026. uint8_t rd = ((bit_sub<7,3>(instr)));
  1027. if(this->disass_enabled){
  1028. /* generate console output when executing the command */
  1029. auto mnemonic = fmt::format(
  1030. "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.and"),
  1031. fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
  1032. std::vector<Value*> args {
  1033. this->core_ptr,
  1034. this->gen_const(64, pc.val),
  1035. this->builder.CreateGlobalStringPtr(mnemonic),
  1036. };
  1037. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1038. }
  1039. Value* cur_pc_val = this->gen_const(32, pc.val);
  1040. pc=pc+2;
  1041. uint8_t rd_idx_val = rd + 8;
  1042. Value* Xtmp0_val = this->builder.CreateAnd(
  1043. this->gen_reg_load(rd_idx_val + traits<ARCH>::X0, 0),
  1044. this->gen_reg_load(rs2 + 8 + traits<ARCH>::X0, 0));
  1045. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd_idx_val + traits<ARCH>::X0), false);
  1046. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1047. this->gen_sync(POST_SYNC, 16);
  1048. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1049. this->gen_trap_check(bb);
  1050. return std::make_tuple(CONT, bb);
  1051. }
  1052. /* instruction 17: C.J */
  1053. std::tuple<continuation_e, BasicBlock*> __c_j(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1054. bb->setName("C.J");
  1055. this->gen_sync(PRE_SYNC, 17);
  1056. int16_t imm = signextend<int16_t,12>((bit_sub<2,1>(instr) << 5) | (bit_sub<3,3>(instr) << 1) | (bit_sub<6,1>(instr) << 7) | (bit_sub<7,1>(instr) << 6) | (bit_sub<8,1>(instr) << 10) | (bit_sub<9,2>(instr) << 8) | (bit_sub<11,1>(instr) << 4) | (bit_sub<12,1>(instr) << 11));
  1057. if(this->disass_enabled){
  1058. /* generate console output when executing the command */
  1059. auto mnemonic = fmt::format(
  1060. "{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c.j"),
  1061. fmt::arg("imm", imm));
  1062. std::vector<Value*> args {
  1063. this->core_ptr,
  1064. this->gen_const(64, pc.val),
  1065. this->builder.CreateGlobalStringPtr(mnemonic),
  1066. };
  1067. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1068. }
  1069. Value* cur_pc_val = this->gen_const(32, pc.val);
  1070. pc=pc+2;
  1071. Value* PC_val = this->builder.CreateAdd(
  1072. this->gen_ext(
  1073. cur_pc_val,
  1074. 32, true),
  1075. this->gen_const(32U, imm));
  1076. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  1077. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  1078. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  1079. this->gen_sync(POST_SYNC, 17);
  1080. this->gen_trap_check(this->leave_blk);
  1081. return std::make_tuple(BRANCH, nullptr);
  1082. }
  1083. /* instruction 18: C.BEQZ */
  1084. std::tuple<continuation_e, BasicBlock*> __c_beqz(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1085. bb->setName("C.BEQZ");
  1086. this->gen_sync(PRE_SYNC, 18);
  1087. int16_t imm = signextend<int16_t,9>((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 1) | (bit_sub<5,2>(instr) << 6) | (bit_sub<10,2>(instr) << 3) | (bit_sub<12,1>(instr) << 8));
  1088. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  1089. if(this->disass_enabled){
  1090. /* generate console output when executing the command */
  1091. auto mnemonic = fmt::format(
  1092. "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.beqz"),
  1093. fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
  1094. std::vector<Value*> args {
  1095. this->core_ptr,
  1096. this->gen_const(64, pc.val),
  1097. this->builder.CreateGlobalStringPtr(mnemonic),
  1098. };
  1099. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1100. }
  1101. Value* cur_pc_val = this->gen_const(32, pc.val);
  1102. pc=pc+2;
  1103. Value* PC_val = this->gen_choose(
  1104. this->builder.CreateICmp(
  1105. ICmpInst::ICMP_EQ,
  1106. this->gen_reg_load(rs1 + 8 + traits<ARCH>::X0, 0),
  1107. this->gen_const(32U, 0)),
  1108. this->builder.CreateAdd(
  1109. this->gen_ext(
  1110. cur_pc_val,
  1111. 32, true),
  1112. this->gen_const(32U, imm)),
  1113. this->builder.CreateAdd(
  1114. cur_pc_val,
  1115. this->gen_const(32U, 2)),
  1116. 32);
  1117. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  1118. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  1119. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  1120. this->gen_sync(POST_SYNC, 18);
  1121. this->gen_trap_check(this->leave_blk);
  1122. return std::make_tuple(BRANCH, nullptr);
  1123. }
  1124. /* instruction 19: C.BNEZ */
  1125. std::tuple<continuation_e, BasicBlock*> __c_bnez(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1126. bb->setName("C.BNEZ");
  1127. this->gen_sync(PRE_SYNC, 19);
  1128. int16_t imm = signextend<int16_t,9>((bit_sub<2,1>(instr) << 5) | (bit_sub<3,2>(instr) << 1) | (bit_sub<5,2>(instr) << 6) | (bit_sub<10,2>(instr) << 3) | (bit_sub<12,1>(instr) << 8));
  1129. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  1130. if(this->disass_enabled){
  1131. /* generate console output when executing the command */
  1132. auto mnemonic = fmt::format(
  1133. "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.bnez"),
  1134. fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
  1135. std::vector<Value*> args {
  1136. this->core_ptr,
  1137. this->gen_const(64, pc.val),
  1138. this->builder.CreateGlobalStringPtr(mnemonic),
  1139. };
  1140. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1141. }
  1142. Value* cur_pc_val = this->gen_const(32, pc.val);
  1143. pc=pc+2;
  1144. Value* PC_val = this->gen_choose(
  1145. this->builder.CreateICmp(
  1146. ICmpInst::ICMP_NE,
  1147. this->gen_reg_load(rs1 + 8 + traits<ARCH>::X0, 0),
  1148. this->gen_const(32U, 0)),
  1149. this->builder.CreateAdd(
  1150. this->gen_ext(
  1151. cur_pc_val,
  1152. 32, true),
  1153. this->gen_const(32U, imm)),
  1154. this->builder.CreateAdd(
  1155. cur_pc_val,
  1156. this->gen_const(32U, 2)),
  1157. 32);
  1158. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  1159. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  1160. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  1161. this->gen_sync(POST_SYNC, 19);
  1162. this->gen_trap_check(this->leave_blk);
  1163. return std::make_tuple(BRANCH, nullptr);
  1164. }
  1165. /* instruction 20: C.SLLI */
  1166. std::tuple<continuation_e, BasicBlock*> __c_slli(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1167. bb->setName("C.SLLI");
  1168. this->gen_sync(PRE_SYNC, 20);
  1169. uint8_t shamt = ((bit_sub<2,5>(instr)));
  1170. uint8_t rs1 = ((bit_sub<7,5>(instr)));
  1171. if(this->disass_enabled){
  1172. /* generate console output when executing the command */
  1173. auto mnemonic = fmt::format(
  1174. "{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c.slli"),
  1175. fmt::arg("rs1", name(rs1)), fmt::arg("shamt", shamt));
  1176. std::vector<Value*> args {
  1177. this->core_ptr,
  1178. this->gen_const(64, pc.val),
  1179. this->builder.CreateGlobalStringPtr(mnemonic),
  1180. };
  1181. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1182. }
  1183. Value* cur_pc_val = this->gen_const(32, pc.val);
  1184. pc=pc+2;
  1185. if(rs1 == 0){
  1186. this->gen_raise_trap(0, 2);
  1187. }
  1188. Value* Xtmp0_val = this->builder.CreateShl(
  1189. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  1190. this->gen_const(32U, shamt));
  1191. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rs1 + traits<ARCH>::X0), false);
  1192. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1193. this->gen_sync(POST_SYNC, 20);
  1194. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1195. this->gen_trap_check(bb);
  1196. return std::make_tuple(CONT, bb);
  1197. }
  1198. /* instruction 21: C.LWSP */
  1199. std::tuple<continuation_e, BasicBlock*> __c_lwsp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1200. bb->setName("C.LWSP");
  1201. this->gen_sync(PRE_SYNC, 21);
  1202. uint8_t uimm = ((bit_sub<2,2>(instr) << 6) | (bit_sub<4,3>(instr) << 2) | (bit_sub<12,1>(instr) << 5));
  1203. uint8_t rd = ((bit_sub<7,5>(instr)));
  1204. if(this->disass_enabled){
  1205. /* generate console output when executing the command */
  1206. auto mnemonic = fmt::format(
  1207. "{mnemonic:10} {rd}, sp, {uimm:#05x}", fmt::arg("mnemonic", "c.lwsp"),
  1208. fmt::arg("rd", name(rd)), fmt::arg("uimm", uimm));
  1209. std::vector<Value*> args {
  1210. this->core_ptr,
  1211. this->gen_const(64, pc.val),
  1212. this->builder.CreateGlobalStringPtr(mnemonic),
  1213. };
  1214. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1215. }
  1216. Value* cur_pc_val = this->gen_const(32, pc.val);
  1217. pc=pc+2;
  1218. Value* offs_val = this->builder.CreateAdd(
  1219. this->gen_reg_load(2 + traits<ARCH>::X0, 0),
  1220. this->gen_const(32U, uimm));
  1221. Value* Xtmp0_val = this->gen_ext(
  1222. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  1223. 32,
  1224. true);
  1225. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  1226. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1227. this->gen_sync(POST_SYNC, 21);
  1228. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1229. this->gen_trap_check(bb);
  1230. return std::make_tuple(CONT, bb);
  1231. }
  1232. /* instruction 22: C.MV */
  1233. std::tuple<continuation_e, BasicBlock*> __c_mv(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1234. bb->setName("C.MV");
  1235. this->gen_sync(PRE_SYNC, 22);
  1236. uint8_t rs2 = ((bit_sub<2,5>(instr)));
  1237. uint8_t rd = ((bit_sub<7,5>(instr)));
  1238. if(this->disass_enabled){
  1239. /* generate console output when executing the command */
  1240. auto mnemonic = fmt::format(
  1241. "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.mv"),
  1242. fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2)));
  1243. std::vector<Value*> args {
  1244. this->core_ptr,
  1245. this->gen_const(64, pc.val),
  1246. this->builder.CreateGlobalStringPtr(mnemonic),
  1247. };
  1248. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1249. }
  1250. Value* cur_pc_val = this->gen_const(32, pc.val);
  1251. pc=pc+2;
  1252. Value* Xtmp0_val = this->gen_reg_load(rs2 + traits<ARCH>::X0, 0);
  1253. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  1254. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1255. this->gen_sync(POST_SYNC, 22);
  1256. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1257. this->gen_trap_check(bb);
  1258. return std::make_tuple(CONT, bb);
  1259. }
  1260. /* instruction 23: C.JR */
  1261. std::tuple<continuation_e, BasicBlock*> __c_jr(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1262. bb->setName("C.JR");
  1263. this->gen_sync(PRE_SYNC, 23);
  1264. uint8_t rs1 = ((bit_sub<7,5>(instr)));
  1265. if(this->disass_enabled){
  1266. /* generate console output when executing the command */
  1267. auto mnemonic = fmt::format(
  1268. "{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c.jr"),
  1269. fmt::arg("rs1", name(rs1)));
  1270. std::vector<Value*> args {
  1271. this->core_ptr,
  1272. this->gen_const(64, pc.val),
  1273. this->builder.CreateGlobalStringPtr(mnemonic),
  1274. };
  1275. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1276. }
  1277. Value* cur_pc_val = this->gen_const(32, pc.val);
  1278. pc=pc+2;
  1279. Value* PC_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  1280. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  1281. this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  1282. this->gen_sync(POST_SYNC, 23);
  1283. this->gen_trap_check(this->leave_blk);
  1284. return std::make_tuple(BRANCH, nullptr);
  1285. }
  1286. /* instruction 24: C.ADD */
  1287. std::tuple<continuation_e, BasicBlock*> __c_add(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1288. bb->setName("C.ADD");
  1289. this->gen_sync(PRE_SYNC, 24);
  1290. uint8_t rs2 = ((bit_sub<2,5>(instr)));
  1291. uint8_t rd = ((bit_sub<7,5>(instr)));
  1292. if(this->disass_enabled){
  1293. /* generate console output when executing the command */
  1294. auto mnemonic = fmt::format(
  1295. "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.add"),
  1296. fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2)));
  1297. std::vector<Value*> args {
  1298. this->core_ptr,
  1299. this->gen_const(64, pc.val),
  1300. this->builder.CreateGlobalStringPtr(mnemonic),
  1301. };
  1302. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1303. }
  1304. Value* cur_pc_val = this->gen_const(32, pc.val);
  1305. pc=pc+2;
  1306. Value* Xtmp0_val = this->builder.CreateAdd(
  1307. this->gen_reg_load(rd + traits<ARCH>::X0, 0),
  1308. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  1309. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  1310. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1311. this->gen_sync(POST_SYNC, 24);
  1312. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1313. this->gen_trap_check(bb);
  1314. return std::make_tuple(CONT, bb);
  1315. }
  1316. /* instruction 25: C.JALR */
  1317. std::tuple<continuation_e, BasicBlock*> __c_jalr(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1318. bb->setName("C.JALR");
  1319. this->gen_sync(PRE_SYNC, 25);
  1320. uint8_t rs1 = ((bit_sub<7,5>(instr)));
  1321. if(this->disass_enabled){
  1322. /* generate console output when executing the command */
  1323. auto mnemonic = fmt::format(
  1324. "{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c.jalr"),
  1325. fmt::arg("rs1", name(rs1)));
  1326. std::vector<Value*> args {
  1327. this->core_ptr,
  1328. this->gen_const(64, pc.val),
  1329. this->builder.CreateGlobalStringPtr(mnemonic),
  1330. };
  1331. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1332. }
  1333. Value* cur_pc_val = this->gen_const(32, pc.val);
  1334. pc=pc+2;
  1335. Value* Xtmp0_val = this->builder.CreateAdd(
  1336. cur_pc_val,
  1337. this->gen_const(32U, 2));
  1338. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(1 + traits<ARCH>::X0), false);
  1339. Value* PC_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  1340. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  1341. this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  1342. this->gen_sync(POST_SYNC, 25);
  1343. this->gen_trap_check(this->leave_blk);
  1344. return std::make_tuple(BRANCH, nullptr);
  1345. }
  1346. /* instruction 26: C.EBREAK */
  1347. std::tuple<continuation_e, BasicBlock*> __c_ebreak(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1348. bb->setName("C.EBREAK");
  1349. this->gen_sync(PRE_SYNC, 26);
  1350. if(this->disass_enabled){
  1351. /* generate console output when executing the command */
  1352. std::vector<Value*> args {
  1353. this->core_ptr,
  1354. this->gen_const(64, pc.val),
  1355. this->builder.CreateGlobalStringPtr("c.ebreak"),
  1356. };
  1357. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1358. }
  1359. Value* cur_pc_val = this->gen_const(32, pc.val);
  1360. pc=pc+2;
  1361. this->gen_raise_trap(0, 3);
  1362. this->gen_sync(POST_SYNC, 26);
  1363. this->gen_trap_check(this->leave_blk);
  1364. return std::make_tuple(BRANCH, nullptr);
  1365. }
  1366. /* instruction 27: C.SWSP */
  1367. std::tuple<continuation_e, BasicBlock*> __c_swsp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1368. bb->setName("C.SWSP");
  1369. this->gen_sync(PRE_SYNC, 27);
  1370. uint8_t rs2 = ((bit_sub<2,5>(instr)));
  1371. uint8_t uimm = ((bit_sub<7,2>(instr) << 6) | (bit_sub<9,4>(instr) << 2));
  1372. if(this->disass_enabled){
  1373. /* generate console output when executing the command */
  1374. auto mnemonic = fmt::format(
  1375. "{mnemonic:10} {rs2}, {uimm:#05x}(sp)", fmt::arg("mnemonic", "c.swsp"),
  1376. fmt::arg("rs2", name(rs2)), fmt::arg("uimm", uimm));
  1377. std::vector<Value*> args {
  1378. this->core_ptr,
  1379. this->gen_const(64, pc.val),
  1380. this->builder.CreateGlobalStringPtr(mnemonic),
  1381. };
  1382. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1383. }
  1384. Value* cur_pc_val = this->gen_const(32, pc.val);
  1385. pc=pc+2;
  1386. Value* offs_val = this->builder.CreateAdd(
  1387. this->gen_reg_load(2 + traits<ARCH>::X0, 0),
  1388. this->gen_const(32U, uimm));
  1389. Value* MEMtmp0_val = this->gen_reg_load(rs2 + traits<ARCH>::X0, 0);
  1390. this->gen_write_mem(
  1391. traits<ARCH>::MEM,
  1392. offs_val,
  1393. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(32)));
  1394. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1395. this->gen_sync(POST_SYNC, 27);
  1396. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1397. this->gen_trap_check(bb);
  1398. return std::make_tuple(CONT, bb);
  1399. }
  1400. /* instruction 28: DII */
  1401. std::tuple<continuation_e, BasicBlock*> __dii(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1402. bb->setName("DII");
  1403. this->gen_sync(PRE_SYNC, 28);
  1404. if(this->disass_enabled){
  1405. /* generate console output when executing the command */
  1406. std::vector<Value*> args {
  1407. this->core_ptr,
  1408. this->gen_const(64, pc.val),
  1409. this->builder.CreateGlobalStringPtr("dii"),
  1410. };
  1411. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1412. }
  1413. Value* cur_pc_val = this->gen_const(32, pc.val);
  1414. pc=pc+2;
  1415. this->gen_raise_trap(0, 2);
  1416. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1417. this->gen_sync(POST_SYNC, 28);
  1418. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1419. this->gen_trap_check(bb);
  1420. return std::make_tuple(CONT, bb);
  1421. }
  1422. /* instruction 29: C.FLD */
  1423. std::tuple<continuation_e, BasicBlock*> __c_fld(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1424. bb->setName("C.FLD");
  1425. this->gen_sync(PRE_SYNC, 29);
  1426. uint8_t rd = ((bit_sub<2,3>(instr)));
  1427. uint8_t uimm = ((bit_sub<5,2>(instr) << 6) | (bit_sub<10,3>(instr) << 3));
  1428. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  1429. if(this->disass_enabled){
  1430. /* generate console output when executing the command */
  1431. auto mnemonic = fmt::format(
  1432. "{mnemonic:10} f(8+{rd}), {uimm}({rs1})", fmt::arg("mnemonic", "c.fld"),
  1433. fmt::arg("rd", rd), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
  1434. std::vector<Value*> args {
  1435. this->core_ptr,
  1436. this->gen_const(64, pc.val),
  1437. this->builder.CreateGlobalStringPtr(mnemonic),
  1438. };
  1439. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1440. }
  1441. Value* cur_pc_val = this->gen_const(32, pc.val);
  1442. pc=pc+2;
  1443. Value* offs_val = this->builder.CreateAdd(
  1444. this->gen_reg_load(rs1 + 8 + traits<ARCH>::X0, 0),
  1445. this->gen_const(32U, uimm));
  1446. Value* res_val = this->gen_read_mem(traits<ARCH>::MEM, offs_val, 64/8);
  1447. if(64 == 64){
  1448. Value* Ftmp0_val = res_val;
  1449. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + 8 + traits<ARCH>::F0), false);
  1450. } else {
  1451. uint64_t upper_val = - 1;
  1452. Value* Ftmp1_val = this->builder.CreateOr(
  1453. this->builder.CreateShl(
  1454. this->gen_const(64U, upper_val),
  1455. this->gen_const(64U, 64)),
  1456. res_val);
  1457. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + 8 + traits<ARCH>::F0), false);
  1458. }
  1459. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1460. this->gen_sync(POST_SYNC, 29);
  1461. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1462. this->gen_trap_check(bb);
  1463. return std::make_tuple(CONT, bb);
  1464. }
  1465. /* instruction 30: C.FSD */
  1466. std::tuple<continuation_e, BasicBlock*> __c_fsd(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1467. bb->setName("C.FSD");
  1468. this->gen_sync(PRE_SYNC, 30);
  1469. uint8_t rs2 = ((bit_sub<2,3>(instr)));
  1470. uint8_t uimm = ((bit_sub<5,2>(instr) << 6) | (bit_sub<10,3>(instr) << 3));
  1471. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  1472. if(this->disass_enabled){
  1473. /* generate console output when executing the command */
  1474. auto mnemonic = fmt::format(
  1475. "{mnemonic:10} f(8+{rs2}), {uimm}({rs1})", fmt::arg("mnemonic", "c.fsd"),
  1476. fmt::arg("rs2", rs2), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
  1477. std::vector<Value*> args {
  1478. this->core_ptr,
  1479. this->gen_const(64, pc.val),
  1480. this->builder.CreateGlobalStringPtr(mnemonic),
  1481. };
  1482. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1483. }
  1484. Value* cur_pc_val = this->gen_const(32, pc.val);
  1485. pc=pc+2;
  1486. Value* offs_val = this->builder.CreateAdd(
  1487. this->gen_reg_load(rs1 + 8 + traits<ARCH>::X0, 0),
  1488. this->gen_const(32U, uimm));
  1489. Value* MEMtmp0_val = this->builder.CreateTrunc(
  1490. this->gen_reg_load(rs2 + 8 + traits<ARCH>::F0, 0),
  1491. this-> get_type(64)
  1492. );
  1493. this->gen_write_mem(
  1494. traits<ARCH>::MEM,
  1495. offs_val,
  1496. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(64)));
  1497. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1498. this->gen_sync(POST_SYNC, 30);
  1499. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1500. this->gen_trap_check(bb);
  1501. return std::make_tuple(CONT, bb);
  1502. }
  1503. /* instruction 31: C.FLDSP */
  1504. std::tuple<continuation_e, BasicBlock*> __c_fldsp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1505. bb->setName("C.FLDSP");
  1506. this->gen_sync(PRE_SYNC, 31);
  1507. uint16_t uimm = ((bit_sub<2,3>(instr) << 6) | (bit_sub<5,2>(instr) << 3) | (bit_sub<12,1>(instr) << 5));
  1508. uint8_t rd = ((bit_sub<7,5>(instr)));
  1509. if(this->disass_enabled){
  1510. /* generate console output when executing the command */
  1511. auto mnemonic = fmt::format(
  1512. "{mnemonic:10} f{rd}, {uimm}(x2)", fmt::arg("mnemonic", "c.fldsp"),
  1513. fmt::arg("rd", rd), fmt::arg("uimm", uimm));
  1514. std::vector<Value*> args {
  1515. this->core_ptr,
  1516. this->gen_const(64, pc.val),
  1517. this->builder.CreateGlobalStringPtr(mnemonic),
  1518. };
  1519. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1520. }
  1521. Value* cur_pc_val = this->gen_const(32, pc.val);
  1522. pc=pc+2;
  1523. Value* offs_val = this->builder.CreateAdd(
  1524. this->gen_reg_load(2 + traits<ARCH>::X0, 0),
  1525. this->gen_const(32U, uimm));
  1526. Value* res_val = this->gen_read_mem(traits<ARCH>::MEM, offs_val, 64/8);
  1527. if(64 == 64){
  1528. Value* Ftmp0_val = res_val;
  1529. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1530. } else {
  1531. uint64_t upper_val = - 1;
  1532. Value* Ftmp1_val = this->builder.CreateOr(
  1533. this->builder.CreateShl(
  1534. this->gen_const(64U, upper_val),
  1535. this->gen_const(64U, 64)),
  1536. this->gen_ext(
  1537. res_val,
  1538. 64,
  1539. false));
  1540. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1541. }
  1542. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1543. this->gen_sync(POST_SYNC, 31);
  1544. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1545. this->gen_trap_check(bb);
  1546. return std::make_tuple(CONT, bb);
  1547. }
  1548. /* instruction 32: C.FSDSP */
  1549. std::tuple<continuation_e, BasicBlock*> __c_fsdsp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1550. bb->setName("C.FSDSP");
  1551. this->gen_sync(PRE_SYNC, 32);
  1552. uint8_t rs2 = ((bit_sub<2,5>(instr)));
  1553. uint16_t uimm = ((bit_sub<7,3>(instr) << 6) | (bit_sub<10,3>(instr) << 3));
  1554. if(this->disass_enabled){
  1555. /* generate console output when executing the command */
  1556. auto mnemonic = fmt::format(
  1557. "{mnemonic:10} f{rs2}, {uimm}(x2), ", fmt::arg("mnemonic", "c.fsdsp"),
  1558. fmt::arg("rs2", rs2), fmt::arg("uimm", uimm));
  1559. std::vector<Value*> args {
  1560. this->core_ptr,
  1561. this->gen_const(64, pc.val),
  1562. this->builder.CreateGlobalStringPtr(mnemonic),
  1563. };
  1564. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1565. }
  1566. Value* cur_pc_val = this->gen_const(32, pc.val);
  1567. pc=pc+2;
  1568. Value* offs_val = this->builder.CreateAdd(
  1569. this->gen_reg_load(2 + traits<ARCH>::X0, 0),
  1570. this->gen_const(32U, uimm));
  1571. Value* MEMtmp0_val = this->builder.CreateTrunc(
  1572. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  1573. this-> get_type(64)
  1574. );
  1575. this->gen_write_mem(
  1576. traits<ARCH>::MEM,
  1577. offs_val,
  1578. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(64)));
  1579. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1580. this->gen_sync(POST_SYNC, 32);
  1581. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1582. this->gen_trap_check(bb);
  1583. return std::make_tuple(CONT, bb);
  1584. }
  1585. /* instruction 33: C.FLW */
  1586. std::tuple<continuation_e, BasicBlock*> __c_flw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1587. bb->setName("C.FLW");
  1588. this->gen_sync(PRE_SYNC, 33);
  1589. uint8_t rd = ((bit_sub<2,3>(instr)));
  1590. uint8_t uimm = ((bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 2) | (bit_sub<10,3>(instr) << 3));
  1591. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  1592. if(this->disass_enabled){
  1593. /* generate console output when executing the command */
  1594. auto mnemonic = fmt::format(
  1595. "{mnemonic:10} f(8+{rd}), {uimm}({rs1})", fmt::arg("mnemonic", "c.flw"),
  1596. fmt::arg("rd", rd), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
  1597. std::vector<Value*> args {
  1598. this->core_ptr,
  1599. this->gen_const(64, pc.val),
  1600. this->builder.CreateGlobalStringPtr(mnemonic),
  1601. };
  1602. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1603. }
  1604. Value* cur_pc_val = this->gen_const(32, pc.val);
  1605. pc=pc+2;
  1606. Value* offs_val = this->builder.CreateAdd(
  1607. this->gen_reg_load(rs1 + 8 + traits<ARCH>::X0, 0),
  1608. this->gen_const(32U, uimm));
  1609. Value* res_val = this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8);
  1610. if(64 == 32){
  1611. Value* Ftmp0_val = res_val;
  1612. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + 8 + traits<ARCH>::F0), false);
  1613. } else {
  1614. uint64_t upper_val = - 1;
  1615. Value* Ftmp1_val = this->builder.CreateOr(
  1616. this->builder.CreateShl(
  1617. this->gen_const(64U, upper_val),
  1618. this->gen_const(64U, 32)),
  1619. this->gen_ext(
  1620. res_val,
  1621. 64,
  1622. false));
  1623. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + 8 + traits<ARCH>::F0), false);
  1624. }
  1625. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1626. this->gen_sync(POST_SYNC, 33);
  1627. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1628. this->gen_trap_check(bb);
  1629. return std::make_tuple(CONT, bb);
  1630. }
  1631. /* instruction 34: C.FSW */
  1632. std::tuple<continuation_e, BasicBlock*> __c_fsw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1633. bb->setName("C.FSW");
  1634. this->gen_sync(PRE_SYNC, 34);
  1635. uint8_t rs2 = ((bit_sub<2,3>(instr)));
  1636. uint8_t uimm = ((bit_sub<5,1>(instr) << 6) | (bit_sub<6,1>(instr) << 2) | (bit_sub<10,3>(instr) << 3));
  1637. uint8_t rs1 = ((bit_sub<7,3>(instr)));
  1638. if(this->disass_enabled){
  1639. /* generate console output when executing the command */
  1640. auto mnemonic = fmt::format(
  1641. "{mnemonic:10} f(8+{rs2}), {uimm}({rs1})", fmt::arg("mnemonic", "c.fsw"),
  1642. fmt::arg("rs2", rs2), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
  1643. std::vector<Value*> args {
  1644. this->core_ptr,
  1645. this->gen_const(64, pc.val),
  1646. this->builder.CreateGlobalStringPtr(mnemonic),
  1647. };
  1648. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1649. }
  1650. Value* cur_pc_val = this->gen_const(32, pc.val);
  1651. pc=pc+2;
  1652. Value* offs_val = this->builder.CreateAdd(
  1653. this->gen_reg_load(rs1 + 8 + traits<ARCH>::X0, 0),
  1654. this->gen_const(32U, uimm));
  1655. Value* MEMtmp0_val = this->builder.CreateTrunc(
  1656. this->gen_reg_load(rs2 + 8 + traits<ARCH>::F0, 0),
  1657. this-> get_type(32)
  1658. );
  1659. this->gen_write_mem(
  1660. traits<ARCH>::MEM,
  1661. offs_val,
  1662. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(32)));
  1663. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1664. this->gen_sync(POST_SYNC, 34);
  1665. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1666. this->gen_trap_check(bb);
  1667. return std::make_tuple(CONT, bb);
  1668. }
  1669. /* instruction 35: C.FLWSP */
  1670. std::tuple<continuation_e, BasicBlock*> __c_flwsp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1671. bb->setName("C.FLWSP");
  1672. this->gen_sync(PRE_SYNC, 35);
  1673. uint8_t uimm = ((bit_sub<2,2>(instr) << 6) | (bit_sub<4,3>(instr) << 2) | (bit_sub<12,1>(instr) << 5));
  1674. uint8_t rd = ((bit_sub<7,5>(instr)));
  1675. if(this->disass_enabled){
  1676. /* generate console output when executing the command */
  1677. auto mnemonic = fmt::format(
  1678. "{mnemonic:10} f{rd}, {uimm}(x2)", fmt::arg("mnemonic", "c.flwsp"),
  1679. fmt::arg("rd", rd), fmt::arg("uimm", uimm));
  1680. std::vector<Value*> args {
  1681. this->core_ptr,
  1682. this->gen_const(64, pc.val),
  1683. this->builder.CreateGlobalStringPtr(mnemonic),
  1684. };
  1685. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1686. }
  1687. Value* cur_pc_val = this->gen_const(32, pc.val);
  1688. pc=pc+2;
  1689. Value* offs_val = this->builder.CreateAdd(
  1690. this->gen_reg_load(2 + traits<ARCH>::X0, 0),
  1691. this->gen_const(32U, uimm));
  1692. Value* res_val = this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8);
  1693. if(64 == 32){
  1694. Value* Ftmp0_val = res_val;
  1695. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1696. } else {
  1697. uint64_t upper_val = - 1;
  1698. Value* Ftmp1_val = this->builder.CreateOr(
  1699. this->builder.CreateShl(
  1700. this->gen_const(64U, upper_val),
  1701. this->gen_const(64U, 32)),
  1702. this->gen_ext(
  1703. res_val,
  1704. 64,
  1705. false));
  1706. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1707. }
  1708. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1709. this->gen_sync(POST_SYNC, 35);
  1710. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1711. this->gen_trap_check(bb);
  1712. return std::make_tuple(CONT, bb);
  1713. }
  1714. /* instruction 36: C.FSWSP */
  1715. std::tuple<continuation_e, BasicBlock*> __c_fswsp(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1716. bb->setName("C.FSWSP");
  1717. this->gen_sync(PRE_SYNC, 36);
  1718. uint8_t rs2 = ((bit_sub<2,5>(instr)));
  1719. uint8_t uimm = ((bit_sub<7,2>(instr) << 6) | (bit_sub<9,4>(instr) << 2));
  1720. if(this->disass_enabled){
  1721. /* generate console output when executing the command */
  1722. auto mnemonic = fmt::format(
  1723. "{mnemonic:10} f{rs2}, {uimm}(x2), ", fmt::arg("mnemonic", "c.fswsp"),
  1724. fmt::arg("rs2", rs2), fmt::arg("uimm", uimm));
  1725. std::vector<Value*> args {
  1726. this->core_ptr,
  1727. this->gen_const(64, pc.val),
  1728. this->builder.CreateGlobalStringPtr(mnemonic),
  1729. };
  1730. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1731. }
  1732. Value* cur_pc_val = this->gen_const(32, pc.val);
  1733. pc=pc+2;
  1734. Value* offs_val = this->builder.CreateAdd(
  1735. this->gen_reg_load(2 + traits<ARCH>::X0, 0),
  1736. this->gen_const(32U, uimm));
  1737. Value* MEMtmp0_val = this->builder.CreateTrunc(
  1738. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  1739. this-> get_type(32)
  1740. );
  1741. this->gen_write_mem(
  1742. traits<ARCH>::MEM,
  1743. offs_val,
  1744. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(32)));
  1745. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1746. this->gen_sync(POST_SYNC, 36);
  1747. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1748. this->gen_trap_check(bb);
  1749. return std::make_tuple(CONT, bb);
  1750. }
  1751. /* instruction 37: FLD */
  1752. std::tuple<continuation_e, BasicBlock*> __fld(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1753. bb->setName("FLD");
  1754. this->gen_sync(PRE_SYNC, 37);
  1755. uint8_t rd = ((bit_sub<7,5>(instr)));
  1756. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  1757. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  1758. if(this->disass_enabled){
  1759. /* generate console output when executing the command */
  1760. auto mnemonic = fmt::format(
  1761. "{mnemonic:10} f{rd}, {imm}({rs1})", fmt::arg("mnemonic", "fld"),
  1762. fmt::arg("rd", rd), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  1763. std::vector<Value*> args {
  1764. this->core_ptr,
  1765. this->gen_const(64, pc.val),
  1766. this->builder.CreateGlobalStringPtr(mnemonic),
  1767. };
  1768. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1769. }
  1770. Value* cur_pc_val = this->gen_const(32, pc.val);
  1771. pc=pc+4;
  1772. Value* offs_val = this->builder.CreateAdd(
  1773. this->gen_ext(
  1774. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  1775. 32, true),
  1776. this->gen_const(32U, imm));
  1777. Value* res_val = this->gen_read_mem(traits<ARCH>::MEM, offs_val, 64/8);
  1778. if(64 == 64){
  1779. Value* Ftmp0_val = res_val;
  1780. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1781. } else {
  1782. uint64_t upper_val = - 1;
  1783. Value* Ftmp1_val = this->builder.CreateOr(
  1784. this->builder.CreateShl(
  1785. this->gen_const(64U, upper_val),
  1786. this->gen_const(64U, 64)),
  1787. res_val);
  1788. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1789. }
  1790. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1791. this->gen_sync(POST_SYNC, 37);
  1792. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1793. this->gen_trap_check(bb);
  1794. return std::make_tuple(CONT, bb);
  1795. }
  1796. /* instruction 38: FSD */
  1797. std::tuple<continuation_e, BasicBlock*> __fsd(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1798. bb->setName("FSD");
  1799. this->gen_sync(PRE_SYNC, 38);
  1800. int16_t imm = signextend<int16_t,12>((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5));
  1801. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  1802. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  1803. if(this->disass_enabled){
  1804. /* generate console output when executing the command */
  1805. auto mnemonic = fmt::format(
  1806. "{mnemonic:10} f{rs2}, {imm}({rs1})", fmt::arg("mnemonic", "fsd"),
  1807. fmt::arg("rs2", rs2), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  1808. std::vector<Value*> args {
  1809. this->core_ptr,
  1810. this->gen_const(64, pc.val),
  1811. this->builder.CreateGlobalStringPtr(mnemonic),
  1812. };
  1813. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1814. }
  1815. Value* cur_pc_val = this->gen_const(32, pc.val);
  1816. pc=pc+4;
  1817. Value* offs_val = this->builder.CreateAdd(
  1818. this->gen_ext(
  1819. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  1820. 32, true),
  1821. this->gen_const(32U, imm));
  1822. Value* MEMtmp0_val = this->builder.CreateTrunc(
  1823. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  1824. this-> get_type(64)
  1825. );
  1826. this->gen_write_mem(
  1827. traits<ARCH>::MEM,
  1828. offs_val,
  1829. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(64)));
  1830. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1831. this->gen_sync(POST_SYNC, 38);
  1832. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1833. this->gen_trap_check(bb);
  1834. return std::make_tuple(CONT, bb);
  1835. }
  1836. /* instruction 39: FMADD.D */
  1837. std::tuple<continuation_e, BasicBlock*> __fmadd_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1838. bb->setName("FMADD.D");
  1839. this->gen_sync(PRE_SYNC, 39);
  1840. uint8_t rd = ((bit_sub<7,5>(instr)));
  1841. uint8_t rm = ((bit_sub<12,3>(instr)));
  1842. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  1843. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  1844. uint8_t rs3 = ((bit_sub<27,5>(instr)));
  1845. if(this->disass_enabled){
  1846. /* generate console output when executing the command */
  1847. auto mnemonic = fmt::format(
  1848. "{mnemonic:10} {rd}, f{rs1}, f{rs2}, f{rs3}", fmt::arg("mnemonic", "fmadd.d"),
  1849. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2), fmt::arg("rs3", rs3));
  1850. std::vector<Value*> args {
  1851. this->core_ptr,
  1852. this->gen_const(64, pc.val),
  1853. this->builder.CreateGlobalStringPtr(mnemonic),
  1854. };
  1855. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1856. }
  1857. Value* cur_pc_val = this->gen_const(32, pc.val);
  1858. pc=pc+4;
  1859. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmadd_d"), std::vector<Value*>{
  1860. this->builder.CreateTrunc(
  1861. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  1862. this-> get_type(64)
  1863. ),
  1864. this->builder.CreateTrunc(
  1865. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  1866. this-> get_type(64)
  1867. ),
  1868. this->builder.CreateTrunc(
  1869. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0),
  1870. this-> get_type(64)
  1871. ),
  1872. this->gen_ext(
  1873. this->gen_const(64U, 0LL),
  1874. 64,
  1875. false),
  1876. this->gen_choose(
  1877. this->builder.CreateICmp(
  1878. ICmpInst::ICMP_ULT,
  1879. this->gen_const(8U, rm),
  1880. this->gen_const(8U, 7)),
  1881. this->gen_const(8U, rm),
  1882. this->builder.CreateTrunc(
  1883. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  1884. this-> get_type(8)
  1885. ),
  1886. 8)
  1887. });
  1888. if(64 == 64){
  1889. Value* Ftmp0_val = res_val;
  1890. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1891. } else {
  1892. uint64_t upper_val = - 1;
  1893. Value* Ftmp1_val = this->builder.CreateOr(
  1894. this->builder.CreateShl(
  1895. this->gen_const(64U, upper_val),
  1896. this->gen_const(64U, 64)),
  1897. res_val);
  1898. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1899. }
  1900. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  1901. });
  1902. Value* FCSR_val = this->builder.CreateAdd(
  1903. this->builder.CreateAnd(
  1904. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  1905. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  1906. flags_val);
  1907. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  1908. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1909. this->gen_sync(POST_SYNC, 39);
  1910. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1911. this->gen_trap_check(bb);
  1912. return std::make_tuple(CONT, bb);
  1913. }
  1914. /* instruction 40: FMSUB.D */
  1915. std::tuple<continuation_e, BasicBlock*> __fmsub_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1916. bb->setName("FMSUB.D");
  1917. this->gen_sync(PRE_SYNC, 40);
  1918. uint8_t rd = ((bit_sub<7,5>(instr)));
  1919. uint8_t rm = ((bit_sub<12,3>(instr)));
  1920. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  1921. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  1922. uint8_t rs3 = ((bit_sub<27,5>(instr)));
  1923. if(this->disass_enabled){
  1924. /* generate console output when executing the command */
  1925. auto mnemonic = fmt::format(
  1926. "{mnemonic:10} {rd}, f{rs1}, f{rs2}, f{rs3}", fmt::arg("mnemonic", "fmsub.d"),
  1927. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2), fmt::arg("rs3", rs3));
  1928. std::vector<Value*> args {
  1929. this->core_ptr,
  1930. this->gen_const(64, pc.val),
  1931. this->builder.CreateGlobalStringPtr(mnemonic),
  1932. };
  1933. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  1934. }
  1935. Value* cur_pc_val = this->gen_const(32, pc.val);
  1936. pc=pc+4;
  1937. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmadd_d"), std::vector<Value*>{
  1938. this->builder.CreateTrunc(
  1939. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  1940. this-> get_type(64)
  1941. ),
  1942. this->builder.CreateTrunc(
  1943. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  1944. this-> get_type(64)
  1945. ),
  1946. this->builder.CreateTrunc(
  1947. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0),
  1948. this-> get_type(64)
  1949. ),
  1950. this->gen_ext(
  1951. this->gen_const(64U, 1LL),
  1952. 32,
  1953. false),
  1954. this->gen_choose(
  1955. this->builder.CreateICmp(
  1956. ICmpInst::ICMP_ULT,
  1957. this->gen_const(8U, rm),
  1958. this->gen_const(8U, 7)),
  1959. this->gen_const(8U, rm),
  1960. this->builder.CreateTrunc(
  1961. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  1962. this-> get_type(8)
  1963. ),
  1964. 8)
  1965. });
  1966. if(64 == 64){
  1967. Value* Ftmp0_val = res_val;
  1968. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1969. } else {
  1970. uint64_t upper_val = - 1;
  1971. Value* Ftmp1_val = this->builder.CreateOr(
  1972. this->builder.CreateShl(
  1973. this->gen_const(64U, upper_val),
  1974. this->gen_const(64U, 64)),
  1975. res_val);
  1976. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  1977. }
  1978. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  1979. });
  1980. Value* FCSR_val = this->builder.CreateAdd(
  1981. this->builder.CreateAnd(
  1982. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  1983. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  1984. flags_val);
  1985. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  1986. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  1987. this->gen_sync(POST_SYNC, 40);
  1988. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  1989. this->gen_trap_check(bb);
  1990. return std::make_tuple(CONT, bb);
  1991. }
  1992. /* instruction 41: FNMADD.D */
  1993. std::tuple<continuation_e, BasicBlock*> __fnmadd_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  1994. bb->setName("FNMADD.D");
  1995. this->gen_sync(PRE_SYNC, 41);
  1996. uint8_t rd = ((bit_sub<7,5>(instr)));
  1997. uint8_t rm = ((bit_sub<12,3>(instr)));
  1998. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  1999. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2000. uint8_t rs3 = ((bit_sub<27,5>(instr)));
  2001. if(this->disass_enabled){
  2002. /* generate console output when executing the command */
  2003. auto mnemonic = fmt::format(
  2004. "{mnemonic:10} {rd}, f{rs1}, f{rs2}, f{rs3}", fmt::arg("mnemonic", "fnmadd.d"),
  2005. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2), fmt::arg("rs3", rs3));
  2006. std::vector<Value*> args {
  2007. this->core_ptr,
  2008. this->gen_const(64, pc.val),
  2009. this->builder.CreateGlobalStringPtr(mnemonic),
  2010. };
  2011. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2012. }
  2013. Value* cur_pc_val = this->gen_const(32, pc.val);
  2014. pc=pc+4;
  2015. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmadd_d"), std::vector<Value*>{
  2016. this->builder.CreateTrunc(
  2017. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2018. this-> get_type(64)
  2019. ),
  2020. this->builder.CreateTrunc(
  2021. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2022. this-> get_type(64)
  2023. ),
  2024. this->builder.CreateTrunc(
  2025. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0),
  2026. this-> get_type(64)
  2027. ),
  2028. this->gen_ext(
  2029. this->gen_const(64U, 2LL),
  2030. 32,
  2031. false),
  2032. this->gen_choose(
  2033. this->builder.CreateICmp(
  2034. ICmpInst::ICMP_ULT,
  2035. this->gen_const(8U, rm),
  2036. this->gen_const(8U, 7)),
  2037. this->gen_const(8U, rm),
  2038. this->builder.CreateTrunc(
  2039. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2040. this-> get_type(8)
  2041. ),
  2042. 8)
  2043. });
  2044. if(64 == 64){
  2045. Value* Ftmp0_val = res_val;
  2046. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2047. } else {
  2048. uint64_t upper_val = - 1;
  2049. Value* Ftmp1_val = this->builder.CreateOr(
  2050. this->builder.CreateShl(
  2051. this->gen_const(64U, upper_val),
  2052. this->gen_const(64U, 64)),
  2053. res_val);
  2054. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2055. }
  2056. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2057. });
  2058. Value* FCSR_val = this->builder.CreateAdd(
  2059. this->builder.CreateAnd(
  2060. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2061. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2062. flags_val);
  2063. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2064. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2065. this->gen_sync(POST_SYNC, 41);
  2066. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2067. this->gen_trap_check(bb);
  2068. return std::make_tuple(CONT, bb);
  2069. }
  2070. /* instruction 42: FNMSUB.D */
  2071. std::tuple<continuation_e, BasicBlock*> __fnmsub_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2072. bb->setName("FNMSUB.D");
  2073. this->gen_sync(PRE_SYNC, 42);
  2074. uint8_t rd = ((bit_sub<7,5>(instr)));
  2075. uint8_t rm = ((bit_sub<12,3>(instr)));
  2076. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2077. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2078. uint8_t rs3 = ((bit_sub<27,5>(instr)));
  2079. if(this->disass_enabled){
  2080. /* generate console output when executing the command */
  2081. auto mnemonic = fmt::format(
  2082. "{mnemonic:10} {rd}, f{rs1}, f{rs2}, f{rs3}", fmt::arg("mnemonic", "fnmsub.d"),
  2083. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2), fmt::arg("rs3", rs3));
  2084. std::vector<Value*> args {
  2085. this->core_ptr,
  2086. this->gen_const(64, pc.val),
  2087. this->builder.CreateGlobalStringPtr(mnemonic),
  2088. };
  2089. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2090. }
  2091. Value* cur_pc_val = this->gen_const(32, pc.val);
  2092. pc=pc+4;
  2093. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmadd_d"), std::vector<Value*>{
  2094. this->builder.CreateTrunc(
  2095. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2096. this-> get_type(64)
  2097. ),
  2098. this->builder.CreateTrunc(
  2099. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2100. this-> get_type(64)
  2101. ),
  2102. this->builder.CreateTrunc(
  2103. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0),
  2104. this-> get_type(64)
  2105. ),
  2106. this->gen_ext(
  2107. this->gen_const(64U, 3LL),
  2108. 32,
  2109. false),
  2110. this->gen_choose(
  2111. this->builder.CreateICmp(
  2112. ICmpInst::ICMP_ULT,
  2113. this->gen_const(8U, rm),
  2114. this->gen_const(8U, 7)),
  2115. this->gen_const(8U, rm),
  2116. this->builder.CreateTrunc(
  2117. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2118. this-> get_type(8)
  2119. ),
  2120. 8)
  2121. });
  2122. if(64 == 64){
  2123. Value* Ftmp0_val = res_val;
  2124. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2125. } else {
  2126. uint64_t upper_val = - 1;
  2127. Value* Ftmp1_val = this->builder.CreateOr(
  2128. this->builder.CreateShl(
  2129. this->gen_const(64U, upper_val),
  2130. this->gen_const(64U, 64)),
  2131. res_val);
  2132. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2133. }
  2134. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2135. });
  2136. Value* FCSR_val = this->builder.CreateAdd(
  2137. this->builder.CreateAnd(
  2138. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2139. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2140. flags_val);
  2141. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2142. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2143. this->gen_sync(POST_SYNC, 42);
  2144. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2145. this->gen_trap_check(bb);
  2146. return std::make_tuple(CONT, bb);
  2147. }
  2148. /* instruction 43: FADD.D */
  2149. std::tuple<continuation_e, BasicBlock*> __fadd_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2150. bb->setName("FADD.D");
  2151. this->gen_sync(PRE_SYNC, 43);
  2152. uint8_t rd = ((bit_sub<7,5>(instr)));
  2153. uint8_t rm = ((bit_sub<12,3>(instr)));
  2154. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2155. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2156. if(this->disass_enabled){
  2157. /* generate console output when executing the command */
  2158. auto mnemonic = fmt::format(
  2159. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fadd.d"),
  2160. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2161. std::vector<Value*> args {
  2162. this->core_ptr,
  2163. this->gen_const(64, pc.val),
  2164. this->builder.CreateGlobalStringPtr(mnemonic),
  2165. };
  2166. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2167. }
  2168. Value* cur_pc_val = this->gen_const(32, pc.val);
  2169. pc=pc+4;
  2170. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fadd_d"), std::vector<Value*>{
  2171. this->builder.CreateTrunc(
  2172. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2173. this-> get_type(64)
  2174. ),
  2175. this->builder.CreateTrunc(
  2176. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2177. this-> get_type(64)
  2178. ),
  2179. this->gen_choose(
  2180. this->builder.CreateICmp(
  2181. ICmpInst::ICMP_ULT,
  2182. this->gen_const(8U, rm),
  2183. this->gen_const(8U, 7)),
  2184. this->gen_const(8U, rm),
  2185. this->builder.CreateTrunc(
  2186. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2187. this-> get_type(8)
  2188. ),
  2189. 8)
  2190. });
  2191. if(64 == 64){
  2192. Value* Ftmp0_val = res_val;
  2193. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2194. } else {
  2195. uint64_t upper_val = - 1;
  2196. Value* Ftmp1_val = this->builder.CreateOr(
  2197. this->builder.CreateShl(
  2198. this->gen_const(64U, upper_val),
  2199. this->gen_const(64U, 64)),
  2200. res_val);
  2201. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2202. }
  2203. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2204. });
  2205. Value* FCSR_val = this->builder.CreateAdd(
  2206. this->builder.CreateAnd(
  2207. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2208. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2209. flags_val);
  2210. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2211. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2212. this->gen_sync(POST_SYNC, 43);
  2213. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2214. this->gen_trap_check(bb);
  2215. return std::make_tuple(CONT, bb);
  2216. }
  2217. /* instruction 44: FSUB.D */
  2218. std::tuple<continuation_e, BasicBlock*> __fsub_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2219. bb->setName("FSUB.D");
  2220. this->gen_sync(PRE_SYNC, 44);
  2221. uint8_t rd = ((bit_sub<7,5>(instr)));
  2222. uint8_t rm = ((bit_sub<12,3>(instr)));
  2223. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2224. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2225. if(this->disass_enabled){
  2226. /* generate console output when executing the command */
  2227. auto mnemonic = fmt::format(
  2228. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fsub.d"),
  2229. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2230. std::vector<Value*> args {
  2231. this->core_ptr,
  2232. this->gen_const(64, pc.val),
  2233. this->builder.CreateGlobalStringPtr(mnemonic),
  2234. };
  2235. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2236. }
  2237. Value* cur_pc_val = this->gen_const(32, pc.val);
  2238. pc=pc+4;
  2239. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fsub_d"), std::vector<Value*>{
  2240. this->builder.CreateTrunc(
  2241. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2242. this-> get_type(64)
  2243. ),
  2244. this->builder.CreateTrunc(
  2245. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2246. this-> get_type(64)
  2247. ),
  2248. this->gen_choose(
  2249. this->builder.CreateICmp(
  2250. ICmpInst::ICMP_ULT,
  2251. this->gen_const(8U, rm),
  2252. this->gen_const(8U, 7)),
  2253. this->gen_const(8U, rm),
  2254. this->builder.CreateTrunc(
  2255. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2256. this-> get_type(8)
  2257. ),
  2258. 8)
  2259. });
  2260. if(64 == 64){
  2261. Value* Ftmp0_val = res_val;
  2262. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2263. } else {
  2264. uint64_t upper_val = - 1;
  2265. Value* Ftmp1_val = this->builder.CreateOr(
  2266. this->builder.CreateShl(
  2267. this->gen_const(64U, upper_val),
  2268. this->gen_const(64U, 64)),
  2269. res_val);
  2270. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2271. }
  2272. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2273. });
  2274. Value* FCSR_val = this->builder.CreateAdd(
  2275. this->builder.CreateAnd(
  2276. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2277. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2278. flags_val);
  2279. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2280. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2281. this->gen_sync(POST_SYNC, 44);
  2282. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2283. this->gen_trap_check(bb);
  2284. return std::make_tuple(CONT, bb);
  2285. }
  2286. /* instruction 45: FMUL.D */
  2287. std::tuple<continuation_e, BasicBlock*> __fmul_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2288. bb->setName("FMUL.D");
  2289. this->gen_sync(PRE_SYNC, 45);
  2290. uint8_t rd = ((bit_sub<7,5>(instr)));
  2291. uint8_t rm = ((bit_sub<12,3>(instr)));
  2292. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2293. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2294. if(this->disass_enabled){
  2295. /* generate console output when executing the command */
  2296. auto mnemonic = fmt::format(
  2297. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fmul.d"),
  2298. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2299. std::vector<Value*> args {
  2300. this->core_ptr,
  2301. this->gen_const(64, pc.val),
  2302. this->builder.CreateGlobalStringPtr(mnemonic),
  2303. };
  2304. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2305. }
  2306. Value* cur_pc_val = this->gen_const(32, pc.val);
  2307. pc=pc+4;
  2308. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmul_d"), std::vector<Value*>{
  2309. this->builder.CreateTrunc(
  2310. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2311. this-> get_type(64)
  2312. ),
  2313. this->builder.CreateTrunc(
  2314. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2315. this-> get_type(64)
  2316. ),
  2317. this->gen_choose(
  2318. this->builder.CreateICmp(
  2319. ICmpInst::ICMP_ULT,
  2320. this->gen_const(8U, rm),
  2321. this->gen_const(8U, 7)),
  2322. this->gen_const(8U, rm),
  2323. this->builder.CreateTrunc(
  2324. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2325. this-> get_type(8)
  2326. ),
  2327. 8)
  2328. });
  2329. if(64 == 64){
  2330. Value* Ftmp0_val = res_val;
  2331. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2332. } else {
  2333. uint64_t upper_val = - 1;
  2334. Value* Ftmp1_val = this->builder.CreateOr(
  2335. this->builder.CreateShl(
  2336. this->gen_const(64U, upper_val),
  2337. this->gen_const(64U, 64)),
  2338. res_val);
  2339. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2340. }
  2341. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2342. });
  2343. Value* FCSR_val = this->builder.CreateAdd(
  2344. this->builder.CreateAnd(
  2345. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2346. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2347. flags_val);
  2348. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2349. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2350. this->gen_sync(POST_SYNC, 45);
  2351. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2352. this->gen_trap_check(bb);
  2353. return std::make_tuple(CONT, bb);
  2354. }
  2355. /* instruction 46: FDIV.D */
  2356. std::tuple<continuation_e, BasicBlock*> __fdiv_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2357. bb->setName("FDIV.D");
  2358. this->gen_sync(PRE_SYNC, 46);
  2359. uint8_t rd = ((bit_sub<7,5>(instr)));
  2360. uint8_t rm = ((bit_sub<12,3>(instr)));
  2361. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2362. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2363. if(this->disass_enabled){
  2364. /* generate console output when executing the command */
  2365. auto mnemonic = fmt::format(
  2366. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fdiv.d"),
  2367. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2368. std::vector<Value*> args {
  2369. this->core_ptr,
  2370. this->gen_const(64, pc.val),
  2371. this->builder.CreateGlobalStringPtr(mnemonic),
  2372. };
  2373. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2374. }
  2375. Value* cur_pc_val = this->gen_const(32, pc.val);
  2376. pc=pc+4;
  2377. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fdiv_d"), std::vector<Value*>{
  2378. this->builder.CreateTrunc(
  2379. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2380. this-> get_type(64)
  2381. ),
  2382. this->builder.CreateTrunc(
  2383. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2384. this-> get_type(64)
  2385. ),
  2386. this->gen_choose(
  2387. this->builder.CreateICmp(
  2388. ICmpInst::ICMP_ULT,
  2389. this->gen_const(8U, rm),
  2390. this->gen_const(8U, 7)),
  2391. this->gen_const(8U, rm),
  2392. this->builder.CreateTrunc(
  2393. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2394. this-> get_type(8)
  2395. ),
  2396. 8)
  2397. });
  2398. if(64 == 64){
  2399. Value* Ftmp0_val = res_val;
  2400. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2401. } else {
  2402. uint64_t upper_val = - 1;
  2403. Value* Ftmp1_val = this->builder.CreateOr(
  2404. this->builder.CreateShl(
  2405. this->gen_const(64U, upper_val),
  2406. this->gen_const(64U, 64)),
  2407. res_val);
  2408. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2409. }
  2410. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2411. });
  2412. Value* FCSR_val = this->builder.CreateAdd(
  2413. this->builder.CreateAnd(
  2414. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2415. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2416. flags_val);
  2417. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2418. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2419. this->gen_sync(POST_SYNC, 46);
  2420. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2421. this->gen_trap_check(bb);
  2422. return std::make_tuple(CONT, bb);
  2423. }
  2424. /* instruction 47: FSQRT.D */
  2425. std::tuple<continuation_e, BasicBlock*> __fsqrt_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2426. bb->setName("FSQRT.D");
  2427. this->gen_sync(PRE_SYNC, 47);
  2428. uint8_t rd = ((bit_sub<7,5>(instr)));
  2429. uint8_t rm = ((bit_sub<12,3>(instr)));
  2430. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2431. if(this->disass_enabled){
  2432. /* generate console output when executing the command */
  2433. auto mnemonic = fmt::format(
  2434. "{mnemonic:10} {rd}, f{rs1}", fmt::arg("mnemonic", "fsqrt.d"),
  2435. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1));
  2436. std::vector<Value*> args {
  2437. this->core_ptr,
  2438. this->gen_const(64, pc.val),
  2439. this->builder.CreateGlobalStringPtr(mnemonic),
  2440. };
  2441. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2442. }
  2443. Value* cur_pc_val = this->gen_const(32, pc.val);
  2444. pc=pc+4;
  2445. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fsqrt_d"), std::vector<Value*>{
  2446. this->builder.CreateTrunc(
  2447. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2448. this-> get_type(64)
  2449. ),
  2450. this->gen_choose(
  2451. this->builder.CreateICmp(
  2452. ICmpInst::ICMP_ULT,
  2453. this->gen_const(8U, rm),
  2454. this->gen_const(8U, 7)),
  2455. this->gen_const(8U, rm),
  2456. this->builder.CreateTrunc(
  2457. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2458. this-> get_type(8)
  2459. ),
  2460. 8)
  2461. });
  2462. if(64 == 64){
  2463. Value* Ftmp0_val = res_val;
  2464. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2465. } else {
  2466. uint64_t upper_val = - 1;
  2467. Value* Ftmp1_val = this->builder.CreateOr(
  2468. this->builder.CreateShl(
  2469. this->gen_const(64U, upper_val),
  2470. this->gen_const(64U, 64)),
  2471. res_val);
  2472. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2473. }
  2474. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2475. });
  2476. Value* FCSR_val = this->builder.CreateAdd(
  2477. this->builder.CreateAnd(
  2478. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2479. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2480. flags_val);
  2481. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2482. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2483. this->gen_sync(POST_SYNC, 47);
  2484. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2485. this->gen_trap_check(bb);
  2486. return std::make_tuple(CONT, bb);
  2487. }
  2488. /* instruction 48: FSGNJ.D */
  2489. std::tuple<continuation_e, BasicBlock*> __fsgnj_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2490. bb->setName("FSGNJ.D");
  2491. this->gen_sync(PRE_SYNC, 48);
  2492. uint8_t rd = ((bit_sub<7,5>(instr)));
  2493. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2494. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2495. if(this->disass_enabled){
  2496. /* generate console output when executing the command */
  2497. auto mnemonic = fmt::format(
  2498. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fsgnj.d"),
  2499. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2500. std::vector<Value*> args {
  2501. this->core_ptr,
  2502. this->gen_const(64, pc.val),
  2503. this->builder.CreateGlobalStringPtr(mnemonic),
  2504. };
  2505. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2506. }
  2507. Value* cur_pc_val = this->gen_const(32, pc.val);
  2508. pc=pc+4;
  2509. uint64_t ONE_val = 1;
  2510. uint64_t MSK1_val = ONE_val << 63;
  2511. uint64_t MSK2_val = MSK1_val - 1;
  2512. Value* res_val = this->builder.CreateOr(
  2513. this->builder.CreateAnd(
  2514. this->builder.CreateTrunc(
  2515. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2516. this-> get_type(64)
  2517. ),
  2518. this->gen_const(64U, MSK2_val)),
  2519. this->builder.CreateAnd(
  2520. this->builder.CreateTrunc(
  2521. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2522. this-> get_type(64)
  2523. ),
  2524. this->gen_const(64U, MSK1_val)));
  2525. if(64 == 64){
  2526. Value* Ftmp0_val = res_val;
  2527. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2528. } else {
  2529. uint64_t upper_val = - 1;
  2530. Value* Ftmp1_val = this->builder.CreateOr(
  2531. this->builder.CreateShl(
  2532. this->gen_const(64U, upper_val),
  2533. this->gen_const(64U, 64)),
  2534. res_val);
  2535. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2536. }
  2537. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2538. this->gen_sync(POST_SYNC, 48);
  2539. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2540. this->gen_trap_check(bb);
  2541. return std::make_tuple(CONT, bb);
  2542. }
  2543. /* instruction 49: FSGNJN.D */
  2544. std::tuple<continuation_e, BasicBlock*> __fsgnjn_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2545. bb->setName("FSGNJN.D");
  2546. this->gen_sync(PRE_SYNC, 49);
  2547. uint8_t rd = ((bit_sub<7,5>(instr)));
  2548. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2549. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2550. if(this->disass_enabled){
  2551. /* generate console output when executing the command */
  2552. auto mnemonic = fmt::format(
  2553. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fsgnjn.d"),
  2554. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2555. std::vector<Value*> args {
  2556. this->core_ptr,
  2557. this->gen_const(64, pc.val),
  2558. this->builder.CreateGlobalStringPtr(mnemonic),
  2559. };
  2560. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2561. }
  2562. Value* cur_pc_val = this->gen_const(32, pc.val);
  2563. pc=pc+4;
  2564. uint64_t ONE_val = 1;
  2565. uint64_t MSK1_val = ONE_val << 63;
  2566. uint64_t MSK2_val = MSK1_val - 1;
  2567. Value* res_val = this->builder.CreateOr(
  2568. this->builder.CreateAnd(
  2569. this->builder.CreateTrunc(
  2570. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2571. this-> get_type(64)
  2572. ),
  2573. this->gen_const(64U, MSK2_val)),
  2574. this->builder.CreateAnd(
  2575. this->builder.CreateNot(this->builder.CreateTrunc(
  2576. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2577. this-> get_type(64)
  2578. )),
  2579. this->gen_const(64U, MSK1_val)));
  2580. if(64 == 64){
  2581. Value* Ftmp0_val = res_val;
  2582. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2583. } else {
  2584. uint64_t upper_val = - 1;
  2585. Value* Ftmp1_val = this->builder.CreateOr(
  2586. this->builder.CreateShl(
  2587. this->gen_const(64U, upper_val),
  2588. this->gen_const(64U, 64)),
  2589. res_val);
  2590. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2591. }
  2592. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2593. this->gen_sync(POST_SYNC, 49);
  2594. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2595. this->gen_trap_check(bb);
  2596. return std::make_tuple(CONT, bb);
  2597. }
  2598. /* instruction 50: FSGNJX.D */
  2599. std::tuple<continuation_e, BasicBlock*> __fsgnjx_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2600. bb->setName("FSGNJX.D");
  2601. this->gen_sync(PRE_SYNC, 50);
  2602. uint8_t rd = ((bit_sub<7,5>(instr)));
  2603. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2604. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2605. if(this->disass_enabled){
  2606. /* generate console output when executing the command */
  2607. auto mnemonic = fmt::format(
  2608. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fsgnjx.d"),
  2609. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2610. std::vector<Value*> args {
  2611. this->core_ptr,
  2612. this->gen_const(64, pc.val),
  2613. this->builder.CreateGlobalStringPtr(mnemonic),
  2614. };
  2615. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2616. }
  2617. Value* cur_pc_val = this->gen_const(32, pc.val);
  2618. pc=pc+4;
  2619. uint64_t ONE_val = 1;
  2620. uint64_t MSK1_val = ONE_val << 63;
  2621. Value* res_val = this->builder.CreateXor(
  2622. this->builder.CreateTrunc(
  2623. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2624. this-> get_type(64)
  2625. ),
  2626. this->builder.CreateAnd(
  2627. this->builder.CreateTrunc(
  2628. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2629. this-> get_type(64)
  2630. ),
  2631. this->gen_const(64U, MSK1_val)));
  2632. if(64 == 64){
  2633. Value* Ftmp0_val = res_val;
  2634. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2635. } else {
  2636. uint64_t upper_val = - 1;
  2637. Value* Ftmp1_val = this->builder.CreateOr(
  2638. this->builder.CreateShl(
  2639. this->gen_const(64U, upper_val),
  2640. this->gen_const(64U, 64)),
  2641. res_val);
  2642. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2643. }
  2644. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2645. this->gen_sync(POST_SYNC, 50);
  2646. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2647. this->gen_trap_check(bb);
  2648. return std::make_tuple(CONT, bb);
  2649. }
  2650. /* instruction 51: FMIN.D */
  2651. std::tuple<continuation_e, BasicBlock*> __fmin_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2652. bb->setName("FMIN.D");
  2653. this->gen_sync(PRE_SYNC, 51);
  2654. uint8_t rd = ((bit_sub<7,5>(instr)));
  2655. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2656. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2657. if(this->disass_enabled){
  2658. /* generate console output when executing the command */
  2659. auto mnemonic = fmt::format(
  2660. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fmin.d"),
  2661. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2662. std::vector<Value*> args {
  2663. this->core_ptr,
  2664. this->gen_const(64, pc.val),
  2665. this->builder.CreateGlobalStringPtr(mnemonic),
  2666. };
  2667. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2668. }
  2669. Value* cur_pc_val = this->gen_const(32, pc.val);
  2670. pc=pc+4;
  2671. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fsel_d"), std::vector<Value*>{
  2672. this->builder.CreateTrunc(
  2673. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2674. this-> get_type(64)
  2675. ),
  2676. this->builder.CreateTrunc(
  2677. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2678. this-> get_type(64)
  2679. ),
  2680. this->gen_ext(
  2681. this->gen_const(64U, 0LL),
  2682. 32,
  2683. false)
  2684. });
  2685. if(64 == 64){
  2686. Value* Ftmp0_val = res_val;
  2687. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2688. } else {
  2689. uint64_t upper_val = - 1;
  2690. Value* Ftmp1_val = this->builder.CreateOr(
  2691. this->builder.CreateShl(
  2692. this->gen_const(64U, upper_val),
  2693. this->gen_const(64U, 64)),
  2694. res_val);
  2695. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2696. }
  2697. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2698. });
  2699. Value* FCSR_val = this->builder.CreateAdd(
  2700. this->builder.CreateAnd(
  2701. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2702. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2703. flags_val);
  2704. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2705. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2706. this->gen_sync(POST_SYNC, 51);
  2707. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2708. this->gen_trap_check(bb);
  2709. return std::make_tuple(CONT, bb);
  2710. }
  2711. /* instruction 52: FMAX.D */
  2712. std::tuple<continuation_e, BasicBlock*> __fmax_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2713. bb->setName("FMAX.D");
  2714. this->gen_sync(PRE_SYNC, 52);
  2715. uint8_t rd = ((bit_sub<7,5>(instr)));
  2716. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2717. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2718. if(this->disass_enabled){
  2719. /* generate console output when executing the command */
  2720. auto mnemonic = fmt::format(
  2721. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fmax.d"),
  2722. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2723. std::vector<Value*> args {
  2724. this->core_ptr,
  2725. this->gen_const(64, pc.val),
  2726. this->builder.CreateGlobalStringPtr(mnemonic),
  2727. };
  2728. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2729. }
  2730. Value* cur_pc_val = this->gen_const(32, pc.val);
  2731. pc=pc+4;
  2732. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fsel_d"), std::vector<Value*>{
  2733. this->builder.CreateTrunc(
  2734. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2735. this-> get_type(64)
  2736. ),
  2737. this->builder.CreateTrunc(
  2738. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2739. this-> get_type(64)
  2740. ),
  2741. this->gen_ext(
  2742. this->gen_const(64U, 1LL),
  2743. 32,
  2744. false)
  2745. });
  2746. if(64 == 64){
  2747. Value* Ftmp0_val = res_val;
  2748. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2749. } else {
  2750. uint64_t upper_val = - 1;
  2751. Value* Ftmp1_val = this->builder.CreateOr(
  2752. this->builder.CreateShl(
  2753. this->gen_const(64U, upper_val),
  2754. this->gen_const(64U, 64)),
  2755. res_val);
  2756. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2757. }
  2758. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2759. });
  2760. Value* FCSR_val = this->builder.CreateAdd(
  2761. this->builder.CreateAnd(
  2762. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2763. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2764. flags_val);
  2765. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2766. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2767. this->gen_sync(POST_SYNC, 52);
  2768. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2769. this->gen_trap_check(bb);
  2770. return std::make_tuple(CONT, bb);
  2771. }
  2772. /* instruction 53: FCVT.S.D */
  2773. std::tuple<continuation_e, BasicBlock*> __fcvt_s_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2774. bb->setName("FCVT.S.D");
  2775. this->gen_sync(PRE_SYNC, 53);
  2776. uint8_t rd = ((bit_sub<7,5>(instr)));
  2777. uint8_t rm = ((bit_sub<12,3>(instr)));
  2778. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2779. if(this->disass_enabled){
  2780. /* generate console output when executing the command */
  2781. auto mnemonic = fmt::format(
  2782. "{mnemonic:10} f{rd}, f{rs1}", fmt::arg("mnemonic", "fcvt.s.d"),
  2783. fmt::arg("rd", rd), fmt::arg("rs1", rs1));
  2784. std::vector<Value*> args {
  2785. this->core_ptr,
  2786. this->gen_const(64, pc.val),
  2787. this->builder.CreateGlobalStringPtr(mnemonic),
  2788. };
  2789. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2790. }
  2791. Value* cur_pc_val = this->gen_const(32, pc.val);
  2792. pc=pc+4;
  2793. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fconv_d2f"), std::vector<Value*>{
  2794. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2795. this->gen_const(8U, rm)
  2796. });
  2797. uint64_t upper_val = - 1;
  2798. Value* Ftmp0_val = this->builder.CreateOr(
  2799. this->builder.CreateShl(
  2800. this->gen_const(64U, upper_val),
  2801. this->gen_const(64U, 32)),
  2802. this->gen_ext(
  2803. res_val,
  2804. 64,
  2805. false));
  2806. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2807. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2808. this->gen_sync(POST_SYNC, 53);
  2809. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2810. this->gen_trap_check(bb);
  2811. return std::make_tuple(CONT, bb);
  2812. }
  2813. /* instruction 54: FCVT.D.S */
  2814. std::tuple<continuation_e, BasicBlock*> __fcvt_d_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2815. bb->setName("FCVT.D.S");
  2816. this->gen_sync(PRE_SYNC, 54);
  2817. uint8_t rd = ((bit_sub<7,5>(instr)));
  2818. uint8_t rm = ((bit_sub<12,3>(instr)));
  2819. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2820. if(this->disass_enabled){
  2821. /* generate console output when executing the command */
  2822. auto mnemonic = fmt::format(
  2823. "{mnemonic:10} f{rd}, f{rs1}", fmt::arg("mnemonic", "fcvt.d.s"),
  2824. fmt::arg("rd", rd), fmt::arg("rs1", rs1));
  2825. std::vector<Value*> args {
  2826. this->core_ptr,
  2827. this->gen_const(64, pc.val),
  2828. this->builder.CreateGlobalStringPtr(mnemonic),
  2829. };
  2830. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2831. }
  2832. Value* cur_pc_val = this->gen_const(32, pc.val);
  2833. pc=pc+4;
  2834. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fconv_f2d"), std::vector<Value*>{
  2835. this->builder.CreateTrunc(
  2836. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2837. this-> get_type(32)
  2838. ),
  2839. this->gen_const(8U, rm)
  2840. });
  2841. if(64 == 64){
  2842. Value* Ftmp0_val = res_val;
  2843. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2844. } else {
  2845. uint64_t upper_val = - 1;
  2846. Value* Ftmp1_val = this->builder.CreateOr(
  2847. this->builder.CreateShl(
  2848. this->gen_const(64U, upper_val),
  2849. this->gen_const(64U, 64)),
  2850. res_val);
  2851. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  2852. }
  2853. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2854. this->gen_sync(POST_SYNC, 54);
  2855. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2856. this->gen_trap_check(bb);
  2857. return std::make_tuple(CONT, bb);
  2858. }
  2859. /* instruction 55: FEQ.D */
  2860. std::tuple<continuation_e, BasicBlock*> __feq_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2861. bb->setName("FEQ.D");
  2862. this->gen_sync(PRE_SYNC, 55);
  2863. uint8_t rd = ((bit_sub<7,5>(instr)));
  2864. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2865. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2866. if(this->disass_enabled){
  2867. /* generate console output when executing the command */
  2868. auto mnemonic = fmt::format(
  2869. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "feq.d"),
  2870. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2871. std::vector<Value*> args {
  2872. this->core_ptr,
  2873. this->gen_const(64, pc.val),
  2874. this->builder.CreateGlobalStringPtr(mnemonic),
  2875. };
  2876. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2877. }
  2878. Value* cur_pc_val = this->gen_const(32, pc.val);
  2879. pc=pc+4;
  2880. Value* Xtmp0_val = this->gen_ext(
  2881. this->builder.CreateCall(this->mod->getFunction("fcmp_d"), std::vector<Value*>{
  2882. this->builder.CreateTrunc(
  2883. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2884. this-> get_type(64)
  2885. ),
  2886. this->builder.CreateTrunc(
  2887. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2888. this-> get_type(64)
  2889. ),
  2890. this->gen_ext(
  2891. this->gen_const(64U, 0LL),
  2892. 32,
  2893. false)
  2894. }),
  2895. 32,
  2896. false);
  2897. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  2898. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2899. });
  2900. Value* FCSR_val = this->builder.CreateAdd(
  2901. this->builder.CreateAnd(
  2902. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2903. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2904. flags_val);
  2905. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2906. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2907. this->gen_sync(POST_SYNC, 55);
  2908. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2909. this->gen_trap_check(bb);
  2910. return std::make_tuple(CONT, bb);
  2911. }
  2912. /* instruction 56: FLT.D */
  2913. std::tuple<continuation_e, BasicBlock*> __flt_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2914. bb->setName("FLT.D");
  2915. this->gen_sync(PRE_SYNC, 56);
  2916. uint8_t rd = ((bit_sub<7,5>(instr)));
  2917. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2918. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2919. if(this->disass_enabled){
  2920. /* generate console output when executing the command */
  2921. auto mnemonic = fmt::format(
  2922. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "flt.d"),
  2923. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2924. std::vector<Value*> args {
  2925. this->core_ptr,
  2926. this->gen_const(64, pc.val),
  2927. this->builder.CreateGlobalStringPtr(mnemonic),
  2928. };
  2929. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2930. }
  2931. Value* cur_pc_val = this->gen_const(32, pc.val);
  2932. pc=pc+4;
  2933. Value* Xtmp0_val = this->gen_ext(
  2934. this->builder.CreateCall(this->mod->getFunction("fcmp_d"), std::vector<Value*>{
  2935. this->builder.CreateTrunc(
  2936. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2937. this-> get_type(64)
  2938. ),
  2939. this->builder.CreateTrunc(
  2940. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2941. this-> get_type(64)
  2942. ),
  2943. this->gen_ext(
  2944. this->gen_const(64U, 2LL),
  2945. 32,
  2946. false)
  2947. }),
  2948. 32,
  2949. false);
  2950. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  2951. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  2952. });
  2953. Value* FCSR_val = this->builder.CreateAdd(
  2954. this->builder.CreateAnd(
  2955. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  2956. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  2957. flags_val);
  2958. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  2959. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  2960. this->gen_sync(POST_SYNC, 56);
  2961. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  2962. this->gen_trap_check(bb);
  2963. return std::make_tuple(CONT, bb);
  2964. }
  2965. /* instruction 57: FLE.D */
  2966. std::tuple<continuation_e, BasicBlock*> __fle_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  2967. bb->setName("FLE.D");
  2968. this->gen_sync(PRE_SYNC, 57);
  2969. uint8_t rd = ((bit_sub<7,5>(instr)));
  2970. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  2971. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  2972. if(this->disass_enabled){
  2973. /* generate console output when executing the command */
  2974. auto mnemonic = fmt::format(
  2975. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fle.d"),
  2976. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  2977. std::vector<Value*> args {
  2978. this->core_ptr,
  2979. this->gen_const(64, pc.val),
  2980. this->builder.CreateGlobalStringPtr(mnemonic),
  2981. };
  2982. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  2983. }
  2984. Value* cur_pc_val = this->gen_const(32, pc.val);
  2985. pc=pc+4;
  2986. Value* Xtmp0_val = this->gen_ext(
  2987. this->builder.CreateCall(this->mod->getFunction("fcmp_d"), std::vector<Value*>{
  2988. this->builder.CreateTrunc(
  2989. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  2990. this-> get_type(64)
  2991. ),
  2992. this->builder.CreateTrunc(
  2993. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  2994. this-> get_type(64)
  2995. ),
  2996. this->gen_ext(
  2997. this->gen_const(64U, 1LL),
  2998. 32,
  2999. false)
  3000. }),
  3001. 32,
  3002. false);
  3003. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3004. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  3005. });
  3006. Value* FCSR_val = this->builder.CreateAdd(
  3007. this->builder.CreateAnd(
  3008. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  3009. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  3010. flags_val);
  3011. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  3012. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3013. this->gen_sync(POST_SYNC, 57);
  3014. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3015. this->gen_trap_check(bb);
  3016. return std::make_tuple(CONT, bb);
  3017. }
  3018. /* instruction 58: FCLASS.D */
  3019. std::tuple<continuation_e, BasicBlock*> __fclass_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3020. bb->setName("FCLASS.D");
  3021. this->gen_sync(PRE_SYNC, 58);
  3022. uint8_t rd = ((bit_sub<7,5>(instr)));
  3023. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3024. if(this->disass_enabled){
  3025. /* generate console output when executing the command */
  3026. auto mnemonic = fmt::format(
  3027. "{mnemonic:10} {rd}, f{rs1}", fmt::arg("mnemonic", "fclass.d"),
  3028. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1));
  3029. std::vector<Value*> args {
  3030. this->core_ptr,
  3031. this->gen_const(64, pc.val),
  3032. this->builder.CreateGlobalStringPtr(mnemonic),
  3033. };
  3034. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3035. }
  3036. Value* cur_pc_val = this->gen_const(32, pc.val);
  3037. pc=pc+4;
  3038. Value* Xtmp0_val = this->builder.CreateCall(this->mod->getFunction("fclass_d"), std::vector<Value*>{
  3039. this->builder.CreateTrunc(
  3040. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  3041. this-> get_type(64)
  3042. )
  3043. });
  3044. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3045. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3046. this->gen_sync(POST_SYNC, 58);
  3047. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3048. this->gen_trap_check(bb);
  3049. return std::make_tuple(CONT, bb);
  3050. }
  3051. /* instruction 59: FCVT.W.D */
  3052. std::tuple<continuation_e, BasicBlock*> __fcvt_w_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3053. bb->setName("FCVT.W.D");
  3054. this->gen_sync(PRE_SYNC, 59);
  3055. uint8_t rd = ((bit_sub<7,5>(instr)));
  3056. uint8_t rm = ((bit_sub<12,3>(instr)));
  3057. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3058. if(this->disass_enabled){
  3059. /* generate console output when executing the command */
  3060. auto mnemonic = fmt::format(
  3061. "{mnemonic:10} {rd}, f{rs1}", fmt::arg("mnemonic", "fcvt.w.d"),
  3062. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1));
  3063. std::vector<Value*> args {
  3064. this->core_ptr,
  3065. this->gen_const(64, pc.val),
  3066. this->builder.CreateGlobalStringPtr(mnemonic),
  3067. };
  3068. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3069. }
  3070. Value* cur_pc_val = this->gen_const(32, pc.val);
  3071. pc=pc+4;
  3072. Value* Xtmp0_val = this->gen_ext(
  3073. this->builder.CreateCall(this->mod->getFunction("fcvt_64_32"), std::vector<Value*>{
  3074. this->builder.CreateTrunc(
  3075. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  3076. this-> get_type(64)
  3077. ),
  3078. this->gen_ext(
  3079. this->gen_const(64U, 0LL),
  3080. 32,
  3081. false),
  3082. this->gen_const(8U, rm)
  3083. }),
  3084. 32,
  3085. true);
  3086. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3087. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  3088. });
  3089. Value* FCSR_val = this->builder.CreateAdd(
  3090. this->builder.CreateAnd(
  3091. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  3092. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  3093. flags_val);
  3094. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  3095. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3096. this->gen_sync(POST_SYNC, 59);
  3097. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3098. this->gen_trap_check(bb);
  3099. return std::make_tuple(CONT, bb);
  3100. }
  3101. /* instruction 60: FCVT.WU.D */
  3102. std::tuple<continuation_e, BasicBlock*> __fcvt_wu_d(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3103. bb->setName("FCVT.WU.D");
  3104. this->gen_sync(PRE_SYNC, 60);
  3105. uint8_t rd = ((bit_sub<7,5>(instr)));
  3106. uint8_t rm = ((bit_sub<12,3>(instr)));
  3107. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3108. if(this->disass_enabled){
  3109. /* generate console output when executing the command */
  3110. auto mnemonic = fmt::format(
  3111. "{mnemonic:10} {rd}, f{rs1}", fmt::arg("mnemonic", "fcvt.wu.d"),
  3112. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1));
  3113. std::vector<Value*> args {
  3114. this->core_ptr,
  3115. this->gen_const(64, pc.val),
  3116. this->builder.CreateGlobalStringPtr(mnemonic),
  3117. };
  3118. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3119. }
  3120. Value* cur_pc_val = this->gen_const(32, pc.val);
  3121. pc=pc+4;
  3122. Value* Xtmp0_val = this->gen_ext(
  3123. this->builder.CreateCall(this->mod->getFunction("fcvt_64_32"), std::vector<Value*>{
  3124. this->builder.CreateTrunc(
  3125. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  3126. this-> get_type(64)
  3127. ),
  3128. this->gen_ext(
  3129. this->gen_const(64U, 1LL),
  3130. 32,
  3131. false),
  3132. this->gen_const(8U, rm)
  3133. }),
  3134. 32,
  3135. true);
  3136. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3137. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  3138. });
  3139. Value* FCSR_val = this->builder.CreateAdd(
  3140. this->builder.CreateAnd(
  3141. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  3142. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  3143. flags_val);
  3144. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  3145. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3146. this->gen_sync(POST_SYNC, 60);
  3147. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3148. this->gen_trap_check(bb);
  3149. return std::make_tuple(CONT, bb);
  3150. }
  3151. /* instruction 61: FCVT.D.W */
  3152. std::tuple<continuation_e, BasicBlock*> __fcvt_d_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3153. bb->setName("FCVT.D.W");
  3154. this->gen_sync(PRE_SYNC, 61);
  3155. uint8_t rd = ((bit_sub<7,5>(instr)));
  3156. uint8_t rm = ((bit_sub<12,3>(instr)));
  3157. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3158. if(this->disass_enabled){
  3159. /* generate console output when executing the command */
  3160. auto mnemonic = fmt::format(
  3161. "{mnemonic:10} f{rd}, {rs1}", fmt::arg("mnemonic", "fcvt.d.w"),
  3162. fmt::arg("rd", rd), fmt::arg("rs1", name(rs1)));
  3163. std::vector<Value*> args {
  3164. this->core_ptr,
  3165. this->gen_const(64, pc.val),
  3166. this->builder.CreateGlobalStringPtr(mnemonic),
  3167. };
  3168. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3169. }
  3170. Value* cur_pc_val = this->gen_const(32, pc.val);
  3171. pc=pc+4;
  3172. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fcvt_32_64"), std::vector<Value*>{
  3173. this->gen_ext(
  3174. this->builder.CreateTrunc(
  3175. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3176. this-> get_type(32)
  3177. ),
  3178. 64,
  3179. true),
  3180. this->gen_ext(
  3181. this->gen_const(64U, 2LL),
  3182. 32,
  3183. false),
  3184. this->gen_const(8U, rm)
  3185. });
  3186. if(64 == 64){
  3187. Value* Ftmp0_val = res_val;
  3188. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  3189. } else {
  3190. uint64_t upper_val = - 1;
  3191. Value* Ftmp1_val = this->builder.CreateOr(
  3192. this->builder.CreateShl(
  3193. this->gen_const(64U, upper_val),
  3194. this->gen_const(64U, 64)),
  3195. res_val);
  3196. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  3197. }
  3198. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3199. this->gen_sync(POST_SYNC, 61);
  3200. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3201. this->gen_trap_check(bb);
  3202. return std::make_tuple(CONT, bb);
  3203. }
  3204. /* instruction 62: FCVT.D.WU */
  3205. std::tuple<continuation_e, BasicBlock*> __fcvt_d_wu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3206. bb->setName("FCVT.D.WU");
  3207. this->gen_sync(PRE_SYNC, 62);
  3208. uint8_t rd = ((bit_sub<7,5>(instr)));
  3209. uint8_t rm = ((bit_sub<12,3>(instr)));
  3210. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3211. if(this->disass_enabled){
  3212. /* generate console output when executing the command */
  3213. auto mnemonic = fmt::format(
  3214. "{mnemonic:10} f{rd}, {rs1}", fmt::arg("mnemonic", "fcvt.d.wu"),
  3215. fmt::arg("rd", rd), fmt::arg("rs1", name(rs1)));
  3216. std::vector<Value*> args {
  3217. this->core_ptr,
  3218. this->gen_const(64, pc.val),
  3219. this->builder.CreateGlobalStringPtr(mnemonic),
  3220. };
  3221. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3222. }
  3223. Value* cur_pc_val = this->gen_const(32, pc.val);
  3224. pc=pc+4;
  3225. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fcvt_32_64"), std::vector<Value*>{
  3226. this->gen_ext(
  3227. this->builder.CreateTrunc(
  3228. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3229. this-> get_type(32)
  3230. ),
  3231. 64,
  3232. false),
  3233. this->gen_ext(
  3234. this->gen_const(64U, 3LL),
  3235. 32,
  3236. false),
  3237. this->gen_const(8U, rm)
  3238. });
  3239. if(64 == 64){
  3240. Value* Ftmp0_val = res_val;
  3241. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  3242. } else {
  3243. uint64_t upper_val = - 1;
  3244. Value* Ftmp1_val = this->builder.CreateOr(
  3245. this->builder.CreateShl(
  3246. this->gen_const(64U, upper_val),
  3247. this->gen_const(64U, 64)),
  3248. res_val);
  3249. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  3250. }
  3251. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3252. this->gen_sync(POST_SYNC, 62);
  3253. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3254. this->gen_trap_check(bb);
  3255. return std::make_tuple(CONT, bb);
  3256. }
  3257. /* instruction 63: LUI */
  3258. std::tuple<continuation_e, BasicBlock*> __lui(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3259. bb->setName("LUI");
  3260. this->gen_sync(PRE_SYNC, 63);
  3261. uint8_t rd = ((bit_sub<7,5>(instr)));
  3262. int32_t imm = signextend<int32_t,32>((bit_sub<12,20>(instr) << 12));
  3263. if(this->disass_enabled){
  3264. /* generate console output when executing the command */
  3265. auto mnemonic = fmt::format(
  3266. "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "lui"),
  3267. fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
  3268. std::vector<Value*> args {
  3269. this->core_ptr,
  3270. this->gen_const(64, pc.val),
  3271. this->builder.CreateGlobalStringPtr(mnemonic),
  3272. };
  3273. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3274. }
  3275. Value* cur_pc_val = this->gen_const(32, pc.val);
  3276. pc=pc+4;
  3277. if(rd != 0){
  3278. Value* Xtmp0_val = this->gen_const(32U, imm);
  3279. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3280. }
  3281. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3282. this->gen_sync(POST_SYNC, 63);
  3283. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3284. this->gen_trap_check(bb);
  3285. return std::make_tuple(CONT, bb);
  3286. }
  3287. /* instruction 64: AUIPC */
  3288. std::tuple<continuation_e, BasicBlock*> __auipc(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3289. bb->setName("AUIPC");
  3290. this->gen_sync(PRE_SYNC, 64);
  3291. uint8_t rd = ((bit_sub<7,5>(instr)));
  3292. int32_t imm = signextend<int32_t,32>((bit_sub<12,20>(instr) << 12));
  3293. if(this->disass_enabled){
  3294. /* generate console output when executing the command */
  3295. auto mnemonic = fmt::format(
  3296. "{mnemonic:10} {rd}, {imm:#08x}", fmt::arg("mnemonic", "auipc"),
  3297. fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
  3298. std::vector<Value*> args {
  3299. this->core_ptr,
  3300. this->gen_const(64, pc.val),
  3301. this->builder.CreateGlobalStringPtr(mnemonic),
  3302. };
  3303. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3304. }
  3305. Value* cur_pc_val = this->gen_const(32, pc.val);
  3306. pc=pc+4;
  3307. if(rd != 0){
  3308. Value* Xtmp0_val = this->builder.CreateAdd(
  3309. this->gen_ext(
  3310. cur_pc_val,
  3311. 32, true),
  3312. this->gen_const(32U, imm));
  3313. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3314. }
  3315. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3316. this->gen_sync(POST_SYNC, 64);
  3317. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3318. this->gen_trap_check(bb);
  3319. return std::make_tuple(CONT, bb);
  3320. }
  3321. /* instruction 65: JAL */
  3322. std::tuple<continuation_e, BasicBlock*> __jal(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3323. bb->setName("JAL");
  3324. this->gen_sync(PRE_SYNC, 65);
  3325. uint8_t rd = ((bit_sub<7,5>(instr)));
  3326. int32_t imm = signextend<int32_t,21>((bit_sub<12,8>(instr) << 12) | (bit_sub<20,1>(instr) << 11) | (bit_sub<21,10>(instr) << 1) | (bit_sub<31,1>(instr) << 20));
  3327. if(this->disass_enabled){
  3328. /* generate console output when executing the command */
  3329. auto mnemonic = fmt::format(
  3330. "{mnemonic:10} {rd}, {imm:#0x}", fmt::arg("mnemonic", "jal"),
  3331. fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
  3332. std::vector<Value*> args {
  3333. this->core_ptr,
  3334. this->gen_const(64, pc.val),
  3335. this->builder.CreateGlobalStringPtr(mnemonic),
  3336. };
  3337. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3338. }
  3339. Value* cur_pc_val = this->gen_const(32, pc.val);
  3340. pc=pc+4;
  3341. if(rd != 0){
  3342. Value* Xtmp0_val = this->builder.CreateAdd(
  3343. cur_pc_val,
  3344. this->gen_const(32U, 4));
  3345. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3346. }
  3347. Value* PC_val = this->builder.CreateAdd(
  3348. this->gen_ext(
  3349. cur_pc_val,
  3350. 32, true),
  3351. this->gen_const(32U, imm));
  3352. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  3353. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  3354. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  3355. this->gen_sync(POST_SYNC, 65);
  3356. this->gen_trap_check(this->leave_blk);
  3357. return std::make_tuple(BRANCH, nullptr);
  3358. }
  3359. /* instruction 66: BEQ */
  3360. std::tuple<continuation_e, BasicBlock*> __beq(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3361. bb->setName("BEQ");
  3362. this->gen_sync(PRE_SYNC, 66);
  3363. int16_t imm = signextend<int16_t,13>((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
  3364. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3365. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3366. if(this->disass_enabled){
  3367. /* generate console output when executing the command */
  3368. auto mnemonic = fmt::format(
  3369. "{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "beq"),
  3370. fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
  3371. std::vector<Value*> args {
  3372. this->core_ptr,
  3373. this->gen_const(64, pc.val),
  3374. this->builder.CreateGlobalStringPtr(mnemonic),
  3375. };
  3376. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3377. }
  3378. Value* cur_pc_val = this->gen_const(32, pc.val);
  3379. pc=pc+4;
  3380. Value* PC_val = this->gen_choose(
  3381. this->builder.CreateICmp(
  3382. ICmpInst::ICMP_EQ,
  3383. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3384. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0)),
  3385. this->builder.CreateAdd(
  3386. this->gen_ext(
  3387. cur_pc_val,
  3388. 32, true),
  3389. this->gen_const(32U, imm)),
  3390. this->builder.CreateAdd(
  3391. cur_pc_val,
  3392. this->gen_const(32U, 4)),
  3393. 32);
  3394. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  3395. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  3396. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  3397. this->gen_sync(POST_SYNC, 66);
  3398. this->gen_trap_check(this->leave_blk);
  3399. return std::make_tuple(BRANCH, nullptr);
  3400. }
  3401. /* instruction 67: BNE */
  3402. std::tuple<continuation_e, BasicBlock*> __bne(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3403. bb->setName("BNE");
  3404. this->gen_sync(PRE_SYNC, 67);
  3405. int16_t imm = signextend<int16_t,13>((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
  3406. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3407. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3408. if(this->disass_enabled){
  3409. /* generate console output when executing the command */
  3410. auto mnemonic = fmt::format(
  3411. "{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "bne"),
  3412. fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
  3413. std::vector<Value*> args {
  3414. this->core_ptr,
  3415. this->gen_const(64, pc.val),
  3416. this->builder.CreateGlobalStringPtr(mnemonic),
  3417. };
  3418. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3419. }
  3420. Value* cur_pc_val = this->gen_const(32, pc.val);
  3421. pc=pc+4;
  3422. Value* PC_val = this->gen_choose(
  3423. this->builder.CreateICmp(
  3424. ICmpInst::ICMP_NE,
  3425. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3426. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0)),
  3427. this->builder.CreateAdd(
  3428. this->gen_ext(
  3429. cur_pc_val,
  3430. 32, true),
  3431. this->gen_const(32U, imm)),
  3432. this->builder.CreateAdd(
  3433. cur_pc_val,
  3434. this->gen_const(32U, 4)),
  3435. 32);
  3436. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  3437. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  3438. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  3439. this->gen_sync(POST_SYNC, 67);
  3440. this->gen_trap_check(this->leave_blk);
  3441. return std::make_tuple(BRANCH, nullptr);
  3442. }
  3443. /* instruction 68: BLT */
  3444. std::tuple<continuation_e, BasicBlock*> __blt(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3445. bb->setName("BLT");
  3446. this->gen_sync(PRE_SYNC, 68);
  3447. int16_t imm = signextend<int16_t,13>((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
  3448. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3449. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3450. if(this->disass_enabled){
  3451. /* generate console output when executing the command */
  3452. auto mnemonic = fmt::format(
  3453. "{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "blt"),
  3454. fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
  3455. std::vector<Value*> args {
  3456. this->core_ptr,
  3457. this->gen_const(64, pc.val),
  3458. this->builder.CreateGlobalStringPtr(mnemonic),
  3459. };
  3460. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3461. }
  3462. Value* cur_pc_val = this->gen_const(32, pc.val);
  3463. pc=pc+4;
  3464. Value* PC_val = this->gen_choose(
  3465. this->builder.CreateICmp(
  3466. ICmpInst::ICMP_SLT,
  3467. this->gen_ext(
  3468. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3469. 32, true),
  3470. this->gen_ext(
  3471. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  3472. 32, true)),
  3473. this->builder.CreateAdd(
  3474. this->gen_ext(
  3475. cur_pc_val,
  3476. 32, true),
  3477. this->gen_const(32U, imm)),
  3478. this->builder.CreateAdd(
  3479. cur_pc_val,
  3480. this->gen_const(32U, 4)),
  3481. 32);
  3482. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  3483. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  3484. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  3485. this->gen_sync(POST_SYNC, 68);
  3486. this->gen_trap_check(this->leave_blk);
  3487. return std::make_tuple(BRANCH, nullptr);
  3488. }
  3489. /* instruction 69: BGE */
  3490. std::tuple<continuation_e, BasicBlock*> __bge(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3491. bb->setName("BGE");
  3492. this->gen_sync(PRE_SYNC, 69);
  3493. int16_t imm = signextend<int16_t,13>((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
  3494. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3495. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3496. if(this->disass_enabled){
  3497. /* generate console output when executing the command */
  3498. auto mnemonic = fmt::format(
  3499. "{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "bge"),
  3500. fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
  3501. std::vector<Value*> args {
  3502. this->core_ptr,
  3503. this->gen_const(64, pc.val),
  3504. this->builder.CreateGlobalStringPtr(mnemonic),
  3505. };
  3506. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3507. }
  3508. Value* cur_pc_val = this->gen_const(32, pc.val);
  3509. pc=pc+4;
  3510. Value* PC_val = this->gen_choose(
  3511. this->builder.CreateICmp(
  3512. ICmpInst::ICMP_SGE,
  3513. this->gen_ext(
  3514. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3515. 32, true),
  3516. this->gen_ext(
  3517. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  3518. 32, true)),
  3519. this->builder.CreateAdd(
  3520. this->gen_ext(
  3521. cur_pc_val,
  3522. 32, true),
  3523. this->gen_const(32U, imm)),
  3524. this->builder.CreateAdd(
  3525. cur_pc_val,
  3526. this->gen_const(32U, 4)),
  3527. 32);
  3528. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  3529. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  3530. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  3531. this->gen_sync(POST_SYNC, 69);
  3532. this->gen_trap_check(this->leave_blk);
  3533. return std::make_tuple(BRANCH, nullptr);
  3534. }
  3535. /* instruction 70: BLTU */
  3536. std::tuple<continuation_e, BasicBlock*> __bltu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3537. bb->setName("BLTU");
  3538. this->gen_sync(PRE_SYNC, 70);
  3539. int16_t imm = signextend<int16_t,13>((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
  3540. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3541. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3542. if(this->disass_enabled){
  3543. /* generate console output when executing the command */
  3544. auto mnemonic = fmt::format(
  3545. "{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "bltu"),
  3546. fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
  3547. std::vector<Value*> args {
  3548. this->core_ptr,
  3549. this->gen_const(64, pc.val),
  3550. this->builder.CreateGlobalStringPtr(mnemonic),
  3551. };
  3552. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3553. }
  3554. Value* cur_pc_val = this->gen_const(32, pc.val);
  3555. pc=pc+4;
  3556. Value* PC_val = this->gen_choose(
  3557. this->builder.CreateICmp(
  3558. ICmpInst::ICMP_ULT,
  3559. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3560. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0)),
  3561. this->builder.CreateAdd(
  3562. this->gen_ext(
  3563. cur_pc_val,
  3564. 32, true),
  3565. this->gen_const(32U, imm)),
  3566. this->builder.CreateAdd(
  3567. cur_pc_val,
  3568. this->gen_const(32U, 4)),
  3569. 32);
  3570. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  3571. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  3572. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  3573. this->gen_sync(POST_SYNC, 70);
  3574. this->gen_trap_check(this->leave_blk);
  3575. return std::make_tuple(BRANCH, nullptr);
  3576. }
  3577. /* instruction 71: BGEU */
  3578. std::tuple<continuation_e, BasicBlock*> __bgeu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3579. bb->setName("BGEU");
  3580. this->gen_sync(PRE_SYNC, 71);
  3581. int16_t imm = signextend<int16_t,13>((bit_sub<7,1>(instr) << 11) | (bit_sub<8,4>(instr) << 1) | (bit_sub<25,6>(instr) << 5) | (bit_sub<31,1>(instr) << 12));
  3582. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3583. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3584. if(this->disass_enabled){
  3585. /* generate console output when executing the command */
  3586. auto mnemonic = fmt::format(
  3587. "{mnemonic:10} {rs1}, {rs2}, {imm:#0x}", fmt::arg("mnemonic", "bgeu"),
  3588. fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm));
  3589. std::vector<Value*> args {
  3590. this->core_ptr,
  3591. this->gen_const(64, pc.val),
  3592. this->builder.CreateGlobalStringPtr(mnemonic),
  3593. };
  3594. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3595. }
  3596. Value* cur_pc_val = this->gen_const(32, pc.val);
  3597. pc=pc+4;
  3598. Value* PC_val = this->gen_choose(
  3599. this->builder.CreateICmp(
  3600. ICmpInst::ICMP_UGE,
  3601. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3602. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0)),
  3603. this->builder.CreateAdd(
  3604. this->gen_ext(
  3605. cur_pc_val,
  3606. 32, true),
  3607. this->gen_const(32U, imm)),
  3608. this->builder.CreateAdd(
  3609. cur_pc_val,
  3610. this->gen_const(32U, 4)),
  3611. 32);
  3612. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  3613. Value* is_cont_v = this->builder.CreateICmp(ICmpInst::ICMP_NE, PC_val, this->gen_const(32U, pc.val), "is_cont_v");
  3614. this->builder.CreateStore(this->gen_ext(is_cont_v, 32U, false), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  3615. this->gen_sync(POST_SYNC, 71);
  3616. this->gen_trap_check(this->leave_blk);
  3617. return std::make_tuple(BRANCH, nullptr);
  3618. }
  3619. /* instruction 72: LB */
  3620. std::tuple<continuation_e, BasicBlock*> __lb(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3621. bb->setName("LB");
  3622. this->gen_sync(PRE_SYNC, 72);
  3623. uint8_t rd = ((bit_sub<7,5>(instr)));
  3624. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3625. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  3626. if(this->disass_enabled){
  3627. /* generate console output when executing the command */
  3628. auto mnemonic = fmt::format(
  3629. "{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lb"),
  3630. fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  3631. std::vector<Value*> args {
  3632. this->core_ptr,
  3633. this->gen_const(64, pc.val),
  3634. this->builder.CreateGlobalStringPtr(mnemonic),
  3635. };
  3636. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3637. }
  3638. Value* cur_pc_val = this->gen_const(32, pc.val);
  3639. pc=pc+4;
  3640. Value* offs_val = this->builder.CreateAdd(
  3641. this->gen_ext(
  3642. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3643. 32, true),
  3644. this->gen_const(32U, imm));
  3645. if(rd != 0){
  3646. Value* Xtmp0_val = this->gen_ext(
  3647. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 8/8),
  3648. 32,
  3649. true);
  3650. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3651. }
  3652. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3653. this->gen_sync(POST_SYNC, 72);
  3654. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3655. this->gen_trap_check(bb);
  3656. return std::make_tuple(CONT, bb);
  3657. }
  3658. /* instruction 73: LH */
  3659. std::tuple<continuation_e, BasicBlock*> __lh(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3660. bb->setName("LH");
  3661. this->gen_sync(PRE_SYNC, 73);
  3662. uint8_t rd = ((bit_sub<7,5>(instr)));
  3663. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3664. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  3665. if(this->disass_enabled){
  3666. /* generate console output when executing the command */
  3667. auto mnemonic = fmt::format(
  3668. "{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lh"),
  3669. fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  3670. std::vector<Value*> args {
  3671. this->core_ptr,
  3672. this->gen_const(64, pc.val),
  3673. this->builder.CreateGlobalStringPtr(mnemonic),
  3674. };
  3675. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3676. }
  3677. Value* cur_pc_val = this->gen_const(32, pc.val);
  3678. pc=pc+4;
  3679. Value* offs_val = this->builder.CreateAdd(
  3680. this->gen_ext(
  3681. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3682. 32, true),
  3683. this->gen_const(32U, imm));
  3684. if(rd != 0){
  3685. Value* Xtmp0_val = this->gen_ext(
  3686. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 16/8),
  3687. 32,
  3688. true);
  3689. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3690. }
  3691. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3692. this->gen_sync(POST_SYNC, 73);
  3693. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3694. this->gen_trap_check(bb);
  3695. return std::make_tuple(CONT, bb);
  3696. }
  3697. /* instruction 74: LW */
  3698. std::tuple<continuation_e, BasicBlock*> __lw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3699. bb->setName("LW");
  3700. this->gen_sync(PRE_SYNC, 74);
  3701. uint8_t rd = ((bit_sub<7,5>(instr)));
  3702. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3703. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  3704. if(this->disass_enabled){
  3705. /* generate console output when executing the command */
  3706. auto mnemonic = fmt::format(
  3707. "{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lw"),
  3708. fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  3709. std::vector<Value*> args {
  3710. this->core_ptr,
  3711. this->gen_const(64, pc.val),
  3712. this->builder.CreateGlobalStringPtr(mnemonic),
  3713. };
  3714. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3715. }
  3716. Value* cur_pc_val = this->gen_const(32, pc.val);
  3717. pc=pc+4;
  3718. Value* offs_val = this->builder.CreateAdd(
  3719. this->gen_ext(
  3720. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3721. 32, true),
  3722. this->gen_const(32U, imm));
  3723. if(rd != 0){
  3724. Value* Xtmp0_val = this->gen_ext(
  3725. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  3726. 32,
  3727. true);
  3728. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3729. }
  3730. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3731. this->gen_sync(POST_SYNC, 74);
  3732. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3733. this->gen_trap_check(bb);
  3734. return std::make_tuple(CONT, bb);
  3735. }
  3736. /* instruction 75: LBU */
  3737. std::tuple<continuation_e, BasicBlock*> __lbu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3738. bb->setName("LBU");
  3739. this->gen_sync(PRE_SYNC, 75);
  3740. uint8_t rd = ((bit_sub<7,5>(instr)));
  3741. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3742. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  3743. if(this->disass_enabled){
  3744. /* generate console output when executing the command */
  3745. auto mnemonic = fmt::format(
  3746. "{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lbu"),
  3747. fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  3748. std::vector<Value*> args {
  3749. this->core_ptr,
  3750. this->gen_const(64, pc.val),
  3751. this->builder.CreateGlobalStringPtr(mnemonic),
  3752. };
  3753. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3754. }
  3755. Value* cur_pc_val = this->gen_const(32, pc.val);
  3756. pc=pc+4;
  3757. Value* offs_val = this->builder.CreateAdd(
  3758. this->gen_ext(
  3759. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3760. 32, true),
  3761. this->gen_const(32U, imm));
  3762. if(rd != 0){
  3763. Value* Xtmp0_val = this->gen_ext(
  3764. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 8/8),
  3765. 32,
  3766. false);
  3767. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3768. }
  3769. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3770. this->gen_sync(POST_SYNC, 75);
  3771. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3772. this->gen_trap_check(bb);
  3773. return std::make_tuple(CONT, bb);
  3774. }
  3775. /* instruction 76: LHU */
  3776. std::tuple<continuation_e, BasicBlock*> __lhu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3777. bb->setName("LHU");
  3778. this->gen_sync(PRE_SYNC, 76);
  3779. uint8_t rd = ((bit_sub<7,5>(instr)));
  3780. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3781. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  3782. if(this->disass_enabled){
  3783. /* generate console output when executing the command */
  3784. auto mnemonic = fmt::format(
  3785. "{mnemonic:10} {rd}, {imm}({rs1})", fmt::arg("mnemonic", "lhu"),
  3786. fmt::arg("rd", name(rd)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  3787. std::vector<Value*> args {
  3788. this->core_ptr,
  3789. this->gen_const(64, pc.val),
  3790. this->builder.CreateGlobalStringPtr(mnemonic),
  3791. };
  3792. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3793. }
  3794. Value* cur_pc_val = this->gen_const(32, pc.val);
  3795. pc=pc+4;
  3796. Value* offs_val = this->builder.CreateAdd(
  3797. this->gen_ext(
  3798. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3799. 32, true),
  3800. this->gen_const(32U, imm));
  3801. if(rd != 0){
  3802. Value* Xtmp0_val = this->gen_ext(
  3803. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 16/8),
  3804. 32,
  3805. false);
  3806. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3807. }
  3808. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3809. this->gen_sync(POST_SYNC, 76);
  3810. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3811. this->gen_trap_check(bb);
  3812. return std::make_tuple(CONT, bb);
  3813. }
  3814. /* instruction 77: SB */
  3815. std::tuple<continuation_e, BasicBlock*> __sb(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3816. bb->setName("SB");
  3817. this->gen_sync(PRE_SYNC, 77);
  3818. int16_t imm = signextend<int16_t,12>((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5));
  3819. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3820. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3821. if(this->disass_enabled){
  3822. /* generate console output when executing the command */
  3823. auto mnemonic = fmt::format(
  3824. "{mnemonic:10} {rs2}, {imm}({rs1})", fmt::arg("mnemonic", "sb"),
  3825. fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  3826. std::vector<Value*> args {
  3827. this->core_ptr,
  3828. this->gen_const(64, pc.val),
  3829. this->builder.CreateGlobalStringPtr(mnemonic),
  3830. };
  3831. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3832. }
  3833. Value* cur_pc_val = this->gen_const(32, pc.val);
  3834. pc=pc+4;
  3835. Value* offs_val = this->builder.CreateAdd(
  3836. this->gen_ext(
  3837. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3838. 32, true),
  3839. this->gen_const(32U, imm));
  3840. Value* MEMtmp0_val = this->gen_reg_load(rs2 + traits<ARCH>::X0, 0);
  3841. this->gen_write_mem(
  3842. traits<ARCH>::MEM,
  3843. offs_val,
  3844. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(8)));
  3845. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3846. this->gen_sync(POST_SYNC, 77);
  3847. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3848. this->gen_trap_check(bb);
  3849. return std::make_tuple(CONT, bb);
  3850. }
  3851. /* instruction 78: SH */
  3852. std::tuple<continuation_e, BasicBlock*> __sh(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3853. bb->setName("SH");
  3854. this->gen_sync(PRE_SYNC, 78);
  3855. int16_t imm = signextend<int16_t,12>((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5));
  3856. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3857. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3858. if(this->disass_enabled){
  3859. /* generate console output when executing the command */
  3860. auto mnemonic = fmt::format(
  3861. "{mnemonic:10} {rs2}, {imm}({rs1})", fmt::arg("mnemonic", "sh"),
  3862. fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  3863. std::vector<Value*> args {
  3864. this->core_ptr,
  3865. this->gen_const(64, pc.val),
  3866. this->builder.CreateGlobalStringPtr(mnemonic),
  3867. };
  3868. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3869. }
  3870. Value* cur_pc_val = this->gen_const(32, pc.val);
  3871. pc=pc+4;
  3872. Value* offs_val = this->builder.CreateAdd(
  3873. this->gen_ext(
  3874. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3875. 32, true),
  3876. this->gen_const(32U, imm));
  3877. Value* MEMtmp0_val = this->gen_reg_load(rs2 + traits<ARCH>::X0, 0);
  3878. this->gen_write_mem(
  3879. traits<ARCH>::MEM,
  3880. offs_val,
  3881. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(16)));
  3882. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3883. this->gen_sync(POST_SYNC, 78);
  3884. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3885. this->gen_trap_check(bb);
  3886. return std::make_tuple(CONT, bb);
  3887. }
  3888. /* instruction 79: SW */
  3889. std::tuple<continuation_e, BasicBlock*> __sw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3890. bb->setName("SW");
  3891. this->gen_sync(PRE_SYNC, 79);
  3892. int16_t imm = signextend<int16_t,12>((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5));
  3893. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3894. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  3895. if(this->disass_enabled){
  3896. /* generate console output when executing the command */
  3897. auto mnemonic = fmt::format(
  3898. "{mnemonic:10} {rs2}, {imm}({rs1})", fmt::arg("mnemonic", "sw"),
  3899. fmt::arg("rs2", name(rs2)), fmt::arg("imm", imm), fmt::arg("rs1", name(rs1)));
  3900. std::vector<Value*> args {
  3901. this->core_ptr,
  3902. this->gen_const(64, pc.val),
  3903. this->builder.CreateGlobalStringPtr(mnemonic),
  3904. };
  3905. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3906. }
  3907. Value* cur_pc_val = this->gen_const(32, pc.val);
  3908. pc=pc+4;
  3909. Value* offs_val = this->builder.CreateAdd(
  3910. this->gen_ext(
  3911. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3912. 32, true),
  3913. this->gen_const(32U, imm));
  3914. Value* MEMtmp0_val = this->gen_reg_load(rs2 + traits<ARCH>::X0, 0);
  3915. this->gen_write_mem(
  3916. traits<ARCH>::MEM,
  3917. offs_val,
  3918. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(32)));
  3919. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3920. this->gen_sync(POST_SYNC, 79);
  3921. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3922. this->gen_trap_check(bb);
  3923. return std::make_tuple(CONT, bb);
  3924. }
  3925. /* instruction 80: ADDI */
  3926. std::tuple<continuation_e, BasicBlock*> __addi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3927. bb->setName("ADDI");
  3928. this->gen_sync(PRE_SYNC, 80);
  3929. uint8_t rd = ((bit_sub<7,5>(instr)));
  3930. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3931. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  3932. if(this->disass_enabled){
  3933. /* generate console output when executing the command */
  3934. auto mnemonic = fmt::format(
  3935. "{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "addi"),
  3936. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
  3937. std::vector<Value*> args {
  3938. this->core_ptr,
  3939. this->gen_const(64, pc.val),
  3940. this->builder.CreateGlobalStringPtr(mnemonic),
  3941. };
  3942. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3943. }
  3944. Value* cur_pc_val = this->gen_const(32, pc.val);
  3945. pc=pc+4;
  3946. if(rd != 0){
  3947. Value* Xtmp0_val = this->builder.CreateAdd(
  3948. this->gen_ext(
  3949. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3950. 32, true),
  3951. this->gen_const(32U, imm));
  3952. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3953. }
  3954. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3955. this->gen_sync(POST_SYNC, 80);
  3956. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3957. this->gen_trap_check(bb);
  3958. return std::make_tuple(CONT, bb);
  3959. }
  3960. /* instruction 81: SLTI */
  3961. std::tuple<continuation_e, BasicBlock*> __slti(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  3962. bb->setName("SLTI");
  3963. this->gen_sync(PRE_SYNC, 81);
  3964. uint8_t rd = ((bit_sub<7,5>(instr)));
  3965. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  3966. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  3967. if(this->disass_enabled){
  3968. /* generate console output when executing the command */
  3969. auto mnemonic = fmt::format(
  3970. "{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "slti"),
  3971. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
  3972. std::vector<Value*> args {
  3973. this->core_ptr,
  3974. this->gen_const(64, pc.val),
  3975. this->builder.CreateGlobalStringPtr(mnemonic),
  3976. };
  3977. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  3978. }
  3979. Value* cur_pc_val = this->gen_const(32, pc.val);
  3980. pc=pc+4;
  3981. if(rd != 0){
  3982. Value* Xtmp0_val = this->gen_choose(
  3983. this->builder.CreateICmp(
  3984. ICmpInst::ICMP_SLT,
  3985. this->gen_ext(
  3986. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  3987. 32, true),
  3988. this->gen_const(32U, imm)),
  3989. this->gen_const(32U, 1),
  3990. this->gen_const(32U, 0),
  3991. 32);
  3992. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  3993. }
  3994. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  3995. this->gen_sync(POST_SYNC, 81);
  3996. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  3997. this->gen_trap_check(bb);
  3998. return std::make_tuple(CONT, bb);
  3999. }
  4000. /* instruction 82: SLTIU */
  4001. std::tuple<continuation_e, BasicBlock*> __sltiu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4002. bb->setName("SLTIU");
  4003. this->gen_sync(PRE_SYNC, 82);
  4004. uint8_t rd = ((bit_sub<7,5>(instr)));
  4005. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4006. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  4007. if(this->disass_enabled){
  4008. /* generate console output when executing the command */
  4009. auto mnemonic = fmt::format(
  4010. "{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "sltiu"),
  4011. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
  4012. std::vector<Value*> args {
  4013. this->core_ptr,
  4014. this->gen_const(64, pc.val),
  4015. this->builder.CreateGlobalStringPtr(mnemonic),
  4016. };
  4017. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4018. }
  4019. Value* cur_pc_val = this->gen_const(32, pc.val);
  4020. pc=pc+4;
  4021. int32_t full_imm_val = imm;
  4022. if(rd != 0){
  4023. Value* Xtmp0_val = this->gen_choose(
  4024. this->builder.CreateICmp(
  4025. ICmpInst::ICMP_ULT,
  4026. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4027. this->gen_const(32U, full_imm_val)),
  4028. this->gen_const(32U, 1),
  4029. this->gen_const(32U, 0),
  4030. 32);
  4031. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4032. }
  4033. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4034. this->gen_sync(POST_SYNC, 82);
  4035. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4036. this->gen_trap_check(bb);
  4037. return std::make_tuple(CONT, bb);
  4038. }
  4039. /* instruction 83: XORI */
  4040. std::tuple<continuation_e, BasicBlock*> __xori(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4041. bb->setName("XORI");
  4042. this->gen_sync(PRE_SYNC, 83);
  4043. uint8_t rd = ((bit_sub<7,5>(instr)));
  4044. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4045. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  4046. if(this->disass_enabled){
  4047. /* generate console output when executing the command */
  4048. auto mnemonic = fmt::format(
  4049. "{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "xori"),
  4050. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
  4051. std::vector<Value*> args {
  4052. this->core_ptr,
  4053. this->gen_const(64, pc.val),
  4054. this->builder.CreateGlobalStringPtr(mnemonic),
  4055. };
  4056. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4057. }
  4058. Value* cur_pc_val = this->gen_const(32, pc.val);
  4059. pc=pc+4;
  4060. if(rd != 0){
  4061. Value* Xtmp0_val = this->builder.CreateXor(
  4062. this->gen_ext(
  4063. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4064. 32, true),
  4065. this->gen_const(32U, imm));
  4066. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4067. }
  4068. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4069. this->gen_sync(POST_SYNC, 83);
  4070. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4071. this->gen_trap_check(bb);
  4072. return std::make_tuple(CONT, bb);
  4073. }
  4074. /* instruction 84: ORI */
  4075. std::tuple<continuation_e, BasicBlock*> __ori(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4076. bb->setName("ORI");
  4077. this->gen_sync(PRE_SYNC, 84);
  4078. uint8_t rd = ((bit_sub<7,5>(instr)));
  4079. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4080. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  4081. if(this->disass_enabled){
  4082. /* generate console output when executing the command */
  4083. auto mnemonic = fmt::format(
  4084. "{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "ori"),
  4085. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
  4086. std::vector<Value*> args {
  4087. this->core_ptr,
  4088. this->gen_const(64, pc.val),
  4089. this->builder.CreateGlobalStringPtr(mnemonic),
  4090. };
  4091. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4092. }
  4093. Value* cur_pc_val = this->gen_const(32, pc.val);
  4094. pc=pc+4;
  4095. if(rd != 0){
  4096. Value* Xtmp0_val = this->builder.CreateOr(
  4097. this->gen_ext(
  4098. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4099. 32, true),
  4100. this->gen_const(32U, imm));
  4101. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4102. }
  4103. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4104. this->gen_sync(POST_SYNC, 84);
  4105. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4106. this->gen_trap_check(bb);
  4107. return std::make_tuple(CONT, bb);
  4108. }
  4109. /* instruction 85: ANDI */
  4110. std::tuple<continuation_e, BasicBlock*> __andi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4111. bb->setName("ANDI");
  4112. this->gen_sync(PRE_SYNC, 85);
  4113. uint8_t rd = ((bit_sub<7,5>(instr)));
  4114. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4115. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  4116. if(this->disass_enabled){
  4117. /* generate console output when executing the command */
  4118. auto mnemonic = fmt::format(
  4119. "{mnemonic:10} {rd}, {rs1}, {imm}", fmt::arg("mnemonic", "andi"),
  4120. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
  4121. std::vector<Value*> args {
  4122. this->core_ptr,
  4123. this->gen_const(64, pc.val),
  4124. this->builder.CreateGlobalStringPtr(mnemonic),
  4125. };
  4126. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4127. }
  4128. Value* cur_pc_val = this->gen_const(32, pc.val);
  4129. pc=pc+4;
  4130. if(rd != 0){
  4131. Value* Xtmp0_val = this->builder.CreateAnd(
  4132. this->gen_ext(
  4133. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4134. 32, true),
  4135. this->gen_const(32U, imm));
  4136. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4137. }
  4138. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4139. this->gen_sync(POST_SYNC, 85);
  4140. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4141. this->gen_trap_check(bb);
  4142. return std::make_tuple(CONT, bb);
  4143. }
  4144. /* instruction 86: SLLI */
  4145. std::tuple<continuation_e, BasicBlock*> __slli(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4146. bb->setName("SLLI");
  4147. this->gen_sync(PRE_SYNC, 86);
  4148. uint8_t rd = ((bit_sub<7,5>(instr)));
  4149. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4150. uint8_t shamt = ((bit_sub<20,5>(instr)));
  4151. if(this->disass_enabled){
  4152. /* generate console output when executing the command */
  4153. auto mnemonic = fmt::format(
  4154. "{mnemonic:10} {rd}, {rs1}, {shamt}", fmt::arg("mnemonic", "slli"),
  4155. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("shamt", shamt));
  4156. std::vector<Value*> args {
  4157. this->core_ptr,
  4158. this->gen_const(64, pc.val),
  4159. this->builder.CreateGlobalStringPtr(mnemonic),
  4160. };
  4161. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4162. }
  4163. Value* cur_pc_val = this->gen_const(32, pc.val);
  4164. pc=pc+4;
  4165. if(shamt > 31){
  4166. this->gen_raise_trap(0, 0);
  4167. } else {
  4168. if(rd != 0){
  4169. Value* Xtmp0_val = this->builder.CreateShl(
  4170. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4171. this->gen_const(32U, shamt));
  4172. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4173. }
  4174. }
  4175. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4176. this->gen_sync(POST_SYNC, 86);
  4177. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4178. this->gen_trap_check(bb);
  4179. return std::make_tuple(CONT, bb);
  4180. }
  4181. /* instruction 87: SRLI */
  4182. std::tuple<continuation_e, BasicBlock*> __srli(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4183. bb->setName("SRLI");
  4184. this->gen_sync(PRE_SYNC, 87);
  4185. uint8_t rd = ((bit_sub<7,5>(instr)));
  4186. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4187. uint8_t shamt = ((bit_sub<20,5>(instr)));
  4188. if(this->disass_enabled){
  4189. /* generate console output when executing the command */
  4190. auto mnemonic = fmt::format(
  4191. "{mnemonic:10} {rd}, {rs1}, {shamt}", fmt::arg("mnemonic", "srli"),
  4192. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("shamt", shamt));
  4193. std::vector<Value*> args {
  4194. this->core_ptr,
  4195. this->gen_const(64, pc.val),
  4196. this->builder.CreateGlobalStringPtr(mnemonic),
  4197. };
  4198. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4199. }
  4200. Value* cur_pc_val = this->gen_const(32, pc.val);
  4201. pc=pc+4;
  4202. if(shamt > 31){
  4203. this->gen_raise_trap(0, 0);
  4204. } else {
  4205. if(rd != 0){
  4206. Value* Xtmp0_val = this->builder.CreateLShr(
  4207. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4208. this->gen_const(32U, shamt));
  4209. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4210. }
  4211. }
  4212. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4213. this->gen_sync(POST_SYNC, 87);
  4214. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4215. this->gen_trap_check(bb);
  4216. return std::make_tuple(CONT, bb);
  4217. }
  4218. /* instruction 88: SRAI */
  4219. std::tuple<continuation_e, BasicBlock*> __srai(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4220. bb->setName("SRAI");
  4221. this->gen_sync(PRE_SYNC, 88);
  4222. uint8_t rd = ((bit_sub<7,5>(instr)));
  4223. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4224. uint8_t shamt = ((bit_sub<20,5>(instr)));
  4225. if(this->disass_enabled){
  4226. /* generate console output when executing the command */
  4227. auto mnemonic = fmt::format(
  4228. "{mnemonic:10} {rd}, {rs1}, {shamt}", fmt::arg("mnemonic", "srai"),
  4229. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("shamt", shamt));
  4230. std::vector<Value*> args {
  4231. this->core_ptr,
  4232. this->gen_const(64, pc.val),
  4233. this->builder.CreateGlobalStringPtr(mnemonic),
  4234. };
  4235. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4236. }
  4237. Value* cur_pc_val = this->gen_const(32, pc.val);
  4238. pc=pc+4;
  4239. if(shamt > 31){
  4240. this->gen_raise_trap(0, 0);
  4241. } else {
  4242. if(rd != 0){
  4243. Value* Xtmp0_val = this->builder.CreateAShr(
  4244. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4245. this->gen_const(32U, shamt));
  4246. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4247. }
  4248. }
  4249. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4250. this->gen_sync(POST_SYNC, 88);
  4251. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4252. this->gen_trap_check(bb);
  4253. return std::make_tuple(CONT, bb);
  4254. }
  4255. /* instruction 89: ADD */
  4256. std::tuple<continuation_e, BasicBlock*> __add(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4257. bb->setName("ADD");
  4258. this->gen_sync(PRE_SYNC, 89);
  4259. uint8_t rd = ((bit_sub<7,5>(instr)));
  4260. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4261. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4262. if(this->disass_enabled){
  4263. /* generate console output when executing the command */
  4264. auto mnemonic = fmt::format(
  4265. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "add"),
  4266. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4267. std::vector<Value*> args {
  4268. this->core_ptr,
  4269. this->gen_const(64, pc.val),
  4270. this->builder.CreateGlobalStringPtr(mnemonic),
  4271. };
  4272. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4273. }
  4274. Value* cur_pc_val = this->gen_const(32, pc.val);
  4275. pc=pc+4;
  4276. if(rd != 0){
  4277. Value* Xtmp0_val = this->builder.CreateAdd(
  4278. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4279. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  4280. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4281. }
  4282. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4283. this->gen_sync(POST_SYNC, 89);
  4284. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4285. this->gen_trap_check(bb);
  4286. return std::make_tuple(CONT, bb);
  4287. }
  4288. /* instruction 90: SUB */
  4289. std::tuple<continuation_e, BasicBlock*> __sub(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4290. bb->setName("SUB");
  4291. this->gen_sync(PRE_SYNC, 90);
  4292. uint8_t rd = ((bit_sub<7,5>(instr)));
  4293. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4294. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4295. if(this->disass_enabled){
  4296. /* generate console output when executing the command */
  4297. auto mnemonic = fmt::format(
  4298. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sub"),
  4299. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4300. std::vector<Value*> args {
  4301. this->core_ptr,
  4302. this->gen_const(64, pc.val),
  4303. this->builder.CreateGlobalStringPtr(mnemonic),
  4304. };
  4305. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4306. }
  4307. Value* cur_pc_val = this->gen_const(32, pc.val);
  4308. pc=pc+4;
  4309. if(rd != 0){
  4310. Value* Xtmp0_val = this->builder.CreateSub(
  4311. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4312. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  4313. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4314. }
  4315. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4316. this->gen_sync(POST_SYNC, 90);
  4317. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4318. this->gen_trap_check(bb);
  4319. return std::make_tuple(CONT, bb);
  4320. }
  4321. /* instruction 91: SLL */
  4322. std::tuple<continuation_e, BasicBlock*> __sll(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4323. bb->setName("SLL");
  4324. this->gen_sync(PRE_SYNC, 91);
  4325. uint8_t rd = ((bit_sub<7,5>(instr)));
  4326. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4327. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4328. if(this->disass_enabled){
  4329. /* generate console output when executing the command */
  4330. auto mnemonic = fmt::format(
  4331. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sll"),
  4332. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4333. std::vector<Value*> args {
  4334. this->core_ptr,
  4335. this->gen_const(64, pc.val),
  4336. this->builder.CreateGlobalStringPtr(mnemonic),
  4337. };
  4338. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4339. }
  4340. Value* cur_pc_val = this->gen_const(32, pc.val);
  4341. pc=pc+4;
  4342. if(rd != 0){
  4343. Value* Xtmp0_val = this->builder.CreateShl(
  4344. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4345. this->builder.CreateAnd(
  4346. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  4347. this->builder.CreateSub(
  4348. this->gen_const(32U, 32),
  4349. this->gen_const(32U, 1))));
  4350. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4351. }
  4352. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4353. this->gen_sync(POST_SYNC, 91);
  4354. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4355. this->gen_trap_check(bb);
  4356. return std::make_tuple(CONT, bb);
  4357. }
  4358. /* instruction 92: SLT */
  4359. std::tuple<continuation_e, BasicBlock*> __slt(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4360. bb->setName("SLT");
  4361. this->gen_sync(PRE_SYNC, 92);
  4362. uint8_t rd = ((bit_sub<7,5>(instr)));
  4363. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4364. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4365. if(this->disass_enabled){
  4366. /* generate console output when executing the command */
  4367. auto mnemonic = fmt::format(
  4368. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "slt"),
  4369. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4370. std::vector<Value*> args {
  4371. this->core_ptr,
  4372. this->gen_const(64, pc.val),
  4373. this->builder.CreateGlobalStringPtr(mnemonic),
  4374. };
  4375. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4376. }
  4377. Value* cur_pc_val = this->gen_const(32, pc.val);
  4378. pc=pc+4;
  4379. if(rd != 0){
  4380. Value* Xtmp0_val = this->gen_choose(
  4381. this->builder.CreateICmp(
  4382. ICmpInst::ICMP_SLT,
  4383. this->gen_ext(
  4384. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4385. 32, true),
  4386. this->gen_ext(
  4387. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  4388. 32, true)),
  4389. this->gen_const(32U, 1),
  4390. this->gen_const(32U, 0),
  4391. 32);
  4392. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4393. }
  4394. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4395. this->gen_sync(POST_SYNC, 92);
  4396. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4397. this->gen_trap_check(bb);
  4398. return std::make_tuple(CONT, bb);
  4399. }
  4400. /* instruction 93: SLTU */
  4401. std::tuple<continuation_e, BasicBlock*> __sltu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4402. bb->setName("SLTU");
  4403. this->gen_sync(PRE_SYNC, 93);
  4404. uint8_t rd = ((bit_sub<7,5>(instr)));
  4405. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4406. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4407. if(this->disass_enabled){
  4408. /* generate console output when executing the command */
  4409. auto mnemonic = fmt::format(
  4410. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sltu"),
  4411. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4412. std::vector<Value*> args {
  4413. this->core_ptr,
  4414. this->gen_const(64, pc.val),
  4415. this->builder.CreateGlobalStringPtr(mnemonic),
  4416. };
  4417. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4418. }
  4419. Value* cur_pc_val = this->gen_const(32, pc.val);
  4420. pc=pc+4;
  4421. if(rd != 0){
  4422. Value* Xtmp0_val = this->gen_choose(
  4423. this->builder.CreateICmp(
  4424. ICmpInst::ICMP_ULT,
  4425. this->gen_ext(
  4426. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4427. 32,
  4428. false),
  4429. this->gen_ext(
  4430. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  4431. 32,
  4432. false)),
  4433. this->gen_const(32U, 1),
  4434. this->gen_const(32U, 0),
  4435. 32);
  4436. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4437. }
  4438. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4439. this->gen_sync(POST_SYNC, 93);
  4440. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4441. this->gen_trap_check(bb);
  4442. return std::make_tuple(CONT, bb);
  4443. }
  4444. /* instruction 94: XOR */
  4445. std::tuple<continuation_e, BasicBlock*> __xor(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4446. bb->setName("XOR");
  4447. this->gen_sync(PRE_SYNC, 94);
  4448. uint8_t rd = ((bit_sub<7,5>(instr)));
  4449. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4450. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4451. if(this->disass_enabled){
  4452. /* generate console output when executing the command */
  4453. auto mnemonic = fmt::format(
  4454. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "xor"),
  4455. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4456. std::vector<Value*> args {
  4457. this->core_ptr,
  4458. this->gen_const(64, pc.val),
  4459. this->builder.CreateGlobalStringPtr(mnemonic),
  4460. };
  4461. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4462. }
  4463. Value* cur_pc_val = this->gen_const(32, pc.val);
  4464. pc=pc+4;
  4465. if(rd != 0){
  4466. Value* Xtmp0_val = this->builder.CreateXor(
  4467. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4468. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  4469. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4470. }
  4471. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4472. this->gen_sync(POST_SYNC, 94);
  4473. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4474. this->gen_trap_check(bb);
  4475. return std::make_tuple(CONT, bb);
  4476. }
  4477. /* instruction 95: SRL */
  4478. std::tuple<continuation_e, BasicBlock*> __srl(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4479. bb->setName("SRL");
  4480. this->gen_sync(PRE_SYNC, 95);
  4481. uint8_t rd = ((bit_sub<7,5>(instr)));
  4482. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4483. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4484. if(this->disass_enabled){
  4485. /* generate console output when executing the command */
  4486. auto mnemonic = fmt::format(
  4487. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "srl"),
  4488. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4489. std::vector<Value*> args {
  4490. this->core_ptr,
  4491. this->gen_const(64, pc.val),
  4492. this->builder.CreateGlobalStringPtr(mnemonic),
  4493. };
  4494. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4495. }
  4496. Value* cur_pc_val = this->gen_const(32, pc.val);
  4497. pc=pc+4;
  4498. if(rd != 0){
  4499. Value* Xtmp0_val = this->builder.CreateLShr(
  4500. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4501. this->builder.CreateAnd(
  4502. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  4503. this->builder.CreateSub(
  4504. this->gen_const(32U, 32),
  4505. this->gen_const(32U, 1))));
  4506. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4507. }
  4508. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4509. this->gen_sync(POST_SYNC, 95);
  4510. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4511. this->gen_trap_check(bb);
  4512. return std::make_tuple(CONT, bb);
  4513. }
  4514. /* instruction 96: SRA */
  4515. std::tuple<continuation_e, BasicBlock*> __sra(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4516. bb->setName("SRA");
  4517. this->gen_sync(PRE_SYNC, 96);
  4518. uint8_t rd = ((bit_sub<7,5>(instr)));
  4519. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4520. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4521. if(this->disass_enabled){
  4522. /* generate console output when executing the command */
  4523. auto mnemonic = fmt::format(
  4524. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sra"),
  4525. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4526. std::vector<Value*> args {
  4527. this->core_ptr,
  4528. this->gen_const(64, pc.val),
  4529. this->builder.CreateGlobalStringPtr(mnemonic),
  4530. };
  4531. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4532. }
  4533. Value* cur_pc_val = this->gen_const(32, pc.val);
  4534. pc=pc+4;
  4535. if(rd != 0){
  4536. Value* Xtmp0_val = this->builder.CreateAShr(
  4537. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4538. this->builder.CreateAnd(
  4539. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  4540. this->builder.CreateSub(
  4541. this->gen_const(32U, 32),
  4542. this->gen_const(32U, 1))));
  4543. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4544. }
  4545. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4546. this->gen_sync(POST_SYNC, 96);
  4547. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4548. this->gen_trap_check(bb);
  4549. return std::make_tuple(CONT, bb);
  4550. }
  4551. /* instruction 97: OR */
  4552. std::tuple<continuation_e, BasicBlock*> __or(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4553. bb->setName("OR");
  4554. this->gen_sync(PRE_SYNC, 97);
  4555. uint8_t rd = ((bit_sub<7,5>(instr)));
  4556. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4557. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4558. if(this->disass_enabled){
  4559. /* generate console output when executing the command */
  4560. auto mnemonic = fmt::format(
  4561. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "or"),
  4562. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4563. std::vector<Value*> args {
  4564. this->core_ptr,
  4565. this->gen_const(64, pc.val),
  4566. this->builder.CreateGlobalStringPtr(mnemonic),
  4567. };
  4568. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4569. }
  4570. Value* cur_pc_val = this->gen_const(32, pc.val);
  4571. pc=pc+4;
  4572. if(rd != 0){
  4573. Value* Xtmp0_val = this->builder.CreateOr(
  4574. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4575. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  4576. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4577. }
  4578. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4579. this->gen_sync(POST_SYNC, 97);
  4580. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4581. this->gen_trap_check(bb);
  4582. return std::make_tuple(CONT, bb);
  4583. }
  4584. /* instruction 98: AND */
  4585. std::tuple<continuation_e, BasicBlock*> __and(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4586. bb->setName("AND");
  4587. this->gen_sync(PRE_SYNC, 98);
  4588. uint8_t rd = ((bit_sub<7,5>(instr)));
  4589. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4590. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4591. if(this->disass_enabled){
  4592. /* generate console output when executing the command */
  4593. auto mnemonic = fmt::format(
  4594. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "and"),
  4595. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  4596. std::vector<Value*> args {
  4597. this->core_ptr,
  4598. this->gen_const(64, pc.val),
  4599. this->builder.CreateGlobalStringPtr(mnemonic),
  4600. };
  4601. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4602. }
  4603. Value* cur_pc_val = this->gen_const(32, pc.val);
  4604. pc=pc+4;
  4605. if(rd != 0){
  4606. Value* Xtmp0_val = this->builder.CreateAnd(
  4607. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  4608. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  4609. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4610. }
  4611. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4612. this->gen_sync(POST_SYNC, 98);
  4613. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4614. this->gen_trap_check(bb);
  4615. return std::make_tuple(CONT, bb);
  4616. }
  4617. /* instruction 99: FENCE */
  4618. std::tuple<continuation_e, BasicBlock*> __fence(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4619. bb->setName("FENCE");
  4620. this->gen_sync(PRE_SYNC, 99);
  4621. uint8_t rd = ((bit_sub<7,5>(instr)));
  4622. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4623. uint8_t succ = ((bit_sub<20,4>(instr)));
  4624. uint8_t pred = ((bit_sub<24,4>(instr)));
  4625. if(this->disass_enabled){
  4626. /* generate console output when executing the command */
  4627. std::vector<Value*> args {
  4628. this->core_ptr,
  4629. this->gen_const(64, pc.val),
  4630. this->builder.CreateGlobalStringPtr("fence"),
  4631. };
  4632. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4633. }
  4634. Value* cur_pc_val = this->gen_const(32, pc.val);
  4635. pc=pc+4;
  4636. Value* FENCEtmp0_val = this->builder.CreateOr(
  4637. this->builder.CreateShl(
  4638. this->gen_const(32U, pred),
  4639. this->gen_const(32U, 4)),
  4640. this->gen_const(32U, succ));
  4641. this->gen_write_mem(
  4642. traits<ARCH>::FENCE,
  4643. this->gen_const(64U, 0),
  4644. this->builder.CreateZExtOrTrunc(FENCEtmp0_val,this->get_type(32)));
  4645. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4646. this->gen_sync(POST_SYNC, 99);
  4647. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4648. this->gen_trap_check(bb);
  4649. return std::make_tuple(CONT, bb);
  4650. }
  4651. /* instruction 100: FENCE_I */
  4652. std::tuple<continuation_e, BasicBlock*> __fence_i(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4653. bb->setName("FENCE_I");
  4654. this->gen_sync(PRE_SYNC, 100);
  4655. uint8_t rd = ((bit_sub<7,5>(instr)));
  4656. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4657. uint16_t imm = ((bit_sub<20,12>(instr)));
  4658. if(this->disass_enabled){
  4659. /* generate console output when executing the command */
  4660. std::vector<Value*> args {
  4661. this->core_ptr,
  4662. this->gen_const(64, pc.val),
  4663. this->builder.CreateGlobalStringPtr("fence_i"),
  4664. };
  4665. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4666. }
  4667. Value* cur_pc_val = this->gen_const(32, pc.val);
  4668. pc=pc+4;
  4669. Value* FENCEtmp0_val = this->gen_const(32U, imm);
  4670. this->gen_write_mem(
  4671. traits<ARCH>::FENCE,
  4672. this->gen_const(64U, 1),
  4673. this->builder.CreateZExtOrTrunc(FENCEtmp0_val,this->get_type(32)));
  4674. this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  4675. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4676. this->gen_sync(POST_SYNC, 100);
  4677. this->gen_trap_check(this->leave_blk);
  4678. return std::make_tuple(FLUSH, nullptr);
  4679. }
  4680. /* instruction 101: ECALL */
  4681. std::tuple<continuation_e, BasicBlock*> __ecall(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4682. bb->setName("ECALL");
  4683. this->gen_sync(PRE_SYNC, 101);
  4684. if(this->disass_enabled){
  4685. /* generate console output when executing the command */
  4686. std::vector<Value*> args {
  4687. this->core_ptr,
  4688. this->gen_const(64, pc.val),
  4689. this->builder.CreateGlobalStringPtr("ecall"),
  4690. };
  4691. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4692. }
  4693. Value* cur_pc_val = this->gen_const(32, pc.val);
  4694. pc=pc+4;
  4695. this->gen_raise_trap(0, 11);
  4696. this->gen_sync(POST_SYNC, 101);
  4697. this->gen_trap_check(this->leave_blk);
  4698. return std::make_tuple(BRANCH, nullptr);
  4699. }
  4700. /* instruction 102: EBREAK */
  4701. std::tuple<continuation_e, BasicBlock*> __ebreak(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4702. bb->setName("EBREAK");
  4703. this->gen_sync(PRE_SYNC, 102);
  4704. if(this->disass_enabled){
  4705. /* generate console output when executing the command */
  4706. std::vector<Value*> args {
  4707. this->core_ptr,
  4708. this->gen_const(64, pc.val),
  4709. this->builder.CreateGlobalStringPtr("ebreak"),
  4710. };
  4711. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4712. }
  4713. Value* cur_pc_val = this->gen_const(32, pc.val);
  4714. pc=pc+4;
  4715. this->gen_raise_trap(0, 3);
  4716. this->gen_sync(POST_SYNC, 102);
  4717. this->gen_trap_check(this->leave_blk);
  4718. return std::make_tuple(BRANCH, nullptr);
  4719. }
  4720. /* instruction 103: URET */
  4721. std::tuple<continuation_e, BasicBlock*> __uret(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4722. bb->setName("URET");
  4723. this->gen_sync(PRE_SYNC, 103);
  4724. if(this->disass_enabled){
  4725. /* generate console output when executing the command */
  4726. std::vector<Value*> args {
  4727. this->core_ptr,
  4728. this->gen_const(64, pc.val),
  4729. this->builder.CreateGlobalStringPtr("uret"),
  4730. };
  4731. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4732. }
  4733. Value* cur_pc_val = this->gen_const(32, pc.val);
  4734. pc=pc+4;
  4735. this->gen_leave_trap(0);
  4736. this->gen_sync(POST_SYNC, 103);
  4737. this->gen_trap_check(this->leave_blk);
  4738. return std::make_tuple(BRANCH, nullptr);
  4739. }
  4740. /* instruction 104: SRET */
  4741. std::tuple<continuation_e, BasicBlock*> __sret(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4742. bb->setName("SRET");
  4743. this->gen_sync(PRE_SYNC, 104);
  4744. if(this->disass_enabled){
  4745. /* generate console output when executing the command */
  4746. std::vector<Value*> args {
  4747. this->core_ptr,
  4748. this->gen_const(64, pc.val),
  4749. this->builder.CreateGlobalStringPtr("sret"),
  4750. };
  4751. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4752. }
  4753. Value* cur_pc_val = this->gen_const(32, pc.val);
  4754. pc=pc+4;
  4755. this->gen_leave_trap(1);
  4756. this->gen_sync(POST_SYNC, 104);
  4757. this->gen_trap_check(this->leave_blk);
  4758. return std::make_tuple(BRANCH, nullptr);
  4759. }
  4760. /* instruction 105: MRET */
  4761. std::tuple<continuation_e, BasicBlock*> __mret(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4762. bb->setName("MRET");
  4763. this->gen_sync(PRE_SYNC, 105);
  4764. if(this->disass_enabled){
  4765. /* generate console output when executing the command */
  4766. std::vector<Value*> args {
  4767. this->core_ptr,
  4768. this->gen_const(64, pc.val),
  4769. this->builder.CreateGlobalStringPtr("mret"),
  4770. };
  4771. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4772. }
  4773. Value* cur_pc_val = this->gen_const(32, pc.val);
  4774. pc=pc+4;
  4775. this->gen_leave_trap(3);
  4776. this->gen_sync(POST_SYNC, 105);
  4777. this->gen_trap_check(this->leave_blk);
  4778. return std::make_tuple(BRANCH, nullptr);
  4779. }
  4780. /* instruction 106: WFI */
  4781. std::tuple<continuation_e, BasicBlock*> __wfi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4782. bb->setName("WFI");
  4783. this->gen_sync(PRE_SYNC, 106);
  4784. if(this->disass_enabled){
  4785. /* generate console output when executing the command */
  4786. std::vector<Value*> args {
  4787. this->core_ptr,
  4788. this->gen_const(64, pc.val),
  4789. this->builder.CreateGlobalStringPtr("wfi"),
  4790. };
  4791. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4792. }
  4793. Value* cur_pc_val = this->gen_const(32, pc.val);
  4794. pc=pc+4;
  4795. this->gen_wait(1);
  4796. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4797. this->gen_sync(POST_SYNC, 106);
  4798. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4799. this->gen_trap_check(bb);
  4800. return std::make_tuple(CONT, bb);
  4801. }
  4802. /* instruction 107: SFENCE.VMA */
  4803. std::tuple<continuation_e, BasicBlock*> __sfence_vma(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4804. bb->setName("SFENCE.VMA");
  4805. this->gen_sync(PRE_SYNC, 107);
  4806. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4807. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  4808. if(this->disass_enabled){
  4809. /* generate console output when executing the command */
  4810. std::vector<Value*> args {
  4811. this->core_ptr,
  4812. this->gen_const(64, pc.val),
  4813. this->builder.CreateGlobalStringPtr("sfence.vma"),
  4814. };
  4815. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4816. }
  4817. Value* cur_pc_val = this->gen_const(32, pc.val);
  4818. pc=pc+4;
  4819. Value* FENCEtmp0_val = this->gen_const(32U, rs1);
  4820. this->gen_write_mem(
  4821. traits<ARCH>::FENCE,
  4822. this->gen_const(64U, 2),
  4823. this->builder.CreateZExtOrTrunc(FENCEtmp0_val,this->get_type(32)));
  4824. Value* FENCEtmp1_val = this->gen_const(32U, rs2);
  4825. this->gen_write_mem(
  4826. traits<ARCH>::FENCE,
  4827. this->gen_const(64U, 3),
  4828. this->builder.CreateZExtOrTrunc(FENCEtmp1_val,this->get_type(32)));
  4829. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4830. this->gen_sync(POST_SYNC, 107);
  4831. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4832. this->gen_trap_check(bb);
  4833. return std::make_tuple(CONT, bb);
  4834. }
  4835. /* instruction 108: CSRRW */
  4836. std::tuple<continuation_e, BasicBlock*> __csrrw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4837. bb->setName("CSRRW");
  4838. this->gen_sync(PRE_SYNC, 108);
  4839. uint8_t rd = ((bit_sub<7,5>(instr)));
  4840. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4841. uint16_t csr = ((bit_sub<20,12>(instr)));
  4842. if(this->disass_enabled){
  4843. /* generate console output when executing the command */
  4844. auto mnemonic = fmt::format(
  4845. "{mnemonic:10} {rd}, {csr}, {rs1}", fmt::arg("mnemonic", "csrrw"),
  4846. fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("rs1", name(rs1)));
  4847. std::vector<Value*> args {
  4848. this->core_ptr,
  4849. this->gen_const(64, pc.val),
  4850. this->builder.CreateGlobalStringPtr(mnemonic),
  4851. };
  4852. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4853. }
  4854. Value* cur_pc_val = this->gen_const(32, pc.val);
  4855. pc=pc+4;
  4856. Value* rs_val_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  4857. if(rd != 0){
  4858. Value* csr_val_val = this->gen_read_mem(traits<ARCH>::CSR, this->gen_const(16U, csr), 32/8);
  4859. Value* CSRtmp0_val = rs_val_val;
  4860. this->gen_write_mem(
  4861. traits<ARCH>::CSR,
  4862. this->gen_const(16U, csr),
  4863. this->builder.CreateZExtOrTrunc(CSRtmp0_val,this->get_type(32)));
  4864. Value* Xtmp1_val = csr_val_val;
  4865. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4866. } else {
  4867. Value* CSRtmp2_val = rs_val_val;
  4868. this->gen_write_mem(
  4869. traits<ARCH>::CSR,
  4870. this->gen_const(16U, csr),
  4871. this->builder.CreateZExtOrTrunc(CSRtmp2_val,this->get_type(32)));
  4872. }
  4873. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4874. this->gen_sync(POST_SYNC, 108);
  4875. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4876. this->gen_trap_check(bb);
  4877. return std::make_tuple(CONT, bb);
  4878. }
  4879. /* instruction 109: CSRRS */
  4880. std::tuple<continuation_e, BasicBlock*> __csrrs(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4881. bb->setName("CSRRS");
  4882. this->gen_sync(PRE_SYNC, 109);
  4883. uint8_t rd = ((bit_sub<7,5>(instr)));
  4884. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4885. uint16_t csr = ((bit_sub<20,12>(instr)));
  4886. if(this->disass_enabled){
  4887. /* generate console output when executing the command */
  4888. auto mnemonic = fmt::format(
  4889. "{mnemonic:10} {rd}, {csr}, {rs1}", fmt::arg("mnemonic", "csrrs"),
  4890. fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("rs1", name(rs1)));
  4891. std::vector<Value*> args {
  4892. this->core_ptr,
  4893. this->gen_const(64, pc.val),
  4894. this->builder.CreateGlobalStringPtr(mnemonic),
  4895. };
  4896. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4897. }
  4898. Value* cur_pc_val = this->gen_const(32, pc.val);
  4899. pc=pc+4;
  4900. Value* xrd_val = this->gen_read_mem(traits<ARCH>::CSR, this->gen_const(16U, csr), 32/8);
  4901. Value* xrs1_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  4902. if(rd != 0){
  4903. Value* Xtmp0_val = xrd_val;
  4904. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4905. }
  4906. if(rs1 != 0){
  4907. Value* CSRtmp1_val = this->builder.CreateOr(
  4908. xrd_val,
  4909. xrs1_val);
  4910. this->gen_write_mem(
  4911. traits<ARCH>::CSR,
  4912. this->gen_const(16U, csr),
  4913. this->builder.CreateZExtOrTrunc(CSRtmp1_val,this->get_type(32)));
  4914. }
  4915. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4916. this->gen_sync(POST_SYNC, 109);
  4917. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4918. this->gen_trap_check(bb);
  4919. return std::make_tuple(CONT, bb);
  4920. }
  4921. /* instruction 110: CSRRC */
  4922. std::tuple<continuation_e, BasicBlock*> __csrrc(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4923. bb->setName("CSRRC");
  4924. this->gen_sync(PRE_SYNC, 110);
  4925. uint8_t rd = ((bit_sub<7,5>(instr)));
  4926. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  4927. uint16_t csr = ((bit_sub<20,12>(instr)));
  4928. if(this->disass_enabled){
  4929. /* generate console output when executing the command */
  4930. auto mnemonic = fmt::format(
  4931. "{mnemonic:10} {rd}, {csr}, {rs1}", fmt::arg("mnemonic", "csrrc"),
  4932. fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("rs1", name(rs1)));
  4933. std::vector<Value*> args {
  4934. this->core_ptr,
  4935. this->gen_const(64, pc.val),
  4936. this->builder.CreateGlobalStringPtr(mnemonic),
  4937. };
  4938. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4939. }
  4940. Value* cur_pc_val = this->gen_const(32, pc.val);
  4941. pc=pc+4;
  4942. Value* xrd_val = this->gen_read_mem(traits<ARCH>::CSR, this->gen_const(16U, csr), 32/8);
  4943. Value* xrs1_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  4944. if(rd != 0){
  4945. Value* Xtmp0_val = xrd_val;
  4946. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4947. }
  4948. if(rs1 != 0){
  4949. Value* CSRtmp1_val = this->builder.CreateAnd(
  4950. xrd_val,
  4951. this->builder.CreateNot(xrs1_val));
  4952. this->gen_write_mem(
  4953. traits<ARCH>::CSR,
  4954. this->gen_const(16U, csr),
  4955. this->builder.CreateZExtOrTrunc(CSRtmp1_val,this->get_type(32)));
  4956. }
  4957. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4958. this->gen_sync(POST_SYNC, 110);
  4959. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4960. this->gen_trap_check(bb);
  4961. return std::make_tuple(CONT, bb);
  4962. }
  4963. /* instruction 111: CSRRWI */
  4964. std::tuple<continuation_e, BasicBlock*> __csrrwi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  4965. bb->setName("CSRRWI");
  4966. this->gen_sync(PRE_SYNC, 111);
  4967. uint8_t rd = ((bit_sub<7,5>(instr)));
  4968. uint8_t zimm = ((bit_sub<15,5>(instr)));
  4969. uint16_t csr = ((bit_sub<20,12>(instr)));
  4970. if(this->disass_enabled){
  4971. /* generate console output when executing the command */
  4972. auto mnemonic = fmt::format(
  4973. "{mnemonic:10} {rd}, {csr}, {zimm:#0x}", fmt::arg("mnemonic", "csrrwi"),
  4974. fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("zimm", zimm));
  4975. std::vector<Value*> args {
  4976. this->core_ptr,
  4977. this->gen_const(64, pc.val),
  4978. this->builder.CreateGlobalStringPtr(mnemonic),
  4979. };
  4980. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  4981. }
  4982. Value* cur_pc_val = this->gen_const(32, pc.val);
  4983. pc=pc+4;
  4984. if(rd != 0){
  4985. Value* Xtmp0_val = this->gen_read_mem(traits<ARCH>::CSR, this->gen_const(16U, csr), 32/8);
  4986. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  4987. }
  4988. Value* CSRtmp1_val = this->gen_ext(
  4989. this->gen_const(32U, zimm),
  4990. 32,
  4991. false);
  4992. this->gen_write_mem(
  4993. traits<ARCH>::CSR,
  4994. this->gen_const(16U, csr),
  4995. this->builder.CreateZExtOrTrunc(CSRtmp1_val,this->get_type(32)));
  4996. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  4997. this->gen_sync(POST_SYNC, 111);
  4998. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  4999. this->gen_trap_check(bb);
  5000. return std::make_tuple(CONT, bb);
  5001. }
  5002. /* instruction 112: CSRRSI */
  5003. std::tuple<continuation_e, BasicBlock*> __csrrsi(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5004. bb->setName("CSRRSI");
  5005. this->gen_sync(PRE_SYNC, 112);
  5006. uint8_t rd = ((bit_sub<7,5>(instr)));
  5007. uint8_t zimm = ((bit_sub<15,5>(instr)));
  5008. uint16_t csr = ((bit_sub<20,12>(instr)));
  5009. if(this->disass_enabled){
  5010. /* generate console output when executing the command */
  5011. auto mnemonic = fmt::format(
  5012. "{mnemonic:10} {rd}, {csr}, {zimm:#0x}", fmt::arg("mnemonic", "csrrsi"),
  5013. fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("zimm", zimm));
  5014. std::vector<Value*> args {
  5015. this->core_ptr,
  5016. this->gen_const(64, pc.val),
  5017. this->builder.CreateGlobalStringPtr(mnemonic),
  5018. };
  5019. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5020. }
  5021. Value* cur_pc_val = this->gen_const(32, pc.val);
  5022. pc=pc+4;
  5023. Value* res_val = this->gen_read_mem(traits<ARCH>::CSR, this->gen_const(16U, csr), 32/8);
  5024. if(zimm != 0){
  5025. Value* CSRtmp0_val = this->builder.CreateOr(
  5026. res_val,
  5027. this->gen_ext(
  5028. this->gen_const(32U, zimm),
  5029. 32,
  5030. false));
  5031. this->gen_write_mem(
  5032. traits<ARCH>::CSR,
  5033. this->gen_const(16U, csr),
  5034. this->builder.CreateZExtOrTrunc(CSRtmp0_val,this->get_type(32)));
  5035. }
  5036. if(rd != 0){
  5037. Value* Xtmp1_val = res_val;
  5038. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  5039. }
  5040. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5041. this->gen_sync(POST_SYNC, 112);
  5042. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5043. this->gen_trap_check(bb);
  5044. return std::make_tuple(CONT, bb);
  5045. }
  5046. /* instruction 113: CSRRCI */
  5047. std::tuple<continuation_e, BasicBlock*> __csrrci(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5048. bb->setName("CSRRCI");
  5049. this->gen_sync(PRE_SYNC, 113);
  5050. uint8_t rd = ((bit_sub<7,5>(instr)));
  5051. uint8_t zimm = ((bit_sub<15,5>(instr)));
  5052. uint16_t csr = ((bit_sub<20,12>(instr)));
  5053. if(this->disass_enabled){
  5054. /* generate console output when executing the command */
  5055. auto mnemonic = fmt::format(
  5056. "{mnemonic:10} {rd}, {csr}, {zimm:#0x}", fmt::arg("mnemonic", "csrrci"),
  5057. fmt::arg("rd", name(rd)), fmt::arg("csr", csr), fmt::arg("zimm", zimm));
  5058. std::vector<Value*> args {
  5059. this->core_ptr,
  5060. this->gen_const(64, pc.val),
  5061. this->builder.CreateGlobalStringPtr(mnemonic),
  5062. };
  5063. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5064. }
  5065. Value* cur_pc_val = this->gen_const(32, pc.val);
  5066. pc=pc+4;
  5067. Value* res_val = this->gen_read_mem(traits<ARCH>::CSR, this->gen_const(16U, csr), 32/8);
  5068. if(rd != 0){
  5069. Value* Xtmp0_val = res_val;
  5070. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  5071. }
  5072. if(zimm != 0){
  5073. Value* CSRtmp1_val = this->builder.CreateAnd(
  5074. res_val,
  5075. this->builder.CreateNot(this->gen_ext(
  5076. this->gen_const(32U, zimm),
  5077. 32,
  5078. false)));
  5079. this->gen_write_mem(
  5080. traits<ARCH>::CSR,
  5081. this->gen_const(16U, csr),
  5082. this->builder.CreateZExtOrTrunc(CSRtmp1_val,this->get_type(32)));
  5083. }
  5084. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5085. this->gen_sync(POST_SYNC, 113);
  5086. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5087. this->gen_trap_check(bb);
  5088. return std::make_tuple(CONT, bb);
  5089. }
  5090. /* instruction 114: FLW */
  5091. std::tuple<continuation_e, BasicBlock*> __flw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5092. bb->setName("FLW");
  5093. this->gen_sync(PRE_SYNC, 114);
  5094. uint8_t rd = ((bit_sub<7,5>(instr)));
  5095. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5096. int16_t imm = signextend<int16_t,12>((bit_sub<20,12>(instr)));
  5097. if(this->disass_enabled){
  5098. /* generate console output when executing the command */
  5099. auto mnemonic = fmt::format(
  5100. "{mnemonic:10} f{rd}, {imm}(x{rs1})", fmt::arg("mnemonic", "flw"),
  5101. fmt::arg("rd", rd), fmt::arg("imm", imm), fmt::arg("rs1", rs1));
  5102. std::vector<Value*> args {
  5103. this->core_ptr,
  5104. this->gen_const(64, pc.val),
  5105. this->builder.CreateGlobalStringPtr(mnemonic),
  5106. };
  5107. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5108. }
  5109. Value* cur_pc_val = this->gen_const(32, pc.val);
  5110. pc=pc+4;
  5111. Value* offs_val = this->builder.CreateAdd(
  5112. this->gen_ext(
  5113. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  5114. 32, true),
  5115. this->gen_const(32U, imm));
  5116. Value* res_val = this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8);
  5117. if(64 == 32){
  5118. Value* Ftmp0_val = res_val;
  5119. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5120. } else {
  5121. uint64_t upper_val = - 1;
  5122. Value* Ftmp1_val = this->builder.CreateOr(
  5123. this->builder.CreateShl(
  5124. this->gen_const(64U, upper_val),
  5125. this->gen_const(64U, 32)),
  5126. this->gen_ext(
  5127. res_val,
  5128. 64,
  5129. false));
  5130. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5131. }
  5132. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5133. this->gen_sync(POST_SYNC, 114);
  5134. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5135. this->gen_trap_check(bb);
  5136. return std::make_tuple(CONT, bb);
  5137. }
  5138. /* instruction 115: FSW */
  5139. std::tuple<continuation_e, BasicBlock*> __fsw(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5140. bb->setName("FSW");
  5141. this->gen_sync(PRE_SYNC, 115);
  5142. int16_t imm = signextend<int16_t,12>((bit_sub<7,5>(instr)) | (bit_sub<25,7>(instr) << 5));
  5143. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5144. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5145. if(this->disass_enabled){
  5146. /* generate console output when executing the command */
  5147. auto mnemonic = fmt::format(
  5148. "{mnemonic:10} f{rs2}, {imm}(x{rs1})", fmt::arg("mnemonic", "fsw"),
  5149. fmt::arg("rs2", rs2), fmt::arg("imm", imm), fmt::arg("rs1", rs1));
  5150. std::vector<Value*> args {
  5151. this->core_ptr,
  5152. this->gen_const(64, pc.val),
  5153. this->builder.CreateGlobalStringPtr(mnemonic),
  5154. };
  5155. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5156. }
  5157. Value* cur_pc_val = this->gen_const(32, pc.val);
  5158. pc=pc+4;
  5159. Value* offs_val = this->builder.CreateAdd(
  5160. this->gen_ext(
  5161. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  5162. 32, true),
  5163. this->gen_const(32U, imm));
  5164. Value* MEMtmp0_val = this->builder.CreateTrunc(
  5165. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5166. this-> get_type(32)
  5167. );
  5168. this->gen_write_mem(
  5169. traits<ARCH>::MEM,
  5170. offs_val,
  5171. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(32)));
  5172. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5173. this->gen_sync(POST_SYNC, 115);
  5174. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5175. this->gen_trap_check(bb);
  5176. return std::make_tuple(CONT, bb);
  5177. }
  5178. /* instruction 116: FMADD.S */
  5179. std::tuple<continuation_e, BasicBlock*> __fmadd_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5180. bb->setName("FMADD.S");
  5181. this->gen_sync(PRE_SYNC, 116);
  5182. uint8_t rd = ((bit_sub<7,5>(instr)));
  5183. uint8_t rm = ((bit_sub<12,3>(instr)));
  5184. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5185. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5186. uint8_t rs3 = ((bit_sub<27,5>(instr)));
  5187. if(this->disass_enabled){
  5188. /* generate console output when executing the command */
  5189. auto mnemonic = fmt::format(
  5190. "{mnemonic:10} x{rd}, f{rs1}, f{rs2}, f{rs3}", fmt::arg("mnemonic", "fmadd.s"),
  5191. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2), fmt::arg("rs3", rs3));
  5192. std::vector<Value*> args {
  5193. this->core_ptr,
  5194. this->gen_const(64, pc.val),
  5195. this->builder.CreateGlobalStringPtr(mnemonic),
  5196. };
  5197. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5198. }
  5199. Value* cur_pc_val = this->gen_const(32, pc.val);
  5200. pc=pc+4;
  5201. if(64 == 32){
  5202. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fmadd_s"), std::vector<Value*>{
  5203. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5204. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5205. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0),
  5206. this->gen_ext(
  5207. this->gen_const(64U, 0LL),
  5208. 32,
  5209. false),
  5210. this->gen_choose(
  5211. this->builder.CreateICmp(
  5212. ICmpInst::ICMP_ULT,
  5213. this->gen_const(8U, rm),
  5214. this->gen_const(8U, 7)),
  5215. this->gen_const(8U, rm),
  5216. this->builder.CreateTrunc(
  5217. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5218. this-> get_type(8)
  5219. ),
  5220. 8)
  5221. });
  5222. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5223. } else {
  5224. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5225. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5226. });
  5227. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5228. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  5229. });
  5230. Value* frs3_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5231. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0)
  5232. });
  5233. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmadd_s"), std::vector<Value*>{
  5234. frs1_val,
  5235. frs2_val,
  5236. frs3_val,
  5237. this->gen_ext(
  5238. this->gen_const(64U, 0LL),
  5239. 32,
  5240. false),
  5241. this->gen_choose(
  5242. this->builder.CreateICmp(
  5243. ICmpInst::ICMP_ULT,
  5244. this->gen_const(8U, rm),
  5245. this->gen_const(8U, 7)),
  5246. this->gen_const(8U, rm),
  5247. this->builder.CreateTrunc(
  5248. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5249. this-> get_type(8)
  5250. ),
  5251. 8)
  5252. });
  5253. uint64_t upper_val = - 1;
  5254. Value* Ftmp1_val = this->builder.CreateOr(
  5255. this->builder.CreateShl(
  5256. this->gen_const(64U, upper_val),
  5257. this->gen_const(64U, 32)),
  5258. this->gen_ext(
  5259. res_val,
  5260. 64,
  5261. false));
  5262. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5263. }
  5264. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5265. });
  5266. Value* FCSR_val = this->builder.CreateAdd(
  5267. this->builder.CreateAnd(
  5268. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5269. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5270. flags_val);
  5271. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5272. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5273. this->gen_sync(POST_SYNC, 116);
  5274. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5275. this->gen_trap_check(bb);
  5276. return std::make_tuple(CONT, bb);
  5277. }
  5278. /* instruction 117: FMSUB.S */
  5279. std::tuple<continuation_e, BasicBlock*> __fmsub_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5280. bb->setName("FMSUB.S");
  5281. this->gen_sync(PRE_SYNC, 117);
  5282. uint8_t rd = ((bit_sub<7,5>(instr)));
  5283. uint8_t rm = ((bit_sub<12,3>(instr)));
  5284. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5285. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5286. uint8_t rs3 = ((bit_sub<27,5>(instr)));
  5287. if(this->disass_enabled){
  5288. /* generate console output when executing the command */
  5289. auto mnemonic = fmt::format(
  5290. "{mnemonic:10} x{rd}, f{rs1}, f{rs2}, f{rs3}", fmt::arg("mnemonic", "fmsub.s"),
  5291. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2), fmt::arg("rs3", rs3));
  5292. std::vector<Value*> args {
  5293. this->core_ptr,
  5294. this->gen_const(64, pc.val),
  5295. this->builder.CreateGlobalStringPtr(mnemonic),
  5296. };
  5297. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5298. }
  5299. Value* cur_pc_val = this->gen_const(32, pc.val);
  5300. pc=pc+4;
  5301. if(64 == 32){
  5302. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fmadd_s"), std::vector<Value*>{
  5303. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5304. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5305. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0),
  5306. this->gen_ext(
  5307. this->gen_const(64U, 1LL),
  5308. 32,
  5309. false),
  5310. this->gen_choose(
  5311. this->builder.CreateICmp(
  5312. ICmpInst::ICMP_ULT,
  5313. this->gen_const(8U, rm),
  5314. this->gen_const(8U, 7)),
  5315. this->gen_const(8U, rm),
  5316. this->builder.CreateTrunc(
  5317. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5318. this-> get_type(8)
  5319. ),
  5320. 8)
  5321. });
  5322. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5323. } else {
  5324. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5325. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5326. });
  5327. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5328. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  5329. });
  5330. Value* frs3_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5331. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0)
  5332. });
  5333. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmadd_s"), std::vector<Value*>{
  5334. frs1_val,
  5335. frs2_val,
  5336. frs3_val,
  5337. this->gen_ext(
  5338. this->gen_const(64U, 1LL),
  5339. 32,
  5340. false),
  5341. this->gen_choose(
  5342. this->builder.CreateICmp(
  5343. ICmpInst::ICMP_ULT,
  5344. this->gen_const(8U, rm),
  5345. this->gen_const(8U, 7)),
  5346. this->gen_const(8U, rm),
  5347. this->builder.CreateTrunc(
  5348. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5349. this-> get_type(8)
  5350. ),
  5351. 8)
  5352. });
  5353. uint64_t upper_val = - 1;
  5354. Value* Ftmp1_val = this->builder.CreateOr(
  5355. this->builder.CreateShl(
  5356. this->gen_const(64U, upper_val),
  5357. this->gen_const(64U, 32)),
  5358. this->gen_ext(
  5359. res_val,
  5360. 64,
  5361. false));
  5362. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5363. }
  5364. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5365. });
  5366. Value* FCSR_val = this->builder.CreateAdd(
  5367. this->builder.CreateAnd(
  5368. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5369. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5370. flags_val);
  5371. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5372. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5373. this->gen_sync(POST_SYNC, 117);
  5374. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5375. this->gen_trap_check(bb);
  5376. return std::make_tuple(CONT, bb);
  5377. }
  5378. /* instruction 118: FNMADD.S */
  5379. std::tuple<continuation_e, BasicBlock*> __fnmadd_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5380. bb->setName("FNMADD.S");
  5381. this->gen_sync(PRE_SYNC, 118);
  5382. uint8_t rd = ((bit_sub<7,5>(instr)));
  5383. uint8_t rm = ((bit_sub<12,3>(instr)));
  5384. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5385. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5386. uint8_t rs3 = ((bit_sub<27,5>(instr)));
  5387. if(this->disass_enabled){
  5388. /* generate console output when executing the command */
  5389. auto mnemonic = fmt::format(
  5390. "{mnemonic:10} x{rd}, f{rs1}, f{rs2}, f{rs3}", fmt::arg("mnemonic", "fnmadd.s"),
  5391. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2), fmt::arg("rs3", rs3));
  5392. std::vector<Value*> args {
  5393. this->core_ptr,
  5394. this->gen_const(64, pc.val),
  5395. this->builder.CreateGlobalStringPtr(mnemonic),
  5396. };
  5397. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5398. }
  5399. Value* cur_pc_val = this->gen_const(32, pc.val);
  5400. pc=pc+4;
  5401. if(64 == 32){
  5402. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fmadd_s"), std::vector<Value*>{
  5403. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5404. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5405. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0),
  5406. this->gen_ext(
  5407. this->gen_const(64U, 2LL),
  5408. 32,
  5409. false),
  5410. this->gen_choose(
  5411. this->builder.CreateICmp(
  5412. ICmpInst::ICMP_ULT,
  5413. this->gen_const(8U, rm),
  5414. this->gen_const(8U, 7)),
  5415. this->gen_const(8U, rm),
  5416. this->builder.CreateTrunc(
  5417. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5418. this-> get_type(8)
  5419. ),
  5420. 8)
  5421. });
  5422. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5423. } else {
  5424. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5425. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5426. });
  5427. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5428. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  5429. });
  5430. Value* frs3_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5431. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0)
  5432. });
  5433. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmadd_s"), std::vector<Value*>{
  5434. frs1_val,
  5435. frs2_val,
  5436. frs3_val,
  5437. this->gen_ext(
  5438. this->gen_const(64U, 2LL),
  5439. 32,
  5440. false),
  5441. this->gen_choose(
  5442. this->builder.CreateICmp(
  5443. ICmpInst::ICMP_ULT,
  5444. this->gen_const(8U, rm),
  5445. this->gen_const(8U, 7)),
  5446. this->gen_const(8U, rm),
  5447. this->builder.CreateTrunc(
  5448. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5449. this-> get_type(8)
  5450. ),
  5451. 8)
  5452. });
  5453. uint64_t upper_val = - 1;
  5454. Value* Ftmp1_val = this->builder.CreateOr(
  5455. this->builder.CreateShl(
  5456. this->gen_const(64U, upper_val),
  5457. this->gen_const(64U, 32)),
  5458. this->gen_ext(
  5459. res_val,
  5460. 64,
  5461. false));
  5462. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5463. }
  5464. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5465. });
  5466. Value* FCSR_val = this->builder.CreateAdd(
  5467. this->builder.CreateAnd(
  5468. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5469. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5470. flags_val);
  5471. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5472. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5473. this->gen_sync(POST_SYNC, 118);
  5474. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5475. this->gen_trap_check(bb);
  5476. return std::make_tuple(CONT, bb);
  5477. }
  5478. /* instruction 119: FNMSUB.S */
  5479. std::tuple<continuation_e, BasicBlock*> __fnmsub_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5480. bb->setName("FNMSUB.S");
  5481. this->gen_sync(PRE_SYNC, 119);
  5482. uint8_t rd = ((bit_sub<7,5>(instr)));
  5483. uint8_t rm = ((bit_sub<12,3>(instr)));
  5484. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5485. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5486. uint8_t rs3 = ((bit_sub<27,5>(instr)));
  5487. if(this->disass_enabled){
  5488. /* generate console output when executing the command */
  5489. auto mnemonic = fmt::format(
  5490. "{mnemonic:10} x{rd}, f{rs1}, f{rs2}, f{rs3}", fmt::arg("mnemonic", "fnmsub.s"),
  5491. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2), fmt::arg("rs3", rs3));
  5492. std::vector<Value*> args {
  5493. this->core_ptr,
  5494. this->gen_const(64, pc.val),
  5495. this->builder.CreateGlobalStringPtr(mnemonic),
  5496. };
  5497. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5498. }
  5499. Value* cur_pc_val = this->gen_const(32, pc.val);
  5500. pc=pc+4;
  5501. if(64 == 32){
  5502. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fmadd_s"), std::vector<Value*>{
  5503. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5504. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5505. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0),
  5506. this->gen_ext(
  5507. this->gen_const(64U, 3LL),
  5508. 32,
  5509. false),
  5510. this->gen_choose(
  5511. this->builder.CreateICmp(
  5512. ICmpInst::ICMP_ULT,
  5513. this->gen_const(8U, rm),
  5514. this->gen_const(8U, 7)),
  5515. this->gen_const(8U, rm),
  5516. this->builder.CreateTrunc(
  5517. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5518. this-> get_type(8)
  5519. ),
  5520. 8)
  5521. });
  5522. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5523. } else {
  5524. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5525. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5526. });
  5527. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5528. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  5529. });
  5530. Value* frs3_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5531. this->gen_reg_load(rs3 + traits<ARCH>::F0, 0)
  5532. });
  5533. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmadd_s"), std::vector<Value*>{
  5534. frs1_val,
  5535. frs2_val,
  5536. frs3_val,
  5537. this->gen_ext(
  5538. this->gen_const(64U, 3LL),
  5539. 32,
  5540. false),
  5541. this->gen_choose(
  5542. this->builder.CreateICmp(
  5543. ICmpInst::ICMP_ULT,
  5544. this->gen_const(8U, rm),
  5545. this->gen_const(8U, 7)),
  5546. this->gen_const(8U, rm),
  5547. this->builder.CreateTrunc(
  5548. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5549. this-> get_type(8)
  5550. ),
  5551. 8)
  5552. });
  5553. uint64_t upper_val = - 1;
  5554. Value* Ftmp1_val = this->builder.CreateOr(
  5555. this->builder.CreateShl(
  5556. this->gen_const(64U, upper_val),
  5557. this->gen_const(64U, 32)),
  5558. this->gen_ext(
  5559. res_val,
  5560. 64,
  5561. false));
  5562. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5563. }
  5564. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5565. });
  5566. Value* FCSR_val = this->builder.CreateAdd(
  5567. this->builder.CreateAnd(
  5568. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5569. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5570. flags_val);
  5571. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5572. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5573. this->gen_sync(POST_SYNC, 119);
  5574. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5575. this->gen_trap_check(bb);
  5576. return std::make_tuple(CONT, bb);
  5577. }
  5578. /* instruction 120: FADD.S */
  5579. std::tuple<continuation_e, BasicBlock*> __fadd_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5580. bb->setName("FADD.S");
  5581. this->gen_sync(PRE_SYNC, 120);
  5582. uint8_t rd = ((bit_sub<7,5>(instr)));
  5583. uint8_t rm = ((bit_sub<12,3>(instr)));
  5584. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5585. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5586. if(this->disass_enabled){
  5587. /* generate console output when executing the command */
  5588. auto mnemonic = fmt::format(
  5589. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fadd.s"),
  5590. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  5591. std::vector<Value*> args {
  5592. this->core_ptr,
  5593. this->gen_const(64, pc.val),
  5594. this->builder.CreateGlobalStringPtr(mnemonic),
  5595. };
  5596. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5597. }
  5598. Value* cur_pc_val = this->gen_const(32, pc.val);
  5599. pc=pc+4;
  5600. if(64 == 32){
  5601. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fadd_s"), std::vector<Value*>{
  5602. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5603. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5604. this->gen_choose(
  5605. this->builder.CreateICmp(
  5606. ICmpInst::ICMP_ULT,
  5607. this->gen_const(8U, rm),
  5608. this->gen_const(8U, 7)),
  5609. this->gen_const(8U, rm),
  5610. this->builder.CreateTrunc(
  5611. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5612. this-> get_type(8)
  5613. ),
  5614. 8)
  5615. });
  5616. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5617. } else {
  5618. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5619. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5620. });
  5621. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5622. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  5623. });
  5624. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fadd_s"), std::vector<Value*>{
  5625. frs1_val,
  5626. frs2_val,
  5627. this->gen_choose(
  5628. this->builder.CreateICmp(
  5629. ICmpInst::ICMP_ULT,
  5630. this->gen_const(8U, rm),
  5631. this->gen_const(8U, 7)),
  5632. this->gen_const(8U, rm),
  5633. this->builder.CreateTrunc(
  5634. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5635. this-> get_type(8)
  5636. ),
  5637. 8)
  5638. });
  5639. uint64_t upper_val = - 1;
  5640. Value* Ftmp1_val = this->builder.CreateOr(
  5641. this->builder.CreateShl(
  5642. this->gen_const(64U, upper_val),
  5643. this->gen_const(64U, 32)),
  5644. this->gen_ext(
  5645. res_val,
  5646. 64,
  5647. false));
  5648. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5649. }
  5650. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5651. });
  5652. Value* FCSR_val = this->builder.CreateAdd(
  5653. this->builder.CreateAnd(
  5654. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5655. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5656. flags_val);
  5657. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5658. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5659. this->gen_sync(POST_SYNC, 120);
  5660. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5661. this->gen_trap_check(bb);
  5662. return std::make_tuple(CONT, bb);
  5663. }
  5664. /* instruction 121: FSUB.S */
  5665. std::tuple<continuation_e, BasicBlock*> __fsub_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5666. bb->setName("FSUB.S");
  5667. this->gen_sync(PRE_SYNC, 121);
  5668. uint8_t rd = ((bit_sub<7,5>(instr)));
  5669. uint8_t rm = ((bit_sub<12,3>(instr)));
  5670. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5671. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5672. if(this->disass_enabled){
  5673. /* generate console output when executing the command */
  5674. auto mnemonic = fmt::format(
  5675. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fsub.s"),
  5676. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  5677. std::vector<Value*> args {
  5678. this->core_ptr,
  5679. this->gen_const(64, pc.val),
  5680. this->builder.CreateGlobalStringPtr(mnemonic),
  5681. };
  5682. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5683. }
  5684. Value* cur_pc_val = this->gen_const(32, pc.val);
  5685. pc=pc+4;
  5686. if(64 == 32){
  5687. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fsub_s"), std::vector<Value*>{
  5688. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5689. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5690. this->gen_choose(
  5691. this->builder.CreateICmp(
  5692. ICmpInst::ICMP_ULT,
  5693. this->gen_const(8U, rm),
  5694. this->gen_const(8U, 7)),
  5695. this->gen_const(8U, rm),
  5696. this->builder.CreateTrunc(
  5697. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5698. this-> get_type(8)
  5699. ),
  5700. 8)
  5701. });
  5702. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5703. } else {
  5704. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5705. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5706. });
  5707. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5708. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  5709. });
  5710. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fsub_s"), std::vector<Value*>{
  5711. frs1_val,
  5712. frs2_val,
  5713. this->gen_choose(
  5714. this->builder.CreateICmp(
  5715. ICmpInst::ICMP_ULT,
  5716. this->gen_const(8U, rm),
  5717. this->gen_const(8U, 7)),
  5718. this->gen_const(8U, rm),
  5719. this->builder.CreateTrunc(
  5720. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5721. this-> get_type(8)
  5722. ),
  5723. 8)
  5724. });
  5725. uint64_t upper_val = - 1;
  5726. Value* Ftmp1_val = this->builder.CreateOr(
  5727. this->builder.CreateShl(
  5728. this->gen_const(64U, upper_val),
  5729. this->gen_const(64U, 32)),
  5730. this->gen_ext(
  5731. res_val,
  5732. 64,
  5733. false));
  5734. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5735. }
  5736. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5737. });
  5738. Value* FCSR_val = this->builder.CreateAdd(
  5739. this->builder.CreateAnd(
  5740. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5741. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5742. flags_val);
  5743. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5744. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5745. this->gen_sync(POST_SYNC, 121);
  5746. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5747. this->gen_trap_check(bb);
  5748. return std::make_tuple(CONT, bb);
  5749. }
  5750. /* instruction 122: FMUL.S */
  5751. std::tuple<continuation_e, BasicBlock*> __fmul_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5752. bb->setName("FMUL.S");
  5753. this->gen_sync(PRE_SYNC, 122);
  5754. uint8_t rd = ((bit_sub<7,5>(instr)));
  5755. uint8_t rm = ((bit_sub<12,3>(instr)));
  5756. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5757. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5758. if(this->disass_enabled){
  5759. /* generate console output when executing the command */
  5760. auto mnemonic = fmt::format(
  5761. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fmul.s"),
  5762. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  5763. std::vector<Value*> args {
  5764. this->core_ptr,
  5765. this->gen_const(64, pc.val),
  5766. this->builder.CreateGlobalStringPtr(mnemonic),
  5767. };
  5768. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5769. }
  5770. Value* cur_pc_val = this->gen_const(32, pc.val);
  5771. pc=pc+4;
  5772. if(64 == 32){
  5773. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fmul_s"), std::vector<Value*>{
  5774. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5775. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5776. this->gen_choose(
  5777. this->builder.CreateICmp(
  5778. ICmpInst::ICMP_ULT,
  5779. this->gen_const(8U, rm),
  5780. this->gen_const(8U, 7)),
  5781. this->gen_const(8U, rm),
  5782. this->builder.CreateTrunc(
  5783. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5784. this-> get_type(8)
  5785. ),
  5786. 8)
  5787. });
  5788. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5789. } else {
  5790. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5791. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5792. });
  5793. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5794. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  5795. });
  5796. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fmul_s"), std::vector<Value*>{
  5797. frs1_val,
  5798. frs2_val,
  5799. this->gen_choose(
  5800. this->builder.CreateICmp(
  5801. ICmpInst::ICMP_ULT,
  5802. this->gen_const(8U, rm),
  5803. this->gen_const(8U, 7)),
  5804. this->gen_const(8U, rm),
  5805. this->builder.CreateTrunc(
  5806. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5807. this-> get_type(8)
  5808. ),
  5809. 8)
  5810. });
  5811. uint64_t upper_val = - 1;
  5812. Value* Ftmp1_val = this->builder.CreateOr(
  5813. this->builder.CreateShl(
  5814. this->gen_const(64U, upper_val),
  5815. this->gen_const(64U, 32)),
  5816. this->gen_ext(
  5817. res_val,
  5818. 64,
  5819. false));
  5820. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5821. }
  5822. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5823. });
  5824. Value* FCSR_val = this->builder.CreateAdd(
  5825. this->builder.CreateAnd(
  5826. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5827. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5828. flags_val);
  5829. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5830. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5831. this->gen_sync(POST_SYNC, 122);
  5832. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5833. this->gen_trap_check(bb);
  5834. return std::make_tuple(CONT, bb);
  5835. }
  5836. /* instruction 123: FDIV.S */
  5837. std::tuple<continuation_e, BasicBlock*> __fdiv_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5838. bb->setName("FDIV.S");
  5839. this->gen_sync(PRE_SYNC, 123);
  5840. uint8_t rd = ((bit_sub<7,5>(instr)));
  5841. uint8_t rm = ((bit_sub<12,3>(instr)));
  5842. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5843. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  5844. if(this->disass_enabled){
  5845. /* generate console output when executing the command */
  5846. auto mnemonic = fmt::format(
  5847. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fdiv.s"),
  5848. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  5849. std::vector<Value*> args {
  5850. this->core_ptr,
  5851. this->gen_const(64, pc.val),
  5852. this->builder.CreateGlobalStringPtr(mnemonic),
  5853. };
  5854. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5855. }
  5856. Value* cur_pc_val = this->gen_const(32, pc.val);
  5857. pc=pc+4;
  5858. if(64 == 32){
  5859. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fdiv_s"), std::vector<Value*>{
  5860. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5861. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  5862. this->gen_choose(
  5863. this->builder.CreateICmp(
  5864. ICmpInst::ICMP_ULT,
  5865. this->gen_const(8U, rm),
  5866. this->gen_const(8U, 7)),
  5867. this->gen_const(8U, rm),
  5868. this->builder.CreateTrunc(
  5869. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5870. this-> get_type(8)
  5871. ),
  5872. 8)
  5873. });
  5874. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5875. } else {
  5876. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5877. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5878. });
  5879. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5880. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  5881. });
  5882. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fdiv_s"), std::vector<Value*>{
  5883. frs1_val,
  5884. frs2_val,
  5885. this->gen_choose(
  5886. this->builder.CreateICmp(
  5887. ICmpInst::ICMP_ULT,
  5888. this->gen_const(8U, rm),
  5889. this->gen_const(8U, 7)),
  5890. this->gen_const(8U, rm),
  5891. this->builder.CreateTrunc(
  5892. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5893. this-> get_type(8)
  5894. ),
  5895. 8)
  5896. });
  5897. uint64_t upper_val = - 1;
  5898. Value* Ftmp1_val = this->builder.CreateOr(
  5899. this->builder.CreateShl(
  5900. this->gen_const(64U, upper_val),
  5901. this->gen_const(64U, 32)),
  5902. this->gen_ext(
  5903. res_val,
  5904. 64,
  5905. false));
  5906. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5907. }
  5908. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5909. });
  5910. Value* FCSR_val = this->builder.CreateAdd(
  5911. this->builder.CreateAnd(
  5912. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5913. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5914. flags_val);
  5915. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5916. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5917. this->gen_sync(POST_SYNC, 123);
  5918. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5919. this->gen_trap_check(bb);
  5920. return std::make_tuple(CONT, bb);
  5921. }
  5922. /* instruction 124: FSQRT.S */
  5923. std::tuple<continuation_e, BasicBlock*> __fsqrt_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  5924. bb->setName("FSQRT.S");
  5925. this->gen_sync(PRE_SYNC, 124);
  5926. uint8_t rd = ((bit_sub<7,5>(instr)));
  5927. uint8_t rm = ((bit_sub<12,3>(instr)));
  5928. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  5929. if(this->disass_enabled){
  5930. /* generate console output when executing the command */
  5931. auto mnemonic = fmt::format(
  5932. "{mnemonic:10} f{rd}, f{rs1}", fmt::arg("mnemonic", "fsqrt.s"),
  5933. fmt::arg("rd", rd), fmt::arg("rs1", rs1));
  5934. std::vector<Value*> args {
  5935. this->core_ptr,
  5936. this->gen_const(64, pc.val),
  5937. this->builder.CreateGlobalStringPtr(mnemonic),
  5938. };
  5939. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  5940. }
  5941. Value* cur_pc_val = this->gen_const(32, pc.val);
  5942. pc=pc+4;
  5943. if(64 == 32){
  5944. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fsqrt_s"), std::vector<Value*>{
  5945. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  5946. this->gen_choose(
  5947. this->builder.CreateICmp(
  5948. ICmpInst::ICMP_ULT,
  5949. this->gen_const(8U, rm),
  5950. this->gen_const(8U, 7)),
  5951. this->gen_const(8U, rm),
  5952. this->builder.CreateTrunc(
  5953. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5954. this-> get_type(8)
  5955. ),
  5956. 8)
  5957. });
  5958. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5959. } else {
  5960. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  5961. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  5962. });
  5963. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fsqrt_s"), std::vector<Value*>{
  5964. frs1_val,
  5965. this->gen_choose(
  5966. this->builder.CreateICmp(
  5967. ICmpInst::ICMP_ULT,
  5968. this->gen_const(8U, rm),
  5969. this->gen_const(8U, 7)),
  5970. this->gen_const(8U, rm),
  5971. this->builder.CreateTrunc(
  5972. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5973. this-> get_type(8)
  5974. ),
  5975. 8)
  5976. });
  5977. uint64_t upper_val = - 1;
  5978. Value* Ftmp1_val = this->builder.CreateOr(
  5979. this->builder.CreateShl(
  5980. this->gen_const(64U, upper_val),
  5981. this->gen_const(64U, 32)),
  5982. this->gen_ext(
  5983. res_val,
  5984. 64,
  5985. false));
  5986. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  5987. }
  5988. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  5989. });
  5990. Value* FCSR_val = this->builder.CreateAdd(
  5991. this->builder.CreateAnd(
  5992. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  5993. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  5994. flags_val);
  5995. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  5996. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  5997. this->gen_sync(POST_SYNC, 124);
  5998. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  5999. this->gen_trap_check(bb);
  6000. return std::make_tuple(CONT, bb);
  6001. }
  6002. /* instruction 125: FSGNJ.S */
  6003. std::tuple<continuation_e, BasicBlock*> __fsgnj_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6004. bb->setName("FSGNJ.S");
  6005. this->gen_sync(PRE_SYNC, 125);
  6006. uint8_t rd = ((bit_sub<7,5>(instr)));
  6007. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6008. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6009. if(this->disass_enabled){
  6010. /* generate console output when executing the command */
  6011. auto mnemonic = fmt::format(
  6012. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fsgnj.s"),
  6013. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  6014. std::vector<Value*> args {
  6015. this->core_ptr,
  6016. this->gen_const(64, pc.val),
  6017. this->builder.CreateGlobalStringPtr(mnemonic),
  6018. };
  6019. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6020. }
  6021. Value* cur_pc_val = this->gen_const(32, pc.val);
  6022. pc=pc+4;
  6023. if(64 == 32){
  6024. Value* Ftmp0_val = this->builder.CreateOr(
  6025. this->builder.CreateAnd(
  6026. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6027. this->gen_const(64U, 0x7fffffff)),
  6028. this->builder.CreateAnd(
  6029. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  6030. this->gen_const(64U, 0x80000000)));
  6031. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6032. } else {
  6033. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6034. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6035. });
  6036. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6037. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  6038. });
  6039. Value* res_val = this->builder.CreateOr(
  6040. this->builder.CreateAnd(
  6041. frs1_val,
  6042. this->gen_const(32U, 0x7fffffff)),
  6043. this->builder.CreateAnd(
  6044. frs2_val,
  6045. this->gen_const(32U, 0x80000000)));
  6046. uint64_t upper_val = - 1;
  6047. Value* Ftmp1_val = this->builder.CreateOr(
  6048. this->builder.CreateShl(
  6049. this->gen_const(64U, upper_val),
  6050. this->gen_const(64U, 32)),
  6051. this->gen_ext(
  6052. res_val,
  6053. 64,
  6054. false));
  6055. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6056. }
  6057. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6058. this->gen_sync(POST_SYNC, 125);
  6059. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6060. this->gen_trap_check(bb);
  6061. return std::make_tuple(CONT, bb);
  6062. }
  6063. /* instruction 126: FSGNJN.S */
  6064. std::tuple<continuation_e, BasicBlock*> __fsgnjn_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6065. bb->setName("FSGNJN.S");
  6066. this->gen_sync(PRE_SYNC, 126);
  6067. uint8_t rd = ((bit_sub<7,5>(instr)));
  6068. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6069. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6070. if(this->disass_enabled){
  6071. /* generate console output when executing the command */
  6072. auto mnemonic = fmt::format(
  6073. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fsgnjn.s"),
  6074. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  6075. std::vector<Value*> args {
  6076. this->core_ptr,
  6077. this->gen_const(64, pc.val),
  6078. this->builder.CreateGlobalStringPtr(mnemonic),
  6079. };
  6080. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6081. }
  6082. Value* cur_pc_val = this->gen_const(32, pc.val);
  6083. pc=pc+4;
  6084. if(64 == 32){
  6085. Value* Ftmp0_val = this->builder.CreateOr(
  6086. this->builder.CreateAnd(
  6087. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6088. this->gen_const(64U, 0x7fffffff)),
  6089. this->builder.CreateAnd(
  6090. this->builder.CreateNot(this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)),
  6091. this->gen_const(64U, 0x80000000)));
  6092. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6093. } else {
  6094. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6095. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6096. });
  6097. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6098. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  6099. });
  6100. Value* res_val = this->builder.CreateOr(
  6101. this->builder.CreateAnd(
  6102. frs1_val,
  6103. this->gen_const(32U, 0x7fffffff)),
  6104. this->builder.CreateAnd(
  6105. this->builder.CreateNot(frs2_val),
  6106. this->gen_const(32U, 0x80000000)));
  6107. uint64_t upper_val = - 1;
  6108. Value* Ftmp1_val = this->builder.CreateOr(
  6109. this->builder.CreateShl(
  6110. this->gen_const(64U, upper_val),
  6111. this->gen_const(64U, 32)),
  6112. this->gen_ext(
  6113. res_val,
  6114. 64,
  6115. false));
  6116. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6117. }
  6118. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6119. this->gen_sync(POST_SYNC, 126);
  6120. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6121. this->gen_trap_check(bb);
  6122. return std::make_tuple(CONT, bb);
  6123. }
  6124. /* instruction 127: FSGNJX.S */
  6125. std::tuple<continuation_e, BasicBlock*> __fsgnjx_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6126. bb->setName("FSGNJX.S");
  6127. this->gen_sync(PRE_SYNC, 127);
  6128. uint8_t rd = ((bit_sub<7,5>(instr)));
  6129. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6130. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6131. if(this->disass_enabled){
  6132. /* generate console output when executing the command */
  6133. auto mnemonic = fmt::format(
  6134. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fsgnjx.s"),
  6135. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  6136. std::vector<Value*> args {
  6137. this->core_ptr,
  6138. this->gen_const(64, pc.val),
  6139. this->builder.CreateGlobalStringPtr(mnemonic),
  6140. };
  6141. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6142. }
  6143. Value* cur_pc_val = this->gen_const(32, pc.val);
  6144. pc=pc+4;
  6145. if(64 == 32){
  6146. Value* Ftmp0_val = this->builder.CreateXor(
  6147. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6148. this->builder.CreateAnd(
  6149. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  6150. this->gen_const(64U, 0x80000000)));
  6151. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6152. } else {
  6153. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6154. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6155. });
  6156. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6157. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  6158. });
  6159. Value* res_val = this->builder.CreateXor(
  6160. frs1_val,
  6161. this->builder.CreateAnd(
  6162. frs2_val,
  6163. this->gen_const(32U, 0x80000000)));
  6164. uint64_t upper_val = - 1;
  6165. Value* Ftmp1_val = this->builder.CreateOr(
  6166. this->builder.CreateShl(
  6167. this->gen_const(64U, upper_val),
  6168. this->gen_const(64U, 32)),
  6169. this->gen_ext(
  6170. res_val,
  6171. 64,
  6172. false));
  6173. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6174. }
  6175. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6176. this->gen_sync(POST_SYNC, 127);
  6177. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6178. this->gen_trap_check(bb);
  6179. return std::make_tuple(CONT, bb);
  6180. }
  6181. /* instruction 128: FMIN.S */
  6182. std::tuple<continuation_e, BasicBlock*> __fmin_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6183. bb->setName("FMIN.S");
  6184. this->gen_sync(PRE_SYNC, 128);
  6185. uint8_t rd = ((bit_sub<7,5>(instr)));
  6186. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6187. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6188. if(this->disass_enabled){
  6189. /* generate console output when executing the command */
  6190. auto mnemonic = fmt::format(
  6191. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fmin.s"),
  6192. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  6193. std::vector<Value*> args {
  6194. this->core_ptr,
  6195. this->gen_const(64, pc.val),
  6196. this->builder.CreateGlobalStringPtr(mnemonic),
  6197. };
  6198. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6199. }
  6200. Value* cur_pc_val = this->gen_const(32, pc.val);
  6201. pc=pc+4;
  6202. if(64 == 32){
  6203. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fsel_s"), std::vector<Value*>{
  6204. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6205. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  6206. this->gen_ext(
  6207. this->gen_const(64U, 0LL),
  6208. 32,
  6209. false)
  6210. });
  6211. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6212. } else {
  6213. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6214. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6215. });
  6216. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6217. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  6218. });
  6219. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fsel_s"), std::vector<Value*>{
  6220. frs1_val,
  6221. frs2_val,
  6222. this->gen_ext(
  6223. this->gen_const(64U, 0LL),
  6224. 32,
  6225. false)
  6226. });
  6227. uint64_t upper_val = - 1;
  6228. Value* Ftmp1_val = this->builder.CreateOr(
  6229. this->builder.CreateShl(
  6230. this->gen_const(64U, upper_val),
  6231. this->gen_const(64U, 32)),
  6232. this->gen_ext(
  6233. res_val,
  6234. 64,
  6235. false));
  6236. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6237. }
  6238. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  6239. });
  6240. Value* FCSR_val = this->builder.CreateAdd(
  6241. this->builder.CreateAnd(
  6242. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  6243. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  6244. flags_val);
  6245. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  6246. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6247. this->gen_sync(POST_SYNC, 128);
  6248. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6249. this->gen_trap_check(bb);
  6250. return std::make_tuple(CONT, bb);
  6251. }
  6252. /* instruction 129: FMAX.S */
  6253. std::tuple<continuation_e, BasicBlock*> __fmax_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6254. bb->setName("FMAX.S");
  6255. this->gen_sync(PRE_SYNC, 129);
  6256. uint8_t rd = ((bit_sub<7,5>(instr)));
  6257. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6258. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6259. if(this->disass_enabled){
  6260. /* generate console output when executing the command */
  6261. auto mnemonic = fmt::format(
  6262. "{mnemonic:10} f{rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fmax.s"),
  6263. fmt::arg("rd", rd), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  6264. std::vector<Value*> args {
  6265. this->core_ptr,
  6266. this->gen_const(64, pc.val),
  6267. this->builder.CreateGlobalStringPtr(mnemonic),
  6268. };
  6269. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6270. }
  6271. Value* cur_pc_val = this->gen_const(32, pc.val);
  6272. pc=pc+4;
  6273. if(64 == 32){
  6274. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fsel_s"), std::vector<Value*>{
  6275. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6276. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  6277. this->gen_ext(
  6278. this->gen_const(64U, 1LL),
  6279. 32,
  6280. false)
  6281. });
  6282. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6283. } else {
  6284. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6285. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6286. });
  6287. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6288. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  6289. });
  6290. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fsel_s"), std::vector<Value*>{
  6291. frs1_val,
  6292. frs2_val,
  6293. this->gen_ext(
  6294. this->gen_const(64U, 1LL),
  6295. 32,
  6296. false)
  6297. });
  6298. uint64_t upper_val = - 1;
  6299. Value* Ftmp1_val = this->builder.CreateOr(
  6300. this->builder.CreateShl(
  6301. this->gen_const(64U, upper_val),
  6302. this->gen_const(64U, 32)),
  6303. this->gen_ext(
  6304. res_val,
  6305. 64,
  6306. false));
  6307. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6308. }
  6309. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  6310. });
  6311. Value* FCSR_val = this->builder.CreateAdd(
  6312. this->builder.CreateAnd(
  6313. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  6314. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  6315. flags_val);
  6316. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  6317. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6318. this->gen_sync(POST_SYNC, 129);
  6319. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6320. this->gen_trap_check(bb);
  6321. return std::make_tuple(CONT, bb);
  6322. }
  6323. /* instruction 130: FCVT.W.S */
  6324. std::tuple<continuation_e, BasicBlock*> __fcvt_w_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6325. bb->setName("FCVT.W.S");
  6326. this->gen_sync(PRE_SYNC, 130);
  6327. uint8_t rd = ((bit_sub<7,5>(instr)));
  6328. uint8_t rm = ((bit_sub<12,3>(instr)));
  6329. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6330. if(this->disass_enabled){
  6331. /* generate console output when executing the command */
  6332. auto mnemonic = fmt::format(
  6333. "{mnemonic:10} {rd}, f{rs1}", fmt::arg("mnemonic", "fcvt.w.s"),
  6334. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1));
  6335. std::vector<Value*> args {
  6336. this->core_ptr,
  6337. this->gen_const(64, pc.val),
  6338. this->builder.CreateGlobalStringPtr(mnemonic),
  6339. };
  6340. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6341. }
  6342. Value* cur_pc_val = this->gen_const(32, pc.val);
  6343. pc=pc+4;
  6344. if(64 == 32){
  6345. Value* Xtmp0_val = this->gen_ext(
  6346. this->builder.CreateCall(this->mod->getFunction("fcvt_s"), std::vector<Value*>{
  6347. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6348. this->gen_ext(
  6349. this->gen_const(64U, 0LL),
  6350. 32,
  6351. false),
  6352. this->gen_const(8U, rm)
  6353. }),
  6354. 32,
  6355. true);
  6356. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6357. } else {
  6358. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6359. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6360. });
  6361. Value* Xtmp1_val = this->gen_ext(
  6362. this->builder.CreateCall(this->mod->getFunction("fcvt_s"), std::vector<Value*>{
  6363. frs1_val,
  6364. this->gen_ext(
  6365. this->gen_const(64U, 0LL),
  6366. 32,
  6367. false),
  6368. this->gen_const(8U, rm)
  6369. }),
  6370. 32,
  6371. true);
  6372. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6373. }
  6374. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  6375. });
  6376. Value* FCSR_val = this->builder.CreateAdd(
  6377. this->builder.CreateAnd(
  6378. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  6379. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  6380. flags_val);
  6381. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  6382. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6383. this->gen_sync(POST_SYNC, 130);
  6384. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6385. this->gen_trap_check(bb);
  6386. return std::make_tuple(CONT, bb);
  6387. }
  6388. /* instruction 131: FCVT.WU.S */
  6389. std::tuple<continuation_e, BasicBlock*> __fcvt_wu_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6390. bb->setName("FCVT.WU.S");
  6391. this->gen_sync(PRE_SYNC, 131);
  6392. uint8_t rd = ((bit_sub<7,5>(instr)));
  6393. uint8_t rm = ((bit_sub<12,3>(instr)));
  6394. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6395. if(this->disass_enabled){
  6396. /* generate console output when executing the command */
  6397. auto mnemonic = fmt::format(
  6398. "{mnemonic:10} {rd}, f{rs1}", fmt::arg("mnemonic", "fcvt.wu.s"),
  6399. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1));
  6400. std::vector<Value*> args {
  6401. this->core_ptr,
  6402. this->gen_const(64, pc.val),
  6403. this->builder.CreateGlobalStringPtr(mnemonic),
  6404. };
  6405. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6406. }
  6407. Value* cur_pc_val = this->gen_const(32, pc.val);
  6408. pc=pc+4;
  6409. if(64 == 32){
  6410. Value* Xtmp0_val = this->gen_ext(
  6411. this->builder.CreateCall(this->mod->getFunction("fcvt_s"), std::vector<Value*>{
  6412. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6413. this->gen_ext(
  6414. this->gen_const(64U, 1LL),
  6415. 32,
  6416. false),
  6417. this->gen_const(8U, rm)
  6418. }),
  6419. 32,
  6420. true);
  6421. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6422. } else {
  6423. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6424. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6425. });
  6426. Value* Xtmp1_val = this->gen_ext(
  6427. this->builder.CreateCall(this->mod->getFunction("fcvt_s"), std::vector<Value*>{
  6428. frs1_val,
  6429. this->gen_ext(
  6430. this->gen_const(64U, 1LL),
  6431. 32,
  6432. false),
  6433. this->gen_const(8U, rm)
  6434. }),
  6435. 32,
  6436. true);
  6437. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6438. }
  6439. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  6440. });
  6441. Value* FCSR_val = this->builder.CreateAdd(
  6442. this->builder.CreateAnd(
  6443. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  6444. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  6445. flags_val);
  6446. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  6447. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6448. this->gen_sync(POST_SYNC, 131);
  6449. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6450. this->gen_trap_check(bb);
  6451. return std::make_tuple(CONT, bb);
  6452. }
  6453. /* instruction 132: FEQ.S */
  6454. std::tuple<continuation_e, BasicBlock*> __feq_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6455. bb->setName("FEQ.S");
  6456. this->gen_sync(PRE_SYNC, 132);
  6457. uint8_t rd = ((bit_sub<7,5>(instr)));
  6458. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6459. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6460. if(this->disass_enabled){
  6461. /* generate console output when executing the command */
  6462. auto mnemonic = fmt::format(
  6463. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "feq.s"),
  6464. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  6465. std::vector<Value*> args {
  6466. this->core_ptr,
  6467. this->gen_const(64, pc.val),
  6468. this->builder.CreateGlobalStringPtr(mnemonic),
  6469. };
  6470. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6471. }
  6472. Value* cur_pc_val = this->gen_const(32, pc.val);
  6473. pc=pc+4;
  6474. if(64 == 32){
  6475. Value* Xtmp0_val = this->gen_ext(
  6476. this->builder.CreateCall(this->mod->getFunction("fcmp_s"), std::vector<Value*>{
  6477. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6478. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  6479. this->gen_ext(
  6480. this->gen_const(64U, 0LL),
  6481. 32,
  6482. false)
  6483. }),
  6484. 32,
  6485. false);
  6486. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6487. } else {
  6488. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6489. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6490. });
  6491. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6492. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  6493. });
  6494. Value* Xtmp1_val = this->gen_ext(
  6495. this->builder.CreateCall(this->mod->getFunction("fcmp_s"), std::vector<Value*>{
  6496. frs1_val,
  6497. frs2_val,
  6498. this->gen_ext(
  6499. this->gen_const(64U, 0LL),
  6500. 32,
  6501. false)
  6502. }),
  6503. 32,
  6504. false);
  6505. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6506. }
  6507. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  6508. });
  6509. Value* FCSR_val = this->builder.CreateAdd(
  6510. this->builder.CreateAnd(
  6511. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  6512. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  6513. flags_val);
  6514. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  6515. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6516. this->gen_sync(POST_SYNC, 132);
  6517. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6518. this->gen_trap_check(bb);
  6519. return std::make_tuple(CONT, bb);
  6520. }
  6521. /* instruction 133: FLT.S */
  6522. std::tuple<continuation_e, BasicBlock*> __flt_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6523. bb->setName("FLT.S");
  6524. this->gen_sync(PRE_SYNC, 133);
  6525. uint8_t rd = ((bit_sub<7,5>(instr)));
  6526. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6527. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6528. if(this->disass_enabled){
  6529. /* generate console output when executing the command */
  6530. auto mnemonic = fmt::format(
  6531. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "flt.s"),
  6532. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  6533. std::vector<Value*> args {
  6534. this->core_ptr,
  6535. this->gen_const(64, pc.val),
  6536. this->builder.CreateGlobalStringPtr(mnemonic),
  6537. };
  6538. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6539. }
  6540. Value* cur_pc_val = this->gen_const(32, pc.val);
  6541. pc=pc+4;
  6542. if(64 == 32){
  6543. Value* Xtmp0_val = this->gen_ext(
  6544. this->builder.CreateCall(this->mod->getFunction("fcmp_s"), std::vector<Value*>{
  6545. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6546. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  6547. this->gen_ext(
  6548. this->gen_const(64U, 2LL),
  6549. 32,
  6550. false)
  6551. }),
  6552. 32,
  6553. false);
  6554. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6555. } else {
  6556. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6557. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6558. });
  6559. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6560. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  6561. });
  6562. Value* Xtmp1_val = this->gen_ext(
  6563. this->builder.CreateCall(this->mod->getFunction("fcmp_s"), std::vector<Value*>{
  6564. frs1_val,
  6565. frs2_val,
  6566. this->gen_ext(
  6567. this->gen_const(64U, 2LL),
  6568. 32,
  6569. false)
  6570. }),
  6571. 32,
  6572. false);
  6573. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6574. }
  6575. Value* Xtmp2_val = this->builder.CreateCall(this->mod->getFunction("fcmp_s"), std::vector<Value*>{
  6576. this->builder.CreateTrunc(
  6577. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6578. this-> get_type(32)
  6579. ),
  6580. this->builder.CreateTrunc(
  6581. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  6582. this-> get_type(32)
  6583. ),
  6584. this->gen_ext(
  6585. this->gen_const(64U, 2LL),
  6586. 32,
  6587. false)
  6588. });
  6589. this->builder.CreateStore(Xtmp2_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6590. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  6591. });
  6592. Value* FCSR_val = this->builder.CreateAdd(
  6593. this->builder.CreateAnd(
  6594. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  6595. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  6596. flags_val);
  6597. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  6598. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6599. this->gen_sync(POST_SYNC, 133);
  6600. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6601. this->gen_trap_check(bb);
  6602. return std::make_tuple(CONT, bb);
  6603. }
  6604. /* instruction 134: FLE.S */
  6605. std::tuple<continuation_e, BasicBlock*> __fle_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6606. bb->setName("FLE.S");
  6607. this->gen_sync(PRE_SYNC, 134);
  6608. uint8_t rd = ((bit_sub<7,5>(instr)));
  6609. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6610. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6611. if(this->disass_enabled){
  6612. /* generate console output when executing the command */
  6613. auto mnemonic = fmt::format(
  6614. "{mnemonic:10} {rd}, f{rs1}, f{rs2}", fmt::arg("mnemonic", "fle.s"),
  6615. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1), fmt::arg("rs2", rs2));
  6616. std::vector<Value*> args {
  6617. this->core_ptr,
  6618. this->gen_const(64, pc.val),
  6619. this->builder.CreateGlobalStringPtr(mnemonic),
  6620. };
  6621. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6622. }
  6623. Value* cur_pc_val = this->gen_const(32, pc.val);
  6624. pc=pc+4;
  6625. if(64 == 32){
  6626. Value* Xtmp0_val = this->gen_ext(
  6627. this->builder.CreateCall(this->mod->getFunction("fcmp_s"), std::vector<Value*>{
  6628. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6629. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0),
  6630. this->gen_ext(
  6631. this->gen_const(64U, 1LL),
  6632. 32,
  6633. false)
  6634. }),
  6635. 32,
  6636. false);
  6637. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6638. } else {
  6639. Value* frs1_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6640. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6641. });
  6642. Value* frs2_val = this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6643. this->gen_reg_load(rs2 + traits<ARCH>::F0, 0)
  6644. });
  6645. Value* Xtmp1_val = this->gen_ext(
  6646. this->builder.CreateCall(this->mod->getFunction("fcmp_s"), std::vector<Value*>{
  6647. frs1_val,
  6648. frs2_val,
  6649. this->gen_ext(
  6650. this->gen_const(64U, 1LL),
  6651. 32,
  6652. false)
  6653. }),
  6654. 32,
  6655. false);
  6656. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6657. }
  6658. Value* flags_val = this->builder.CreateCall(this->mod->getFunction("fget_flags"), std::vector<Value*>{
  6659. });
  6660. Value* FCSR_val = this->builder.CreateAdd(
  6661. this->builder.CreateAnd(
  6662. this->gen_reg_load(traits<ARCH>::FCSR, 0),
  6663. this->builder.CreateNot(this->gen_const(32U, 0x1f))),
  6664. flags_val);
  6665. this->builder.CreateStore(FCSR_val, get_reg_ptr(traits<ARCH>::FCSR), false);
  6666. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6667. this->gen_sync(POST_SYNC, 134);
  6668. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6669. this->gen_trap_check(bb);
  6670. return std::make_tuple(CONT, bb);
  6671. }
  6672. /* instruction 135: FCLASS.S */
  6673. std::tuple<continuation_e, BasicBlock*> __fclass_s(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6674. bb->setName("FCLASS.S");
  6675. this->gen_sync(PRE_SYNC, 135);
  6676. uint8_t rd = ((bit_sub<7,5>(instr)));
  6677. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6678. if(this->disass_enabled){
  6679. /* generate console output when executing the command */
  6680. auto mnemonic = fmt::format(
  6681. "{mnemonic:10} {rd}, f{rs1}", fmt::arg("mnemonic", "fclass.s"),
  6682. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1));
  6683. std::vector<Value*> args {
  6684. this->core_ptr,
  6685. this->gen_const(64, pc.val),
  6686. this->builder.CreateGlobalStringPtr(mnemonic),
  6687. };
  6688. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6689. }
  6690. Value* cur_pc_val = this->gen_const(32, pc.val);
  6691. pc=pc+4;
  6692. Value* Xtmp0_val = this->builder.CreateCall(this->mod->getFunction("fclass_s"), std::vector<Value*>{
  6693. this->builder.CreateCall(this->mod->getFunction("unbox_s"), std::vector<Value*>{
  6694. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0)
  6695. })
  6696. });
  6697. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6698. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6699. this->gen_sync(POST_SYNC, 135);
  6700. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6701. this->gen_trap_check(bb);
  6702. return std::make_tuple(CONT, bb);
  6703. }
  6704. /* instruction 136: FCVT.S.W */
  6705. std::tuple<continuation_e, BasicBlock*> __fcvt_s_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6706. bb->setName("FCVT.S.W");
  6707. this->gen_sync(PRE_SYNC, 136);
  6708. uint8_t rd = ((bit_sub<7,5>(instr)));
  6709. uint8_t rm = ((bit_sub<12,3>(instr)));
  6710. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6711. if(this->disass_enabled){
  6712. /* generate console output when executing the command */
  6713. auto mnemonic = fmt::format(
  6714. "{mnemonic:10} f{rd}, {rs1}", fmt::arg("mnemonic", "fcvt.s.w"),
  6715. fmt::arg("rd", rd), fmt::arg("rs1", name(rs1)));
  6716. std::vector<Value*> args {
  6717. this->core_ptr,
  6718. this->gen_const(64, pc.val),
  6719. this->builder.CreateGlobalStringPtr(mnemonic),
  6720. };
  6721. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6722. }
  6723. Value* cur_pc_val = this->gen_const(32, pc.val);
  6724. pc=pc+4;
  6725. if(64 == 32){
  6726. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fcvt_s"), std::vector<Value*>{
  6727. this->builder.CreateTrunc(
  6728. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  6729. this-> get_type(32)
  6730. ),
  6731. this->gen_ext(
  6732. this->gen_const(64U, 2LL),
  6733. 32,
  6734. false),
  6735. this->gen_const(8U, rm)
  6736. });
  6737. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6738. } else {
  6739. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fcvt_s"), std::vector<Value*>{
  6740. this->builder.CreateTrunc(
  6741. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  6742. this-> get_type(32)
  6743. ),
  6744. this->gen_ext(
  6745. this->gen_const(64U, 2LL),
  6746. 32,
  6747. false),
  6748. this->gen_const(8U, rm)
  6749. });
  6750. uint64_t upper_val = - 1;
  6751. Value* Ftmp1_val = this->builder.CreateOr(
  6752. this->builder.CreateShl(
  6753. this->gen_const(64U, upper_val),
  6754. this->gen_const(64U, 32)),
  6755. this->gen_ext(
  6756. res_val,
  6757. 64,
  6758. false));
  6759. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6760. }
  6761. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6762. this->gen_sync(POST_SYNC, 136);
  6763. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6764. this->gen_trap_check(bb);
  6765. return std::make_tuple(CONT, bb);
  6766. }
  6767. /* instruction 137: FCVT.S.WU */
  6768. std::tuple<continuation_e, BasicBlock*> __fcvt_s_wu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6769. bb->setName("FCVT.S.WU");
  6770. this->gen_sync(PRE_SYNC, 137);
  6771. uint8_t rd = ((bit_sub<7,5>(instr)));
  6772. uint8_t rm = ((bit_sub<12,3>(instr)));
  6773. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6774. if(this->disass_enabled){
  6775. /* generate console output when executing the command */
  6776. auto mnemonic = fmt::format(
  6777. "{mnemonic:10} f{rd}, {rs1}", fmt::arg("mnemonic", "fcvt.s.wu"),
  6778. fmt::arg("rd", rd), fmt::arg("rs1", name(rs1)));
  6779. std::vector<Value*> args {
  6780. this->core_ptr,
  6781. this->gen_const(64, pc.val),
  6782. this->builder.CreateGlobalStringPtr(mnemonic),
  6783. };
  6784. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6785. }
  6786. Value* cur_pc_val = this->gen_const(32, pc.val);
  6787. pc=pc+4;
  6788. if(64 == 32){
  6789. Value* Ftmp0_val = this->builder.CreateCall(this->mod->getFunction("fcvt_s"), std::vector<Value*>{
  6790. this->builder.CreateTrunc(
  6791. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  6792. this-> get_type(32)
  6793. ),
  6794. this->gen_ext(
  6795. this->gen_const(64U, 3LL),
  6796. 32,
  6797. false),
  6798. this->gen_const(8U, rm)
  6799. });
  6800. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6801. } else {
  6802. Value* res_val = this->builder.CreateCall(this->mod->getFunction("fcvt_s"), std::vector<Value*>{
  6803. this->builder.CreateTrunc(
  6804. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  6805. this-> get_type(32)
  6806. ),
  6807. this->gen_ext(
  6808. this->gen_const(64U, 3LL),
  6809. 32,
  6810. false),
  6811. this->gen_const(8U, rm)
  6812. });
  6813. uint64_t upper_val = - 1;
  6814. Value* Ftmp1_val = this->builder.CreateOr(
  6815. this->builder.CreateShl(
  6816. this->gen_const(64U, upper_val),
  6817. this->gen_const(64U, 32)),
  6818. this->gen_ext(
  6819. res_val,
  6820. 64,
  6821. false));
  6822. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6823. }
  6824. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6825. this->gen_sync(POST_SYNC, 137);
  6826. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6827. this->gen_trap_check(bb);
  6828. return std::make_tuple(CONT, bb);
  6829. }
  6830. /* instruction 138: FMV.X.W */
  6831. std::tuple<continuation_e, BasicBlock*> __fmv_x_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6832. bb->setName("FMV.X.W");
  6833. this->gen_sync(PRE_SYNC, 138);
  6834. uint8_t rd = ((bit_sub<7,5>(instr)));
  6835. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6836. if(this->disass_enabled){
  6837. /* generate console output when executing the command */
  6838. auto mnemonic = fmt::format(
  6839. "{mnemonic:10} {rd}, f{rs1}", fmt::arg("mnemonic", "fmv.x.w"),
  6840. fmt::arg("rd", name(rd)), fmt::arg("rs1", rs1));
  6841. std::vector<Value*> args {
  6842. this->core_ptr,
  6843. this->gen_const(64, pc.val),
  6844. this->builder.CreateGlobalStringPtr(mnemonic),
  6845. };
  6846. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6847. }
  6848. Value* cur_pc_val = this->gen_const(32, pc.val);
  6849. pc=pc+4;
  6850. Value* Xtmp0_val = this->gen_ext(
  6851. this->builder.CreateTrunc(
  6852. this->gen_reg_load(rs1 + traits<ARCH>::F0, 0),
  6853. this-> get_type(32)
  6854. ),
  6855. 32,
  6856. true);
  6857. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6858. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6859. this->gen_sync(POST_SYNC, 138);
  6860. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6861. this->gen_trap_check(bb);
  6862. return std::make_tuple(CONT, bb);
  6863. }
  6864. /* instruction 139: FMV.W.X */
  6865. std::tuple<continuation_e, BasicBlock*> __fmv_w_x(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6866. bb->setName("FMV.W.X");
  6867. this->gen_sync(PRE_SYNC, 139);
  6868. uint8_t rd = ((bit_sub<7,5>(instr)));
  6869. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6870. if(this->disass_enabled){
  6871. /* generate console output when executing the command */
  6872. auto mnemonic = fmt::format(
  6873. "{mnemonic:10} f{rd}, {rs1}", fmt::arg("mnemonic", "fmv.w.x"),
  6874. fmt::arg("rd", rd), fmt::arg("rs1", name(rs1)));
  6875. std::vector<Value*> args {
  6876. this->core_ptr,
  6877. this->gen_const(64, pc.val),
  6878. this->builder.CreateGlobalStringPtr(mnemonic),
  6879. };
  6880. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6881. }
  6882. Value* cur_pc_val = this->gen_const(32, pc.val);
  6883. pc=pc+4;
  6884. if(64 == 32){
  6885. Value* Ftmp0_val = this->builder.CreateTrunc(
  6886. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  6887. this-> get_type(32)
  6888. );
  6889. this->builder.CreateStore(Ftmp0_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6890. } else {
  6891. uint64_t upper_val = - 1;
  6892. Value* Ftmp1_val = this->builder.CreateOr(
  6893. this->builder.CreateShl(
  6894. this->gen_const(64U, upper_val),
  6895. this->gen_const(64U, 32)),
  6896. this->gen_ext(
  6897. this->builder.CreateTrunc(
  6898. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  6899. this-> get_type(32)
  6900. ),
  6901. 64,
  6902. false));
  6903. this->builder.CreateStore(Ftmp1_val, get_reg_ptr(rd + traits<ARCH>::F0), false);
  6904. }
  6905. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6906. this->gen_sync(POST_SYNC, 139);
  6907. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6908. this->gen_trap_check(bb);
  6909. return std::make_tuple(CONT, bb);
  6910. }
  6911. /* instruction 140: LR.W */
  6912. std::tuple<continuation_e, BasicBlock*> __lr_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6913. bb->setName("LR.W");
  6914. this->gen_sync(PRE_SYNC, 140);
  6915. uint8_t rd = ((bit_sub<7,5>(instr)));
  6916. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6917. uint8_t rl = ((bit_sub<25,1>(instr)));
  6918. uint8_t aq = ((bit_sub<26,1>(instr)));
  6919. if(this->disass_enabled){
  6920. /* generate console output when executing the command */
  6921. auto mnemonic = fmt::format(
  6922. "{mnemonic:10} {rd}, {rs1}", fmt::arg("mnemonic", "lr.w"),
  6923. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)));
  6924. std::vector<Value*> args {
  6925. this->core_ptr,
  6926. this->gen_const(64, pc.val),
  6927. this->builder.CreateGlobalStringPtr(mnemonic),
  6928. };
  6929. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6930. }
  6931. Value* cur_pc_val = this->gen_const(32, pc.val);
  6932. pc=pc+4;
  6933. if(rd != 0){
  6934. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  6935. Value* Xtmp0_val = this->gen_ext(
  6936. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  6937. 32,
  6938. true);
  6939. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  6940. Value* REStmp1_val = this->gen_ext(
  6941. this->builder.CreateNeg(this->gen_const(8U, 1)),
  6942. 32,
  6943. true);
  6944. this->gen_write_mem(
  6945. traits<ARCH>::RES,
  6946. offs_val,
  6947. this->builder.CreateZExtOrTrunc(REStmp1_val,this->get_type(32)));
  6948. }
  6949. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  6950. this->gen_sync(POST_SYNC, 140);
  6951. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  6952. this->gen_trap_check(bb);
  6953. return std::make_tuple(CONT, bb);
  6954. }
  6955. /* instruction 141: SC.W */
  6956. std::tuple<continuation_e, BasicBlock*> __sc_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  6957. bb->setName("SC.W");
  6958. this->gen_sync(PRE_SYNC, 141);
  6959. uint8_t rd = ((bit_sub<7,5>(instr)));
  6960. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  6961. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  6962. uint8_t rl = ((bit_sub<25,1>(instr)));
  6963. uint8_t aq = ((bit_sub<26,1>(instr)));
  6964. if(this->disass_enabled){
  6965. /* generate console output when executing the command */
  6966. auto mnemonic = fmt::format(
  6967. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "sc.w"),
  6968. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  6969. std::vector<Value*> args {
  6970. this->core_ptr,
  6971. this->gen_const(64, pc.val),
  6972. this->builder.CreateGlobalStringPtr(mnemonic),
  6973. };
  6974. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  6975. }
  6976. Value* cur_pc_val = this->gen_const(32, pc.val);
  6977. pc=pc+4;
  6978. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  6979. Value* res1_val = this->gen_read_mem(traits<ARCH>::RES, offs_val, 32/8);
  6980. {
  6981. BasicBlock* bbnext = BasicBlock::Create(this->mod->getContext(), "endif", this->func, this->leave_blk);
  6982. BasicBlock* bb_then = BasicBlock::Create(this->mod->getContext(), "thenbr", this->func, bbnext);
  6983. // this->builder.SetInsertPoint(bb);
  6984. this->gen_cond_branch(this->builder.CreateICmp(
  6985. ICmpInst::ICMP_NE,
  6986. res1_val,
  6987. this->gen_const(32U, 0)),
  6988. bb_then,
  6989. bbnext);
  6990. this->builder.SetInsertPoint(bb_then);
  6991. {
  6992. Value* MEMtmp0_val = this->gen_reg_load(rs2 + traits<ARCH>::X0, 1);
  6993. this->gen_write_mem(
  6994. traits<ARCH>::MEM,
  6995. offs_val,
  6996. this->builder.CreateZExtOrTrunc(MEMtmp0_val,this->get_type(32)));
  6997. }
  6998. this->builder.CreateBr(bbnext);
  6999. bb=bbnext;
  7000. }
  7001. this->builder.SetInsertPoint(bb);
  7002. if(rd != 0){
  7003. Value* Xtmp1_val = this->gen_choose(
  7004. this->builder.CreateICmp(
  7005. ICmpInst::ICMP_NE,
  7006. res1_val,
  7007. this->gen_ext(
  7008. this->gen_const(32U, 0),
  7009. 32,
  7010. false)),
  7011. this->gen_const(32U, 0),
  7012. this->gen_const(32U, 1),
  7013. 32);
  7014. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7015. }
  7016. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7017. this->gen_sync(POST_SYNC, 141);
  7018. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7019. this->gen_trap_check(bb);
  7020. return std::make_tuple(CONT, bb);
  7021. }
  7022. /* instruction 142: AMOSWAP.W */
  7023. std::tuple<continuation_e, BasicBlock*> __amoswap_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7024. bb->setName("AMOSWAP.W");
  7025. this->gen_sync(PRE_SYNC, 142);
  7026. uint8_t rd = ((bit_sub<7,5>(instr)));
  7027. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7028. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7029. uint8_t rl = ((bit_sub<25,1>(instr)));
  7030. uint8_t aq = ((bit_sub<26,1>(instr)));
  7031. if(this->disass_enabled){
  7032. /* generate console output when executing the command */
  7033. auto mnemonic = fmt::format(
  7034. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amoswap.w"),
  7035. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7036. std::vector<Value*> args {
  7037. this->core_ptr,
  7038. this->gen_const(64, pc.val),
  7039. this->builder.CreateGlobalStringPtr(mnemonic),
  7040. };
  7041. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7042. }
  7043. Value* cur_pc_val = this->gen_const(32, pc.val);
  7044. pc=pc+4;
  7045. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7046. if(rd != 0){
  7047. Value* Xtmp0_val = this->gen_ext(
  7048. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7049. 32,
  7050. true);
  7051. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7052. }
  7053. Value* MEMtmp1_val = this->gen_reg_load(rs2 + traits<ARCH>::X0, 0);
  7054. this->gen_write_mem(
  7055. traits<ARCH>::MEM,
  7056. offs_val,
  7057. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7058. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7059. this->gen_sync(POST_SYNC, 142);
  7060. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7061. this->gen_trap_check(bb);
  7062. return std::make_tuple(CONT, bb);
  7063. }
  7064. /* instruction 143: AMOADD.W */
  7065. std::tuple<continuation_e, BasicBlock*> __amoadd_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7066. bb->setName("AMOADD.W");
  7067. this->gen_sync(PRE_SYNC, 143);
  7068. uint8_t rd = ((bit_sub<7,5>(instr)));
  7069. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7070. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7071. uint8_t rl = ((bit_sub<25,1>(instr)));
  7072. uint8_t aq = ((bit_sub<26,1>(instr)));
  7073. if(this->disass_enabled){
  7074. /* generate console output when executing the command */
  7075. auto mnemonic = fmt::format(
  7076. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amoadd.w"),
  7077. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7078. std::vector<Value*> args {
  7079. this->core_ptr,
  7080. this->gen_const(64, pc.val),
  7081. this->builder.CreateGlobalStringPtr(mnemonic),
  7082. };
  7083. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7084. }
  7085. Value* cur_pc_val = this->gen_const(32, pc.val);
  7086. pc=pc+4;
  7087. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7088. Value* res1_val = this->gen_ext(
  7089. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7090. 32,
  7091. true);
  7092. if(rd != 0){
  7093. Value* Xtmp0_val = res1_val;
  7094. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7095. }
  7096. Value* res2_val = this->builder.CreateAdd(
  7097. res1_val,
  7098. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  7099. Value* MEMtmp1_val = res2_val;
  7100. this->gen_write_mem(
  7101. traits<ARCH>::MEM,
  7102. offs_val,
  7103. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7104. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7105. this->gen_sync(POST_SYNC, 143);
  7106. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7107. this->gen_trap_check(bb);
  7108. return std::make_tuple(CONT, bb);
  7109. }
  7110. /* instruction 144: AMOXOR.W */
  7111. std::tuple<continuation_e, BasicBlock*> __amoxor_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7112. bb->setName("AMOXOR.W");
  7113. this->gen_sync(PRE_SYNC, 144);
  7114. uint8_t rd = ((bit_sub<7,5>(instr)));
  7115. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7116. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7117. uint8_t rl = ((bit_sub<25,1>(instr)));
  7118. uint8_t aq = ((bit_sub<26,1>(instr)));
  7119. if(this->disass_enabled){
  7120. /* generate console output when executing the command */
  7121. auto mnemonic = fmt::format(
  7122. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amoxor.w"),
  7123. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7124. std::vector<Value*> args {
  7125. this->core_ptr,
  7126. this->gen_const(64, pc.val),
  7127. this->builder.CreateGlobalStringPtr(mnemonic),
  7128. };
  7129. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7130. }
  7131. Value* cur_pc_val = this->gen_const(32, pc.val);
  7132. pc=pc+4;
  7133. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7134. Value* res1_val = this->gen_ext(
  7135. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7136. 32,
  7137. true);
  7138. if(rd != 0){
  7139. Value* Xtmp0_val = res1_val;
  7140. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7141. }
  7142. Value* res2_val = this->builder.CreateXor(
  7143. res1_val,
  7144. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  7145. Value* MEMtmp1_val = res2_val;
  7146. this->gen_write_mem(
  7147. traits<ARCH>::MEM,
  7148. offs_val,
  7149. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7150. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7151. this->gen_sync(POST_SYNC, 144);
  7152. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7153. this->gen_trap_check(bb);
  7154. return std::make_tuple(CONT, bb);
  7155. }
  7156. /* instruction 145: AMOAND.W */
  7157. std::tuple<continuation_e, BasicBlock*> __amoand_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7158. bb->setName("AMOAND.W");
  7159. this->gen_sync(PRE_SYNC, 145);
  7160. uint8_t rd = ((bit_sub<7,5>(instr)));
  7161. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7162. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7163. uint8_t rl = ((bit_sub<25,1>(instr)));
  7164. uint8_t aq = ((bit_sub<26,1>(instr)));
  7165. if(this->disass_enabled){
  7166. /* generate console output when executing the command */
  7167. auto mnemonic = fmt::format(
  7168. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amoand.w"),
  7169. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7170. std::vector<Value*> args {
  7171. this->core_ptr,
  7172. this->gen_const(64, pc.val),
  7173. this->builder.CreateGlobalStringPtr(mnemonic),
  7174. };
  7175. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7176. }
  7177. Value* cur_pc_val = this->gen_const(32, pc.val);
  7178. pc=pc+4;
  7179. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7180. Value* res1_val = this->gen_ext(
  7181. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7182. 32,
  7183. true);
  7184. if(rd != 0){
  7185. Value* Xtmp0_val = res1_val;
  7186. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7187. }
  7188. Value* res2_val = this->builder.CreateAnd(
  7189. res1_val,
  7190. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  7191. Value* MEMtmp1_val = res2_val;
  7192. this->gen_write_mem(
  7193. traits<ARCH>::MEM,
  7194. offs_val,
  7195. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7196. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7197. this->gen_sync(POST_SYNC, 145);
  7198. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7199. this->gen_trap_check(bb);
  7200. return std::make_tuple(CONT, bb);
  7201. }
  7202. /* instruction 146: AMOOR.W */
  7203. std::tuple<continuation_e, BasicBlock*> __amoor_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7204. bb->setName("AMOOR.W");
  7205. this->gen_sync(PRE_SYNC, 146);
  7206. uint8_t rd = ((bit_sub<7,5>(instr)));
  7207. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7208. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7209. uint8_t rl = ((bit_sub<25,1>(instr)));
  7210. uint8_t aq = ((bit_sub<26,1>(instr)));
  7211. if(this->disass_enabled){
  7212. /* generate console output when executing the command */
  7213. auto mnemonic = fmt::format(
  7214. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amoor.w"),
  7215. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7216. std::vector<Value*> args {
  7217. this->core_ptr,
  7218. this->gen_const(64, pc.val),
  7219. this->builder.CreateGlobalStringPtr(mnemonic),
  7220. };
  7221. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7222. }
  7223. Value* cur_pc_val = this->gen_const(32, pc.val);
  7224. pc=pc+4;
  7225. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7226. Value* res1_val = this->gen_ext(
  7227. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7228. 32,
  7229. true);
  7230. if(rd != 0){
  7231. Value* Xtmp0_val = res1_val;
  7232. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7233. }
  7234. Value* res2_val = this->builder.CreateOr(
  7235. res1_val,
  7236. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0));
  7237. Value* MEMtmp1_val = res2_val;
  7238. this->gen_write_mem(
  7239. traits<ARCH>::MEM,
  7240. offs_val,
  7241. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7242. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7243. this->gen_sync(POST_SYNC, 146);
  7244. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7245. this->gen_trap_check(bb);
  7246. return std::make_tuple(CONT, bb);
  7247. }
  7248. /* instruction 147: AMOMIN.W */
  7249. std::tuple<continuation_e, BasicBlock*> __amomin_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7250. bb->setName("AMOMIN.W");
  7251. this->gen_sync(PRE_SYNC, 147);
  7252. uint8_t rd = ((bit_sub<7,5>(instr)));
  7253. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7254. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7255. uint8_t rl = ((bit_sub<25,1>(instr)));
  7256. uint8_t aq = ((bit_sub<26,1>(instr)));
  7257. if(this->disass_enabled){
  7258. /* generate console output when executing the command */
  7259. auto mnemonic = fmt::format(
  7260. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amomin.w"),
  7261. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7262. std::vector<Value*> args {
  7263. this->core_ptr,
  7264. this->gen_const(64, pc.val),
  7265. this->builder.CreateGlobalStringPtr(mnemonic),
  7266. };
  7267. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7268. }
  7269. Value* cur_pc_val = this->gen_const(32, pc.val);
  7270. pc=pc+4;
  7271. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7272. Value* res1_val = this->gen_ext(
  7273. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7274. 32,
  7275. true);
  7276. if(rd != 0){
  7277. Value* Xtmp0_val = res1_val;
  7278. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7279. }
  7280. Value* res2_val = this->gen_choose(
  7281. this->builder.CreateICmp(
  7282. ICmpInst::ICMP_SGT,
  7283. this->gen_ext(
  7284. res1_val,
  7285. 32, true),
  7286. this->gen_ext(
  7287. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7288. 32, true)),
  7289. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7290. res1_val,
  7291. 32);
  7292. Value* MEMtmp1_val = res2_val;
  7293. this->gen_write_mem(
  7294. traits<ARCH>::MEM,
  7295. offs_val,
  7296. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7297. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7298. this->gen_sync(POST_SYNC, 147);
  7299. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7300. this->gen_trap_check(bb);
  7301. return std::make_tuple(CONT, bb);
  7302. }
  7303. /* instruction 148: AMOMAX.W */
  7304. std::tuple<continuation_e, BasicBlock*> __amomax_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7305. bb->setName("AMOMAX.W");
  7306. this->gen_sync(PRE_SYNC, 148);
  7307. uint8_t rd = ((bit_sub<7,5>(instr)));
  7308. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7309. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7310. uint8_t rl = ((bit_sub<25,1>(instr)));
  7311. uint8_t aq = ((bit_sub<26,1>(instr)));
  7312. if(this->disass_enabled){
  7313. /* generate console output when executing the command */
  7314. auto mnemonic = fmt::format(
  7315. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amomax.w"),
  7316. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7317. std::vector<Value*> args {
  7318. this->core_ptr,
  7319. this->gen_const(64, pc.val),
  7320. this->builder.CreateGlobalStringPtr(mnemonic),
  7321. };
  7322. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7323. }
  7324. Value* cur_pc_val = this->gen_const(32, pc.val);
  7325. pc=pc+4;
  7326. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7327. Value* res1_val = this->gen_ext(
  7328. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7329. 32,
  7330. true);
  7331. if(rd != 0){
  7332. Value* Xtmp0_val = res1_val;
  7333. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7334. }
  7335. Value* res2_val = this->gen_choose(
  7336. this->builder.CreateICmp(
  7337. ICmpInst::ICMP_SLT,
  7338. this->gen_ext(
  7339. res1_val,
  7340. 32, true),
  7341. this->gen_ext(
  7342. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7343. 32, true)),
  7344. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7345. res1_val,
  7346. 32);
  7347. Value* MEMtmp1_val = res2_val;
  7348. this->gen_write_mem(
  7349. traits<ARCH>::MEM,
  7350. offs_val,
  7351. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7352. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7353. this->gen_sync(POST_SYNC, 148);
  7354. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7355. this->gen_trap_check(bb);
  7356. return std::make_tuple(CONT, bb);
  7357. }
  7358. /* instruction 149: AMOMINU.W */
  7359. std::tuple<continuation_e, BasicBlock*> __amominu_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7360. bb->setName("AMOMINU.W");
  7361. this->gen_sync(PRE_SYNC, 149);
  7362. uint8_t rd = ((bit_sub<7,5>(instr)));
  7363. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7364. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7365. uint8_t rl = ((bit_sub<25,1>(instr)));
  7366. uint8_t aq = ((bit_sub<26,1>(instr)));
  7367. if(this->disass_enabled){
  7368. /* generate console output when executing the command */
  7369. auto mnemonic = fmt::format(
  7370. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amominu.w"),
  7371. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7372. std::vector<Value*> args {
  7373. this->core_ptr,
  7374. this->gen_const(64, pc.val),
  7375. this->builder.CreateGlobalStringPtr(mnemonic),
  7376. };
  7377. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7378. }
  7379. Value* cur_pc_val = this->gen_const(32, pc.val);
  7380. pc=pc+4;
  7381. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7382. Value* res1_val = this->gen_ext(
  7383. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7384. 32,
  7385. true);
  7386. if(rd != 0){
  7387. Value* Xtmp0_val = res1_val;
  7388. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7389. }
  7390. Value* res2_val = this->gen_choose(
  7391. this->builder.CreateICmp(
  7392. ICmpInst::ICMP_UGT,
  7393. res1_val,
  7394. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0)),
  7395. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7396. res1_val,
  7397. 32);
  7398. Value* MEMtmp1_val = res2_val;
  7399. this->gen_write_mem(
  7400. traits<ARCH>::MEM,
  7401. offs_val,
  7402. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7403. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7404. this->gen_sync(POST_SYNC, 149);
  7405. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7406. this->gen_trap_check(bb);
  7407. return std::make_tuple(CONT, bb);
  7408. }
  7409. /* instruction 150: AMOMAXU.W */
  7410. std::tuple<continuation_e, BasicBlock*> __amomaxu_w(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7411. bb->setName("AMOMAXU.W");
  7412. this->gen_sync(PRE_SYNC, 150);
  7413. uint8_t rd = ((bit_sub<7,5>(instr)));
  7414. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7415. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7416. uint8_t rl = ((bit_sub<25,1>(instr)));
  7417. uint8_t aq = ((bit_sub<26,1>(instr)));
  7418. if(this->disass_enabled){
  7419. /* generate console output when executing the command */
  7420. auto mnemonic = fmt::format(
  7421. "{mnemonic:10} {rd}, {rs1}, {rs2} (aqu={aq},rel={rl})", fmt::arg("mnemonic", "amomaxu.w"),
  7422. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)), fmt::arg("aq", aq), fmt::arg("rl", rl));
  7423. std::vector<Value*> args {
  7424. this->core_ptr,
  7425. this->gen_const(64, pc.val),
  7426. this->builder.CreateGlobalStringPtr(mnemonic),
  7427. };
  7428. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7429. }
  7430. Value* cur_pc_val = this->gen_const(32, pc.val);
  7431. pc=pc+4;
  7432. Value* offs_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 0);
  7433. Value* res1_val = this->gen_ext(
  7434. this->gen_read_mem(traits<ARCH>::MEM, offs_val, 32/8),
  7435. 32,
  7436. true);
  7437. if(rd != 0){
  7438. Value* Xtmp0_val = res1_val;
  7439. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7440. }
  7441. Value* res2_val = this->gen_choose(
  7442. this->builder.CreateICmp(
  7443. ICmpInst::ICMP_ULT,
  7444. res1_val,
  7445. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0)),
  7446. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7447. res1_val,
  7448. 32);
  7449. Value* MEMtmp1_val = res2_val;
  7450. this->gen_write_mem(
  7451. traits<ARCH>::MEM,
  7452. offs_val,
  7453. this->builder.CreateZExtOrTrunc(MEMtmp1_val,this->get_type(32)));
  7454. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7455. this->gen_sync(POST_SYNC, 150);
  7456. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7457. this->gen_trap_check(bb);
  7458. return std::make_tuple(CONT, bb);
  7459. }
  7460. /* instruction 151: MUL */
  7461. std::tuple<continuation_e, BasicBlock*> __mul(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7462. bb->setName("MUL");
  7463. this->gen_sync(PRE_SYNC, 151);
  7464. uint8_t rd = ((bit_sub<7,5>(instr)));
  7465. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7466. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7467. if(this->disass_enabled){
  7468. /* generate console output when executing the command */
  7469. auto mnemonic = fmt::format(
  7470. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "mul"),
  7471. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  7472. std::vector<Value*> args {
  7473. this->core_ptr,
  7474. this->gen_const(64, pc.val),
  7475. this->builder.CreateGlobalStringPtr(mnemonic),
  7476. };
  7477. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7478. }
  7479. Value* cur_pc_val = this->gen_const(32, pc.val);
  7480. pc=pc+4;
  7481. if(rd != 0){
  7482. Value* res_val = this->builder.CreateMul(
  7483. this->gen_ext(
  7484. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  7485. 128,
  7486. false),
  7487. this->gen_ext(
  7488. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7489. 128,
  7490. false));
  7491. Value* Xtmp0_val = this->gen_ext(
  7492. res_val,
  7493. 32,
  7494. false);
  7495. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7496. }
  7497. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7498. this->gen_sync(POST_SYNC, 151);
  7499. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7500. this->gen_trap_check(bb);
  7501. return std::make_tuple(CONT, bb);
  7502. }
  7503. /* instruction 152: MULH */
  7504. std::tuple<continuation_e, BasicBlock*> __mulh(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7505. bb->setName("MULH");
  7506. this->gen_sync(PRE_SYNC, 152);
  7507. uint8_t rd = ((bit_sub<7,5>(instr)));
  7508. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7509. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7510. if(this->disass_enabled){
  7511. /* generate console output when executing the command */
  7512. auto mnemonic = fmt::format(
  7513. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "mulh"),
  7514. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  7515. std::vector<Value*> args {
  7516. this->core_ptr,
  7517. this->gen_const(64, pc.val),
  7518. this->builder.CreateGlobalStringPtr(mnemonic),
  7519. };
  7520. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7521. }
  7522. Value* cur_pc_val = this->gen_const(32, pc.val);
  7523. pc=pc+4;
  7524. if(rd != 0){
  7525. Value* res_val = this->builder.CreateMul(
  7526. this->gen_ext(
  7527. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  7528. 128,
  7529. true),
  7530. this->gen_ext(
  7531. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7532. 128,
  7533. true));
  7534. Value* Xtmp0_val = this->gen_ext(
  7535. this->builder.CreateLShr(
  7536. res_val,
  7537. this->gen_const(32U, 32)),
  7538. 32,
  7539. false);
  7540. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7541. }
  7542. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7543. this->gen_sync(POST_SYNC, 152);
  7544. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7545. this->gen_trap_check(bb);
  7546. return std::make_tuple(CONT, bb);
  7547. }
  7548. /* instruction 153: MULHSU */
  7549. std::tuple<continuation_e, BasicBlock*> __mulhsu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7550. bb->setName("MULHSU");
  7551. this->gen_sync(PRE_SYNC, 153);
  7552. uint8_t rd = ((bit_sub<7,5>(instr)));
  7553. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7554. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7555. if(this->disass_enabled){
  7556. /* generate console output when executing the command */
  7557. auto mnemonic = fmt::format(
  7558. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "mulhsu"),
  7559. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  7560. std::vector<Value*> args {
  7561. this->core_ptr,
  7562. this->gen_const(64, pc.val),
  7563. this->builder.CreateGlobalStringPtr(mnemonic),
  7564. };
  7565. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7566. }
  7567. Value* cur_pc_val = this->gen_const(32, pc.val);
  7568. pc=pc+4;
  7569. if(rd != 0){
  7570. Value* res_val = this->builder.CreateMul(
  7571. this->gen_ext(
  7572. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  7573. 128,
  7574. true),
  7575. this->gen_ext(
  7576. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7577. 128,
  7578. false));
  7579. Value* Xtmp0_val = this->gen_ext(
  7580. this->builder.CreateLShr(
  7581. res_val,
  7582. this->gen_const(32U, 32)),
  7583. 32,
  7584. false);
  7585. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7586. }
  7587. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7588. this->gen_sync(POST_SYNC, 153);
  7589. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7590. this->gen_trap_check(bb);
  7591. return std::make_tuple(CONT, bb);
  7592. }
  7593. /* instruction 154: MULHU */
  7594. std::tuple<continuation_e, BasicBlock*> __mulhu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7595. bb->setName("MULHU");
  7596. this->gen_sync(PRE_SYNC, 154);
  7597. uint8_t rd = ((bit_sub<7,5>(instr)));
  7598. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7599. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7600. if(this->disass_enabled){
  7601. /* generate console output when executing the command */
  7602. auto mnemonic = fmt::format(
  7603. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "mulhu"),
  7604. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  7605. std::vector<Value*> args {
  7606. this->core_ptr,
  7607. this->gen_const(64, pc.val),
  7608. this->builder.CreateGlobalStringPtr(mnemonic),
  7609. };
  7610. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7611. }
  7612. Value* cur_pc_val = this->gen_const(32, pc.val);
  7613. pc=pc+4;
  7614. if(rd != 0){
  7615. Value* res_val = this->builder.CreateMul(
  7616. this->gen_ext(
  7617. this->gen_reg_load(rs1 + traits<ARCH>::X0, 0),
  7618. 128,
  7619. false),
  7620. this->gen_ext(
  7621. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7622. 128,
  7623. false));
  7624. Value* Xtmp0_val = this->gen_ext(
  7625. this->builder.CreateLShr(
  7626. res_val,
  7627. this->gen_const(32U, 32)),
  7628. 32,
  7629. false);
  7630. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7631. }
  7632. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7633. this->gen_sync(POST_SYNC, 154);
  7634. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7635. this->gen_trap_check(bb);
  7636. return std::make_tuple(CONT, bb);
  7637. }
  7638. /* instruction 155: DIV */
  7639. std::tuple<continuation_e, BasicBlock*> __div(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7640. bb->setName("DIV");
  7641. this->gen_sync(PRE_SYNC, 155);
  7642. uint8_t rd = ((bit_sub<7,5>(instr)));
  7643. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7644. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7645. if(this->disass_enabled){
  7646. /* generate console output when executing the command */
  7647. auto mnemonic = fmt::format(
  7648. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "div"),
  7649. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  7650. std::vector<Value*> args {
  7651. this->core_ptr,
  7652. this->gen_const(64, pc.val),
  7653. this->builder.CreateGlobalStringPtr(mnemonic),
  7654. };
  7655. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7656. }
  7657. Value* cur_pc_val = this->gen_const(32, pc.val);
  7658. pc=pc+4;
  7659. if(rd != 0){
  7660. {
  7661. BasicBlock* bbnext = BasicBlock::Create(this->mod->getContext(), "endif", this->func, this->leave_blk);
  7662. BasicBlock* bb_then = BasicBlock::Create(this->mod->getContext(), "thenbr", this->func, bbnext);
  7663. BasicBlock* bb_else = BasicBlock::Create(this->mod->getContext(), "elsebr", this->func, bbnext);
  7664. // this->builder.SetInsertPoint(bb);
  7665. this->gen_cond_branch(this->builder.CreateICmp(
  7666. ICmpInst::ICMP_NE,
  7667. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7668. this->gen_const(32U, 0)),
  7669. bb_then,
  7670. bb_else);
  7671. this->builder.SetInsertPoint(bb_then);
  7672. {
  7673. uint32_t M1_val = - 1;
  7674. uint8_t XLM1_val = 32 - 1;
  7675. uint32_t ONE_val = 1;
  7676. uint32_t MMIN_val = ONE_val << XLM1_val;
  7677. {
  7678. BasicBlock* bbnext = BasicBlock::Create(this->mod->getContext(), "endif", this->func, this->leave_blk);
  7679. BasicBlock* bb_then = BasicBlock::Create(this->mod->getContext(), "thenbr", this->func, bbnext);
  7680. BasicBlock* bb_else = BasicBlock::Create(this->mod->getContext(), "elsebr", this->func, bbnext);
  7681. // this->builder.SetInsertPoint(bb);
  7682. this->gen_cond_branch(this->builder.CreateAnd(
  7683. this->builder.CreateICmp(
  7684. ICmpInst::ICMP_EQ,
  7685. this->gen_reg_load(rs1 + traits<ARCH>::X0, 1),
  7686. this->gen_const(32U, MMIN_val)),
  7687. this->builder.CreateICmp(
  7688. ICmpInst::ICMP_EQ,
  7689. this->gen_reg_load(rs2 + traits<ARCH>::X0, 1),
  7690. this->gen_const(32U, M1_val))),
  7691. bb_then,
  7692. bb_else);
  7693. this->builder.SetInsertPoint(bb_then);
  7694. {
  7695. Value* Xtmp0_val = this->gen_const(32U, MMIN_val);
  7696. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7697. }
  7698. this->builder.CreateBr(bbnext);
  7699. this->builder.SetInsertPoint(bb_else);
  7700. {
  7701. Value* Xtmp1_val = this->builder.CreateSDiv(
  7702. this->gen_ext(
  7703. this->gen_reg_load(rs1 + traits<ARCH>::X0, 2),
  7704. 32, true),
  7705. this->gen_ext(
  7706. this->gen_reg_load(rs2 + traits<ARCH>::X0, 2),
  7707. 32, true));
  7708. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7709. }
  7710. this->builder.CreateBr(bbnext);
  7711. bb=bbnext;
  7712. }
  7713. this->builder.SetInsertPoint(bb);
  7714. }
  7715. this->builder.CreateBr(bbnext);
  7716. this->builder.SetInsertPoint(bb_else);
  7717. {
  7718. Value* Xtmp2_val = this->builder.CreateNeg(this->gen_const(32U, 1));
  7719. this->builder.CreateStore(Xtmp2_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7720. }
  7721. this->builder.CreateBr(bbnext);
  7722. bb=bbnext;
  7723. }
  7724. this->builder.SetInsertPoint(bb);
  7725. }
  7726. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7727. this->gen_sync(POST_SYNC, 155);
  7728. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7729. this->gen_trap_check(bb);
  7730. return std::make_tuple(CONT, bb);
  7731. }
  7732. /* instruction 156: DIVU */
  7733. std::tuple<continuation_e, BasicBlock*> __divu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7734. bb->setName("DIVU");
  7735. this->gen_sync(PRE_SYNC, 156);
  7736. uint8_t rd = ((bit_sub<7,5>(instr)));
  7737. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7738. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7739. if(this->disass_enabled){
  7740. /* generate console output when executing the command */
  7741. auto mnemonic = fmt::format(
  7742. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "divu"),
  7743. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  7744. std::vector<Value*> args {
  7745. this->core_ptr,
  7746. this->gen_const(64, pc.val),
  7747. this->builder.CreateGlobalStringPtr(mnemonic),
  7748. };
  7749. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7750. }
  7751. Value* cur_pc_val = this->gen_const(32, pc.val);
  7752. pc=pc+4;
  7753. if(rd != 0){
  7754. {
  7755. BasicBlock* bbnext = BasicBlock::Create(this->mod->getContext(), "endif", this->func, this->leave_blk);
  7756. BasicBlock* bb_then = BasicBlock::Create(this->mod->getContext(), "thenbr", this->func, bbnext);
  7757. BasicBlock* bb_else = BasicBlock::Create(this->mod->getContext(), "elsebr", this->func, bbnext);
  7758. // this->builder.SetInsertPoint(bb);
  7759. this->gen_cond_branch(this->builder.CreateICmp(
  7760. ICmpInst::ICMP_NE,
  7761. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7762. this->gen_const(32U, 0)),
  7763. bb_then,
  7764. bb_else);
  7765. this->builder.SetInsertPoint(bb_then);
  7766. {
  7767. Value* Xtmp0_val = this->builder.CreateUDiv(
  7768. this->gen_reg_load(rs1 + traits<ARCH>::X0, 1),
  7769. this->gen_reg_load(rs2 + traits<ARCH>::X0, 1));
  7770. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7771. }
  7772. this->builder.CreateBr(bbnext);
  7773. this->builder.SetInsertPoint(bb_else);
  7774. {
  7775. Value* Xtmp1_val = this->builder.CreateNeg(this->gen_const(32U, 1));
  7776. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7777. }
  7778. this->builder.CreateBr(bbnext);
  7779. bb=bbnext;
  7780. }
  7781. this->builder.SetInsertPoint(bb);
  7782. }
  7783. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7784. this->gen_sync(POST_SYNC, 156);
  7785. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7786. this->gen_trap_check(bb);
  7787. return std::make_tuple(CONT, bb);
  7788. }
  7789. /* instruction 157: REM */
  7790. std::tuple<continuation_e, BasicBlock*> __rem(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7791. bb->setName("REM");
  7792. this->gen_sync(PRE_SYNC, 157);
  7793. uint8_t rd = ((bit_sub<7,5>(instr)));
  7794. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7795. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7796. if(this->disass_enabled){
  7797. /* generate console output when executing the command */
  7798. auto mnemonic = fmt::format(
  7799. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "rem"),
  7800. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  7801. std::vector<Value*> args {
  7802. this->core_ptr,
  7803. this->gen_const(64, pc.val),
  7804. this->builder.CreateGlobalStringPtr(mnemonic),
  7805. };
  7806. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7807. }
  7808. Value* cur_pc_val = this->gen_const(32, pc.val);
  7809. pc=pc+4;
  7810. if(rd != 0){
  7811. {
  7812. BasicBlock* bbnext = BasicBlock::Create(this->mod->getContext(), "endif", this->func, this->leave_blk);
  7813. BasicBlock* bb_then = BasicBlock::Create(this->mod->getContext(), "thenbr", this->func, bbnext);
  7814. BasicBlock* bb_else = BasicBlock::Create(this->mod->getContext(), "elsebr", this->func, bbnext);
  7815. // this->builder.SetInsertPoint(bb);
  7816. this->gen_cond_branch(this->builder.CreateICmp(
  7817. ICmpInst::ICMP_NE,
  7818. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7819. this->gen_const(32U, 0)),
  7820. bb_then,
  7821. bb_else);
  7822. this->builder.SetInsertPoint(bb_then);
  7823. {
  7824. uint32_t M1_val = - 1;
  7825. uint32_t XLM1_val = 32 - 1;
  7826. uint32_t ONE_val = 1;
  7827. uint32_t MMIN_val = ONE_val << XLM1_val;
  7828. {
  7829. BasicBlock* bbnext = BasicBlock::Create(this->mod->getContext(), "endif", this->func, this->leave_blk);
  7830. BasicBlock* bb_then = BasicBlock::Create(this->mod->getContext(), "thenbr", this->func, bbnext);
  7831. BasicBlock* bb_else = BasicBlock::Create(this->mod->getContext(), "elsebr", this->func, bbnext);
  7832. // this->builder.SetInsertPoint(bb);
  7833. this->gen_cond_branch(this->builder.CreateAnd(
  7834. this->builder.CreateICmp(
  7835. ICmpInst::ICMP_EQ,
  7836. this->gen_reg_load(rs1 + traits<ARCH>::X0, 1),
  7837. this->gen_const(32U, MMIN_val)),
  7838. this->builder.CreateICmp(
  7839. ICmpInst::ICMP_EQ,
  7840. this->gen_reg_load(rs2 + traits<ARCH>::X0, 1),
  7841. this->gen_const(32U, M1_val))),
  7842. bb_then,
  7843. bb_else);
  7844. this->builder.SetInsertPoint(bb_then);
  7845. {
  7846. Value* Xtmp0_val = this->gen_const(32U, 0);
  7847. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7848. }
  7849. this->builder.CreateBr(bbnext);
  7850. this->builder.SetInsertPoint(bb_else);
  7851. {
  7852. Value* Xtmp1_val = this->builder.CreateSRem(
  7853. this->gen_ext(
  7854. this->gen_reg_load(rs1 + traits<ARCH>::X0, 2),
  7855. 32, true),
  7856. this->gen_ext(
  7857. this->gen_reg_load(rs2 + traits<ARCH>::X0, 2),
  7858. 32, true));
  7859. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7860. }
  7861. this->builder.CreateBr(bbnext);
  7862. bb=bbnext;
  7863. }
  7864. this->builder.SetInsertPoint(bb);
  7865. }
  7866. this->builder.CreateBr(bbnext);
  7867. this->builder.SetInsertPoint(bb_else);
  7868. {
  7869. Value* Xtmp2_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 1);
  7870. this->builder.CreateStore(Xtmp2_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7871. }
  7872. this->builder.CreateBr(bbnext);
  7873. bb=bbnext;
  7874. }
  7875. this->builder.SetInsertPoint(bb);
  7876. }
  7877. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7878. this->gen_sync(POST_SYNC, 157);
  7879. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7880. this->gen_trap_check(bb);
  7881. return std::make_tuple(CONT, bb);
  7882. }
  7883. /* instruction 158: REMU */
  7884. std::tuple<continuation_e, BasicBlock*> __remu(virt_addr_t& pc, code_word_t instr, BasicBlock* bb){
  7885. bb->setName("REMU");
  7886. this->gen_sync(PRE_SYNC, 158);
  7887. uint8_t rd = ((bit_sub<7,5>(instr)));
  7888. uint8_t rs1 = ((bit_sub<15,5>(instr)));
  7889. uint8_t rs2 = ((bit_sub<20,5>(instr)));
  7890. if(this->disass_enabled){
  7891. /* generate console output when executing the command */
  7892. auto mnemonic = fmt::format(
  7893. "{mnemonic:10} {rd}, {rs1}, {rs2}", fmt::arg("mnemonic", "remu"),
  7894. fmt::arg("rd", name(rd)), fmt::arg("rs1", name(rs1)), fmt::arg("rs2", name(rs2)));
  7895. std::vector<Value*> args {
  7896. this->core_ptr,
  7897. this->gen_const(64, pc.val),
  7898. this->builder.CreateGlobalStringPtr(mnemonic),
  7899. };
  7900. this->builder.CreateCall(this->mod->getFunction("print_disass"), args);
  7901. }
  7902. Value* cur_pc_val = this->gen_const(32, pc.val);
  7903. pc=pc+4;
  7904. if(rd != 0){
  7905. {
  7906. BasicBlock* bbnext = BasicBlock::Create(this->mod->getContext(), "endif", this->func, this->leave_blk);
  7907. BasicBlock* bb_then = BasicBlock::Create(this->mod->getContext(), "thenbr", this->func, bbnext);
  7908. BasicBlock* bb_else = BasicBlock::Create(this->mod->getContext(), "elsebr", this->func, bbnext);
  7909. // this->builder.SetInsertPoint(bb);
  7910. this->gen_cond_branch(this->builder.CreateICmp(
  7911. ICmpInst::ICMP_NE,
  7912. this->gen_reg_load(rs2 + traits<ARCH>::X0, 0),
  7913. this->gen_const(32U, 0)),
  7914. bb_then,
  7915. bb_else);
  7916. this->builder.SetInsertPoint(bb_then);
  7917. {
  7918. Value* Xtmp0_val = this->builder.CreateURem(
  7919. this->gen_reg_load(rs1 + traits<ARCH>::X0, 1),
  7920. this->gen_reg_load(rs2 + traits<ARCH>::X0, 1));
  7921. this->builder.CreateStore(Xtmp0_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7922. }
  7923. this->builder.CreateBr(bbnext);
  7924. this->builder.SetInsertPoint(bb_else);
  7925. {
  7926. Value* Xtmp1_val = this->gen_reg_load(rs1 + traits<ARCH>::X0, 1);
  7927. this->builder.CreateStore(Xtmp1_val, get_reg_ptr(rd + traits<ARCH>::X0), false);
  7928. }
  7929. this->builder.CreateBr(bbnext);
  7930. bb=bbnext;
  7931. }
  7932. this->builder.SetInsertPoint(bb);
  7933. }
  7934. this->gen_set_pc(pc, traits<ARCH>::NEXT_PC);
  7935. this->gen_sync(POST_SYNC, 158);
  7936. bb = BasicBlock::Create(this->mod->getContext(), "entry", this->func, this->leave_blk); /* create next BasicBlock in chain */
  7937. this->gen_trap_check(bb);
  7938. return std::make_tuple(CONT, bb);
  7939. }
  7940. /****************************************************************************
  7941. * end opcode definitions
  7942. ****************************************************************************/
  7943. std::tuple<continuation_e, BasicBlock *> illegal_intruction(virt_addr_t &pc, code_word_t instr, BasicBlock *bb) {
  7944. this->gen_sync(iss::PRE_SYNC, instr_descr.size());
  7945. this->builder.CreateStore(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::NEXT_PC), true),
  7946. get_reg_ptr(traits<ARCH>::PC), true);
  7947. this->builder.CreateStore(
  7948. this->builder.CreateAdd(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::ICOUNT), true),
  7949. this->gen_const(64U, 1)),
  7950. get_reg_ptr(traits<ARCH>::ICOUNT), true);
  7951. pc = pc + ((instr & 3) == 3 ? 4 : 2);
  7952. this->gen_raise_trap(0, 2); // illegal instruction trap
  7953. this->gen_sync(iss::POST_SYNC, instr_descr.size());
  7954. this->gen_trap_check(this->leave_blk);
  7955. return std::make_tuple(BRANCH, nullptr);
  7956. }
  7957. };
  7958. template <typename CODE_WORD> void debug_fn(CODE_WORD insn) {
  7959. volatile CODE_WORD x = insn;
  7960. insn = 2 * x;
  7961. }
  7962. template <typename ARCH> vm_impl<ARCH>::vm_impl() { this(new ARCH()); }
  7963. template <typename ARCH>
  7964. vm_impl<ARCH>::vm_impl(ARCH &core, unsigned core_id, unsigned cluster_id)
  7965. : vm_base<ARCH>(core, core_id, cluster_id) {
  7966. qlut[0] = lut_00.data();
  7967. qlut[1] = lut_01.data();
  7968. qlut[2] = lut_10.data();
  7969. qlut[3] = lut_11.data();
  7970. for (auto instr : instr_descr) {
  7971. auto quantrant = instr.value & 0x3;
  7972. expand_bit_mask(29, lutmasks[quantrant], instr.value >> 2, instr.mask >> 2, 0, qlut[quantrant], instr.op);
  7973. }
  7974. }
  7975. template <typename ARCH>
  7976. std::tuple<continuation_e, BasicBlock *>
  7977. vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt, BasicBlock *this_block) {
  7978. // we fetch at max 4 byte, alignment is 2
  7979. enum {TRAP_ID=1<<16};
  7980. code_word_t insn = 0;
  7981. const typename traits<ARCH>::addr_t upper_bits = ~traits<ARCH>::PGMASK;
  7982. phys_addr_t paddr(pc);
  7983. auto *const data = (uint8_t *)&insn;
  7984. paddr = this->core.v2p(pc);
  7985. if ((pc.val & upper_bits) != ((pc.val + 2) & upper_bits)) { // we may cross a page boundary
  7986. auto res = this->core.read(paddr, 2, data);
  7987. if (res != iss::Ok) throw trap_access(TRAP_ID, pc.val);
  7988. if ((insn & 0x3) == 0x3) { // this is a 32bit instruction
  7989. res = this->core.read(this->core.v2p(pc + 2), 2, data + 2);
  7990. }
  7991. } else {
  7992. auto res = this->core.read(paddr, 4, data);
  7993. if (res != iss::Ok) throw trap_access(TRAP_ID, pc.val);
  7994. }
  7995. if (insn == 0x0000006f || (insn&0xffff)==0xa001) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
  7996. // curr pc on stack
  7997. ++inst_cnt;
  7998. auto lut_val = extract_fields(insn);
  7999. auto f = qlut[insn & 0x3][lut_val];
  8000. if (f == nullptr) {
  8001. f = &this_class::illegal_intruction;
  8002. }
  8003. return (this->*f)(pc, insn, this_block);
  8004. }
  8005. template <typename ARCH> void vm_impl<ARCH>::gen_leave_behavior(BasicBlock *leave_blk) {
  8006. this->builder.SetInsertPoint(leave_blk);
  8007. this->builder.CreateRet(this->builder.CreateLoad(get_reg_ptr(arch::traits<ARCH>::NEXT_PC), false));
  8008. }
  8009. template <typename ARCH> void vm_impl<ARCH>::gen_raise_trap(uint16_t trap_id, uint16_t cause) {
  8010. auto *TRAP_val = this->gen_const(32, 0x80 << 24 | (cause << 16) | trap_id);
  8011. this->builder.CreateStore(TRAP_val, get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
  8012. this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  8013. }
  8014. template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(unsigned lvl) {
  8015. std::vector<Value *> args{ this->core_ptr, ConstantInt::get(getContext(), APInt(64, lvl)) };
  8016. this->builder.CreateCall(this->mod->getFunction("leave_trap"), args);
  8017. auto *PC_val = this->gen_read_mem(traits<ARCH>::CSR, (lvl << 8) + 0x41, traits<ARCH>::XLEN / 8);
  8018. this->builder.CreateStore(PC_val, get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  8019. this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()), get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  8020. }
  8021. template <typename ARCH> void vm_impl<ARCH>::gen_wait(unsigned type) {
  8022. std::vector<Value *> args{ this->core_ptr, ConstantInt::get(getContext(), APInt(64, type)) };
  8023. this->builder.CreateCall(this->mod->getFunction("wait"), args);
  8024. }
  8025. template <typename ARCH> void vm_impl<ARCH>::gen_trap_behavior(BasicBlock *trap_blk) {
  8026. this->builder.SetInsertPoint(trap_blk);
  8027. auto *trap_state_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::TRAP_STATE), true);
  8028. this->builder.CreateStore(this->gen_const(32U, std::numeric_limits<uint32_t>::max()),
  8029. get_reg_ptr(traits<ARCH>::LAST_BRANCH), false);
  8030. std::vector<Value *> args{this->core_ptr, this->adj_to64(trap_state_val),
  8031. this->adj_to64(this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::PC), false))};
  8032. this->builder.CreateCall(this->mod->getFunction("enter_trap"), args);
  8033. auto *trap_addr_val = this->builder.CreateLoad(get_reg_ptr(traits<ARCH>::NEXT_PC), false);
  8034. this->builder.CreateRet(trap_addr_val);
  8035. }
  8036. template <typename ARCH> inline void vm_impl<ARCH>::gen_trap_check(BasicBlock *bb) {
  8037. auto *v = this->builder.CreateLoad(get_reg_ptr(arch::traits<ARCH>::TRAP_STATE), true);
  8038. this->gen_cond_branch(this->builder.CreateICmp(
  8039. ICmpInst::ICMP_EQ, v,
  8040. ConstantInt::get(getContext(), APInt(v->getType()->getIntegerBitWidth(), 0))),
  8041. bb, this->trap_blk, 1);
  8042. }
  8043. } // namespace rv32gc
  8044. template <>
  8045. std::unique_ptr<vm_if> create<arch::rv32gc>(arch::rv32gc *core, unsigned short port, bool dump) {
  8046. auto ret = new rv32gc::vm_impl<arch::rv32gc>(*core, dump);
  8047. if (port != 0) debugger::server<debugger::gdb_session>::run_server(ret, port);
  8048. return std::unique_ptr<vm_if>(ret);
  8049. }
  8050. } // namespace iss