build.rs 99 KB

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