build.rs 88 KB

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