build.rs 100 KB

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