build.rs 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387
  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 diff = if to_u64(b_) > b { to_u64(b_) - b } else { b - to_u64(b_) };
  1639. assert_eq!(((a,), b, true), ((a,), b, diff <= 1));
  1640. }
  1641. }
  1642. "
  1643. }
  1644. }
  1645. #[derive(Eq, Hash, PartialEq)]
  1646. pub struct Floatundidf {
  1647. a: u64,
  1648. b: u64, // f64
  1649. }
  1650. impl TestCase for Floatundidf {
  1651. fn name() -> &'static str {
  1652. "floatundidf"
  1653. }
  1654. fn generate<R>(rng: &mut R) -> Option<Self>
  1655. where
  1656. R: Rng,
  1657. Self: Sized,
  1658. {
  1659. let a = gen_u64(rng);
  1660. Some(
  1661. Floatundidf {
  1662. a,
  1663. b: to_u64(f64(a)),
  1664. },
  1665. )
  1666. }
  1667. fn to_string(&self, buffer: &mut String) {
  1668. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1669. }
  1670. fn prologue() -> &'static str {
  1671. r#"
  1672. #[cfg(all(target_arch = "arm",
  1673. not(any(target_env = "gnu", target_env = "musl")),
  1674. target_os = "linux",
  1675. test))]
  1676. use core::mem;
  1677. #[cfg(not(all(target_arch = "arm",
  1678. not(any(target_env = "gnu", target_env = "musl")),
  1679. target_os = "linux",
  1680. test)))]
  1681. use std::mem;
  1682. use compiler_builtins::float::conv::__floatundidf;
  1683. fn to_u64(x: f64) -> u64 {
  1684. unsafe { mem::transmute(x) }
  1685. }
  1686. static TEST_CASES: &[((u64,), u64)] = &[
  1687. "#
  1688. }
  1689. fn epilogue() -> &'static str {
  1690. "
  1691. ];
  1692. #[test]
  1693. fn floatundidf() {
  1694. for &((a,), b) in TEST_CASES {
  1695. let b_ = __floatundidf(a);
  1696. assert_eq!(((a,), b), ((a,), to_u64(b_)));
  1697. }
  1698. }
  1699. "
  1700. }
  1701. }
  1702. #[derive(Eq, Hash, PartialEq)]
  1703. pub struct Floatunsidf {
  1704. a: u32,
  1705. b: u64, // f64
  1706. }
  1707. impl TestCase for Floatunsidf {
  1708. fn name() -> &'static str {
  1709. "floatunsidf"
  1710. }
  1711. fn generate<R>(rng: &mut R) -> Option<Self>
  1712. where
  1713. R: Rng,
  1714. Self: Sized,
  1715. {
  1716. let a = gen_u32(rng);
  1717. Some(
  1718. Floatunsidf {
  1719. a,
  1720. b: to_u64(f64(a)),
  1721. },
  1722. )
  1723. }
  1724. fn to_string(&self, buffer: &mut String) {
  1725. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1726. }
  1727. fn prologue() -> &'static str {
  1728. r#"
  1729. #[cfg(all(target_arch = "arm",
  1730. not(any(target_env = "gnu", target_env = "musl")),
  1731. target_os = "linux",
  1732. test))]
  1733. use core::mem;
  1734. #[cfg(not(all(target_arch = "arm",
  1735. not(any(target_env = "gnu", target_env = "musl")),
  1736. target_os = "linux",
  1737. test)))]
  1738. use std::mem;
  1739. use compiler_builtins::float::conv::__floatunsidf;
  1740. fn to_u64(x: f64) -> u64 {
  1741. unsafe { mem::transmute(x) }
  1742. }
  1743. static TEST_CASES: &[((u32,), u64)] = &[
  1744. "#
  1745. }
  1746. fn epilogue() -> &'static str {
  1747. "
  1748. ];
  1749. #[test]
  1750. fn floatunsidf() {
  1751. for &((a,), b) in TEST_CASES {
  1752. let b_ = __floatunsidf(a);
  1753. assert_eq!(((a,), b), ((a,), to_u64(b_)));
  1754. }
  1755. }
  1756. "
  1757. }
  1758. }
  1759. #[derive(Eq, Hash, PartialEq)]
  1760. pub struct Floatunsisf {
  1761. a: u32,
  1762. b: u32, // f32
  1763. }
  1764. impl TestCase for Floatunsisf {
  1765. fn name() -> &'static str {
  1766. "floatunsisf"
  1767. }
  1768. fn generate<R>(rng: &mut R) -> Option<Self>
  1769. where
  1770. R: Rng,
  1771. Self: Sized,
  1772. {
  1773. let a = gen_u32(rng);
  1774. Some(
  1775. Floatunsisf {
  1776. a,
  1777. b: to_u32(f32(a)),
  1778. },
  1779. )
  1780. }
  1781. fn to_string(&self, buffer: &mut String) {
  1782. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1783. }
  1784. fn prologue() -> &'static str {
  1785. r#"
  1786. #[cfg(all(target_arch = "arm",
  1787. not(any(target_env = "gnu", target_env = "musl")),
  1788. target_os = "linux",
  1789. test))]
  1790. use core::mem;
  1791. #[cfg(not(all(target_arch = "arm",
  1792. not(any(target_env = "gnu", target_env = "musl")),
  1793. target_os = "linux",
  1794. test)))]
  1795. use std::mem;
  1796. use compiler_builtins::float::conv::__floatunsisf;
  1797. fn to_u32(x: f32) -> u32 {
  1798. unsafe { mem::transmute(x) }
  1799. }
  1800. static TEST_CASES: &[((u32,), u32)] = &[
  1801. "#
  1802. }
  1803. fn epilogue() -> &'static str {
  1804. "
  1805. ];
  1806. #[test]
  1807. fn floatunsisf() {
  1808. for &((a,), b) in TEST_CASES {
  1809. let b_ = __floatunsisf(a);
  1810. assert_eq!(((a,), b), ((a,), to_u32(b_)));
  1811. }
  1812. }
  1813. "
  1814. }
  1815. }
  1816. #[derive(Eq, Hash, PartialEq)]
  1817. pub struct Floatuntisf {
  1818. a: u128,
  1819. b: u32, // f32
  1820. }
  1821. impl TestCase for Floatuntisf {
  1822. fn name() -> &'static str {
  1823. "floatuntisf"
  1824. }
  1825. fn generate<R>(rng: &mut R) -> Option<Self>
  1826. where
  1827. R: Rng,
  1828. Self: Sized,
  1829. {
  1830. let a = gen_u128(rng);
  1831. let f_a = f32(a);
  1832. f_a.ok().map(|f| {
  1833. Floatuntisf {
  1834. a,
  1835. b: to_u32(f),
  1836. }
  1837. })
  1838. }
  1839. fn to_string(&self, buffer: &mut String) {
  1840. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1841. }
  1842. fn prologue() -> &'static str {
  1843. r#"
  1844. #[cfg(all(target_arch = "arm",
  1845. not(any(target_env = "gnu", target_env = "musl")),
  1846. target_os = "linux",
  1847. test))]
  1848. use core::mem;
  1849. #[cfg(not(all(target_arch = "arm",
  1850. not(any(target_env = "gnu", target_env = "musl")),
  1851. target_os = "linux",
  1852. test)))]
  1853. use std::mem;
  1854. use compiler_builtins::float::conv::__floatuntisf;
  1855. fn to_u32(x: f32) -> u32 {
  1856. unsafe { mem::transmute(x) }
  1857. }
  1858. static TEST_CASES: &[((u128,), u32)] = &[
  1859. "#
  1860. }
  1861. fn epilogue() -> &'static str {
  1862. "
  1863. ];
  1864. #[test]
  1865. fn floatuntisf() {
  1866. for &((a,), b) in TEST_CASES {
  1867. let b_ = __floatuntisf(a);
  1868. assert_eq!(((a,), b), ((a,), to_u32(b_)));
  1869. }
  1870. }
  1871. "
  1872. }
  1873. }
  1874. #[derive(Eq, Hash, PartialEq)]
  1875. pub struct Floatuntidf {
  1876. a: u128,
  1877. b: u64, // f64
  1878. }
  1879. impl TestCase for Floatuntidf {
  1880. fn name() -> &'static str {
  1881. "floatuntidf"
  1882. }
  1883. fn generate<R>(rng: &mut R) -> Option<Self>
  1884. where
  1885. R: Rng,
  1886. Self: Sized,
  1887. {
  1888. let a = gen_u128(rng);
  1889. Some(
  1890. Floatuntidf {
  1891. a,
  1892. b: to_u64(f64(a)),
  1893. },
  1894. )
  1895. }
  1896. fn to_string(&self, buffer: &mut String) {
  1897. writeln!(buffer, "(({a},), {b}),", a = self.a, b = self.b).unwrap();
  1898. }
  1899. fn prologue() -> &'static str {
  1900. r#"
  1901. #[cfg(all(target_arch = "arm",
  1902. not(any(target_env = "gnu", target_env = "musl")),
  1903. target_os = "linux",
  1904. test))]
  1905. use core::mem;
  1906. #[cfg(not(all(target_arch = "arm",
  1907. not(any(target_env = "gnu", target_env = "musl")),
  1908. target_os = "linux",
  1909. test)))]
  1910. use std::mem;
  1911. use compiler_builtins::float::conv::__floatuntidf;
  1912. fn to_u64(x: f64) -> u64 {
  1913. unsafe { mem::transmute(x) }
  1914. }
  1915. static TEST_CASES: &[((u128,), u64)] = &[
  1916. "#
  1917. }
  1918. fn epilogue() -> &'static str {
  1919. "
  1920. ];
  1921. #[test]
  1922. fn floatuntidf() {
  1923. for &((a,), b) in TEST_CASES {
  1924. let b_ = __floatuntidf(a);
  1925. let diff = if to_u64(b_) > b { to_u64(b_) - b } else { b - to_u64(b_) };
  1926. assert_eq!(((a,), b, true), ((a,), b, diff <= 1));
  1927. }
  1928. }
  1929. "
  1930. }
  1931. }
  1932. #[derive(Eq, Hash, PartialEq)]
  1933. pub struct Moddi3 {
  1934. a: i64,
  1935. b: i64,
  1936. c: i64,
  1937. }
  1938. impl TestCase for Moddi3 {
  1939. fn name() -> &'static str {
  1940. "moddi3"
  1941. }
  1942. fn generate<R>(rng: &mut R) -> Option<Self>
  1943. where
  1944. R: Rng,
  1945. Self: Sized,
  1946. {
  1947. let a = gen_i64(rng);
  1948. let b = gen_i64(rng);
  1949. if b == 0 {
  1950. return None;
  1951. }
  1952. let c = a % b;
  1953. Some(Moddi3 { a, b, c })
  1954. }
  1955. fn to_string(&self, buffer: &mut String) {
  1956. writeln!(
  1957. buffer,
  1958. "(({a}, {b}), {c}),",
  1959. a = self.a,
  1960. b = self.b,
  1961. c = self.c
  1962. )
  1963. .unwrap();
  1964. }
  1965. fn prologue() -> &'static str {
  1966. "
  1967. use compiler_builtins::int::sdiv::__moddi3;
  1968. static TEST_CASES: &[((i64, i64), i64)] = &[
  1969. "
  1970. }
  1971. fn epilogue() -> &'static str {
  1972. "
  1973. ];
  1974. #[test]
  1975. fn moddi3() {
  1976. for &((a, b), c) in TEST_CASES {
  1977. let c_ = __moddi3(a, b);
  1978. assert_eq!(((a, b), c), ((a, b), c_));
  1979. }
  1980. }
  1981. "
  1982. }
  1983. }
  1984. #[derive(Eq, Hash, PartialEq)]
  1985. pub struct Modsi3 {
  1986. a: i32,
  1987. b: i32,
  1988. c: i32,
  1989. }
  1990. impl TestCase for Modsi3 {
  1991. fn name() -> &'static str {
  1992. "modsi3"
  1993. }
  1994. fn generate<R>(rng: &mut R) -> Option<Self>
  1995. where
  1996. R: Rng,
  1997. Self: Sized,
  1998. {
  1999. let a = gen_i32(rng);
  2000. let b = gen_i32(rng);
  2001. if b == 0 {
  2002. return None;
  2003. }
  2004. let c = a % b;
  2005. Some(Modsi3 { a, b, c })
  2006. }
  2007. fn to_string(&self, buffer: &mut String) {
  2008. writeln!(
  2009. buffer,
  2010. "(({a}, {b}), {c}),",
  2011. a = self.a,
  2012. b = self.b,
  2013. c = self.c
  2014. )
  2015. .unwrap();
  2016. }
  2017. fn prologue() -> &'static str {
  2018. "
  2019. use compiler_builtins::int::sdiv::__modsi3;
  2020. static TEST_CASES: &[((i32, i32), i32)] = &[
  2021. "
  2022. }
  2023. fn epilogue() -> &'static str {
  2024. "
  2025. ];
  2026. #[test]
  2027. fn modsi3() {
  2028. for &((a, b), c) in TEST_CASES {
  2029. let c_ = __modsi3(a, b);
  2030. assert_eq!(((a, b), c), ((a, b), c_));
  2031. }
  2032. }
  2033. "
  2034. }
  2035. }
  2036. #[derive(Eq, Hash, PartialEq)]
  2037. pub struct Modti3 {
  2038. a: i128,
  2039. b: i128,
  2040. c: i128,
  2041. }
  2042. impl TestCase for Modti3 {
  2043. fn name() -> &'static str {
  2044. "modti3"
  2045. }
  2046. fn generate<R>(rng: &mut R) -> Option<Self>
  2047. where
  2048. R: Rng,
  2049. Self: Sized,
  2050. {
  2051. let a = gen_i128(rng);
  2052. let b = gen_i128(rng);
  2053. if b == 0 {
  2054. return None;
  2055. }
  2056. let c = a % b;
  2057. Some(Modti3 { a, b, c })
  2058. }
  2059. fn to_string(&self, buffer: &mut String) {
  2060. writeln!(
  2061. buffer,
  2062. "(({a}, {b}), {c}),",
  2063. a = self.a,
  2064. b = self.b,
  2065. c = self.c
  2066. )
  2067. .unwrap();
  2068. }
  2069. fn prologue() -> &'static str {
  2070. "
  2071. use compiler_builtins::int::sdiv::__modti3;
  2072. static TEST_CASES: &[((i128, i128), i128)] = &[
  2073. "
  2074. }
  2075. fn epilogue() -> &'static str {
  2076. "
  2077. ];
  2078. #[test]
  2079. fn modti3() {
  2080. for &((a, b), c) in TEST_CASES {
  2081. let c_ = __modti3(a, b);
  2082. assert_eq!(((a, b), c), ((a, b), c_));
  2083. }
  2084. }
  2085. "
  2086. }
  2087. }
  2088. #[derive(Eq, Hash, PartialEq)]
  2089. struct Muldi3 {
  2090. a: u64,
  2091. b: u64,
  2092. c: u64,
  2093. }
  2094. impl TestCase for Muldi3 {
  2095. fn name() -> &'static str {
  2096. "muldi3"
  2097. }
  2098. fn generate<R>(rng: &mut R) -> Option<Self>
  2099. where
  2100. R: Rng,
  2101. Self: Sized,
  2102. {
  2103. let a = gen_u64(rng);
  2104. let b = gen_u64(rng);
  2105. let c = a.wrapping_mul(b);
  2106. Some(Muldi3 { a, b, c })
  2107. }
  2108. fn to_string(&self, buffer: &mut String) {
  2109. writeln!(
  2110. buffer,
  2111. "(({a}, {b}), {c}),",
  2112. a = self.a,
  2113. b = self.b,
  2114. c = self.c
  2115. )
  2116. .unwrap();
  2117. }
  2118. fn prologue() -> &'static str {
  2119. "
  2120. use compiler_builtins::int::mul::__muldi3;
  2121. static TEST_CASES: &[((u64, u64), u64)] = &[
  2122. "
  2123. }
  2124. fn epilogue() -> &'static str {
  2125. "
  2126. ];
  2127. #[test]
  2128. fn muldi3() {
  2129. for &((a, b), c) in TEST_CASES {
  2130. let c_ = __muldi3(a, b);
  2131. assert_eq!(((a, b), c), ((a, b), c_));
  2132. }
  2133. }
  2134. "
  2135. }
  2136. }
  2137. #[derive(Eq, Hash, PartialEq)]
  2138. pub struct Mulodi4 {
  2139. a: i64,
  2140. b: i64,
  2141. c: i64,
  2142. overflow: u32,
  2143. }
  2144. impl TestCase for Mulodi4 {
  2145. fn name() -> &'static str {
  2146. "mulodi4"
  2147. }
  2148. fn generate<R>(rng: &mut R) -> Option<Self>
  2149. where
  2150. R: Rng,
  2151. {
  2152. let a = gen_i64(rng);
  2153. let b = gen_i64(rng);
  2154. let c = a.wrapping_mul(b);
  2155. let overflow = if a.checked_mul(b).is_some() { 0 } else { 1 };
  2156. Some(Mulodi4 { a, b, c, overflow })
  2157. }
  2158. fn to_string(&self, buffer: &mut String) {
  2159. writeln!(
  2160. buffer,
  2161. "(({a}, {b}), ({c}, {overflow})),",
  2162. a = self.a,
  2163. b = self.b,
  2164. c = self.c,
  2165. overflow = self.overflow
  2166. )
  2167. .unwrap();
  2168. }
  2169. fn prologue() -> &'static str {
  2170. "
  2171. use compiler_builtins::int::mul::__mulodi4;
  2172. static TEST_CASES: &[((i64, i64), (i64, i32))] = &[
  2173. "
  2174. }
  2175. fn epilogue() -> &'static str {
  2176. "
  2177. ];
  2178. #[test]
  2179. fn mulodi4() {
  2180. let mut overflow_ = 2;
  2181. for &((a, b), (c, overflow)) in TEST_CASES {
  2182. let c_ = __mulodi4(a, b, &mut overflow_);
  2183. assert_eq!(((a, b), (c, overflow)), ((a, b), (c_, overflow_)));
  2184. }
  2185. }
  2186. "
  2187. }
  2188. }
  2189. #[derive(Eq, Hash, PartialEq)]
  2190. pub struct Mulosi4 {
  2191. a: i32,
  2192. b: i32,
  2193. c: i32,
  2194. overflow: u32,
  2195. }
  2196. impl TestCase for Mulosi4 {
  2197. fn name() -> &'static str {
  2198. "mulosi4"
  2199. }
  2200. fn generate<R>(rng: &mut R) -> Option<Self>
  2201. where
  2202. R: Rng,
  2203. {
  2204. let a = gen_i32(rng);
  2205. let b = gen_i32(rng);
  2206. let c = a.wrapping_mul(b);
  2207. let overflow = if a.checked_mul(b).is_some() { 0 } else { 1 };
  2208. Some(Mulosi4 { a, b, c, overflow })
  2209. }
  2210. fn prologue() -> &'static str {
  2211. "
  2212. use compiler_builtins::int::mul::__mulosi4;
  2213. static TEST_CASES: &[((i32, i32), (i32, i32))] = &[
  2214. "
  2215. }
  2216. fn epilogue() -> &'static str {
  2217. "
  2218. ];
  2219. #[test]
  2220. fn mulosi4() {
  2221. let mut overflow_ = 2;
  2222. for &((a, b), (c, overflow)) in TEST_CASES {
  2223. let c_ = __mulosi4(a, b, &mut overflow_);
  2224. assert_eq!(((a, b), (c, overflow)), ((a, b), (c_, overflow_)));
  2225. }
  2226. }
  2227. "
  2228. }
  2229. fn to_string(&self, buffer: &mut String) {
  2230. writeln!(
  2231. buffer,
  2232. "(({a}, {b}), ({c}, {overflow})),",
  2233. a = self.a,
  2234. b = self.b,
  2235. c = self.c,
  2236. overflow = self.overflow
  2237. )
  2238. .unwrap();
  2239. }
  2240. }
  2241. #[derive(Eq, Hash, PartialEq)]
  2242. pub struct Muloti4 {
  2243. a: i128,
  2244. b: i128,
  2245. c: i128,
  2246. overflow: u32,
  2247. }
  2248. impl TestCase for Muloti4 {
  2249. fn name() -> &'static str {
  2250. "muloti4"
  2251. }
  2252. fn generate<R>(rng: &mut R) -> Option<Self>
  2253. where
  2254. R: Rng,
  2255. {
  2256. let a = gen_i128(rng);
  2257. let b = gen_i128(rng);
  2258. let c = a.wrapping_mul(b);
  2259. let overflow = if a.checked_mul(b).is_some() { 0 } else { 1 };
  2260. Some(Muloti4 { a, b, c, overflow })
  2261. }
  2262. fn prologue() -> &'static str {
  2263. "
  2264. use compiler_builtins::int::mul::__muloti4;
  2265. static TEST_CASES: &[((i128, i128), (i128, i32))] = &[
  2266. "
  2267. }
  2268. fn epilogue() -> &'static str {
  2269. "
  2270. ];
  2271. #[test]
  2272. fn muloti4() {
  2273. let mut overflow_ = 2;
  2274. for &((a, b), (c, overflow)) in TEST_CASES {
  2275. let c_ = __muloti4(a, b, &mut overflow_);
  2276. assert_eq!(((a, b), (c, overflow)), ((a, b), (c_, overflow_)));
  2277. }
  2278. }
  2279. "
  2280. }
  2281. fn to_string(&self, buffer: &mut String) {
  2282. writeln!(
  2283. buffer,
  2284. "(({a}, {b}), ({c}, {overflow})),",
  2285. a = self.a,
  2286. b = self.b,
  2287. c = self.c,
  2288. overflow = self.overflow
  2289. )
  2290. .unwrap();
  2291. }
  2292. }
  2293. #[derive(Eq, Hash, PartialEq)]
  2294. pub struct Multi3 {
  2295. a: i128,
  2296. b: i128,
  2297. c: i128,
  2298. }
  2299. impl TestCase for Multi3 {
  2300. fn name() -> &'static str {
  2301. "multi3"
  2302. }
  2303. fn generate<R>(rng: &mut R) -> Option<Self>
  2304. where
  2305. R: Rng,
  2306. Self: Sized,
  2307. {
  2308. let a = gen_i128(rng);
  2309. let b = gen_i128(rng);
  2310. let c = a.wrapping_mul(b);
  2311. Some(Multi3 { a, b, c })
  2312. }
  2313. fn to_string(&self, buffer: &mut String) {
  2314. writeln!(
  2315. buffer,
  2316. "(({a}, {b}), {c}),",
  2317. a = self.a,
  2318. b = self.b,
  2319. c = self.c
  2320. )
  2321. .unwrap();
  2322. }
  2323. fn prologue() -> &'static str {
  2324. "
  2325. use compiler_builtins::int::mul::__multi3;
  2326. static TEST_CASES: &[((i128, i128), i128)] = &[
  2327. "
  2328. }
  2329. fn epilogue() -> &'static str {
  2330. "
  2331. ];
  2332. #[test]
  2333. fn multi3() {
  2334. for &((a, b), c) in TEST_CASES {
  2335. let c_ = __multi3(a, b);
  2336. assert_eq!(((a, b), c), ((a, b), c_));
  2337. }
  2338. }
  2339. "
  2340. }
  2341. }
  2342. #[derive(Eq, Hash, PartialEq)]
  2343. pub struct Powidf2 {
  2344. a: u64, // f64
  2345. b: i32,
  2346. c: u64, // f64
  2347. }
  2348. impl TestCase for Powidf2 {
  2349. fn name() -> &'static str {
  2350. "powidf2"
  2351. }
  2352. fn generate<R>(rng: &mut R) -> Option<Self>
  2353. where
  2354. R: Rng,
  2355. Self: Sized,
  2356. {
  2357. let a = gen_f64(rng);
  2358. let b = gen_i32(rng);
  2359. let c = a.powi(b);
  2360. // TODO accept NaNs. We don't do that right now because we can't check
  2361. // for NaN-ness on the thumb targets
  2362. if a.is_nan() || c.is_nan() {
  2363. return None;
  2364. }
  2365. Some(
  2366. Powidf2 {
  2367. a: to_u64(a),
  2368. b,
  2369. c: to_u64(c),
  2370. },
  2371. )
  2372. }
  2373. fn to_string(&self, buffer: &mut String) {
  2374. writeln!(
  2375. buffer,
  2376. "(({a}, {b}), {c}),",
  2377. a = self.a,
  2378. b = self.b,
  2379. c = self.c
  2380. )
  2381. .unwrap();
  2382. }
  2383. fn prologue() -> &'static str {
  2384. r#"
  2385. #[cfg(all(target_arch = "arm",
  2386. not(any(target_env = "gnu", target_env = "musl")),
  2387. target_os = "linux",
  2388. test))]
  2389. use core::mem;
  2390. #[cfg(not(all(target_arch = "arm",
  2391. not(any(target_env = "gnu", target_env = "musl")),
  2392. target_os = "linux",
  2393. test)))]
  2394. use std::mem;
  2395. use compiler_builtins::float::pow::__powidf2;
  2396. fn mk_f64(x: u64) -> f64 {
  2397. unsafe { mem::transmute(x) }
  2398. }
  2399. fn to_u64(x: f64) -> u64 {
  2400. unsafe { mem::transmute(x) }
  2401. }
  2402. static TEST_CASES: &[((u64, i32), u64)] = &[
  2403. "#
  2404. }
  2405. fn epilogue() -> &'static str {
  2406. "
  2407. ];
  2408. #[test]
  2409. fn powidf2() {
  2410. for &((a, b), c) in TEST_CASES {
  2411. let c_ = __powidf2(mk_f64(a), b);
  2412. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  2413. }
  2414. }
  2415. "
  2416. }
  2417. }
  2418. #[derive(Eq, Hash, PartialEq)]
  2419. pub struct Powisf2 {
  2420. a: u32, // f32
  2421. b: i32,
  2422. c: u32, // f32
  2423. }
  2424. impl TestCase for Powisf2 {
  2425. fn name() -> &'static str {
  2426. "powisf2"
  2427. }
  2428. fn generate<R>(rng: &mut R) -> Option<Self>
  2429. where
  2430. R: Rng,
  2431. Self: Sized,
  2432. {
  2433. let a = gen_f32(rng);
  2434. let b = gen_i32(rng);
  2435. let c = a.powi(b);
  2436. // TODO accept NaNs. We don't do that right now because we can't check
  2437. // for NaN-ness on the thumb targets
  2438. if a.is_nan() || c.is_nan() {
  2439. return None;
  2440. }
  2441. Some(
  2442. Powisf2 {
  2443. a: to_u32(a),
  2444. b,
  2445. c: to_u32(c),
  2446. },
  2447. )
  2448. }
  2449. fn to_string(&self, buffer: &mut String) {
  2450. writeln!(
  2451. buffer,
  2452. "(({a}, {b}), {c}),",
  2453. a = self.a,
  2454. b = self.b,
  2455. c = self.c
  2456. )
  2457. .unwrap();
  2458. }
  2459. fn prologue() -> &'static str {
  2460. r#"
  2461. #[cfg(all(target_arch = "arm",
  2462. not(any(target_env = "gnu", target_env = "musl")),
  2463. target_os = "linux",
  2464. test))]
  2465. use core::mem;
  2466. #[cfg(not(all(target_arch = "arm",
  2467. not(any(target_env = "gnu", target_env = "musl")),
  2468. target_os = "linux",
  2469. test)))]
  2470. use std::mem;
  2471. use compiler_builtins::float::pow::__powisf2;
  2472. fn mk_f32(x: u32) -> f32 {
  2473. unsafe { mem::transmute(x) }
  2474. }
  2475. fn to_u32(x: f32) -> u32 {
  2476. unsafe { mem::transmute(x) }
  2477. }
  2478. static TEST_CASES: &[((u32, i32), u32)] = &[
  2479. "#
  2480. }
  2481. fn epilogue() -> &'static str {
  2482. "
  2483. ];
  2484. #[test]
  2485. fn powisf2() {
  2486. for &((a, b), c) in TEST_CASES {
  2487. let c_ = __powisf2(mk_f32(a), b);
  2488. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  2489. }
  2490. }
  2491. "
  2492. }
  2493. }
  2494. #[derive(Eq, Hash, PartialEq)]
  2495. pub struct Lshrdi3 {
  2496. a: u64,
  2497. b: u32,
  2498. c: u64,
  2499. }
  2500. impl TestCase for Lshrdi3 {
  2501. fn name() -> &'static str {
  2502. "lshrdi3"
  2503. }
  2504. fn generate<R>(rng: &mut R) -> Option<Self>
  2505. where
  2506. R: Rng,
  2507. Self: Sized,
  2508. {
  2509. let a = gen_u64(rng);
  2510. let b = (rng.gen::<u8>() % 64) as u32;
  2511. let c = a >> b;
  2512. Some(Lshrdi3 { a, b, c })
  2513. }
  2514. fn to_string(&self, buffer: &mut String) {
  2515. writeln!(
  2516. buffer,
  2517. "(({a}, {b}), {c}),",
  2518. a = self.a,
  2519. b = self.b,
  2520. c = self.c
  2521. )
  2522. .unwrap();
  2523. }
  2524. fn prologue() -> &'static str {
  2525. "
  2526. use compiler_builtins::int::shift::__lshrdi3;
  2527. static TEST_CASES: &[((u64, u32), u64)] = &[
  2528. "
  2529. }
  2530. fn epilogue() -> &'static str {
  2531. "
  2532. ];
  2533. #[test]
  2534. fn lshrdi3() {
  2535. for &((a, b), c) in TEST_CASES {
  2536. let c_ = __lshrdi3(a, b);
  2537. assert_eq!(((a, b), c), ((a, b), c_));
  2538. }
  2539. }
  2540. "
  2541. }
  2542. }
  2543. #[derive(Eq, Hash, PartialEq)]
  2544. pub struct Lshrti3 {
  2545. a: u128,
  2546. b: u32,
  2547. c: u128,
  2548. }
  2549. impl TestCase for Lshrti3 {
  2550. fn name() -> &'static str {
  2551. "lshrti3"
  2552. }
  2553. fn generate<R>(rng: &mut R) -> Option<Self>
  2554. where
  2555. R: Rng,
  2556. Self: Sized,
  2557. {
  2558. let a = gen_u128(rng);
  2559. let b = (rng.gen::<u8>() % 128) as u32;
  2560. let c = a >> b;
  2561. Some(Lshrti3 { a, b, c })
  2562. }
  2563. fn to_string(&self, buffer: &mut String) {
  2564. writeln!(
  2565. buffer,
  2566. "(({a}, {b}), {c}),",
  2567. a = self.a,
  2568. b = self.b,
  2569. c = self.c
  2570. )
  2571. .unwrap();
  2572. }
  2573. fn prologue() -> &'static str {
  2574. "
  2575. use compiler_builtins::int::shift::__lshrti3;
  2576. static TEST_CASES: &[((u128, u32), u128)] = &[
  2577. "
  2578. }
  2579. fn epilogue() -> &'static str {
  2580. "
  2581. ];
  2582. #[test]
  2583. fn lshrti3() {
  2584. for &((a, b), c) in TEST_CASES {
  2585. let c_ = __lshrti3(a, b);
  2586. assert_eq!(((a, b), c), ((a, b), c_));
  2587. }
  2588. }
  2589. "
  2590. }
  2591. }
  2592. #[derive(Eq, Hash, PartialEq)]
  2593. pub struct Subdf3 {
  2594. a: u64, // f64
  2595. b: u64, // f64
  2596. c: u64, // f64
  2597. }
  2598. impl TestCase for Subdf3 {
  2599. fn name() -> &'static str {
  2600. "subdf3"
  2601. }
  2602. fn generate<R>(rng: &mut R) -> Option<Self>
  2603. where
  2604. R: Rng,
  2605. Self: Sized,
  2606. {
  2607. let a = gen_f64(rng);
  2608. let b = gen_f64(rng);
  2609. let c = a - b;
  2610. // TODO accept NaNs. We don't do that right now because we can't check
  2611. // for NaN-ness on the thumb targets (due to missing intrinsics)
  2612. if a.is_nan() || b.is_nan() || c.is_nan() {
  2613. return None;
  2614. }
  2615. Some(
  2616. Subdf3 {
  2617. a: to_u64(a),
  2618. b: to_u64(b),
  2619. c: to_u64(c),
  2620. },
  2621. )
  2622. }
  2623. fn to_string(&self, buffer: &mut String) {
  2624. writeln!(
  2625. buffer,
  2626. "(({a}, {b}), {c}),",
  2627. a = self.a,
  2628. b = self.b,
  2629. c = self.c
  2630. )
  2631. .unwrap();
  2632. }
  2633. fn prologue() -> &'static str {
  2634. r#"
  2635. #[cfg(all(target_arch = "arm",
  2636. not(any(target_env = "gnu", target_env = "musl")),
  2637. target_os = "linux",
  2638. test))]
  2639. use core::mem;
  2640. #[cfg(not(all(target_arch = "arm",
  2641. not(any(target_env = "gnu", target_env = "musl")),
  2642. target_os = "linux",
  2643. test)))]
  2644. use std::mem;
  2645. use compiler_builtins::float::sub::__subdf3;
  2646. fn mk_f64(x: u64) -> f64 {
  2647. unsafe { mem::transmute(x) }
  2648. }
  2649. fn to_u64(x: f64) -> u64 {
  2650. unsafe { mem::transmute(x) }
  2651. }
  2652. static TEST_CASES: &[((u64, u64), u64)] = &[
  2653. "#
  2654. }
  2655. fn epilogue() -> &'static str {
  2656. "
  2657. ];
  2658. #[test]
  2659. fn subdf3() {
  2660. for &((a, b), c) in TEST_CASES {
  2661. let c_ = __subdf3(mk_f64(a), mk_f64(b));
  2662. assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
  2663. }
  2664. }
  2665. "
  2666. }
  2667. }
  2668. #[derive(Eq, Hash, PartialEq)]
  2669. pub struct Subsf3 {
  2670. a: u32, // f32
  2671. b: u32, // f32
  2672. c: u32, // f32
  2673. }
  2674. impl TestCase for Subsf3 {
  2675. fn name() -> &'static str {
  2676. "subsf3"
  2677. }
  2678. fn generate<R>(rng: &mut R) -> Option<Self>
  2679. where
  2680. R: Rng,
  2681. Self: Sized,
  2682. {
  2683. let a = gen_f32(rng);
  2684. let b = gen_f32(rng);
  2685. let c = a - b;
  2686. // TODO accept NaNs. We don't do that right now because we can't check
  2687. // for NaN-ness on the thumb targets (due to missing intrinsics)
  2688. if a.is_nan() || b.is_nan() || c.is_nan() {
  2689. return None;
  2690. }
  2691. Some(
  2692. Subsf3 {
  2693. a: to_u32(a),
  2694. b: to_u32(b),
  2695. c: to_u32(c),
  2696. },
  2697. )
  2698. }
  2699. fn to_string(&self, buffer: &mut String) {
  2700. writeln!(
  2701. buffer,
  2702. "(({a}, {b}), {c}),",
  2703. a = self.a,
  2704. b = self.b,
  2705. c = self.c
  2706. )
  2707. .unwrap();
  2708. }
  2709. fn prologue() -> &'static str {
  2710. r#"
  2711. #[cfg(all(target_arch = "arm",
  2712. not(any(target_env = "gnu", target_env = "musl")),
  2713. target_os = "linux",
  2714. test))]
  2715. use core::mem;
  2716. #[cfg(not(all(target_arch = "arm",
  2717. not(any(target_env = "gnu", target_env = "musl")),
  2718. target_os = "linux",
  2719. test)))]
  2720. use std::mem;
  2721. use compiler_builtins::float::sub::__subsf3;
  2722. fn mk_f32(x: u32) -> f32 {
  2723. unsafe { mem::transmute(x) }
  2724. }
  2725. fn to_u32(x: f32) -> u32 {
  2726. unsafe { mem::transmute(x) }
  2727. }
  2728. static TEST_CASES: &[((u32, u32), u32)] = &[
  2729. "#
  2730. }
  2731. fn epilogue() -> &'static str {
  2732. "
  2733. ];
  2734. #[test]
  2735. fn subsf3() {
  2736. for &((a, b), c) in TEST_CASES {
  2737. let c_ = __subsf3(mk_f32(a), mk_f32(b));
  2738. assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
  2739. }
  2740. }
  2741. "
  2742. }
  2743. }
  2744. #[derive(Eq, Hash, PartialEq)]
  2745. pub struct Udivdi3 {
  2746. a: u64,
  2747. b: u64,
  2748. c: u64,
  2749. }
  2750. impl TestCase for Udivdi3 {
  2751. fn name() -> &'static str {
  2752. "udivdi3"
  2753. }
  2754. fn generate<R>(rng: &mut R) -> Option<Self>
  2755. where
  2756. R: Rng,
  2757. Self: Sized,
  2758. {
  2759. let a = gen_u64(rng);
  2760. let b = gen_u64(rng);
  2761. if b == 0 {
  2762. return None;
  2763. }
  2764. let c = a / b;
  2765. Some(Udivdi3 { a, b, c })
  2766. }
  2767. fn to_string(&self, buffer: &mut String) {
  2768. writeln!(
  2769. buffer,
  2770. "(({a}, {b}), {c}),",
  2771. a = self.a,
  2772. b = self.b,
  2773. c = self.c
  2774. )
  2775. .unwrap();
  2776. }
  2777. fn prologue() -> &'static str {
  2778. "
  2779. use compiler_builtins::int::udiv::__udivdi3;
  2780. static TEST_CASES: &[((u64, u64), u64)] = &[
  2781. "
  2782. }
  2783. fn epilogue() -> &'static str {
  2784. "
  2785. ];
  2786. #[test]
  2787. fn udivdi3() {
  2788. for &((a, b), c) in TEST_CASES {
  2789. let c_ = __udivdi3(a, b);
  2790. assert_eq!(((a, b), c), ((a, b), c_));
  2791. }
  2792. }
  2793. "
  2794. }
  2795. }
  2796. #[derive(Eq, Hash, PartialEq)]
  2797. pub struct Udivmoddi4 {
  2798. a: u64,
  2799. b: u64,
  2800. c: u64,
  2801. rem: u64,
  2802. }
  2803. impl TestCase for Udivmoddi4 {
  2804. fn name() -> &'static str {
  2805. "udivmoddi4"
  2806. }
  2807. fn generate<R>(rng: &mut R) -> Option<Self>
  2808. where
  2809. R: Rng,
  2810. Self: Sized,
  2811. {
  2812. let a = gen_u64(rng);
  2813. let b = gen_u64(rng);
  2814. if b == 0 {
  2815. return None;
  2816. }
  2817. let c = a / b;
  2818. let rem = a % b;
  2819. Some(Udivmoddi4 { a, b, c, rem })
  2820. }
  2821. fn to_string(&self, buffer: &mut String) {
  2822. writeln!(
  2823. buffer,
  2824. "(({a}, {b}), ({c}, {rem})),",
  2825. a = self.a,
  2826. b = self.b,
  2827. c = self.c,
  2828. rem = self.rem
  2829. )
  2830. .unwrap();
  2831. }
  2832. fn prologue() -> &'static str {
  2833. "
  2834. use compiler_builtins::int::udiv::__udivmoddi4;
  2835. static TEST_CASES: &[((u64, u64), (u64, u64))] = &[
  2836. "
  2837. }
  2838. fn epilogue() -> &'static str {
  2839. "
  2840. ];
  2841. #[test]
  2842. fn udivmoddi4() {
  2843. for &((a, b), (c, rem)) in TEST_CASES {
  2844. let mut rem_ = 0;
  2845. let c_ = __udivmoddi4(a, b, Some(&mut rem_));
  2846. assert_eq!(((a, b), (c, rem)), ((a, b), (c_, rem_)));
  2847. }
  2848. }
  2849. "
  2850. }
  2851. }
  2852. #[derive(Eq, Hash, PartialEq)]
  2853. pub struct Udivmodsi4 {
  2854. a: u32,
  2855. b: u32,
  2856. c: u32,
  2857. rem: u32,
  2858. }
  2859. impl TestCase for Udivmodsi4 {
  2860. fn name() -> &'static str {
  2861. "udivmodsi4"
  2862. }
  2863. fn generate<R>(rng: &mut R) -> Option<Self>
  2864. where
  2865. R: Rng,
  2866. Self: Sized,
  2867. {
  2868. let a = gen_u32(rng);
  2869. let b = gen_u32(rng);
  2870. if b == 0 {
  2871. return None;
  2872. }
  2873. let c = a / b;
  2874. let rem = a % b;
  2875. Some(Udivmodsi4 { a, b, c, rem })
  2876. }
  2877. fn to_string(&self, buffer: &mut String) {
  2878. writeln!(
  2879. buffer,
  2880. "(({a}, {b}), ({c}, {rem})),",
  2881. a = self.a,
  2882. b = self.b,
  2883. c = self.c,
  2884. rem = self.rem
  2885. )
  2886. .unwrap();
  2887. }
  2888. fn prologue() -> &'static str {
  2889. "
  2890. use compiler_builtins::int::udiv::__udivmodsi4;
  2891. static TEST_CASES: &[((u32, u32), (u32, u32))] = &[
  2892. "
  2893. }
  2894. fn epilogue() -> &'static str {
  2895. "
  2896. ];
  2897. #[test]
  2898. fn udivmodsi4() {
  2899. for &((a, b), (c, rem)) in TEST_CASES {
  2900. let mut rem_ = 0;
  2901. let c_ = __udivmodsi4(a, b, Some(&mut rem_));
  2902. assert_eq!(((a, b), (c, rem)), ((a, b), (c_, rem_)));
  2903. }
  2904. }
  2905. "
  2906. }
  2907. }
  2908. #[derive(Eq, Hash, PartialEq)]
  2909. pub struct Udivmodti4 {
  2910. a: u128,
  2911. b: u128,
  2912. c: u128,
  2913. rem: u128,
  2914. }
  2915. impl TestCase for Udivmodti4 {
  2916. fn name() -> &'static str {
  2917. "udivmodti4"
  2918. }
  2919. fn generate<R>(rng: &mut R) -> Option<Self>
  2920. where
  2921. R: Rng,
  2922. Self: Sized,
  2923. {
  2924. let a = gen_u128(rng);
  2925. let b = gen_u128(rng);
  2926. if b == 0 {
  2927. return None;
  2928. }
  2929. let c = a / b;
  2930. let rem = a % b;
  2931. Some(Udivmodti4 { a, b, c, rem })
  2932. }
  2933. fn to_string(&self, buffer: &mut String) {
  2934. writeln!(
  2935. buffer,
  2936. "(({a}, {b}), ({c}, {rem})),",
  2937. a = self.a,
  2938. b = self.b,
  2939. c = self.c,
  2940. rem = self.rem
  2941. )
  2942. .unwrap();
  2943. }
  2944. fn prologue() -> &'static str {
  2945. "
  2946. use compiler_builtins::int::udiv::__udivmodti4;
  2947. static TEST_CASES: &[((u128, u128), (u128, u128))] = &[
  2948. "
  2949. }
  2950. fn epilogue() -> &'static str {
  2951. "
  2952. ];
  2953. #[test]
  2954. fn udivmodti4() {
  2955. for &((a, b), (c, rem)) in TEST_CASES {
  2956. let mut rem_ = 0;
  2957. let c_ = __udivmodti4(a, b, Some(&mut rem_));
  2958. assert_eq!(((a, b), (c, rem)), ((a, b), (c_, rem_)));
  2959. }
  2960. }
  2961. "
  2962. }
  2963. }
  2964. #[derive(Eq, Hash, PartialEq)]
  2965. pub struct Udivsi3 {
  2966. a: u32,
  2967. b: u32,
  2968. c: u32,
  2969. }
  2970. impl TestCase for Udivsi3 {
  2971. fn name() -> &'static str {
  2972. "udivsi3"
  2973. }
  2974. fn generate<R>(rng: &mut R) -> Option<Self>
  2975. where
  2976. R: Rng,
  2977. Self: Sized,
  2978. {
  2979. let a = gen_u32(rng);
  2980. let b = gen_u32(rng);
  2981. if b == 0 {
  2982. return None;
  2983. }
  2984. let c = a / b;
  2985. Some(Udivsi3 { a, b, c })
  2986. }
  2987. fn to_string(&self, buffer: &mut String) {
  2988. writeln!(
  2989. buffer,
  2990. "(({a}, {b}), {c}),",
  2991. a = self.a,
  2992. b = self.b,
  2993. c = self.c
  2994. )
  2995. .unwrap();
  2996. }
  2997. fn prologue() -> &'static str {
  2998. "
  2999. use compiler_builtins::int::udiv::__udivsi3;
  3000. static TEST_CASES: &[((u32, u32), u32)] = &[
  3001. "
  3002. }
  3003. fn epilogue() -> &'static str {
  3004. "
  3005. ];
  3006. #[test]
  3007. fn udivsi3() {
  3008. for &((a, b), c) in TEST_CASES {
  3009. let c_ = __udivsi3(a, b);
  3010. assert_eq!(((a, b), c), ((a, b), c_));
  3011. }
  3012. }
  3013. "
  3014. }
  3015. }
  3016. #[derive(Eq, Hash, PartialEq)]
  3017. pub struct Udivti3 {
  3018. a: u128,
  3019. b: u128,
  3020. c: u128,
  3021. }
  3022. impl TestCase for Udivti3 {
  3023. fn name() -> &'static str {
  3024. "udivti3"
  3025. }
  3026. fn generate<R>(rng: &mut R) -> Option<Self>
  3027. where
  3028. R: Rng,
  3029. Self: Sized,
  3030. {
  3031. let a = gen_u128(rng);
  3032. let b = gen_u128(rng);
  3033. if b == 0 {
  3034. return None;
  3035. }
  3036. let c = a / b;
  3037. Some(Udivti3 { a, b, c })
  3038. }
  3039. fn to_string(&self, buffer: &mut String) {
  3040. writeln!(
  3041. buffer,
  3042. "(({a}, {b}), {c}),",
  3043. a = self.a,
  3044. b = self.b,
  3045. c = self.c
  3046. )
  3047. .unwrap();
  3048. }
  3049. fn prologue() -> &'static str {
  3050. "
  3051. use compiler_builtins::int::udiv::__udivti3;
  3052. static TEST_CASES: &[((u128, u128), u128)] = &[
  3053. "
  3054. }
  3055. fn epilogue() -> &'static str {
  3056. "
  3057. ];
  3058. #[test]
  3059. fn udivti3() {
  3060. for &((a, b), c) in TEST_CASES {
  3061. let c_ = __udivti3(a, b);
  3062. assert_eq!(((a, b), c), ((a, b), c_));
  3063. }
  3064. }
  3065. "
  3066. }
  3067. }
  3068. #[derive(Eq, Hash, PartialEq)]
  3069. pub struct Umoddi3 {
  3070. a: u64,
  3071. b: u64,
  3072. c: u64,
  3073. }
  3074. impl TestCase for Umoddi3 {
  3075. fn name() -> &'static str {
  3076. "umoddi3"
  3077. }
  3078. fn generate<R>(rng: &mut R) -> Option<Self>
  3079. where
  3080. R: Rng,
  3081. Self: Sized,
  3082. {
  3083. let a = gen_u64(rng);
  3084. let b = gen_u64(rng);
  3085. if b == 0 {
  3086. return None;
  3087. }
  3088. let c = a % b;
  3089. Some(Umoddi3 { a, b, c })
  3090. }
  3091. fn to_string(&self, buffer: &mut String) {
  3092. writeln!(
  3093. buffer,
  3094. "(({a}, {b}), {c}),",
  3095. a = self.a,
  3096. b = self.b,
  3097. c = self.c
  3098. )
  3099. .unwrap();
  3100. }
  3101. fn prologue() -> &'static str {
  3102. "
  3103. use compiler_builtins::int::udiv::__umoddi3;
  3104. static TEST_CASES: &[((u64, u64), u64)] = &[
  3105. "
  3106. }
  3107. fn epilogue() -> &'static str {
  3108. "
  3109. ];
  3110. #[test]
  3111. fn umoddi3() {
  3112. for &((a, b), c) in TEST_CASES {
  3113. let c_ = __umoddi3(a, b);
  3114. assert_eq!(((a, b), c), ((a, b), c_));
  3115. }
  3116. }
  3117. "
  3118. }
  3119. }
  3120. #[derive(Eq, Hash, PartialEq)]
  3121. pub struct Umodsi3 {
  3122. a: u32,
  3123. b: u32,
  3124. c: u32,
  3125. }
  3126. impl TestCase for Umodsi3 {
  3127. fn name() -> &'static str {
  3128. "umodsi3"
  3129. }
  3130. fn generate<R>(rng: &mut R) -> Option<Self>
  3131. where
  3132. R: Rng,
  3133. Self: Sized,
  3134. {
  3135. let a = gen_u32(rng);
  3136. let b = gen_u32(rng);
  3137. if b == 0 {
  3138. return None;
  3139. }
  3140. let c = a % b;
  3141. Some(Umodsi3 { a, b, c })
  3142. }
  3143. fn to_string(&self, buffer: &mut String) {
  3144. writeln!(
  3145. buffer,
  3146. "(({a}, {b}), {c}),",
  3147. a = self.a,
  3148. b = self.b,
  3149. c = self.c
  3150. )
  3151. .unwrap();
  3152. }
  3153. fn prologue() -> &'static str {
  3154. "
  3155. use compiler_builtins::int::udiv::__umodsi3;
  3156. static TEST_CASES: &[((u32, u32), u32)] = &[
  3157. "
  3158. }
  3159. fn epilogue() -> &'static str {
  3160. "
  3161. ];
  3162. #[test]
  3163. fn umodsi3() {
  3164. for &((a, b), c) in TEST_CASES {
  3165. let c_ = __umodsi3(a, b);
  3166. assert_eq!(((a, b), c), ((a, b), c_));
  3167. }
  3168. }
  3169. "
  3170. }
  3171. }
  3172. #[derive(Eq, Hash, PartialEq)]
  3173. pub struct Umodti3 {
  3174. a: u128,
  3175. b: u128,
  3176. c: u128,
  3177. }
  3178. impl TestCase for Umodti3 {
  3179. fn name() -> &'static str {
  3180. "umodti3"
  3181. }
  3182. fn generate<R>(rng: &mut R) -> Option<Self>
  3183. where
  3184. R: Rng,
  3185. Self: Sized,
  3186. {
  3187. let a = gen_u128(rng);
  3188. let b = gen_u128(rng);
  3189. if b == 0 {
  3190. return None;
  3191. }
  3192. let c = a % b;
  3193. Some(Umodti3 { a, b, c })
  3194. }
  3195. fn to_string(&self, buffer: &mut String) {
  3196. writeln!(
  3197. buffer,
  3198. "(({a}, {b}), {c}),",
  3199. a = self.a,
  3200. b = self.b,
  3201. c = self.c
  3202. )
  3203. .unwrap();
  3204. }
  3205. fn prologue() -> &'static str {
  3206. "
  3207. use compiler_builtins::int::udiv::__umodti3;
  3208. static TEST_CASES: &[((u128, u128), u128)] = &[
  3209. "
  3210. }
  3211. fn epilogue() -> &'static str {
  3212. "
  3213. ];
  3214. #[test]
  3215. fn umodti3() {
  3216. for &((a, b), c) in TEST_CASES {
  3217. let c_ = __umodti3(a, b);
  3218. assert_eq!(((a, b), c), ((a, b), c_));
  3219. }
  3220. }
  3221. "
  3222. }
  3223. }
  3224. trait TestCase {
  3225. /// Name of the intrinsic to test
  3226. fn name() -> &'static str;
  3227. /// Generates a valid test case
  3228. fn generate<R>(rng: &mut R) -> Option<Self>
  3229. where
  3230. R: Rng,
  3231. Self: Sized;
  3232. /// Stringifies a test case
  3233. fn to_string(&self, buffer: &mut String);
  3234. /// Prologue of the test file
  3235. fn prologue() -> &'static str;
  3236. /// Epilogue of the test file
  3237. fn epilogue() -> &'static str;
  3238. }
  3239. const PROLOGUE: &'static str = r#"
  3240. extern crate compiler_builtins;
  3241. // test runner
  3242. #[cfg(all(target_arch = "arm",
  3243. not(any(target_env = "gnu", target_env = "musl")),
  3244. target_os = "linux",
  3245. test))]
  3246. extern crate utest_cortex_m_qemu;
  3247. // overrides `panic!`
  3248. #[cfg(all(target_arch = "arm",
  3249. not(any(target_env = "gnu", target_env = "musl")),
  3250. target_os = "linux",
  3251. test))]
  3252. #[macro_use]
  3253. extern crate utest_macros;
  3254. #[cfg(all(target_arch = "arm",
  3255. not(any(target_env = "gnu", target_env = "musl")),
  3256. target_os = "linux",
  3257. test))]
  3258. macro_rules! panic {
  3259. ($($tt:tt)*) => {
  3260. upanic!($($tt)*);
  3261. };
  3262. }
  3263. "#;
  3264. macro_rules! gen_int {
  3265. ($name:ident, $ity:ident, $hty:ident) => {
  3266. fn $name<R>(rng: &mut R) -> $ity
  3267. where
  3268. R: Rng,
  3269. {
  3270. let mut mk = || if rng.gen_weighted_bool(10) {
  3271. *rng.choose(&[::std::$hty::MAX, 0, ::std::$hty::MIN]).unwrap()
  3272. } else {
  3273. rng.gen::<$hty>()
  3274. };
  3275. unsafe { mem::transmute([mk(), mk()]) }
  3276. }
  3277. }
  3278. }
  3279. gen_int!(gen_i32, i32, i16);
  3280. gen_int!(gen_i64, i64, i32);
  3281. gen_int!(gen_i128, i128, i64);
  3282. macro_rules! gen_float {
  3283. ($name:ident,
  3284. $fty:ident,
  3285. $uty:ident,
  3286. $bits:expr,
  3287. $significand_bits:expr) => {
  3288. pub fn $name<R>(rng: &mut R) -> $fty
  3289. where
  3290. R: Rng,
  3291. {
  3292. const BITS: u8 = $bits;
  3293. const SIGNIFICAND_BITS: u8 = $significand_bits;
  3294. const SIGNIFICAND_MASK: $uty = (1 << SIGNIFICAND_BITS) - 1;
  3295. const SIGN_MASK: $uty = (1 << (BITS - 1));
  3296. const EXPONENT_MASK: $uty = !(SIGN_MASK | SIGNIFICAND_MASK);
  3297. fn mk_f32(sign: bool, exponent: $uty, significand: $uty) -> $fty {
  3298. unsafe {
  3299. mem::transmute(((sign as $uty) << (BITS - 1)) |
  3300. ((exponent & EXPONENT_MASK) <<
  3301. SIGNIFICAND_BITS) |
  3302. (significand & SIGNIFICAND_MASK))
  3303. }
  3304. }
  3305. if rng.gen_weighted_bool(10) {
  3306. // Special values
  3307. *rng.choose(&[-0.0,
  3308. 0.0,
  3309. ::std::$fty::NAN,
  3310. ::std::$fty::INFINITY,
  3311. -::std::$fty::INFINITY])
  3312. .unwrap()
  3313. } else if rng.gen_weighted_bool(10) {
  3314. // NaN patterns
  3315. mk_f32(rng.gen(), rng.gen(), 0)
  3316. } else if rng.gen() {
  3317. // Denormalized
  3318. mk_f32(rng.gen(), 0, rng.gen())
  3319. } else {
  3320. // Random anything
  3321. mk_f32(rng.gen(), rng.gen(), rng.gen())
  3322. }
  3323. }
  3324. }
  3325. }
  3326. gen_float!(gen_f32, f32, u32, 32, 23);
  3327. gen_float!(gen_f64, f64, u64, 64, 52);
  3328. pub fn gen_u128<R>(rng: &mut R) -> u128
  3329. where
  3330. R: Rng,
  3331. {
  3332. gen_i128(rng) as u128
  3333. }
  3334. pub fn gen_u32<R>(rng: &mut R) -> u32
  3335. where
  3336. R: Rng,
  3337. {
  3338. gen_i32(rng) as u32
  3339. }
  3340. fn gen_u64<R>(rng: &mut R) -> u64
  3341. where
  3342. R: Rng,
  3343. {
  3344. gen_i64(rng) as u64
  3345. }
  3346. pub fn to_u32(x: f32) -> u32 {
  3347. unsafe { mem::transmute(x) }
  3348. }
  3349. pub fn to_u64(x: f64) -> u64 {
  3350. unsafe { mem::transmute(x) }
  3351. }
  3352. fn mk_tests<T, R>(mut n: usize, rng: &mut R) -> String
  3353. where
  3354. T: Eq + Hash + TestCase,
  3355. R: Rng,
  3356. {
  3357. let mut buffer = PROLOGUE.to_owned();
  3358. buffer.push_str(T::prologue());
  3359. let mut cases = HashSet::new();
  3360. while n != 0 {
  3361. if let Some(case) = T::generate(rng) {
  3362. if cases.contains(&case) {
  3363. continue;
  3364. }
  3365. case.to_string(&mut buffer);
  3366. n -= 1;
  3367. cases.insert(case);
  3368. }
  3369. }
  3370. buffer.push_str(T::epilogue());
  3371. buffer
  3372. }
  3373. fn mk_file<T>()
  3374. where
  3375. T: Eq + Hash + TestCase,
  3376. {
  3377. use std::io::Write;
  3378. let rng = &mut rand::thread_rng();
  3379. let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
  3380. let out_file_name = format!("{}.rs", T::name());
  3381. let out_file = out_dir.join(&out_file_name);
  3382. println!("Generating {}", out_file_name);
  3383. let contents = mk_tests::<T, _>(NTESTS, rng);
  3384. File::create(out_file)
  3385. .unwrap()
  3386. .write_all(contents.as_bytes())
  3387. .unwrap();
  3388. }
  3389. }
  3390. #[cfg(feature = "c")]
  3391. mod c {
  3392. extern crate gcc;
  3393. use std::collections::BTreeMap;
  3394. use std::env;
  3395. use std::path::Path;
  3396. struct Sources {
  3397. // SYMBOL -> PATH TO SOURCE
  3398. map: BTreeMap<&'static str, &'static str>,
  3399. }
  3400. impl Sources {
  3401. fn new() -> Sources {
  3402. Sources { map: BTreeMap::new() }
  3403. }
  3404. fn extend(&mut self, sources: &[&'static str]) {
  3405. // NOTE Some intrinsics have both a generic implementation (e.g.
  3406. // `floatdidf.c`) and an arch optimized implementation
  3407. // (`x86_64/floatdidf.c`). In those cases, we keep the arch optimized
  3408. // implementation and discard the generic implementation. If we don't
  3409. // and keep both implementations, the linker will yell at us about
  3410. // duplicate symbols!
  3411. for &src in sources {
  3412. let symbol = Path::new(src).file_stem().unwrap().to_str().unwrap();
  3413. if src.contains("/") {
  3414. // Arch-optimized implementation (preferred)
  3415. self.map.insert(symbol, src);
  3416. } else {
  3417. // Generic implementation
  3418. if !self.map.contains_key(symbol) {
  3419. self.map.insert(symbol, src);
  3420. }
  3421. }
  3422. }
  3423. }
  3424. fn remove(&mut self, symbols: &[&str]) {
  3425. for symbol in symbols {
  3426. self.map.remove(*symbol).unwrap();
  3427. }
  3428. }
  3429. }
  3430. /// Compile intrinsics from the compiler-rt C source code
  3431. pub fn compile(llvm_target: &[&str]) {
  3432. let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
  3433. let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
  3434. let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
  3435. let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
  3436. let cfg = &mut gcc::Config::new();
  3437. if target_env == "msvc" {
  3438. // Don't pull in extra libraries on MSVC
  3439. cfg.flag("/Zl");
  3440. // Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP
  3441. cfg.define("__func__", Some("__FUNCTION__"));
  3442. } else {
  3443. // Turn off various features of gcc and such, mostly copying
  3444. // compiler-rt's build system already
  3445. cfg.flag("-fno-builtin");
  3446. cfg.flag("-fvisibility=hidden");
  3447. cfg.flag("-fomit-frame-pointer");
  3448. cfg.flag("-ffreestanding");
  3449. cfg.define("VISIBILITY_HIDDEN", None);
  3450. }
  3451. // NOTE Most of the ARM intrinsics are written in assembly. Tell gcc which arch we are going
  3452. // to target to make sure that the assembly implementations really work for the target. If
  3453. // the implementation is not valid for the arch, then gcc will error when compiling it.
  3454. if llvm_target[0].starts_with("thumb") {
  3455. cfg.flag("-mthumb");
  3456. if llvm_target.last() == Some(&"eabihf") {
  3457. cfg.flag("-mfloat-abi=hard");
  3458. }
  3459. }
  3460. if llvm_target[0] == "thumbv6m" {
  3461. cfg.flag("-march=armv6-m");
  3462. }
  3463. if llvm_target[0] == "thumbv7m" {
  3464. cfg.flag("-march=armv7-m");
  3465. }
  3466. if llvm_target[0] == "thumbv7em" {
  3467. cfg.flag("-march=armv7e-m");
  3468. }
  3469. let mut sources = Sources::new();
  3470. sources.extend(
  3471. &[
  3472. "absvdi2.c",
  3473. "absvsi2.c",
  3474. "addvdi3.c",
  3475. "addvsi3.c",
  3476. "apple_versioning.c",
  3477. "clzdi2.c",
  3478. "clzsi2.c",
  3479. "cmpdi2.c",
  3480. "comparedf2.c",
  3481. "comparesf2.c",
  3482. "ctzdi2.c",
  3483. "ctzsi2.c",
  3484. "divdc3.c",
  3485. "divdf3.c",
  3486. "divsc3.c",
  3487. "divsf3.c",
  3488. "divxc3.c",
  3489. "extendsfdf2.c",
  3490. "extendhfsf2.c",
  3491. "ffsdi2.c",
  3492. "fixdfdi.c",
  3493. "fixdfsi.c",
  3494. "fixsfdi.c",
  3495. "fixsfsi.c",
  3496. "fixunsdfdi.c",
  3497. "fixunsdfsi.c",
  3498. "fixunssfdi.c",
  3499. "fixunssfsi.c",
  3500. "fixunsxfdi.c",
  3501. "fixunsxfsi.c",
  3502. "fixxfdi.c",
  3503. "floatdidf.c",
  3504. "floatdisf.c",
  3505. "floatdixf.c",
  3506. "floatsidf.c",
  3507. "floatsisf.c",
  3508. "floatundidf.c",
  3509. "floatundisf.c",
  3510. "floatundixf.c",
  3511. "floatunsidf.c",
  3512. "floatunsisf.c",
  3513. "int_util.c",
  3514. "muldc3.c",
  3515. "muldf3.c",
  3516. "mulsc3.c",
  3517. "mulsf3.c",
  3518. "mulvdi3.c",
  3519. "mulvsi3.c",
  3520. "mulxc3.c",
  3521. "negdf2.c",
  3522. "negdi2.c",
  3523. "negsf2.c",
  3524. "negvdi2.c",
  3525. "negvsi2.c",
  3526. "paritydi2.c",
  3527. "paritysi2.c",
  3528. "popcountdi2.c",
  3529. "popcountsi2.c",
  3530. "powixf2.c",
  3531. "subvdi3.c",
  3532. "subvsi3.c",
  3533. "truncdfhf2.c",
  3534. "truncdfsf2.c",
  3535. "truncsfhf2.c",
  3536. "ucmpdi2.c",
  3537. ],
  3538. );
  3539. if target_os != "ios" {
  3540. sources.extend(
  3541. &[
  3542. "absvti2.c",
  3543. "addvti3.c",
  3544. "clzti2.c",
  3545. "cmpti2.c",
  3546. "ctzti2.c",
  3547. "ffsti2.c",
  3548. "fixdfti.c",
  3549. "fixsfti.c",
  3550. "fixunsdfti.c",
  3551. "fixunssfti.c",
  3552. "fixunsxfti.c",
  3553. "fixxfti.c",
  3554. "floattidf.c",
  3555. "floattisf.c",
  3556. "floattixf.c",
  3557. "floatuntidf.c",
  3558. "floatuntisf.c",
  3559. "floatuntixf.c",
  3560. "mulvti3.c",
  3561. "negti2.c",
  3562. "negvti2.c",
  3563. "parityti2.c",
  3564. "popcountti2.c",
  3565. "subvti3.c",
  3566. "ucmpti2.c",
  3567. ],
  3568. );
  3569. }
  3570. if target_vendor == "apple" {
  3571. sources.extend(
  3572. &[
  3573. "atomic_flag_clear.c",
  3574. "atomic_flag_clear_explicit.c",
  3575. "atomic_flag_test_and_set.c",
  3576. "atomic_flag_test_and_set_explicit.c",
  3577. "atomic_signal_fence.c",
  3578. "atomic_thread_fence.c",
  3579. ],
  3580. );
  3581. }
  3582. if target_env == "msvc" {
  3583. if target_arch == "x86_64" {
  3584. sources.extend(
  3585. &[
  3586. "x86_64/floatdidf.c",
  3587. "x86_64/floatdisf.c",
  3588. "x86_64/floatdixf.c",
  3589. ],
  3590. );
  3591. }
  3592. } else {
  3593. if target_os != "freebsd" && target_os != "netbsd" {
  3594. sources.extend(&["gcc_personality_v0.c"]);
  3595. }
  3596. if target_arch == "x86_64" {
  3597. sources.extend(
  3598. &[
  3599. "x86_64/chkstk.S",
  3600. "x86_64/chkstk2.S",
  3601. "x86_64/floatdidf.c",
  3602. "x86_64/floatdisf.c",
  3603. "x86_64/floatdixf.c",
  3604. "x86_64/floatundidf.S",
  3605. "x86_64/floatundisf.S",
  3606. "x86_64/floatundixf.S",
  3607. ],
  3608. );
  3609. }
  3610. if target_arch == "x86" {
  3611. sources.extend(
  3612. &[
  3613. "i386/ashldi3.S",
  3614. "i386/ashrdi3.S",
  3615. "i386/chkstk.S",
  3616. "i386/chkstk2.S",
  3617. "i386/divdi3.S",
  3618. "i386/floatdidf.S",
  3619. "i386/floatdisf.S",
  3620. "i386/floatdixf.S",
  3621. "i386/floatundidf.S",
  3622. "i386/floatundisf.S",
  3623. "i386/floatundixf.S",
  3624. "i386/lshrdi3.S",
  3625. "i386/moddi3.S",
  3626. "i386/muldi3.S",
  3627. "i386/udivdi3.S",
  3628. "i386/umoddi3.S",
  3629. ],
  3630. );
  3631. }
  3632. }
  3633. if target_arch == "arm" && target_os != "ios" {
  3634. sources.extend(
  3635. &[
  3636. "arm/aeabi_cdcmp.S",
  3637. "arm/aeabi_cdcmpeq_check_nan.c",
  3638. "arm/aeabi_cfcmp.S",
  3639. "arm/aeabi_cfcmpeq_check_nan.c",
  3640. "arm/aeabi_dcmp.S",
  3641. "arm/aeabi_div0.c",
  3642. "arm/aeabi_drsub.c",
  3643. "arm/aeabi_fcmp.S",
  3644. "arm/aeabi_frsub.c",
  3645. "arm/bswapdi2.S",
  3646. "arm/bswapsi2.S",
  3647. "arm/clzdi2.S",
  3648. "arm/clzsi2.S",
  3649. "arm/comparesf2.S",
  3650. "arm/divmodsi4.S",
  3651. "arm/divsi3.S",
  3652. "arm/modsi3.S",
  3653. "arm/switch16.S",
  3654. "arm/switch32.S",
  3655. "arm/switch8.S",
  3656. "arm/switchu8.S",
  3657. "arm/sync_synchronize.S",
  3658. "arm/udivmodsi4.S",
  3659. "arm/udivsi3.S",
  3660. "arm/umodsi3.S",
  3661. ],
  3662. );
  3663. }
  3664. if llvm_target[0] == "armv7" {
  3665. sources.extend(
  3666. &[
  3667. "arm/sync_fetch_and_add_4.S",
  3668. "arm/sync_fetch_and_add_8.S",
  3669. "arm/sync_fetch_and_and_4.S",
  3670. "arm/sync_fetch_and_and_8.S",
  3671. "arm/sync_fetch_and_max_4.S",
  3672. "arm/sync_fetch_and_max_8.S",
  3673. "arm/sync_fetch_and_min_4.S",
  3674. "arm/sync_fetch_and_min_8.S",
  3675. "arm/sync_fetch_and_nand_4.S",
  3676. "arm/sync_fetch_and_nand_8.S",
  3677. "arm/sync_fetch_and_or_4.S",
  3678. "arm/sync_fetch_and_or_8.S",
  3679. "arm/sync_fetch_and_sub_4.S",
  3680. "arm/sync_fetch_and_sub_8.S",
  3681. "arm/sync_fetch_and_umax_4.S",
  3682. "arm/sync_fetch_and_umax_8.S",
  3683. "arm/sync_fetch_and_umin_4.S",
  3684. "arm/sync_fetch_and_umin_8.S",
  3685. "arm/sync_fetch_and_xor_4.S",
  3686. "arm/sync_fetch_and_xor_8.S",
  3687. ],
  3688. );
  3689. }
  3690. if llvm_target.last().unwrap().ends_with("eabihf") {
  3691. if !llvm_target[0].starts_with("thumbv7em") {
  3692. sources.extend(
  3693. &[
  3694. "arm/adddf3vfp.S",
  3695. "arm/addsf3vfp.S",
  3696. "arm/divdf3vfp.S",
  3697. "arm/divsf3vfp.S",
  3698. "arm/eqdf2vfp.S",
  3699. "arm/eqsf2vfp.S",
  3700. "arm/extendsfdf2vfp.S",
  3701. "arm/fixdfsivfp.S",
  3702. "arm/fixsfsivfp.S",
  3703. "arm/fixunsdfsivfp.S",
  3704. "arm/fixunssfsivfp.S",
  3705. "arm/floatsidfvfp.S",
  3706. "arm/floatsisfvfp.S",
  3707. "arm/floatunssidfvfp.S",
  3708. "arm/floatunssisfvfp.S",
  3709. "arm/gedf2vfp.S",
  3710. "arm/gesf2vfp.S",
  3711. "arm/gtdf2vfp.S",
  3712. "arm/gtsf2vfp.S",
  3713. "arm/ledf2vfp.S",
  3714. "arm/lesf2vfp.S",
  3715. "arm/ltdf2vfp.S",
  3716. "arm/ltsf2vfp.S",
  3717. "arm/muldf3vfp.S",
  3718. "arm/mulsf3vfp.S",
  3719. "arm/nedf2vfp.S",
  3720. "arm/nesf2vfp.S",
  3721. "arm/restore_vfp_d8_d15_regs.S",
  3722. "arm/save_vfp_d8_d15_regs.S",
  3723. "arm/subdf3vfp.S",
  3724. "arm/subsf3vfp.S",
  3725. ],
  3726. );
  3727. }
  3728. sources.extend(&["arm/negdf2vfp.S", "arm/negsf2vfp.S"]);
  3729. }
  3730. if target_arch == "aarch64" {
  3731. sources.extend(
  3732. &[
  3733. "comparetf2.c",
  3734. "extenddftf2.c",
  3735. "extendsftf2.c",
  3736. "fixtfdi.c",
  3737. "fixtfsi.c",
  3738. "fixtfti.c",
  3739. "fixunstfdi.c",
  3740. "fixunstfsi.c",
  3741. "fixunstfti.c",
  3742. "floatditf.c",
  3743. "floatsitf.c",
  3744. "floatunditf.c",
  3745. "floatunsitf.c",
  3746. "multc3.c",
  3747. "trunctfdf2.c",
  3748. "trunctfsf2.c",
  3749. ],
  3750. );
  3751. }
  3752. // Remove the assembly implementations that won't compile for the target
  3753. if llvm_target[0] == "thumbv6m" {
  3754. sources.remove(
  3755. &[
  3756. "aeabi_cdcmp",
  3757. "aeabi_cfcmp",
  3758. "aeabi_dcmp",
  3759. "aeabi_fcmp",
  3760. "clzdi2",
  3761. "clzsi2",
  3762. "comparesf2",
  3763. "divmodsi4",
  3764. "divsi3",
  3765. "modsi3",
  3766. "switch16",
  3767. "switch32",
  3768. "switch8",
  3769. "switchu8",
  3770. "udivmodsi4",
  3771. "udivsi3",
  3772. "umodsi3",
  3773. ],
  3774. );
  3775. // But use some generic implementations where possible
  3776. sources.extend(&["clzdi2.c", "clzsi2.c"])
  3777. }
  3778. if llvm_target[0] == "thumbv7m" || llvm_target[0] == "thumbv7em" {
  3779. sources.remove(&["aeabi_cdcmp", "aeabi_cfcmp"]);
  3780. }
  3781. let root = if env::var_os("CARGO_FEATURE_RUSTBUILD").is_some() {
  3782. Path::new("../../libcompiler_builtins")
  3783. } else {
  3784. Path::new(".")
  3785. };
  3786. let src_dir = root.join("compiler-rt/lib/builtins");
  3787. for src in sources.map.values() {
  3788. let src = src_dir.join(src);
  3789. cfg.file(&src);
  3790. println!("cargo:rerun-if-changed={}", src.display());
  3791. }
  3792. cfg.compile("libcompiler-rt.a");
  3793. }
  3794. }