build.rs 127 KB

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