build.rs 106 KB

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