build.rs 89 KB

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