build.rs 93 KB

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