build.rs 99 KB

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