build.rs 136 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976
  1. #![feature(i128_type)]
  2. use std::env;
  3. fn main() {
  4. println!("cargo:rerun-if-changed=build.rs");
  5. let target = env::var("TARGET").unwrap();
  6. // Emscripten's runtime includes all the builtins
  7. if target.contains("emscripten") {
  8. return;
  9. }
  10. // Forcibly enable memory intrinsics on wasm32 as we don't have a libc to
  11. // provide them.
  12. if target.contains("wasm32") {
  13. println!("cargo:rustc-cfg=feature=\"mem\"");
  14. }
  15. // NOTE we are going to assume that llvm-target, what determines our codegen option, matches the
  16. // target triple. This is usually correct for our built-in targets but can break in presence of
  17. // custom targets, which can have arbitrary names.
  18. let llvm_target = target.split('-').collect::<Vec<_>>();
  19. // Build test files
  20. #[cfg(feature = "gen-tests")]
  21. tests::generate();
  22. // Build missing intrinsics from compiler-rt C source code. If we're
  23. // mangling names though we assume that we're also in test mode so we don't
  24. // build anything and we rely on the upstream implementation of compiler-rt
  25. // functions
  26. if !cfg!(feature = "mangled-names") && cfg!(feature = "c") {
  27. // no C compiler for wasm
  28. if !target.contains("wasm32") {
  29. #[cfg(feature = "c")]
  30. c::compile(&llvm_target);
  31. println!("cargo:rustc-cfg=use_c");
  32. }
  33. }
  34. // To compile intrinsics.rs for thumb targets, where there is no libc
  35. if llvm_target[0].starts_with("thumb") {
  36. println!("cargo:rustc-cfg=thumb")
  37. }
  38. // compiler-rt `cfg`s away some intrinsics for thumbv6m because that target doesn't have full
  39. // THUMBv2 support. We have to cfg our code accordingly.
  40. if llvm_target[0] == "thumbv6m" {
  41. println!("cargo:rustc-cfg=thumbv6m")
  42. }
  43. // Only emit the ARM Linux atomic emulation on pre-ARMv6 architectures.
  44. if llvm_target[0] == "armv4t" || llvm_target[0] == "armv5te" {
  45. println!("cargo:rustc-cfg=kernel_user_helpers")
  46. }
  47. }
  48. #[cfg(feature = "gen-tests")]
  49. mod tests {
  50. extern crate cast;
  51. extern crate rand;
  52. use std::collections::HashSet;
  53. use std::fmt::Write;
  54. use std::fs::File;
  55. use std::hash::Hash;
  56. use std::path::PathBuf;
  57. use std::{env, mem};
  58. use self::cast::{f32, f64, u32, u64, u128, i32, i64, i128};
  59. use self::rand::Rng;
  60. const NTESTS: usize = 10_000;
  61. macro_rules! test {
  62. ($($intrinsic:ident,)+) => {
  63. $(
  64. mk_file::<$intrinsic>();
  65. )+
  66. }
  67. }
  68. pub fn generate() {
  69. // TODO move to main
  70. test! {
  71. // float/add.rs
  72. Adddf3,
  73. Addsf3,
  74. // float/cmp.rs
  75. Gedf2,
  76. Gesf2,
  77. Ledf2,
  78. Lesf2,
  79. // float/conv.rs
  80. Fixdfdi,
  81. Fixdfsi,
  82. Fixsfdi,
  83. Fixsfsi,
  84. Fixsfti,
  85. Fixdfti,
  86. Fixunsdfdi,
  87. Fixunsdfsi,
  88. Fixunssfdi,
  89. Fixunssfsi,
  90. Fixunssfti,
  91. Fixunsdfti,
  92. Floatdidf,
  93. Floatsidf,
  94. Floatsisf,
  95. Floattisf,
  96. Floattidf,
  97. Floatundidf,
  98. Floatunsidf,
  99. Floatunsisf,
  100. Floatuntisf,
  101. Floatuntidf,
  102. // float/pow.rs
  103. Powidf2,
  104. Powisf2,
  105. // float/sub.rs
  106. Subdf3,
  107. Subsf3,
  108. // float/mul.rs
  109. Mulsf3,
  110. Muldf3,
  111. Mulsf3vfp,
  112. Muldf3vfp,
  113. // float/div.rs
  114. Divsf3,
  115. Divdf3,
  116. Divsf3vfp,
  117. Divdf3vfp,
  118. // int/addsub.rs
  119. AddU128,
  120. AddI128,
  121. AddoU128,
  122. AddoI128,
  123. SubU128,
  124. SubI128,
  125. SuboU128,
  126. SuboI128,
  127. // int/mul.rs
  128. Muldi3,
  129. Mulodi4,
  130. Mulosi4,
  131. Muloti4,
  132. Multi3,
  133. // int/sdiv.rs
  134. Divdi3,
  135. Divmoddi4,
  136. Divmodsi4,
  137. Divsi3,
  138. Divti3,
  139. Moddi3,
  140. Modsi3,
  141. Modti3,
  142. // int/shift.rs
  143. Ashldi3,
  144. Ashlti3,
  145. Ashrdi3,
  146. Ashrti3,
  147. Lshrdi3,
  148. Lshrti3,
  149. // int/udiv.rs
  150. Udivdi3,
  151. Udivmoddi4,
  152. Udivmodsi4,
  153. Udivmodti4,
  154. Udivsi3,
  155. Udivti3,
  156. Umoddi3,
  157. Umodsi3,
  158. Umodti3,
  159. }
  160. }
  161. #[derive(Eq, Hash, PartialEq)]
  162. pub struct Adddf3 {
  163. a: u64, // f64
  164. b: u64, // f64
  165. c: u64, // f64
  166. }
  167. impl TestCase for Adddf3 {
  168. fn name() -> &'static str {
  169. "adddf3"
  170. }
  171. fn generate<R>(rng: &mut R) -> Option<Self>
  172. where
  173. R: Rng,
  174. Self: Sized,
  175. {
  176. let a = gen_f64(rng);
  177. let b = gen_f64(rng);
  178. let c = a + b;
  179. // TODO accept NaNs. We don't do that right now because we can't check
  180. // for NaN-ness on the thumb targets (due to missing intrinsics)
  181. if a.is_nan() || b.is_nan() || c.is_nan() {
  182. return None;
  183. }
  184. Some(
  185. Adddf3 {
  186. a: to_u64(a),
  187. b: to_u64(b),
  188. c: to_u64(c),
  189. },
  190. )
  191. }
  192. fn to_string(&self, buffer: &mut String) {
  193. writeln!(
  194. buffer,
  195. "(({a}, {b}), {c}),",
  196. a = self.a,
  197. b = self.b,
  198. c = self.c
  199. )
  200. .unwrap();
  201. }
  202. fn prologue() -> &'static str {
  203. r#"
  204. #[cfg(all(target_arch = "arm",
  205. not(any(target_env = "gnu", target_env = "musl")),
  206. target_os = "linux",
  207. test))]
  208. use core::mem;
  209. #[cfg(not(all(target_arch = "arm",
  210. not(any(target_env = "gnu", target_env = "musl")),
  211. target_os = "linux",
  212. test)))]
  213. use std::mem;
  214. use compiler_builtins::float::add::__adddf3;
  215. fn mk_f64(x: u64) -> f64 {
  216. unsafe { mem::transmute(x) }
  217. }
  218. fn to_u64(x: f64) -> u64 {
  219. unsafe { mem::transmute(x) }
  220. }
  221. static TEST_CASES: &[((u64, u64), u64)] = &[
  222. "#
  223. }
  224. fn epilogue() -> &'static str {
  225. "
  226. ];
  227. #[test]
  228. fn adddf3() {
  229. for &((a, b), c) in TEST_CASES {
  230. let c_ = __adddf3(mk_f64(a), mk_f64(b));
  231. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  232. }
  233. }
  234. "
  235. }
  236. }
  237. #[derive(Eq, Hash, PartialEq)]
  238. pub struct Addsf3 {
  239. a: u32, // f32
  240. b: u32, // f32
  241. c: u32, // f32
  242. }
  243. impl TestCase for Addsf3 {
  244. fn name() -> &'static str {
  245. "addsf3"
  246. }
  247. fn generate<R>(rng: &mut R) -> Option<Self>
  248. where
  249. R: Rng,
  250. Self: Sized,
  251. {
  252. let a = gen_f32(rng);
  253. let b = gen_f32(rng);
  254. let c = a + b;
  255. // TODO accept NaNs. We don't do that right now because we can't check
  256. // for NaN-ness on the thumb targets (due to missing intrinsics)
  257. if a.is_nan() || b.is_nan() || c.is_nan() {
  258. return None;
  259. }
  260. Some(
  261. Addsf3 {
  262. a: to_u32(a),
  263. b: to_u32(b),
  264. c: to_u32(c),
  265. },
  266. )
  267. }
  268. fn to_string(&self, buffer: &mut String) {
  269. writeln!(
  270. buffer,
  271. "(({a}, {b}), {c}),",
  272. a = self.a,
  273. b = self.b,
  274. c = self.c
  275. )
  276. .unwrap();
  277. }
  278. fn prologue() -> &'static str {
  279. r#"
  280. #[cfg(all(target_arch = "arm",
  281. not(any(target_env = "gnu", target_env = "musl")),
  282. target_os = "linux",
  283. test))]
  284. use core::mem;
  285. #[cfg(not(all(target_arch = "arm",
  286. not(any(target_env = "gnu", target_env = "musl")),
  287. target_os = "linux",
  288. test)))]
  289. use std::mem;
  290. use compiler_builtins::float::add::__addsf3;
  291. fn mk_f32(x: u32) -> f32 {
  292. unsafe { mem::transmute(x) }
  293. }
  294. fn to_u32(x: f32) -> u32 {
  295. unsafe { mem::transmute(x) }
  296. }
  297. static TEST_CASES: &[((u32, u32), u32)] = &[
  298. "#
  299. }
  300. fn epilogue() -> &'static str {
  301. "
  302. ];
  303. #[test]
  304. fn addsf3() {
  305. for &((a, b), c) in TEST_CASES {
  306. let c_ = __addsf3(mk_f32(a), mk_f32(b));
  307. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  308. }
  309. }
  310. "
  311. }
  312. }
  313. #[derive(Eq, Hash, PartialEq)]
  314. pub struct AddU128 {
  315. a: u128,
  316. b: u128,
  317. c: u128,
  318. }
  319. impl TestCase for AddU128 {
  320. fn name() -> &'static str {
  321. "u128_add"
  322. }
  323. fn generate<R>(rng: &mut R) -> Option<Self>
  324. where
  325. R: Rng,
  326. Self: Sized,
  327. {
  328. let a = gen_u128(rng);
  329. let b = gen_u128(rng);
  330. let c = a.wrapping_add(b);
  331. Some(AddU128 { a, b, c })
  332. }
  333. fn to_string(&self, buffer: &mut String) {
  334. writeln!(
  335. buffer,
  336. "(({a}, {b}), {c}),",
  337. a = self.a,
  338. b = self.b,
  339. c = self.c
  340. )
  341. .unwrap();
  342. }
  343. fn prologue() -> &'static str {
  344. "
  345. use compiler_builtins::int::addsub::rust_u128_add;
  346. static TEST_CASES: &[((u128, u128), u128)] = &[
  347. "
  348. }
  349. fn epilogue() -> &'static str {
  350. "
  351. ];
  352. #[test]
  353. fn u128_add() {
  354. for &((a, b), c) in TEST_CASES {
  355. let c_ = rust_u128_add(a, b);
  356. assert_eq!(((a, b), c), ((a, b), c_));
  357. }
  358. }
  359. "
  360. }
  361. }
  362. #[derive(Eq, Hash, PartialEq)]
  363. pub struct AddI128 {
  364. a: i128,
  365. b: i128,
  366. c: i128,
  367. }
  368. impl TestCase for AddI128 {
  369. fn name() -> &'static str {
  370. "i128_add"
  371. }
  372. fn generate<R>(rng: &mut R) -> Option<Self>
  373. where
  374. R: Rng,
  375. Self: Sized,
  376. {
  377. let a = gen_i128(rng);
  378. let b = gen_i128(rng);
  379. let c = a.wrapping_add(b);
  380. Some(AddI128 { a, b, c })
  381. }
  382. fn to_string(&self, buffer: &mut String) {
  383. writeln!(
  384. buffer,
  385. "(({a}, {b}), {c}),",
  386. a = self.a,
  387. b = self.b,
  388. c = self.c
  389. )
  390. .unwrap();
  391. }
  392. fn prologue() -> &'static str {
  393. "
  394. use compiler_builtins::int::addsub::rust_i128_add;
  395. static TEST_CASES: &[((i128, i128), i128)] = &[
  396. "
  397. }
  398. fn epilogue() -> &'static str {
  399. "
  400. ];
  401. #[test]
  402. fn i128_add() {
  403. for &((a, b), c) in TEST_CASES {
  404. let c_ = rust_i128_add(a, b);
  405. assert_eq!(((a, b), c), ((a, b), c_));
  406. }
  407. }
  408. "
  409. }
  410. }
  411. #[derive(Eq, Hash, PartialEq)]
  412. pub struct AddoU128 {
  413. a: u128,
  414. b: u128,
  415. c: u128,
  416. d: bool,
  417. }
  418. impl TestCase for AddoU128 {
  419. fn name() -> &'static str {
  420. "u128_addo"
  421. }
  422. fn generate<R>(rng: &mut R) -> Option<Self>
  423. where
  424. R: Rng,
  425. Self: Sized,
  426. {
  427. let a = gen_u128(rng);
  428. let b = gen_u128(rng);
  429. let (c, d) = a.overflowing_add(b);
  430. Some(AddoU128 { a, b, c, d })
  431. }
  432. fn to_string(&self, buffer: &mut String) {
  433. writeln!(
  434. buffer,
  435. "(({a}, {b}), ({c}, {d})),",
  436. a = self.a,
  437. b = self.b,
  438. c = self.c,
  439. d = self.d
  440. )
  441. .unwrap();
  442. }
  443. fn prologue() -> &'static str {
  444. "
  445. use compiler_builtins::int::addsub::rust_u128_addo;
  446. static TEST_CASES: &[((u128, u128), (u128, bool))] = &[
  447. "
  448. }
  449. fn epilogue() -> &'static str {
  450. "
  451. ];
  452. #[test]
  453. fn u128_addo() {
  454. for &((a, b), (c, d)) in TEST_CASES {
  455. let (c_, d_) = rust_u128_addo(a, b);
  456. assert_eq!(((a, b), (c, d)), ((a, b), (c_, d_)));
  457. }
  458. }
  459. "
  460. }
  461. }
  462. #[derive(Eq, Hash, PartialEq)]
  463. pub struct AddoI128 {
  464. a: i128,
  465. b: i128,
  466. c: i128,
  467. d: bool,
  468. }
  469. impl TestCase for AddoI128 {
  470. fn name() -> &'static str {
  471. "i128_addo"
  472. }
  473. fn generate<R>(rng: &mut R) -> Option<Self>
  474. where
  475. R: Rng,
  476. Self: Sized,
  477. {
  478. let a = gen_i128(rng);
  479. let b = gen_i128(rng);
  480. let (c, d) = a.overflowing_add(b);
  481. Some(AddoI128 { a, b, c, d })
  482. }
  483. fn to_string(&self, buffer: &mut String) {
  484. writeln!(
  485. buffer,
  486. "(({a}, {b}), ({c}, {d})),",
  487. a = self.a,
  488. b = self.b,
  489. c = self.c,
  490. d = self.d
  491. )
  492. .unwrap();
  493. }
  494. fn prologue() -> &'static str {
  495. "
  496. use compiler_builtins::int::addsub::rust_i128_addo;
  497. static TEST_CASES: &[((i128, i128), (i128, bool))] = &[
  498. "
  499. }
  500. fn epilogue() -> &'static str {
  501. "
  502. ];
  503. #[test]
  504. fn i128_addo() {
  505. for &((a, b), (c, d)) in TEST_CASES {
  506. let (c_, d_) = rust_i128_addo(a, b);
  507. assert_eq!(((a, b), (c, d)), ((a, b), (c_, d_)));
  508. }
  509. }
  510. "
  511. }
  512. }
  513. #[derive(Eq, Hash, PartialEq)]
  514. pub struct Ashldi3 {
  515. a: u64,
  516. b: u32,
  517. c: u64,
  518. }
  519. impl TestCase for Ashldi3 {
  520. fn name() -> &'static str {
  521. "ashldi3"
  522. }
  523. fn generate<R>(rng: &mut R) -> Option<Self>
  524. where
  525. R: Rng,
  526. Self: Sized,
  527. {
  528. let a = gen_u64(rng);
  529. let b = (rng.gen::<u8>() % 64) as u32;
  530. let c = a << b;
  531. Some(Ashldi3 { a, b, c })
  532. }
  533. fn to_string(&self, buffer: &mut String) {
  534. writeln!(
  535. buffer,
  536. "(({a}, {b}), {c}),",
  537. a = self.a,
  538. b = self.b,
  539. c = self.c
  540. )
  541. .unwrap();
  542. }
  543. fn prologue() -> &'static str {
  544. "
  545. use compiler_builtins::int::shift::__ashldi3;
  546. static TEST_CASES: &[((u64, u32), u64)] = &[
  547. "
  548. }
  549. fn epilogue() -> &'static str {
  550. "
  551. ];
  552. #[test]
  553. fn ashldi3() {
  554. for &((a, b), c) in TEST_CASES {
  555. let c_ = __ashldi3(a, b);
  556. assert_eq!(((a, b), c), ((a, b), c_));
  557. }
  558. }
  559. "
  560. }
  561. }
  562. #[derive(Eq, Hash, PartialEq)]
  563. pub struct Ashlti3 {
  564. a: u128,
  565. b: u32,
  566. c: u128,
  567. }
  568. impl TestCase for Ashlti3 {
  569. fn name() -> &'static str {
  570. "ashlti3"
  571. }
  572. fn generate<R>(rng: &mut R) -> Option<Self>
  573. where
  574. R: Rng,
  575. Self: Sized,
  576. {
  577. let a = gen_u128(rng);
  578. let b = (rng.gen::<u8>() % 128) as u32;
  579. let c = a << b;
  580. Some(Ashlti3 { a, b, c })
  581. }
  582. fn to_string(&self, buffer: &mut String) {
  583. writeln!(
  584. buffer,
  585. "(({a}, {b}), {c}),",
  586. a = self.a,
  587. b = self.b,
  588. c = self.c
  589. )
  590. .unwrap();
  591. }
  592. fn prologue() -> &'static str {
  593. "
  594. use compiler_builtins::int::shift::__ashlti3;
  595. static TEST_CASES: &[((u128, u32), u128)] = &[
  596. "
  597. }
  598. fn epilogue() -> &'static str {
  599. "
  600. ];
  601. #[test]
  602. fn ashlti3() {
  603. for &((a, b), c) in TEST_CASES {
  604. let c_ = __ashlti3(a, b);
  605. assert_eq!(((a, b), c), ((a, b), c_));
  606. }
  607. }
  608. "
  609. }
  610. }
  611. #[derive(Eq, Hash, PartialEq)]
  612. pub struct Ashrdi3 {
  613. a: i64,
  614. b: u32,
  615. c: i64,
  616. }
  617. impl TestCase for Ashrdi3 {
  618. fn name() -> &'static str {
  619. "ashrdi3"
  620. }
  621. fn generate<R>(rng: &mut R) -> Option<Self>
  622. where
  623. R: Rng,
  624. Self: Sized,
  625. {
  626. let a = gen_i64(rng);
  627. let b = (rng.gen::<u8>() % 64) as u32;
  628. let c = a >> b;
  629. Some(Ashrdi3 { a, b, c })
  630. }
  631. fn to_string(&self, buffer: &mut String) {
  632. writeln!(
  633. buffer,
  634. "(({a}, {b}), {c}),",
  635. a = self.a,
  636. b = self.b,
  637. c = self.c
  638. )
  639. .unwrap();
  640. }
  641. fn prologue() -> &'static str {
  642. "
  643. use compiler_builtins::int::shift::__ashrdi3;
  644. static TEST_CASES: &[((i64, u32), i64)] = &[
  645. "
  646. }
  647. fn epilogue() -> &'static str {
  648. "
  649. ];
  650. #[test]
  651. fn ashrdi3() {
  652. for &((a, b), c) in TEST_CASES {
  653. let c_ = __ashrdi3(a, b);
  654. assert_eq!(((a, b), c), ((a, b), c_));
  655. }
  656. }
  657. "
  658. }
  659. }
  660. #[derive(Eq, Hash, PartialEq)]
  661. pub struct Ashrti3 {
  662. a: i128,
  663. b: u32,
  664. c: i128,
  665. }
  666. impl TestCase for Ashrti3 {
  667. fn name() -> &'static str {
  668. "ashrti3"
  669. }
  670. fn generate<R>(rng: &mut R) -> Option<Self>
  671. where
  672. R: Rng,
  673. Self: Sized,
  674. {
  675. let a = gen_i128(rng);
  676. let b = (rng.gen::<u8>() % 128) as u32;
  677. let c = a >> b;
  678. Some(Ashrti3 { a, b, c })
  679. }
  680. fn to_string(&self, buffer: &mut String) {
  681. writeln!(
  682. buffer,
  683. "(({a}, {b}), {c}),",
  684. a = self.a,
  685. b = self.b,
  686. c = self.c
  687. )
  688. .unwrap();
  689. }
  690. fn prologue() -> &'static str {
  691. "
  692. use compiler_builtins::int::shift::__ashrti3;
  693. static TEST_CASES: &[((i128, u32), i128)] = &[
  694. "
  695. }
  696. fn epilogue() -> &'static str {
  697. "
  698. ];
  699. #[test]
  700. fn ashrti3() {
  701. for &((a, b), c) in TEST_CASES {
  702. let c_ = __ashrti3(a, b);
  703. assert_eq!(((a, b), c), ((a, b), c_));
  704. }
  705. }
  706. "
  707. }
  708. }
  709. #[derive(Eq, Hash, PartialEq)]
  710. pub struct Divmoddi4 {
  711. a: i64,
  712. b: i64,
  713. c: i64,
  714. rem: i64,
  715. }
  716. impl TestCase for Divmoddi4 {
  717. fn name() -> &'static str {
  718. "divmoddi4"
  719. }
  720. fn generate<R>(rng: &mut R) -> Option<Self>
  721. where
  722. R: Rng,
  723. Self: Sized,
  724. {
  725. let a = gen_i64(rng);
  726. let b = gen_i64(rng);
  727. if b == 0 {
  728. return None;
  729. }
  730. let c = a / b;
  731. let rem = a % b;
  732. Some(Divmoddi4 { a, b, c, rem })
  733. }
  734. fn to_string(&self, buffer: &mut String) {
  735. writeln!(
  736. buffer,
  737. "(({a}, {b}), ({c}, {rem})),",
  738. a = self.a,
  739. b = self.b,
  740. c = self.c,
  741. rem = self.rem
  742. )
  743. .unwrap();
  744. }
  745. fn prologue() -> &'static str {
  746. "
  747. use compiler_builtins::int::sdiv::__divmoddi4;
  748. static TEST_CASES: &[((i64, i64), (i64, i64))] = &[
  749. "
  750. }
  751. fn epilogue() -> &'static str {
  752. "
  753. ];
  754. #[test]
  755. fn divmoddi4() {
  756. for &((a, b), (c, rem)) in TEST_CASES {
  757. let mut rem_ = 0;
  758. let c_ = __divmoddi4(a, b, &mut rem_);
  759. assert_eq!(((a, b), (c, rem)), ((a, b), (c_, rem_)));
  760. }
  761. }
  762. "
  763. }
  764. }
  765. #[derive(Eq, Hash, PartialEq)]
  766. pub struct Divdi3 {
  767. a: i64,
  768. b: i64,
  769. c: i64,
  770. }
  771. impl TestCase for Divdi3 {
  772. fn name() -> &'static str {
  773. "divdi3"
  774. }
  775. fn generate<R>(rng: &mut R) -> Option<Self>
  776. where
  777. R: Rng,
  778. Self: Sized,
  779. {
  780. let a = gen_i64(rng);
  781. let b = gen_i64(rng);
  782. if b == 0 {
  783. return None;
  784. }
  785. let c = a / b;
  786. Some(Divdi3 { a, b, c })
  787. }
  788. fn to_string(&self, buffer: &mut String) {
  789. writeln!(
  790. buffer,
  791. "(({a}, {b}), {c}),",
  792. a = self.a,
  793. b = self.b,
  794. c = self.c
  795. )
  796. .unwrap();
  797. }
  798. fn prologue() -> &'static str {
  799. "
  800. use compiler_builtins::int::sdiv::__divdi3;
  801. static TEST_CASES: &[((i64, i64), i64)] = &[
  802. "
  803. }
  804. fn epilogue() -> &'static str {
  805. "
  806. ];
  807. #[test]
  808. fn divdi3() {
  809. for &((a, b), c) in TEST_CASES {
  810. let c_ = __divdi3(a, b);
  811. assert_eq!(((a, b), c), ((a, b), c_));
  812. }
  813. }
  814. "
  815. }
  816. }
  817. #[derive(Eq, Hash, PartialEq)]
  818. pub struct Divmodsi4 {
  819. a: i32,
  820. b: i32,
  821. c: i32,
  822. rem: i32,
  823. }
  824. impl TestCase for Divmodsi4 {
  825. fn name() -> &'static str {
  826. "divmodsi4"
  827. }
  828. fn generate<R>(rng: &mut R) -> Option<Self>
  829. where
  830. R: Rng,
  831. Self: Sized,
  832. {
  833. let a = gen_i32(rng);
  834. let b = gen_i32(rng);
  835. if b == 0 {
  836. return None;
  837. }
  838. let c = a / b;
  839. let rem = a % b;
  840. Some(Divmodsi4 { a, b, c, rem })
  841. }
  842. fn to_string(&self, buffer: &mut String) {
  843. writeln!(
  844. buffer,
  845. "(({a}, {b}), ({c}, {rem})),",
  846. a = self.a,
  847. b = self.b,
  848. c = self.c,
  849. rem = self.rem
  850. )
  851. .unwrap();
  852. }
  853. fn prologue() -> &'static str {
  854. "
  855. use compiler_builtins::int::sdiv::__divmodsi4;
  856. static TEST_CASES: &[((i32, i32), (i32, i32))] = &[
  857. "
  858. }
  859. fn epilogue() -> &'static str {
  860. "
  861. ];
  862. #[test]
  863. fn divmodsi4() {
  864. for &((a, b), (c, rem)) in TEST_CASES {
  865. let mut rem_ = 0;
  866. let c_ = __divmodsi4(a, b, &mut rem_);
  867. assert_eq!(((a, b), (c, rem)), ((a, b), (c_, rem_)));
  868. }
  869. }
  870. "
  871. }
  872. }
  873. #[derive(Eq, Hash, PartialEq)]
  874. pub struct Divsi3 {
  875. a: i32,
  876. b: i32,
  877. c: i32,
  878. }
  879. impl TestCase for Divsi3 {
  880. fn name() -> &'static str {
  881. "divsi3"
  882. }
  883. fn generate<R>(rng: &mut R) -> Option<Self>
  884. where
  885. R: Rng,
  886. Self: Sized,
  887. {
  888. let a = gen_i32(rng);
  889. let b = gen_i32(rng);
  890. if b == 0 {
  891. return None;
  892. }
  893. let c = a / b;
  894. Some(Divsi3 { a, b, c })
  895. }
  896. fn to_string(&self, buffer: &mut String) {
  897. writeln!(
  898. buffer,
  899. "(({a}, {b}), {c}),",
  900. a = self.a,
  901. b = self.b,
  902. c = self.c
  903. )
  904. .unwrap();
  905. }
  906. fn prologue() -> &'static str {
  907. "
  908. use compiler_builtins::int::sdiv::__divsi3;
  909. static TEST_CASES: &[((i32, i32), i32)] = &[
  910. "
  911. }
  912. fn epilogue() -> &'static str {
  913. "
  914. ];
  915. #[test]
  916. fn divsi3() {
  917. for &((a, b), c) in TEST_CASES {
  918. let c_ = __divsi3(a, b);
  919. assert_eq!(((a, b), c), ((a, b), c_));
  920. }
  921. }
  922. "
  923. }
  924. }
  925. #[derive(Eq, Hash, PartialEq)]
  926. pub struct Divti3 {
  927. a: i128,
  928. b: i128,
  929. c: i128,
  930. }
  931. impl TestCase for Divti3 {
  932. fn name() -> &'static str {
  933. "divti3"
  934. }
  935. fn generate<R>(rng: &mut R) -> Option<Self>
  936. where
  937. R: Rng,
  938. Self: Sized,
  939. {
  940. let a = gen_i128(rng);
  941. let b = gen_i128(rng);
  942. if b == 0 {
  943. return None;
  944. }
  945. let c = a / b;
  946. Some(Divti3 { a, b, c })
  947. }
  948. fn to_string(&self, buffer: &mut String) {
  949. writeln!(
  950. buffer,
  951. "(({a}, {b}), {c}),",
  952. a = self.a,
  953. b = self.b,
  954. c = self.c
  955. )
  956. .unwrap();
  957. }
  958. fn prologue() -> &'static str {
  959. "
  960. use compiler_builtins::int::sdiv::__divti3;
  961. static TEST_CASES: &[((i128, i128), i128)] = &[
  962. "
  963. }
  964. fn epilogue() -> &'static str {
  965. "
  966. ];
  967. #[test]
  968. fn divti3() {
  969. for &((a, b), c) in TEST_CASES {
  970. let c_ = __divti3(a, b);
  971. assert_eq!(((a, b), c), ((a, b), c_));
  972. }
  973. }
  974. "
  975. }
  976. }
  977. #[derive(Eq, Hash, PartialEq)]
  978. pub struct Fixdfdi {
  979. a: u64, // f64
  980. b: i64,
  981. }
  982. impl TestCase for Fixdfdi {
  983. fn name() -> &'static str {
  984. "fixdfdi"
  985. }
  986. fn generate<R>(rng: &mut R) -> Option<Self>
  987. where
  988. R: Rng,
  989. Self: Sized,
  990. {
  991. let a = gen_f64(rng);
  992. i64(a).ok().map(|b| Fixdfdi { a: to_u64(a), b })
  993. }
  994. fn to_string(&self, buffer: &mut String) {
  995. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  996. }
  997. fn prologue() -> &'static str {
  998. r#"
  999. #[cfg(all(target_arch = "arm",
  1000. not(any(target_env = "gnu", target_env = "musl")),
  1001. target_os = "linux",
  1002. test))]
  1003. use core::mem;
  1004. #[cfg(not(all(target_arch = "arm",
  1005. not(any(target_env = "gnu", target_env = "musl")),
  1006. target_os = "linux",
  1007. test)))]
  1008. use std::mem;
  1009. use compiler_builtins::float::conv::__fixdfdi;
  1010. fn mk_f64(x: u64) -> f64 {
  1011. unsafe { mem::transmute(x) }
  1012. }
  1013. static TEST_CASES: &[((u64,), i64)] = &[
  1014. "#
  1015. }
  1016. fn epilogue() -> &'static str {
  1017. "
  1018. ];
  1019. #[test]
  1020. fn fixdfdi() {
  1021. for &((a,), b) in TEST_CASES {
  1022. let b_ = __fixdfdi(mk_f64(a));
  1023. assert_eq!(((a,), b), ((a,), b_));
  1024. }
  1025. }
  1026. "
  1027. }
  1028. }
  1029. #[derive(Eq, Hash, PartialEq)]
  1030. pub struct Fixdfsi {
  1031. a: u64, // f64
  1032. b: i32,
  1033. }
  1034. impl TestCase for Fixdfsi {
  1035. fn name() -> &'static str {
  1036. "fixdfsi"
  1037. }
  1038. fn generate<R>(rng: &mut R) -> Option<Self>
  1039. where
  1040. R: Rng,
  1041. Self: Sized,
  1042. {
  1043. let a = gen_f64(rng);
  1044. i32(a).ok().map(|b| Fixdfsi { a: to_u64(a), b })
  1045. }
  1046. fn to_string(&self, buffer: &mut String) {
  1047. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1048. }
  1049. fn prologue() -> &'static str {
  1050. r#"
  1051. #[cfg(all(target_arch = "arm",
  1052. not(any(target_env = "gnu", target_env = "musl")),
  1053. target_os = "linux",
  1054. test))]
  1055. use core::mem;
  1056. #[cfg(not(all(target_arch = "arm",
  1057. not(any(target_env = "gnu", target_env = "musl")),
  1058. target_os = "linux",
  1059. test)))]
  1060. use std::mem;
  1061. use compiler_builtins::float::conv::__fixdfsi;
  1062. fn mk_f64(x: u64) -> f64 {
  1063. unsafe { mem::transmute(x) }
  1064. }
  1065. static TEST_CASES: &[((u64,), i32)] = &[
  1066. "#
  1067. }
  1068. fn epilogue() -> &'static str {
  1069. "
  1070. ];
  1071. #[test]
  1072. fn fixdfdi() {
  1073. for &((a,), b) in TEST_CASES {
  1074. let b_ = __fixdfsi(mk_f64(a));
  1075. assert_eq!(((a,), b), ((a,), b_));
  1076. }
  1077. }
  1078. "
  1079. }
  1080. }
  1081. #[derive(Eq, Hash, PartialEq)]
  1082. pub struct Fixsfdi {
  1083. a: u32, // f32
  1084. b: i64,
  1085. }
  1086. impl TestCase for Fixsfdi {
  1087. fn name() -> &'static str {
  1088. "fixsfdi"
  1089. }
  1090. fn generate<R>(rng: &mut R) -> Option<Self>
  1091. where
  1092. R: Rng,
  1093. Self: Sized,
  1094. {
  1095. let a = gen_f32(rng);
  1096. i64(a).ok().map(|b| Fixsfdi { a: to_u32(a), b })
  1097. }
  1098. fn to_string(&self, buffer: &mut String) {
  1099. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1100. }
  1101. fn prologue() -> &'static str {
  1102. r#"
  1103. #[cfg(all(target_arch = "arm",
  1104. not(any(target_env = "gnu", target_env = "musl")),
  1105. target_os = "linux",
  1106. test))]
  1107. use core::mem;
  1108. #[cfg(not(all(target_arch = "arm",
  1109. not(any(target_env = "gnu", target_env = "musl")),
  1110. target_os = "linux",
  1111. test)))]
  1112. use std::mem;
  1113. use compiler_builtins::float::conv::__fixsfdi;
  1114. fn mk_f32(x: u32) -> f32 {
  1115. unsafe { mem::transmute(x) }
  1116. }
  1117. static TEST_CASES: &[((u32,), i64)] = &[
  1118. "#
  1119. }
  1120. fn epilogue() -> &'static str {
  1121. "
  1122. ];
  1123. #[test]
  1124. fn fixsfdi() {
  1125. for &((a,), b) in TEST_CASES {
  1126. let b_ = __fixsfdi(mk_f32(a));
  1127. assert_eq!(((a,), b), ((a,), b_));
  1128. }
  1129. }
  1130. "
  1131. }
  1132. }
  1133. #[derive(Eq, Hash, PartialEq)]
  1134. pub struct Fixsfsi {
  1135. a: u32, // f32
  1136. b: i32,
  1137. }
  1138. impl TestCase for Fixsfsi {
  1139. fn name() -> &'static str {
  1140. "fixsfsi"
  1141. }
  1142. fn generate<R>(rng: &mut R) -> Option<Self>
  1143. where
  1144. R: Rng,
  1145. Self: Sized,
  1146. {
  1147. let a = gen_f32(rng);
  1148. i32(a).ok().map(|b| Fixsfsi { a: to_u32(a), b })
  1149. }
  1150. fn to_string(&self, buffer: &mut String) {
  1151. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1152. }
  1153. fn prologue() -> &'static str {
  1154. r#"
  1155. #[cfg(all(target_arch = "arm",
  1156. not(any(target_env = "gnu", target_env = "musl")),
  1157. target_os = "linux",
  1158. test))]
  1159. use core::mem;
  1160. #[cfg(not(all(target_arch = "arm",
  1161. not(any(target_env = "gnu", target_env = "musl")),
  1162. target_os = "linux",
  1163. test)))]
  1164. use std::mem;
  1165. use compiler_builtins::float::conv::__fixsfsi;
  1166. fn mk_f32(x: u32) -> f32 {
  1167. unsafe { mem::transmute(x) }
  1168. }
  1169. static TEST_CASES: &[((u32,), i32)] = &[
  1170. "#
  1171. }
  1172. fn epilogue() -> &'static str {
  1173. "
  1174. ];
  1175. #[test]
  1176. fn fixsfsi() {
  1177. for &((a,), b) in TEST_CASES {
  1178. let b_ = __fixsfsi(mk_f32(a));
  1179. assert_eq!(((a,), b), ((a,), b_));
  1180. }
  1181. }
  1182. "
  1183. }
  1184. }
  1185. #[derive(Eq, Hash, PartialEq)]
  1186. pub struct Fixsfti {
  1187. a: u32, // f32
  1188. b: i128,
  1189. }
  1190. impl TestCase for Fixsfti {
  1191. fn name() -> &'static str {
  1192. "fixsfti"
  1193. }
  1194. fn generate<R>(rng: &mut R) -> Option<Self>
  1195. where
  1196. R: Rng,
  1197. Self: Sized,
  1198. {
  1199. let a = gen_f32(rng);
  1200. i128(a).ok().map(|b| Fixsfti { a: to_u32(a), b })
  1201. }
  1202. fn to_string(&self, buffer: &mut String) {
  1203. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1204. }
  1205. fn prologue() -> &'static str {
  1206. r#"
  1207. #[cfg(all(target_arch = "arm",
  1208. not(any(target_env = "gnu", target_env = "musl")),
  1209. target_os = "linux",
  1210. test))]
  1211. use core::mem;
  1212. #[cfg(not(all(target_arch = "arm",
  1213. not(any(target_env = "gnu", target_env = "musl")),
  1214. target_os = "linux",
  1215. test)))]
  1216. use std::mem;
  1217. use compiler_builtins::float::conv::__fixsfti;
  1218. fn mk_f32(x: u32) -> f32 {
  1219. unsafe { mem::transmute(x) }
  1220. }
  1221. static TEST_CASES: &[((u32,), i128)] = &[
  1222. "#
  1223. }
  1224. fn epilogue() -> &'static str {
  1225. "
  1226. ];
  1227. #[test]
  1228. fn fixsfti() {
  1229. for &((a,), b) in TEST_CASES {
  1230. let b_ = __fixsfti(mk_f32(a));
  1231. assert_eq!(((a,), b), ((a,), b_));
  1232. }
  1233. }
  1234. "
  1235. }
  1236. }
  1237. #[derive(Eq, Hash, PartialEq)]
  1238. pub struct Fixdfti {
  1239. a: u64, // f64
  1240. b: i128,
  1241. }
  1242. impl TestCase for Fixdfti {
  1243. fn name() -> &'static str {
  1244. "fixdfti"
  1245. }
  1246. fn generate<R>(rng: &mut R) -> Option<Self>
  1247. where
  1248. R: Rng,
  1249. Self: Sized,
  1250. {
  1251. let a = gen_f64(rng);
  1252. i128(a).ok().map(|b| Fixdfti { a: to_u64(a), b })
  1253. }
  1254. fn to_string(&self, buffer: &mut String) {
  1255. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1256. }
  1257. fn prologue() -> &'static str {
  1258. r#"
  1259. #[cfg(all(target_arch = "arm",
  1260. not(any(target_env = "gnu", target_env = "musl")),
  1261. target_os = "linux",
  1262. test))]
  1263. use core::mem;
  1264. #[cfg(not(all(target_arch = "arm",
  1265. not(any(target_env = "gnu", target_env = "musl")),
  1266. target_os = "linux",
  1267. test)))]
  1268. use std::mem;
  1269. use compiler_builtins::float::conv::__fixdfti;
  1270. fn mk_f64(x: u64) -> f64 {
  1271. unsafe { mem::transmute(x) }
  1272. }
  1273. static TEST_CASES: &[((u64,), i128)] = &[
  1274. "#
  1275. }
  1276. fn epilogue() -> &'static str {
  1277. "
  1278. ];
  1279. #[test]
  1280. fn fixdfti() {
  1281. for &((a,), b) in TEST_CASES {
  1282. let b_ = __fixdfti(mk_f64(a));
  1283. assert_eq!(((a,), b), ((a,), b_));
  1284. }
  1285. }
  1286. "
  1287. }
  1288. }
  1289. #[derive(Eq, Hash, PartialEq)]
  1290. pub struct Fixunsdfdi {
  1291. a: u64, // f64
  1292. b: u64,
  1293. }
  1294. impl TestCase for Fixunsdfdi {
  1295. fn name() -> &'static str {
  1296. "fixunsdfdi"
  1297. }
  1298. fn generate<R>(rng: &mut R) -> Option<Self>
  1299. where
  1300. R: Rng,
  1301. Self: Sized,
  1302. {
  1303. let a = gen_f64(rng);
  1304. u64(a).ok().map(|b| Fixunsdfdi { a: to_u64(a), b })
  1305. }
  1306. fn to_string(&self, buffer: &mut String) {
  1307. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1308. }
  1309. fn prologue() -> &'static str {
  1310. r#"
  1311. #[cfg(all(target_arch = "arm",
  1312. not(any(target_env = "gnu", target_env = "musl")),
  1313. target_os = "linux",
  1314. test))]
  1315. use core::mem;
  1316. #[cfg(not(all(target_arch = "arm",
  1317. not(any(target_env = "gnu", target_env = "musl")),
  1318. target_os = "linux",
  1319. test)))]
  1320. use std::mem;
  1321. use compiler_builtins::float::conv::__fixunsdfdi;
  1322. fn mk_f64(x: u64) -> f64 {
  1323. unsafe { mem::transmute(x) }
  1324. }
  1325. static TEST_CASES: &[((u64,), u64)] = &[
  1326. "#
  1327. }
  1328. fn epilogue() -> &'static str {
  1329. "
  1330. ];
  1331. #[test]
  1332. fn fixunsdfdi() {
  1333. for &((a,), b) in TEST_CASES {
  1334. let b_ = __fixunsdfdi(mk_f64(a));
  1335. assert_eq!(((a,), b), ((a,), b_));
  1336. }
  1337. }
  1338. "
  1339. }
  1340. }
  1341. #[derive(Eq, Hash, PartialEq)]
  1342. pub struct Fixunsdfsi {
  1343. a: u64, // f64
  1344. b: u32,
  1345. }
  1346. impl TestCase for Fixunsdfsi {
  1347. fn name() -> &'static str {
  1348. "fixunsdfsi"
  1349. }
  1350. fn generate<R>(rng: &mut R) -> Option<Self>
  1351. where
  1352. R: Rng,
  1353. Self: Sized,
  1354. {
  1355. let a = gen_f64(rng);
  1356. u32(a).ok().map(|b| Fixunsdfsi { a: to_u64(a), b })
  1357. }
  1358. fn to_string(&self, buffer: &mut String) {
  1359. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1360. }
  1361. fn prologue() -> &'static str {
  1362. r#"
  1363. #[cfg(all(target_arch = "arm",
  1364. not(any(target_env = "gnu", target_env = "musl")),
  1365. target_os = "linux",
  1366. test))]
  1367. use core::mem;
  1368. #[cfg(not(all(target_arch = "arm",
  1369. not(any(target_env = "gnu", target_env = "musl")),
  1370. target_os = "linux",
  1371. test)))]
  1372. use std::mem;
  1373. use compiler_builtins::float::conv::__fixunsdfsi;
  1374. fn mk_f64(x: u64) -> f64 {
  1375. unsafe { mem::transmute(x) }
  1376. }
  1377. static TEST_CASES: &[((u64,), u32)] = &[
  1378. "#
  1379. }
  1380. fn epilogue() -> &'static str {
  1381. "
  1382. ];
  1383. #[test]
  1384. fn fixunsdfdi() {
  1385. for &((a,), b) in TEST_CASES {
  1386. let b_ = __fixunsdfsi(mk_f64(a));
  1387. assert_eq!(((a,), b), ((a,), b_));
  1388. }
  1389. }
  1390. "
  1391. }
  1392. }
  1393. #[derive(Eq, Hash, PartialEq)]
  1394. pub struct Fixunssfdi {
  1395. a: u32, // f32
  1396. b: u64,
  1397. }
  1398. impl TestCase for Fixunssfdi {
  1399. fn name() -> &'static str {
  1400. "fixunssfdi"
  1401. }
  1402. fn generate<R>(rng: &mut R) -> Option<Self>
  1403. where
  1404. R: Rng,
  1405. Self: Sized,
  1406. {
  1407. let a = gen_f32(rng);
  1408. u64(a).ok().map(|b| Fixunssfdi { a: to_u32(a), b })
  1409. }
  1410. fn to_string(&self, buffer: &mut String) {
  1411. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1412. }
  1413. fn prologue() -> &'static str {
  1414. r#"
  1415. #[cfg(all(target_arch = "arm",
  1416. not(any(target_env = "gnu", target_env = "musl")),
  1417. target_os = "linux",
  1418. test))]
  1419. use core::mem;
  1420. #[cfg(not(all(target_arch = "arm",
  1421. not(any(target_env = "gnu", target_env = "musl")),
  1422. target_os = "linux",
  1423. test)))]
  1424. use std::mem;
  1425. use compiler_builtins::float::conv::__fixunssfdi;
  1426. fn mk_f32(x: u32) -> f32 {
  1427. unsafe { mem::transmute(x) }
  1428. }
  1429. static TEST_CASES: &[((u32,), u64)] = &[
  1430. "#
  1431. }
  1432. fn epilogue() -> &'static str {
  1433. "
  1434. ];
  1435. #[test]
  1436. fn fixunssfdi() {
  1437. for &((a,), b) in TEST_CASES {
  1438. let b_ = __fixunssfdi(mk_f32(a));
  1439. assert_eq!(((a,), b), ((a,), b_));
  1440. }
  1441. }
  1442. "
  1443. }
  1444. }
  1445. #[derive(Eq, Hash, PartialEq)]
  1446. pub struct Fixunssfsi {
  1447. a: u32, // f32
  1448. b: u32,
  1449. }
  1450. impl TestCase for Fixunssfsi {
  1451. fn name() -> &'static str {
  1452. "fixunssfsi"
  1453. }
  1454. fn generate<R>(rng: &mut R) -> Option<Self>
  1455. where
  1456. R: Rng,
  1457. Self: Sized,
  1458. {
  1459. let a = gen_f32(rng);
  1460. u32(a).ok().map(|b| Fixunssfsi { a: to_u32(a), b })
  1461. }
  1462. fn to_string(&self, buffer: &mut String) {
  1463. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1464. }
  1465. fn prologue() -> &'static str {
  1466. r#"
  1467. #[cfg(all(target_arch = "arm",
  1468. not(any(target_env = "gnu", target_env = "musl")),
  1469. target_os = "linux",
  1470. test))]
  1471. use core::mem;
  1472. #[cfg(not(all(target_arch = "arm",
  1473. not(any(target_env = "gnu", target_env = "musl")),
  1474. target_os = "linux",
  1475. test)))]
  1476. use std::mem;
  1477. use compiler_builtins::float::conv::__fixunssfsi;
  1478. fn mk_f32(x: u32) -> f32 {
  1479. unsafe { mem::transmute(x) }
  1480. }
  1481. static TEST_CASES: &[((u32,), u32)] = &[
  1482. "#
  1483. }
  1484. fn epilogue() -> &'static str {
  1485. "
  1486. ];
  1487. #[test]
  1488. fn fixunssfsi() {
  1489. for &((a,), b) in TEST_CASES {
  1490. let b_ = __fixunssfsi(mk_f32(a));
  1491. assert_eq!(((a,), b), ((a,), b_));
  1492. }
  1493. }
  1494. "
  1495. }
  1496. }
  1497. #[derive(Eq, Hash, PartialEq)]
  1498. pub struct Fixunssfti {
  1499. a: u32, // f32
  1500. b: u128,
  1501. }
  1502. impl TestCase for Fixunssfti {
  1503. fn name() -> &'static str {
  1504. "fixunssfti"
  1505. }
  1506. fn generate<R>(rng: &mut R) -> Option<Self>
  1507. where
  1508. R: Rng,
  1509. Self: Sized,
  1510. {
  1511. let a = gen_f32(rng);
  1512. u128(a).ok().map(|b| Fixunssfti { a: to_u32(a), b })
  1513. }
  1514. fn to_string(&self, buffer: &mut String) {
  1515. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1516. }
  1517. fn prologue() -> &'static str {
  1518. r#"
  1519. #[cfg(all(target_arch = "arm",
  1520. not(any(target_env = "gnu", target_env = "musl")),
  1521. target_os = "linux",
  1522. test))]
  1523. use core::mem;
  1524. #[cfg(not(all(target_arch = "arm",
  1525. not(any(target_env = "gnu", target_env = "musl")),
  1526. target_os = "linux",
  1527. test)))]
  1528. use std::mem;
  1529. use compiler_builtins::float::conv::__fixunssfti;
  1530. fn mk_f32(x: u32) -> f32 {
  1531. unsafe { mem::transmute(x) }
  1532. }
  1533. static TEST_CASES: &[((u32,), u128)] = &[
  1534. "#
  1535. }
  1536. fn epilogue() -> &'static str {
  1537. "
  1538. ];
  1539. #[test]
  1540. fn fixunssfti() {
  1541. for &((a,), b) in TEST_CASES {
  1542. let b_ = __fixunssfti(mk_f32(a));
  1543. assert_eq!(((a,), b), ((a,), b_));
  1544. }
  1545. }
  1546. "
  1547. }
  1548. }
  1549. #[derive(Eq, Hash, PartialEq)]
  1550. pub struct Fixunsdfti {
  1551. a: u64, // f64
  1552. b: u128,
  1553. }
  1554. impl TestCase for Fixunsdfti {
  1555. fn name() -> &'static str {
  1556. "fixunsdfti"
  1557. }
  1558. fn generate<R>(rng: &mut R) -> Option<Self>
  1559. where
  1560. R: Rng,
  1561. Self: Sized,
  1562. {
  1563. let a = gen_f64(rng);
  1564. u128(a).ok().map(|b| Fixunsdfti { a: to_u64(a), b })
  1565. }
  1566. fn to_string(&self, buffer: &mut String) {
  1567. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1568. }
  1569. fn prologue() -> &'static str {
  1570. r#"
  1571. #[cfg(all(target_arch = "arm",
  1572. not(any(target_env = "gnu", target_env = "musl")),
  1573. target_os = "linux",
  1574. test))]
  1575. use core::mem;
  1576. #[cfg(not(all(target_arch = "arm",
  1577. not(any(target_env = "gnu", target_env = "musl")),
  1578. target_os = "linux",
  1579. test)))]
  1580. use std::mem;
  1581. use compiler_builtins::float::conv::__fixunsdfti;
  1582. fn mk_f64(x: u64) -> f64 {
  1583. unsafe { mem::transmute(x) }
  1584. }
  1585. static TEST_CASES: &[((u64,), u128)] = &[
  1586. "#
  1587. }
  1588. fn epilogue() -> &'static str {
  1589. "
  1590. ];
  1591. #[test]
  1592. fn fixunsdfti() {
  1593. for &((a,), b) in TEST_CASES {
  1594. let b_ = __fixunsdfti(mk_f64(a));
  1595. assert_eq!(((a,), b), ((a,), b_));
  1596. }
  1597. }
  1598. "
  1599. }
  1600. }
  1601. #[derive(Eq, Hash, PartialEq)]
  1602. pub struct Floatdidf {
  1603. a: i64,
  1604. b: u64, // f64
  1605. }
  1606. impl TestCase for Floatdidf {
  1607. fn name() -> &'static str {
  1608. "floatdidf"
  1609. }
  1610. fn generate<R>(rng: &mut R) -> Option<Self>
  1611. where
  1612. R: Rng,
  1613. Self: Sized,
  1614. {
  1615. let a = gen_i64(rng);
  1616. Some(
  1617. Floatdidf {
  1618. a,
  1619. b: to_u64(f64(a)),
  1620. },
  1621. )
  1622. }
  1623. fn to_string(&self, buffer: &mut String) {
  1624. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1625. }
  1626. fn prologue() -> &'static str {
  1627. r#"
  1628. #[cfg(all(target_arch = "arm",
  1629. not(any(target_env = "gnu", target_env = "musl")),
  1630. target_os = "linux",
  1631. test))]
  1632. use core::mem;
  1633. #[cfg(not(all(target_arch = "arm",
  1634. not(any(target_env = "gnu", target_env = "musl")),
  1635. target_os = "linux",
  1636. test)))]
  1637. use std::mem;
  1638. use compiler_builtins::float::conv::__floatdidf;
  1639. fn to_u64(x: f64) -> u64 {
  1640. unsafe { mem::transmute(x) }
  1641. }
  1642. static TEST_CASES: &[((i64,), u64)] = &[
  1643. "#
  1644. }
  1645. fn epilogue() -> &'static str {
  1646. "
  1647. ];
  1648. #[test]
  1649. fn floatdidf() {
  1650. for &((a,), b) in TEST_CASES {
  1651. let b_ = __floatdidf(a);
  1652. assert_eq!(((a,), b), ((a,), to_u64(b_)));
  1653. }
  1654. }
  1655. "
  1656. }
  1657. }
  1658. #[derive(Eq, Hash, PartialEq)]
  1659. pub struct Floatsidf {
  1660. a: i32,
  1661. b: u64, // f64
  1662. }
  1663. impl TestCase for Floatsidf {
  1664. fn name() -> &'static str {
  1665. "floatsidf"
  1666. }
  1667. fn generate<R>(rng: &mut R) -> Option<Self>
  1668. where
  1669. R: Rng,
  1670. Self: Sized,
  1671. {
  1672. let a = gen_i32(rng);
  1673. Some(
  1674. Floatsidf {
  1675. a,
  1676. b: to_u64(f64(a)),
  1677. },
  1678. )
  1679. }
  1680. fn to_string(&self, buffer: &mut String) {
  1681. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1682. }
  1683. fn prologue() -> &'static str {
  1684. r#"
  1685. #[cfg(all(target_arch = "arm",
  1686. not(any(target_env = "gnu", target_env = "musl")),
  1687. target_os = "linux",
  1688. test))]
  1689. use core::mem;
  1690. #[cfg(not(all(target_arch = "arm",
  1691. not(any(target_env = "gnu", target_env = "musl")),
  1692. target_os = "linux",
  1693. test)))]
  1694. use std::mem;
  1695. use compiler_builtins::float::conv::__floatsidf;
  1696. fn to_u64(x: f64) -> u64 {
  1697. unsafe { mem::transmute(x) }
  1698. }
  1699. static TEST_CASES: &[((i32,), u64)] = &[
  1700. "#
  1701. }
  1702. fn epilogue() -> &'static str {
  1703. "
  1704. ];
  1705. #[test]
  1706. fn floatsidf() {
  1707. for &((a,), b) in TEST_CASES {
  1708. let b_ = __floatsidf(a);
  1709. assert_eq!(((a,), b), ((a,), to_u64(b_)));
  1710. }
  1711. }
  1712. "
  1713. }
  1714. }
  1715. #[derive(Eq, Hash, PartialEq)]
  1716. pub struct Floatsisf {
  1717. a: i32,
  1718. b: u32, // f32
  1719. }
  1720. impl TestCase for Floatsisf {
  1721. fn name() -> &'static str {
  1722. "floatsisf"
  1723. }
  1724. fn generate<R>(rng: &mut R) -> Option<Self>
  1725. where
  1726. R: Rng,
  1727. Self: Sized,
  1728. {
  1729. let a = gen_i32(rng);
  1730. Some(
  1731. Floatsisf {
  1732. a,
  1733. b: to_u32(f32(a)),
  1734. },
  1735. )
  1736. }
  1737. fn to_string(&self, buffer: &mut String) {
  1738. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1739. }
  1740. fn prologue() -> &'static str {
  1741. r#"
  1742. #[cfg(all(target_arch = "arm",
  1743. not(any(target_env = "gnu", target_env = "musl")),
  1744. target_os = "linux",
  1745. test))]
  1746. use core::mem;
  1747. #[cfg(not(all(target_arch = "arm",
  1748. not(any(target_env = "gnu", target_env = "musl")),
  1749. target_os = "linux",
  1750. test)))]
  1751. use std::mem;
  1752. use compiler_builtins::float::conv::__floatsisf;
  1753. fn to_u32(x: f32) -> u32 {
  1754. unsafe { mem::transmute(x) }
  1755. }
  1756. static TEST_CASES: &[((i32,), u32)] = &[
  1757. "#
  1758. }
  1759. fn epilogue() -> &'static str {
  1760. "
  1761. ];
  1762. #[test]
  1763. fn floatsisf() {
  1764. for &((a,), b) in TEST_CASES {
  1765. let b_ = __floatsisf(a);
  1766. assert_eq!(((a,), b), ((a,), to_u32(b_)));
  1767. }
  1768. }
  1769. "
  1770. }
  1771. }
  1772. #[derive(Eq, Hash, PartialEq)]
  1773. pub struct Floattisf {
  1774. a: i128,
  1775. b: u32, // f32
  1776. }
  1777. impl TestCase for Floattisf {
  1778. fn name() -> &'static str {
  1779. "floattisf"
  1780. }
  1781. fn generate<R>(rng: &mut R) -> Option<Self>
  1782. where
  1783. R: Rng,
  1784. Self: Sized,
  1785. {
  1786. let a = gen_i128(rng);
  1787. Some(
  1788. Floattisf {
  1789. a,
  1790. b: to_u32(f32(a)),
  1791. },
  1792. )
  1793. }
  1794. fn to_string(&self, buffer: &mut String) {
  1795. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1796. }
  1797. fn prologue() -> &'static str {
  1798. r#"
  1799. #[cfg(all(target_arch = "arm",
  1800. not(any(target_env = "gnu", target_env = "musl")),
  1801. target_os = "linux",
  1802. test))]
  1803. use core::mem;
  1804. #[cfg(not(all(target_arch = "arm",
  1805. not(any(target_env = "gnu", target_env = "musl")),
  1806. target_os = "linux",
  1807. test)))]
  1808. use std::mem;
  1809. use compiler_builtins::float::conv::__floattisf;
  1810. fn to_u32(x: f32) -> u32 {
  1811. unsafe { mem::transmute(x) }
  1812. }
  1813. static TEST_CASES: &[((i128,), u32)] = &[
  1814. "#
  1815. }
  1816. fn epilogue() -> &'static str {
  1817. "
  1818. ];
  1819. #[test]
  1820. fn floattisf() {
  1821. for &((a,), b) in TEST_CASES {
  1822. let b_ = __floattisf(a);
  1823. assert_eq!(((a,), b), ((a,), to_u32(b_)));
  1824. }
  1825. }
  1826. "
  1827. }
  1828. }
  1829. #[derive(Eq, Hash, PartialEq)]
  1830. pub struct Floattidf {
  1831. a: i128,
  1832. b: u64, // f64
  1833. }
  1834. impl TestCase for Floattidf {
  1835. fn name() -> &'static str {
  1836. "floattidf"
  1837. }
  1838. fn generate<R>(rng: &mut R) -> Option<Self>
  1839. where
  1840. R: Rng,
  1841. Self: Sized,
  1842. {
  1843. let a = gen_i128(rng);
  1844. Some(
  1845. Floattidf {
  1846. a,
  1847. b: to_u64(f64(a)),
  1848. },
  1849. )
  1850. }
  1851. fn to_string(&self, buffer: &mut String) {
  1852. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1853. }
  1854. fn prologue() -> &'static str {
  1855. r#"
  1856. #[cfg(all(target_arch = "arm",
  1857. not(any(target_env = "gnu", target_env = "musl")),
  1858. target_os = "linux",
  1859. test))]
  1860. use core::mem;
  1861. #[cfg(not(all(target_arch = "arm",
  1862. not(any(target_env = "gnu", target_env = "musl")),
  1863. target_os = "linux",
  1864. test)))]
  1865. use std::mem;
  1866. use compiler_builtins::float::conv::__floattidf;
  1867. fn to_u64(x: f64) -> u64 {
  1868. unsafe { mem::transmute(x) }
  1869. }
  1870. static TEST_CASES: &[((i128,), u64)] = &[
  1871. "#
  1872. }
  1873. fn epilogue() -> &'static str {
  1874. "
  1875. ];
  1876. #[test]
  1877. fn floattidf() {
  1878. for &((a,), b) in TEST_CASES {
  1879. let b_ = __floattidf(a);
  1880. let g_b = to_u64(b_);
  1881. let diff = if g_b > b { g_b - b } else { b - g_b };
  1882. assert_eq!(((a,), b, g_b, true), ((a,), b, g_b, diff <= 1));
  1883. }
  1884. }
  1885. "
  1886. }
  1887. }
  1888. #[derive(Eq, Hash, PartialEq)]
  1889. pub struct Floatundidf {
  1890. a: u64,
  1891. b: u64, // f64
  1892. }
  1893. impl TestCase for Floatundidf {
  1894. fn name() -> &'static str {
  1895. "floatundidf"
  1896. }
  1897. fn generate<R>(rng: &mut R) -> Option<Self>
  1898. where
  1899. R: Rng,
  1900. Self: Sized,
  1901. {
  1902. let a = gen_u64(rng);
  1903. Some(
  1904. Floatundidf {
  1905. a,
  1906. b: to_u64(f64(a)),
  1907. },
  1908. )
  1909. }
  1910. fn to_string(&self, buffer: &mut String) {
  1911. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1912. }
  1913. fn prologue() -> &'static str {
  1914. r#"
  1915. #[cfg(all(target_arch = "arm",
  1916. not(any(target_env = "gnu", target_env = "musl")),
  1917. target_os = "linux",
  1918. test))]
  1919. use core::mem;
  1920. #[cfg(not(all(target_arch = "arm",
  1921. not(any(target_env = "gnu", target_env = "musl")),
  1922. target_os = "linux",
  1923. test)))]
  1924. use std::mem;
  1925. use compiler_builtins::float::conv::__floatundidf;
  1926. fn to_u64(x: f64) -> u64 {
  1927. unsafe { mem::transmute(x) }
  1928. }
  1929. static TEST_CASES: &[((u64,), u64)] = &[
  1930. "#
  1931. }
  1932. fn epilogue() -> &'static str {
  1933. "
  1934. ];
  1935. #[test]
  1936. fn floatundidf() {
  1937. for &((a,), b) in TEST_CASES {
  1938. let b_ = __floatundidf(a);
  1939. assert_eq!(((a,), b), ((a,), to_u64(b_)));
  1940. }
  1941. }
  1942. "
  1943. }
  1944. }
  1945. #[derive(Eq, Hash, PartialEq)]
  1946. pub struct Floatunsidf {
  1947. a: u32,
  1948. b: u64, // f64
  1949. }
  1950. impl TestCase for Floatunsidf {
  1951. fn name() -> &'static str {
  1952. "floatunsidf"
  1953. }
  1954. fn generate<R>(rng: &mut R) -> Option<Self>
  1955. where
  1956. R: Rng,
  1957. Self: Sized,
  1958. {
  1959. let a = gen_u32(rng);
  1960. Some(
  1961. Floatunsidf {
  1962. a,
  1963. b: to_u64(f64(a)),
  1964. },
  1965. )
  1966. }
  1967. fn to_string(&self, buffer: &mut String) {
  1968. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1969. }
  1970. fn prologue() -> &'static str {
  1971. r#"
  1972. #[cfg(all(target_arch = "arm",
  1973. not(any(target_env = "gnu", target_env = "musl")),
  1974. target_os = "linux",
  1975. test))]
  1976. use core::mem;
  1977. #[cfg(not(all(target_arch = "arm",
  1978. not(any(target_env = "gnu", target_env = "musl")),
  1979. target_os = "linux",
  1980. test)))]
  1981. use std::mem;
  1982. use compiler_builtins::float::conv::__floatunsidf;
  1983. fn to_u64(x: f64) -> u64 {
  1984. unsafe { mem::transmute(x) }
  1985. }
  1986. static TEST_CASES: &[((u32,), u64)] = &[
  1987. "#
  1988. }
  1989. fn epilogue() -> &'static str {
  1990. "
  1991. ];
  1992. #[test]
  1993. fn floatunsidf() {
  1994. for &((a,), b) in TEST_CASES {
  1995. let b_ = __floatunsidf(a);
  1996. assert_eq!(((a,), b), ((a,), to_u64(b_)));
  1997. }
  1998. }
  1999. "
  2000. }
  2001. }
  2002. #[derive(Eq, Hash, PartialEq)]
  2003. pub struct Floatunsisf {
  2004. a: u32,
  2005. b: u32, // f32
  2006. }
  2007. impl TestCase for Floatunsisf {
  2008. fn name() -> &'static str {
  2009. "floatunsisf"
  2010. }
  2011. fn generate<R>(rng: &mut R) -> Option<Self>
  2012. where
  2013. R: Rng,
  2014. Self: Sized,
  2015. {
  2016. let a = gen_u32(rng);
  2017. Some(
  2018. Floatunsisf {
  2019. a,
  2020. b: to_u32(f32(a)),
  2021. },
  2022. )
  2023. }
  2024. fn to_string(&self, buffer: &mut String) {
  2025. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  2026. }
  2027. fn prologue() -> &'static str {
  2028. r#"
  2029. #[cfg(all(target_arch = "arm",
  2030. not(any(target_env = "gnu", target_env = "musl")),
  2031. target_os = "linux",
  2032. test))]
  2033. use core::mem;
  2034. #[cfg(not(all(target_arch = "arm",
  2035. not(any(target_env = "gnu", target_env = "musl")),
  2036. target_os = "linux",
  2037. test)))]
  2038. use std::mem;
  2039. use compiler_builtins::float::conv::__floatunsisf;
  2040. fn to_u32(x: f32) -> u32 {
  2041. unsafe { mem::transmute(x) }
  2042. }
  2043. static TEST_CASES: &[((u32,), u32)] = &[
  2044. "#
  2045. }
  2046. fn epilogue() -> &'static str {
  2047. "
  2048. ];
  2049. #[test]
  2050. fn floatunsisf() {
  2051. for &((a,), b) in TEST_CASES {
  2052. let b_ = __floatunsisf(a);
  2053. assert_eq!(((a,), b), ((a,), to_u32(b_)));
  2054. }
  2055. }
  2056. "
  2057. }
  2058. }
  2059. #[derive(Eq, Hash, PartialEq)]
  2060. pub struct Floatuntisf {
  2061. a: u128,
  2062. b: u32, // f32
  2063. }
  2064. impl TestCase for Floatuntisf {
  2065. fn name() -> &'static str {
  2066. "floatuntisf"
  2067. }
  2068. fn generate<R>(rng: &mut R) -> Option<Self>
  2069. where
  2070. R: Rng,
  2071. Self: Sized,
  2072. {
  2073. let a = gen_u128(rng);
  2074. let f_a = f32(a);
  2075. f_a.ok().map(|f| {
  2076. Floatuntisf {
  2077. a,
  2078. b: to_u32(f),
  2079. }
  2080. })
  2081. }
  2082. fn to_string(&self, buffer: &mut String) {
  2083. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  2084. }
  2085. fn prologue() -> &'static str {
  2086. r#"
  2087. #[cfg(all(target_arch = "arm",
  2088. not(any(target_env = "gnu", target_env = "musl")),
  2089. target_os = "linux",
  2090. test))]
  2091. use core::mem;
  2092. #[cfg(not(all(target_arch = "arm",
  2093. not(any(target_env = "gnu", target_env = "musl")),
  2094. target_os = "linux",
  2095. test)))]
  2096. use std::mem;
  2097. use compiler_builtins::float::conv::__floatuntisf;
  2098. fn to_u32(x: f32) -> u32 {
  2099. unsafe { mem::transmute(x) }
  2100. }
  2101. static TEST_CASES: &[((u128,), u32)] = &[
  2102. "#
  2103. }
  2104. fn epilogue() -> &'static str {
  2105. "
  2106. ];
  2107. #[test]
  2108. fn floatuntisf() {
  2109. for &((a,), b) in TEST_CASES {
  2110. let b_ = __floatuntisf(a);
  2111. assert_eq!(((a,), b), ((a,), to_u32(b_)));
  2112. }
  2113. }
  2114. "
  2115. }
  2116. }
  2117. #[derive(Eq, Hash, PartialEq)]
  2118. pub struct Floatuntidf {
  2119. a: u128,
  2120. b: u64, // f64
  2121. }
  2122. impl TestCase for Floatuntidf {
  2123. fn name() -> &'static str {
  2124. "floatuntidf"
  2125. }
  2126. fn generate<R>(rng: &mut R) -> Option<Self>
  2127. where
  2128. R: Rng,
  2129. Self: Sized,
  2130. {
  2131. let a = gen_u128(rng);
  2132. Some(
  2133. Floatuntidf {
  2134. a,
  2135. b: to_u64(f64(a)),
  2136. },
  2137. )
  2138. }
  2139. fn to_string(&self, buffer: &mut String) {
  2140. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  2141. }
  2142. fn prologue() -> &'static str {
  2143. r#"
  2144. #[cfg(all(target_arch = "arm",
  2145. not(any(target_env = "gnu", target_env = "musl")),
  2146. target_os = "linux",
  2147. test))]
  2148. use core::mem;
  2149. #[cfg(not(all(target_arch = "arm",
  2150. not(any(target_env = "gnu", target_env = "musl")),
  2151. target_os = "linux",
  2152. test)))]
  2153. use std::mem;
  2154. use compiler_builtins::float::conv::__floatuntidf;
  2155. fn to_u64(x: f64) -> u64 {
  2156. unsafe { mem::transmute(x) }
  2157. }
  2158. static TEST_CASES: &[((u128,), u64)] = &[
  2159. "#
  2160. }
  2161. fn epilogue() -> &'static str {
  2162. "
  2163. ];
  2164. #[test]
  2165. fn floatuntidf() {
  2166. for &((a,), b) in TEST_CASES {
  2167. let b_ = __floatuntidf(a);
  2168. let g_b = to_u64(b_);
  2169. let diff = if g_b > b { g_b - b } else { b - g_b };
  2170. assert_eq!(((a,), b, g_b, true), ((a,), b, g_b, diff <= 1));
  2171. }
  2172. }
  2173. "
  2174. }
  2175. }
  2176. #[derive(Eq, Hash, PartialEq)]
  2177. pub struct Gedf2 {
  2178. a: u64,
  2179. b: u64,
  2180. c: i32,
  2181. }
  2182. impl TestCase for Gedf2 {
  2183. fn name() -> &'static str {
  2184. "gedf2"
  2185. }
  2186. fn generate<R>(rng: &mut R) -> Option<Self>
  2187. where
  2188. R: Rng,
  2189. Self: Sized,
  2190. {
  2191. let a = gen_f64(rng);
  2192. let b = gen_f64(rng);
  2193. // TODO accept NaNs. We don't do that right now because we can't check
  2194. // for NaN-ness on the thumb targets (due to missing intrinsics)
  2195. if a.is_nan() || b.is_nan() {
  2196. return None;
  2197. }
  2198. let c;
  2199. if a.is_nan() || b.is_nan() {
  2200. c = -1;
  2201. } else if a < b {
  2202. c = -1;
  2203. } else if a > b {
  2204. c = 1;
  2205. } else {
  2206. c = 0;
  2207. }
  2208. Some(Gedf2 { a: to_u64(a), b: to_u64(b), c })
  2209. }
  2210. fn to_string(&self, buffer: &mut String) {
  2211. writeln!(
  2212. buffer,
  2213. "(({a}, {b}), {c}),",
  2214. a = self.a,
  2215. b = self.b,
  2216. c = self.c
  2217. )
  2218. .unwrap();
  2219. }
  2220. fn prologue() -> &'static str {
  2221. "
  2222. use std::mem;
  2223. use compiler_builtins::float::cmp::__gedf2;
  2224. fn to_f64(x: u64) -> f64 {
  2225. unsafe { mem::transmute(x) }
  2226. }
  2227. static TEST_CASES: &[((u64, u64), i32)] = &[
  2228. "
  2229. }
  2230. fn epilogue() -> &'static str {
  2231. "
  2232. ];
  2233. #[test]
  2234. fn gedf2() {
  2235. for &((a, b), c) in TEST_CASES {
  2236. let c_ = __gedf2(to_f64(a), to_f64(b));
  2237. assert_eq!(((a, b), c), ((a, b), c_));
  2238. }
  2239. }
  2240. "
  2241. }
  2242. }
  2243. #[derive(Eq, Hash, PartialEq)]
  2244. pub struct Gesf2 {
  2245. a: u32,
  2246. b: u32,
  2247. c: i32,
  2248. }
  2249. impl TestCase for Gesf2 {
  2250. fn name() -> &'static str {
  2251. "gesf2"
  2252. }
  2253. fn generate<R>(rng: &mut R) -> Option<Self>
  2254. where
  2255. R: Rng,
  2256. Self: Sized,
  2257. {
  2258. let a = gen_f32(rng);
  2259. let b = gen_f32(rng);
  2260. // TODO accept NaNs. We don't do that right now because we can't check
  2261. // for NaN-ness on the thumb targets (due to missing intrinsics)
  2262. if a.is_nan() || b.is_nan() {
  2263. return None;
  2264. }
  2265. let c;
  2266. if a.is_nan() || b.is_nan() {
  2267. c = -1;
  2268. } else if a < b {
  2269. c = -1;
  2270. } else if a > b {
  2271. c = 1;
  2272. } else {
  2273. c = 0;
  2274. }
  2275. Some(Gesf2 { a: to_u32(a), b: to_u32(b), c })
  2276. }
  2277. fn to_string(&self, buffer: &mut String) {
  2278. writeln!(
  2279. buffer,
  2280. "(({a}, {b}), {c}),",
  2281. a = self.a,
  2282. b = self.b,
  2283. c = self.c
  2284. )
  2285. .unwrap();
  2286. }
  2287. fn prologue() -> &'static str {
  2288. "
  2289. use std::mem;
  2290. use compiler_builtins::float::cmp::__gesf2;
  2291. fn to_f32(x: u32) -> f32 {
  2292. unsafe { mem::transmute(x) }
  2293. }
  2294. static TEST_CASES: &[((u32, u32), i32)] = &[
  2295. "
  2296. }
  2297. fn epilogue() -> &'static str {
  2298. "
  2299. ];
  2300. #[test]
  2301. fn gesf2() {
  2302. for &((a, b), c) in TEST_CASES {
  2303. let c_ = __gesf2(to_f32(a), to_f32(b));
  2304. assert_eq!(((a, b), c), ((a, b), c_));
  2305. }
  2306. }
  2307. "
  2308. }
  2309. }
  2310. #[derive(Eq, Hash, PartialEq)]
  2311. pub struct Ledf2 {
  2312. a: u64,
  2313. b: u64,
  2314. c: i32,
  2315. }
  2316. impl TestCase for Ledf2 {
  2317. fn name() -> &'static str {
  2318. "ledf2"
  2319. }
  2320. fn generate<R>(rng: &mut R) -> Option<Self>
  2321. where
  2322. R: Rng,
  2323. Self: Sized,
  2324. {
  2325. let a = gen_f64(rng);
  2326. let b = gen_f64(rng);
  2327. // TODO accept NaNs. We don't do that right now because we can't check
  2328. // for NaN-ness on the thumb targets (due to missing intrinsics)
  2329. if a.is_nan() || b.is_nan() {
  2330. return None;
  2331. }
  2332. let c;
  2333. if a.is_nan() || b.is_nan() {
  2334. c = 1;
  2335. } else if a < b {
  2336. c = -1;
  2337. } else if a > b {
  2338. c = 1;
  2339. } else {
  2340. c = 0;
  2341. }
  2342. Some(Ledf2 { a: to_u64(a), b: to_u64(b), c })
  2343. }
  2344. fn to_string(&self, buffer: &mut String) {
  2345. writeln!(
  2346. buffer,
  2347. "(({a}, {b}), {c}),",
  2348. a = self.a,
  2349. b = self.b,
  2350. c = self.c
  2351. )
  2352. .unwrap();
  2353. }
  2354. fn prologue() -> &'static str {
  2355. "
  2356. use std::mem;
  2357. use compiler_builtins::float::cmp::__ledf2;
  2358. fn to_f64(x: u64) -> f64 {
  2359. unsafe { mem::transmute(x) }
  2360. }
  2361. static TEST_CASES: &[((u64, u64), i32)] = &[
  2362. "
  2363. }
  2364. fn epilogue() -> &'static str {
  2365. "
  2366. ];
  2367. #[test]
  2368. fn ledf2() {
  2369. for &((a, b), c) in TEST_CASES {
  2370. let c_ = __ledf2(to_f64(a), to_f64(b));
  2371. assert_eq!(((a, b), c), ((a, b), c_));
  2372. }
  2373. }
  2374. "
  2375. }
  2376. }
  2377. #[derive(Eq, Hash, PartialEq)]
  2378. pub struct Lesf2 {
  2379. a: u32,
  2380. b: u32,
  2381. c: i32,
  2382. }
  2383. impl TestCase for Lesf2 {
  2384. fn name() -> &'static str {
  2385. "lesf2"
  2386. }
  2387. fn generate<R>(rng: &mut R) -> Option<Self>
  2388. where
  2389. R: Rng,
  2390. Self: Sized,
  2391. {
  2392. let a = gen_f32(rng);
  2393. let b = gen_f32(rng);
  2394. // TODO accept NaNs. We don't do that right now because we can't check
  2395. // for NaN-ness on the thumb targets (due to missing intrinsics)
  2396. if a.is_nan() || b.is_nan() {
  2397. return None;
  2398. }
  2399. let c;
  2400. if a.is_nan() || b.is_nan() {
  2401. c = 1;
  2402. } else if a < b {
  2403. c = -1;
  2404. } else if a > b {
  2405. c = 1;
  2406. } else {
  2407. c = 0;
  2408. }
  2409. Some(Lesf2 { a: to_u32(a), b: to_u32(b), c })
  2410. }
  2411. fn to_string(&self, buffer: &mut String) {
  2412. writeln!(
  2413. buffer,
  2414. "(({a}, {b}), {c}),",
  2415. a = self.a,
  2416. b = self.b,
  2417. c = self.c
  2418. )
  2419. .unwrap();
  2420. }
  2421. fn prologue() -> &'static str {
  2422. "
  2423. use std::mem;
  2424. use compiler_builtins::float::cmp::__lesf2;
  2425. fn to_f32(x: u32) -> f32 {
  2426. unsafe { mem::transmute(x) }
  2427. }
  2428. static TEST_CASES: &[((u32, u32), i32)] = &[
  2429. "
  2430. }
  2431. fn epilogue() -> &'static str {
  2432. "
  2433. ];
  2434. #[test]
  2435. fn lesf2() {
  2436. for &((a, b), c) in TEST_CASES {
  2437. let c_ = __lesf2(to_f32(a), to_f32(b));
  2438. assert_eq!(((a, b), c), ((a, b), c_));
  2439. }
  2440. }
  2441. "
  2442. }
  2443. }
  2444. #[derive(Eq, Hash, PartialEq)]
  2445. pub struct Moddi3 {
  2446. a: i64,
  2447. b: i64,
  2448. c: i64,
  2449. }
  2450. impl TestCase for Moddi3 {
  2451. fn name() -> &'static str {
  2452. "moddi3"
  2453. }
  2454. fn generate<R>(rng: &mut R) -> Option<Self>
  2455. where
  2456. R: Rng,
  2457. Self: Sized,
  2458. {
  2459. let a = gen_i64(rng);
  2460. let b = gen_i64(rng);
  2461. if b == 0 {
  2462. return None;
  2463. }
  2464. let c = a % b;
  2465. Some(Moddi3 { a, b, c })
  2466. }
  2467. fn to_string(&self, buffer: &mut String) {
  2468. writeln!(
  2469. buffer,
  2470. "(({a}, {b}), {c}),",
  2471. a = self.a,
  2472. b = self.b,
  2473. c = self.c
  2474. )
  2475. .unwrap();
  2476. }
  2477. fn prologue() -> &'static str {
  2478. "
  2479. use compiler_builtins::int::sdiv::__moddi3;
  2480. static TEST_CASES: &[((i64, i64), i64)] = &[
  2481. "
  2482. }
  2483. fn epilogue() -> &'static str {
  2484. "
  2485. ];
  2486. #[test]
  2487. fn moddi3() {
  2488. for &((a, b), c) in TEST_CASES {
  2489. let c_ = __moddi3(a, b);
  2490. assert_eq!(((a, b), c), ((a, b), c_));
  2491. }
  2492. }
  2493. "
  2494. }
  2495. }
  2496. #[derive(Eq, Hash, PartialEq)]
  2497. pub struct Modsi3 {
  2498. a: i32,
  2499. b: i32,
  2500. c: i32,
  2501. }
  2502. impl TestCase for Modsi3 {
  2503. fn name() -> &'static str {
  2504. "modsi3"
  2505. }
  2506. fn generate<R>(rng: &mut R) -> Option<Self>
  2507. where
  2508. R: Rng,
  2509. Self: Sized,
  2510. {
  2511. let a = gen_i32(rng);
  2512. let b = gen_i32(rng);
  2513. if b == 0 {
  2514. return None;
  2515. }
  2516. let c = a % b;
  2517. Some(Modsi3 { a, b, c })
  2518. }
  2519. fn to_string(&self, buffer: &mut String) {
  2520. writeln!(
  2521. buffer,
  2522. "(({a}, {b}), {c}),",
  2523. a = self.a,
  2524. b = self.b,
  2525. c = self.c
  2526. )
  2527. .unwrap();
  2528. }
  2529. fn prologue() -> &'static str {
  2530. "
  2531. use compiler_builtins::int::sdiv::__modsi3;
  2532. static TEST_CASES: &[((i32, i32), i32)] = &[
  2533. "
  2534. }
  2535. fn epilogue() -> &'static str {
  2536. "
  2537. ];
  2538. #[test]
  2539. fn modsi3() {
  2540. for &((a, b), c) in TEST_CASES {
  2541. let c_ = __modsi3(a, b);
  2542. assert_eq!(((a, b), c), ((a, b), c_));
  2543. }
  2544. }
  2545. "
  2546. }
  2547. }
  2548. #[derive(Eq, Hash, PartialEq)]
  2549. pub struct Modti3 {
  2550. a: i128,
  2551. b: i128,
  2552. c: i128,
  2553. }
  2554. impl TestCase for Modti3 {
  2555. fn name() -> &'static str {
  2556. "modti3"
  2557. }
  2558. fn generate<R>(rng: &mut R) -> Option<Self>
  2559. where
  2560. R: Rng,
  2561. Self: Sized,
  2562. {
  2563. let a = gen_i128(rng);
  2564. let b = gen_i128(rng);
  2565. if b == 0 {
  2566. return None;
  2567. }
  2568. let c = a % b;
  2569. Some(Modti3 { a, b, c })
  2570. }
  2571. fn to_string(&self, buffer: &mut String) {
  2572. writeln!(
  2573. buffer,
  2574. "(({a}, {b}), {c}),",
  2575. a = self.a,
  2576. b = self.b,
  2577. c = self.c
  2578. )
  2579. .unwrap();
  2580. }
  2581. fn prologue() -> &'static str {
  2582. "
  2583. use compiler_builtins::int::sdiv::__modti3;
  2584. static TEST_CASES: &[((i128, i128), i128)] = &[
  2585. "
  2586. }
  2587. fn epilogue() -> &'static str {
  2588. "
  2589. ];
  2590. #[test]
  2591. fn modti3() {
  2592. for &((a, b), c) in TEST_CASES {
  2593. let c_ = __modti3(a, b);
  2594. assert_eq!(((a, b), c), ((a, b), c_));
  2595. }
  2596. }
  2597. "
  2598. }
  2599. }
  2600. #[derive(Eq, Hash, PartialEq)]
  2601. struct Muldi3 {
  2602. a: u64,
  2603. b: u64,
  2604. c: u64,
  2605. }
  2606. impl TestCase for Muldi3 {
  2607. fn name() -> &'static str {
  2608. "muldi3"
  2609. }
  2610. fn generate<R>(rng: &mut R) -> Option<Self>
  2611. where
  2612. R: Rng,
  2613. Self: Sized,
  2614. {
  2615. let a = gen_u64(rng);
  2616. let b = gen_u64(rng);
  2617. let c = a.wrapping_mul(b);
  2618. Some(Muldi3 { a, b, c })
  2619. }
  2620. fn to_string(&self, buffer: &mut String) {
  2621. writeln!(
  2622. buffer,
  2623. "(({a}, {b}), {c}),",
  2624. a = self.a,
  2625. b = self.b,
  2626. c = self.c
  2627. )
  2628. .unwrap();
  2629. }
  2630. fn prologue() -> &'static str {
  2631. "
  2632. use compiler_builtins::int::mul::__muldi3;
  2633. static TEST_CASES: &[((u64, u64), u64)] = &[
  2634. "
  2635. }
  2636. fn epilogue() -> &'static str {
  2637. "
  2638. ];
  2639. #[test]
  2640. fn muldi3() {
  2641. for &((a, b), c) in TEST_CASES {
  2642. let c_ = __muldi3(a, b);
  2643. assert_eq!(((a, b), c), ((a, b), c_));
  2644. }
  2645. }
  2646. "
  2647. }
  2648. }
  2649. #[derive(Eq, Hash, PartialEq)]
  2650. pub struct Mulodi4 {
  2651. a: i64,
  2652. b: i64,
  2653. c: i64,
  2654. overflow: u32,
  2655. }
  2656. impl TestCase for Mulodi4 {
  2657. fn name() -> &'static str {
  2658. "mulodi4"
  2659. }
  2660. fn generate<R>(rng: &mut R) -> Option<Self>
  2661. where
  2662. R: Rng,
  2663. {
  2664. let a = gen_i64(rng);
  2665. let b = gen_i64(rng);
  2666. let c = a.wrapping_mul(b);
  2667. let overflow = if a.checked_mul(b).is_some() { 0 } else { 1 };
  2668. Some(Mulodi4 { a, b, c, overflow })
  2669. }
  2670. fn to_string(&self, buffer: &mut String) {
  2671. writeln!(
  2672. buffer,
  2673. "(({a}, {b}), ({c}, {overflow})),",
  2674. a = self.a,
  2675. b = self.b,
  2676. c = self.c,
  2677. overflow = self.overflow
  2678. )
  2679. .unwrap();
  2680. }
  2681. fn prologue() -> &'static str {
  2682. "
  2683. use compiler_builtins::int::mul::__mulodi4;
  2684. static TEST_CASES: &[((i64, i64), (i64, i32))] = &[
  2685. "
  2686. }
  2687. fn epilogue() -> &'static str {
  2688. "
  2689. ];
  2690. #[test]
  2691. fn mulodi4() {
  2692. let mut overflow_ = 2;
  2693. for &((a, b), (c, overflow)) in TEST_CASES {
  2694. let c_ = __mulodi4(a, b, &mut overflow_);
  2695. assert_eq!(((a, b), (c, overflow)), ((a, b), (c_, overflow_)));
  2696. }
  2697. }
  2698. "
  2699. }
  2700. }
  2701. #[derive(Eq, Hash, PartialEq)]
  2702. pub struct Mulosi4 {
  2703. a: i32,
  2704. b: i32,
  2705. c: i32,
  2706. overflow: u32,
  2707. }
  2708. impl TestCase for Mulosi4 {
  2709. fn name() -> &'static str {
  2710. "mulosi4"
  2711. }
  2712. fn generate<R>(rng: &mut R) -> Option<Self>
  2713. where
  2714. R: Rng,
  2715. {
  2716. let a = gen_i32(rng);
  2717. let b = gen_i32(rng);
  2718. let c = a.wrapping_mul(b);
  2719. let overflow = if a.checked_mul(b).is_some() { 0 } else { 1 };
  2720. Some(Mulosi4 { a, b, c, overflow })
  2721. }
  2722. fn prologue() -> &'static str {
  2723. "
  2724. use compiler_builtins::int::mul::__mulosi4;
  2725. static TEST_CASES: &[((i32, i32), (i32, i32))] = &[
  2726. "
  2727. }
  2728. fn epilogue() -> &'static str {
  2729. "
  2730. ];
  2731. #[test]
  2732. fn mulosi4() {
  2733. let mut overflow_ = 2;
  2734. for &((a, b), (c, overflow)) in TEST_CASES {
  2735. let c_ = __mulosi4(a, b, &mut overflow_);
  2736. assert_eq!(((a, b), (c, overflow)), ((a, b), (c_, overflow_)));
  2737. }
  2738. }
  2739. "
  2740. }
  2741. fn to_string(&self, buffer: &mut String) {
  2742. writeln!(
  2743. buffer,
  2744. "(({a}, {b}), ({c}, {overflow})),",
  2745. a = self.a,
  2746. b = self.b,
  2747. c = self.c,
  2748. overflow = self.overflow
  2749. )
  2750. .unwrap();
  2751. }
  2752. }
  2753. #[derive(Eq, Hash, PartialEq)]
  2754. pub struct Muloti4 {
  2755. a: i128,
  2756. b: i128,
  2757. c: i128,
  2758. overflow: u32,
  2759. }
  2760. impl TestCase for Muloti4 {
  2761. fn name() -> &'static str {
  2762. "muloti4"
  2763. }
  2764. fn generate<R>(rng: &mut R) -> Option<Self>
  2765. where
  2766. R: Rng,
  2767. {
  2768. let a = gen_i128(rng);
  2769. let b = gen_i128(rng);
  2770. let c = a.wrapping_mul(b);
  2771. let overflow = if a.checked_mul(b).is_some() { 0 } else { 1 };
  2772. Some(Muloti4 { a, b, c, overflow })
  2773. }
  2774. fn prologue() -> &'static str {
  2775. "
  2776. use compiler_builtins::int::mul::__muloti4;
  2777. static TEST_CASES: &[((i128, i128), (i128, i32))] = &[
  2778. "
  2779. }
  2780. fn epilogue() -> &'static str {
  2781. "
  2782. ];
  2783. #[test]
  2784. fn muloti4() {
  2785. let mut overflow_ = 2;
  2786. for &((a, b), (c, overflow)) in TEST_CASES {
  2787. let c_ = __muloti4(a, b, &mut overflow_);
  2788. assert_eq!(((a, b), (c, overflow)), ((a, b), (c_, overflow_)));
  2789. }
  2790. }
  2791. "
  2792. }
  2793. fn to_string(&self, buffer: &mut String) {
  2794. writeln!(
  2795. buffer,
  2796. "(({a}, {b}), ({c}, {overflow})),",
  2797. a = self.a,
  2798. b = self.b,
  2799. c = self.c,
  2800. overflow = self.overflow
  2801. )
  2802. .unwrap();
  2803. }
  2804. }
  2805. #[derive(Eq, Hash, PartialEq)]
  2806. pub struct Multi3 {
  2807. a: i128,
  2808. b: i128,
  2809. c: i128,
  2810. }
  2811. impl TestCase for Multi3 {
  2812. fn name() -> &'static str {
  2813. "multi3"
  2814. }
  2815. fn generate<R>(rng: &mut R) -> Option<Self>
  2816. where
  2817. R: Rng,
  2818. Self: Sized,
  2819. {
  2820. let a = gen_i128(rng);
  2821. let b = gen_i128(rng);
  2822. let c = a.wrapping_mul(b);
  2823. Some(Multi3 { a, b, c })
  2824. }
  2825. fn to_string(&self, buffer: &mut String) {
  2826. writeln!(
  2827. buffer,
  2828. "(({a}, {b}), {c}),",
  2829. a = self.a,
  2830. b = self.b,
  2831. c = self.c
  2832. )
  2833. .unwrap();
  2834. }
  2835. fn prologue() -> &'static str {
  2836. "
  2837. use compiler_builtins::int::mul::__multi3;
  2838. static TEST_CASES: &[((i128, i128), i128)] = &[
  2839. "
  2840. }
  2841. fn epilogue() -> &'static str {
  2842. "
  2843. ];
  2844. #[test]
  2845. fn multi3() {
  2846. for &((a, b), c) in TEST_CASES {
  2847. let c_ = __multi3(a, b);
  2848. assert_eq!(((a, b), c), ((a, b), c_));
  2849. }
  2850. }
  2851. "
  2852. }
  2853. }
  2854. #[derive(Eq, Hash, PartialEq)]
  2855. pub struct Powidf2 {
  2856. a: u64, // f64
  2857. b: i32,
  2858. c: u64, // f64
  2859. }
  2860. impl TestCase for Powidf2 {
  2861. fn name() -> &'static str {
  2862. "powidf2"
  2863. }
  2864. fn generate<R>(rng: &mut R) -> Option<Self>
  2865. where
  2866. R: Rng,
  2867. Self: Sized,
  2868. {
  2869. let a = gen_f64(rng);
  2870. let b = gen_i32(rng);
  2871. let c = a.powi(b);
  2872. // TODO accept NaNs. We don't do that right now because we can't check
  2873. // for NaN-ness on the thumb targets
  2874. if a.is_nan() || c.is_nan() {
  2875. return None;
  2876. }
  2877. Some(
  2878. Powidf2 {
  2879. a: to_u64(a),
  2880. b,
  2881. c: to_u64(c),
  2882. },
  2883. )
  2884. }
  2885. fn to_string(&self, buffer: &mut String) {
  2886. writeln!(
  2887. buffer,
  2888. "(({a}, {b}), {c}),",
  2889. a = self.a,
  2890. b = self.b,
  2891. c = self.c
  2892. )
  2893. .unwrap();
  2894. }
  2895. fn prologue() -> &'static str {
  2896. r#"
  2897. #[cfg(all(target_arch = "arm",
  2898. not(any(target_env = "gnu", target_env = "musl")),
  2899. target_os = "linux",
  2900. test))]
  2901. use core::mem;
  2902. #[cfg(not(all(target_arch = "arm",
  2903. not(any(target_env = "gnu", target_env = "musl")),
  2904. target_os = "linux",
  2905. test)))]
  2906. use std::mem;
  2907. use compiler_builtins::float::pow::__powidf2;
  2908. fn mk_f64(x: u64) -> f64 {
  2909. unsafe { mem::transmute(x) }
  2910. }
  2911. fn to_u64(x: f64) -> u64 {
  2912. unsafe { mem::transmute(x) }
  2913. }
  2914. static TEST_CASES: &[((u64, i32), u64)] = &[
  2915. "#
  2916. }
  2917. fn epilogue() -> &'static str {
  2918. "
  2919. ];
  2920. #[test]
  2921. fn powidf2() {
  2922. for &((a, b), c) in TEST_CASES {
  2923. let c_ = __powidf2(mk_f64(a), b);
  2924. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  2925. }
  2926. }
  2927. "
  2928. }
  2929. }
  2930. #[derive(Eq, Hash, PartialEq)]
  2931. pub struct Powisf2 {
  2932. a: u32, // f32
  2933. b: i32,
  2934. c: u32, // f32
  2935. }
  2936. impl TestCase for Powisf2 {
  2937. fn name() -> &'static str {
  2938. "powisf2"
  2939. }
  2940. fn generate<R>(rng: &mut R) -> Option<Self>
  2941. where
  2942. R: Rng,
  2943. Self: Sized,
  2944. {
  2945. let a = gen_f32(rng);
  2946. let b = gen_i32(rng);
  2947. let c = a.powi(b);
  2948. // TODO accept NaNs. We don't do that right now because we can't check
  2949. // for NaN-ness on the thumb targets
  2950. if a.is_nan() || c.is_nan() {
  2951. return None;
  2952. }
  2953. Some(
  2954. Powisf2 {
  2955. a: to_u32(a),
  2956. b,
  2957. c: to_u32(c),
  2958. },
  2959. )
  2960. }
  2961. fn to_string(&self, buffer: &mut String) {
  2962. writeln!(
  2963. buffer,
  2964. "(({a}, {b}), {c}),",
  2965. a = self.a,
  2966. b = self.b,
  2967. c = self.c
  2968. )
  2969. .unwrap();
  2970. }
  2971. fn prologue() -> &'static str {
  2972. r#"
  2973. #[cfg(all(target_arch = "arm",
  2974. not(any(target_env = "gnu", target_env = "musl")),
  2975. target_os = "linux",
  2976. test))]
  2977. use core::mem;
  2978. #[cfg(not(all(target_arch = "arm",
  2979. not(any(target_env = "gnu", target_env = "musl")),
  2980. target_os = "linux",
  2981. test)))]
  2982. use std::mem;
  2983. use compiler_builtins::float::pow::__powisf2;
  2984. fn mk_f32(x: u32) -> f32 {
  2985. unsafe { mem::transmute(x) }
  2986. }
  2987. fn to_u32(x: f32) -> u32 {
  2988. unsafe { mem::transmute(x) }
  2989. }
  2990. static TEST_CASES: &[((u32, i32), u32)] = &[
  2991. "#
  2992. }
  2993. fn epilogue() -> &'static str {
  2994. "
  2995. ];
  2996. #[test]
  2997. fn powisf2() {
  2998. for &((a, b), c) in TEST_CASES {
  2999. let c_ = __powisf2(mk_f32(a), b);
  3000. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  3001. }
  3002. }
  3003. "
  3004. }
  3005. }
  3006. #[derive(Eq, Hash, PartialEq)]
  3007. pub struct Lshrdi3 {
  3008. a: u64,
  3009. b: u32,
  3010. c: u64,
  3011. }
  3012. impl TestCase for Lshrdi3 {
  3013. fn name() -> &'static str {
  3014. "lshrdi3"
  3015. }
  3016. fn generate<R>(rng: &mut R) -> Option<Self>
  3017. where
  3018. R: Rng,
  3019. Self: Sized,
  3020. {
  3021. let a = gen_u64(rng);
  3022. let b = (rng.gen::<u8>() % 64) as u32;
  3023. let c = a >> b;
  3024. Some(Lshrdi3 { a, b, c })
  3025. }
  3026. fn to_string(&self, buffer: &mut String) {
  3027. writeln!(
  3028. buffer,
  3029. "(({a}, {b}), {c}),",
  3030. a = self.a,
  3031. b = self.b,
  3032. c = self.c
  3033. )
  3034. .unwrap();
  3035. }
  3036. fn prologue() -> &'static str {
  3037. "
  3038. use compiler_builtins::int::shift::__lshrdi3;
  3039. static TEST_CASES: &[((u64, u32), u64)] = &[
  3040. "
  3041. }
  3042. fn epilogue() -> &'static str {
  3043. "
  3044. ];
  3045. #[test]
  3046. fn lshrdi3() {
  3047. for &((a, b), c) in TEST_CASES {
  3048. let c_ = __lshrdi3(a, b);
  3049. assert_eq!(((a, b), c), ((a, b), c_));
  3050. }
  3051. }
  3052. "
  3053. }
  3054. }
  3055. #[derive(Eq, Hash, PartialEq)]
  3056. pub struct Lshrti3 {
  3057. a: u128,
  3058. b: u32,
  3059. c: u128,
  3060. }
  3061. impl TestCase for Lshrti3 {
  3062. fn name() -> &'static str {
  3063. "lshrti3"
  3064. }
  3065. fn generate<R>(rng: &mut R) -> Option<Self>
  3066. where
  3067. R: Rng,
  3068. Self: Sized,
  3069. {
  3070. let a = gen_u128(rng);
  3071. let b = (rng.gen::<u8>() % 128) as u32;
  3072. let c = a >> b;
  3073. Some(Lshrti3 { a, b, c })
  3074. }
  3075. fn to_string(&self, buffer: &mut String) {
  3076. writeln!(
  3077. buffer,
  3078. "(({a}, {b}), {c}),",
  3079. a = self.a,
  3080. b = self.b,
  3081. c = self.c
  3082. )
  3083. .unwrap();
  3084. }
  3085. fn prologue() -> &'static str {
  3086. "
  3087. use compiler_builtins::int::shift::__lshrti3;
  3088. static TEST_CASES: &[((u128, u32), u128)] = &[
  3089. "
  3090. }
  3091. fn epilogue() -> &'static str {
  3092. "
  3093. ];
  3094. #[test]
  3095. fn lshrti3() {
  3096. for &((a, b), c) in TEST_CASES {
  3097. let c_ = __lshrti3(a, b);
  3098. assert_eq!(((a, b), c), ((a, b), c_));
  3099. }
  3100. }
  3101. "
  3102. }
  3103. }
  3104. #[derive(Eq, Hash, PartialEq)]
  3105. pub struct Subdf3 {
  3106. a: u64, // f64
  3107. b: u64, // f64
  3108. c: u64, // f64
  3109. }
  3110. impl TestCase for Subdf3 {
  3111. fn name() -> &'static str {
  3112. "subdf3"
  3113. }
  3114. fn generate<R>(rng: &mut R) -> Option<Self>
  3115. where
  3116. R: Rng,
  3117. Self: Sized,
  3118. {
  3119. let a = gen_f64(rng);
  3120. let b = gen_f64(rng);
  3121. let c = a - b;
  3122. // TODO accept NaNs. We don't do that right now because we can't check
  3123. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3124. if a.is_nan() || b.is_nan() || c.is_nan() {
  3125. return None;
  3126. }
  3127. Some(
  3128. Subdf3 {
  3129. a: to_u64(a),
  3130. b: to_u64(b),
  3131. c: to_u64(c),
  3132. },
  3133. )
  3134. }
  3135. fn to_string(&self, buffer: &mut String) {
  3136. writeln!(
  3137. buffer,
  3138. "(({a}, {b}), {c}),",
  3139. a = self.a,
  3140. b = self.b,
  3141. c = self.c
  3142. )
  3143. .unwrap();
  3144. }
  3145. fn prologue() -> &'static str {
  3146. r#"
  3147. #[cfg(all(target_arch = "arm",
  3148. not(any(target_env = "gnu", target_env = "musl")),
  3149. target_os = "linux",
  3150. test))]
  3151. use core::mem;
  3152. #[cfg(not(all(target_arch = "arm",
  3153. not(any(target_env = "gnu", target_env = "musl")),
  3154. target_os = "linux",
  3155. test)))]
  3156. use std::mem;
  3157. use compiler_builtins::float::sub::__subdf3;
  3158. fn mk_f64(x: u64) -> f64 {
  3159. unsafe { mem::transmute(x) }
  3160. }
  3161. fn to_u64(x: f64) -> u64 {
  3162. unsafe { mem::transmute(x) }
  3163. }
  3164. static TEST_CASES: &[((u64, u64), u64)] = &[
  3165. "#
  3166. }
  3167. fn epilogue() -> &'static str {
  3168. "
  3169. ];
  3170. #[test]
  3171. fn subdf3() {
  3172. for &((a, b), c) in TEST_CASES {
  3173. let c_ = __subdf3(mk_f64(a), mk_f64(b));
  3174. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  3175. }
  3176. }
  3177. "
  3178. }
  3179. }
  3180. #[derive(Eq, Hash, PartialEq)]
  3181. pub struct Subsf3 {
  3182. a: u32, // f32
  3183. b: u32, // f32
  3184. c: u32, // f32
  3185. }
  3186. impl TestCase for Subsf3 {
  3187. fn name() -> &'static str {
  3188. "subsf3"
  3189. }
  3190. fn generate<R>(rng: &mut R) -> Option<Self>
  3191. where
  3192. R: Rng,
  3193. Self: Sized,
  3194. {
  3195. let a = gen_f32(rng);
  3196. let b = gen_f32(rng);
  3197. let c = a - b;
  3198. // TODO accept NaNs. We don't do that right now because we can't check
  3199. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3200. if a.is_nan() || b.is_nan() || c.is_nan() {
  3201. return None;
  3202. }
  3203. Some(
  3204. Subsf3 {
  3205. a: to_u32(a),
  3206. b: to_u32(b),
  3207. c: to_u32(c),
  3208. },
  3209. )
  3210. }
  3211. fn to_string(&self, buffer: &mut String) {
  3212. writeln!(
  3213. buffer,
  3214. "(({a}, {b}), {c}),",
  3215. a = self.a,
  3216. b = self.b,
  3217. c = self.c
  3218. )
  3219. .unwrap();
  3220. }
  3221. fn prologue() -> &'static str {
  3222. r#"
  3223. #[cfg(all(target_arch = "arm",
  3224. not(any(target_env = "gnu", target_env = "musl")),
  3225. target_os = "linux",
  3226. test))]
  3227. use core::mem;
  3228. #[cfg(not(all(target_arch = "arm",
  3229. not(any(target_env = "gnu", target_env = "musl")),
  3230. target_os = "linux",
  3231. test)))]
  3232. use std::mem;
  3233. use compiler_builtins::float::sub::__subsf3;
  3234. fn mk_f32(x: u32) -> f32 {
  3235. unsafe { mem::transmute(x) }
  3236. }
  3237. fn to_u32(x: f32) -> u32 {
  3238. unsafe { mem::transmute(x) }
  3239. }
  3240. static TEST_CASES: &[((u32, u32), u32)] = &[
  3241. "#
  3242. }
  3243. fn epilogue() -> &'static str {
  3244. "
  3245. ];
  3246. #[test]
  3247. fn subsf3() {
  3248. for &((a, b), c) in TEST_CASES {
  3249. let c_ = __subsf3(mk_f32(a), mk_f32(b));
  3250. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  3251. }
  3252. }
  3253. "
  3254. }
  3255. }
  3256. #[derive(Eq, Hash, PartialEq)]
  3257. pub struct SubU128 {
  3258. a: u128,
  3259. b: u128,
  3260. c: u128,
  3261. }
  3262. impl TestCase for SubU128 {
  3263. fn name() -> &'static str {
  3264. "u128_sub"
  3265. }
  3266. fn generate<R>(rng: &mut R) -> Option<Self>
  3267. where
  3268. R: Rng,
  3269. Self: Sized,
  3270. {
  3271. let a = gen_u128(rng);
  3272. let b = gen_u128(rng);
  3273. let c = a.wrapping_sub(b);
  3274. Some(SubU128 { a, b, c })
  3275. }
  3276. fn to_string(&self, buffer: &mut String) {
  3277. writeln!(
  3278. buffer,
  3279. "(({a}, {b}), {c}),",
  3280. a = self.a,
  3281. b = self.b,
  3282. c = self.c
  3283. )
  3284. .unwrap();
  3285. }
  3286. fn prologue() -> &'static str {
  3287. "
  3288. use compiler_builtins::int::addsub::rust_u128_sub;
  3289. static TEST_CASES: &[((u128, u128), u128)] = &[
  3290. "
  3291. }
  3292. fn epilogue() -> &'static str {
  3293. "
  3294. ];
  3295. #[test]
  3296. fn u128_sub() {
  3297. for &((a, b), c) in TEST_CASES {
  3298. let c_ = rust_u128_sub(a, b);
  3299. assert_eq!(((a, b), c), ((a, b), c_));
  3300. }
  3301. }
  3302. "
  3303. }
  3304. }
  3305. #[derive(Eq, Hash, PartialEq)]
  3306. pub struct SubI128 {
  3307. a: i128,
  3308. b: i128,
  3309. c: i128,
  3310. }
  3311. impl TestCase for SubI128 {
  3312. fn name() -> &'static str {
  3313. "i128_sub"
  3314. }
  3315. fn generate<R>(rng: &mut R) -> Option<Self>
  3316. where
  3317. R: Rng,
  3318. Self: Sized,
  3319. {
  3320. let a = gen_i128(rng);
  3321. let b = gen_i128(rng);
  3322. let c = a.wrapping_sub(b);
  3323. Some(SubI128 { a, b, c })
  3324. }
  3325. fn to_string(&self, buffer: &mut String) {
  3326. writeln!(
  3327. buffer,
  3328. "(({a}, {b}), {c}),",
  3329. a = self.a,
  3330. b = self.b,
  3331. c = self.c
  3332. )
  3333. .unwrap();
  3334. }
  3335. fn prologue() -> &'static str {
  3336. "
  3337. use compiler_builtins::int::addsub::rust_i128_sub;
  3338. static TEST_CASES: &[((i128, i128), i128)] = &[
  3339. "
  3340. }
  3341. fn epilogue() -> &'static str {
  3342. "
  3343. ];
  3344. #[test]
  3345. fn i128_sub() {
  3346. for &((a, b), c) in TEST_CASES {
  3347. let c_ = rust_i128_sub(a, b);
  3348. assert_eq!(((a, b), c), ((a, b), c_));
  3349. }
  3350. }
  3351. "
  3352. }
  3353. }
  3354. #[derive(Eq, Hash, PartialEq)]
  3355. pub struct SuboU128 {
  3356. a: u128,
  3357. b: u128,
  3358. c: u128,
  3359. d: bool,
  3360. }
  3361. impl TestCase for SuboU128 {
  3362. fn name() -> &'static str {
  3363. "u128_subo"
  3364. }
  3365. fn generate<R>(rng: &mut R) -> Option<Self>
  3366. where
  3367. R: Rng,
  3368. Self: Sized,
  3369. {
  3370. let a = gen_u128(rng);
  3371. let b = gen_u128(rng);
  3372. let (c, d) = a.overflowing_sub(b);
  3373. Some(SuboU128 { a, b, c, d })
  3374. }
  3375. fn to_string(&self, buffer: &mut String) {
  3376. writeln!(
  3377. buffer,
  3378. "(({a}, {b}), ({c}, {d})),",
  3379. a = self.a,
  3380. b = self.b,
  3381. c = self.c,
  3382. d = self.d
  3383. )
  3384. .unwrap();
  3385. }
  3386. fn prologue() -> &'static str {
  3387. "
  3388. use compiler_builtins::int::addsub::rust_u128_subo;
  3389. static TEST_CASES: &[((u128, u128), (u128, bool))] = &[
  3390. "
  3391. }
  3392. fn epilogue() -> &'static str {
  3393. "
  3394. ];
  3395. #[test]
  3396. fn u128_subo() {
  3397. for &((a, b), (c, d)) in TEST_CASES {
  3398. let (c_, d_) = rust_u128_subo(a, b);
  3399. assert_eq!(((a, b), (c, d)), ((a, b), (c_, d_)));
  3400. }
  3401. }
  3402. "
  3403. }
  3404. }
  3405. #[derive(Eq, Hash, PartialEq)]
  3406. pub struct SuboI128 {
  3407. a: i128,
  3408. b: i128,
  3409. c: i128,
  3410. d: bool,
  3411. }
  3412. impl TestCase for SuboI128 {
  3413. fn name() -> &'static str {
  3414. "i128_subo"
  3415. }
  3416. fn generate<R>(rng: &mut R) -> Option<Self>
  3417. where
  3418. R: Rng,
  3419. Self: Sized,
  3420. {
  3421. let a = gen_i128(rng);
  3422. let b = gen_i128(rng);
  3423. let (c, d) = a.overflowing_sub(b);
  3424. Some(SuboI128 { a, b, c, d })
  3425. }
  3426. fn to_string(&self, buffer: &mut String) {
  3427. writeln!(
  3428. buffer,
  3429. "(({a}, {b}), ({c}, {d})),",
  3430. a = self.a,
  3431. b = self.b,
  3432. c = self.c,
  3433. d = self.d
  3434. )
  3435. .unwrap();
  3436. }
  3437. fn prologue() -> &'static str {
  3438. "
  3439. use compiler_builtins::int::addsub::rust_i128_subo;
  3440. static TEST_CASES: &[((i128, i128), (i128, bool))] = &[
  3441. "
  3442. }
  3443. fn epilogue() -> &'static str {
  3444. "
  3445. ];
  3446. #[test]
  3447. fn i128_subo() {
  3448. for &((a, b), (c, d)) in TEST_CASES {
  3449. let (c_, d_) = rust_i128_subo(a, b);
  3450. assert_eq!(((a, b), (c, d)), ((a, b), (c_, d_)));
  3451. }
  3452. }
  3453. "
  3454. }
  3455. }
  3456. #[derive(Eq, Hash, PartialEq)]
  3457. pub struct Mulsf3 {
  3458. a: u32, // f32
  3459. b: u32, // f32
  3460. c: u32, // f32
  3461. }
  3462. impl TestCase for Mulsf3 {
  3463. fn name() -> &'static str {
  3464. "mulsf3"
  3465. }
  3466. fn generate<R>(rng: &mut R) -> Option<Self>
  3467. where
  3468. R: Rng,
  3469. Self: Sized,
  3470. {
  3471. let a = gen_large_f32(rng);
  3472. let b = gen_large_f32(rng);
  3473. let c = a * b;
  3474. // TODO accept NaNs. We don't do that right now because we can't check
  3475. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3476. if a.is_nan() || b.is_nan() || c.is_nan() {
  3477. return None;
  3478. }
  3479. Some(
  3480. Mulsf3 {
  3481. a: to_u32(a),
  3482. b: to_u32(b),
  3483. c: to_u32(c),
  3484. },
  3485. )
  3486. }
  3487. fn to_string(&self, buffer: &mut String) {
  3488. writeln!(
  3489. buffer,
  3490. "(({a}, {b}), {c}),",
  3491. a = self.a,
  3492. b = self.b,
  3493. c = self.c
  3494. )
  3495. .unwrap();
  3496. }
  3497. fn prologue() -> &'static str {
  3498. r#"
  3499. #[cfg(all(target_arch = "arm",
  3500. not(any(target_env = "gnu", target_env = "musl")),
  3501. target_os = "linux",
  3502. test))]
  3503. use core::mem;
  3504. #[cfg(not(all(target_arch = "arm",
  3505. not(any(target_env = "gnu", target_env = "musl")),
  3506. target_os = "linux",
  3507. test)))]
  3508. use std::mem;
  3509. use compiler_builtins::float::mul::__mulsf3;
  3510. fn mk_f32(x: u32) -> f32 {
  3511. unsafe { mem::transmute(x) }
  3512. }
  3513. fn to_u32(x: f32) -> u32 {
  3514. unsafe { mem::transmute(x) }
  3515. }
  3516. static TEST_CASES: &[((u32, u32), u32)] = &[
  3517. "#
  3518. }
  3519. fn epilogue() -> &'static str {
  3520. "
  3521. ];
  3522. #[test]
  3523. fn mulsf3() {
  3524. for &((a, b), c) in TEST_CASES {
  3525. let c_ = __mulsf3(mk_f32(a), mk_f32(b));
  3526. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  3527. }
  3528. }
  3529. "
  3530. }
  3531. }
  3532. #[derive(Eq, Hash, PartialEq)]
  3533. pub struct Muldf3 {
  3534. a: u64, // f64
  3535. b: u64, // f64
  3536. c: u64, // f64
  3537. }
  3538. impl TestCase for Muldf3 {
  3539. fn name() -> &'static str {
  3540. "muldf3"
  3541. }
  3542. fn generate<R>(rng: &mut R) -> Option<Self>
  3543. where
  3544. R: Rng,
  3545. Self: Sized,
  3546. {
  3547. let a = gen_large_f64(rng);
  3548. let b = gen_large_f64(rng);
  3549. let c = a * b;
  3550. // TODO accept NaNs. We don't do that right now because we can't check
  3551. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3552. if a.is_nan() || b.is_nan() || c.is_nan() {
  3553. return None;
  3554. }
  3555. Some(
  3556. Muldf3 {
  3557. a: to_u64(a),
  3558. b: to_u64(b),
  3559. c: to_u64(c),
  3560. },
  3561. )
  3562. }
  3563. fn to_string(&self, buffer: &mut String) {
  3564. writeln!(
  3565. buffer,
  3566. "(({a}, {b}), {c}),",
  3567. a = self.a,
  3568. b = self.b,
  3569. c = self.c
  3570. )
  3571. .unwrap();
  3572. }
  3573. fn prologue() -> &'static str {
  3574. r#"
  3575. #[cfg(all(target_arch = "arm",
  3576. not(any(target_env = "gnu", target_env = "musl")),
  3577. target_os = "linux",
  3578. test))]
  3579. use core::mem;
  3580. #[cfg(not(all(target_arch = "arm",
  3581. not(any(target_env = "gnu", target_env = "musl")),
  3582. target_os = "linux",
  3583. test)))]
  3584. use std::mem;
  3585. use compiler_builtins::float::mul::__muldf3;
  3586. fn mk_f64(x: u64) -> f64 {
  3587. unsafe { mem::transmute(x) }
  3588. }
  3589. fn to_u64(x: f64) -> u64 {
  3590. unsafe { mem::transmute(x) }
  3591. }
  3592. static TEST_CASES: &[((u64, u64), u64)] = &[
  3593. "#
  3594. }
  3595. fn epilogue() -> &'static str {
  3596. "
  3597. ];
  3598. #[test]
  3599. fn muldf3() {
  3600. for &((a, b), c) in TEST_CASES {
  3601. let c_ = __muldf3(mk_f64(a), mk_f64(b));
  3602. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  3603. }
  3604. }
  3605. "
  3606. }
  3607. }
  3608. #[derive(Eq, Hash, PartialEq)]
  3609. pub struct Mulsf3vfp {
  3610. a: u32, // f32
  3611. b: u32, // f32
  3612. c: u32, // f32
  3613. }
  3614. impl TestCase for Mulsf3vfp {
  3615. fn name() -> &'static str {
  3616. "mulsf3vfp"
  3617. }
  3618. fn generate<R>(rng: &mut R) -> Option<Self>
  3619. where
  3620. R: Rng,
  3621. Self: Sized,
  3622. {
  3623. let a = gen_large_f32(rng);
  3624. let b = gen_large_f32(rng);
  3625. let c = a * b;
  3626. // TODO accept NaNs. We don't do that right now because we can't check
  3627. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3628. if a.is_nan() || b.is_nan() || c.is_nan() {
  3629. return None;
  3630. }
  3631. Some(
  3632. Mulsf3vfp {
  3633. a: to_u32(a),
  3634. b: to_u32(b),
  3635. c: to_u32(c),
  3636. },
  3637. )
  3638. }
  3639. fn to_string(&self, buffer: &mut String) {
  3640. writeln!(
  3641. buffer,
  3642. "(({a}, {b}), {c}),",
  3643. a = self.a,
  3644. b = self.b,
  3645. c = self.c
  3646. )
  3647. .unwrap();
  3648. }
  3649. fn prologue() -> &'static str {
  3650. r#"
  3651. #[cfg(all(target_arch = "arm",
  3652. not(any(target_env = "gnu", target_env = "musl")),
  3653. target_os = "linux",
  3654. test))]
  3655. use core::mem;
  3656. #[cfg(not(all(target_arch = "arm",
  3657. not(any(target_env = "gnu", target_env = "musl")),
  3658. target_os = "linux",
  3659. test)))]
  3660. use std::mem;
  3661. use compiler_builtins::float::mul::__mulsf3vfp;
  3662. fn mk_f32(x: u32) -> f32 {
  3663. unsafe { mem::transmute(x) }
  3664. }
  3665. fn to_u32(x: f32) -> u32 {
  3666. unsafe { mem::transmute(x) }
  3667. }
  3668. static TEST_CASES: &[((u32, u32), u32)] = &[
  3669. "#
  3670. }
  3671. fn epilogue() -> &'static str {
  3672. "
  3673. ];
  3674. #[test]
  3675. fn mulsf3vfp() {
  3676. for &((a, b), c) in TEST_CASES {
  3677. let c_ = __mulsf3vfp(mk_f32(a), mk_f32(b));
  3678. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  3679. }
  3680. }
  3681. "
  3682. }
  3683. }
  3684. #[derive(Eq, Hash, PartialEq)]
  3685. pub struct Muldf3vfp {
  3686. a: u64, // f64
  3687. b: u64, // f64
  3688. c: u64, // f64
  3689. }
  3690. impl TestCase for Muldf3vfp {
  3691. fn name() -> &'static str {
  3692. "muldf3vfp"
  3693. }
  3694. fn generate<R>(rng: &mut R) -> Option<Self>
  3695. where
  3696. R: Rng,
  3697. Self: Sized,
  3698. {
  3699. let a = gen_large_f64(rng);
  3700. let b = gen_large_f64(rng);
  3701. let c = a * b;
  3702. // TODO accept NaNs. We don't do that right now because we can't check
  3703. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3704. if a.is_nan() || b.is_nan() || c.is_nan() {
  3705. return None;
  3706. }
  3707. Some(
  3708. Muldf3vfp {
  3709. a: to_u64(a),
  3710. b: to_u64(b),
  3711. c: to_u64(c),
  3712. },
  3713. )
  3714. }
  3715. fn to_string(&self, buffer: &mut String) {
  3716. writeln!(
  3717. buffer,
  3718. "(({a}, {b}), {c}),",
  3719. a = self.a,
  3720. b = self.b,
  3721. c = self.c
  3722. )
  3723. .unwrap();
  3724. }
  3725. fn prologue() -> &'static str {
  3726. r#"
  3727. #[cfg(all(target_arch = "arm",
  3728. not(any(target_env = "gnu", target_env = "musl")),
  3729. target_os = "linux",
  3730. test))]
  3731. use core::mem;
  3732. #[cfg(not(all(target_arch = "arm",
  3733. not(any(target_env = "gnu", target_env = "musl")),
  3734. target_os = "linux",
  3735. test)))]
  3736. use std::mem;
  3737. use compiler_builtins::float::mul::__muldf3vfp;
  3738. fn mk_f64(x: u64) -> f64 {
  3739. unsafe { mem::transmute(x) }
  3740. }
  3741. fn to_u64(x: f64) -> u64 {
  3742. unsafe { mem::transmute(x) }
  3743. }
  3744. static TEST_CASES: &[((u64, u64), u64)] = &[
  3745. "#
  3746. }
  3747. fn epilogue() -> &'static str {
  3748. "
  3749. ];
  3750. #[test]
  3751. fn muldf3vfp() {
  3752. for &((a, b), c) in TEST_CASES {
  3753. let c_ = __muldf3vfp(mk_f64(a), mk_f64(b));
  3754. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  3755. }
  3756. }
  3757. "
  3758. }
  3759. }
  3760. #[derive(Eq, Hash, PartialEq)]
  3761. pub struct Divsf3 {
  3762. a: u32, // f32
  3763. b: u32, // f32
  3764. c: u32, // f32
  3765. }
  3766. impl TestCase for Divsf3 {
  3767. fn name() -> &'static str {
  3768. "divsf3"
  3769. }
  3770. fn generate<R>(rng: &mut R) -> Option<Self>
  3771. where
  3772. R: Rng,
  3773. Self: Sized,
  3774. {
  3775. let a = gen_large_f32(rng);
  3776. let b = gen_large_f32(rng);
  3777. if b == 0.0 {
  3778. return None;
  3779. }
  3780. let c = a / b;
  3781. // TODO accept NaNs. We don't do that right now because we can't check
  3782. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3783. if a.is_nan() || b.is_nan() || c.is_nan()|| c.abs() <= unsafe { mem::transmute(16777215u32) } {
  3784. return None;
  3785. }
  3786. Some(
  3787. Divsf3 {
  3788. a: to_u32(a),
  3789. b: to_u32(b),
  3790. c: to_u32(c),
  3791. },
  3792. )
  3793. }
  3794. fn to_string(&self, buffer: &mut String) {
  3795. writeln!(
  3796. buffer,
  3797. "(({a}, {b}), {c}),",
  3798. a = self.a,
  3799. b = self.b,
  3800. c = self.c
  3801. )
  3802. .unwrap();
  3803. }
  3804. fn prologue() -> &'static str {
  3805. r#"
  3806. #[cfg(all(target_arch = "arm",
  3807. not(any(target_env = "gnu", target_env = "musl")),
  3808. target_os = "linux",
  3809. test))]
  3810. use core::mem;
  3811. #[cfg(not(all(target_arch = "arm",
  3812. not(any(target_env = "gnu", target_env = "musl")),
  3813. target_os = "linux",
  3814. test)))]
  3815. use std::mem;
  3816. use compiler_builtins::float::div::__divsf3;
  3817. fn mk_f32(x: u32) -> f32 {
  3818. unsafe { mem::transmute(x) }
  3819. }
  3820. fn to_u32(x: f32) -> u32 {
  3821. unsafe { mem::transmute(x) }
  3822. }
  3823. static TEST_CASES: &[((u32, u32), u32)] = &[
  3824. "#
  3825. }
  3826. fn epilogue() -> &'static str {
  3827. "
  3828. ];
  3829. #[test]
  3830. fn divsf3() {
  3831. for &((a, b), c) in TEST_CASES {
  3832. let c_ = __divsf3(mk_f32(a), mk_f32(b));
  3833. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  3834. }
  3835. }
  3836. "
  3837. }
  3838. }
  3839. #[derive(Eq, Hash, PartialEq)]
  3840. pub struct Divdf3 {
  3841. a: u64, // f64
  3842. b: u64, // f64
  3843. c: u64, // f64
  3844. }
  3845. impl TestCase for Divdf3 {
  3846. fn name() -> &'static str {
  3847. "divdf3"
  3848. }
  3849. fn generate<R>(rng: &mut R) -> Option<Self>
  3850. where
  3851. R: Rng,
  3852. Self: Sized,
  3853. {
  3854. let a = gen_large_f64(rng);
  3855. let b = gen_large_f64(rng);
  3856. if b == 0.0 {
  3857. return None;
  3858. }
  3859. let c = a / b;
  3860. // TODO accept NaNs. We don't do that right now because we can't check
  3861. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3862. if a.is_nan() || b.is_nan() || c.is_nan()
  3863. || c.abs() <= unsafe { mem::transmute(4503599627370495u64) } {
  3864. return None;
  3865. }
  3866. Some(
  3867. Divdf3 {
  3868. a: to_u64(a),
  3869. b: to_u64(b),
  3870. c: to_u64(c),
  3871. },
  3872. )
  3873. }
  3874. fn to_string(&self, buffer: &mut String) {
  3875. writeln!(
  3876. buffer,
  3877. "(({a}, {b}), {c}),",
  3878. a = self.a,
  3879. b = self.b,
  3880. c = self.c
  3881. )
  3882. .unwrap();
  3883. }
  3884. fn prologue() -> &'static str {
  3885. r#"
  3886. #[cfg(all(target_arch = "arm",
  3887. not(any(target_env = "gnu", target_env = "musl")),
  3888. target_os = "linux",
  3889. test))]
  3890. use core::mem;
  3891. #[cfg(not(all(target_arch = "arm",
  3892. not(any(target_env = "gnu", target_env = "musl")),
  3893. target_os = "linux",
  3894. test)))]
  3895. use std::mem;
  3896. use compiler_builtins::float::div::__divdf3;
  3897. fn mk_f64(x: u64) -> f64 {
  3898. unsafe { mem::transmute(x) }
  3899. }
  3900. fn to_u64(x: f64) -> u64 {
  3901. unsafe { mem::transmute(x) }
  3902. }
  3903. static TEST_CASES: &[((u64, u64), u64)] = &[
  3904. "#
  3905. }
  3906. fn epilogue() -> &'static str {
  3907. "
  3908. ];
  3909. #[test]
  3910. fn divdf3() {
  3911. for &((a, b), c) in TEST_CASES {
  3912. let c_ = __divdf3(mk_f64(a), mk_f64(b));
  3913. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  3914. }
  3915. }
  3916. "
  3917. }
  3918. }
  3919. #[derive(Eq, Hash, PartialEq)]
  3920. pub struct Divsf3vfp {
  3921. a: u32, // f32
  3922. b: u32, // f32
  3923. c: u32, // f32
  3924. }
  3925. impl TestCase for Divsf3vfp {
  3926. fn name() -> &'static str {
  3927. "divsf3vfp"
  3928. }
  3929. fn generate<R>(rng: &mut R) -> Option<Self>
  3930. where
  3931. R: Rng,
  3932. Self: Sized,
  3933. {
  3934. let a = gen_large_f32(rng);
  3935. let b = gen_large_f32(rng);
  3936. if b == 0.0 {
  3937. return None;
  3938. }
  3939. let c = a / b;
  3940. // TODO accept NaNs. We don't do that right now because we can't check
  3941. // for NaN-ness on the thumb targets (due to missing intrinsics)
  3942. if a.is_nan() || b.is_nan() || c.is_nan()|| c.abs() <= unsafe { mem::transmute(16777215u32) } {
  3943. return None;
  3944. }
  3945. Some(
  3946. Divsf3vfp {
  3947. a: to_u32(a),
  3948. b: to_u32(b),
  3949. c: to_u32(c),
  3950. },
  3951. )
  3952. }
  3953. fn to_string(&self, buffer: &mut String) {
  3954. writeln!(
  3955. buffer,
  3956. "(({a}, {b}), {c}),",
  3957. a = self.a,
  3958. b = self.b,
  3959. c = self.c
  3960. )
  3961. .unwrap();
  3962. }
  3963. fn prologue() -> &'static str {
  3964. r#"
  3965. #[cfg(all(target_arch = "arm",
  3966. not(any(target_env = "gnu", target_env = "musl")),
  3967. target_os = "linux",
  3968. test))]
  3969. use core::mem;
  3970. #[cfg(not(all(target_arch = "arm",
  3971. not(any(target_env = "gnu", target_env = "musl")),
  3972. target_os = "linux",
  3973. test)))]
  3974. use std::mem;
  3975. use compiler_builtins::float::div::__divsf3vfp;
  3976. fn mk_f32(x: u32) -> f32 {
  3977. unsafe { mem::transmute(x) }
  3978. }
  3979. fn to_u32(x: f32) -> u32 {
  3980. unsafe { mem::transmute(x) }
  3981. }
  3982. static TEST_CASES: &[((u32, u32), u32)] = &[
  3983. "#
  3984. }
  3985. fn epilogue() -> &'static str {
  3986. "
  3987. ];
  3988. #[test]
  3989. fn divsf3vfp() {
  3990. for &((a, b), c) in TEST_CASES {
  3991. let c_ = __divsf3vfp(mk_f32(a), mk_f32(b));
  3992. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  3993. }
  3994. }
  3995. "
  3996. }
  3997. }
  3998. #[derive(Eq, Hash, PartialEq)]
  3999. pub struct Divdf3vfp {
  4000. a: u64, // f64
  4001. b: u64, // f64
  4002. c: u64, // f64
  4003. }
  4004. impl TestCase for Divdf3vfp {
  4005. fn name() -> &'static str {
  4006. "divdf3vfp"
  4007. }
  4008. fn generate<R>(rng: &mut R) -> Option<Self>
  4009. where
  4010. R: Rng,
  4011. Self: Sized,
  4012. {
  4013. let a = gen_large_f64(rng);
  4014. let b = gen_large_f64(rng);
  4015. if b == 0.0 {
  4016. return None;
  4017. }
  4018. let c = a / b;
  4019. // TODO accept NaNs. We don't do that right now because we can't check
  4020. // for NaN-ness on the thumb targets (due to missing intrinsics)
  4021. if a.is_nan() || b.is_nan() || c.is_nan()
  4022. || c.abs() <= unsafe { mem::transmute(4503599627370495u64) } {
  4023. return None;
  4024. }
  4025. Some(
  4026. Divdf3vfp {
  4027. a: to_u64(a),
  4028. b: to_u64(b),
  4029. c: to_u64(c),
  4030. },
  4031. )
  4032. }
  4033. fn to_string(&self, buffer: &mut String) {
  4034. writeln!(
  4035. buffer,
  4036. "(({a}, {b}), {c}),",
  4037. a = self.a,
  4038. b = self.b,
  4039. c = self.c
  4040. )
  4041. .unwrap();
  4042. }
  4043. fn prologue() -> &'static str {
  4044. r#"
  4045. #[cfg(all(target_arch = "arm",
  4046. not(any(target_env = "gnu", target_env = "musl")),
  4047. target_os = "linux",
  4048. test))]
  4049. use core::mem;
  4050. #[cfg(not(all(target_arch = "arm",
  4051. not(any(target_env = "gnu", target_env = "musl")),
  4052. target_os = "linux",
  4053. test)))]
  4054. use std::mem;
  4055. use compiler_builtins::float::div::__divdf3vfp;
  4056. fn mk_f64(x: u64) -> f64 {
  4057. unsafe { mem::transmute(x) }
  4058. }
  4059. fn to_u64(x: f64) -> u64 {
  4060. unsafe { mem::transmute(x) }
  4061. }
  4062. static TEST_CASES: &[((u64, u64), u64)] = &[
  4063. "#
  4064. }
  4065. fn epilogue() -> &'static str {
  4066. "
  4067. ];
  4068. #[test]
  4069. fn divdf3vfp() {
  4070. for &((a, b), c) in TEST_CASES {
  4071. let c_ = __divdf3vfp(mk_f64(a), mk_f64(b));
  4072. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  4073. }
  4074. }
  4075. "
  4076. }
  4077. }
  4078. #[derive(Eq, Hash, PartialEq)]
  4079. pub struct Udivdi3 {
  4080. a: u64,
  4081. b: u64,
  4082. c: u64,
  4083. }
  4084. impl TestCase for Udivdi3 {
  4085. fn name() -> &'static str {
  4086. "udivdi3"
  4087. }
  4088. fn generate<R>(rng: &mut R) -> Option<Self>
  4089. where
  4090. R: Rng,
  4091. Self: Sized,
  4092. {
  4093. let a = gen_u64(rng);
  4094. let b = gen_u64(rng);
  4095. if b == 0 {
  4096. return None;
  4097. }
  4098. let c = a / b;
  4099. Some(Udivdi3 { a, b, c })
  4100. }
  4101. fn to_string(&self, buffer: &mut String) {
  4102. writeln!(
  4103. buffer,
  4104. "(({a}, {b}), {c}),",
  4105. a = self.a,
  4106. b = self.b,
  4107. c = self.c
  4108. )
  4109. .unwrap();
  4110. }
  4111. fn prologue() -> &'static str {
  4112. "
  4113. use compiler_builtins::int::udiv::__udivdi3;
  4114. static TEST_CASES: &[((u64, u64), u64)] = &[
  4115. "
  4116. }
  4117. fn epilogue() -> &'static str {
  4118. "
  4119. ];
  4120. #[test]
  4121. fn udivdi3() {
  4122. for &((a, b), c) in TEST_CASES {
  4123. let c_ = __udivdi3(a, b);
  4124. assert_eq!(((a, b), c), ((a, b), c_));
  4125. }
  4126. }
  4127. "
  4128. }
  4129. }
  4130. #[derive(Eq, Hash, PartialEq)]
  4131. pub struct Udivmoddi4 {
  4132. a: u64,
  4133. b: u64,
  4134. c: u64,
  4135. rem: u64,
  4136. }
  4137. impl TestCase for Udivmoddi4 {
  4138. fn name() -> &'static str {
  4139. "udivmoddi4"
  4140. }
  4141. fn generate<R>(rng: &mut R) -> Option<Self>
  4142. where
  4143. R: Rng,
  4144. Self: Sized,
  4145. {
  4146. let a = gen_u64(rng);
  4147. let b = gen_u64(rng);
  4148. if b == 0 {
  4149. return None;
  4150. }
  4151. let c = a / b;
  4152. let rem = a % b;
  4153. Some(Udivmoddi4 { a, b, c, rem })
  4154. }
  4155. fn to_string(&self, buffer: &mut String) {
  4156. writeln!(
  4157. buffer,
  4158. "(({a}, {b}), ({c}, {rem})),",
  4159. a = self.a,
  4160. b = self.b,
  4161. c = self.c,
  4162. rem = self.rem
  4163. )
  4164. .unwrap();
  4165. }
  4166. fn prologue() -> &'static str {
  4167. "
  4168. use compiler_builtins::int::udiv::__udivmoddi4;
  4169. static TEST_CASES: &[((u64, u64), (u64, u64))] = &[
  4170. "
  4171. }
  4172. fn epilogue() -> &'static str {
  4173. "
  4174. ];
  4175. #[test]
  4176. fn udivmoddi4() {
  4177. for &((a, b), (c, rem)) in TEST_CASES {
  4178. let mut rem_ = 0;
  4179. let c_ = __udivmoddi4(a, b, Some(&mut rem_));
  4180. assert_eq!(((a, b), (c, rem)), ((a, b), (c_, rem_)));
  4181. }
  4182. }
  4183. "
  4184. }
  4185. }
  4186. #[derive(Eq, Hash, PartialEq)]
  4187. pub struct Udivmodsi4 {
  4188. a: u32,
  4189. b: u32,
  4190. c: u32,
  4191. rem: u32,
  4192. }
  4193. impl TestCase for Udivmodsi4 {
  4194. fn name() -> &'static str {
  4195. "udivmodsi4"
  4196. }
  4197. fn generate<R>(rng: &mut R) -> Option<Self>
  4198. where
  4199. R: Rng,
  4200. Self: Sized,
  4201. {
  4202. let a = gen_u32(rng);
  4203. let b = gen_u32(rng);
  4204. if b == 0 {
  4205. return None;
  4206. }
  4207. let c = a / b;
  4208. let rem = a % b;
  4209. Some(Udivmodsi4 { a, b, c, rem })
  4210. }
  4211. fn to_string(&self, buffer: &mut String) {
  4212. writeln!(
  4213. buffer,
  4214. "(({a}, {b}), ({c}, {rem})),",
  4215. a = self.a,
  4216. b = self.b,
  4217. c = self.c,
  4218. rem = self.rem
  4219. )
  4220. .unwrap();
  4221. }
  4222. fn prologue() -> &'static str {
  4223. "
  4224. use compiler_builtins::int::udiv::__udivmodsi4;
  4225. static TEST_CASES: &[((u32, u32), (u32, u32))] = &[
  4226. "
  4227. }
  4228. fn epilogue() -> &'static str {
  4229. "
  4230. ];
  4231. #[test]
  4232. fn udivmodsi4() {
  4233. for &((a, b), (c, rem)) in TEST_CASES {
  4234. let mut rem_ = 0;
  4235. let c_ = __udivmodsi4(a, b, Some(&mut rem_));
  4236. assert_eq!(((a, b), (c, rem)), ((a, b), (c_, rem_)));
  4237. }
  4238. }
  4239. "
  4240. }
  4241. }
  4242. #[derive(Eq, Hash, PartialEq)]
  4243. pub struct Udivmodti4 {
  4244. a: u128,
  4245. b: u128,
  4246. c: u128,
  4247. rem: u128,
  4248. }
  4249. impl TestCase for Udivmodti4 {
  4250. fn name() -> &'static str {
  4251. "udivmodti4"
  4252. }
  4253. fn generate<R>(rng: &mut R) -> Option<Self>
  4254. where
  4255. R: Rng,
  4256. Self: Sized,
  4257. {
  4258. let a = gen_u128(rng);
  4259. let b = gen_u128(rng);
  4260. if b == 0 {
  4261. return None;
  4262. }
  4263. let c = a / b;
  4264. let rem = a % b;
  4265. Some(Udivmodti4 { a, b, c, rem })
  4266. }
  4267. fn to_string(&self, buffer: &mut String) {
  4268. writeln!(
  4269. buffer,
  4270. "(({a}, {b}), ({c}, {rem})),",
  4271. a = self.a,
  4272. b = self.b,
  4273. c = self.c,
  4274. rem = self.rem
  4275. )
  4276. .unwrap();
  4277. }
  4278. fn prologue() -> &'static str {
  4279. "
  4280. use compiler_builtins::int::udiv::__udivmodti4;
  4281. static TEST_CASES: &[((u128, u128), (u128, u128))] = &[
  4282. "
  4283. }
  4284. fn epilogue() -> &'static str {
  4285. "
  4286. ];
  4287. #[test]
  4288. fn udivmodti4() {
  4289. for &((a, b), (c, rem)) in TEST_CASES {
  4290. let mut rem_ = 0;
  4291. let c_ = __udivmodti4(a, b, Some(&mut rem_));
  4292. assert_eq!(((a, b), (c, rem)), ((a, b), (c_, rem_)));
  4293. }
  4294. }
  4295. "
  4296. }
  4297. }
  4298. #[derive(Eq, Hash, PartialEq)]
  4299. pub struct Udivsi3 {
  4300. a: u32,
  4301. b: u32,
  4302. c: u32,
  4303. }
  4304. impl TestCase for Udivsi3 {
  4305. fn name() -> &'static str {
  4306. "udivsi3"
  4307. }
  4308. fn generate<R>(rng: &mut R) -> Option<Self>
  4309. where
  4310. R: Rng,
  4311. Self: Sized,
  4312. {
  4313. let a = gen_u32(rng);
  4314. let b = gen_u32(rng);
  4315. if b == 0 {
  4316. return None;
  4317. }
  4318. let c = a / b;
  4319. Some(Udivsi3 { a, b, c })
  4320. }
  4321. fn to_string(&self, buffer: &mut String) {
  4322. writeln!(
  4323. buffer,
  4324. "(({a}, {b}), {c}),",
  4325. a = self.a,
  4326. b = self.b,
  4327. c = self.c
  4328. )
  4329. .unwrap();
  4330. }
  4331. fn prologue() -> &'static str {
  4332. "
  4333. use compiler_builtins::int::udiv::__udivsi3;
  4334. static TEST_CASES: &[((u32, u32), u32)] = &[
  4335. "
  4336. }
  4337. fn epilogue() -> &'static str {
  4338. "
  4339. ];
  4340. #[test]
  4341. fn udivsi3() {
  4342. for &((a, b), c) in TEST_CASES {
  4343. let c_ = __udivsi3(a, b);
  4344. assert_eq!(((a, b), c), ((a, b), c_));
  4345. }
  4346. }
  4347. "
  4348. }
  4349. }
  4350. #[derive(Eq, Hash, PartialEq)]
  4351. pub struct Udivti3 {
  4352. a: u128,
  4353. b: u128,
  4354. c: u128,
  4355. }
  4356. impl TestCase for Udivti3 {
  4357. fn name() -> &'static str {
  4358. "udivti3"
  4359. }
  4360. fn generate<R>(rng: &mut R) -> Option<Self>
  4361. where
  4362. R: Rng,
  4363. Self: Sized,
  4364. {
  4365. let a = gen_u128(rng);
  4366. let b = gen_u128(rng);
  4367. if b == 0 {
  4368. return None;
  4369. }
  4370. let c = a / b;
  4371. Some(Udivti3 { a, b, c })
  4372. }
  4373. fn to_string(&self, buffer: &mut String) {
  4374. writeln!(
  4375. buffer,
  4376. "(({a}, {b}), {c}),",
  4377. a = self.a,
  4378. b = self.b,
  4379. c = self.c
  4380. )
  4381. .unwrap();
  4382. }
  4383. fn prologue() -> &'static str {
  4384. "
  4385. use compiler_builtins::int::udiv::__udivti3;
  4386. static TEST_CASES: &[((u128, u128), u128)] = &[
  4387. "
  4388. }
  4389. fn epilogue() -> &'static str {
  4390. "
  4391. ];
  4392. #[test]
  4393. fn udivti3() {
  4394. for &((a, b), c) in TEST_CASES {
  4395. let c_ = __udivti3(a, b);
  4396. assert_eq!(((a, b), c), ((a, b), c_));
  4397. }
  4398. }
  4399. "
  4400. }
  4401. }
  4402. #[derive(Eq, Hash, PartialEq)]
  4403. pub struct Umoddi3 {
  4404. a: u64,
  4405. b: u64,
  4406. c: u64,
  4407. }
  4408. impl TestCase for Umoddi3 {
  4409. fn name() -> &'static str {
  4410. "umoddi3"
  4411. }
  4412. fn generate<R>(rng: &mut R) -> Option<Self>
  4413. where
  4414. R: Rng,
  4415. Self: Sized,
  4416. {
  4417. let a = gen_u64(rng);
  4418. let b = gen_u64(rng);
  4419. if b == 0 {
  4420. return None;
  4421. }
  4422. let c = a % b;
  4423. Some(Umoddi3 { a, b, c })
  4424. }
  4425. fn to_string(&self, buffer: &mut String) {
  4426. writeln!(
  4427. buffer,
  4428. "(({a}, {b}), {c}),",
  4429. a = self.a,
  4430. b = self.b,
  4431. c = self.c
  4432. )
  4433. .unwrap();
  4434. }
  4435. fn prologue() -> &'static str {
  4436. "
  4437. use compiler_builtins::int::udiv::__umoddi3;
  4438. static TEST_CASES: &[((u64, u64), u64)] = &[
  4439. "
  4440. }
  4441. fn epilogue() -> &'static str {
  4442. "
  4443. ];
  4444. #[test]
  4445. fn umoddi3() {
  4446. for &((a, b), c) in TEST_CASES {
  4447. let c_ = __umoddi3(a, b);
  4448. assert_eq!(((a, b), c), ((a, b), c_));
  4449. }
  4450. }
  4451. "
  4452. }
  4453. }
  4454. #[derive(Eq, Hash, PartialEq)]
  4455. pub struct Umodsi3 {
  4456. a: u32,
  4457. b: u32,
  4458. c: u32,
  4459. }
  4460. impl TestCase for Umodsi3 {
  4461. fn name() -> &'static str {
  4462. "umodsi3"
  4463. }
  4464. fn generate<R>(rng: &mut R) -> Option<Self>
  4465. where
  4466. R: Rng,
  4467. Self: Sized,
  4468. {
  4469. let a = gen_u32(rng);
  4470. let b = gen_u32(rng);
  4471. if b == 0 {
  4472. return None;
  4473. }
  4474. let c = a % b;
  4475. Some(Umodsi3 { a, b, c })
  4476. }
  4477. fn to_string(&self, buffer: &mut String) {
  4478. writeln!(
  4479. buffer,
  4480. "(({a}, {b}), {c}),",
  4481. a = self.a,
  4482. b = self.b,
  4483. c = self.c
  4484. )
  4485. .unwrap();
  4486. }
  4487. fn prologue() -> &'static str {
  4488. "
  4489. use compiler_builtins::int::udiv::__umodsi3;
  4490. static TEST_CASES: &[((u32, u32), u32)] = &[
  4491. "
  4492. }
  4493. fn epilogue() -> &'static str {
  4494. "
  4495. ];
  4496. #[test]
  4497. fn umodsi3() {
  4498. for &((a, b), c) in TEST_CASES {
  4499. let c_ = __umodsi3(a, b);
  4500. assert_eq!(((a, b), c), ((a, b), c_));
  4501. }
  4502. }
  4503. "
  4504. }
  4505. }
  4506. #[derive(Eq, Hash, PartialEq)]
  4507. pub struct Umodti3 {
  4508. a: u128,
  4509. b: u128,
  4510. c: u128,
  4511. }
  4512. impl TestCase for Umodti3 {
  4513. fn name() -> &'static str {
  4514. "umodti3"
  4515. }
  4516. fn generate<R>(rng: &mut R) -> Option<Self>
  4517. where
  4518. R: Rng,
  4519. Self: Sized,
  4520. {
  4521. let a = gen_u128(rng);
  4522. let b = gen_u128(rng);
  4523. if b == 0 {
  4524. return None;
  4525. }
  4526. let c = a % b;
  4527. Some(Umodti3 { a, b, c })
  4528. }
  4529. fn to_string(&self, buffer: &mut String) {
  4530. writeln!(
  4531. buffer,
  4532. "(({a}, {b}), {c}),",
  4533. a = self.a,
  4534. b = self.b,
  4535. c = self.c
  4536. )
  4537. .unwrap();
  4538. }
  4539. fn prologue() -> &'static str {
  4540. "
  4541. use compiler_builtins::int::udiv::__umodti3;
  4542. static TEST_CASES: &[((u128, u128), u128)] = &[
  4543. "
  4544. }
  4545. fn epilogue() -> &'static str {
  4546. "
  4547. ];
  4548. #[test]
  4549. fn umodti3() {
  4550. for &((a, b), c) in TEST_CASES {
  4551. let c_ = __umodti3(a, b);
  4552. assert_eq!(((a, b), c), ((a, b), c_));
  4553. }
  4554. }
  4555. "
  4556. }
  4557. }
  4558. trait TestCase {
  4559. /// Name of the intrinsic to test
  4560. fn name() -> &'static str;
  4561. /// Generates a valid test case
  4562. fn generate<R>(rng: &mut R) -> Option<Self>
  4563. where
  4564. R: Rng,
  4565. Self: Sized;
  4566. /// Stringifies a test case
  4567. fn to_string(&self, buffer: &mut String);
  4568. /// Prologue of the test file
  4569. fn prologue() -> &'static str;
  4570. /// Epilogue of the test file
  4571. fn epilogue() -> &'static str;
  4572. }
  4573. const PROLOGUE: &'static str = r#"
  4574. extern crate compiler_builtins;
  4575. // test runner
  4576. #[cfg(all(target_arch = "arm",
  4577. not(any(target_env = "gnu", target_env = "musl")),
  4578. target_os = "linux",
  4579. test))]
  4580. extern crate utest_cortex_m_qemu;
  4581. // overrides `panic!`
  4582. #[cfg(all(target_arch = "arm",
  4583. not(any(target_env = "gnu", target_env = "musl")),
  4584. target_os = "linux",
  4585. test))]
  4586. #[macro_use]
  4587. extern crate utest_macros;
  4588. #[cfg(all(target_arch = "arm",
  4589. not(any(target_env = "gnu", target_env = "musl")),
  4590. target_os = "linux",
  4591. test))]
  4592. macro_rules! panic {
  4593. ($($tt:tt)*) => {
  4594. upanic!($($tt)*);
  4595. };
  4596. }
  4597. "#;
  4598. macro_rules! gen_int {
  4599. ($name:ident, $ity:ident, $hty:ident) => {
  4600. fn $name<R>(rng: &mut R) -> $ity
  4601. where
  4602. R: Rng,
  4603. {
  4604. let mut mk = || if rng.gen_weighted_bool(10) {
  4605. *rng.choose(&[::std::$hty::MAX, 0, ::std::$hty::MIN]).unwrap()
  4606. } else {
  4607. rng.gen::<$hty>()
  4608. };
  4609. unsafe { mem::transmute([mk(), mk()]) }
  4610. }
  4611. }
  4612. }
  4613. gen_int!(gen_i32, i32, i16);
  4614. gen_int!(gen_i64, i64, i32);
  4615. gen_int!(gen_i128, i128, i64);
  4616. macro_rules! gen_float {
  4617. ($name:ident,
  4618. $fty:ident,
  4619. $uty:ident,
  4620. $bits:expr,
  4621. $significand_bits:expr) => {
  4622. pub fn $name<R>(rng: &mut R) -> $fty
  4623. where
  4624. R: Rng,
  4625. {
  4626. const BITS: u8 = $bits;
  4627. const SIGNIFICAND_BITS: u8 = $significand_bits;
  4628. const SIGNIFICAND_MASK: $uty = (1 << SIGNIFICAND_BITS) - 1;
  4629. const SIGN_MASK: $uty = (1 << (BITS - 1));
  4630. const EXPONENT_MASK: $uty = !(SIGN_MASK | SIGNIFICAND_MASK);
  4631. fn mk_f32(sign: bool, exponent: $uty, significand: $uty) -> $fty {
  4632. unsafe {
  4633. mem::transmute(((sign as $uty) << (BITS - 1)) |
  4634. ((exponent & EXPONENT_MASK) <<
  4635. SIGNIFICAND_BITS) |
  4636. (significand & SIGNIFICAND_MASK))
  4637. }
  4638. }
  4639. if rng.gen_weighted_bool(10) {
  4640. // Special values
  4641. *rng.choose(&[-0.0,
  4642. 0.0,
  4643. ::std::$fty::NAN,
  4644. ::std::$fty::INFINITY,
  4645. -::std::$fty::INFINITY])
  4646. .unwrap()
  4647. } else if rng.gen_weighted_bool(10) {
  4648. // NaN patterns
  4649. mk_f32(rng.gen(), rng.gen(), 0)
  4650. } else if rng.gen() {
  4651. // Denormalized
  4652. mk_f32(rng.gen(), 0, rng.gen())
  4653. } else {
  4654. // Random anything
  4655. mk_f32(rng.gen(), rng.gen(), rng.gen())
  4656. }
  4657. }
  4658. }
  4659. }
  4660. gen_float!(gen_f32, f32, u32, 32, 23);
  4661. gen_float!(gen_f64, f64, u64, 64, 52);
  4662. macro_rules! gen_large_float {
  4663. ($name:ident,
  4664. $fty:ident,
  4665. $uty:ident,
  4666. $bits:expr,
  4667. $significand_bits:expr) => {
  4668. pub fn $name<R>(rng: &mut R) -> $fty
  4669. where
  4670. R: Rng,
  4671. {
  4672. const BITS: u8 = $bits;
  4673. const SIGNIFICAND_BITS: u8 = $significand_bits;
  4674. const SIGNIFICAND_MASK: $uty = (1 << SIGNIFICAND_BITS) - 1;
  4675. const SIGN_MASK: $uty = (1 << (BITS - 1));
  4676. const EXPONENT_MASK: $uty = !(SIGN_MASK | SIGNIFICAND_MASK);
  4677. fn mk_f32(sign: bool, exponent: $uty, significand: $uty) -> $fty {
  4678. unsafe {
  4679. mem::transmute(((sign as $uty) << (BITS - 1)) |
  4680. ((exponent & EXPONENT_MASK) <<
  4681. SIGNIFICAND_BITS) |
  4682. (significand & SIGNIFICAND_MASK))
  4683. }
  4684. }
  4685. if rng.gen_weighted_bool(10) {
  4686. // Special values
  4687. *rng.choose(&[-0.0,
  4688. 0.0,
  4689. ::std::$fty::NAN,
  4690. ::std::$fty::INFINITY,
  4691. -::std::$fty::INFINITY])
  4692. .unwrap()
  4693. } else if rng.gen_weighted_bool(10) {
  4694. // NaN patterns
  4695. mk_f32(rng.gen(), rng.gen(), 0)
  4696. } else if rng.gen() {
  4697. // Denormalized
  4698. mk_f32(rng.gen(), 0, rng.gen())
  4699. } else {
  4700. // Random anything
  4701. rng.gen::<$fty>()
  4702. }
  4703. }
  4704. }
  4705. }
  4706. gen_large_float!(gen_large_f32, f32, u32, 32, 23);
  4707. gen_large_float!(gen_large_f64, f64, u64, 64, 52);
  4708. pub fn gen_u128<R>(rng: &mut R) -> u128
  4709. where
  4710. R: Rng,
  4711. {
  4712. gen_i128(rng) as u128
  4713. }
  4714. pub fn gen_u32<R>(rng: &mut R) -> u32
  4715. where
  4716. R: Rng,
  4717. {
  4718. gen_i32(rng) as u32
  4719. }
  4720. fn gen_u64<R>(rng: &mut R) -> u64
  4721. where
  4722. R: Rng,
  4723. {
  4724. gen_i64(rng) as u64
  4725. }
  4726. pub fn to_u32(x: f32) -> u32 {
  4727. unsafe { mem::transmute(x) }
  4728. }
  4729. pub fn to_u64(x: f64) -> u64 {
  4730. unsafe { mem::transmute(x) }
  4731. }
  4732. fn mk_tests<T, R>(mut n: usize, rng: &mut R) -> String
  4733. where
  4734. T: Eq + Hash + TestCase,
  4735. R: Rng,
  4736. {
  4737. let mut buffer = PROLOGUE.to_owned();
  4738. buffer.push_str(T::prologue());
  4739. let mut cases = HashSet::new();
  4740. while n != 0 {
  4741. if let Some(case) = T::generate(rng) {
  4742. if cases.contains(&case) {
  4743. continue;
  4744. }
  4745. case.to_string(&mut buffer);
  4746. n -= 1;
  4747. cases.insert(case);
  4748. }
  4749. }
  4750. buffer.push_str(T::epilogue());
  4751. buffer
  4752. }
  4753. fn mk_file<T>()
  4754. where
  4755. T: Eq + Hash + TestCase,
  4756. {
  4757. use std::io::Write;
  4758. let rng = &mut rand::thread_rng();
  4759. let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
  4760. let out_file_name = format!("{}.rs", T::name());
  4761. let out_file = out_dir.join(&out_file_name);
  4762. println!("Generating {}", out_file_name);
  4763. let contents = mk_tests::<T, _>(NTESTS, rng);
  4764. File::create(out_file)
  4765. .unwrap()
  4766. .write_all(contents.as_bytes())
  4767. .unwrap();
  4768. }
  4769. }
  4770. #[cfg(feature = "c")]
  4771. mod c {
  4772. extern crate cc;
  4773. use std::collections::BTreeMap;
  4774. use std::env;
  4775. use std::path::Path;
  4776. struct Sources {
  4777. // SYMBOL -> PATH TO SOURCE
  4778. map: BTreeMap<&'static str, &'static str>,
  4779. }
  4780. impl Sources {
  4781. fn new() -> Sources {
  4782. Sources { map: BTreeMap::new() }
  4783. }
  4784. fn extend(&mut self, sources: &[&'static str]) {
  4785. // NOTE Some intrinsics have both a generic implementation (e.g.
  4786. // `floatdidf.c`) and an arch optimized implementation
  4787. // (`x86_64/floatdidf.c`). In those cases, we keep the arch optimized
  4788. // implementation and discard the generic implementation. If we don't
  4789. // and keep both implementations, the linker will yell at us about
  4790. // duplicate symbols!
  4791. for &src in sources {
  4792. let symbol = Path::new(src).file_stem().unwrap().to_str().unwrap();
  4793. if src.contains("/") {
  4794. // Arch-optimized implementation (preferred)
  4795. self.map.insert(symbol, src);
  4796. } else {
  4797. // Generic implementation
  4798. if !self.map.contains_key(symbol) {
  4799. self.map.insert(symbol, src);
  4800. }
  4801. }
  4802. }
  4803. }
  4804. fn remove(&mut self, symbols: &[&str]) {
  4805. for symbol in symbols {
  4806. self.map.remove(*symbol).unwrap();
  4807. }
  4808. }
  4809. }
  4810. /// Compile intrinsics from the compiler-rt C source code
  4811. pub fn compile(llvm_target: &[&str]) {
  4812. let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
  4813. let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
  4814. let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
  4815. let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
  4816. let cfg = &mut cc::Build::new();
  4817. cfg.warnings(false);
  4818. if target_env == "msvc" {
  4819. // Don't pull in extra libraries on MSVC
  4820. cfg.flag("/Zl");
  4821. // Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP
  4822. cfg.define("__func__", Some("__FUNCTION__"));
  4823. } else {
  4824. // Turn off various features of gcc and such, mostly copying
  4825. // compiler-rt's build system already
  4826. cfg.flag("-fno-builtin");
  4827. cfg.flag("-fvisibility=hidden");
  4828. cfg.flag("-ffreestanding");
  4829. // Avoid the following warning appearing once **per file**:
  4830. // clang: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7' [-Wignored-optimization-argument]
  4831. //
  4832. // Note that compiler-rt's build system also checks
  4833. //
  4834. // `check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG)`
  4835. //
  4836. // in https://github.com/rust-lang/compiler-rt/blob/c8fbcb3/cmake/config-ix.cmake#L19.
  4837. cfg.flag_if_supported("-fomit-frame-pointer");
  4838. cfg.define("VISIBILITY_HIDDEN", None);
  4839. }
  4840. // NOTE Most of the ARM intrinsics are written in assembly. Tell gcc which arch we are going
  4841. // to target to make sure that the assembly implementations really work for the target. If
  4842. // the implementation is not valid for the arch, then gcc will error when compiling it.
  4843. if llvm_target[0].starts_with("thumb") {
  4844. cfg.flag("-mthumb");
  4845. if llvm_target.last() == Some(&"eabihf") {
  4846. cfg.flag("-mfloat-abi=hard");
  4847. }
  4848. }
  4849. if llvm_target[0] == "thumbv6m" {
  4850. cfg.flag("-march=armv6-m");
  4851. }
  4852. if llvm_target[0] == "thumbv7m" {
  4853. cfg.flag("-march=armv7-m");
  4854. }
  4855. if llvm_target[0] == "thumbv7em" {
  4856. cfg.flag("-march=armv7e-m");
  4857. }
  4858. let mut sources = Sources::new();
  4859. sources.extend(
  4860. &[
  4861. "absvdi2.c",
  4862. "absvsi2.c",
  4863. "addvdi3.c",
  4864. "addvsi3.c",
  4865. "apple_versioning.c",
  4866. "clzdi2.c",
  4867. "clzsi2.c",
  4868. "cmpdi2.c",
  4869. "ctzdi2.c",
  4870. "ctzsi2.c",
  4871. "divdc3.c",
  4872. "divsc3.c",
  4873. "divxc3.c",
  4874. "extendsfdf2.c",
  4875. "extendhfsf2.c",
  4876. "floatdisf.c",
  4877. "floatundisf.c",
  4878. "int_util.c",
  4879. "muldc3.c",
  4880. "mulsc3.c",
  4881. "mulvdi3.c",
  4882. "mulvsi3.c",
  4883. "mulxc3.c",
  4884. "negdf2.c",
  4885. "negdi2.c",
  4886. "negsf2.c",
  4887. "negvdi2.c",
  4888. "negvsi2.c",
  4889. "paritydi2.c",
  4890. "paritysi2.c",
  4891. "popcountdi2.c",
  4892. "popcountsi2.c",
  4893. "powixf2.c",
  4894. "subvdi3.c",
  4895. "subvsi3.c",
  4896. "truncdfhf2.c",
  4897. "truncdfsf2.c",
  4898. "truncsfhf2.c",
  4899. "ucmpdi2.c",
  4900. ],
  4901. );
  4902. // When compiling in rustbuild (the rust-lang/rust repo) this library
  4903. // also needs to satisfy intrinsics that jemalloc or C in general may
  4904. // need, so include a few more that aren't typically needed by
  4905. // LLVM/Rust.
  4906. if cfg!(feature = "rustbuild") {
  4907. sources.extend(&[
  4908. "ffsdi2.c",
  4909. ]);
  4910. }
  4911. // On iOS and 32-bit OSX these are all just empty intrinsics, no need to
  4912. // include them.
  4913. if target_os != "ios" && (target_vendor != "apple" || target_arch != "x86") {
  4914. sources.extend(
  4915. &[
  4916. "absvti2.c",
  4917. "addvti3.c",
  4918. "clzti2.c",
  4919. "cmpti2.c",
  4920. "ctzti2.c",
  4921. "ffsti2.c",
  4922. "mulvti3.c",
  4923. "negti2.c",
  4924. "negvti2.c",
  4925. "parityti2.c",
  4926. "popcountti2.c",
  4927. "subvti3.c",
  4928. "ucmpti2.c",
  4929. ],
  4930. );
  4931. }
  4932. if target_vendor == "apple" {
  4933. sources.extend(
  4934. &[
  4935. "atomic_flag_clear.c",
  4936. "atomic_flag_clear_explicit.c",
  4937. "atomic_flag_test_and_set.c",
  4938. "atomic_flag_test_and_set_explicit.c",
  4939. "atomic_signal_fence.c",
  4940. "atomic_thread_fence.c",
  4941. ],
  4942. );
  4943. }
  4944. if target_env == "msvc" {
  4945. if target_arch == "x86_64" {
  4946. sources.extend(
  4947. &[
  4948. "x86_64/floatdisf.c",
  4949. "x86_64/floatdixf.c",
  4950. ],
  4951. );
  4952. }
  4953. } else {
  4954. // None of these seem to be used on x86_64 windows, and they've all
  4955. // got the wrong ABI anyway, so we want to avoid them.
  4956. if target_os != "windows" {
  4957. if target_arch == "x86_64" {
  4958. sources.extend(
  4959. &[
  4960. "x86_64/floatdisf.c",
  4961. "x86_64/floatdixf.c",
  4962. "x86_64/floatundidf.S",
  4963. "x86_64/floatundisf.S",
  4964. "x86_64/floatundixf.S",
  4965. ],
  4966. );
  4967. }
  4968. }
  4969. if target_arch == "x86" {
  4970. sources.extend(
  4971. &[
  4972. "i386/ashldi3.S",
  4973. "i386/ashrdi3.S",
  4974. "i386/divdi3.S",
  4975. "i386/floatdidf.S",
  4976. "i386/floatdisf.S",
  4977. "i386/floatdixf.S",
  4978. "i386/floatundidf.S",
  4979. "i386/floatundisf.S",
  4980. "i386/floatundixf.S",
  4981. "i386/lshrdi3.S",
  4982. "i386/moddi3.S",
  4983. "i386/muldi3.S",
  4984. "i386/udivdi3.S",
  4985. "i386/umoddi3.S",
  4986. ],
  4987. );
  4988. }
  4989. }
  4990. if target_arch == "arm" && target_os != "ios" {
  4991. sources.extend(
  4992. &[
  4993. "arm/aeabi_div0.c",
  4994. "arm/aeabi_drsub.c",
  4995. "arm/aeabi_frsub.c",
  4996. "arm/bswapdi2.S",
  4997. "arm/bswapsi2.S",
  4998. "arm/clzdi2.S",
  4999. "arm/clzsi2.S",
  5000. "arm/divmodsi4.S",
  5001. "arm/modsi3.S",
  5002. "arm/switch16.S",
  5003. "arm/switch32.S",
  5004. "arm/switch8.S",
  5005. "arm/switchu8.S",
  5006. "arm/sync_synchronize.S",
  5007. "arm/udivmodsi4.S",
  5008. "arm/umodsi3.S",
  5009. // Exclude these two files for now even though we haven't
  5010. // translated their implementation into Rust yet (#173).
  5011. // They appear... buggy? The `udivsi3` implementation was
  5012. // the one that seemed buggy, but the `divsi3` file
  5013. // references a symbol from `udivsi3` so we compile them
  5014. // both with the Rust versions.
  5015. //
  5016. // Note that if these are added back they should be removed
  5017. // from thumbv6m below.
  5018. //
  5019. // "arm/divsi3.S",
  5020. // "arm/udivsi3.S",
  5021. ],
  5022. );
  5023. // First of all aeabi_cdcmp and aeabi_cfcmp are never called by LLVM.
  5024. // Second are little-endian only, so build fail on big-endian targets.
  5025. // Temporally workaround: exclude these files for big-endian targets.
  5026. if !llvm_target[0].starts_with("thumbeb") &&
  5027. !llvm_target[0].starts_with("armeb") {
  5028. sources.extend(
  5029. &[
  5030. "arm/aeabi_cdcmp.S",
  5031. "arm/aeabi_cdcmpeq_check_nan.c",
  5032. "arm/aeabi_cfcmp.S",
  5033. "arm/aeabi_cfcmpeq_check_nan.c",
  5034. ],
  5035. );
  5036. }
  5037. }
  5038. if llvm_target[0] == "armv7" {
  5039. sources.extend(
  5040. &[
  5041. "arm/sync_fetch_and_add_4.S",
  5042. "arm/sync_fetch_and_add_8.S",
  5043. "arm/sync_fetch_and_and_4.S",
  5044. "arm/sync_fetch_and_and_8.S",
  5045. "arm/sync_fetch_and_max_4.S",
  5046. "arm/sync_fetch_and_max_8.S",
  5047. "arm/sync_fetch_and_min_4.S",
  5048. "arm/sync_fetch_and_min_8.S",
  5049. "arm/sync_fetch_and_nand_4.S",
  5050. "arm/sync_fetch_and_nand_8.S",
  5051. "arm/sync_fetch_and_or_4.S",
  5052. "arm/sync_fetch_and_or_8.S",
  5053. "arm/sync_fetch_and_sub_4.S",
  5054. "arm/sync_fetch_and_sub_8.S",
  5055. "arm/sync_fetch_and_umax_4.S",
  5056. "arm/sync_fetch_and_umax_8.S",
  5057. "arm/sync_fetch_and_umin_4.S",
  5058. "arm/sync_fetch_and_umin_8.S",
  5059. "arm/sync_fetch_and_xor_4.S",
  5060. "arm/sync_fetch_and_xor_8.S",
  5061. ],
  5062. );
  5063. }
  5064. if llvm_target.last().unwrap().ends_with("eabihf") {
  5065. if !llvm_target[0].starts_with("thumbv7em") {
  5066. sources.extend(
  5067. &[
  5068. "arm/adddf3vfp.S",
  5069. "arm/addsf3vfp.S",
  5070. "arm/eqdf2vfp.S",
  5071. "arm/eqsf2vfp.S",
  5072. "arm/extendsfdf2vfp.S",
  5073. "arm/fixdfsivfp.S",
  5074. "arm/fixsfsivfp.S",
  5075. "arm/fixunsdfsivfp.S",
  5076. "arm/fixunssfsivfp.S",
  5077. "arm/floatsidfvfp.S",
  5078. "arm/floatsisfvfp.S",
  5079. "arm/floatunssidfvfp.S",
  5080. "arm/floatunssisfvfp.S",
  5081. "arm/gedf2vfp.S",
  5082. "arm/gesf2vfp.S",
  5083. "arm/gtdf2vfp.S",
  5084. "arm/gtsf2vfp.S",
  5085. "arm/ledf2vfp.S",
  5086. "arm/lesf2vfp.S",
  5087. "arm/ltdf2vfp.S",
  5088. "arm/ltsf2vfp.S",
  5089. "arm/nedf2vfp.S",
  5090. "arm/nesf2vfp.S",
  5091. "arm/restore_vfp_d8_d15_regs.S",
  5092. "arm/save_vfp_d8_d15_regs.S",
  5093. "arm/subdf3vfp.S",
  5094. "arm/subsf3vfp.S",
  5095. ],
  5096. );
  5097. }
  5098. sources.extend(&["arm/negdf2vfp.S", "arm/negsf2vfp.S"]);
  5099. }
  5100. if target_arch == "aarch64" {
  5101. sources.extend(
  5102. &[
  5103. "comparetf2.c",
  5104. "extenddftf2.c",
  5105. "extendsftf2.c",
  5106. "fixtfdi.c",
  5107. "fixtfsi.c",
  5108. "fixtfti.c",
  5109. "fixunstfdi.c",
  5110. "fixunstfsi.c",
  5111. "fixunstfti.c",
  5112. "floatditf.c",
  5113. "floatsitf.c",
  5114. "floatunditf.c",
  5115. "floatunsitf.c",
  5116. "multc3.c",
  5117. "trunctfdf2.c",
  5118. "trunctfsf2.c",
  5119. ],
  5120. );
  5121. }
  5122. // Remove the assembly implementations that won't compile for the target
  5123. if llvm_target[0] == "thumbv6m" {
  5124. sources.remove(
  5125. &[
  5126. "aeabi_cdcmp",
  5127. "aeabi_cfcmp",
  5128. "aeabi_dcmp",
  5129. "aeabi_fcmp",
  5130. "clzdi2",
  5131. "clzsi2",
  5132. "comparesf2",
  5133. "divmodsi4",
  5134. "modsi3",
  5135. "switch16",
  5136. "switch32",
  5137. "switch8",
  5138. "switchu8",
  5139. "udivmodsi4",
  5140. "umodsi3",
  5141. ],
  5142. );
  5143. // But use some generic implementations where possible
  5144. sources.extend(&["clzdi2.c", "clzsi2.c"])
  5145. }
  5146. if llvm_target[0] == "thumbv7m" || llvm_target[0] == "thumbv7em" {
  5147. sources.remove(&["aeabi_cdcmp", "aeabi_cfcmp"]);
  5148. }
  5149. // When compiling in rustbuild (the rust-lang/rust repo) this build
  5150. // script runs from a directory other than this root directory.
  5151. let root = if cfg!(feature = "rustbuild") {
  5152. Path::new("../../libcompiler_builtins")
  5153. } else {
  5154. Path::new(".")
  5155. };
  5156. let src_dir = root.join("compiler-rt/lib/builtins");
  5157. for src in sources.map.values() {
  5158. let src = src_dir.join(src);
  5159. cfg.file(&src);
  5160. println!("cargo:rerun-if-changed={}", src.display());
  5161. }
  5162. cfg.compile("libcompiler-rt.a");
  5163. }
  5164. }