build.rs 100 KB

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