build.rs 110 KB

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