build.rs 90 KB

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