build.rs 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297
  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. "floatdisf.c",
  4291. "floatundisf.c",
  4292. "int_util.c",
  4293. "muldc3.c",
  4294. "mulsc3.c",
  4295. "mulvdi3.c",
  4296. "mulvsi3.c",
  4297. "mulxc3.c",
  4298. "negdf2.c",
  4299. "negdi2.c",
  4300. "negsf2.c",
  4301. "negvdi2.c",
  4302. "negvsi2.c",
  4303. "paritydi2.c",
  4304. "paritysi2.c",
  4305. "popcountdi2.c",
  4306. "popcountsi2.c",
  4307. "powixf2.c",
  4308. "subvdi3.c",
  4309. "subvsi3.c",
  4310. "truncdfhf2.c",
  4311. "truncdfsf2.c",
  4312. "truncsfhf2.c",
  4313. "ucmpdi2.c",
  4314. ],
  4315. );
  4316. // When compiling in rustbuild (the rust-lang/rust repo) this library
  4317. // also needs to satisfy intrinsics that jemalloc or C in general may
  4318. // need, so include a few more that aren't typically needed by
  4319. // LLVM/Rust.
  4320. if cfg!(feature = "rustbuild") {
  4321. sources.extend(&[
  4322. "ffsdi2.c",
  4323. ]);
  4324. }
  4325. // On iOS and 32-bit OSX these are all just empty intrinsics, no need to
  4326. // include them.
  4327. if target_os != "ios" && (target_vendor != "apple" || target_arch != "x86") {
  4328. sources.extend(
  4329. &[
  4330. "absvti2.c",
  4331. "addvti3.c",
  4332. "clzti2.c",
  4333. "cmpti2.c",
  4334. "ctzti2.c",
  4335. "ffsti2.c",
  4336. "mulvti3.c",
  4337. "negti2.c",
  4338. "negvti2.c",
  4339. "parityti2.c",
  4340. "popcountti2.c",
  4341. "subvti3.c",
  4342. "ucmpti2.c",
  4343. ],
  4344. );
  4345. }
  4346. if target_vendor == "apple" {
  4347. sources.extend(
  4348. &[
  4349. "atomic_flag_clear.c",
  4350. "atomic_flag_clear_explicit.c",
  4351. "atomic_flag_test_and_set.c",
  4352. "atomic_flag_test_and_set_explicit.c",
  4353. "atomic_signal_fence.c",
  4354. "atomic_thread_fence.c",
  4355. ],
  4356. );
  4357. }
  4358. if target_env == "msvc" {
  4359. if target_arch == "x86_64" {
  4360. sources.extend(
  4361. &[
  4362. "x86_64/floatdisf.c",
  4363. "x86_64/floatdixf.c",
  4364. ],
  4365. );
  4366. }
  4367. } else {
  4368. // None of these seem to be used on x86_64 windows, and they've all
  4369. // got the wrong ABI anyway, so we want to avoid them.
  4370. if target_os != "windows" {
  4371. if target_arch == "x86_64" {
  4372. sources.extend(
  4373. &[
  4374. "x86_64/floatdisf.c",
  4375. "x86_64/floatdixf.c",
  4376. "x86_64/floatundidf.S",
  4377. "x86_64/floatundisf.S",
  4378. "x86_64/floatundixf.S",
  4379. ],
  4380. );
  4381. }
  4382. }
  4383. if target_arch == "x86" {
  4384. sources.extend(
  4385. &[
  4386. "i386/ashldi3.S",
  4387. "i386/ashrdi3.S",
  4388. "i386/divdi3.S",
  4389. "i386/floatdidf.S",
  4390. "i386/floatdisf.S",
  4391. "i386/floatdixf.S",
  4392. "i386/floatundidf.S",
  4393. "i386/floatundisf.S",
  4394. "i386/floatundixf.S",
  4395. "i386/lshrdi3.S",
  4396. "i386/moddi3.S",
  4397. "i386/muldi3.S",
  4398. "i386/udivdi3.S",
  4399. "i386/umoddi3.S",
  4400. ],
  4401. );
  4402. }
  4403. }
  4404. if target_arch == "arm" && target_os != "ios" {
  4405. sources.extend(
  4406. &[
  4407. "arm/aeabi_cdcmp.S",
  4408. "arm/aeabi_cdcmpeq_check_nan.c",
  4409. "arm/aeabi_cfcmp.S",
  4410. "arm/aeabi_cfcmpeq_check_nan.c",
  4411. "arm/aeabi_dcmp.S",
  4412. "arm/aeabi_div0.c",
  4413. "arm/aeabi_drsub.c",
  4414. "arm/aeabi_fcmp.S",
  4415. "arm/aeabi_frsub.c",
  4416. "arm/bswapdi2.S",
  4417. "arm/bswapsi2.S",
  4418. "arm/clzdi2.S",
  4419. "arm/clzsi2.S",
  4420. "arm/comparesf2.S",
  4421. "arm/divmodsi4.S",
  4422. "arm/modsi3.S",
  4423. "arm/switch16.S",
  4424. "arm/switch32.S",
  4425. "arm/switch8.S",
  4426. "arm/switchu8.S",
  4427. "arm/sync_synchronize.S",
  4428. "arm/udivmodsi4.S",
  4429. "arm/umodsi3.S",
  4430. // Exclude these two files for now even though we haven't
  4431. // translated their implementation into Rust yet (#173).
  4432. // They appear... buggy? The `udivsi3` implementation was
  4433. // the one that seemed buggy, but the `divsi3` file
  4434. // references a symbol from `udivsi3` so we compile them
  4435. // both with the Rust versions.
  4436. //
  4437. // Note that if these are added back they should be removed
  4438. // from thumbv6m below.
  4439. //
  4440. // "arm/divsi3.S",
  4441. // "arm/udivsi3.S",
  4442. ],
  4443. );
  4444. }
  4445. if llvm_target[0] == "armv7" {
  4446. sources.extend(
  4447. &[
  4448. "arm/sync_fetch_and_add_4.S",
  4449. "arm/sync_fetch_and_add_8.S",
  4450. "arm/sync_fetch_and_and_4.S",
  4451. "arm/sync_fetch_and_and_8.S",
  4452. "arm/sync_fetch_and_max_4.S",
  4453. "arm/sync_fetch_and_max_8.S",
  4454. "arm/sync_fetch_and_min_4.S",
  4455. "arm/sync_fetch_and_min_8.S",
  4456. "arm/sync_fetch_and_nand_4.S",
  4457. "arm/sync_fetch_and_nand_8.S",
  4458. "arm/sync_fetch_and_or_4.S",
  4459. "arm/sync_fetch_and_or_8.S",
  4460. "arm/sync_fetch_and_sub_4.S",
  4461. "arm/sync_fetch_and_sub_8.S",
  4462. "arm/sync_fetch_and_umax_4.S",
  4463. "arm/sync_fetch_and_umax_8.S",
  4464. "arm/sync_fetch_and_umin_4.S",
  4465. "arm/sync_fetch_and_umin_8.S",
  4466. "arm/sync_fetch_and_xor_4.S",
  4467. "arm/sync_fetch_and_xor_8.S",
  4468. ],
  4469. );
  4470. }
  4471. if llvm_target.last().unwrap().ends_with("eabihf") {
  4472. if !llvm_target[0].starts_with("thumbv7em") {
  4473. sources.extend(
  4474. &[
  4475. "arm/adddf3vfp.S",
  4476. "arm/addsf3vfp.S",
  4477. "arm/divdf3vfp.S",
  4478. "arm/divsf3vfp.S",
  4479. "arm/eqdf2vfp.S",
  4480. "arm/eqsf2vfp.S",
  4481. "arm/extendsfdf2vfp.S",
  4482. "arm/fixdfsivfp.S",
  4483. "arm/fixsfsivfp.S",
  4484. "arm/fixunsdfsivfp.S",
  4485. "arm/fixunssfsivfp.S",
  4486. "arm/floatsidfvfp.S",
  4487. "arm/floatsisfvfp.S",
  4488. "arm/floatunssidfvfp.S",
  4489. "arm/floatunssisfvfp.S",
  4490. "arm/gedf2vfp.S",
  4491. "arm/gesf2vfp.S",
  4492. "arm/gtdf2vfp.S",
  4493. "arm/gtsf2vfp.S",
  4494. "arm/ledf2vfp.S",
  4495. "arm/lesf2vfp.S",
  4496. "arm/ltdf2vfp.S",
  4497. "arm/ltsf2vfp.S",
  4498. "arm/muldf3vfp.S",
  4499. "arm/mulsf3vfp.S",
  4500. "arm/nedf2vfp.S",
  4501. "arm/nesf2vfp.S",
  4502. "arm/restore_vfp_d8_d15_regs.S",
  4503. "arm/save_vfp_d8_d15_regs.S",
  4504. "arm/subdf3vfp.S",
  4505. "arm/subsf3vfp.S",
  4506. ],
  4507. );
  4508. }
  4509. sources.extend(&["arm/negdf2vfp.S", "arm/negsf2vfp.S"]);
  4510. }
  4511. if target_arch == "aarch64" {
  4512. sources.extend(
  4513. &[
  4514. "comparetf2.c",
  4515. "extenddftf2.c",
  4516. "extendsftf2.c",
  4517. "fixtfdi.c",
  4518. "fixtfsi.c",
  4519. "fixtfti.c",
  4520. "fixunstfdi.c",
  4521. "fixunstfsi.c",
  4522. "fixunstfti.c",
  4523. "floatditf.c",
  4524. "floatsitf.c",
  4525. "floatunditf.c",
  4526. "floatunsitf.c",
  4527. "multc3.c",
  4528. "trunctfdf2.c",
  4529. "trunctfsf2.c",
  4530. ],
  4531. );
  4532. }
  4533. // Remove the assembly implementations that won't compile for the target
  4534. if llvm_target[0] == "thumbv6m" {
  4535. sources.remove(
  4536. &[
  4537. "aeabi_cdcmp",
  4538. "aeabi_cfcmp",
  4539. "aeabi_dcmp",
  4540. "aeabi_fcmp",
  4541. "clzdi2",
  4542. "clzsi2",
  4543. "comparesf2",
  4544. "divmodsi4",
  4545. "modsi3",
  4546. "switch16",
  4547. "switch32",
  4548. "switch8",
  4549. "switchu8",
  4550. "udivmodsi4",
  4551. "umodsi3",
  4552. ],
  4553. );
  4554. // But use some generic implementations where possible
  4555. sources.extend(&["clzdi2.c", "clzsi2.c"])
  4556. }
  4557. if llvm_target[0] == "thumbv7m" || llvm_target[0] == "thumbv7em" {
  4558. sources.remove(&["aeabi_cdcmp", "aeabi_cfcmp"]);
  4559. }
  4560. // When compiling in rustbuild (the rust-lang/rust repo) this build
  4561. // script runs from a directory other than this root directory.
  4562. let root = if cfg!(feature = "rustbuild") {
  4563. Path::new("../../libcompiler_builtins")
  4564. } else {
  4565. Path::new(".")
  4566. };
  4567. let src_dir = root.join("compiler-rt/lib/builtins");
  4568. for src in sources.map.values() {
  4569. let src = src_dir.join(src);
  4570. cfg.file(&src);
  4571. println!("cargo:rerun-if-changed={}", src.display());
  4572. }
  4573. cfg.compile("libcompiler-rt.a");
  4574. }
  4575. }