build.rs 120 KB

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