build.rs 99 KB

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