build.rs 99 KB

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