musl-git.patch 241 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837
  1. diff -Nur musl-0.9.13/.gitignore musl-git/.gitignore
  2. --- musl-0.9.13/.gitignore 1970-01-01 01:00:00.000000000 +0100
  3. +++ musl-git/.gitignore 2013-09-16 20:31:39.000000000 +0200
  4. @@ -0,0 +1,10 @@
  5. +*.o
  6. +*.lo
  7. +*.a
  8. +*.so
  9. +*.so.1
  10. +arch/*/bits/alltypes.h
  11. +config.mak
  12. +include/bits
  13. +tools/musl-gcc
  14. +lib/musl-gcc.specs
  15. diff -Nur musl-0.9.13/Makefile musl-git/Makefile
  16. --- musl-0.9.13/Makefile 2013-08-30 23:30:53.000000000 +0200
  17. +++ musl-git/Makefile 2013-09-16 20:31:39.000000000 +0200
  18. @@ -157,7 +157,7 @@
  19. $(INSTALL) -D -m 644 $< $@
  20. $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
  21. - $(INSTALL) -D -l $< $@ || true
  22. + $(INSTALL) -D -l $(libdir)/libc.so $@ || true
  23. install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
  24. diff -Nur musl-0.9.13/arch/microblaze/bits/limits.h musl-git/arch/microblaze/bits/limits.h
  25. --- musl-0.9.13/arch/microblaze/bits/limits.h 2013-08-30 23:30:53.000000000 +0200
  26. +++ musl-git/arch/microblaze/bits/limits.h 2013-09-16 20:31:39.000000000 +0200
  27. @@ -1,6 +1,5 @@
  28. #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  29. || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  30. -#define PAGE_SIZE 4096
  31. #define LONG_BIT 32
  32. #endif
  33. diff -Nur musl-0.9.13/arch/microblaze/reloc.h musl-git/arch/microblaze/reloc.h
  34. --- musl-0.9.13/arch/microblaze/reloc.h 2013-08-30 23:30:53.000000000 +0200
  35. +++ musl-git/arch/microblaze/reloc.h 2013-09-16 20:31:39.000000000 +0200
  36. @@ -49,7 +49,7 @@
  37. for (a+=c+1; *a; a++);
  38. for (a++; *a; a+=2) if (*a<20) t[*a] = a[1];
  39. base = (char *)t[AT_BASE];
  40. - if (!base) base = (char *)(t[AT_PHDR] & -4096);
  41. + if (!base) base = (char *)(t[AT_PHDR] & -t[AT_PAGESZ]);
  42. for (a=dynv; *a; a+=2) if (*a<20) t[*a] = a[1];
  43. n = t[DT_RELASZ];
  44. for (a=(void *)(base+t[DT_RELA]); n; a+=3, n-=12)
  45. diff -Nur musl-0.9.13/arch/mips/bits/limits.h musl-git/arch/mips/bits/limits.h
  46. --- musl-0.9.13/arch/mips/bits/limits.h 2013-08-30 23:30:53.000000000 +0200
  47. +++ musl-git/arch/mips/bits/limits.h 2013-09-16 20:31:39.000000000 +0200
  48. @@ -1,6 +1,5 @@
  49. #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  50. || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  51. -#define PAGE_SIZE 4096
  52. #define LONG_BIT 32
  53. #endif
  54. diff -Nur musl-0.9.13/arch/mips/bits/msg.h musl-git/arch/mips/bits/msg.h
  55. --- musl-0.9.13/arch/mips/bits/msg.h 2013-08-30 23:30:53.000000000 +0200
  56. +++ musl-git/arch/mips/bits/msg.h 2013-09-16 20:31:39.000000000 +0200
  57. @@ -1,12 +1,21 @@
  58. struct msqid_ds
  59. {
  60. struct ipc_perm msg_perm;
  61. +#if _MIPSEL || __MIPSEL || __MIPSEL__
  62. time_t msg_stime;
  63. int __unused1;
  64. time_t msg_rtime;
  65. int __unused2;
  66. time_t msg_ctime;
  67. int __unused3;
  68. +#else
  69. + int __unused1;
  70. + time_t msg_stime;
  71. + int __unused2;
  72. + time_t msg_rtime;
  73. + int __unused3;
  74. + time_t msg_ctime;
  75. +#endif
  76. unsigned long msg_cbytes;
  77. msgqnum_t msg_qnum;
  78. msglen_t msg_qbytes;
  79. diff -Nur musl-0.9.13/arch/mips/bits/shm.h musl-git/arch/mips/bits/shm.h
  80. --- musl-0.9.13/arch/mips/bits/shm.h 2013-08-30 23:30:53.000000000 +0200
  81. +++ musl-git/arch/mips/bits/shm.h 2013-09-16 20:31:39.000000000 +0200
  82. @@ -5,11 +5,8 @@
  83. struct ipc_perm shm_perm;
  84. size_t shm_segsz;
  85. time_t shm_atime;
  86. - int __unused1;
  87. time_t shm_dtime;
  88. - int __unused2;
  89. time_t shm_ctime;
  90. - int __unused3;
  91. pid_t shm_cpid;
  92. pid_t shm_lpid;
  93. unsigned long shm_nattch;
  94. diff -Nur musl-0.9.13/arch/mips/reloc.h musl-git/arch/mips/reloc.h
  95. --- musl-0.9.13/arch/mips/reloc.h 2013-08-30 23:30:53.000000000 +0200
  96. +++ musl-git/arch/mips/reloc.h 2013-09-16 20:31:39.000000000 +0200
  97. @@ -51,7 +51,7 @@
  98. for (a+=c+1; *a; a++);
  99. for (a++; *a; a+=2) if (*a<20) t[*a] = a[1];
  100. base = (char *)t[AT_BASE];
  101. - if (!base) base = (char *)(t[AT_PHDR] & -4096);
  102. + if (!base) base = (char *)(t[AT_PHDR] & -t[AT_PAGESZ]);
  103. for (a=dynv; *a; a+=2) if (*a-0x70000000UL<20) t[*a&31] = a[1];
  104. n = t[DT_MIPS_LOCAL_GOTNO - 0x70000000];
  105. for (a=got; n; a++, n--) *a += (size_t)base;
  106. diff -Nur musl-0.9.13/arch/powerpc/bits/limits.h musl-git/arch/powerpc/bits/limits.h
  107. --- musl-0.9.13/arch/powerpc/bits/limits.h 2013-08-30 23:30:53.000000000 +0200
  108. +++ musl-git/arch/powerpc/bits/limits.h 2013-09-16 20:31:39.000000000 +0200
  109. @@ -1,6 +1,5 @@
  110. #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  111. || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  112. -#define PAGE_SIZE 4096
  113. #define LONG_BIT 32
  114. #endif
  115. diff -Nur musl-0.9.13/arch/powerpc/reloc.h musl-git/arch/powerpc/reloc.h
  116. --- musl-0.9.13/arch/powerpc/reloc.h 2013-08-30 23:30:53.000000000 +0200
  117. +++ musl-git/arch/powerpc/reloc.h 2013-09-16 20:31:39.000000000 +0200
  118. @@ -46,7 +46,7 @@
  119. for (a+=c+1; *a; a++);
  120. for (a++; *a; a+=2) if (*a<20) t[*a] = a[1];
  121. base = (char *)t[AT_BASE];
  122. - if (!base) base = (char *)(t[AT_PHDR] & -4096);
  123. + if (!base) base = (char *)(t[AT_PHDR] & -t[AT_PAGESZ]);
  124. for (a=dynv; *a; a+=2) if (*a<20) t[*a] = a[1];
  125. n = t[DT_RELASZ];
  126. for (a=(void *)(base+t[DT_RELA]); n; a+=3, n-=12)
  127. diff -Nur musl-0.9.13/include/elf.h musl-git/include/elf.h
  128. --- musl-0.9.13/include/elf.h 2013-08-30 23:30:53.000000000 +0200
  129. +++ musl-git/include/elf.h 2013-09-16 20:31:39.000000000 +0200
  130. @@ -105,6 +105,7 @@
  131. #define ELFOSABI_HPUX 1
  132. #define ELFOSABI_NETBSD 2
  133. #define ELFOSABI_LINUX 3
  134. +#define ELFOSABI_GNU 3
  135. #define ELFOSABI_SOLARIS 6
  136. #define ELFOSABI_AIX 7
  137. #define ELFOSABI_IRIX 8
  138. @@ -211,7 +212,11 @@
  139. #define EM_OPENRISC 92
  140. #define EM_ARC_A5 93
  141. #define EM_XTENSA 94
  142. -#define EM_NUM 95
  143. +#define EM_AARCH64 183
  144. +#define EM_TILEPRO 188
  145. +#define EM_MICROBLAZE 189
  146. +#define EM_TILEGX 191
  147. +#define EM_NUM 192
  148. #define EM_ALPHA 0x9026
  149. #define EV_NONE 0
  150. @@ -487,6 +492,8 @@
  151. #define PT_HIPROC 0x7fffffff
  152. +#define PN_XNUM 0xffff
  153. +
  154. #define PF_X (1 << 0)
  155. #define PF_W (1 << 1)
  156. @@ -512,12 +519,31 @@
  157. #define NT_LWPSTATUS 16
  158. #define NT_LWPSINFO 17
  159. #define NT_PRFPXREG 20
  160. +#define NT_SIGINFO 0x53494749
  161. +#define NT_FILE 0x46494c45
  162. #define NT_PRXFPREG 0x46e62b7f
  163. #define NT_PPC_VMX 0x100
  164. #define NT_PPC_SPE 0x101
  165. #define NT_PPC_VSX 0x102
  166. #define NT_386_TLS 0x200
  167. #define NT_386_IOPERM 0x201
  168. +#define NT_X86_XSTATE 0x202
  169. +#define NT_S390_HIGH_GPRS 0x300
  170. +#define NT_S390_TIMER 0x301
  171. +#define NT_S390_TODCMP 0x302
  172. +#define NT_S390_TODPREG 0x303
  173. +#define NT_S390_CTRS 0x304
  174. +#define NT_S390_PREFIX 0x305
  175. +#define NT_S390_LAST_BREAK 0x306
  176. +#define NT_S390_SYSTEM_CALL 0x307
  177. +#define NT_S390_TDB 0x308
  178. +#define NT_ARM_VFP 0x400
  179. +#define NT_ARM_TLS 0x401
  180. +#define NT_ARM_HW_BREAK 0x402
  181. +#define NT_ARM_HW_WATCH 0x403
  182. +#define NT_METAG_CBUF 0x500
  183. +#define NT_METAG_RPIPE 0x501
  184. +#define NT_METAG_TLS 0x502
  185. #define NT_VERSION 1
  186. @@ -666,7 +692,15 @@
  187. #define DF_1_ENDFILTEE 0x00004000
  188. #define DF_1_DISPRELDNE 0x00008000
  189. #define DF_1_DISPRELPND 0x00010000
  190. -
  191. +#define DF_1_NODIRECT 0x00020000
  192. +#define DF_1_IGNMULDEF 0x00040000
  193. +#define DF_1_NOKSYMS 0x00080000
  194. +#define DF_1_NOHDR 0x00100000
  195. +#define DF_1_EDITED 0x00200000
  196. +#define DF_1_NORELOC 0x00400000
  197. +#define DF_1_SYMINTPOSE 0x00800000
  198. +#define DF_1_GLOBAUDIT 0x01000000
  199. +#define DF_1_SINGLETON 0x02000000
  200. #define DTF_1_PARINIT 0x00000001
  201. #define DTF_1_CONFEXP 0x00000002
  202. @@ -832,6 +866,8 @@
  203. #define AT_RANDOM 25
  204. +#define AT_HWCAP2 26
  205. +
  206. #define AT_EXECFN 31
  207. @@ -979,6 +1015,7 @@
  208. #define R_386_TLS_DTPMOD32 35
  209. #define R_386_TLS_DTPOFF32 36
  210. #define R_386_TLS_TPOFF32 37
  211. +#define R_386_SIZE32 38
  212. #define R_386_TLS_GOTDESC 39
  213. #define R_386_TLS_DESC_CALL 40
  214. #define R_386_TLS_DESC 41
  215. @@ -1109,20 +1146,6 @@
  216. #define DT_SPARC_NUM 2
  217. -
  218. -#define HWCAP_SPARC_FLUSH 1
  219. -#define HWCAP_SPARC_STBAR 2
  220. -#define HWCAP_SPARC_SWAP 4
  221. -#define HWCAP_SPARC_MULDIV 8
  222. -#define HWCAP_SPARC_V9 16
  223. -#define HWCAP_SPARC_ULTRA3 32
  224. -#define HWCAP_SPARC_BLKINIT 64
  225. -#define HWCAP_SPARC_N2 128
  226. -
  227. -
  228. -
  229. -
  230. -
  231. #define EF_MIPS_NOREORDER 1
  232. #define EF_MIPS_PIC 2
  233. #define EF_MIPS_CPIC 4
  234. @@ -1139,9 +1162,10 @@
  235. #define EF_MIPS_ARCH_3 0x20000000
  236. #define EF_MIPS_ARCH_4 0x30000000
  237. #define EF_MIPS_ARCH_5 0x40000000
  238. -#define EF_MIPS_ARCH_32 0x60000000
  239. -#define EF_MIPS_ARCH_64 0x70000000
  240. -
  241. +#define EF_MIPS_ARCH_32 0x50000000
  242. +#define EF_MIPS_ARCH_64 0x60000000
  243. +#define EF_MIPS_ARCH_32R2 0x70000000
  244. +#define EF_MIPS_ARCH_64R2 0x80000000
  245. #define E_MIPS_ARCH_1 0x00000000
  246. @@ -1149,8 +1173,8 @@
  247. #define E_MIPS_ARCH_3 0x20000000
  248. #define E_MIPS_ARCH_4 0x30000000
  249. #define E_MIPS_ARCH_5 0x40000000
  250. -#define E_MIPS_ARCH_32 0x60000000
  251. -#define E_MIPS_ARCH_64 0x70000000
  252. +#define E_MIPS_ARCH_32 0x50000000
  253. +#define E_MIPS_ARCH_64 0x60000000
  254. @@ -2020,7 +2044,8 @@
  255. #define EF_ARM_VFP_FLOAT 0x400
  256. #define EF_ARM_MAVERICK_FLOAT 0x800
  257. -
  258. +#define EF_ARM_ABI_FLOAT_SOFT 0x200
  259. +#define EF_ARM_ABI_FLOAT_HARD 0x400
  260. #define EF_ARM_SYMSARESORTED 0x04
  261. @@ -2064,6 +2089,17 @@
  262. #define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3)
  263. +#define R_AARCH64_NONE 0
  264. +#define R_AARCH64_ABS64 257
  265. +#define R_AARCH64_ABS32 258
  266. +#define R_AARCH64_COPY 1024
  267. +#define R_AARCH64_GLOB_DAT 1025
  268. +#define R_AARCH64_JUMP_SLOT 1026
  269. +#define R_AARCH64_RELATIVE 1027
  270. +#define R_AARCH64_TLS_DTPMOD64 1028
  271. +#define R_AARCH64_TLS_DTPREL64 1029
  272. +#define R_AARCH64_TLS_TPREL64 1030
  273. +#define R_AARCH64_TLSDESC 1031
  274. #define R_ARM_NONE 0
  275. @@ -2079,7 +2115,7 @@
  276. #define R_ARM_THM_PC22 10
  277. #define R_ARM_THM_PC8 11
  278. #define R_ARM_AMP_VCALL9 12
  279. -#define R_ARM_SWI24 13
  280. +#define R_ARM_TLS_DESC 13
  281. #define R_ARM_THM_SWI8 14
  282. #define R_ARM_XPC25 15
  283. #define R_ARM_THM_XPC22 16
  284. @@ -2094,12 +2130,78 @@
  285. #define R_ARM_GOTPC 25
  286. #define R_ARM_GOT32 26
  287. #define R_ARM_PLT32 27
  288. +#define R_ARM_CALL 28
  289. +#define R_ARM_JUMP24 29
  290. +#define R_ARM_THM_JUMP24 30
  291. +#define R_ARM_BASE_ABS 31
  292. #define R_ARM_ALU_PCREL_7_0 32
  293. #define R_ARM_ALU_PCREL_15_8 33
  294. #define R_ARM_ALU_PCREL_23_15 34
  295. #define R_ARM_LDR_SBREL_11_0 35
  296. #define R_ARM_ALU_SBREL_19_12 36
  297. #define R_ARM_ALU_SBREL_27_20 37
  298. +#define R_ARM_TARGET1 38
  299. +#define R_ARM_SBREL31 39
  300. +#define R_ARM_V4BX 40
  301. +#define R_ARM_TARGET2 41
  302. +#define R_ARM_PREL31 42
  303. +#define R_ARM_MOVW_ABS_NC 43
  304. +#define R_ARM_MOVT_ABS 44
  305. +#define R_ARM_MOVW_PREL_NC 45
  306. +#define R_ARM_MOVT_PREL 46
  307. +#define R_ARM_THM_MOVW_ABS_NC 47
  308. +#define R_ARM_THM_MOVT_ABS 48
  309. +#define R_ARM_THM_MOVW_PREL_NC 49
  310. +#define R_ARM_THM_MOVT_PREL 50
  311. +#define R_ARM_THM_JUMP19 51
  312. +#define R_ARM_THM_JUMP6 52
  313. +#define R_ARM_THM_ALU_PREL_11_0 53
  314. +#define R_ARM_THM_PC12 54
  315. +#define R_ARM_ABS32_NOI 55
  316. +#define R_ARM_REL32_NOI 56
  317. +#define R_ARM_ALU_PC_G0_NC 57
  318. +#define R_ARM_ALU_PC_G0 58
  319. +#define R_ARM_ALU_PC_G1_NC 59
  320. +#define R_ARM_ALU_PC_G1 60
  321. +#define R_ARM_ALU_PC_G2 61
  322. +#define R_ARM_LDR_PC_G1 62
  323. +#define R_ARM_LDR_PC_G2 63
  324. +#define R_ARM_LDRS_PC_G0 64
  325. +#define R_ARM_LDRS_PC_G1 65
  326. +#define R_ARM_LDRS_PC_G2 66
  327. +#define R_ARM_LDC_PC_G0 67
  328. +#define R_ARM_LDC_PC_G1 68
  329. +#define R_ARM_LDC_PC_G2 69
  330. +#define R_ARM_ALU_SB_G0_NC 70
  331. +#define R_ARM_ALU_SB_G0 71
  332. +#define R_ARM_ALU_SB_G1_NC 72
  333. +#define R_ARM_ALU_SB_G1 73
  334. +#define R_ARM_ALU_SB_G2 74
  335. +#define R_ARM_LDR_SB_G0 75
  336. +#define R_ARM_LDR_SB_G1 76
  337. +#define R_ARM_LDR_SB_G2 77
  338. +#define R_ARM_LDRS_SB_G0 78
  339. +#define R_ARM_LDRS_SB_G1 79
  340. +#define R_ARM_LDRS_SB_G2 80
  341. +#define R_ARM_LDC_SB_G0 81
  342. +#define R_ARM_LDC_SB_G1 82
  343. +#define R_ARM_LDC_SB_G2 83
  344. +#define R_ARM_MOVW_BREL_NC 84
  345. +#define R_ARM_MOVT_BREL 85
  346. +#define R_ARM_MOVW_BREL 86
  347. +#define R_ARM_THM_MOVW_BREL_NC 87
  348. +#define R_ARM_THM_MOVT_BREL 88
  349. +#define R_ARM_THM_MOVW_BREL 89
  350. +#define R_ARM_TLS_GOTDESC 90
  351. +#define R_ARM_TLS_CALL 91
  352. +#define R_ARM_TLS_DESCSEQ 92
  353. +#define R_ARM_THM_TLS_CALL 93
  354. +#define R_ARM_PLT32_ABS 94
  355. +#define R_ARM_GOT_ABS 95
  356. +#define R_ARM_GOT_PREL 96
  357. +#define R_ARM_GOT_BREL12 97
  358. +#define R_ARM_GOTOFF12 98
  359. +#define R_ARM_GOTRELAX 99
  360. #define R_ARM_GNU_VTENTRY 100
  361. #define R_ARM_GNU_VTINHERIT 101
  362. #define R_ARM_THM_PC11 102
  363. @@ -2113,7 +2215,15 @@
  364. #define R_ARM_TLS_IE32 107
  365. #define R_ARM_TLS_LE32 108
  366. -
  367. +#define R_ARM_TLS_LDO12 109
  368. +#define R_ARM_TLS_LE12 110
  369. +#define R_ARM_TLS_IE12GP 111
  370. +#define R_ARM_ME_TOO 128
  371. +#define R_ARM_THM_TLS_DESCSEQ 129
  372. +#define R_ARM_THM_TLS_DESCSEQ16 129
  373. +#define R_ARM_THM_TLS_DESCSEQ32 130
  374. +#define R_ARM_THM_GOT_BREL12 131
  375. +#define R_ARM_IRELATIVE 160
  376. #define R_ARM_RXPC25 249
  377. #define R_ARM_RSBREL32 250
  378. #define R_ARM_THM_RPC22 251
  379. @@ -2421,15 +2531,21 @@
  380. #define R_X86_64_PC64 24
  381. #define R_X86_64_GOTOFF64 25
  382. #define R_X86_64_GOTPC32 26
  383. -
  384. +#define R_X86_64_GOT64 27
  385. +#define R_X86_64_GOTPCREL64 28
  386. +#define R_X86_64_GOTPC64 29
  387. +#define R_X86_64_GOTPLT64 30
  388. +#define R_X86_64_PLTOFF64 31
  389. +#define R_X86_64_SIZE32 32
  390. +#define R_X86_64_SIZE64 33
  391. #define R_X86_64_GOTPC32_TLSDESC 34
  392. #define R_X86_64_TLSDESC_CALL 35
  393. #define R_X86_64_TLSDESC 36
  394. #define R_X86_64_IRELATIVE 37
  395. -
  396. -#define R_X86_64_NUM 38
  397. +#define R_X86_64_RELATIVE64 38
  398. +#define R_X86_64_NUM 39
  399. diff -Nur musl-0.9.13/include/limits.h musl-git/include/limits.h
  400. --- musl-0.9.13/include/limits.h 2013-08-30 23:30:53.000000000 +0200
  401. +++ musl-git/include/limits.h 2013-09-16 20:31:39.000000000 +0200
  402. @@ -40,7 +40,9 @@
  403. || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  404. #define PIPE_BUF 4096
  405. +#ifdef PAGE_SIZE
  406. #define PAGESIZE PAGE_SIZE
  407. +#endif
  408. #define FILESIZEBITS 64
  409. #define NAME_MAX 255
  410. #define SYMLINK_MAX 255
  411. diff -Nur musl-0.9.13/include/net/if_arp.h musl-git/include/net/if_arp.h
  412. --- musl-0.9.13/include/net/if_arp.h 2013-08-30 23:30:53.000000000 +0200
  413. +++ musl-git/include/net/if_arp.h 2013-09-16 20:31:39.000000000 +0200
  414. @@ -52,6 +52,7 @@
  415. #define ARPHRD_ROSE 270
  416. #define ARPHRD_X25 271
  417. #define ARPHRD_HWX25 272
  418. +#define ARPHRD_CAN 280
  419. #define ARPHRD_PPP 512
  420. #define ARPHRD_CISCO 513
  421. #define ARPHRD_HDLC ARPHRD_CISCO
  422. @@ -84,7 +85,12 @@
  423. #define ARPHRD_IEEE80211_PRISM 802
  424. #define ARPHRD_IEEE80211_RADIOTAP 803
  425. #define ARPHRD_IEEE802154 804
  426. -#define ARPHRD_IEEE802154_PHY 805
  427. +#define ARPHRD_IEEE802154_MONITOR 805
  428. +#define ARPHRD_PHONET 820
  429. +#define ARPHRD_PHONET_PIPE 821
  430. +#define ARPHRD_CAIF 822
  431. +#define ARPHRD_IP6GRE 823
  432. +#define ARPHRD_NETLINK 824
  433. #define ARPHRD_VOID 0xFFFF
  434. #define ARPHRD_NONE 0xFFFE
  435. diff -Nur musl-0.9.13/include/netinet/in.h musl-git/include/netinet/in.h
  436. --- musl-0.9.13/include/netinet/in.h 2013-08-30 23:30:53.000000000 +0200
  437. +++ musl-git/include/netinet/in.h 2013-09-16 20:31:39.000000000 +0200
  438. @@ -91,10 +91,12 @@
  439. #define IPPROTO_NONE 59
  440. #define IPPROTO_DSTOPTS 60
  441. #define IPPROTO_MTP 92
  442. +#define IPPROTO_BEETPH 94
  443. #define IPPROTO_ENCAP 98
  444. #define IPPROTO_PIM 103
  445. #define IPPROTO_COMP 108
  446. #define IPPROTO_SCTP 132
  447. +#define IPPROTO_MH 135
  448. #define IPPROTO_UDPLITE 136
  449. #define IPPROTO_RAW 255
  450. #define IPPROTO_MAX 256
  451. diff -Nur musl-0.9.13/include/sys/ptrace.h musl-git/include/sys/ptrace.h
  452. --- musl-0.9.13/include/sys/ptrace.h 2013-08-30 23:30:53.000000000 +0200
  453. +++ musl-git/include/sys/ptrace.h 2013-09-16 20:31:39.000000000 +0200
  454. @@ -37,6 +37,8 @@
  455. #define PTRACE_INTERRUPT 0x4207
  456. #define PTRACE_LISTEN 0x4208
  457. #define PTRACE_PEEKSIGINFO 0x4209
  458. +#define PTRACE_GETSIGMASK 0x420a
  459. +#define PTRACE_SETSIGMASK 0x420b
  460. #define PT_READ_I PTRACE_PEEKTEXT
  461. #define PT_READ_D PTRACE_PEEKDATA
  462. diff -Nur musl-0.9.13/include/sys/resource.h musl-git/include/sys/resource.h
  463. --- musl-0.9.13/include/sys/resource.h 2013-08-30 23:30:53.000000000 +0200
  464. +++ musl-git/include/sys/resource.h 2013-09-16 20:31:39.000000000 +0200
  465. @@ -59,6 +59,9 @@
  466. #define prlimit64 prlimit
  467. #endif
  468. +#define PRIO_MIN (-20)
  469. +#define PRIO_MAX 20
  470. +
  471. #define PRIO_PROCESS 0
  472. #define PRIO_PGRP 1
  473. #define PRIO_USER 2
  474. diff -Nur musl-0.9.13/include/sys/socket.h musl-git/include/sys/socket.h
  475. --- musl-0.9.13/include/sys/socket.h 2013-08-30 23:30:53.000000000 +0200
  476. +++ musl-git/include/sys/socket.h 2013-09-16 20:31:39.000000000 +0200
  477. @@ -199,6 +199,7 @@
  478. #define SO_NOFCS 43
  479. #define SO_LOCK_FILTER 44
  480. #define SO_SELECT_ERR_QUEUE 45
  481. +#define SO_BUSY_POLL 46
  482. #ifndef SOL_SOCKET
  483. #define SOL_SOCKET 1
  484. diff -Nur musl-0.9.13/include/wait.h musl-git/include/wait.h
  485. --- musl-0.9.13/include/wait.h 1970-01-01 01:00:00.000000000 +0100
  486. +++ musl-git/include/wait.h 2013-09-16 20:31:39.000000000 +0200
  487. @@ -0,0 +1,2 @@
  488. +#warning redirecting incorrect #include <wait.h> to <sys/wait.h>
  489. +#include <sys/wait.h>
  490. diff -Nur musl-0.9.13/src/aio/aio_readwrite.c musl-git/src/aio/aio_readwrite.c
  491. --- musl-0.9.13/src/aio/aio_readwrite.c 2013-08-30 23:30:53.000000000 +0200
  492. +++ musl-git/src/aio/aio_readwrite.c 2013-09-16 20:31:39.000000000 +0200
  493. @@ -2,8 +2,8 @@
  494. #include <fcntl.h>
  495. #include <errno.h>
  496. #include <unistd.h>
  497. -#include <limits.h>
  498. #include "pthread_impl.h"
  499. +#include "libc.h"
  500. static void dummy(void)
  501. {
  502. diff -Nur musl-0.9.13/src/aio/lio_listio.c musl-git/src/aio/lio_listio.c
  503. --- musl-0.9.13/src/aio/lio_listio.c 2013-08-30 23:30:53.000000000 +0200
  504. +++ musl-git/src/aio/lio_listio.c 2013-09-16 20:31:39.000000000 +0200
  505. @@ -1,9 +1,9 @@
  506. #include <aio.h>
  507. #include <errno.h>
  508. -#include <limits.h>
  509. #include <unistd.h>
  510. #include <string.h>
  511. #include "pthread_impl.h"
  512. +#include "libc.h"
  513. struct lio_state {
  514. struct sigevent *sev;
  515. diff -Nur musl-0.9.13/src/conf/fpathconf.c musl-git/src/conf/fpathconf.c
  516. --- musl-0.9.13/src/conf/fpathconf.c 2013-08-30 23:30:53.000000000 +0200
  517. +++ musl-git/src/conf/fpathconf.c 2013-09-16 20:31:39.000000000 +0200
  518. @@ -19,11 +19,11 @@
  519. [_PC_PRIO_IO] = -1,
  520. [_PC_SOCK_MAXBUF] = -1,
  521. [_PC_FILESIZEBITS] = FILESIZEBITS,
  522. - [_PC_REC_INCR_XFER_SIZE] = PAGE_SIZE,
  523. - [_PC_REC_MAX_XFER_SIZE] = PAGE_SIZE,
  524. - [_PC_REC_MIN_XFER_SIZE] = PAGE_SIZE,
  525. - [_PC_REC_XFER_ALIGN] = PAGE_SIZE,
  526. - [_PC_ALLOC_SIZE_MIN] = PAGE_SIZE,
  527. + [_PC_REC_INCR_XFER_SIZE] = 4096,
  528. + [_PC_REC_MAX_XFER_SIZE] = 4096,
  529. + [_PC_REC_MIN_XFER_SIZE] = 4096,
  530. + [_PC_REC_XFER_ALIGN] = 4096,
  531. + [_PC_ALLOC_SIZE_MIN] = 4096,
  532. [_PC_SYMLINK_MAX] = SYMLINK_MAX,
  533. [_PC_2_SYMLINKS] = 1
  534. };
  535. diff -Nur musl-0.9.13/src/conf/sysconf.c musl-git/src/conf/sysconf.c
  536. --- musl-0.9.13/src/conf/sysconf.c 2013-08-30 23:30:53.000000000 +0200
  537. +++ musl-git/src/conf/sysconf.c 2013-09-16 20:31:39.000000000 +0200
  538. @@ -3,6 +3,7 @@
  539. #include <errno.h>
  540. #include <sys/resource.h>
  541. #include "syscall.h"
  542. +#include "libc.h"
  543. #define VER (-2)
  544. #define OFLOW (-3)
  545. @@ -40,9 +41,9 @@
  546. [_SC_AIO_PRIO_DELTA_MAX] = 0, /* ?? */
  547. [_SC_DELAYTIMER_MAX] = _POSIX_DELAYTIMER_MAX,
  548. [_SC_MQ_OPEN_MAX] = -1,
  549. - [_SC_MQ_PRIO_MAX] = MQ_PRIO_MAX,
  550. + [_SC_MQ_PRIO_MAX] = OFLOW,
  551. [_SC_VERSION] = VER,
  552. - [_SC_PAGE_SIZE] = PAGE_SIZE,
  553. + [_SC_PAGE_SIZE] = OFLOW,
  554. [_SC_RTSIG_MAX] = 63, /* ?? */
  555. [_SC_SEM_NSEMS_MAX] = SEM_NSEMS_MAX,
  556. [_SC_SEM_VALUE_MAX] = OFLOW,
  557. @@ -221,6 +222,9 @@
  558. } else if (values[name] == OFLOW) {
  559. if (name == _SC_ARG_MAX) return ARG_MAX;
  560. if (name == _SC_SEM_VALUE_MAX) return SEM_VALUE_MAX;
  561. + if (name == _SC_MQ_PRIO_MAX) return MQ_PRIO_MAX;
  562. + /* name == _SC_PAGE_SIZE */
  563. + return PAGE_SIZE;
  564. } else if (values[name] == CPUCNT) {
  565. unsigned char set[128] = {1};
  566. int i, cnt;
  567. diff -Nur musl-0.9.13/src/env/__libc_start_main.c musl-git/src/env/__libc_start_main.c
  568. --- musl-0.9.13/src/env/__libc_start_main.c 2013-08-30 23:30:53.000000000 +0200
  569. +++ musl-git/src/env/__libc_start_main.c 2013-09-16 20:31:39.000000000 +0200
  570. @@ -26,6 +26,7 @@
  571. for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
  572. __hwcap = aux[AT_HWCAP];
  573. __sysinfo = aux[AT_SYSINFO];
  574. + libc.page_size = aux[AT_PAGESZ];
  575. if (pn) {
  576. __progname = __progname_full = pn;
  577. diff -Nur musl-0.9.13/src/internal/libc.h musl-git/src/internal/libc.h
  578. --- musl-0.9.13/src/internal/libc.h 2013-08-30 23:30:53.000000000 +0200
  579. +++ musl-git/src/internal/libc.h 2013-09-16 20:31:39.000000000 +0200
  580. @@ -3,6 +3,7 @@
  581. #include <stdlib.h>
  582. #include <stdio.h>
  583. +#include <limits.h>
  584. struct __libc {
  585. void *main_thread;
  586. @@ -14,10 +15,15 @@
  587. FILE *ofl_head;
  588. int ofl_lock[2];
  589. size_t tls_size;
  590. + size_t page_size;
  591. };
  592. extern size_t __hwcap;
  593. +#ifndef PAGE_SIZE
  594. +#define PAGE_SIZE libc.page_size
  595. +#endif
  596. +
  597. #if !defined(__PIC__) || (100*__GNUC__+__GNUC_MINOR__ >= 303 && !defined(__PCC__))
  598. #ifdef __PIC__
  599. diff -Nur musl-0.9.13/src/internal/libm.h musl-git/src/internal/libm.h
  600. --- musl-0.9.13/src/internal/libm.h 2013-08-30 23:30:53.000000000 +0200
  601. +++ musl-git/src/internal/libm.h 2013-09-16 20:31:39.000000000 +0200
  602. @@ -17,117 +17,115 @@
  603. #include <float.h>
  604. #include <math.h>
  605. #include <complex.h>
  606. +#include <endian.h>
  607. -#include "longdbl.h"
  608. -
  609. -#include "libc.h"
  610. -
  611. -union fshape {
  612. - float value;
  613. - uint32_t bits;
  614. +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  615. +#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
  616. +union ldshape {
  617. + long double f;
  618. + struct {
  619. + uint64_t m;
  620. + uint16_t se;
  621. + } i;
  622. };
  623. -
  624. -union dshape {
  625. - double value;
  626. - uint64_t bits;
  627. +#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
  628. +union ldshape {
  629. + long double f;
  630. + struct {
  631. + uint64_t lo;
  632. + uint32_t mid;
  633. + uint16_t top;
  634. + uint16_t se;
  635. + } i;
  636. + struct {
  637. + uint64_t lo;
  638. + uint64_t hi;
  639. + } i2;
  640. };
  641. +#else
  642. +#error Unsupported long double representation
  643. +#endif
  644. -#define FORCE_EVAL(x) do { \
  645. - if (sizeof(x) == sizeof(float)) { \
  646. - volatile float __x; \
  647. - __x = (x); \
  648. - } else if (sizeof(x) == sizeof(double)) { \
  649. - volatile double __x; \
  650. - __x = (x); \
  651. - } else { \
  652. - volatile long double __x; \
  653. - __x = (x); \
  654. - } \
  655. +#define FORCE_EVAL(x) do { \
  656. + if (sizeof(x) == sizeof(float)) { \
  657. + volatile float __x; \
  658. + __x = (x); \
  659. + } else if (sizeof(x) == sizeof(double)) { \
  660. + volatile double __x; \
  661. + __x = (x); \
  662. + } else { \
  663. + volatile long double __x; \
  664. + __x = (x); \
  665. + } \
  666. } while(0)
  667. /* Get two 32 bit ints from a double. */
  668. -#define EXTRACT_WORDS(hi,lo,d) \
  669. -do { \
  670. - union dshape __u; \
  671. - __u.value = (d); \
  672. - (hi) = __u.bits >> 32; \
  673. - (lo) = (uint32_t)__u.bits; \
  674. -} while (0)
  675. -
  676. -/* Get a 64 bit int from a double. */
  677. -#define EXTRACT_WORD64(i,d) \
  678. -do { \
  679. - union dshape __u; \
  680. - __u.value = (d); \
  681. - (i) = __u.bits; \
  682. +#define EXTRACT_WORDS(hi,lo,d) \
  683. +do { \
  684. + union {double f; uint64_t i;} __u; \
  685. + __u.f = (d); \
  686. + (hi) = __u.i >> 32; \
  687. + (lo) = (uint32_t)__u.i; \
  688. } while (0)
  689. /* Get the more significant 32 bit int from a double. */
  690. -#define GET_HIGH_WORD(i,d) \
  691. -do { \
  692. - union dshape __u; \
  693. - __u.value = (d); \
  694. - (i) = __u.bits >> 32; \
  695. +#define GET_HIGH_WORD(hi,d) \
  696. +do { \
  697. + union {double f; uint64_t i;} __u; \
  698. + __u.f = (d); \
  699. + (hi) = __u.i >> 32; \
  700. } while (0)
  701. /* Get the less significant 32 bit int from a double. */
  702. -#define GET_LOW_WORD(i,d) \
  703. -do { \
  704. - union dshape __u; \
  705. - __u.value = (d); \
  706. - (i) = (uint32_t)__u.bits; \
  707. +#define GET_LOW_WORD(lo,d) \
  708. +do { \
  709. + union {double f; uint64_t i;} __u; \
  710. + __u.f = (d); \
  711. + (lo) = (uint32_t)__u.i; \
  712. } while (0)
  713. /* Set a double from two 32 bit ints. */
  714. -#define INSERT_WORDS(d,hi,lo) \
  715. -do { \
  716. - union dshape __u; \
  717. - __u.bits = ((uint64_t)(hi) << 32) | (uint32_t)(lo); \
  718. - (d) = __u.value; \
  719. -} while (0)
  720. -
  721. -/* Set a double from a 64 bit int. */
  722. -#define INSERT_WORD64(d,i) \
  723. -do { \
  724. - union dshape __u; \
  725. - __u.bits = (i); \
  726. - (d) = __u.value; \
  727. +#define INSERT_WORDS(d,hi,lo) \
  728. +do { \
  729. + union {double f; uint64_t i;} __u; \
  730. + __u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo); \
  731. + (d) = __u.f; \
  732. } while (0)
  733. /* Set the more significant 32 bits of a double from an int. */
  734. -#define SET_HIGH_WORD(d,hi) \
  735. -do { \
  736. - union dshape __u; \
  737. - __u.value = (d); \
  738. - __u.bits &= 0xffffffff; \
  739. - __u.bits |= (uint64_t)(hi) << 32; \
  740. - (d) = __u.value; \
  741. +#define SET_HIGH_WORD(d,hi) \
  742. +do { \
  743. + union {double f; uint64_t i;} __u; \
  744. + __u.f = (d); \
  745. + __u.i &= 0xffffffff; \
  746. + __u.i |= (uint64_t)(hi) << 32; \
  747. + (d) = __u.f; \
  748. } while (0)
  749. /* Set the less significant 32 bits of a double from an int. */
  750. -#define SET_LOW_WORD(d,lo) \
  751. -do { \
  752. - union dshape __u; \
  753. - __u.value = (d); \
  754. - __u.bits &= 0xffffffff00000000ull; \
  755. - __u.bits |= (uint32_t)(lo); \
  756. - (d) = __u.value; \
  757. +#define SET_LOW_WORD(d,lo) \
  758. +do { \
  759. + union {double f; uint64_t i;} __u; \
  760. + __u.f = (d); \
  761. + __u.i &= 0xffffffff00000000ull; \
  762. + __u.i |= (uint32_t)(lo); \
  763. + (d) = __u.f; \
  764. } while (0)
  765. /* Get a 32 bit int from a float. */
  766. -#define GET_FLOAT_WORD(i,d) \
  767. -do { \
  768. - union fshape __u; \
  769. - __u.value = (d); \
  770. - (i) = __u.bits; \
  771. +#define GET_FLOAT_WORD(w,d) \
  772. +do { \
  773. + union {float f; uint32_t i;} __u; \
  774. + __u.f = (d); \
  775. + (w) = __u.i; \
  776. } while (0)
  777. /* Set a float from a 32 bit int. */
  778. -#define SET_FLOAT_WORD(d,i) \
  779. -do { \
  780. - union fshape __u; \
  781. - __u.bits = (i); \
  782. - (d) = __u.value; \
  783. +#define SET_FLOAT_WORD(d,w) \
  784. +do { \
  785. + union {float f; uint32_t i;} __u; \
  786. + __u.i = (w); \
  787. + (d) = __u.f; \
  788. } while (0)
  789. /* fdlibm kernel functions */
  790. @@ -157,15 +155,4 @@
  791. long double __polevll(long double, const long double *, int);
  792. long double __p1evll(long double, const long double *, int);
  793. -#if 0
  794. -/* Attempt to get strict C99 semantics for assignment with non-C99 compilers. */
  795. -#define STRICT_ASSIGN(type, lval, rval) do { \
  796. - volatile type __v = (rval); \
  797. - (lval) = __v; \
  798. -} while (0)
  799. -#else
  800. -/* Should work with -fexcess-precision=standard (>=gcc-4.5) or -ffloat-store */
  801. -#define STRICT_ASSIGN(type, lval, rval) ((lval) = (type)(rval))
  802. -#endif
  803. -
  804. #endif
  805. diff -Nur musl-0.9.13/src/internal/longdbl.h musl-git/src/internal/longdbl.h
  806. --- musl-0.9.13/src/internal/longdbl.h 2013-08-30 23:30:53.000000000 +0200
  807. +++ musl-git/src/internal/longdbl.h 1970-01-01 01:00:00.000000000 +0100
  808. @@ -1,137 +0,0 @@
  809. -#ifndef _LDHACK_H
  810. -#define _LDHACK_H
  811. -
  812. -#include <float.h>
  813. -#include <stdint.h>
  814. -
  815. -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  816. -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  817. -union ldshape {
  818. - long double value;
  819. - struct {
  820. - uint64_t m;
  821. - uint16_t exp:15;
  822. - uint16_t sign:1;
  823. - uint16_t pad;
  824. - } bits;
  825. -};
  826. -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
  827. -union ldshape {
  828. - long double value;
  829. - struct {
  830. - uint64_t mlo;
  831. - uint64_t mhi:48;
  832. - uint16_t exp:15;
  833. - uint16_t sign:1;
  834. - } bits;
  835. -};
  836. -#else
  837. -#error Unsupported long double representation
  838. -#endif
  839. -
  840. -
  841. -// FIXME: hacks to make freebsd+openbsd long double code happy
  842. -
  843. -// union and macros for freebsd
  844. -
  845. -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  846. -
  847. -union IEEEl2bits {
  848. - long double e;
  849. - struct {
  850. - uint32_t manl:32;
  851. - uint32_t manh:32;
  852. - uint32_t exp:15;
  853. - uint32_t sign:1;
  854. - uint32_t pad:16;
  855. - } bits;
  856. - struct {
  857. - uint64_t man:64;
  858. - uint32_t expsign:16;
  859. - uint32_t pad:16;
  860. - } xbits;
  861. -};
  862. -
  863. -#define LDBL_MANL_SIZE 32
  864. -#define LDBL_MANH_SIZE 32
  865. -#define LDBL_NBIT (1ull << LDBL_MANH_SIZE-1)
  866. -#undef LDBL_IMPLICIT_NBIT
  867. -#define mask_nbit_l(u) ((u).bits.manh &= ~LDBL_NBIT)
  868. -
  869. -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
  870. -/*
  871. -// ld128 float.h
  872. -//#define LDBL_MAX 1.189731495357231765085759326628007016E+4932L
  873. -#define LDBL_MAX 0x1.ffffffffffffffffffffffffffffp+16383
  874. -#define LDBL_MAX_EXP 16384
  875. -#define LDBL_HAS_INFINITY 1
  876. -//#define LDBL_MIN 3.362103143112093506262677817321752603E-4932L
  877. -#define LDBL_MIN 0x1p-16382
  878. -#define LDBL_HAS_QUIET_NAN 1
  879. -#define LDBL_HAS_DENORM 1
  880. -//#define LDBL_EPSILON 1.925929944387235853055977942584927319E-34L
  881. -#define LDBL_EPSILON 0x1p-112
  882. -#define LDBL_MANT_DIG 113
  883. -#define LDBL_MIN_EXP (-16381)
  884. -#define LDBL_MAX_10_EXP 4932
  885. -#define LDBL_DENORM_MIN 0x0.0000000000000000000000000001p-16381
  886. -#define LDBL_MIN_10_EXP (-4931)
  887. -#define LDBL_DIG 33
  888. -*/
  889. -
  890. -union IEEEl2bits {
  891. - long double e;
  892. - struct {
  893. - uint64_t manl:64;
  894. - uint64_t manh:48;
  895. - uint32_t exp:15;
  896. - uint32_t sign:1;
  897. - } bits;
  898. - struct {
  899. - uint64_t unused0:64;
  900. - uint64_t unused1:48;
  901. - uint32_t expsign:16;
  902. - } xbits;
  903. -};
  904. -
  905. -#define LDBL_MANL_SIZE 64
  906. -#define LDBL_MANH_SIZE 48
  907. -#define LDBL_NBIT (1ull << LDBL_MANH_SIZE)
  908. -#define LDBL_IMPLICIT_NBIT 1
  909. -#define mask_nbit_l(u)
  910. -
  911. -#endif
  912. -
  913. -
  914. -// macros for openbsd
  915. -
  916. -#define GET_LDOUBLE_WORDS(se,mh,ml, f) do{ \
  917. - union IEEEl2bits u; \
  918. - u.e = (f); \
  919. - (se) = u.xbits.expsign; \
  920. - (mh) = u.bits.manh; \
  921. - (ml) = u.bits.manl; \
  922. -}while(0)
  923. -
  924. -#define SET_LDOUBLE_WORDS(f, se,mh,ml) do{ \
  925. - union IEEEl2bits u; \
  926. - u.xbits.expsign = (se); \
  927. - u.bits.manh = (mh); \
  928. - u.bits.manl = (ml); \
  929. - (f) = u.e; \
  930. -}while(0)
  931. -
  932. -#define GET_LDOUBLE_EXP(se, f) do{ \
  933. - union IEEEl2bits u; \
  934. - u.e = (f); \
  935. - (se) = u.xbits.expsign; \
  936. -}while(0)
  937. -
  938. -#define SET_LDOUBLE_EXP(f, se) do{ \
  939. - union IEEEl2bits u; \
  940. - u.e = (f); \
  941. - u.xbits.expsign = (se); \
  942. - (f) = u.e; \
  943. -}while(0)
  944. -
  945. -#endif
  946. diff -Nur musl-0.9.13/src/ldso/dynlink.c musl-git/src/ldso/dynlink.c
  947. --- musl-0.9.13/src/ldso/dynlink.c 2013-08-30 23:30:53.000000000 +0200
  948. +++ musl-git/src/ldso/dynlink.c 2013-09-16 20:31:39.000000000 +0200
  949. @@ -614,6 +614,8 @@
  950. sys_path = "";
  951. }
  952. fclose(f);
  953. + } else if (errno != ENOENT) {
  954. + sys_path = "";
  955. }
  956. }
  957. if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
  958. @@ -978,6 +980,7 @@
  959. env_preload = 0;
  960. libc.secure = 1;
  961. }
  962. + libc.page_size = aux[AT_PAGESZ];
  963. /* If the dynamic linker was invoked as a program itself, AT_BASE
  964. * will not be set. In that case, we assume the base address is
  965. diff -Nur musl-0.9.13/src/legacy/getpagesize.c musl-git/src/legacy/getpagesize.c
  966. --- musl-0.9.13/src/legacy/getpagesize.c 2013-08-30 23:30:53.000000000 +0200
  967. +++ musl-git/src/legacy/getpagesize.c 2013-09-16 20:31:39.000000000 +0200
  968. @@ -1,5 +1,5 @@
  969. #include <unistd.h>
  970. -#include <limits.h>
  971. +#include "libc.h"
  972. int getpagesize(void)
  973. {
  974. diff -Nur musl-0.9.13/src/legacy/valloc.c musl-git/src/legacy/valloc.c
  975. --- musl-0.9.13/src/legacy/valloc.c 2013-08-30 23:30:53.000000000 +0200
  976. +++ musl-git/src/legacy/valloc.c 2013-09-16 20:31:39.000000000 +0200
  977. @@ -1,6 +1,6 @@
  978. #define _BSD_SOURCE
  979. #include <stdlib.h>
  980. -#include <limits.h>
  981. +#include "libc.h"
  982. void *valloc(size_t size)
  983. {
  984. diff -Nur musl-0.9.13/src/math/__cosl.c musl-git/src/math/__cosl.c
  985. --- musl-0.9.13/src/math/__cosl.c 2013-08-30 23:30:53.000000000 +0200
  986. +++ musl-git/src/math/__cosl.c 2013-09-16 20:31:39.000000000 +0200
  987. @@ -1,4 +1,5 @@
  988. /* origin: FreeBSD /usr/src/lib/msun/ld80/k_cosl.c */
  989. +/* origin: FreeBSD /usr/src/lib/msun/ld128/k_cosl.c */
  990. /*
  991. * ====================================================
  992. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  993. @@ -14,7 +15,8 @@
  994. #include "libm.h"
  995. -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  996. +#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  997. +#if LDBL_MANT_DIG == 64
  998. /*
  999. * ld80 version of __cos.c. See __cos.c for most comments.
  1000. */
  1001. @@ -43,7 +45,6 @@
  1002. */
  1003. static const long double
  1004. C1 = 0.0416666666666666666136L; /* 0xaaaaaaaaaaaaaa9b.0p-68 */
  1005. -
  1006. static const double
  1007. C2 = -0.0013888888888888874, /* -0x16c16c16c16c10.0p-62 */
  1008. C3 = 0.000024801587301571716, /* 0x1a01a01a018e22.0p-68 */
  1009. @@ -51,13 +52,43 @@
  1010. C5 = 0.0000000020876754400407278, /* 0x11eed8caaeccf1.0p-81 */
  1011. C6 = -1.1470297442401303e-11, /* -0x19393412bd1529.0p-89 */
  1012. C7 = 4.7383039476436467e-14; /* 0x1aac9d9af5c43e.0p-97 */
  1013. +#define POLY(z) (z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*C7)))))))
  1014. +#elif LDBL_MANT_DIG == 113
  1015. +/*
  1016. + * ld128 version of __cos.c. See __cos.c for most comments.
  1017. + */
  1018. +/*
  1019. + * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]:
  1020. + * |cos(x) - c(x))| < 2**-122.0
  1021. + *
  1022. + * 113-bit precision requires more care than 64-bit precision, since
  1023. + * simple methods give a minimax polynomial with coefficient for x^2
  1024. + * that is 1 ulp below 0.5, but we want it to be precisely 0.5. See
  1025. + * above for more details.
  1026. + */
  1027. +static const long double
  1028. +C1 = 0.04166666666666666666666666666666658424671L,
  1029. +C2 = -0.001388888888888888888888888888863490893732L,
  1030. +C3 = 0.00002480158730158730158730158600795304914210L,
  1031. +C4 = -0.2755731922398589065255474947078934284324e-6L,
  1032. +C5 = 0.2087675698786809897659225313136400793948e-8L,
  1033. +C6 = -0.1147074559772972315817149986812031204775e-10L,
  1034. +C7 = 0.4779477332386808976875457937252120293400e-13L;
  1035. +static const double
  1036. +C8 = -0.1561920696721507929516718307820958119868e-15,
  1037. +C9 = 0.4110317413744594971475941557607804508039e-18,
  1038. +C10 = -0.8896592467191938803288521958313920156409e-21,
  1039. +C11 = 0.1601061435794535138244346256065192782581e-23;
  1040. +#define POLY(z) (z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+ \
  1041. + z*(C8+z*(C9+z*(C10+z*C11)))))))))))
  1042. +#endif
  1043. long double __cosl(long double x, long double y)
  1044. {
  1045. long double hz,z,r,w;
  1046. z = x*x;
  1047. - r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*C7))))));
  1048. + r = POLY(z);
  1049. hz = 0.5*z;
  1050. w = 1.0-hz;
  1051. return w + (((1.0-w)-hz) + (z*r-x*y));
  1052. diff -Nur musl-0.9.13/src/math/__fpclassify.c musl-git/src/math/__fpclassify.c
  1053. --- musl-0.9.13/src/math/__fpclassify.c 2013-08-30 23:30:53.000000000 +0200
  1054. +++ musl-git/src/math/__fpclassify.c 2013-09-16 20:31:39.000000000 +0200
  1055. @@ -1,10 +1,11 @@
  1056. -#include "libm.h"
  1057. +#include <math.h>
  1058. +#include <stdint.h>
  1059. int __fpclassify(double x)
  1060. {
  1061. - union dshape u = { x };
  1062. - int e = u.bits>>52 & 0x7ff;
  1063. - if (!e) return u.bits<<1 ? FP_SUBNORMAL : FP_ZERO;
  1064. - if (e==0x7ff) return u.bits<<12 ? FP_NAN : FP_INFINITE;
  1065. + union {double f; uint64_t i;} u = {x};
  1066. + int e = u.i>>52 & 0x7ff;
  1067. + if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
  1068. + if (e==0x7ff) return u.i<<12 ? FP_NAN : FP_INFINITE;
  1069. return FP_NORMAL;
  1070. }
  1071. diff -Nur musl-0.9.13/src/math/__fpclassifyf.c musl-git/src/math/__fpclassifyf.c
  1072. --- musl-0.9.13/src/math/__fpclassifyf.c 2013-08-30 23:30:53.000000000 +0200
  1073. +++ musl-git/src/math/__fpclassifyf.c 2013-09-16 20:31:39.000000000 +0200
  1074. @@ -1,10 +1,11 @@
  1075. -#include "libm.h"
  1076. +#include <math.h>
  1077. +#include <stdint.h>
  1078. int __fpclassifyf(float x)
  1079. {
  1080. - union fshape u = { x };
  1081. - int e = u.bits>>23 & 0xff;
  1082. - if (!e) return u.bits<<1 ? FP_SUBNORMAL : FP_ZERO;
  1083. - if (e==0xff) return u.bits<<9 ? FP_NAN : FP_INFINITE;
  1084. + union {float f; uint32_t i;} u = {x};
  1085. + int e = u.i>>23 & 0xff;
  1086. + if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
  1087. + if (e==0xff) return u.i<<9 ? FP_NAN : FP_INFINITE;
  1088. return FP_NORMAL;
  1089. }
  1090. diff -Nur musl-0.9.13/src/math/__fpclassifyl.c musl-git/src/math/__fpclassifyl.c
  1091. --- musl-0.9.13/src/math/__fpclassifyl.c 2013-08-30 23:30:53.000000000 +0200
  1092. +++ musl-git/src/math/__fpclassifyl.c 2013-09-16 20:31:39.000000000 +0200
  1093. @@ -5,26 +5,28 @@
  1094. #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  1095. int __fpclassifyl(long double x)
  1096. {
  1097. - union ldshape u = { x };
  1098. - int e = u.bits.exp;
  1099. - if (!e) {
  1100. - if (u.bits.m >> 63) return FP_NAN;
  1101. - else if (u.bits.m) return FP_SUBNORMAL;
  1102. - else return FP_ZERO;
  1103. - }
  1104. + union ldshape u = {x};
  1105. + int e = u.i.se & 0x7fff;
  1106. + int msb = u.i.m>>63;
  1107. + if (!e && !msb)
  1108. + return u.i.m ? FP_SUBNORMAL : FP_ZERO;
  1109. + if (!msb)
  1110. + return FP_NAN;
  1111. if (e == 0x7fff)
  1112. - return u.bits.m & (uint64_t)-1>>1 ? FP_NAN : FP_INFINITE;
  1113. - return u.bits.m & (uint64_t)1<<63 ? FP_NORMAL : FP_NAN;
  1114. + return u.i.m << 1 ? FP_NAN : FP_INFINITE;
  1115. + return FP_NORMAL;
  1116. }
  1117. #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
  1118. int __fpclassifyl(long double x)
  1119. {
  1120. - union ldshape u = { x };
  1121. - int e = u.bits.exp;
  1122. + union ldshape u = {x};
  1123. + int e = u.i.se & 0x7fff;
  1124. if (!e)
  1125. - return u.bits.mlo | u.bits.mhi ? FP_SUBNORMAL : FP_ZERO;
  1126. - if (e == 0x7fff)
  1127. - return u.bits.mlo | u.bits.mhi ? FP_NAN : FP_INFINITE;
  1128. + return u.i2.lo | u.i2.hi ? FP_SUBNORMAL : FP_ZERO;
  1129. + if (e == 0x7fff) {
  1130. + u.i.se = 0;
  1131. + return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE;
  1132. + }
  1133. return FP_NORMAL;
  1134. }
  1135. #endif
  1136. diff -Nur musl-0.9.13/src/math/__invtrigl.c musl-git/src/math/__invtrigl.c
  1137. --- musl-0.9.13/src/math/__invtrigl.c 2013-08-30 23:30:53.000000000 +0200
  1138. +++ musl-git/src/math/__invtrigl.c 2013-09-16 20:31:39.000000000 +0200
  1139. @@ -1,7 +1,7 @@
  1140. +#include <float.h>
  1141. #include "__invtrigl.h"
  1142. #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  1143. -
  1144. static const long double
  1145. pS0 = 1.66666666666666666631e-01L,
  1146. pS1 = -4.16313987993683104320e-01L,
  1147. @@ -28,4 +28,36 @@
  1148. q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*(qS4+z*qS5))));
  1149. return p/q;
  1150. }
  1151. +#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
  1152. +static const long double
  1153. +pS0 = 1.66666666666666666666666666666700314e-01L,
  1154. +pS1 = -7.32816946414566252574527475428622708e-01L,
  1155. +pS2 = 1.34215708714992334609030036562143589e+00L,
  1156. +pS3 = -1.32483151677116409805070261790752040e+00L,
  1157. +pS4 = 7.61206183613632558824485341162121989e-01L,
  1158. +pS5 = -2.56165783329023486777386833928147375e-01L,
  1159. +pS6 = 4.80718586374448793411019434585413855e-02L,
  1160. +pS7 = -4.42523267167024279410230886239774718e-03L,
  1161. +pS8 = 1.44551535183911458253205638280410064e-04L,
  1162. +pS9 = -2.10558957916600254061591040482706179e-07L,
  1163. +qS1 = -4.84690167848739751544716485245697428e+00L,
  1164. +qS2 = 9.96619113536172610135016921140206980e+00L,
  1165. +qS3 = -1.13177895428973036660836798461641458e+01L,
  1166. +qS4 = 7.74004374389488266169304117714658761e+00L,
  1167. +qS5 = -3.25871986053534084709023539900339905e+00L,
  1168. +qS6 = 8.27830318881232209752469022352928864e-01L,
  1169. +qS7 = -1.18768052702942805423330715206348004e-01L,
  1170. +qS8 = 8.32600764660522313269101537926539470e-03L,
  1171. +qS9 = -1.99407384882605586705979504567947007e-04L;
  1172. +
  1173. +const long double pio2_hi = 1.57079632679489661923132169163975140L;
  1174. +const long double pio2_lo = 4.33590506506189051239852201302167613e-35L;
  1175. +
  1176. +long double __invtrigl_R(long double z)
  1177. +{
  1178. + long double p, q;
  1179. + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*(pS5+z*(pS6+z*(pS7+z*(pS8+z*pS9)))))))));
  1180. + q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*(qS4+z*(qS5+z*(pS6+z*(pS7+z*(pS8+z*pS9))))))));
  1181. + return p/q;
  1182. +}
  1183. #endif
  1184. diff -Nur musl-0.9.13/src/math/__invtrigl.h musl-git/src/math/__invtrigl.h
  1185. --- musl-0.9.13/src/math/__invtrigl.h 2013-08-30 23:30:53.000000000 +0200
  1186. +++ musl-git/src/math/__invtrigl.h 2013-09-16 20:31:39.000000000 +0200
  1187. @@ -1,10 +1,6 @@
  1188. -#include <float.h>
  1189. -
  1190. -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  1191. /* shared by acosl, asinl and atan2l */
  1192. #define pio2_hi __pio2_hi
  1193. #define pio2_lo __pio2_lo
  1194. extern const long double pio2_hi, pio2_lo;
  1195. long double __invtrigl_R(long double z);
  1196. -#endif
  1197. diff -Nur musl-0.9.13/src/math/__rem_pio2.c musl-git/src/math/__rem_pio2.c
  1198. --- musl-0.9.13/src/math/__rem_pio2.c 2013-08-30 23:30:53.000000000 +0200
  1199. +++ musl-git/src/math/__rem_pio2.c 2013-09-16 20:31:39.000000000 +0200
  1200. @@ -112,7 +112,7 @@
  1201. uint32_t high;
  1202. medium:
  1203. /* Use a specialized rint() to get fn. Assume round-to-nearest. */
  1204. - STRICT_ASSIGN(double, fn, x*invpio2 + 0x1.8p52);
  1205. + fn = x*invpio2 + 0x1.8p52;
  1206. fn = fn - 0x1.8p52;
  1207. // FIXME
  1208. #ifdef HAVE_EFFICIENT_IRINT
  1209. diff -Nur musl-0.9.13/src/math/__rem_pio2_large.c musl-git/src/math/__rem_pio2_large.c
  1210. --- musl-0.9.13/src/math/__rem_pio2_large.c 2013-08-30 23:30:53.000000000 +0200
  1211. +++ musl-git/src/math/__rem_pio2_large.c 2013-09-16 20:31:39.000000000 +0200
  1212. @@ -415,7 +415,8 @@
  1213. fw = 0.0;
  1214. for (i=jz; i>=0; i--)
  1215. fw += fq[i];
  1216. - STRICT_ASSIGN(double,fw,fw);
  1217. + // TODO: drop excess precision here once double_t is used
  1218. + fw = (double)fw;
  1219. y[0] = ih==0 ? fw : -fw;
  1220. fw = fq[0]-fw;
  1221. for (i=1; i<=jz; i++)
  1222. diff -Nur musl-0.9.13/src/math/__rem_pio2f.c musl-git/src/math/__rem_pio2f.c
  1223. --- musl-0.9.13/src/math/__rem_pio2f.c 2013-08-30 23:30:53.000000000 +0200
  1224. +++ musl-git/src/math/__rem_pio2f.c 2013-09-16 20:31:39.000000000 +0200
  1225. @@ -44,7 +44,7 @@
  1226. /* 25+53 bit pi is good enough for medium size */
  1227. if (ix < 0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */
  1228. /* Use a specialized rint() to get fn. Assume round-to-nearest. */
  1229. - STRICT_ASSIGN(double, fn, x*invpio2 + 0x1.8p52);
  1230. + fn = x*invpio2 + 0x1.8p52;
  1231. fn = fn - 0x1.8p52;
  1232. // FIXME
  1233. #ifdef HAVE_EFFICIENT_IRINT
  1234. diff -Nur musl-0.9.13/src/math/__rem_pio2l.c musl-git/src/math/__rem_pio2l.c
  1235. --- musl-0.9.13/src/math/__rem_pio2l.c 2013-08-30 23:30:53.000000000 +0200
  1236. +++ musl-git/src/math/__rem_pio2l.c 2013-09-16 20:31:39.000000000 +0200
  1237. @@ -13,15 +13,22 @@
  1238. * Optimized by Bruce D. Evans.
  1239. */
  1240. #include "libm.h"
  1241. -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  1242. -/* ld80 version of __rem_pio2(x,y)
  1243. +#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  1244. +/* ld80 and ld128 version of __rem_pio2(x,y)
  1245. *
  1246. * return the remainder of x rem pi/2 in y[0]+y[1]
  1247. * use __rem_pio2_large() for large x
  1248. */
  1249. -#define BIAS (LDBL_MAX_EXP - 1)
  1250. -
  1251. +#if LDBL_MANT_DIG == 64
  1252. +/* u ~< 0x1p25*pi/2 */
  1253. +#define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < ((0x3fff + 25)<<16 | 0x921f>>1 | 0x8000))
  1254. +#define TOINT 0x1.8p63
  1255. +#define QUOBITS(x) ((uint32_t)(int32_t)x & 0x7fffffff)
  1256. +#define ROUND1 22
  1257. +#define ROUND2 61
  1258. +#define NX 3
  1259. +#define NY 2
  1260. /*
  1261. * invpio2: 64 bits of 2/pi
  1262. * pio2_1: first 39 bits of pi/2
  1263. @@ -32,60 +39,61 @@
  1264. * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
  1265. */
  1266. static const double
  1267. -two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
  1268. pio2_1 = 1.57079632679597125389e+00, /* 0x3FF921FB, 0x54444000 */
  1269. pio2_2 = -1.07463465549783099519e-12, /* -0x12e7b967674000.0p-92 */
  1270. pio2_3 = 6.36831716351370313614e-25; /* 0x18a2e037074000.0p-133 */
  1271. -
  1272. static const long double
  1273. invpio2 = 6.36619772367581343076e-01L, /* 0xa2f9836e4e44152a.0p-64 */
  1274. pio2_1t = -1.07463465549719416346e-12L, /* -0x973dcb3b399d747f.0p-103 */
  1275. pio2_2t = 6.36831716351095013979e-25L, /* 0xc51701b839a25205.0p-144 */
  1276. pio2_3t = -2.75299651904407171810e-37L; /* -0xbb5bf6c7ddd660ce.0p-185 */
  1277. +#elif LDBL_MANT_DIG == 113
  1278. +/* u ~< 0x1p45*pi/2 */
  1279. +#define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.top) < ((0x3fff + 45)<<16 | 0x921f))
  1280. +#define TOINT 0x1.8p112
  1281. +#define QUOBITS(x) ((uint32_t)(int64_t)x & 0x7fffffff)
  1282. +#define ROUND1 51
  1283. +#define ROUND2 119
  1284. +#define NX 5
  1285. +#define NY 3
  1286. +static const long double
  1287. +invpio2 = 6.3661977236758134307553505349005747e-01L, /* 0x145f306dc9c882a53f84eafa3ea6a.0p-113 */
  1288. +pio2_1 = 1.5707963267948966192292994253909555e+00L, /* 0x1921fb54442d18469800000000000.0p-112 */
  1289. +pio2_1t = 2.0222662487959507323996846200947577e-21L, /* 0x13198a2e03707344a4093822299f3.0p-181 */
  1290. +pio2_2 = 2.0222662487959507323994779168837751e-21L, /* 0x13198a2e03707344a400000000000.0p-181 */
  1291. +pio2_2t = 2.0670321098263988236496903051604844e-43L, /* 0x127044533e63a0105df531d89cd91.0p-254 */
  1292. +pio2_3 = 2.0670321098263988236499468110329591e-43L, /* 0x127044533e63a0105e00000000000.0p-254 */
  1293. +pio2_3t = -2.5650587247459238361625433492959285e-65L; /* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */
  1294. +#endif
  1295. int __rem_pio2l(long double x, long double *y)
  1296. {
  1297. - union IEEEl2bits u,u1;
  1298. + union ldshape u,uz;
  1299. long double z,w,t,r,fn;
  1300. - double tx[3],ty[2];
  1301. - int e0,ex,i,j,nx,n;
  1302. - int16_t expsign;
  1303. -
  1304. - u.e = x;
  1305. - expsign = u.xbits.expsign;
  1306. - ex = expsign & 0x7fff;
  1307. - if (ex < BIAS + 25 || (ex == BIAS + 25 && u.bits.manh < 0xc90fdaa2)) {
  1308. - union IEEEl2bits u2;
  1309. - int ex1;
  1310. + double tx[NX],ty[NY];
  1311. + int ex,ey,n,i;
  1312. - /* |x| ~< 2^25*(pi/2), medium size */
  1313. - /* Use a specialized rint() to get fn. Assume round-to-nearest. */
  1314. - fn = x*invpio2 + 0x1.8p63;
  1315. - fn = fn - 0x1.8p63;
  1316. -// FIXME
  1317. -//#ifdef HAVE_EFFICIENT_IRINT
  1318. -// n = irint(fn);
  1319. -//#else
  1320. - n = fn;
  1321. -//#endif
  1322. + u.f = x;
  1323. + ex = u.i.se & 0x7fff;
  1324. + if (SMALL(u)) {
  1325. + /* rint(x/(pi/2)), Assume round-to-nearest. */
  1326. + fn = x*invpio2 + TOINT - TOINT;
  1327. + n = QUOBITS(fn);
  1328. r = x-fn*pio2_1;
  1329. - w = fn*pio2_1t; /* 1st round good to 102 bit */
  1330. - j = ex;
  1331. + w = fn*pio2_1t; /* 1st round good to 102/180 bits (ld80/ld128) */
  1332. y[0] = r-w;
  1333. - u2.e = y[0];
  1334. - ex1 = u2.xbits.expsign & 0x7fff;
  1335. - i = j-ex1;
  1336. - if (i > 22) { /* 2nd iteration needed, good to 141 */
  1337. + u.f = y[0];
  1338. + ey = u.i.se & 0x7fff;
  1339. + if (ex - ey > ROUND1) { /* 2nd iteration needed, good to 141/248 (ld80/ld128) */
  1340. t = r;
  1341. w = fn*pio2_2;
  1342. r = t-w;
  1343. w = fn*pio2_2t-((t-r)-w);
  1344. y[0] = r-w;
  1345. - u2.e = y[0];
  1346. - ex1 = u2.xbits.expsign & 0x7fff;
  1347. - i = j-ex1;
  1348. - if (i > 61) { /* 3rd iteration need, 180 bits acc */
  1349. - t = r; /* will cover all possible cases */
  1350. + u.f = y[0];
  1351. + ey = u.i.se & 0x7fff;
  1352. + if (ex - ey > ROUND2) { /* 3rd iteration, good to 180/316 bits */
  1353. + t = r; /* will cover all possible cases (not verified for ld128) */
  1354. w = fn*pio2_3;
  1355. r = t-w;
  1356. w = fn*pio2_3t-((t-r)-w);
  1357. @@ -102,23 +110,26 @@
  1358. y[0] = y[1] = x - x;
  1359. return 0;
  1360. }
  1361. - /* set z = scalbn(|x|,ilogb(x)-23) */
  1362. - u1.e = x;
  1363. - e0 = ex - BIAS - 23; /* e0 = ilogb(|x|)-23; */
  1364. - u1.xbits.expsign = ex - e0;
  1365. - z = u1.e;
  1366. - for (i=0; i<2; i++) {
  1367. + /* set z = scalbn(|x|,-ilogb(x)+23) */
  1368. + uz.f = x;
  1369. + uz.i.se = 0x3fff + 23;
  1370. + z = uz.f;
  1371. + for (i=0; i < NX - 1; i++) {
  1372. tx[i] = (double)(int32_t)z;
  1373. - z = (z-tx[i])*two24;
  1374. + z = (z-tx[i])*0x1p24;
  1375. }
  1376. - tx[2] = z;
  1377. - nx = 3;
  1378. - while (tx[nx-1] == 0.0)
  1379. - nx--; /* skip zero term */
  1380. - n = __rem_pio2_large(tx,ty,e0,nx,2);
  1381. - r = (long double)ty[0] + ty[1];
  1382. - w = ty[1] - (r - ty[0]);
  1383. - if (expsign < 0) {
  1384. + tx[i] = z;
  1385. + while (tx[i] == 0)
  1386. + i--;
  1387. + n = __rem_pio2_large(tx, ty, ex-0x3fff-23, i+1, NY);
  1388. + w = ty[1];
  1389. + if (NY == 3)
  1390. + w += ty[2];
  1391. + r = ty[0] + w;
  1392. + /* TODO: for ld128 this does not follow the recommendation of the
  1393. + comments of __rem_pio2_large which seem wrong if |ty[0]| > |ty[1]+ty[2]| */
  1394. + w -= r - ty[0];
  1395. + if (u.i.se >> 15) {
  1396. y[0] = -r;
  1397. y[1] = -w;
  1398. return -n;
  1399. diff -Nur musl-0.9.13/src/math/__signbitl.c musl-git/src/math/__signbitl.c
  1400. --- musl-0.9.13/src/math/__signbitl.c 2013-08-30 23:30:53.000000000 +0200
  1401. +++ musl-git/src/math/__signbitl.c 2013-09-16 20:31:39.000000000 +0200
  1402. @@ -1,11 +1,9 @@
  1403. #include "libm.h"
  1404. -// FIXME: should be a macro
  1405. #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  1406. int __signbitl(long double x)
  1407. {
  1408. union ldshape u = {x};
  1409. -
  1410. - return u.bits.sign;
  1411. + return u.i.se >> 15;
  1412. }
  1413. #endif
  1414. diff -Nur musl-0.9.13/src/math/__sinl.c musl-git/src/math/__sinl.c
  1415. --- musl-0.9.13/src/math/__sinl.c 2013-08-30 23:30:53.000000000 +0200
  1416. +++ musl-git/src/math/__sinl.c 2013-09-16 20:31:39.000000000 +0200
  1417. @@ -1,4 +1,5 @@
  1418. /* origin: FreeBSD /usr/src/lib/msun/ld80/k_sinl.c */
  1419. +/* origin: FreeBSD /usr/src/lib/msun/ld128/k_sinl.c */
  1420. /*
  1421. * ====================================================
  1422. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  1423. @@ -13,7 +14,8 @@
  1424. #include "libm.h"
  1425. -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  1426. +#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  1427. +#if LDBL_MANT_DIG == 64
  1428. /*
  1429. * ld80 version of __sin.c. See __sin.c for most comments.
  1430. */
  1431. @@ -23,10 +25,8 @@
  1432. *
  1433. * See __cosl.c for more details about the polynomial.
  1434. */
  1435. -
  1436. static const long double
  1437. S1 = -0.166666666666666666671L; /* -0xaaaaaaaaaaaaaaab.0p-66 */
  1438. -
  1439. static const double
  1440. S2 = 0.0083333333333333332, /* 0x11111111111111.0p-59 */
  1441. S3 = -0.00019841269841269427, /* -0x1a01a01a019f81.0p-65 */
  1442. @@ -35,6 +35,34 @@
  1443. S6 = 1.6059006598854211e-10, /* 0x161242b90243b5.0p-85 */
  1444. S7 = -7.6429779983024564e-13, /* -0x1ae42ebd1b2e00.0p-93 */
  1445. S8 = 2.6174587166648325e-15; /* 0x179372ea0b3f64.0p-101 */
  1446. +#define POLY(z) (S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*S8))))))
  1447. +#elif LDBL_MANT_DIG == 113
  1448. +/*
  1449. + * ld128 version of __sin.c. See __sin.c for most comments.
  1450. + */
  1451. +/*
  1452. + * Domain [-0.7854, 0.7854], range ~[-1.53e-37, 1.659e-37]
  1453. + * |sin(x)/x - s(x)| < 2**-122.1
  1454. + *
  1455. + * See __cosl.c for more details about the polynomial.
  1456. + */
  1457. +static const long double
  1458. +S1 = -0.16666666666666666666666666666666666606732416116558L,
  1459. +S2 = 0.0083333333333333333333333333333331135404851288270047L,
  1460. +S3 = -0.00019841269841269841269841269839935785325638310428717L,
  1461. +S4 = 0.27557319223985890652557316053039946268333231205686e-5L,
  1462. +S5 = -0.25052108385441718775048214826384312253862930064745e-7L,
  1463. +S6 = 0.16059043836821614596571832194524392581082444805729e-9L,
  1464. +S7 = -0.76471637318198151807063387954939213287488216303768e-12L,
  1465. +S8 = 0.28114572543451292625024967174638477283187397621303e-14L;
  1466. +static const double
  1467. +S9 = -0.82206352458348947812512122163446202498005154296863e-17,
  1468. +S10 = 0.19572940011906109418080609928334380560135358385256e-19,
  1469. +S11 = -0.38680813379701966970673724299207480965452616911420e-22,
  1470. +S12 = 0.64038150078671872796678569586315881020659912139412e-25;
  1471. +#define POLY(z) (S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*(S8+ \
  1472. + z*(S9+z*(S10+z*(S11+z*S12))))))))))
  1473. +#endif
  1474. long double __sinl(long double x, long double y, int iy)
  1475. {
  1476. @@ -42,7 +70,7 @@
  1477. z = x*x;
  1478. v = z*x;
  1479. - r = S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*S8)))));
  1480. + r = POLY(z);
  1481. if (iy == 0)
  1482. return x+v*(S1+z*r);
  1483. return x-((z*(0.5*y-v*r)-y)-v*S1);
  1484. diff -Nur musl-0.9.13/src/math/__tanl.c musl-git/src/math/__tanl.c
  1485. --- musl-0.9.13/src/math/__tanl.c 2013-08-30 23:30:53.000000000 +0200
  1486. +++ musl-git/src/math/__tanl.c 2013-09-16 20:31:39.000000000 +0200
  1487. @@ -1,4 +1,5 @@
  1488. /* origin: FreeBSD /usr/src/lib/msun/ld80/k_tanl.c */
  1489. +/* origin: FreeBSD /usr/src/lib/msun/ld128/k_tanl.c */
  1490. /*
  1491. * ====================================================
  1492. * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
  1493. @@ -12,7 +13,8 @@
  1494. #include "libm.h"
  1495. -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  1496. +#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  1497. +#if LDBL_MANT_DIG == 64
  1498. /*
  1499. * ld80 version of __tan.c. See __tan.c for most comments.
  1500. */
  1501. @@ -22,14 +24,12 @@
  1502. *
  1503. * See __cosl.c for more details about the polynomial.
  1504. */
  1505. -
  1506. static const long double
  1507. T3 = 0.333333333333333333180L, /* 0xaaaaaaaaaaaaaaa5.0p-65 */
  1508. T5 = 0.133333333333333372290L, /* 0x88888888888893c3.0p-66 */
  1509. T7 = 0.0539682539682504975744L, /* 0xdd0dd0dd0dc13ba2.0p-68 */
  1510. pio4 = 0.785398163397448309628L, /* 0xc90fdaa22168c235.0p-64 */
  1511. pio4lo = -1.25413940316708300586e-20L; /* -0xece675d1fc8f8cbb.0p-130 */
  1512. -
  1513. static const double
  1514. T9 = 0.021869488536312216, /* 0x1664f4882cc1c2.0p-58 */
  1515. T11 = 0.0088632355256619590, /* 0x1226e355c17612.0p-59 */
  1516. @@ -44,6 +44,59 @@
  1517. T29 = 0.0000078293456938132840, /* 0x106b59141a6cb3.0p-69 */
  1518. T31 = -0.0000032609076735050182, /* -0x1b5abef3ba4b59.0p-71 */
  1519. T33 = 0.0000023261313142559411; /* 0x13835436c0c87f.0p-71 */
  1520. +#define RPOLY(w) (T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + \
  1521. + w * (T25 + w * (T29 + w * T33)))))))
  1522. +#define VPOLY(w) (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + \
  1523. + w * (T27 + w * T31))))))
  1524. +#elif LDBL_MANT_DIG == 113
  1525. +/*
  1526. + * ld128 version of __tan.c. See __tan.c for most comments.
  1527. + */
  1528. +/*
  1529. + * Domain [-0.67434, 0.67434], range ~[-3.37e-36, 1.982e-37]
  1530. + * |tan(x)/x - t(x)| < 2**-117.8 (XXX should be ~1e-37)
  1531. + *
  1532. + * See __cosl.c for more details about the polynomial.
  1533. + */
  1534. +static const long double
  1535. +T3 = 0x1.5555555555555555555555555553p-2L,
  1536. +T5 = 0x1.1111111111111111111111111eb5p-3L,
  1537. +T7 = 0x1.ba1ba1ba1ba1ba1ba1ba1b694cd6p-5L,
  1538. +T9 = 0x1.664f4882c10f9f32d6bbe09d8bcdp-6L,
  1539. +T11 = 0x1.226e355e6c23c8f5b4f5762322eep-7L,
  1540. +T13 = 0x1.d6d3d0e157ddfb5fed8e84e27b37p-9L,
  1541. +T15 = 0x1.7da36452b75e2b5fce9ee7c2c92ep-10L,
  1542. +T17 = 0x1.355824803674477dfcf726649efep-11L,
  1543. +T19 = 0x1.f57d7734d1656e0aceb716f614c2p-13L,
  1544. +T21 = 0x1.967e18afcb180ed942dfdc518d6cp-14L,
  1545. +T23 = 0x1.497d8eea21e95bc7e2aa79b9f2cdp-15L,
  1546. +T25 = 0x1.0b132d39f055c81be49eff7afd50p-16L,
  1547. +T27 = 0x1.b0f72d33eff7bfa2fbc1059d90b6p-18L,
  1548. +T29 = 0x1.5ef2daf21d1113df38d0fbc00267p-19L,
  1549. +T31 = 0x1.1c77d6eac0234988cdaa04c96626p-20L,
  1550. +T33 = 0x1.cd2a5a292b180e0bdd701057dfe3p-22L,
  1551. +T35 = 0x1.75c7357d0298c01a31d0a6f7d518p-23L,
  1552. +T37 = 0x1.2f3190f4718a9a520f98f50081fcp-24L,
  1553. +pio4 = 0x1.921fb54442d18469898cc51701b8p-1L,
  1554. +pio4lo = 0x1.cd129024e088a67cc74020bbea60p-116L;
  1555. +static const double
  1556. +T39 = 0.000000028443389121318352, /* 0x1e8a7592977938.0p-78 */
  1557. +T41 = 0.000000011981013102001973, /* 0x19baa1b1223219.0p-79 */
  1558. +T43 = 0.0000000038303578044958070, /* 0x107385dfb24529.0p-80 */
  1559. +T45 = 0.0000000034664378216909893, /* 0x1dc6c702a05262.0p-81 */
  1560. +T47 = -0.0000000015090641701997785, /* -0x19ecef3569ebb6.0p-82 */
  1561. +T49 = 0.0000000029449552300483952, /* 0x194c0668da786a.0p-81 */
  1562. +T51 = -0.0000000022006995706097711, /* -0x12e763b8845268.0p-81 */
  1563. +T53 = 0.0000000015468200913196612, /* 0x1a92fc98c29554.0p-82 */
  1564. +T55 = -0.00000000061311613386849674, /* -0x151106cbc779a9.0p-83 */
  1565. +T57 = 1.4912469681508012e-10; /* 0x147edbdba6f43a.0p-85 */
  1566. +#define RPOLY(w) (T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + \
  1567. + w * (T25 + w * (T29 + w * (T33 + w * (T37 + w * (T41 + \
  1568. + w * (T45 + w * (T49 + w * (T53 + w * T57)))))))))))))
  1569. +#define VPOLY(w) (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + \
  1570. + w * (T27 + w * (T31 + w * (T35 + w * (T39 + w * (T43 + \
  1571. + w * (T47 + w * (T51 + w * T55))))))))))))
  1572. +#endif
  1573. long double __tanl(long double x, long double y, int odd) {
  1574. long double z, r, v, w, s, a, t;
  1575. @@ -62,10 +115,8 @@
  1576. }
  1577. z = x * x;
  1578. w = z * z;
  1579. - r = T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 +
  1580. - w * (T25 + w * (T29 + w * T33))))));
  1581. - v = z * (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 +
  1582. - w * (T27 + w * T31))))));
  1583. + r = RPOLY(w);
  1584. + v = z * VPOLY(w);
  1585. s = z * x;
  1586. r = y + z * (s * (r + v) + y) + T3 * s;
  1587. w = x + r;
  1588. @@ -76,7 +127,6 @@
  1589. }
  1590. if (!odd)
  1591. return w;
  1592. -
  1593. /*
  1594. * if allow error up to 2 ulp, simply return
  1595. * -1.0 / (x+r) here
  1596. diff -Nur musl-0.9.13/src/math/acoshf.c musl-git/src/math/acoshf.c
  1597. --- musl-0.9.13/src/math/acoshf.c 2013-08-30 23:30:53.000000000 +0200
  1598. +++ musl-git/src/math/acoshf.c 2013-09-16 20:31:39.000000000 +0200
  1599. @@ -3,14 +3,15 @@
  1600. /* acosh(x) = log(x + sqrt(x*x-1)) */
  1601. float acoshf(float x)
  1602. {
  1603. - union {float f; int32_t i;} u = {.f = x};
  1604. + union {float f; uint32_t i;} u = {x};
  1605. + uint32_t a = u.i & 0x7fffffff;
  1606. - if (u.i < 0x3f800000+(1<<23))
  1607. - /* x < 2, invalid if x < 1 or nan */
  1608. + if (a < 0x3f800000+(1<<23))
  1609. + /* |x| < 2, invalid if x < 1 or nan */
  1610. /* up to 2ulp error in [1,1.125] */
  1611. return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1)));
  1612. - if (u.i < 0x3f800000+(12<<23))
  1613. - /* x < 0x1p12 */
  1614. + if (a < 0x3f800000+(12<<23))
  1615. + /* |x| < 0x1p12 */
  1616. return logf(2*x - 1/(x+sqrtf(x*x-1)));
  1617. /* x >= 0x1p12 */
  1618. return logf(x) + 0.693147180559945309417232121458176568f;
  1619. diff -Nur musl-0.9.13/src/math/acoshl.c musl-git/src/math/acoshl.c
  1620. --- musl-0.9.13/src/math/acoshl.c 2013-08-30 23:30:53.000000000 +0200
  1621. +++ musl-git/src/math/acoshl.c 2013-09-16 20:31:39.000000000 +0200
  1622. @@ -9,16 +9,14 @@
  1623. /* acosh(x) = log(x + sqrt(x*x-1)) */
  1624. long double acoshl(long double x)
  1625. {
  1626. - union {
  1627. - long double f;
  1628. - struct{uint64_t m; int16_t se; uint16_t pad;} i;
  1629. - } u = {.f = x};
  1630. + union ldshape u = {x};
  1631. + int e = u.i.se & 0x7fff;
  1632. - if (u.i.se < 0x3fff + 1)
  1633. - /* x < 2, invalid if x < 1 or nan */
  1634. + if (e < 0x3fff + 1)
  1635. + /* |x| < 2, invalid if x < 1 or nan */
  1636. return log1pl(x-1 + sqrtl((x-1)*(x-1)+2*(x-1)));
  1637. - if (u.i.se < 0x3fff + 32)
  1638. - /* x < 0x1p32 */
  1639. + if (e < 0x3fff + 32)
  1640. + /* |x| < 0x1p32 */
  1641. return logl(2*x - 1/(x+sqrtl(x*x-1)));
  1642. return logl(x) + 0.693147180559945309417232121458176568L;
  1643. }
  1644. diff -Nur musl-0.9.13/src/math/acosl.c musl-git/src/math/acosl.c
  1645. --- musl-0.9.13/src/math/acosl.c 2013-08-30 23:30:53.000000000 +0200
  1646. +++ musl-git/src/math/acosl.c 2013-09-16 20:31:39.000000000 +0200
  1647. @@ -23,46 +23,45 @@
  1648. }
  1649. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  1650. #include "__invtrigl.h"
  1651. +#if LDBL_MANT_DIG == 64
  1652. +#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32)
  1653. +#elif LDBL_MANT_DIG == 113
  1654. +#define CLEARBOTTOM(u) (u.i.lo = 0)
  1655. +#endif
  1656. long double acosl(long double x)
  1657. {
  1658. - union IEEEl2bits u;
  1659. - long double z, w, s, c, df;
  1660. - int16_t expsign, expt;
  1661. - u.e = x;
  1662. - expsign = u.xbits.expsign;
  1663. - expt = expsign & 0x7fff;
  1664. + union ldshape u = {x};
  1665. + long double z, s, c, f;
  1666. + uint16_t e = u.i.se & 0x7fff;
  1667. +
  1668. /* |x| >= 1 or nan */
  1669. - if (expt >= 0x3fff) {
  1670. - if (expt == 0x3fff &&
  1671. - ((u.bits.manh & ~LDBL_NBIT) | u.bits.manl) == 0) {
  1672. - if (expsign > 0)
  1673. - return 0; /* acos(1) = 0 */
  1674. - return 2*pio2_hi + 0x1p-120f; /* acos(-1)= pi */
  1675. - }
  1676. - return 0/(x-x); /* acos(|x|>1) is NaN */
  1677. + if (e >= 0x3fff) {
  1678. + if (x == 1)
  1679. + return 0;
  1680. + if (x == -1)
  1681. + return 2*pio2_hi + 0x1p-120f;
  1682. + return 0/(x-x);
  1683. }
  1684. /* |x| < 0.5 */
  1685. - if (expt < 0x3fff - 1) {
  1686. - if (expt < 0x3fff - 65)
  1687. - return pio2_hi + 0x1p-120f; /* x < 0x1p-65: acosl(x)=pi/2 */
  1688. - return pio2_hi - (x - (pio2_lo - x * __invtrigl_R(x*x)));
  1689. + if (e < 0x3fff - 1) {
  1690. + if (e < 0x3fff - LDBL_MANT_DIG - 1)
  1691. + return pio2_hi + 0x1p-120f;
  1692. + return pio2_hi - (__invtrigl_R(x*x)*x - pio2_lo + x);
  1693. }
  1694. /* x < -0.5 */
  1695. - if (expsign < 0) {
  1696. - z = (1.0 + x) * 0.5;
  1697. + if (u.i.se >> 15) {
  1698. + z = (1 + x)*0.5;
  1699. s = sqrtl(z);
  1700. - w = __invtrigl_R(z) * s - pio2_lo;
  1701. - return 2*(pio2_hi - (s + w));
  1702. + return 2*(pio2_hi - (__invtrigl_R(z)*s - pio2_lo + s));
  1703. }
  1704. /* x > 0.5 */
  1705. - z = (1.0 - x) * 0.5;
  1706. + z = (1 - x)*0.5;
  1707. s = sqrtl(z);
  1708. - u.e = s;
  1709. - u.bits.manl = 0;
  1710. - df = u.e;
  1711. - c = (z - df * df) / (s + df);
  1712. - w = __invtrigl_R(z) * s + c;
  1713. - return 2*(df + w);
  1714. + u.f = s;
  1715. + CLEARBOTTOM(u);
  1716. + f = u.f;
  1717. + c = (z - f*f)/(s + f);
  1718. + return 2*(__invtrigl_R(z)*s + c + f);
  1719. }
  1720. #endif
  1721. diff -Nur musl-0.9.13/src/math/asinhl.c musl-git/src/math/asinhl.c
  1722. --- musl-0.9.13/src/math/asinhl.c 2013-08-30 23:30:53.000000000 +0200
  1723. +++ musl-git/src/math/asinhl.c 2013-09-16 20:31:39.000000000 +0200
  1724. @@ -9,10 +9,7 @@
  1725. /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
  1726. long double asinhl(long double x)
  1727. {
  1728. - union {
  1729. - long double f;
  1730. - struct{uint64_t m; uint16_t se; uint16_t pad;} i;
  1731. - } u = {.f = x};
  1732. + union ldshape u = {x};
  1733. unsigned e = u.i.se & 0x7fff;
  1734. unsigned s = u.i.se >> 15;
  1735. diff -Nur musl-0.9.13/src/math/asinl.c musl-git/src/math/asinl.c
  1736. --- musl-0.9.13/src/math/asinl.c 2013-08-30 23:30:53.000000000 +0200
  1737. +++ musl-git/src/math/asinl.c 2013-09-16 20:31:39.000000000 +0200
  1738. @@ -23,27 +23,29 @@
  1739. }
  1740. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  1741. #include "__invtrigl.h"
  1742. -/* 0.95 */
  1743. -#define THRESH ((0xe666666666666666ULL>>(64-(LDBL_MANH_SIZE-1)))|LDBL_NBIT)
  1744. +#if LDBL_MANT_DIG == 64
  1745. +#define CLOSETO1(u) (u.i.m>>56 >= 0xf7)
  1746. +#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32)
  1747. +#elif LDBL_MANT_DIG == 113
  1748. +#define CLOSETO1(u) (u.i.top >= 0xee00)
  1749. +#define CLEARBOTTOM(u) (u.i.lo = 0)
  1750. +#endif
  1751. long double asinl(long double x)
  1752. {
  1753. - union IEEEl2bits u;
  1754. - long double z,r,s;
  1755. - uint16_t expsign, expt;
  1756. + union ldshape u = {x};
  1757. + long double z, r, s;
  1758. + uint16_t e = u.i.se & 0x7fff;
  1759. + int sign = u.i.se >> 15;
  1760. - u.e = x;
  1761. - expsign = u.xbits.expsign;
  1762. - expt = expsign & 0x7fff;
  1763. - if (expt >= 0x3fff) { /* |x| >= 1 or nan */
  1764. - if (expt == 0x3fff &&
  1765. - ((u.bits.manh&~LDBL_NBIT)|u.bits.manl) == 0)
  1766. - /* asin(+-1)=+-pi/2 with inexact */
  1767. + if (e >= 0x3fff) { /* |x| >= 1 or nan */
  1768. + /* asin(+-1)=+-pi/2 with inexact */
  1769. + if (x == 1 || x == -1)
  1770. return x*pio2_hi + 0x1p-120f;
  1771. return 0/(x-x);
  1772. }
  1773. - if (expt < 0x3fff - 1) { /* |x| < 0.5 */
  1774. - if (expt < 0x3fff - 32) { /* |x|<0x1p-32, asinl(x)=x */
  1775. + if (e < 0x3fff - 1) { /* |x| < 0.5 */
  1776. + if (e < 0x3fff - (LDBL_MANT_DIG+1)/2) {
  1777. /* return x with inexact if x!=0 */
  1778. FORCE_EVAL(x + 0x1p120f);
  1779. return x;
  1780. @@ -54,18 +56,16 @@
  1781. z = (1.0 - fabsl(x))*0.5;
  1782. s = sqrtl(z);
  1783. r = __invtrigl_R(z);
  1784. - if (u.bits.manh >= THRESH) { /* if |x| is close to 1 */
  1785. + if (CLOSETO1(u)) {
  1786. x = pio2_hi - (2*(s+s*r)-pio2_lo);
  1787. } else {
  1788. long double f, c;
  1789. - u.e = s;
  1790. - u.bits.manl = 0;
  1791. - f = u.e;
  1792. - c = (z-f*f)/(s+f);
  1793. + u.f = s;
  1794. + CLEARBOTTOM(u);
  1795. + f = u.f;
  1796. + c = (z - f*f)/(s + f);
  1797. x = 0.5*pio2_hi-(2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f));
  1798. }
  1799. - if (expsign>>15)
  1800. - return -x;
  1801. - return x;
  1802. + return sign ? -x : x;
  1803. }
  1804. #endif
  1805. diff -Nur musl-0.9.13/src/math/atan2l.c musl-git/src/math/atan2l.c
  1806. --- musl-0.9.13/src/math/atan2l.c 2013-08-30 23:30:53.000000000 +0200
  1807. +++ musl-git/src/math/atan2l.c 2013-09-16 20:31:39.000000000 +0200
  1808. @@ -27,56 +27,50 @@
  1809. long double atan2l(long double y, long double x)
  1810. {
  1811. - union IEEEl2bits ux, uy;
  1812. + union ldshape ux, uy;
  1813. long double z;
  1814. - int m;
  1815. - uint16_t exptx, expsignx, expty, expsigny;
  1816. + int m, ex, ey;
  1817. if (isnan(x) || isnan(y))
  1818. return x+y;
  1819. if (x == 1)
  1820. return atanl(y);
  1821. - uy.e = y;
  1822. - expsigny = uy.xbits.expsign;
  1823. - expty = expsigny & 0x7fff;
  1824. - ux.e = x;
  1825. - expsignx = ux.xbits.expsign;
  1826. - exptx = expsignx & 0x7fff;
  1827. - m = ((expsigny>>15)&1) | ((expsignx>>14)&2); /* 2*sign(x)+sign(y) */
  1828. -
  1829. + ux.f = x;
  1830. + uy.f = y;
  1831. + ex = ux.i.se & 0x7fff;
  1832. + ey = uy.i.se & 0x7fff;
  1833. + m = 2*(ux.i.se>>15) | uy.i.se>>15;
  1834. if (y == 0) {
  1835. switch(m) {
  1836. case 0:
  1837. case 1: return y; /* atan(+-0,+anything)=+-0 */
  1838. - case 2: return 2*pio2_hi+0x1p-120f; /* atan(+0,-anything) = pi */
  1839. - case 3: return -2*pio2_hi-0x1p-120f; /* atan(-0,-anything) =-pi */
  1840. + case 2: return 2*pio2_hi; /* atan(+0,-anything) = pi */
  1841. + case 3: return -2*pio2_hi; /* atan(-0,-anything) =-pi */
  1842. }
  1843. }
  1844. if (x == 0)
  1845. - return m&1 ? -pio2_hi-0x1p-120f : pio2_hi+0x1p-120f;
  1846. - /* when x is INF */
  1847. - if (exptx == 0x7fff) {
  1848. - if (expty == 0x7fff) {
  1849. + return m&1 ? -pio2_hi : pio2_hi;
  1850. + if (ex == 0x7fff) {
  1851. + if (ey == 0x7fff) {
  1852. switch(m) {
  1853. - case 0: return pio2_hi*0.5+0x1p-120f; /* atan(+INF,+INF) */
  1854. - case 1: return -pio2_hi*0.5-0x1p-120f; /* atan(-INF,+INF) */
  1855. - case 2: return 1.5*pio2_hi+0x1p-120f; /* atan(+INF,-INF) */
  1856. - case 3: return -1.5*pio2_hi-0x1p-120f; /* atan(-INF,-INF) */
  1857. + case 0: return pio2_hi/2; /* atan(+INF,+INF) */
  1858. + case 1: return -pio2_hi/2; /* atan(-INF,+INF) */
  1859. + case 2: return 1.5*pio2_hi; /* atan(+INF,-INF) */
  1860. + case 3: return -1.5*pio2_hi; /* atan(-INF,-INF) */
  1861. }
  1862. } else {
  1863. switch(m) {
  1864. case 0: return 0.0; /* atan(+...,+INF) */
  1865. case 1: return -0.0; /* atan(-...,+INF) */
  1866. - case 2: return 2*pio2_hi+0x1p-120f; /* atan(+...,-INF) */
  1867. - case 3: return -2*pio2_hi-0x1p-120f; /* atan(-...,-INF) */
  1868. + case 2: return 2*pio2_hi; /* atan(+...,-INF) */
  1869. + case 3: return -2*pio2_hi; /* atan(-...,-INF) */
  1870. }
  1871. }
  1872. }
  1873. - /* when y is INF */
  1874. - if (exptx+120 < expty || expty == 0x7fff)
  1875. - return m&1 ? -pio2_hi-0x1p-120f : pio2_hi+0x1p-120f;
  1876. -
  1877. - if ((m&2) && expty+120 < exptx) /* |y/x| tiny, x<0 */
  1878. + if (ex+120 < ey || ey == 0x7fff)
  1879. + return m&1 ? -pio2_hi : pio2_hi;
  1880. + /* z = atan(|y/x|) without spurious underflow */
  1881. + if ((m&2) && ey+120 < ex) /* |y/x| < 0x1p-120, x<0 */
  1882. z = 0.0;
  1883. else
  1884. z = atanl(fabsl(y/x));
  1885. diff -Nur musl-0.9.13/src/math/atanh.c musl-git/src/math/atanh.c
  1886. --- musl-0.9.13/src/math/atanh.c 2013-08-30 23:30:53.000000000 +0200
  1887. +++ musl-git/src/math/atanh.c 2013-09-16 20:31:39.000000000 +0200
  1888. @@ -6,16 +6,24 @@
  1889. union {double f; uint64_t i;} u = {.f = x};
  1890. unsigned e = u.i >> 52 & 0x7ff;
  1891. unsigned s = u.i >> 63;
  1892. + double_t y;
  1893. /* |x| */
  1894. u.i &= (uint64_t)-1/2;
  1895. - x = u.f;
  1896. + y = u.f;
  1897. if (e < 0x3ff - 1) {
  1898. - /* |x| < 0.5, up to 1.7ulp error */
  1899. - x = 0.5*log1p(2*x + 2*x*x/(1-x));
  1900. + if (e < 0x3ff - 32) {
  1901. + /* handle underflow */
  1902. + if (e == 0)
  1903. + FORCE_EVAL((float)y);
  1904. + } else {
  1905. + /* |x| < 0.5, up to 1.7ulp error */
  1906. + y = 0.5*log1p(2*y + 2*y*y/(1-y));
  1907. + }
  1908. } else {
  1909. - x = 0.5*log1p(2*x/(1-x));
  1910. + /* avoid overflow */
  1911. + y = 0.5*log1p(2*(y/(1-y)));
  1912. }
  1913. - return s ? -x : x;
  1914. + return s ? -y : y;
  1915. }
  1916. diff -Nur musl-0.9.13/src/math/atanhf.c musl-git/src/math/atanhf.c
  1917. --- musl-0.9.13/src/math/atanhf.c 2013-08-30 23:30:53.000000000 +0200
  1918. +++ musl-git/src/math/atanhf.c 2013-09-16 20:31:39.000000000 +0200
  1919. @@ -5,16 +5,24 @@
  1920. {
  1921. union {float f; uint32_t i;} u = {.f = x};
  1922. unsigned s = u.i >> 31;
  1923. + float_t y;
  1924. /* |x| */
  1925. u.i &= 0x7fffffff;
  1926. - x = u.f;
  1927. + y = u.f;
  1928. if (u.i < 0x3f800000 - (1<<23)) {
  1929. - /* |x| < 0.5, up to 1.7ulp error */
  1930. - x = 0.5f*log1pf(2*x + 2*x*x/(1-x));
  1931. + if (u.i < 0x3f800000 - (32<<23)) {
  1932. + /* handle underflow */
  1933. + if (u.i < (1<<23))
  1934. + FORCE_EVAL((float)(y*y));
  1935. + } else {
  1936. + /* |x| < 0.5, up to 1.7ulp error */
  1937. + y = 0.5f*log1pf(2*y + 2*y*y/(1-y));
  1938. + }
  1939. } else {
  1940. - x = 0.5f*log1pf(2*x/(1-x));
  1941. + /* avoid overflow */
  1942. + y = 0.5f*log1pf(2*(y/(1-y)));
  1943. }
  1944. - return s ? -x : x;
  1945. + return s ? -y : y;
  1946. }
  1947. diff -Nur musl-0.9.13/src/math/atanhl.c musl-git/src/math/atanhl.c
  1948. --- musl-0.9.13/src/math/atanhl.c 2013-08-30 23:30:53.000000000 +0200
  1949. +++ musl-git/src/math/atanhl.c 2013-09-16 20:31:39.000000000 +0200
  1950. @@ -9,10 +9,7 @@
  1951. /* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */
  1952. long double atanhl(long double x)
  1953. {
  1954. - union {
  1955. - long double f;
  1956. - struct{uint64_t m; uint16_t se; uint16_t pad;} i;
  1957. - } u = {.f = x};
  1958. + union ldshape u = {x};
  1959. unsigned e = u.i.se & 0x7fff;
  1960. unsigned s = u.i.se >> 15;
  1961. @@ -20,11 +17,18 @@
  1962. u.i.se = e;
  1963. x = u.f;
  1964. - if (e < 0x3fff - 1) {
  1965. - /* |x| < 0.5, up to 1.7ulp error */
  1966. - x = 0.5*log1pl(2*x + 2*x*x/(1-x));
  1967. + if (e < 0x3ff - 1) {
  1968. + if (e < 0x3ff - LDBL_MANT_DIG/2) {
  1969. + /* handle underflow */
  1970. + if (e == 0)
  1971. + FORCE_EVAL((float)x);
  1972. + } else {
  1973. + /* |x| < 0.5, up to 1.7ulp error */
  1974. + x = 0.5*log1pl(2*x + 2*x*x/(1-x));
  1975. + }
  1976. } else {
  1977. - x = 0.5*log1pl(2*x/(1-x));
  1978. + /* avoid overflow */
  1979. + x = 0.5*log1pl(2*(x/(1-x)));
  1980. }
  1981. return s ? -x : x;
  1982. }
  1983. diff -Nur musl-0.9.13/src/math/atanl.c musl-git/src/math/atanl.c
  1984. --- musl-0.9.13/src/math/atanl.c 2013-08-30 23:30:53.000000000 +0200
  1985. +++ musl-git/src/math/atanl.c 2013-09-16 20:31:39.000000000 +0200
  1986. @@ -23,6 +23,9 @@
  1987. }
  1988. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  1989. +#if LDBL_MANT_DIG == 64
  1990. +#define EXPMAN(u) ((u.i.se & 0x7fff)<<8 | (u.i.m>>55 & 0xff))
  1991. +
  1992. static const long double atanhi[] = {
  1993. 4.63647609000806116202e-01L,
  1994. 7.85398163397448309628e-01L,
  1995. @@ -64,32 +67,85 @@
  1996. return aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] +
  1997. x * (aT[9] + x * aT[11]))));
  1998. }
  1999. +#elif LDBL_MANT_DIG == 113
  2000. +#define EXPMAN(u) ((u.i.se & 0x7fff)<<8 | u.i.top>>8)
  2001. +
  2002. +const long double atanhi[] = {
  2003. + 4.63647609000806116214256231461214397e-01L,
  2004. + 7.85398163397448309615660845819875699e-01L,
  2005. + 9.82793723247329067985710611014666038e-01L,
  2006. + 1.57079632679489661923132169163975140e+00L,
  2007. +};
  2008. +
  2009. +const long double atanlo[] = {
  2010. + 4.89509642257333492668618435220297706e-36L,
  2011. + 2.16795253253094525619926100651083806e-35L,
  2012. + -2.31288434538183565909319952098066272e-35L,
  2013. + 4.33590506506189051239852201302167613e-35L,
  2014. +};
  2015. +
  2016. +const long double aT[] = {
  2017. + 3.33333333333333333333333333333333125e-01L,
  2018. + -1.99999999999999999999999999999180430e-01L,
  2019. + 1.42857142857142857142857142125269827e-01L,
  2020. + -1.11111111111111111111110834490810169e-01L,
  2021. + 9.09090909090909090908522355708623681e-02L,
  2022. + -7.69230769230769230696553844935357021e-02L,
  2023. + 6.66666666666666660390096773046256096e-02L,
  2024. + -5.88235294117646671706582985209643694e-02L,
  2025. + 5.26315789473666478515847092020327506e-02L,
  2026. + -4.76190476189855517021024424991436144e-02L,
  2027. + 4.34782608678695085948531993458097026e-02L,
  2028. + -3.99999999632663469330634215991142368e-02L,
  2029. + 3.70370363987423702891250829918659723e-02L,
  2030. + -3.44827496515048090726669907612335954e-02L,
  2031. + 3.22579620681420149871973710852268528e-02L,
  2032. + -3.03020767654269261041647570626778067e-02L,
  2033. + 2.85641979882534783223403715930946138e-02L,
  2034. + -2.69824879726738568189929461383741323e-02L,
  2035. + 2.54194698498808542954187110873675769e-02L,
  2036. + -2.35083879708189059926183138130183215e-02L,
  2037. + 2.04832358998165364349957325067131428e-02L,
  2038. + -1.54489555488544397858507248612362957e-02L,
  2039. + 8.64492360989278761493037861575248038e-03L,
  2040. + -2.58521121597609872727919154569765469e-03L,
  2041. +};
  2042. +
  2043. +static long double T_even(long double x)
  2044. +{
  2045. + return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * (aT[8] +
  2046. + x * (aT[10] + x * (aT[12] + x * (aT[14] + x * (aT[16] +
  2047. + x * (aT[18] + x * (aT[20] + x * aT[22])))))))))));
  2048. +}
  2049. +
  2050. +static long double T_odd(long double x)
  2051. +{
  2052. + return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * (aT[9] +
  2053. + x * (aT[11] + x * (aT[13] + x * (aT[15] + x * (aT[17] +
  2054. + x * (aT[19] + x * (aT[21] + x * aT[23])))))))))));
  2055. +}
  2056. +#endif
  2057. long double atanl(long double x)
  2058. {
  2059. - union IEEEl2bits u;
  2060. - long double w,s1,s2,z;
  2061. + union ldshape u = {x};
  2062. + long double w, s1, s2, z;
  2063. int id;
  2064. - uint16_t expsign, expt;
  2065. - uint32_t expman;
  2066. + unsigned e = u.i.se & 0x7fff;
  2067. + unsigned sign = u.i.se >> 15;
  2068. + unsigned expman;
  2069. - u.e = x;
  2070. - expsign = u.xbits.expsign;
  2071. - expt = expsign & 0x7fff;
  2072. - if (expt >= 0x3fff + 65) { /* if |x| is large, atan(x)~=pi/2 */
  2073. - if (expt == 0x7fff &&
  2074. - ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)!=0) /* NaN */
  2075. - return x+x;
  2076. - z = atanhi[3] + 0x1p-120f;
  2077. - return expsign>>15 ? -z : z;
  2078. + if (e >= 0x3fff + LDBL_MANT_DIG + 1) { /* if |x| is large, atan(x)~=pi/2 */
  2079. + if (isnan(x))
  2080. + return x;
  2081. + return sign ? -atanhi[3] : atanhi[3];
  2082. }
  2083. /* Extract the exponent and the first few bits of the mantissa. */
  2084. - /* XXX There should be a more convenient way to do this. */
  2085. - expman = (expt << 8) | ((u.bits.manh >> (LDBL_MANH_SIZE - 9)) & 0xff);
  2086. + expman = EXPMAN(u);
  2087. if (expman < ((0x3fff - 2) << 8) + 0xc0) { /* |x| < 0.4375 */
  2088. - if (expt < 0x3fff - 32) { /* if |x| is small, atanl(x)~=x */
  2089. + if (e < 0x3fff - (LDBL_MANT_DIG+1)/2) { /* if |x| is small, atanl(x)~=x */
  2090. /* raise underflow if subnormal */
  2091. - if (expt == 0)
  2092. + if (e == 0)
  2093. FORCE_EVAL((float)x);
  2094. return x;
  2095. }
  2096. @@ -108,7 +164,7 @@
  2097. if (expman < ((0x3fff + 1) << 8) + 0x38) { /* |x| < 2.4375 */
  2098. id = 2;
  2099. x = (x-1.5)/(1.0+1.5*x);
  2100. - } else { /* 2.4375 <= |x| < 2^ATAN_CONST */
  2101. + } else { /* 2.4375 <= |x| */
  2102. id = 3;
  2103. x = -1.0/x;
  2104. }
  2105. @@ -123,6 +179,6 @@
  2106. if (id < 0)
  2107. return x - x*(s1+s2);
  2108. z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
  2109. - return expsign>>15 ? -z : z;
  2110. + return sign ? -z : z;
  2111. }
  2112. #endif
  2113. diff -Nur musl-0.9.13/src/math/cbrt.c musl-git/src/math/cbrt.c
  2114. --- musl-0.9.13/src/math/cbrt.c 2013-08-30 23:30:53.000000000 +0200
  2115. +++ musl-git/src/math/cbrt.c 2013-09-16 20:31:39.000000000 +0200
  2116. @@ -15,7 +15,8 @@
  2117. * Return cube root of x
  2118. */
  2119. -#include "libm.h"
  2120. +#include <math.h>
  2121. +#include <stdint.h>
  2122. static const uint32_t
  2123. B1 = 715094163, /* B1 = (1023-1023/3-0.03306235651)*2**20 */
  2124. @@ -31,15 +32,10 @@
  2125. double cbrt(double x)
  2126. {
  2127. - int32_t hx;
  2128. - union dshape u;
  2129. - double r,s,t=0.0,w;
  2130. - uint32_t sign;
  2131. - uint32_t high,low;
  2132. -
  2133. - EXTRACT_WORDS(hx, low, x);
  2134. - sign = hx & 0x80000000;
  2135. - hx ^= sign;
  2136. + union {double f; uint64_t i;} u = {x};
  2137. + double_t r,s,t,w;
  2138. + uint32_t hx = u.i>>32 & 0x7fffffff;
  2139. +
  2140. if (hx >= 0x7ff00000) /* cbrt(NaN,INF) is itself */
  2141. return x+x;
  2142. @@ -59,14 +55,16 @@
  2143. * division rounds towards minus infinity; this is also efficient.
  2144. */
  2145. if (hx < 0x00100000) { /* zero or subnormal? */
  2146. - if ((hx|low) == 0)
  2147. + u.f = x*0x1p54;
  2148. + hx = u.i>>32 & 0x7fffffff;
  2149. + if (hx == 0)
  2150. return x; /* cbrt(0) is itself */
  2151. - SET_HIGH_WORD(t, 0x43500000); /* set t = 2**54 */
  2152. - t *= x;
  2153. - GET_HIGH_WORD(high, t);
  2154. - INSERT_WORDS(t, sign|((high&0x7fffffff)/3+B2), 0);
  2155. + hx = hx/3 + B2;
  2156. } else
  2157. - INSERT_WORDS(t, sign|(hx/3+B1), 0);
  2158. + hx = hx/3 + B1;
  2159. + u.i &= 1ULL<<63;
  2160. + u.i |= (uint64_t)hx << 32;
  2161. + t = u.f;
  2162. /*
  2163. * New cbrt to 23 bits:
  2164. @@ -76,7 +74,7 @@
  2165. * has produced t such than |t/cbrt(x) - 1| ~< 1/32, and cubing this
  2166. * gives us bounds for r = t**3/x.
  2167. *
  2168. - * Try to optimize for parallel evaluation as in k_tanf.c.
  2169. + * Try to optimize for parallel evaluation as in __tanf.c.
  2170. */
  2171. r = (t*t)*(t/x);
  2172. t = t*((P0+r*(P1+r*P2))+((r*r)*r)*(P3+r*P4));
  2173. @@ -91,9 +89,9 @@
  2174. * 0.667; the error in the rounded t can be up to about 3 23-bit ulps
  2175. * before the final error is larger than 0.667 ulps.
  2176. */
  2177. - u.value = t;
  2178. - u.bits = (u.bits + 0x80000000) & 0xffffffffc0000000ULL;
  2179. - t = u.value;
  2180. + u.f = t;
  2181. + u.i = (u.i + 0x80000000) & 0xffffffffc0000000ULL;
  2182. + t = u.f;
  2183. /* one step Newton iteration to 53 bits with error < 0.667 ulps */
  2184. s = t*t; /* t*t is exact */
  2185. diff -Nur musl-0.9.13/src/math/cbrtf.c musl-git/src/math/cbrtf.c
  2186. --- musl-0.9.13/src/math/cbrtf.c 2013-08-30 23:30:53.000000000 +0200
  2187. +++ musl-git/src/math/cbrtf.c 2013-09-16 20:31:39.000000000 +0200
  2188. @@ -17,7 +17,8 @@
  2189. * Return cube root of x
  2190. */
  2191. -#include "libm.h"
  2192. +#include <math.h>
  2193. +#include <stdint.h>
  2194. static const unsigned
  2195. B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */
  2196. @@ -25,15 +26,10 @@
  2197. float cbrtf(float x)
  2198. {
  2199. - double r,T;
  2200. - float t;
  2201. - int32_t hx;
  2202. - uint32_t sign;
  2203. - uint32_t high;
  2204. -
  2205. - GET_FLOAT_WORD(hx, x);
  2206. - sign = hx & 0x80000000;
  2207. - hx ^= sign;
  2208. + double_t r,T;
  2209. + union {float f; uint32_t i;} u = {x};
  2210. + uint32_t hx = u.i & 0x7fffffff;
  2211. +
  2212. if (hx >= 0x7f800000) /* cbrt(NaN,INF) is itself */
  2213. return x + x;
  2214. @@ -41,28 +37,29 @@
  2215. if (hx < 0x00800000) { /* zero or subnormal? */
  2216. if (hx == 0)
  2217. return x; /* cbrt(+-0) is itself */
  2218. - SET_FLOAT_WORD(t, 0x4b800000); /* set t = 2**24 */
  2219. - t *= x;
  2220. - GET_FLOAT_WORD(high, t);
  2221. - SET_FLOAT_WORD(t, sign|((high&0x7fffffff)/3+B2));
  2222. + u.f = x*0x1p24f;
  2223. + hx = u.i & 0x7fffffff;
  2224. + hx = hx/3 + B2;
  2225. } else
  2226. - SET_FLOAT_WORD(t, sign|(hx/3+B1));
  2227. + hx = hx/3 + B1;
  2228. + u.i &= 0x80000000;
  2229. + u.i |= hx;
  2230. /*
  2231. * First step Newton iteration (solving t*t-x/t == 0) to 16 bits. In
  2232. * double precision so that its terms can be arranged for efficiency
  2233. * without causing overflow or underflow.
  2234. */
  2235. - T = t;
  2236. + T = u.f;
  2237. r = T*T*T;
  2238. - T = T*((double)x+x+r)/(x+r+r);
  2239. + T = T*((double_t)x+x+r)/(x+r+r);
  2240. /*
  2241. * Second step Newton iteration to 47 bits. In double precision for
  2242. * efficiency and accuracy.
  2243. */
  2244. r = T*T*T;
  2245. - T = T*((double)x+x+r)/(x+r+r);
  2246. + T = T*((double_t)x+x+r)/(x+r+r);
  2247. /* rounding to 24 bits is perfect in round-to-nearest mode */
  2248. return T;
  2249. diff -Nur musl-0.9.13/src/math/cbrtl.c musl-git/src/math/cbrtl.c
  2250. --- musl-0.9.13/src/math/cbrtl.c 2013-08-30 23:30:53.000000000 +0200
  2251. +++ musl-git/src/math/cbrtl.c 2013-09-16 20:31:39.000000000 +0200
  2252. @@ -23,58 +23,50 @@
  2253. return cbrt(x);
  2254. }
  2255. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  2256. -
  2257. -#define BIAS (LDBL_MAX_EXP - 1)
  2258. static const unsigned B1 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */
  2259. long double cbrtl(long double x)
  2260. {
  2261. - union IEEEl2bits u, v;
  2262. + union ldshape u = {x}, v;
  2263. + union {float f; uint32_t i;} uft;
  2264. long double r, s, t, w;
  2265. - double dr, dt, dx;
  2266. - float ft, fx;
  2267. - uint32_t hx;
  2268. - uint16_t expsign;
  2269. - int k;
  2270. -
  2271. - u.e = x;
  2272. - expsign = u.xbits.expsign;
  2273. - k = expsign & 0x7fff;
  2274. + double_t dr, dt, dx;
  2275. + float_t ft;
  2276. + int e = u.i.se & 0x7fff;
  2277. + int sign = u.i.se & 0x8000;
  2278. /*
  2279. * If x = +-Inf, then cbrt(x) = +-Inf.
  2280. * If x = NaN, then cbrt(x) = NaN.
  2281. */
  2282. - if (k == BIAS + LDBL_MAX_EXP)
  2283. + if (e == 0x7fff)
  2284. return x + x;
  2285. -
  2286. - if (k == 0) {
  2287. + if (e == 0) {
  2288. + /* Adjust subnormal numbers. */
  2289. + u.f *= 0x1p120;
  2290. + e = u.i.se & 0x7fff;
  2291. /* If x = +-0, then cbrt(x) = +-0. */
  2292. - if ((u.bits.manh | u.bits.manl) == 0)
  2293. + if (e == 0)
  2294. return x;
  2295. - /* Adjust subnormal numbers. */
  2296. - u.e *= 0x1.0p514;
  2297. - k = u.bits.exp;
  2298. - k -= BIAS + 514;
  2299. - } else
  2300. - k -= BIAS;
  2301. - u.xbits.expsign = BIAS;
  2302. - v.e = 1;
  2303. -
  2304. - x = u.e;
  2305. - switch (k % 3) {
  2306. + e -= 120;
  2307. + }
  2308. + e -= 0x3fff;
  2309. + u.i.se = 0x3fff;
  2310. + x = u.f;
  2311. + switch (e % 3) {
  2312. case 1:
  2313. case -2:
  2314. - x = 2*x;
  2315. - k--;
  2316. + x *= 2;
  2317. + e--;
  2318. break;
  2319. case 2:
  2320. case -1:
  2321. - x = 4*x;
  2322. - k -= 2;
  2323. + x *= 4;
  2324. + e -= 2;
  2325. break;
  2326. }
  2327. - v.xbits.expsign = (expsign & 0x8000) | (BIAS + k / 3);
  2328. + v.f = 1.0;
  2329. + v.i.se = sign | (0x3fff + e/3);
  2330. /*
  2331. * The following is the guts of s_cbrtf, with the handling of
  2332. @@ -83,9 +75,9 @@
  2333. */
  2334. /* ~5-bit estimate: */
  2335. - fx = x;
  2336. - GET_FLOAT_WORD(hx, fx);
  2337. - SET_FLOAT_WORD(ft, ((hx & 0x7fffffff) / 3 + B1));
  2338. + uft.f = x;
  2339. + uft.i = (uft.i & 0x7fffffff)/3 + B1;
  2340. + ft = uft.f;
  2341. /* ~16-bit estimate: */
  2342. dx = x;
  2343. @@ -126,7 +118,7 @@
  2344. r = (r-t)/(w+r); /* r-t is exact; w+r ~= 3*t */
  2345. t = t+t*r; /* error <= 0.5 + 0.5/3 + epsilon */
  2346. - t *= v.e;
  2347. + t *= v.f;
  2348. return t;
  2349. }
  2350. #endif
  2351. diff -Nur musl-0.9.13/src/math/ceil.c musl-git/src/math/ceil.c
  2352. --- musl-0.9.13/src/math/ceil.c 2013-08-30 23:30:53.000000000 +0200
  2353. +++ musl-git/src/math/ceil.c 2013-09-16 20:31:39.000000000 +0200
  2354. @@ -1,82 +1,24 @@
  2355. -/* origin: FreeBSD /usr/src/lib/msun/src/s_ceil.c */
  2356. -/*
  2357. - * ====================================================
  2358. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  2359. - *
  2360. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  2361. - * Permission to use, copy, modify, and distribute this
  2362. - * software is freely granted, provided that this notice
  2363. - * is preserved.
  2364. - * ====================================================
  2365. - */
  2366. -/*
  2367. - * ceil(x)
  2368. - * Return x rounded toward -inf to integral value
  2369. - * Method:
  2370. - * Bit twiddling.
  2371. - * Exception:
  2372. - * Inexact flag raised if x not equal to ceil(x).
  2373. - */
  2374. -
  2375. #include "libm.h"
  2376. -static const double huge = 1.0e300;
  2377. -
  2378. double ceil(double x)
  2379. {
  2380. - int32_t i0,i1,j0;
  2381. - uint32_t i,j;
  2382. + union {double f; uint64_t i;} u = {x};
  2383. + int e = u.i >> 52 & 0x7ff;
  2384. + double_t y;
  2385. - EXTRACT_WORDS(i0, i1, x);
  2386. - // FIXME signed shift
  2387. - j0 = ((i0>>20)&0x7ff) - 0x3ff;
  2388. - if (j0 < 20) {
  2389. - if (j0 < 0) {
  2390. - /* raise inexact if x != 0 */
  2391. - if (huge+x > 0.0) {
  2392. - if (i0 < 0) {
  2393. - i0 = 0x80000000;
  2394. - i1=0;
  2395. - } else if ((i0|i1) != 0) {
  2396. - i0=0x3ff00000;
  2397. - i1=0;
  2398. - }
  2399. - }
  2400. - } else {
  2401. - i = 0x000fffff>>j0;
  2402. - if (((i0&i)|i1) == 0) /* x is integral */
  2403. - return x;
  2404. - /* raise inexact flag */
  2405. - if (huge+x > 0.0) {
  2406. - if (i0 > 0)
  2407. - i0 += 0x00100000>>j0;
  2408. - i0 &= ~i;
  2409. - i1 = 0;
  2410. - }
  2411. - }
  2412. - } else if (j0 > 51) {
  2413. - if (j0 == 0x400) /* inf or NaN */
  2414. - return x+x;
  2415. - return x; /* x is integral */
  2416. - } else {
  2417. - i = (uint32_t)0xffffffff>>(j0-20);
  2418. - if ((i1&i) == 0)
  2419. - return x; /* x is integral */
  2420. - /* raise inexact flag */
  2421. - if (huge+x > 0.0) {
  2422. - if (i0 > 0) {
  2423. - if (j0 == 20)
  2424. - i0 += 1;
  2425. - else {
  2426. - j = i1 + (1<<(52-j0));
  2427. - if (j < i1) /* got a carry */
  2428. - i0 += 1;
  2429. - i1 = j;
  2430. - }
  2431. - }
  2432. - i1 &= ~i;
  2433. - }
  2434. + if (e >= 0x3ff+52 || x == 0)
  2435. + return x;
  2436. + /* y = int(x) - x, where int(x) is an integer neighbor of x */
  2437. + if (u.i >> 63)
  2438. + y = (double)(x - 0x1p52) + 0x1p52 - x;
  2439. + else
  2440. + y = (double)(x + 0x1p52) - 0x1p52 - x;
  2441. + /* special case because of non-nearest rounding modes */
  2442. + if (e <= 0x3ff-1) {
  2443. + FORCE_EVAL(y);
  2444. + return u.i >> 63 ? -0.0 : 1;
  2445. }
  2446. - INSERT_WORDS(x, i0, i1);
  2447. - return x;
  2448. + if (y < 0)
  2449. + return x + y + 1;
  2450. + return x + y;
  2451. }
  2452. diff -Nur musl-0.9.13/src/math/ceilf.c musl-git/src/math/ceilf.c
  2453. --- musl-0.9.13/src/math/ceilf.c 2013-08-30 23:30:53.000000000 +0200
  2454. +++ musl-git/src/math/ceilf.c 2013-09-16 20:31:39.000000000 +0200
  2455. @@ -1,54 +1,27 @@
  2456. -/* origin: FreeBSD /usr/src/lib/msun/src/s_ceilf.c */
  2457. -/*
  2458. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  2459. - */
  2460. -/*
  2461. - * ====================================================
  2462. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  2463. - *
  2464. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  2465. - * Permission to use, copy, modify, and distribute this
  2466. - * software is freely granted, provided that this notice
  2467. - * is preserved.
  2468. - * ====================================================
  2469. - */
  2470. -
  2471. #include "libm.h"
  2472. -static const float huge = 1.0e30;
  2473. -
  2474. float ceilf(float x)
  2475. {
  2476. - int32_t i0,j0;
  2477. - uint32_t i;
  2478. + union {float f; uint32_t i;} u = {x};
  2479. + int e = (int)(u.i >> 23 & 0xff) - 0x7f;
  2480. + uint32_t m;
  2481. - GET_FLOAT_WORD(i0, x);
  2482. - j0 = ((i0>>23)&0xff) - 0x7f;
  2483. - if (j0 < 23) {
  2484. - if (j0 < 0) {
  2485. - /* raise inexact if x != 0 */
  2486. - if (huge+x > 0.0f) {
  2487. - if (i0 < 0)
  2488. - i0 = 0x80000000;
  2489. - else if(i0 != 0)
  2490. - i0 = 0x3f800000;
  2491. - }
  2492. - } else {
  2493. - i = 0x007fffff>>j0;
  2494. - if ((i0&i) == 0)
  2495. - return x; /* x is integral */
  2496. - /* raise inexact flag */
  2497. - if (huge+x > 0.0f) {
  2498. - if (i0 > 0)
  2499. - i0 += 0x00800000>>j0;
  2500. - i0 &= ~i;
  2501. - }
  2502. - }
  2503. + if (e >= 23)
  2504. + return x;
  2505. + if (e >= 0) {
  2506. + m = 0x007fffff >> e;
  2507. + if ((u.i & m) == 0)
  2508. + return x;
  2509. + FORCE_EVAL(x + 0x1p120f);
  2510. + if (u.i >> 31 == 0)
  2511. + u.i += m;
  2512. + u.i &= ~m;
  2513. } else {
  2514. - if (j0 == 0x80) /* inf or NaN */
  2515. - return x+x;
  2516. - return x; /* x is integral */
  2517. + FORCE_EVAL(x + 0x1p120f);
  2518. + if (u.i >> 31)
  2519. + u.f = -0.0;
  2520. + else if (u.i << 1)
  2521. + u.f = 1.0;
  2522. }
  2523. - SET_FLOAT_WORD(x, i0);
  2524. - return x;
  2525. + return u.f;
  2526. }
  2527. diff -Nur musl-0.9.13/src/math/ceill.c musl-git/src/math/ceill.c
  2528. --- musl-0.9.13/src/math/ceill.c 2013-08-30 23:30:53.000000000 +0200
  2529. +++ musl-git/src/math/ceill.c 2013-09-16 20:31:39.000000000 +0200
  2530. @@ -1,23 +1,3 @@
  2531. -/* origin: FreeBSD /usr/src/lib/msun/src/s_ceill.c */
  2532. -/*
  2533. - * ====================================================
  2534. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  2535. - *
  2536. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  2537. - * Permission to use, copy, modify, and distribute this
  2538. - * software is freely granted, provided that this notice
  2539. - * is preserved.
  2540. - * ====================================================
  2541. - */
  2542. -/*
  2543. - * ceill(x)
  2544. - * Return x rounded toward -inf to integral value
  2545. - * Method:
  2546. - * Bit twiddling.
  2547. - * Exception:
  2548. - * Inexact flag raised if x not equal to ceill(x).
  2549. - */
  2550. -
  2551. #include "libm.h"
  2552. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  2553. @@ -26,77 +6,31 @@
  2554. return ceil(x);
  2555. }
  2556. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  2557. -
  2558. -#ifdef LDBL_IMPLICIT_NBIT
  2559. -#define MANH_SIZE (LDBL_MANH_SIZE + 1)
  2560. -#define INC_MANH(u, c) do { \
  2561. - uint64_t o = u.bits.manh; \
  2562. - u.bits.manh += (c); \
  2563. - if (u.bits.manh < o) \
  2564. - u.bits.exp++; \
  2565. -} while (0)
  2566. -#else
  2567. -#define MANH_SIZE LDBL_MANH_SIZE
  2568. -#define INC_MANH(u, c) do { \
  2569. - uint64_t o = u.bits.manh; \
  2570. - u.bits.manh += (c); \
  2571. - if (u.bits.manh < o) { \
  2572. - u.bits.exp++; \
  2573. - u.bits.manh |= 1llu << (LDBL_MANH_SIZE - 1); \
  2574. - } \
  2575. -} while (0)
  2576. +#if LDBL_MANT_DIG == 64
  2577. +#define TOINT 0x1p63
  2578. +#elif LDBL_MANT_DIG == 113
  2579. +#define TOINT 0x1p112
  2580. #endif
  2581. -
  2582. -static const long double huge = 1.0e300;
  2583. -
  2584. long double ceill(long double x)
  2585. {
  2586. - union IEEEl2bits u = { .e = x };
  2587. - int e = u.bits.exp - LDBL_MAX_EXP + 1;
  2588. -
  2589. - if (e < MANH_SIZE - 1) {
  2590. - if (e < 0) {
  2591. - /* raise inexact if x != 0 */
  2592. - if (huge + x > 0.0)
  2593. - if (u.bits.exp > 0 ||
  2594. - (u.bits.manh | u.bits.manl) != 0)
  2595. - u.e = u.bits.sign ? -0.0 : 1.0;
  2596. - } else {
  2597. - uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
  2598. - if (((u.bits.manh & m) | u.bits.manl) == 0)
  2599. - return x; /* x is integral */
  2600. - if (!u.bits.sign) {
  2601. -#ifdef LDBL_IMPLICIT_NBIT
  2602. - if (e == 0)
  2603. - u.bits.exp++;
  2604. - else
  2605. -#endif
  2606. - INC_MANH(u, 1llu << (MANH_SIZE - e - 1));
  2607. - }
  2608. - /* raise inexact flag */
  2609. - if (huge + x > 0.0) {
  2610. - u.bits.manh &= ~m;
  2611. - u.bits.manl = 0;
  2612. - }
  2613. - }
  2614. - } else if (e < LDBL_MANT_DIG - 1) {
  2615. - uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
  2616. - if ((u.bits.manl & m) == 0)
  2617. - return x; /* x is integral */
  2618. - if (!u.bits.sign) {
  2619. - if (e == MANH_SIZE - 1)
  2620. - INC_MANH(u, 1);
  2621. - else {
  2622. - uint64_t o = u.bits.manl;
  2623. - u.bits.manl += 1llu << (LDBL_MANT_DIG - e - 1);
  2624. - if (u.bits.manl < o) /* got a carry */
  2625. - INC_MANH(u, 1);
  2626. - }
  2627. - }
  2628. - /* raise inexact flag */
  2629. - if (huge + x > 0.0)
  2630. - u.bits.manl &= ~m;
  2631. + union ldshape u = {x};
  2632. + int e = u.i.se & 0x7fff;
  2633. + long double y;
  2634. +
  2635. + if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0)
  2636. + return x;
  2637. + /* y = int(x) - x, where int(x) is an integer neighbor of x */
  2638. + if (u.i.se >> 15)
  2639. + y = x - TOINT + TOINT - x;
  2640. + else
  2641. + y = x + TOINT - TOINT - x;
  2642. + /* special case because of non-nearest rounding modes */
  2643. + if (e <= 0x3fff-1) {
  2644. + FORCE_EVAL(y);
  2645. + return u.i.se >> 15 ? -0.0 : 1;
  2646. }
  2647. - return u.e;
  2648. + if (y < 0)
  2649. + return x + y + 1;
  2650. + return x + y;
  2651. }
  2652. #endif
  2653. diff -Nur musl-0.9.13/src/math/copysign.c musl-git/src/math/copysign.c
  2654. --- musl-0.9.13/src/math/copysign.c 2013-08-30 23:30:53.000000000 +0200
  2655. +++ musl-git/src/math/copysign.c 2013-09-16 20:31:39.000000000 +0200
  2656. @@ -1,11 +1,8 @@
  2657. #include "libm.h"
  2658. double copysign(double x, double y) {
  2659. - union dshape ux, uy;
  2660. -
  2661. - ux.value = x;
  2662. - uy.value = y;
  2663. - ux.bits &= (uint64_t)-1>>1;
  2664. - ux.bits |= uy.bits & (uint64_t)1<<63;
  2665. - return ux.value;
  2666. + union {double f; uint64_t i;} ux={x}, uy={y};
  2667. + ux.i &= -1ULL/2;
  2668. + ux.i |= uy.i & 1ULL<<63;
  2669. + return ux.f;
  2670. }
  2671. diff -Nur musl-0.9.13/src/math/copysignf.c musl-git/src/math/copysignf.c
  2672. --- musl-0.9.13/src/math/copysignf.c 2013-08-30 23:30:53.000000000 +0200
  2673. +++ musl-git/src/math/copysignf.c 2013-09-16 20:31:39.000000000 +0200
  2674. @@ -1,11 +1,10 @@
  2675. -#include "libm.h"
  2676. +#include <math.h>
  2677. +#include <stdint.h>
  2678. -float copysignf(float x, float y) {
  2679. - union fshape ux, uy;
  2680. -
  2681. - ux.value = x;
  2682. - uy.value = y;
  2683. - ux.bits &= (uint32_t)-1>>1;
  2684. - ux.bits |= uy.bits & (uint32_t)1<<31;
  2685. - return ux.value;
  2686. +float copysignf(float x, float y)
  2687. +{
  2688. + union {float f; uint32_t i;} ux={x}, uy={y};
  2689. + ux.i &= 0x7fffffff;
  2690. + ux.i |= uy.i & 0x80000000;
  2691. + return ux.f;
  2692. }
  2693. diff -Nur musl-0.9.13/src/math/copysignl.c musl-git/src/math/copysignl.c
  2694. --- musl-0.9.13/src/math/copysignl.c 2013-08-30 23:30:53.000000000 +0200
  2695. +++ musl-git/src/math/copysignl.c 2013-09-16 20:31:39.000000000 +0200
  2696. @@ -9,8 +9,8 @@
  2697. long double copysignl(long double x, long double y)
  2698. {
  2699. union ldshape ux = {x}, uy = {y};
  2700. -
  2701. - ux.bits.sign = uy.bits.sign;
  2702. - return ux.value;
  2703. + ux.i.se &= 0x7fff;
  2704. + ux.i.se |= uy.i.se & 0x8000;
  2705. + return ux.f;
  2706. }
  2707. #endif
  2708. diff -Nur musl-0.9.13/src/math/coshl.c musl-git/src/math/coshl.c
  2709. --- musl-0.9.13/src/math/coshl.c 2013-08-30 23:30:53.000000000 +0200
  2710. +++ musl-git/src/math/coshl.c 2013-09-16 20:31:39.000000000 +0200
  2711. @@ -8,10 +8,7 @@
  2712. #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  2713. long double coshl(long double x)
  2714. {
  2715. - union {
  2716. - long double f;
  2717. - struct{uint64_t m; uint16_t se; uint16_t pad;} i;
  2718. - } u = {.f = x};
  2719. + union ldshape u = {x};
  2720. unsigned ex = u.i.se & 0x7fff;
  2721. uint32_t w;
  2722. long double t;
  2723. diff -Nur musl-0.9.13/src/math/cosl.c musl-git/src/math/cosl.c
  2724. --- musl-0.9.13/src/math/cosl.c 2013-08-30 23:30:53.000000000 +0200
  2725. +++ musl-git/src/math/cosl.c 2013-09-16 20:31:39.000000000 +0200
  2726. @@ -1,34 +1,3 @@
  2727. -/* origin: FreeBSD /usr/src/lib/msun/src/s_cosl.c */
  2728. -/*-
  2729. - * Copyright (c) 2007 Steven G. Kargl
  2730. - * All rights reserved.
  2731. - *
  2732. - * Redistribution and use in source and binary forms, with or without
  2733. - * modification, are permitted provided that the following conditions
  2734. - * are met:
  2735. - * 1. Redistributions of source code must retain the above copyright
  2736. - * notice unmodified, this list of conditions, and the following
  2737. - * disclaimer.
  2738. - * 2. Redistributions in binary form must reproduce the above copyright
  2739. - * notice, this list of conditions and the following disclaimer in the
  2740. - * documentation and/or other materials provided with the distribution.
  2741. - *
  2742. - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  2743. - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2744. - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2745. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  2746. - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  2747. - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  2748. - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  2749. - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  2750. - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  2751. - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2752. - */
  2753. -/*
  2754. - * Limited testing on pseudorandom numbers drawn within [-2e8:4e8] shows
  2755. - * an accuracy of <= 0.7412 ULP.
  2756. - */
  2757. -
  2758. #include "libm.h"
  2759. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  2760. @@ -38,44 +7,33 @@
  2761. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  2762. long double cosl(long double x)
  2763. {
  2764. - union IEEEl2bits z;
  2765. + union ldshape u = {x};
  2766. unsigned n;
  2767. - long double y[2];
  2768. - long double hi, lo;
  2769. -
  2770. - z.e = x;
  2771. - z.bits.sign = 0;
  2772. + long double y[2], hi, lo;
  2773. - /* If x = NaN or Inf, then cos(x) = NaN. */
  2774. - if (z.bits.exp == 0x7fff)
  2775. - return (x - x) / (x - x);
  2776. -
  2777. - /* |x| < (double)pi/4 */
  2778. - if (z.e < M_PI_4) {
  2779. - /* |x| < 0x1p-64 */
  2780. - if (z.bits.exp < 0x3fff - 64)
  2781. + u.i.se &= 0x7fff;
  2782. + if (u.i.se == 0x7fff)
  2783. + return x - x;
  2784. + x = u.f;
  2785. + if (x < M_PI_4) {
  2786. + if (u.i.se < 0x3fff - LDBL_MANT_DIG)
  2787. /* raise inexact if x!=0 */
  2788. return 1.0 + x;
  2789. - return __cosl(z.e, 0);
  2790. + return __cosl(x, 0);
  2791. }
  2792. -
  2793. n = __rem_pio2l(x, y);
  2794. hi = y[0];
  2795. lo = y[1];
  2796. switch (n & 3) {
  2797. case 0:
  2798. - hi = __cosl(hi, lo);
  2799. - break;
  2800. + return __cosl(hi, lo);
  2801. case 1:
  2802. - hi = -__sinl(hi, lo, 1);
  2803. - break;
  2804. + return -__sinl(hi, lo, 1);
  2805. case 2:
  2806. - hi = -__cosl(hi, lo);
  2807. - break;
  2808. + return -__cosl(hi, lo);
  2809. case 3:
  2810. - hi = __sinl(hi, lo, 1);
  2811. - break;
  2812. + default:
  2813. + return __sinl(hi, lo, 1);
  2814. }
  2815. - return hi;
  2816. }
  2817. #endif
  2818. diff -Nur musl-0.9.13/src/math/erfl.c musl-git/src/math/erfl.c
  2819. --- musl-0.9.13/src/math/erfl.c 2013-08-30 23:30:53.000000000 +0200
  2820. +++ musl-git/src/math/erfl.c 2013-09-16 20:31:39.000000000 +0200
  2821. @@ -253,8 +253,8 @@
  2822. static long double erfc2(uint32_t ix, long double x)
  2823. {
  2824. + union ldshape u;
  2825. long double s,z,R,S;
  2826. - uint32_t i0,i1;
  2827. if (ix < 0x3fffa000) /* 0.84375 <= |x| < 1.25 */
  2828. return erfc1(x);
  2829. @@ -288,28 +288,22 @@
  2830. S = sc[0] + s * (sc[1] + s * (sc[2] + s * (sc[3] +
  2831. s * (sc[4] + s))));
  2832. }
  2833. - z = x;
  2834. - GET_LDOUBLE_WORDS(ix, i0, i1, z);
  2835. - i1 = 0;
  2836. - i0 &= 0xffffff00;
  2837. - SET_LDOUBLE_WORDS(z, ix, i0, i1);
  2838. + u.f = x;
  2839. + u.i.m &= -1ULL << 40;
  2840. + z = u.f;
  2841. return expl(-z*z - 0.5625) * expl((z - x) * (z + x) + R / S) / x;
  2842. }
  2843. long double erfl(long double x)
  2844. {
  2845. long double r, s, z, y;
  2846. - uint32_t i0, i1, ix;
  2847. - int sign;
  2848. + union ldshape u = {x};
  2849. + uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48;
  2850. + int sign = u.i.se >> 15;
  2851. - GET_LDOUBLE_WORDS(ix, i0, i1, x);
  2852. - sign = ix >> 15;
  2853. - ix &= 0x7fff;
  2854. - if (ix == 0x7fff) {
  2855. + if (ix >= 0x7fff0000)
  2856. /* erf(nan)=nan, erf(+-inf)=+-1 */
  2857. return 1 - 2*sign + 1/x;
  2858. - }
  2859. - ix = (ix << 16) | (i0 >> 16);
  2860. if (ix < 0x3ffed800) { /* |x| < 0.84375 */
  2861. if (ix < 0x3fde8000) { /* |x| < 2**-33 */
  2862. return 0.125 * (8 * x + efx8 * x); /* avoid underflow */
  2863. @@ -332,17 +326,13 @@
  2864. long double erfcl(long double x)
  2865. {
  2866. long double r, s, z, y;
  2867. - uint32_t i0, i1, ix;
  2868. - int sign;
  2869. + union ldshape u = {x};
  2870. + uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48;
  2871. + int sign = u.i.se >> 15;
  2872. - GET_LDOUBLE_WORDS(ix, i0, i1, x);
  2873. - sign = ix>>15;
  2874. - ix &= 0x7fff;
  2875. - if (ix == 0x7fff)
  2876. + if (ix >= 0x7fff0000)
  2877. /* erfc(nan) = nan, erfc(+-inf) = 0,2 */
  2878. return 2*sign + 1/x;
  2879. -
  2880. - ix = (ix << 16) | (i0 >> 16);
  2881. if (ix < 0x3ffed800) { /* |x| < 0.84375 */
  2882. if (ix < 0x3fbe0000) /* |x| < 2**-65 */
  2883. return 1.0 - x;
  2884. @@ -358,6 +348,7 @@
  2885. }
  2886. if (ix < 0x4005d600) /* |x| < 107 */
  2887. return sign ? 2 - erfc2(ix,x) : erfc2(ix,x);
  2888. - return sign ? 2 - 0x1p-16382L : 0x1p-16382L*0x1p-16382L;
  2889. + y = 0x1p-16382L;
  2890. + return sign ? 2 - y : y*y;
  2891. }
  2892. #endif
  2893. diff -Nur musl-0.9.13/src/math/exp.c musl-git/src/math/exp.c
  2894. --- musl-0.9.13/src/math/exp.c 2013-08-30 23:30:53.000000000 +0200
  2895. +++ musl-git/src/math/exp.c 2013-09-16 20:31:39.000000000 +0200
  2896. @@ -80,7 +80,7 @@
  2897. double exp(double x)
  2898. {
  2899. - double hi, lo, c, xx;
  2900. + double_t hi, lo, c, xx, y;
  2901. int k, sign;
  2902. uint32_t hx;
  2903. @@ -89,20 +89,19 @@
  2904. hx &= 0x7fffffff; /* high word of |x| */
  2905. /* special cases */
  2906. - if (hx >= 0x40862e42) { /* if |x| >= 709.78... */
  2907. + if (hx >= 0x4086232b) { /* if |x| >= 708.39... */
  2908. if (isnan(x))
  2909. return x;
  2910. - if (hx == 0x7ff00000 && sign) /* -inf */
  2911. - return 0;
  2912. if (x > 709.782712893383973096) {
  2913. /* overflow if x!=inf */
  2914. - STRICT_ASSIGN(double, x, 0x1p1023 * x);
  2915. + x *= 0x1p1023;
  2916. return x;
  2917. }
  2918. - if (x < -745.13321910194110842) {
  2919. - /* underflow */
  2920. - STRICT_ASSIGN(double, x, 0x1p-1000 * 0x1p-1000);
  2921. - return x;
  2922. + if (x < -708.39641853226410622) {
  2923. + /* underflow if x!=-inf */
  2924. + FORCE_EVAL((float)(-0x1p-149/x));
  2925. + if (x < -745.13321910194110842)
  2926. + return 0;
  2927. }
  2928. }
  2929. @@ -114,7 +113,7 @@
  2930. k = 1 - sign - sign;
  2931. hi = x - k*ln2hi; /* k*ln2hi is exact here */
  2932. lo = k*ln2lo;
  2933. - STRICT_ASSIGN(double, x, hi - lo);
  2934. + x = hi - lo;
  2935. } else if (hx > 0x3e300000) { /* if |x| > 2**-28 */
  2936. k = 0;
  2937. hi = x;
  2938. @@ -128,8 +127,8 @@
  2939. /* x is now in primary range */
  2940. xx = x*x;
  2941. c = x - xx*(P1+xx*(P2+xx*(P3+xx*(P4+xx*P5))));
  2942. - x = 1 + (x*c/(2-c) - lo + hi);
  2943. + y = 1 + (x*c/(2-c) - lo + hi);
  2944. if (k == 0)
  2945. - return x;
  2946. - return scalbn(x, k);
  2947. + return y;
  2948. + return scalbn(y, k);
  2949. }
  2950. diff -Nur musl-0.9.13/src/math/exp2.c musl-git/src/math/exp2.c
  2951. --- musl-0.9.13/src/math/exp2.c 2013-08-30 23:30:53.000000000 +0200
  2952. +++ musl-git/src/math/exp2.c 2013-09-16 20:31:39.000000000 +0200
  2953. @@ -305,7 +305,7 @@
  2954. * Method: (accurate tables)
  2955. *
  2956. * Reduce x:
  2957. - * x = 2**k + y, for integer k and |y| <= 1/2.
  2958. + * x = k + y, for integer k and |y| <= 1/2.
  2959. * Thus we have exp2(x) = 2**k * exp2(y).
  2960. *
  2961. * Reduce y:
  2962. @@ -330,41 +330,41 @@
  2963. */
  2964. double exp2(double x)
  2965. {
  2966. - double r, t, z;
  2967. - uint32_t hx, ix, i0;
  2968. + double_t r, t, z;
  2969. + uint32_t ix, i0;
  2970. + union {double f; uint64_t i;} u = {x};
  2971. union {uint32_t u; int32_t i;} k;
  2972. /* Filter out exceptional cases. */
  2973. - GET_HIGH_WORD(hx, x);
  2974. - ix = hx & 0x7fffffff;
  2975. - if (ix >= 0x40900000) { /* |x| >= 1024 */
  2976. - if (ix >= 0x7ff00000) {
  2977. - GET_LOW_WORD(ix, x);
  2978. - if (hx == 0xfff00000 && ix == 0) /* -inf */
  2979. - return 0;
  2980. - return x;
  2981. - }
  2982. - if (x >= 1024) {
  2983. - STRICT_ASSIGN(double, x, x * 0x1p1023);
  2984. + ix = u.i>>32 & 0x7fffffff;
  2985. + if (ix >= 0x408ff000) { /* |x| >= 1022 or nan */
  2986. + if (ix >= 0x40900000 && u.i>>63 == 0) { /* x >= 1024 or nan */
  2987. + /* overflow */
  2988. + x *= 0x1p1023;
  2989. return x;
  2990. }
  2991. - if (x <= -1075) {
  2992. - STRICT_ASSIGN(double, x, 0x1p-1000*0x1p-1000);
  2993. - return x;
  2994. + if (ix >= 0x7ff00000) /* -inf or -nan */
  2995. + return -1/x;
  2996. + if (u.i>>63) { /* x <= -1022 */
  2997. + /* underflow */
  2998. + if (x <= -1075 || x - 0x1p52 + 0x1p52 != x)
  2999. + FORCE_EVAL((float)(-0x1p-149/x));
  3000. + if (x <= -1075)
  3001. + return 0;
  3002. }
  3003. } else if (ix < 0x3c900000) { /* |x| < 0x1p-54 */
  3004. return 1.0 + x;
  3005. }
  3006. /* Reduce x, computing z, i0, and k. */
  3007. - STRICT_ASSIGN(double, t, x + redux);
  3008. - GET_LOW_WORD(i0, t);
  3009. + u.f = x + redux;
  3010. + i0 = u.i;
  3011. i0 += TBLSIZE / 2;
  3012. k.u = i0 / TBLSIZE * TBLSIZE;
  3013. k.i /= TBLSIZE;
  3014. i0 %= TBLSIZE;
  3015. - t -= redux;
  3016. - z = x - t;
  3017. + u.f -= redux;
  3018. + z = x - u.f;
  3019. /* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */
  3020. t = tbl[2*i0]; /* exp2t[i0] */
  3021. diff -Nur musl-0.9.13/src/math/exp2f.c musl-git/src/math/exp2f.c
  3022. --- musl-0.9.13/src/math/exp2f.c 2013-08-30 23:30:53.000000000 +0200
  3023. +++ musl-git/src/math/exp2f.c 2013-09-16 20:31:39.000000000 +0200
  3024. @@ -63,7 +63,7 @@
  3025. * Method: (equally-spaced tables)
  3026. *
  3027. * Reduce x:
  3028. - * x = 2**k + y, for integer k and |y| <= 1/2.
  3029. + * x = k + y, for integer k and |y| <= 1/2.
  3030. * Thus we have exp2f(x) = 2**k * exp2(y).
  3031. *
  3032. * Reduce y:
  3033. @@ -83,46 +83,42 @@
  3034. */
  3035. float exp2f(float x)
  3036. {
  3037. - double tv, twopk, u, z;
  3038. - float t;
  3039. - uint32_t hx, ix, i0, k;
  3040. + double_t t, r, z;
  3041. + union {float f; uint32_t i;} u = {x};
  3042. + union {double f; uint64_t i;} uk;
  3043. + uint32_t ix, i0, k;
  3044. /* Filter out exceptional cases. */
  3045. - GET_FLOAT_WORD(hx, x);
  3046. - ix = hx & 0x7fffffff;
  3047. - if (ix >= 0x43000000) { /* |x| >= 128 */
  3048. - if (ix >= 0x7f800000) {
  3049. - if (hx == 0xff800000) /* -inf */
  3050. - return 0;
  3051. - return x;
  3052. - }
  3053. - if (x >= 128) {
  3054. - STRICT_ASSIGN(float, x, x * 0x1p127f);
  3055. + ix = u.i & 0x7fffffff;
  3056. + if (ix > 0x42fc0000) { /* |x| > 126 */
  3057. + if (u.i >= 0x43000000 && u.i < 0x80000000) { /* x >= 128 */
  3058. + x *= 0x1p127f;
  3059. return x;
  3060. }
  3061. - if (x <= -150) {
  3062. - STRICT_ASSIGN(float, x, 0x1p-100f*0x1p-100f);
  3063. - return x;
  3064. + if (u.i >= 0x80000000) { /* x < -126 */
  3065. + if (u.i >= 0xc3160000 || (u.i & 0x0000ffff))
  3066. + FORCE_EVAL(-0x1p-149f/x);
  3067. + if (u.i >= 0xc3160000) /* x <= -150 */
  3068. + return 0;
  3069. }
  3070. } else if (ix <= 0x33000000) { /* |x| <= 0x1p-25 */
  3071. return 1.0f + x;
  3072. }
  3073. /* Reduce x, computing z, i0, and k. */
  3074. - STRICT_ASSIGN(float, t, x + redux);
  3075. - GET_FLOAT_WORD(i0, t);
  3076. + u.f = x + redux;
  3077. + i0 = u.i;
  3078. i0 += TBLSIZE / 2;
  3079. - k = (i0 / TBLSIZE) << 20;
  3080. + k = i0 / TBLSIZE;
  3081. + uk.i = (uint64_t)(0x3ff + k)<<52;
  3082. i0 &= TBLSIZE - 1;
  3083. - t -= redux;
  3084. - z = x - t;
  3085. - INSERT_WORDS(twopk, 0x3ff00000 + k, 0);
  3086. -
  3087. + u.f -= redux;
  3088. + z = x - u.f;
  3089. /* Compute r = exp2(y) = exp2ft[i0] * p(z). */
  3090. - tv = exp2ft[i0];
  3091. - u = tv * z;
  3092. - tv = tv + u * (P1 + z * P2) + u * (z * z) * (P3 + z * P4);
  3093. + r = exp2ft[i0];
  3094. + t = r * z;
  3095. + r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
  3096. - /* Scale by 2**(k>>20). */
  3097. - return tv * twopk;
  3098. + /* Scale by 2**k */
  3099. + return r * uk.f;
  3100. }
  3101. diff -Nur musl-0.9.13/src/math/exp2l.c musl-git/src/math/exp2l.c
  3102. --- musl-0.9.13/src/math/exp2l.c 2013-08-30 23:30:53.000000000 +0200
  3103. +++ musl-git/src/math/exp2l.c 2013-09-16 20:31:39.000000000 +0200
  3104. @@ -33,13 +33,9 @@
  3105. return exp2(x);
  3106. }
  3107. #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  3108. -
  3109. #define TBLBITS 7
  3110. #define TBLSIZE (1 << TBLBITS)
  3111. -#define BIAS (LDBL_MAX_EXP - 1)
  3112. -#define EXPMASK (BIAS + LDBL_MAX_EXP)
  3113. -
  3114. static const double
  3115. redux = 0x1.8p63 / TBLSIZE,
  3116. P1 = 0x1.62e42fefa39efp-1,
  3117. @@ -203,29 +199,29 @@
  3118. */
  3119. long double exp2l(long double x)
  3120. {
  3121. - union IEEEl2bits u, v;
  3122. + union ldshape u = {x};
  3123. + int e = u.i.se & 0x7fff;
  3124. long double r, z;
  3125. - uint32_t hx, ix, i0;
  3126. + uint32_t i0;
  3127. union {uint32_t u; int32_t i;} k;
  3128. /* Filter out exceptional cases. */
  3129. - u.e = x;
  3130. - hx = u.xbits.expsign;
  3131. - ix = hx & EXPMASK;
  3132. - if (ix >= BIAS + 14) { /* |x| >= 16384 or x is NaN */
  3133. - if (ix == EXPMASK) {
  3134. - if (u.xbits.man == 1ULL << 63 && hx == 0xffff) /* -inf */
  3135. + if (e >= 0x3fff + 13) { /* |x| >= 8192 or x is NaN */
  3136. + if (u.i.se >= 0x3fff + 14 && u.i.se >> 15 == 0)
  3137. + /* overflow */
  3138. + return x * 0x1p16383L;
  3139. + if (e == 0x7fff) /* -inf or -nan */
  3140. + return -1/x;
  3141. + if (x < -16382) {
  3142. + if (x <= -16446 || x - 0x1p63 + 0x1p63 != x)
  3143. + /* underflow */
  3144. + FORCE_EVAL((float)(-0x1p-149/x));
  3145. + if (x <= -16446)
  3146. return 0;
  3147. - return x;
  3148. - }
  3149. - if (x >= 16384) {
  3150. - x *= 0x1p16383L;
  3151. - return x;
  3152. }
  3153. - if (x <= -16446)
  3154. - return 0x1p-10000L*0x1p-10000L;
  3155. - } else if (ix < BIAS - 64) /* |x| < 0x1p-64 */
  3156. + } else if (e < 0x3fff - 64) {
  3157. return 1 + x;
  3158. + }
  3159. /*
  3160. * Reduce x, computing z, i0, and k. The low bits of x + redux
  3161. @@ -238,13 +234,13 @@
  3162. * We split this into k = 0xabc and i0 = 0x12 (adjusted to
  3163. * index into the table), then we compute z = 0x0.003456p0.
  3164. */
  3165. - u.e = x + redux;
  3166. - i0 = u.bits.manl + TBLSIZE / 2;
  3167. + u.f = x + redux;
  3168. + i0 = u.i.m + TBLSIZE / 2;
  3169. k.u = i0 / TBLSIZE * TBLSIZE;
  3170. k.i /= TBLSIZE;
  3171. i0 %= TBLSIZE;
  3172. - u.e -= redux;
  3173. - z = x - u.e;
  3174. + u.f -= redux;
  3175. + z = x - u.f;
  3176. /* Compute r = exp2l(y) = exp2lt[i0] * p(z). */
  3177. long double t_hi = tbl[2*i0];
  3178. diff -Nur musl-0.9.13/src/math/expf.c musl-git/src/math/expf.c
  3179. --- musl-0.9.13/src/math/expf.c 2013-08-30 23:30:53.000000000 +0200
  3180. +++ musl-git/src/math/expf.c 2013-09-16 20:31:39.000000000 +0200
  3181. @@ -29,7 +29,7 @@
  3182. float expf(float x)
  3183. {
  3184. - float hi, lo, c, xx;
  3185. + float_t hi, lo, c, xx, y;
  3186. int k, sign;
  3187. uint32_t hx;
  3188. @@ -38,20 +38,17 @@
  3189. hx &= 0x7fffffff; /* high word of |x| */
  3190. /* special cases */
  3191. - if (hx >= 0x42b17218) { /* if |x| >= 88.722839f or NaN */
  3192. - if (hx > 0x7f800000) /* NaN */
  3193. - return x;
  3194. - if (!sign) {
  3195. - /* overflow if x!=inf */
  3196. - STRICT_ASSIGN(float, x, x * 0x1p127f);
  3197. + if (hx >= 0x42aeac50) { /* if |x| >= -87.33655f or NaN */
  3198. + if (hx >= 0x42b17218 && !sign) { /* x >= 88.722839f */
  3199. + /* overflow */
  3200. + x *= 0x1p127f;
  3201. return x;
  3202. }
  3203. - if (hx == 0x7f800000) /* -inf */
  3204. - return 0;
  3205. - if (hx >= 0x42cff1b5) { /* x <= -103.972084f */
  3206. + if (sign) {
  3207. /* underflow */
  3208. - STRICT_ASSIGN(float, x, 0x1p-100f*0x1p-100f);
  3209. - return x;
  3210. + FORCE_EVAL(-0x1p-149f/x);
  3211. + if (hx >= 0x42cff1b5) /* x <= -103.972084f */
  3212. + return 0;
  3213. }
  3214. }
  3215. @@ -63,7 +60,7 @@
  3216. k = 1 - sign - sign;
  3217. hi = x - k*ln2hi; /* k*ln2hi is exact here */
  3218. lo = k*ln2lo;
  3219. - STRICT_ASSIGN(float, x, hi - lo);
  3220. + x = hi - lo;
  3221. } else if (hx > 0x39000000) { /* |x| > 2**-14 */
  3222. k = 0;
  3223. hi = x;
  3224. @@ -77,8 +74,8 @@
  3225. /* x is now in primary range */
  3226. xx = x*x;
  3227. c = x - xx*(P1+xx*P2);
  3228. - x = 1 + (x*c/(2-c) - lo + hi);
  3229. + y = 1 + (x*c/(2-c) - lo + hi);
  3230. if (k == 0)
  3231. - return x;
  3232. - return scalbnf(x, k);
  3233. + return y;
  3234. + return scalbnf(y, k);
  3235. }
  3236. diff -Nur musl-0.9.13/src/math/expl.c musl-git/src/math/expl.c
  3237. --- musl-0.9.13/src/math/expl.c 2013-08-30 23:30:53.000000000 +0200
  3238. +++ musl-git/src/math/expl.c 2013-09-16 20:31:39.000000000 +0200
  3239. @@ -100,7 +100,7 @@
  3240. if (x > 11356.5234062941439488L) /* x > ln(2^16384 - 0.5) */
  3241. return x * 0x1p16383L;
  3242. if (x < -11399.4985314888605581L) /* x < ln(2^-16446) */
  3243. - return 0x1p-10000L * 0x1p-10000L;
  3244. + return -0x1p-16445L/x;
  3245. /* Express e**x = e**f 2**k
  3246. * = e**(f + k ln(2))
  3247. diff -Nur musl-0.9.13/src/math/expm1.c musl-git/src/math/expm1.c
  3248. --- musl-0.9.13/src/math/expm1.c 2013-08-30 23:30:53.000000000 +0200
  3249. +++ musl-git/src/math/expm1.c 2013-09-16 20:31:39.000000000 +0200
  3250. @@ -31,7 +31,7 @@
  3251. * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r)
  3252. * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r))
  3253. * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ...
  3254. - * We use a special Reme algorithm on [0,0.347] to generate
  3255. + * We use a special Remez algorithm on [0,0.347] to generate
  3256. * a polynomial of degree 5 in r*r to approximate R1. The
  3257. * maximum error of this polynomial approximation is bounded
  3258. * by 2**-61. In other words,
  3259. @@ -107,8 +107,6 @@
  3260. #include "libm.h"
  3261. static const double
  3262. -huge = 1.0e+300,
  3263. -tiny = 1.0e-300,
  3264. o_threshold = 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
  3265. ln2_hi = 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
  3266. ln2_lo = 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
  3267. @@ -122,39 +120,27 @@
  3268. double expm1(double x)
  3269. {
  3270. - double y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
  3271. - int32_t k,xsb;
  3272. - uint32_t hx;
  3273. -
  3274. - GET_HIGH_WORD(hx, x);
  3275. - xsb = hx&0x80000000; /* sign bit of x */
  3276. - hx &= 0x7fffffff; /* high word of |x| */
  3277. + double_t y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
  3278. + union {double f; uint64_t i;} u = {x};
  3279. + uint32_t hx = u.i>>32 & 0x7fffffff;
  3280. + int k, sign = u.i>>63;
  3281. /* filter out huge and non-finite argument */
  3282. if (hx >= 0x4043687A) { /* if |x|>=56*ln2 */
  3283. - if (hx >= 0x40862E42) { /* if |x|>=709.78... */
  3284. - if (hx >= 0x7ff00000) {
  3285. - uint32_t low;
  3286. -
  3287. - GET_LOW_WORD(low, x);
  3288. - if (((hx&0xfffff)|low) != 0) /* NaN */
  3289. - return x+x;
  3290. - return xsb==0 ? x : -1.0; /* exp(+-inf)={inf,-1} */
  3291. - }
  3292. - if(x > o_threshold)
  3293. - return huge*huge; /* overflow */
  3294. - }
  3295. - if (xsb != 0) { /* x < -56*ln2, return -1.0 with inexact */
  3296. - /* raise inexact */
  3297. - if(x+tiny<0.0)
  3298. - return tiny-1.0; /* return -1 */
  3299. + if (isnan(x))
  3300. + return x;
  3301. + if (sign)
  3302. + return -1;
  3303. + if (x > o_threshold) {
  3304. + x *= 0x1p1023;
  3305. + return x;
  3306. }
  3307. }
  3308. /* argument reduction */
  3309. if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
  3310. if (hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
  3311. - if (xsb == 0) {
  3312. + if (!sign) {
  3313. hi = x - ln2_hi;
  3314. lo = ln2_lo;
  3315. k = 1;
  3316. @@ -164,17 +150,17 @@
  3317. k = -1;
  3318. }
  3319. } else {
  3320. - k = invln2*x + (xsb==0 ? 0.5 : -0.5);
  3321. + k = invln2*x + (sign ? -0.5 : 0.5);
  3322. t = k;
  3323. hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
  3324. lo = t*ln2_lo;
  3325. }
  3326. - STRICT_ASSIGN(double, x, hi - lo);
  3327. + x = hi-lo;
  3328. c = (hi-x)-lo;
  3329. } else if (hx < 0x3c900000) { /* |x| < 2**-54, return x */
  3330. - /* raise inexact flags when x != 0 */
  3331. - t = huge+x;
  3332. - return x - (t-(huge+x));
  3333. + if (hx < 0x00100000)
  3334. + FORCE_EVAL((float)x);
  3335. + return x;
  3336. } else
  3337. k = 0;
  3338. @@ -186,9 +172,9 @@
  3339. e = hxs*((r1-t)/(6.0 - x*t));
  3340. if (k == 0) /* c is 0 */
  3341. return x - (x*e-hxs);
  3342. - INSERT_WORDS(twopk, 0x3ff00000+(k<<20), 0); /* 2^k */
  3343. e = x*(e-c) - c;
  3344. e -= hxs;
  3345. + /* exp(x) ~ 2^k (x_reduced - e + 1) */
  3346. if (k == -1)
  3347. return 0.5*(x-e) - 0.5;
  3348. if (k == 1) {
  3349. @@ -196,24 +182,20 @@
  3350. return -2.0*(e-(x+0.5));
  3351. return 1.0+2.0*(x-e);
  3352. }
  3353. - if (k <= -2 || k > 56) { /* suffice to return exp(x)-1 */
  3354. - y = 1.0 - (e-x);
  3355. + u.i = (uint64_t)(0x3ff + k)<<52; /* 2^k */
  3356. + twopk = u.f;
  3357. + if (k < 0 || k > 56) { /* suffice to return exp(x)-1 */
  3358. + y = x - e + 1.0;
  3359. if (k == 1024)
  3360. y = y*2.0*0x1p1023;
  3361. else
  3362. y = y*twopk;
  3363. return y - 1.0;
  3364. }
  3365. - t = 1.0;
  3366. - if (k < 20) {
  3367. - SET_HIGH_WORD(t, 0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */
  3368. - y = t-(e-x);
  3369. - y = y*twopk;
  3370. - } else {
  3371. - SET_HIGH_WORD(t, ((0x3ff-k)<<20)); /* 2^-k */
  3372. - y = x-(e+t);
  3373. - y += 1.0;
  3374. - y = y*twopk;
  3375. - }
  3376. + u.i = (uint64_t)(0x3ff - k)<<52; /* 2^-k */
  3377. + if (k < 20)
  3378. + y = (x-e+(1-u.f))*twopk;
  3379. + else
  3380. + y = (x-(e+u.f)+1)*twopk;
  3381. return y;
  3382. }
  3383. diff -Nur musl-0.9.13/src/math/expm1f.c musl-git/src/math/expm1f.c
  3384. --- musl-0.9.13/src/math/expm1f.c 2013-08-30 23:30:53.000000000 +0200
  3385. +++ musl-git/src/math/expm1f.c 2013-09-16 20:31:39.000000000 +0200
  3386. @@ -16,8 +16,6 @@
  3387. #include "libm.h"
  3388. static const float
  3389. -huge = 1.0e+30,
  3390. -tiny = 1.0e-30,
  3391. o_threshold = 8.8721679688e+01, /* 0x42b17180 */
  3392. ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
  3393. ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
  3394. @@ -32,35 +30,27 @@
  3395. float expm1f(float x)
  3396. {
  3397. - float y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
  3398. - int32_t k,xsb;
  3399. - uint32_t hx;
  3400. -
  3401. - GET_FLOAT_WORD(hx, x);
  3402. - xsb = hx&0x80000000; /* sign bit of x */
  3403. - hx &= 0x7fffffff; /* high word of |x| */
  3404. + float_t y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
  3405. + union {float f; uint32_t i;} u = {x};
  3406. + uint32_t hx = u.i & 0x7fffffff;
  3407. + int k, sign = u.i >> 31;
  3408. /* filter out huge and non-finite argument */
  3409. if (hx >= 0x4195b844) { /* if |x|>=27*ln2 */
  3410. - if (hx >= 0x42b17218) { /* if |x|>=88.721... */
  3411. - if (hx > 0x7f800000) /* NaN */
  3412. - return x+x;
  3413. - if (hx == 0x7f800000) /* exp(+-inf)={inf,-1} */
  3414. - return xsb==0 ? x : -1.0;
  3415. - if (x > o_threshold)
  3416. - return huge*huge; /* overflow */
  3417. - }
  3418. - if (xsb != 0) { /* x < -27*ln2 */
  3419. - /* raise inexact */
  3420. - if (x+tiny < 0.0f)
  3421. - return tiny-1.0f; /* return -1 */
  3422. + if (hx > 0x7f800000) /* NaN */
  3423. + return x;
  3424. + if (sign)
  3425. + return -1;
  3426. + if (x > o_threshold) {
  3427. + x *= 0x1p127f;
  3428. + return x;
  3429. }
  3430. }
  3431. /* argument reduction */
  3432. if (hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */
  3433. if (hx < 0x3F851592) { /* and |x| < 1.5 ln2 */
  3434. - if (xsb == 0) {
  3435. + if (!sign) {
  3436. hi = x - ln2_hi;
  3437. lo = ln2_lo;
  3438. k = 1;
  3439. @@ -70,16 +60,17 @@
  3440. k = -1;
  3441. }
  3442. } else {
  3443. - k = invln2*x + (xsb==0 ? 0.5f : -0.5f);
  3444. + k = invln2*x + (sign ? -0.5f : 0.5f);
  3445. t = k;
  3446. hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
  3447. lo = t*ln2_lo;
  3448. }
  3449. - STRICT_ASSIGN(float, x, hi - lo);
  3450. + x = hi-lo;
  3451. c = (hi-x)-lo;
  3452. } else if (hx < 0x33000000) { /* when |x|<2**-25, return x */
  3453. - t = huge+x; /* return x with inexact flags when x!=0 */
  3454. - return x - (t-(huge+x));
  3455. + if (hx < 0x00800000)
  3456. + FORCE_EVAL(x*x);
  3457. + return x;
  3458. } else
  3459. k = 0;
  3460. @@ -91,9 +82,9 @@
  3461. e = hxs*((r1-t)/(6.0f - x*t));
  3462. if (k == 0) /* c is 0 */
  3463. return x - (x*e-hxs);
  3464. - SET_FLOAT_WORD(twopk, 0x3f800000+(k<<23)); /* 2^k */
  3465. e = x*(e-c) - c;
  3466. e -= hxs;
  3467. + /* exp(x) ~ 2^k (x_reduced - e + 1) */
  3468. if (k == -1)
  3469. return 0.5f*(x-e) - 0.5f;
  3470. if (k == 1) {
  3471. @@ -101,24 +92,20 @@
  3472. return -2.0f*(e-(x+0.5f));
  3473. return 1.0f + 2.0f*(x-e);
  3474. }
  3475. - if (k <= -2 || k > 56) { /* suffice to return exp(x)-1 */
  3476. - y = 1.0f - (e - x);
  3477. + u.i = (0x7f+k)<<23; /* 2^k */
  3478. + twopk = u.f;
  3479. + if (k < 0 || k > 56) { /* suffice to return exp(x)-1 */
  3480. + y = x - e + 1.0f;
  3481. if (k == 128)
  3482. y = y*2.0f*0x1p127f;
  3483. else
  3484. y = y*twopk;
  3485. return y - 1.0f;
  3486. }
  3487. - t = 1.0f;
  3488. - if (k < 23) {
  3489. - SET_FLOAT_WORD(t, 0x3f800000 - (0x1000000>>k)); /* t=1-2^-k */
  3490. - y = t - (e - x);
  3491. - y = y*twopk;
  3492. - } else {
  3493. - SET_FLOAT_WORD(t, (0x7f-k)<<23); /* 2^-k */
  3494. - y = x - (e + t);
  3495. - y += 1.0f;
  3496. - y = y*twopk;
  3497. - }
  3498. + u.i = (0x7f-k)<<23; /* 2^-k */
  3499. + if (k < 23)
  3500. + y = (x-e+(1-u.f))*twopk;
  3501. + else
  3502. + y = (x-(e+u.f)+1)*twopk;
  3503. return y;
  3504. }
  3505. diff -Nur musl-0.9.13/src/math/fabs.c musl-git/src/math/fabs.c
  3506. --- musl-0.9.13/src/math/fabs.c 2013-08-30 23:30:53.000000000 +0200
  3507. +++ musl-git/src/math/fabs.c 2013-09-16 20:31:39.000000000 +0200
  3508. @@ -1,10 +1,9 @@
  3509. -#include "libm.h"
  3510. +#include <math.h>
  3511. +#include <stdint.h>
  3512. double fabs(double x)
  3513. {
  3514. - union dshape u;
  3515. -
  3516. - u.value = x;
  3517. - u.bits &= (uint64_t)-1 / 2;
  3518. - return u.value;
  3519. + union {double f; uint64_t i;} u = {x};
  3520. + u.i &= -1ULL/2;
  3521. + return u.f;
  3522. }
  3523. diff -Nur musl-0.9.13/src/math/fabsf.c musl-git/src/math/fabsf.c
  3524. --- musl-0.9.13/src/math/fabsf.c 2013-08-30 23:30:53.000000000 +0200
  3525. +++ musl-git/src/math/fabsf.c 2013-09-16 20:31:39.000000000 +0200
  3526. @@ -1,10 +1,9 @@
  3527. -#include "libm.h"
  3528. +#include <math.h>
  3529. +#include <stdint.h>
  3530. float fabsf(float x)
  3531. {
  3532. - union fshape u;
  3533. -
  3534. - u.value = x;
  3535. - u.bits &= (uint32_t)-1 / 2;
  3536. - return u.value;
  3537. + union {float f; uint32_t i;} u = {x};
  3538. + u.i &= 0x7fffffff;
  3539. + return u.f;
  3540. }
  3541. diff -Nur musl-0.9.13/src/math/fabsl.c musl-git/src/math/fabsl.c
  3542. --- musl-0.9.13/src/math/fabsl.c 2013-08-30 23:30:53.000000000 +0200
  3543. +++ musl-git/src/math/fabsl.c 2013-09-16 20:31:39.000000000 +0200
  3544. @@ -9,7 +9,7 @@
  3545. {
  3546. union ldshape u = {x};
  3547. - u.bits.sign = 0;
  3548. - return u.value;
  3549. + u.i.se &= 0x7fff;
  3550. + return u.f;
  3551. }
  3552. #endif
  3553. diff -Nur musl-0.9.13/src/math/floor.c musl-git/src/math/floor.c
  3554. --- musl-0.9.13/src/math/floor.c 2013-08-30 23:30:53.000000000 +0200
  3555. +++ musl-git/src/math/floor.c 2013-09-16 20:31:39.000000000 +0200
  3556. @@ -1,82 +1,24 @@
  3557. -/* origin: FreeBSD /usr/src/lib/msun/src/s_floor.c */
  3558. -/*
  3559. - * ====================================================
  3560. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  3561. - *
  3562. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  3563. - * Permission to use, copy, modify, and distribute this
  3564. - * software is freely granted, provided that this notice
  3565. - * is preserved.
  3566. - * ====================================================
  3567. - */
  3568. -/*
  3569. - * floor(x)
  3570. - * Return x rounded toward -inf to integral value
  3571. - * Method:
  3572. - * Bit twiddling.
  3573. - * Exception:
  3574. - * Inexact flag raised if x not equal to floor(x).
  3575. - */
  3576. -
  3577. #include "libm.h"
  3578. -static const double huge = 1.0e300;
  3579. -
  3580. double floor(double x)
  3581. {
  3582. - int32_t i0,i1,j0;
  3583. - uint32_t i,j;
  3584. + union {double f; uint64_t i;} u = {x};
  3585. + int e = u.i >> 52 & 0x7ff;
  3586. + double_t y;
  3587. - EXTRACT_WORDS(i0, i1, x);
  3588. - // FIXME: signed shift
  3589. - j0 = ((i0>>20)&0x7ff) - 0x3ff;
  3590. - if (j0 < 20) {
  3591. - if (j0 < 0) { /* |x| < 1 */
  3592. - /* raise inexact if x != 0 */
  3593. - if (huge+x > 0.0) {
  3594. - if (i0 >= 0) { /* x >= 0 */
  3595. - i0 = i1 = 0;
  3596. - } else if (((i0&0x7fffffff)|i1) != 0) {
  3597. - i0 = 0xbff00000;
  3598. - i1 = 0;
  3599. - }
  3600. - }
  3601. - } else {
  3602. - i = 0x000fffff>>j0;
  3603. - if (((i0&i)|i1) == 0)
  3604. - return x; /* x is integral */
  3605. - /* raise inexact flag */
  3606. - if (huge+x > 0.0) {
  3607. - if (i0 < 0)
  3608. - i0 += 0x00100000>>j0;
  3609. - i0 &= ~i;
  3610. - i1 = 0;
  3611. - }
  3612. - }
  3613. - } else if (j0 > 51) {
  3614. - if (j0 == 0x400)
  3615. - return x+x; /* inf or NaN */
  3616. - else
  3617. - return x; /* x is integral */
  3618. - } else {
  3619. - i = (uint32_t)0xffffffff>>(j0-20);
  3620. - if ((i1&i) == 0)
  3621. - return x; /* x is integral */
  3622. - /* raise inexact flag */
  3623. - if (huge+x > 0.0) {
  3624. - if (i0 < 0) {
  3625. - if (j0 == 20)
  3626. - i0++;
  3627. - else {
  3628. - j = i1+(1<<(52-j0));
  3629. - if (j < i1)
  3630. - i0++; /* got a carry */
  3631. - i1 = j;
  3632. - }
  3633. - }
  3634. - i1 &= ~i;
  3635. - }
  3636. + if (e >= 0x3ff+52 || x == 0)
  3637. + return x;
  3638. + /* y = int(x) - x, where int(x) is an integer neighbor of x */
  3639. + if (u.i >> 63)
  3640. + y = (double)(x - 0x1p52) + 0x1p52 - x;
  3641. + else
  3642. + y = (double)(x + 0x1p52) - 0x1p52 - x;
  3643. + /* special case because of non-nearest rounding modes */
  3644. + if (e <= 0x3ff-1) {
  3645. + FORCE_EVAL(y);
  3646. + return u.i >> 63 ? -1 : 0;
  3647. }
  3648. - INSERT_WORDS(x, i0, i1);
  3649. - return x;
  3650. + if (y > 0)
  3651. + return x + y - 1;
  3652. + return x + y;
  3653. }
  3654. diff -Nur musl-0.9.13/src/math/floorf.c musl-git/src/math/floorf.c
  3655. --- musl-0.9.13/src/math/floorf.c 2013-08-30 23:30:53.000000000 +0200
  3656. +++ musl-git/src/math/floorf.c 2013-09-16 20:31:39.000000000 +0200
  3657. @@ -1,64 +1,27 @@
  3658. -/* origin: FreeBSD /usr/src/lib/msun/src/s_floorf.c */
  3659. -/*
  3660. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  3661. - */
  3662. -/*
  3663. - * ====================================================
  3664. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  3665. - *
  3666. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  3667. - * Permission to use, copy, modify, and distribute this
  3668. - * software is freely granted, provided that this notice
  3669. - * is preserved.
  3670. - * ====================================================
  3671. - */
  3672. -/*
  3673. - * floorf(x)
  3674. - * Return x rounded toward -inf to integral value
  3675. - * Method:
  3676. - * Bit twiddling.
  3677. - * Exception:
  3678. - * Inexact flag raised if x not equal to floorf(x).
  3679. - */
  3680. -
  3681. #include "libm.h"
  3682. -static const float huge = 1.0e30;
  3683. -
  3684. float floorf(float x)
  3685. {
  3686. - int32_t i0,j0;
  3687. - uint32_t i;
  3688. + union {float f; uint32_t i;} u = {x};
  3689. + int e = (int)(u.i >> 23 & 0xff) - 0x7f;
  3690. + uint32_t m;
  3691. - GET_FLOAT_WORD(i0, x);
  3692. - // FIXME: signed shift
  3693. - j0 = ((i0>>23)&0xff) - 0x7f;
  3694. - if (j0 < 23) {
  3695. - if (j0 < 0) { /* |x| < 1 */
  3696. - /* raise inexact if x != 0 */
  3697. - if (huge+x > 0.0f) {
  3698. - if (i0 >= 0) /* x >= 0 */
  3699. - i0 = 0;
  3700. - else if ((i0&0x7fffffff) != 0)
  3701. - i0 = 0xbf800000;
  3702. - }
  3703. - } else {
  3704. - i = 0x007fffff>>j0;
  3705. - if ((i0&i) == 0)
  3706. - return x; /* x is integral */
  3707. - /* raise inexact flag */
  3708. - if (huge+x > 0.0f) {
  3709. - if (i0 < 0)
  3710. - i0 += 0x00800000>>j0;
  3711. - i0 &= ~i;
  3712. - }
  3713. - }
  3714. + if (e >= 23)
  3715. + return x;
  3716. + if (e >= 0) {
  3717. + m = 0x007fffff >> e;
  3718. + if ((u.i & m) == 0)
  3719. + return x;
  3720. + FORCE_EVAL(x + 0x1p120f);
  3721. + if (u.i >> 31)
  3722. + u.i += m;
  3723. + u.i &= ~m;
  3724. } else {
  3725. - if (j0 == 0x80) /* inf or NaN */
  3726. - return x+x;
  3727. - else
  3728. - return x; /* x is integral */
  3729. + FORCE_EVAL(x + 0x1p120f);
  3730. + if (u.i >> 31 == 0)
  3731. + u.i = 0;
  3732. + else if (u.i << 1)
  3733. + u.f = -1.0;
  3734. }
  3735. - SET_FLOAT_WORD(x, i0);
  3736. - return x;
  3737. + return u.f;
  3738. }
  3739. diff -Nur musl-0.9.13/src/math/floorl.c musl-git/src/math/floorl.c
  3740. --- musl-0.9.13/src/math/floorl.c 2013-08-30 23:30:53.000000000 +0200
  3741. +++ musl-git/src/math/floorl.c 2013-09-16 20:31:39.000000000 +0200
  3742. @@ -1,23 +1,3 @@
  3743. -/* origin: FreeBSD /usr/src/lib/msun/src/s_floorl.c */
  3744. -/*
  3745. - * ====================================================
  3746. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  3747. - *
  3748. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  3749. - * Permission to use, copy, modify, and distribute this
  3750. - * software is freely granted, provided that this notice
  3751. - * is preserved.
  3752. - * ====================================================
  3753. - */
  3754. -/*
  3755. - * floorl(x)
  3756. - * Return x rounded toward -inf to integral value
  3757. - * Method:
  3758. - * Bit twiddling.
  3759. - * Exception:
  3760. - * Inexact flag raised if x not equal to floorl(x).
  3761. - */
  3762. -
  3763. #include "libm.h"
  3764. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  3765. @@ -26,77 +6,31 @@
  3766. return floor(x);
  3767. }
  3768. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  3769. -
  3770. -#ifdef LDBL_IMPLICIT_NBIT
  3771. -#define MANH_SIZE (LDBL_MANH_SIZE + 1)
  3772. -#define INC_MANH(u, c) do { \
  3773. - uint64_t o = u.bits.manh; \
  3774. - u.bits.manh += (c); \
  3775. - if (u.bits.manh < o) \
  3776. - u.bits.exp++; \
  3777. -} while (0)
  3778. -#else
  3779. -#define MANH_SIZE LDBL_MANH_SIZE
  3780. -#define INC_MANH(u, c) do { \
  3781. - uint64_t o = u.bits.manh; \
  3782. - u.bits.manh += (c); \
  3783. - if (u.bits.manh < o) { \
  3784. - u.bits.exp++; \
  3785. - u.bits.manh |= 1llu << (LDBL_MANH_SIZE - 1); \
  3786. - } \
  3787. -} while (0)
  3788. +#if LDBL_MANT_DIG == 64
  3789. +#define TOINT 0x1p63
  3790. +#elif LDBL_MANT_DIG == 113
  3791. +#define TOINT 0x1p112
  3792. #endif
  3793. -
  3794. -static const long double huge = 1.0e300;
  3795. -
  3796. long double floorl(long double x)
  3797. {
  3798. - union IEEEl2bits u = { .e = x };
  3799. - int e = u.bits.exp - LDBL_MAX_EXP + 1;
  3800. -
  3801. - if (e < MANH_SIZE - 1) {
  3802. - if (e < 0) {
  3803. - /* raise inexact if x != 0 */
  3804. - if (huge + x > 0.0)
  3805. - if (u.bits.exp > 0 ||
  3806. - (u.bits.manh | u.bits.manl) != 0)
  3807. - u.e = u.bits.sign ? -1.0 : 0.0;
  3808. - } else {
  3809. - uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
  3810. - if (((u.bits.manh & m) | u.bits.manl) == 0)
  3811. - return x; /* x is integral */
  3812. - if (u.bits.sign) {
  3813. -#ifdef LDBL_IMPLICIT_NBIT
  3814. - if (e == 0)
  3815. - u.bits.exp++;
  3816. - else
  3817. -#endif
  3818. - INC_MANH(u, 1llu << (MANH_SIZE - e - 1));
  3819. - }
  3820. - /* raise inexact flag */
  3821. - if (huge + x > 0.0) {
  3822. - u.bits.manh &= ~m;
  3823. - u.bits.manl = 0;
  3824. - }
  3825. - }
  3826. - } else if (e < LDBL_MANT_DIG - 1) {
  3827. - uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
  3828. - if ((u.bits.manl & m) == 0)
  3829. - return x; /* x is integral */
  3830. - if (u.bits.sign) {
  3831. - if (e == MANH_SIZE - 1)
  3832. - INC_MANH(u, 1);
  3833. - else {
  3834. - uint64_t o = u.bits.manl;
  3835. - u.bits.manl += 1llu << (LDBL_MANT_DIG - e - 1);
  3836. - if (u.bits.manl < o) /* got a carry */
  3837. - INC_MANH(u, 1);
  3838. - }
  3839. - }
  3840. - /* raise inexact flag */
  3841. - if (huge + x > 0.0)
  3842. - u.bits.manl &= ~m;
  3843. + union ldshape u = {x};
  3844. + int e = u.i.se & 0x7fff;
  3845. + long double y;
  3846. +
  3847. + if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0)
  3848. + return x;
  3849. + /* y = int(x) - x, where int(x) is an integer neighbor of x */
  3850. + if (u.i.se >> 15)
  3851. + y = x - TOINT + TOINT - x;
  3852. + else
  3853. + y = x + TOINT - TOINT - x;
  3854. + /* special case because of non-nearest rounding modes */
  3855. + if (e <= 0x3fff-1) {
  3856. + FORCE_EVAL(y);
  3857. + return u.i.se >> 15 ? -1 : 0;
  3858. }
  3859. - return u.e;
  3860. + if (y > 0)
  3861. + return x + y - 1;
  3862. + return x + y;
  3863. }
  3864. #endif
  3865. diff -Nur musl-0.9.13/src/math/fma.c musl-git/src/math/fma.c
  3866. --- musl-0.9.13/src/math/fma.c 2013-08-30 23:30:53.000000000 +0200
  3867. +++ musl-git/src/math/fma.c 2013-09-16 20:31:39.000000000 +0200
  3868. @@ -2,16 +2,6 @@
  3869. #include "libm.h"
  3870. #if LDBL_MANT_DIG==64 && LDBL_MAX_EXP==16384
  3871. -union ld80 {
  3872. - long double x;
  3873. - struct {
  3874. - uint64_t m;
  3875. - uint16_t e : 15;
  3876. - uint16_t s : 1;
  3877. - uint16_t pad;
  3878. - } bits;
  3879. -};
  3880. -
  3881. /* exact add, assumes exponent_x >= exponent_y */
  3882. static void add(long double *hi, long double *lo, long double x, long double y)
  3883. {
  3884. @@ -45,25 +35,25 @@
  3885. */
  3886. static long double adjust(long double hi, long double lo)
  3887. {
  3888. - union ld80 uhi, ulo;
  3889. + union ldshape uhi, ulo;
  3890. if (lo == 0)
  3891. return hi;
  3892. - uhi.x = hi;
  3893. - if (uhi.bits.m & 0x3ff)
  3894. + uhi.f = hi;
  3895. + if (uhi.i.m & 0x3ff)
  3896. return hi;
  3897. - ulo.x = lo;
  3898. - if (uhi.bits.s == ulo.bits.s)
  3899. - uhi.bits.m++;
  3900. + ulo.f = lo;
  3901. + if ((uhi.i.se & 0x8000) == (ulo.i.se & 0x8000))
  3902. + uhi.i.m++;
  3903. else {
  3904. - uhi.bits.m--;
  3905. /* handle underflow and take care of ld80 implicit msb */
  3906. - if (uhi.bits.m == (uint64_t)-1/2) {
  3907. - uhi.bits.m *= 2;
  3908. - uhi.bits.e--;
  3909. + if (uhi.i.m << 1 == 0) {
  3910. + uhi.i.m = 0;
  3911. + uhi.i.se--;
  3912. }
  3913. + uhi.i.m--;
  3914. }
  3915. - return uhi.x;
  3916. + return uhi.f;
  3917. }
  3918. /* adjusted add so the result is correct when rounded to double (or less) precision */
  3919. @@ -82,9 +72,9 @@
  3920. static int getexp(long double x)
  3921. {
  3922. - union ld80 u;
  3923. - u.x = x;
  3924. - return u.bits.e;
  3925. + union ldshape u;
  3926. + u.f = x;
  3927. + return u.i.se & 0x7fff;
  3928. }
  3929. double fma(double x, double y, double z)
  3930. @@ -242,16 +232,16 @@
  3931. static inline double add_adjusted(double a, double b)
  3932. {
  3933. struct dd sum;
  3934. - uint64_t hibits, lobits;
  3935. + union {double f; uint64_t i;} uhi, ulo;
  3936. sum = dd_add(a, b);
  3937. if (sum.lo != 0) {
  3938. - EXTRACT_WORD64(hibits, sum.hi);
  3939. - if ((hibits & 1) == 0) {
  3940. + uhi.f = sum.hi;
  3941. + if ((uhi.i & 1) == 0) {
  3942. /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */
  3943. - EXTRACT_WORD64(lobits, sum.lo);
  3944. - hibits += 1 - ((hibits ^ lobits) >> 62);
  3945. - INSERT_WORD64(sum.hi, hibits);
  3946. + ulo.f = sum.lo;
  3947. + uhi.i += 1 - ((uhi.i ^ ulo.i) >> 62);
  3948. + sum.hi = uhi.f;
  3949. }
  3950. }
  3951. return (sum.hi);
  3952. @@ -265,7 +255,7 @@
  3953. static inline double add_and_denormalize(double a, double b, int scale)
  3954. {
  3955. struct dd sum;
  3956. - uint64_t hibits, lobits;
  3957. + union {double f; uint64_t i;} uhi, ulo;
  3958. int bits_lost;
  3959. sum = dd_add(a, b);
  3960. @@ -281,13 +271,13 @@
  3961. * break the ties manually.
  3962. */
  3963. if (sum.lo != 0) {
  3964. - EXTRACT_WORD64(hibits, sum.hi);
  3965. - bits_lost = -((int)(hibits >> 52) & 0x7ff) - scale + 1;
  3966. - if (bits_lost != 1 ^ (int)(hibits & 1)) {
  3967. + uhi.f = sum.hi;
  3968. + bits_lost = -((int)(uhi.i >> 52) & 0x7ff) - scale + 1;
  3969. + if (bits_lost != 1 ^ (int)(uhi.i & 1)) {
  3970. /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */
  3971. - EXTRACT_WORD64(lobits, sum.lo);
  3972. - hibits += 1 - (((hibits ^ lobits) >> 62) & 2);
  3973. - INSERT_WORD64(sum.hi, hibits);
  3974. + ulo.f = sum.lo;
  3975. + uhi.i += 1 - (((uhi.i ^ ulo.i) >> 62) & 2);
  3976. + sum.hi = uhi.f;
  3977. }
  3978. }
  3979. return scalbn(sum.hi, scale);
  3980. diff -Nur musl-0.9.13/src/math/fmal.c musl-git/src/math/fmal.c
  3981. --- musl-0.9.13/src/math/fmal.c 2013-08-30 23:30:53.000000000 +0200
  3982. +++ musl-git/src/math/fmal.c 2013-09-16 20:31:39.000000000 +0200
  3983. @@ -34,6 +34,13 @@
  3984. }
  3985. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  3986. #include <fenv.h>
  3987. +#if LDBL_MANT_DIG == 64
  3988. +#define LASTBIT(u) (u.i.m & 1)
  3989. +#define SPLIT (0x1p32L + 1)
  3990. +#elif LDBL_MANT_DIG == 113
  3991. +#define LASTBIT(u) (u.i.lo & 1)
  3992. +#define SPLIT (0x1p57L + 1)
  3993. +#endif
  3994. /*
  3995. * A struct dd represents a floating-point number with twice the precision
  3996. @@ -75,12 +82,12 @@
  3997. static inline long double add_adjusted(long double a, long double b)
  3998. {
  3999. struct dd sum;
  4000. - union IEEEl2bits u;
  4001. + union ldshape u;
  4002. sum = dd_add(a, b);
  4003. if (sum.lo != 0) {
  4004. - u.e = sum.hi;
  4005. - if ((u.bits.manl & 1) == 0)
  4006. + u.f = sum.hi;
  4007. + if (!LASTBIT(u))
  4008. sum.hi = nextafterl(sum.hi, INFINITY * sum.lo);
  4009. }
  4010. return (sum.hi);
  4011. @@ -95,7 +102,7 @@
  4012. {
  4013. struct dd sum;
  4014. int bits_lost;
  4015. - union IEEEl2bits u;
  4016. + union ldshape u;
  4017. sum = dd_add(a, b);
  4018. @@ -110,9 +117,9 @@
  4019. * break the ties manually.
  4020. */
  4021. if (sum.lo != 0) {
  4022. - u.e = sum.hi;
  4023. - bits_lost = -u.bits.exp - scale + 1;
  4024. - if (bits_lost != 1 ^ (int)(u.bits.manl & 1))
  4025. + u.f = sum.hi;
  4026. + bits_lost = -u.i.se - scale + 1;
  4027. + if ((bits_lost != 1) ^ LASTBIT(u))
  4028. sum.hi = nextafterl(sum.hi, INFINITY * sum.lo);
  4029. }
  4030. return scalbnl(sum.hi, scale);
  4031. @@ -125,20 +132,15 @@
  4032. */
  4033. static inline struct dd dd_mul(long double a, long double b)
  4034. {
  4035. -#if LDBL_MANT_DIG == 64
  4036. - static const long double split = 0x1p32L + 1.0;
  4037. -#elif LDBL_MANT_DIG == 113
  4038. - static const long double split = 0x1p57L + 1.0;
  4039. -#endif
  4040. struct dd ret;
  4041. long double ha, hb, la, lb, p, q;
  4042. - p = a * split;
  4043. + p = a * SPLIT;
  4044. ha = a - p;
  4045. ha += p;
  4046. la = a - ha;
  4047. - p = b * split;
  4048. + p = b * SPLIT;
  4049. hb = b - p;
  4050. hb += p;
  4051. lb = b - hb;
  4052. diff -Nur musl-0.9.13/src/math/fmod.c musl-git/src/math/fmod.c
  4053. --- musl-0.9.13/src/math/fmod.c 2013-08-30 23:30:53.000000000 +0200
  4054. +++ musl-git/src/math/fmod.c 2013-09-16 20:31:39.000000000 +0200
  4055. @@ -1,145 +1,68 @@
  4056. -/* origin: FreeBSD /usr/src/lib/msun/src/e_fmod.c */
  4057. -/*
  4058. - * ====================================================
  4059. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4060. - *
  4061. - * Developed at SunSoft, a Sun Microsystems, Inc. business.
  4062. - * Permission to use, copy, modify, and distribute this
  4063. - * software is freely granted, provided that this notice
  4064. - * is preserved.
  4065. - * ====================================================
  4066. - */
  4067. -/*
  4068. - * fmod(x,y)
  4069. - * Return x mod y in exact arithmetic
  4070. - * Method: shift and subtract
  4071. - */
  4072. -
  4073. -#include "libm.h"
  4074. -
  4075. -static const double Zero[] = {0.0, -0.0,};
  4076. +#include <math.h>
  4077. +#include <stdint.h>
  4078. double fmod(double x, double y)
  4079. {
  4080. - int32_t n,hx,hy,hz,ix,iy,sx,i;
  4081. - uint32_t lx,ly,lz;
  4082. + union {double f; uint64_t i;} ux = {x}, uy = {y};
  4083. + int ex = ux.i>>52 & 0x7ff;
  4084. + int ey = uy.i>>52 & 0x7ff;
  4085. + int sx = ux.i>>63;
  4086. + uint64_t i;
  4087. +
  4088. + /* in the followings uxi should be ux.i, but then gcc wrongly adds */
  4089. + /* float load/store to inner loops ruining performance and code size */
  4090. + uint64_t uxi = ux.i;
  4091. - EXTRACT_WORDS(hx, lx, x);
  4092. - EXTRACT_WORDS(hy, ly, y);
  4093. - sx = hx & 0x80000000; /* sign of x */
  4094. - hx ^= sx; /* |x| */
  4095. - hy &= 0x7fffffff; /* |y| */
  4096. -
  4097. - /* purge off exception values */
  4098. - if ((hy|ly) == 0 || hx >= 0x7ff00000 || /* y=0,or x not finite */
  4099. - (hy|((ly|-ly)>>31)) > 0x7ff00000) /* or y is NaN */
  4100. + if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff)
  4101. return (x*y)/(x*y);
  4102. - if (hx <= hy) {
  4103. - if (hx < hy || lx < ly) /* |x| < |y| */
  4104. - return x;
  4105. - if (lx == ly) /* |x| = |y|, return x*0 */
  4106. - return Zero[(uint32_t)sx>>31];
  4107. - }
  4108. -
  4109. - /* determine ix = ilogb(x) */
  4110. - if (hx < 0x00100000) { /* subnormal x */
  4111. - if (hx == 0) {
  4112. - for (ix = -1043, i = lx; i > 0; i <<= 1)
  4113. - ix -= 1;
  4114. - } else {
  4115. - for (ix = -1022, i = hx<<11; i > 0; i <<= 1)
  4116. - ix -= 1;
  4117. - }
  4118. - } else
  4119. - ix = (hx>>20) - 1023;
  4120. -
  4121. - /* determine iy = ilogb(y) */
  4122. - if (hy < 0x00100000) { /* subnormal y */
  4123. - if (hy == 0) {
  4124. - for (iy = -1043, i = ly; i > 0; i <<= 1)
  4125. - iy -= 1;
  4126. - } else {
  4127. - for (iy = -1022, i = hy<<11; i > 0; i <<= 1)
  4128. - iy -= 1;
  4129. - }
  4130. - } else
  4131. - iy = (hy>>20) - 1023;
  4132. -
  4133. - /* set up {hx,lx}, {hy,ly} and align y to x */
  4134. - if (ix >= -1022)
  4135. - hx = 0x00100000|(0x000fffff&hx);
  4136. - else { /* subnormal x, shift x to normal */
  4137. - n = -1022-ix;
  4138. - if (n <= 31) {
  4139. - hx = (hx<<n)|(lx>>(32-n));
  4140. - lx <<= n;
  4141. - } else {
  4142. - hx = lx<<(n-32);
  4143. - lx = 0;
  4144. - }
  4145. - }
  4146. - if(iy >= -1022)
  4147. - hy = 0x00100000|(0x000fffff&hy);
  4148. - else { /* subnormal y, shift y to normal */
  4149. - n = -1022-iy;
  4150. - if (n <= 31) {
  4151. - hy = (hy<<n)|(ly>>(32-n));
  4152. - ly <<= n;
  4153. - } else {
  4154. - hy = ly<<(n-32);
  4155. - ly = 0;
  4156. - }
  4157. - }
  4158. -
  4159. - /* fix point fmod */
  4160. - n = ix - iy;
  4161. - while (n--) {
  4162. - hz = hx-hy;
  4163. - lz = lx-ly;
  4164. - if (lx < ly)
  4165. - hz -= 1;
  4166. - if (hz < 0) {
  4167. - hx = hx+hx+(lx>>31);
  4168. - lx = lx+lx;
  4169. - } else {
  4170. - if ((hz|lz) == 0) /* return sign(x)*0 */
  4171. - return Zero[(uint32_t)sx>>31];
  4172. - hx = hz+hz+(lz>>31);
  4173. - lx = lz+lz;
  4174. - }
  4175. - }
  4176. - hz = hx-hy;
  4177. - lz = lx-ly;
  4178. - if (lx < ly)
  4179. - hz -= 1;
  4180. - if (hz >= 0) {
  4181. - hx = hz;
  4182. - lx = lz;
  4183. - }
  4184. -
  4185. - /* convert back to floating value and restore the sign */
  4186. - if ((hx|lx) == 0) /* return sign(x)*0 */
  4187. - return Zero[(uint32_t)sx>>31];
  4188. - while (hx < 0x00100000) { /* normalize x */
  4189. - hx = hx+hx+(lx>>31);
  4190. - lx = lx+lx;
  4191. - iy -= 1;
  4192. - }
  4193. - if (iy >= -1022) { /* normalize output */
  4194. - hx = ((hx-0x00100000)|((iy+1023)<<20));
  4195. - INSERT_WORDS(x, hx|sx, lx);
  4196. - } else { /* subnormal output */
  4197. - n = -1022 - iy;
  4198. - if (n <= 20) {
  4199. - lx = (lx>>n)|((uint32_t)hx<<(32-n));
  4200. - hx >>= n;
  4201. - } else if (n <= 31) {
  4202. - lx = (hx<<(32-n))|(lx>>n);
  4203. - hx = sx;
  4204. - } else {
  4205. - lx = hx>>(n-32); hx = sx;
  4206. - }
  4207. - INSERT_WORDS(x, hx|sx, lx);
  4208. - }
  4209. - return x; /* exact output */
  4210. + if (uxi<<1 <= uy.i<<1) {
  4211. + if (uxi<<1 == uy.i<<1)
  4212. + return 0*x;
  4213. + return x;
  4214. + }
  4215. +
  4216. + /* normalize x and y */
  4217. + if (!ex) {
  4218. + for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1);
  4219. + uxi <<= -ex + 1;
  4220. + } else {
  4221. + uxi &= -1ULL >> 12;
  4222. + uxi |= 1ULL << 52;
  4223. + }
  4224. + if (!ey) {
  4225. + for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1);
  4226. + uy.i <<= -ey + 1;
  4227. + } else {
  4228. + uy.i &= -1ULL >> 12;
  4229. + uy.i |= 1ULL << 52;
  4230. + }
  4231. +
  4232. + /* x mod y */
  4233. + for (; ex > ey; ex--) {
  4234. + i = uxi - uy.i;
  4235. + if (i >> 63 == 0) {
  4236. + if (i == 0)
  4237. + return 0*x;
  4238. + uxi = i;
  4239. + }
  4240. + uxi <<= 1;
  4241. + }
  4242. + i = uxi - uy.i;
  4243. + if (i >> 63 == 0) {
  4244. + if (i == 0)
  4245. + return 0*x;
  4246. + uxi = i;
  4247. + }
  4248. + for (; uxi>>52 == 0; uxi <<= 1, ex--);
  4249. +
  4250. + /* scale result */
  4251. + if (ex > 0) {
  4252. + uxi -= 1ULL << 52;
  4253. + uxi |= (uint64_t)ex << 52;
  4254. + } else {
  4255. + uxi >>= -ex + 1;
  4256. + }
  4257. + uxi |= (uint64_t)sx << 63;
  4258. + ux.i = uxi;
  4259. + return ux.f;
  4260. }
  4261. diff -Nur musl-0.9.13/src/math/fmodf.c musl-git/src/math/fmodf.c
  4262. --- musl-0.9.13/src/math/fmodf.c 2013-08-30 23:30:53.000000000 +0200
  4263. +++ musl-git/src/math/fmodf.c 2013-09-16 20:31:39.000000000 +0200
  4264. @@ -1,104 +1,65 @@
  4265. -/* origin: FreeBSD /usr/src/lib/msun/src/e_fmodf.c */
  4266. -/*
  4267. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  4268. - */
  4269. -/*
  4270. - * ====================================================
  4271. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4272. - *
  4273. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  4274. - * Permission to use, copy, modify, and distribute this
  4275. - * software is freely granted, provided that this notice
  4276. - * is preserved.
  4277. - * ====================================================
  4278. - */
  4279. -/*
  4280. - * fmodf(x,y)
  4281. - * Return x mod y in exact arithmetic
  4282. - * Method: shift and subtract
  4283. - */
  4284. -
  4285. -#include "libm.h"
  4286. -
  4287. -static const float Zero[] = {0.0, -0.0,};
  4288. +#include <math.h>
  4289. +#include <stdint.h>
  4290. float fmodf(float x, float y)
  4291. {
  4292. - int32_t n,hx,hy,hz,ix,iy,sx,i;
  4293. + union {float f; uint32_t i;} ux = {x}, uy = {y};
  4294. + int ex = ux.i>>23 & 0xff;
  4295. + int ey = uy.i>>23 & 0xff;
  4296. + uint32_t sx = ux.i & 0x80000000;
  4297. + uint32_t i;
  4298. + uint32_t uxi = ux.i;
  4299. - GET_FLOAT_WORD(hx, x);
  4300. - GET_FLOAT_WORD(hy, y);
  4301. - sx = hx & 0x80000000; /* sign of x */
  4302. - hx ^= sx; /* |x| */
  4303. - hy &= 0x7fffffff; /* |y| */
  4304. -
  4305. - /* purge off exception values */
  4306. - if (hy == 0 || hx >= 0x7f800000 || /* y=0,or x not finite */
  4307. - hy > 0x7f800000) /* or y is NaN */
  4308. + if (uy.i<<1 == 0 || isnan(y) || ex == 0xff)
  4309. return (x*y)/(x*y);
  4310. - if (hx < hy) /* |x| < |y| */
  4311. + if (uxi<<1 <= uy.i<<1) {
  4312. + if (uxi<<1 == uy.i<<1)
  4313. + return 0*x;
  4314. return x;
  4315. - if (hx == hy) /* |x| = |y|, return x*0 */
  4316. - return Zero[(uint32_t)sx>>31];
  4317. -
  4318. - /* determine ix = ilogb(x) */
  4319. - if (hx < 0x00800000) { /* subnormal x */
  4320. - for (ix = -126, i = hx<<8; i > 0; i <<= 1)
  4321. - ix -= 1;
  4322. - } else
  4323. - ix = (hx>>23) - 127;
  4324. -
  4325. - /* determine iy = ilogb(y) */
  4326. - if (hy < 0x00800000) { /* subnormal y */
  4327. - for (iy = -126, i = hy<<8; i >= 0; i <<= 1)
  4328. - iy -= 1;
  4329. - } else
  4330. - iy = (hy>>23) - 127;
  4331. + }
  4332. - /* set up {hx,lx}, {hy,ly} and align y to x */
  4333. - if (ix >= -126)
  4334. - hx = 0x00800000|(0x007fffff&hx);
  4335. - else { /* subnormal x, shift x to normal */
  4336. - n = -126-ix;
  4337. - hx = hx<<n;
  4338. - }
  4339. - if (iy >= -126)
  4340. - hy = 0x00800000|(0x007fffff&hy);
  4341. - else { /* subnormal y, shift y to normal */
  4342. - n = -126-iy;
  4343. - hy = hy<<n;
  4344. + /* normalize x and y */
  4345. + if (!ex) {
  4346. + for (i = uxi<<9; i>>31 == 0; ex--, i <<= 1);
  4347. + uxi <<= -ex + 1;
  4348. + } else {
  4349. + uxi &= -1U >> 9;
  4350. + uxi |= 1U << 23;
  4351. + }
  4352. + if (!ey) {
  4353. + for (i = uy.i<<9; i>>31 == 0; ey--, i <<= 1);
  4354. + uy.i <<= -ey + 1;
  4355. + } else {
  4356. + uy.i &= -1U >> 9;
  4357. + uy.i |= 1U << 23;
  4358. }
  4359. - /* fix point fmod */
  4360. - n = ix - iy;
  4361. - while (n--) {
  4362. - hz = hx-hy;
  4363. - if (hz<0)
  4364. - hx = hx+hx;
  4365. - else {
  4366. - if(hz == 0) /* return sign(x)*0 */
  4367. - return Zero[(uint32_t)sx>>31];
  4368. - hx = hz+hz;
  4369. + /* x mod y */
  4370. + for (; ex > ey; ex--) {
  4371. + i = uxi - uy.i;
  4372. + if (i >> 31 == 0) {
  4373. + if (i == 0)
  4374. + return 0*x;
  4375. + uxi = i;
  4376. }
  4377. + uxi <<= 1;
  4378. + }
  4379. + i = uxi - uy.i;
  4380. + if (i >> 31 == 0) {
  4381. + if (i == 0)
  4382. + return 0*x;
  4383. + uxi = i;
  4384. }
  4385. - hz = hx-hy;
  4386. - if (hz >= 0)
  4387. - hx = hz;
  4388. + for (; uxi>>23 == 0; uxi <<= 1, ex--);
  4389. - /* convert back to floating value and restore the sign */
  4390. - if (hx == 0) /* return sign(x)*0 */
  4391. - return Zero[(uint32_t)sx>>31];
  4392. - while (hx < 0x00800000) { /* normalize x */
  4393. - hx = hx+hx;
  4394. - iy -= 1;
  4395. - }
  4396. - if (iy >= -126) { /* normalize output */
  4397. - hx = ((hx-0x00800000)|((iy+127)<<23));
  4398. - SET_FLOAT_WORD(x, hx|sx);
  4399. - } else { /* subnormal output */
  4400. - n = -126 - iy;
  4401. - hx >>= n;
  4402. - SET_FLOAT_WORD(x, hx|sx);
  4403. + /* scale result up */
  4404. + if (ex > 0) {
  4405. + uxi -= 1U << 23;
  4406. + uxi |= (uint32_t)ex << 23;
  4407. + } else {
  4408. + uxi >>= -ex + 1;
  4409. }
  4410. - return x; /* exact output */
  4411. + uxi |= sx;
  4412. + ux.i = uxi;
  4413. + return ux.f;
  4414. }
  4415. diff -Nur musl-0.9.13/src/math/fmodl.c musl-git/src/math/fmodl.c
  4416. --- musl-0.9.13/src/math/fmodl.c 2013-08-30 23:30:53.000000000 +0200
  4417. +++ musl-git/src/math/fmodl.c 2013-09-16 20:31:39.000000000 +0200
  4418. @@ -1,15 +1,3 @@
  4419. -/* origin: FreeBSD /usr/src/lib/msun/src/e_fmodl.c */
  4420. -/*-
  4421. - * ====================================================
  4422. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4423. - *
  4424. - * Developed at SunSoft, a Sun Microsystems, Inc. business.
  4425. - * Permission to use, copy, modify, and distribute this
  4426. - * software is freely granted, provided that this notice
  4427. - * is preserved.
  4428. - * ====================================================
  4429. - */
  4430. -
  4431. #include "libm.h"
  4432. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  4433. @@ -18,141 +6,100 @@
  4434. return fmod(x, y);
  4435. }
  4436. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  4437. -
  4438. -#define BIAS (LDBL_MAX_EXP - 1)
  4439. -
  4440. -#if LDBL_MANL_SIZE > 32
  4441. -typedef uint64_t manl_t;
  4442. -#else
  4443. -typedef uint32_t manl_t;
  4444. -#endif
  4445. -
  4446. -#if LDBL_MANH_SIZE > 32
  4447. -typedef uint64_t manh_t;
  4448. -#else
  4449. -typedef uint32_t manh_t;
  4450. -#endif
  4451. -
  4452. -/*
  4453. - * These macros add and remove an explicit integer bit in front of the
  4454. - * fractional mantissa, if the architecture doesn't have such a bit by
  4455. - * default already.
  4456. - */
  4457. -#ifdef LDBL_IMPLICIT_NBIT
  4458. -#define SET_NBIT(hx) ((hx) | (1ULL << LDBL_MANH_SIZE))
  4459. -#define HFRAC_BITS LDBL_MANH_SIZE
  4460. -#else
  4461. -#define SET_NBIT(hx) (hx)
  4462. -#define HFRAC_BITS (LDBL_MANH_SIZE - 1)
  4463. -#endif
  4464. -
  4465. -#define MANL_SHIFT (LDBL_MANL_SIZE - 1)
  4466. -
  4467. -static const long double Zero[] = {0.0, -0.0,};
  4468. -
  4469. -/*
  4470. - * fmodl(x,y)
  4471. - * Return x mod y in exact arithmetic
  4472. - * Method: shift and subtract
  4473. - *
  4474. - * Assumptions:
  4475. - * - The low part of the mantissa fits in a manl_t exactly.
  4476. - * - The high part of the mantissa fits in an int64_t with enough room
  4477. - * for an explicit integer bit in front of the fractional bits.
  4478. - */
  4479. long double fmodl(long double x, long double y)
  4480. {
  4481. - union IEEEl2bits ux, uy;
  4482. - int64_t hx,hz; /* We need a carry bit even if LDBL_MANH_SIZE is 32. */
  4483. - manh_t hy;
  4484. - manl_t lx,ly,lz;
  4485. - int ix,iy,n,sx;
  4486. -
  4487. - ux.e = x;
  4488. - uy.e = y;
  4489. - sx = ux.bits.sign;
  4490. + union ldshape ux = {x}, uy = {y};
  4491. + int ex = ux.i.se & 0x7fff;
  4492. + int ey = uy.i.se & 0x7fff;
  4493. + int sx = ux.i.se & 0x8000;
  4494. - /* purge off exception values */
  4495. - if ((uy.bits.exp|uy.bits.manh|uy.bits.manl) == 0 || /* y=0 */
  4496. - ux.bits.exp == BIAS + LDBL_MAX_EXP || /* or x not finite */
  4497. - (uy.bits.exp == BIAS + LDBL_MAX_EXP &&
  4498. - ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0)) /* or y is NaN */
  4499. + if (y == 0 || isnan(y) || ex == 0x7fff)
  4500. return (x*y)/(x*y);
  4501. - if (ux.bits.exp <= uy.bits.exp) {
  4502. - if (ux.bits.exp < uy.bits.exp ||
  4503. - (ux.bits.manh<=uy.bits.manh &&
  4504. - (ux.bits.manh<uy.bits.manh ||
  4505. - ux.bits.manl<uy.bits.manl))) /* |x|<|y| return x or x-y */
  4506. - return x;
  4507. - if (ux.bits.manh==uy.bits.manh && ux.bits.manl==uy.bits.manl)
  4508. - return Zero[sx]; /* |x| = |y| return x*0 */
  4509. - }
  4510. -
  4511. - /* determine ix = ilogb(x) */
  4512. - if (ux.bits.exp == 0) { /* subnormal x */
  4513. - ux.e *= 0x1.0p512;
  4514. - ix = ux.bits.exp - (BIAS + 512);
  4515. - } else {
  4516. - ix = ux.bits.exp - BIAS;
  4517. - }
  4518. -
  4519. - /* determine iy = ilogb(y) */
  4520. - if (uy.bits.exp == 0) { /* subnormal y */
  4521. - uy.e *= 0x1.0p512;
  4522. - iy = uy.bits.exp - (BIAS + 512);
  4523. - } else {
  4524. - iy = uy.bits.exp - BIAS;
  4525. - }
  4526. -
  4527. - /* set up {hx,lx}, {hy,ly} and align y to x */
  4528. - hx = SET_NBIT(ux.bits.manh);
  4529. - hy = SET_NBIT(uy.bits.manh);
  4530. - lx = ux.bits.manl;
  4531. - ly = uy.bits.manl;
  4532. -
  4533. - /* fix point fmod */
  4534. - n = ix - iy;
  4535. -
  4536. - while (n--) {
  4537. - hz = hx-hy;
  4538. - lz = lx-ly;
  4539. - if (lx < ly)
  4540. - hz -= 1;
  4541. - if (hz < 0) {
  4542. - hx = hx+hx+(lx>>MANL_SHIFT);
  4543. - lx = lx+lx;
  4544. + ux.i.se = ex;
  4545. + uy.i.se = ey;
  4546. + if (ux.f <= uy.f) {
  4547. + if (ux.f == uy.f)
  4548. + return 0*x;
  4549. + return x;
  4550. + }
  4551. +
  4552. + /* normalize x and y */
  4553. + if (!ex) {
  4554. + ux.f *= 0x1p120f;
  4555. + ex = ux.i.se - 120;
  4556. + }
  4557. + if (!ey) {
  4558. + uy.f *= 0x1p120f;
  4559. + ey = uy.i.se - 120;
  4560. + }
  4561. +
  4562. + /* x mod y */
  4563. +#if LDBL_MANT_DIG == 64
  4564. + uint64_t i, mx, my;
  4565. + mx = ux.i.m;
  4566. + my = uy.i.m;
  4567. + for (; ex > ey; ex--) {
  4568. + i = mx - my;
  4569. + if (mx >= my) {
  4570. + if (i == 0)
  4571. + return 0*x;
  4572. + mx = 2*i;
  4573. + } else if (2*mx < mx) {
  4574. + mx = 2*mx - my;
  4575. } else {
  4576. - if ((hz|lz)==0) /* return sign(x)*0 */
  4577. - return Zero[sx];
  4578. - hx = hz+hz+(lz>>MANL_SHIFT);
  4579. - lx = lz+lz;
  4580. + mx = 2*mx;
  4581. }
  4582. }
  4583. - hz = hx-hy;
  4584. - lz = lx-ly;
  4585. - if (lx < ly)
  4586. - hz -= 1;
  4587. - if (hz >= 0) {
  4588. - hx = hz;
  4589. - lx = lz;
  4590. + i = mx - my;
  4591. + if (mx >= my) {
  4592. + if (i == 0)
  4593. + return 0*x;
  4594. + mx = i;
  4595. + }
  4596. + for (; mx >> 63 == 0; mx *= 2, ex--);
  4597. + ux.i.m = mx;
  4598. +#elif LDBL_MANT_DIG == 113
  4599. + uint64_t hi, lo, xhi, xlo, yhi, ylo;
  4600. + xhi = (ux.i2.hi & -1ULL>>16) | 1ULL<<48;
  4601. + yhi = (uy.i2.hi & -1ULL>>16) | 1ULL<<48;
  4602. + xlo = ux.i2.lo;
  4603. + ylo = ux.i2.lo;
  4604. + for (; ex > ey; ex--) {
  4605. + hi = xhi - yhi;
  4606. + lo = xlo - ylo;
  4607. + if (xlo < ylo)
  4608. + hi -= 1;
  4609. + if (hi >> 63 == 0) {
  4610. + if ((hi|lo) == 0)
  4611. + return 0*x;
  4612. + xhi = 2*hi + (lo>>63);
  4613. + xlo = 2*lo;
  4614. + } else {
  4615. + xhi = 2*xhi + (xlo>>63);
  4616. + xlo = 2*xlo;
  4617. + }
  4618. }
  4619. + hi = xhi - yhi;
  4620. + lo = xlo - ylo;
  4621. + if (xlo < ylo)
  4622. + hi -= 1;
  4623. + if (hi >> 63 == 0) {
  4624. + if ((hi|lo) == 0)
  4625. + return 0*x;
  4626. + xhi = hi;
  4627. + xlo = lo;
  4628. + }
  4629. + for (; xhi >> 48 == 0; xhi = 2*xhi + (xlo>>63), xlo = 2*xlo, ex--);
  4630. + ux.i2.hi = xhi;
  4631. + ux.i2.lo = xlo;
  4632. +#endif
  4633. - /* convert back to floating value and restore the sign */
  4634. - if ((hx|lx) == 0) /* return sign(x)*0 */
  4635. - return Zero[sx];
  4636. - while (hx < (1ULL<<HFRAC_BITS)) { /* normalize x */
  4637. - hx = hx+hx+(lx>>MANL_SHIFT);
  4638. - lx = lx+lx;
  4639. - iy -= 1;
  4640. - }
  4641. - ux.bits.manh = hx; /* The mantissa is truncated here if needed. */
  4642. - ux.bits.manl = lx;
  4643. - if (iy < LDBL_MIN_EXP) {
  4644. - ux.bits.exp = iy + (BIAS + 512);
  4645. - ux.e *= 0x1p-512;
  4646. - } else {
  4647. - ux.bits.exp = iy + BIAS;
  4648. - }
  4649. - return ux.e; /* exact output */
  4650. + /* scale result */
  4651. + if (ex <= 0) {
  4652. + ux.i.se = (ex+120)|sx;
  4653. + ux.f *= 0x1p-120f;
  4654. + } else
  4655. + ux.i.se = ex|sx;
  4656. + return ux.f;
  4657. }
  4658. #endif
  4659. diff -Nur musl-0.9.13/src/math/frexpl.c musl-git/src/math/frexpl.c
  4660. --- musl-0.9.13/src/math/frexpl.c 2013-08-30 23:30:53.000000000 +0200
  4661. +++ musl-git/src/math/frexpl.c 2013-09-16 20:31:39.000000000 +0200
  4662. @@ -1,20 +1,20 @@
  4663. -#include <math.h>
  4664. -#include <stdint.h>
  4665. -#include <float.h>
  4666. -
  4667. -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  4668. -
  4669. -/* This version is for 80-bit little endian long double */
  4670. +#include "libm.h"
  4671. +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  4672. long double frexpl(long double x, int *e)
  4673. {
  4674. - union { long double ld; uint16_t hw[5]; } y = { x };
  4675. - int ee = y.hw[4]&0x7fff;
  4676. + return frexp(x, e);
  4677. +}
  4678. +#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  4679. +long double frexpl(long double x, int *e)
  4680. +{
  4681. + union ldshape u = {x};
  4682. + int ee = u.i.se & 0x7fff;
  4683. if (!ee) {
  4684. if (x) {
  4685. - x = frexpl(x*0x1p64, e);
  4686. - *e -= 64;
  4687. + x = frexpl(x*0x1p120, e);
  4688. + *e -= 120;
  4689. } else *e = 0;
  4690. return x;
  4691. } else if (ee == 0x7fff) {
  4692. @@ -22,16 +22,8 @@
  4693. }
  4694. *e = ee - 0x3ffe;
  4695. - y.hw[4] &= 0x8000;
  4696. - y.hw[4] |= 0x3ffe;
  4697. - return y.ld;
  4698. + u.i.se &= 0x8000;
  4699. + u.i.se |= 0x3ffe;
  4700. + return u.f;
  4701. }
  4702. -
  4703. -#else
  4704. -
  4705. -long double frexpl(long double x, int *e)
  4706. -{
  4707. - return frexp(x, e);
  4708. -}
  4709. -
  4710. #endif
  4711. diff -Nur musl-0.9.13/src/math/hypot.c musl-git/src/math/hypot.c
  4712. --- musl-0.9.13/src/math/hypot.c 2013-08-30 23:30:53.000000000 +0200
  4713. +++ musl-git/src/math/hypot.c 2013-09-16 20:31:39.000000000 +0200
  4714. @@ -1,123 +1,67 @@
  4715. -/* origin: FreeBSD /usr/src/lib/msun/src/e_hypot.c */
  4716. -/*
  4717. - * ====================================================
  4718. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4719. - *
  4720. - * Developed at SunSoft, a Sun Microsystems, Inc. business.
  4721. - * Permission to use, copy, modify, and distribute this
  4722. - * software is freely granted, provided that this notice
  4723. - * is preserved.
  4724. - * ====================================================
  4725. - */
  4726. -/* hypot(x,y)
  4727. - *
  4728. - * Method :
  4729. - * If (assume round-to-nearest) z=x*x+y*y
  4730. - * has error less than sqrt(2)/2 ulp, then
  4731. - * sqrt(z) has error less than 1 ulp (exercise).
  4732. - *
  4733. - * So, compute sqrt(x*x+y*y) with some care as
  4734. - * follows to get the error below 1 ulp:
  4735. - *
  4736. - * Assume x>y>0;
  4737. - * (if possible, set rounding to round-to-nearest)
  4738. - * 1. if x > 2y use
  4739. - * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y
  4740. - * where x1 = x with lower 32 bits cleared, x2 = x-x1; else
  4741. - * 2. if x <= 2y use
  4742. - * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y))
  4743. - * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1,
  4744. - * y1= y with lower 32 bits chopped, y2 = y-y1.
  4745. - *
  4746. - * NOTE: scaling may be necessary if some argument is too
  4747. - * large or too tiny
  4748. - *
  4749. - * Special cases:
  4750. - * hypot(x,y) is INF if x or y is +INF or -INF; else
  4751. - * hypot(x,y) is NAN if x or y is NAN.
  4752. - *
  4753. - * Accuracy:
  4754. - * hypot(x,y) returns sqrt(x^2+y^2) with error less
  4755. - * than 1 ulps (units in the last place)
  4756. - */
  4757. +#include <math.h>
  4758. +#include <stdint.h>
  4759. +#include <float.h>
  4760. -#include "libm.h"
  4761. +#if FLT_EVAL_METHOD > 1U && LDBL_MANT_DIG == 64
  4762. +#define SPLIT (0x1p32 + 1)
  4763. +#else
  4764. +#define SPLIT (0x1p27 + 1)
  4765. +#endif
  4766. +
  4767. +static void sq(double_t *hi, double_t *lo, double x)
  4768. +{
  4769. + double_t xh, xl, xc;
  4770. +
  4771. + xc = x*SPLIT;
  4772. + xh = x - xc + xc;
  4773. + xl = x - xh;
  4774. + *hi = x*x;
  4775. + *lo = xh*xh - *hi + 2*xh*xl + xl*xl;
  4776. +}
  4777. double hypot(double x, double y)
  4778. {
  4779. - double a,b,t1,t2,y1,y2,w;
  4780. - int32_t j,k,ha,hb;
  4781. + union {double f; uint64_t i;} ux = {x}, uy = {y}, ut;
  4782. + int ex, ey;
  4783. + double_t hx, lx, hy, ly, z;
  4784. - GET_HIGH_WORD(ha, x);
  4785. - ha &= 0x7fffffff;
  4786. - GET_HIGH_WORD(hb, y);
  4787. - hb &= 0x7fffffff;
  4788. - if (hb > ha) {
  4789. - a = y;
  4790. - b = x;
  4791. - j=ha; ha=hb; hb=j;
  4792. - } else {
  4793. - a = x;
  4794. - b = y;
  4795. + /* arrange |x| >= |y| */
  4796. + ux.i &= -1ULL>>1;
  4797. + uy.i &= -1ULL>>1;
  4798. + if (ux.i < uy.i) {
  4799. + ut = ux;
  4800. + ux = uy;
  4801. + uy = ut;
  4802. }
  4803. - a = fabs(a);
  4804. - b = fabs(b);
  4805. - if (ha - hb > 0x3c00000) /* x/y > 2**60 */
  4806. - return a+b;
  4807. - k = 0;
  4808. - if (ha > 0x5f300000) { /* a > 2**500 */
  4809. - if(ha >= 0x7ff00000) { /* Inf or NaN */
  4810. - uint32_t low;
  4811. - /* Use original arg order iff result is NaN; quieten sNaNs. */
  4812. - w = fabs(x+0.0) - fabs(y+0.0);
  4813. - GET_LOW_WORD(low, a);
  4814. - if (((ha&0xfffff)|low) == 0) w = a;
  4815. - GET_LOW_WORD(low, b);
  4816. - if (((hb^0x7ff00000)|low) == 0) w = b;
  4817. - return w;
  4818. - }
  4819. - /* scale a and b by 2**-600 */
  4820. - ha -= 0x25800000; hb -= 0x25800000; k += 600;
  4821. - SET_HIGH_WORD(a, ha);
  4822. - SET_HIGH_WORD(b, hb);
  4823. - }
  4824. - if (hb < 0x20b00000) { /* b < 2**-500 */
  4825. - if (hb <= 0x000fffff) { /* subnormal b or 0 */
  4826. - uint32_t low;
  4827. - GET_LOW_WORD(low, b);
  4828. - if ((hb|low) == 0)
  4829. - return a;
  4830. - t1 = 0;
  4831. - SET_HIGH_WORD(t1, 0x7fd00000); /* t1 = 2^1022 */
  4832. - b *= t1;
  4833. - a *= t1;
  4834. - k -= 1022;
  4835. - } else { /* scale a and b by 2^600 */
  4836. - ha += 0x25800000; /* a *= 2^600 */
  4837. - hb += 0x25800000; /* b *= 2^600 */
  4838. - k -= 600;
  4839. - SET_HIGH_WORD(a, ha);
  4840. - SET_HIGH_WORD(b, hb);
  4841. - }
  4842. - }
  4843. - /* medium size a and b */
  4844. - w = a - b;
  4845. - if (w > b) {
  4846. - t1 = 0;
  4847. - SET_HIGH_WORD(t1, ha);
  4848. - t2 = a-t1;
  4849. - w = sqrt(t1*t1-(b*(-b)-t2*(a+t1)));
  4850. - } else {
  4851. - a = a + a;
  4852. - y1 = 0;
  4853. - SET_HIGH_WORD(y1, hb);
  4854. - y2 = b - y1;
  4855. - t1 = 0;
  4856. - SET_HIGH_WORD(t1, ha+0x00100000);
  4857. - t2 = a - t1;
  4858. - w = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
  4859. +
  4860. + /* special cases */
  4861. + ex = ux.i>>52;
  4862. + ey = uy.i>>52;
  4863. + x = ux.f;
  4864. + y = uy.f;
  4865. + /* note: hypot(inf,nan) == inf */
  4866. + if (ey == 0x7ff)
  4867. + return y;
  4868. + if (ex == 0x7ff || uy.i == 0)
  4869. + return x;
  4870. + /* note: hypot(x,y) ~= x + y*y/x/2 with inexact for small y/x */
  4871. + /* 64 difference is enough for ld80 double_t */
  4872. + if (ex - ey > 64)
  4873. + return x + y;
  4874. +
  4875. + /* precise sqrt argument in nearest rounding mode without overflow */
  4876. + /* xh*xh must not overflow and xl*xl must not underflow in sq */
  4877. + z = 1;
  4878. + if (ex > 0x3ff+510) {
  4879. + z = 0x1p700;
  4880. + x *= 0x1p-700;
  4881. + y *= 0x1p-700;
  4882. + } else if (ey < 0x3ff-450) {
  4883. + z = 0x1p-700;
  4884. + x *= 0x1p700;
  4885. + y *= 0x1p700;
  4886. }
  4887. - if (k)
  4888. - w = scalbn(w, k);
  4889. - return w;
  4890. + sq(&hx, &lx, x);
  4891. + sq(&hy, &ly, y);
  4892. + return z*sqrt(ly+lx+hy+hx);
  4893. }
  4894. diff -Nur musl-0.9.13/src/math/hypotf.c musl-git/src/math/hypotf.c
  4895. --- musl-0.9.13/src/math/hypotf.c 2013-08-30 23:30:53.000000000 +0200
  4896. +++ musl-git/src/math/hypotf.c 2013-09-16 20:31:39.000000000 +0200
  4897. @@ -1,86 +1,35 @@
  4898. -/* origin: FreeBSD /usr/src/lib/msun/src/e_hypotf.c */
  4899. -/*
  4900. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  4901. - */
  4902. -/*
  4903. - * ====================================================
  4904. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4905. - *
  4906. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  4907. - * Permission to use, copy, modify, and distribute this
  4908. - * software is freely granted, provided that this notice
  4909. - * is preserved.
  4910. - * ====================================================
  4911. - */
  4912. -
  4913. -#include "libm.h"
  4914. +#include <math.h>
  4915. +#include <stdint.h>
  4916. float hypotf(float x, float y)
  4917. {
  4918. - float a,b,t1,t2,y1,y2,w;
  4919. - int32_t j,k,ha,hb;
  4920. + union {float f; uint32_t i;} ux = {x}, uy = {y}, ut;
  4921. + float_t z;
  4922. - GET_FLOAT_WORD(ha,x);
  4923. - ha &= 0x7fffffff;
  4924. - GET_FLOAT_WORD(hb,y);
  4925. - hb &= 0x7fffffff;
  4926. - if (hb > ha) {
  4927. - a = y;
  4928. - b = x;
  4929. - j=ha; ha=hb; hb=j;
  4930. - } else {
  4931. - a = x;
  4932. - b = y;
  4933. - }
  4934. - a = fabsf(a);
  4935. - b = fabsf(b);
  4936. - if (ha - hb > 0xf000000) /* x/y > 2**30 */
  4937. - return a+b;
  4938. - k = 0;
  4939. - if (ha > 0x58800000) { /* a > 2**50 */
  4940. - if(ha >= 0x7f800000) { /* Inf or NaN */
  4941. - /* Use original arg order iff result is NaN; quieten sNaNs. */
  4942. - w = fabsf(x+0.0f) - fabsf(y+0.0f);
  4943. - if (ha == 0x7f800000) w = a;
  4944. - if (hb == 0x7f800000) w = b;
  4945. - return w;
  4946. - }
  4947. - /* scale a and b by 2**-68 */
  4948. - ha -= 0x22000000; hb -= 0x22000000; k += 68;
  4949. - SET_FLOAT_WORD(a, ha);
  4950. - SET_FLOAT_WORD(b, hb);
  4951. - }
  4952. - if (hb < 0x26800000) { /* b < 2**-50 */
  4953. - if (hb <= 0x007fffff) { /* subnormal b or 0 */
  4954. - if (hb == 0)
  4955. - return a;
  4956. - SET_FLOAT_WORD(t1, 0x7e800000); /* t1 = 2^126 */
  4957. - b *= t1;
  4958. - a *= t1;
  4959. - k -= 126;
  4960. - } else { /* scale a and b by 2^68 */
  4961. - ha += 0x22000000; /* a *= 2^68 */
  4962. - hb += 0x22000000; /* b *= 2^68 */
  4963. - k -= 68;
  4964. - SET_FLOAT_WORD(a, ha);
  4965. - SET_FLOAT_WORD(b, hb);
  4966. - }
  4967. + ux.i &= -1U>>1;
  4968. + uy.i &= -1U>>1;
  4969. + if (ux.i < uy.i) {
  4970. + ut = ux;
  4971. + ux = uy;
  4972. + uy = ut;
  4973. }
  4974. - /* medium size a and b */
  4975. - w = a - b;
  4976. - if (w > b) {
  4977. - SET_FLOAT_WORD(t1, ha&0xfffff000);
  4978. - t2 = a - t1;
  4979. - w = sqrtf(t1*t1-(b*(-b)-t2*(a+t1)));
  4980. - } else {
  4981. - a = a + a;
  4982. - SET_FLOAT_WORD(y1, hb&0xfffff000);
  4983. - y2 = b - y1;
  4984. - SET_FLOAT_WORD(t1,(ha+0x00800000)&0xfffff000);
  4985. - t2 = a - t1;
  4986. - w = sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
  4987. +
  4988. + x = ux.f;
  4989. + y = uy.f;
  4990. + if (uy.i == 0xff<<23)
  4991. + return y;
  4992. + if (ux.i >= 0xff<<23 || uy.i == 0 || ux.i - uy.i >= 25<<23)
  4993. + return x + y;
  4994. +
  4995. + z = 1;
  4996. + if (ux.i >= (0x7f+60)<<23) {
  4997. + z = 0x1p90f;
  4998. + x *= 0x1p-90f;
  4999. + y *= 0x1p-90f;
  5000. + } else if (uy.i < (0x7f-60)<<23) {
  5001. + z = 0x1p-90f;
  5002. + x *= 0x1p90f;
  5003. + y *= 0x1p90f;
  5004. }
  5005. - if (k)
  5006. - w = scalbnf(w, k);
  5007. - return w;
  5008. + return z*sqrtf((double)x*x + (double)y*y);
  5009. }
  5010. diff -Nur musl-0.9.13/src/math/hypotl.c musl-git/src/math/hypotl.c
  5011. --- musl-0.9.13/src/math/hypotl.c 2013-08-30 23:30:53.000000000 +0200
  5012. +++ musl-git/src/math/hypotl.c 2013-09-16 20:31:39.000000000 +0200
  5013. @@ -1,16 +1,3 @@
  5014. -/* origin: FreeBSD /usr/src/lib/msun/src/e_hypotl.c */
  5015. -/*
  5016. - * ====================================================
  5017. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5018. - *
  5019. - * Developed at SunSoft, a Sun Microsystems, Inc. business.
  5020. - * Permission to use, copy, modify, and distribute this
  5021. - * software is freely granted, provided that this notice
  5022. - * is preserved.
  5023. - * ====================================================
  5024. - */
  5025. -/* long double version of hypot(). See comments in hypot.c. */
  5026. -
  5027. #include "libm.h"
  5028. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  5029. @@ -19,130 +6,61 @@
  5030. return hypot(x, y);
  5031. }
  5032. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  5033. -
  5034. -#define GET_LDBL_EXPSIGN(i, v) do { \
  5035. - union IEEEl2bits uv; \
  5036. - \
  5037. - uv.e = v; \
  5038. - i = uv.xbits.expsign; \
  5039. -} while (0)
  5040. -
  5041. -#define GET_LDBL_MAN(h, l, v) do { \
  5042. - union IEEEl2bits uv; \
  5043. - \
  5044. - uv.e = v; \
  5045. - h = uv.bits.manh; \
  5046. - l = uv.bits.manl; \
  5047. -} while (0)
  5048. -
  5049. -#define SET_LDBL_EXPSIGN(v, i) do { \
  5050. - union IEEEl2bits uv; \
  5051. - \
  5052. - uv.e = v; \
  5053. - uv.xbits.expsign = i; \
  5054. - v = uv.e; \
  5055. -} while (0)
  5056. -
  5057. -#undef GET_HIGH_WORD
  5058. -#define GET_HIGH_WORD(i, v) GET_LDBL_EXPSIGN(i, v)
  5059. -#undef SET_HIGH_WORD
  5060. -#define SET_HIGH_WORD(v, i) SET_LDBL_EXPSIGN(v, i)
  5061. -
  5062. -#define DESW(exp) (exp) /* delta expsign word */
  5063. -#define ESW(exp) (MAX_EXP - 1 + (exp)) /* expsign word */
  5064. -#define MANT_DIG LDBL_MANT_DIG
  5065. -#define MAX_EXP LDBL_MAX_EXP
  5066. -
  5067. -#if LDBL_MANL_SIZE > 32
  5068. -typedef uint64_t man_t;
  5069. -#else
  5070. -typedef uint32_t man_t;
  5071. +#if LDBL_MANT_DIG == 64
  5072. +#define SPLIT (0x1p32L+1)
  5073. +#elif LDBL_MANT_DIG == 113
  5074. +#define SPLIT (0x1p57L+1)
  5075. #endif
  5076. -long double hypotl(long double x, long double y)
  5077. +static void sq(long double *hi, long double *lo, long double x)
  5078. {
  5079. - long double a=x,b=y,t1,t2,y1,y2,w;
  5080. - int32_t j,k,ha,hb;
  5081. + long double xh, xl, xc;
  5082. + xc = x*SPLIT;
  5083. + xh = x - xc + xc;
  5084. + xl = x - xh;
  5085. + *hi = x*x;
  5086. + *lo = xh*xh - *hi + 2*xh*xl + xl*xl;
  5087. +}
  5088. - GET_HIGH_WORD(ha, x);
  5089. - ha &= 0x7fff;
  5090. - GET_HIGH_WORD(hb, y);
  5091. - hb &= 0x7fff;
  5092. - if (hb > ha) {
  5093. - a = y;
  5094. - b = x;
  5095. - j=ha; ha=hb; hb=j;
  5096. - } else {
  5097. - a = x;
  5098. - b = y;
  5099. - }
  5100. - a = fabsl(a);
  5101. - b = fabsl(b);
  5102. - if (ha - hb > DESW(MANT_DIG+7)) /* x/y > 2**(MANT_DIG+7) */
  5103. - return a+b;
  5104. - k = 0;
  5105. - if (ha > ESW(MAX_EXP/2-12)) { /* a>2**(MAX_EXP/2-12) */
  5106. - if (ha >= ESW(MAX_EXP)) { /* Inf or NaN */
  5107. - man_t manh, manl;
  5108. - /* Use original arg order iff result is NaN; quieten sNaNs. */
  5109. - w = fabsl(x+0.0)-fabsl(y+0.0);
  5110. - GET_LDBL_MAN(manh,manl,a);
  5111. - if (manh == LDBL_NBIT && manl == 0) w = a;
  5112. - GET_LDBL_MAN(manh,manl,b);
  5113. - if (hb >= ESW(MAX_EXP) && manh == LDBL_NBIT && manl == 0) w = b;
  5114. - return w;
  5115. - }
  5116. - /* scale a and b by 2**-(MAX_EXP/2+88) */
  5117. - ha -= DESW(MAX_EXP/2+88); hb -= DESW(MAX_EXP/2+88);
  5118. - k += MAX_EXP/2+88;
  5119. - SET_HIGH_WORD(a, ha);
  5120. - SET_HIGH_WORD(b, hb);
  5121. - }
  5122. - if (hb < ESW(-(MAX_EXP/2-12))) { /* b < 2**-(MAX_EXP/2-12) */
  5123. - if (hb <= 0) { /* subnormal b or 0 */
  5124. - man_t manh, manl;
  5125. - GET_LDBL_MAN(manh,manl,b);
  5126. - if ((manh|manl) == 0)
  5127. - return a;
  5128. - t1 = 0;
  5129. - SET_HIGH_WORD(t1, ESW(MAX_EXP-2)); /* t1 = 2^(MAX_EXP-2) */
  5130. - b *= t1;
  5131. - a *= t1;
  5132. - k -= MAX_EXP-2;
  5133. - } else { /* scale a and b by 2^(MAX_EXP/2+88) */
  5134. - ha += DESW(MAX_EXP/2+88);
  5135. - hb += DESW(MAX_EXP/2+88);
  5136. - k -= MAX_EXP/2+88;
  5137. - SET_HIGH_WORD(a, ha);
  5138. - SET_HIGH_WORD(b, hb);
  5139. - }
  5140. - }
  5141. - /* medium size a and b */
  5142. - w = a - b;
  5143. - if (w > b) {
  5144. - t1 = a;
  5145. - union IEEEl2bits uv;
  5146. - uv.e = t1; uv.bits.manl = 0; t1 = uv.e;
  5147. - t2 = a-t1;
  5148. - w = sqrtl(t1*t1-(b*(-b)-t2*(a+t1)));
  5149. +long double hypotl(long double x, long double y)
  5150. +{
  5151. + union ldshape ux = {x}, uy = {y};
  5152. + int ex, ey;
  5153. + long double hx, lx, hy, ly, z;
  5154. +
  5155. + ux.i.se &= 0x7fff;
  5156. + uy.i.se &= 0x7fff;
  5157. + if (ux.i.se < uy.i.se) {
  5158. + ex = uy.i.se;
  5159. + ey = ux.i.se;
  5160. + x = uy.f;
  5161. + y = ux.f;
  5162. } else {
  5163. - a = a+a;
  5164. - y1 = b;
  5165. - union IEEEl2bits uv;
  5166. - uv.e = y1; uv.bits.manl = 0; y1 = uv.e;
  5167. - y2 = b - y1;
  5168. - t1 = a;
  5169. - uv.e = t1; uv.bits.manl = 0; t1 = uv.e;
  5170. - t2 = a - t1;
  5171. - w = sqrtl(t1*y1-(w*(-w)-(t1*y2+t2*b)));
  5172. + ex = ux.i.se;
  5173. + ey = uy.i.se;
  5174. + x = ux.f;
  5175. + y = uy.f;
  5176. }
  5177. - if(k!=0) {
  5178. - uint32_t high;
  5179. - t1 = 1.0;
  5180. - GET_HIGH_WORD(high, t1);
  5181. - SET_HIGH_WORD(t1, high+DESW(k));
  5182. - return t1*w;
  5183. +
  5184. + if (ex == 0x7fff && isinf(y))
  5185. + return y;
  5186. + if (ex == 0x7fff || y == 0)
  5187. + return x;
  5188. + if (ex - ey > LDBL_MANT_DIG)
  5189. + return x + y;
  5190. +
  5191. + z = 1;
  5192. + if (ex > 0x3fff+8000) {
  5193. + z = 0x1p10000L;
  5194. + x *= 0x1p-10000L;
  5195. + y *= 0x1p-10000L;
  5196. + } else if (ey < 0x3fff-8000) {
  5197. + z = 0x1p-10000L;
  5198. + x *= 0x1p10000L;
  5199. + y *= 0x1p10000L;
  5200. }
  5201. - return w;
  5202. + sq(&hx, &lx, x);
  5203. + sq(&hy, &ly, y);
  5204. + return z*sqrtl(ly+lx+hy+hx);
  5205. }
  5206. #endif
  5207. diff -Nur musl-0.9.13/src/math/i386/exp.s musl-git/src/math/i386/exp.s
  5208. --- musl-0.9.13/src/math/i386/exp.s 2013-08-30 23:30:53.000000000 +0200
  5209. +++ musl-git/src/math/i386/exp.s 2013-09-16 20:31:39.000000000 +0200
  5210. @@ -95,42 +95,32 @@
  5211. .type exp2,@function
  5212. exp2:
  5213. fldl 4(%esp)
  5214. -1: pushl $0x467ff000
  5215. - flds (%esp) # 16380
  5216. - xorl %eax,%eax
  5217. - pushl $0x80000000
  5218. - push %eax
  5219. - fld %st(1)
  5220. - fabs
  5221. - fucomp %st(1)
  5222. - fnstsw
  5223. - fstp %st(0)
  5224. - sahf
  5225. - ja 3f # |x| > 16380
  5226. - jp 2f # x is nan (avoid invalid except in fistp)
  5227. +1: sub $12,%esp
  5228. fld %st(0)
  5229. - fistpl 8(%esp)
  5230. - fildl 8(%esp)
  5231. - fxch %st(1)
  5232. - fsub %st(1)
  5233. - mov $0x3fff,%eax
  5234. - add %eax,8(%esp)
  5235. - f2xm1
  5236. - fld1
  5237. - faddp # 2^(x-rint(x))
  5238. - fldt (%esp) # 2^rint(x)
  5239. - fmulp
  5240. - fstp %st(1)
  5241. -2: add $12,%esp
  5242. - ret
  5243. -
  5244. -3: fld %st(0)
  5245. fstpt (%esp)
  5246. - fld1
  5247. mov 8(%esp),%ax
  5248. and $0x7fff,%ax
  5249. - cmp $0x7fff,%ax
  5250. - je 1f # x = +-inf
  5251. + cmp $0x3fff+13,%ax
  5252. + jb 4f # |x| < 8192
  5253. + cmp $0x3fff+15,%ax
  5254. + jae 3f # |x| >= 32768
  5255. + fsts (%esp)
  5256. + cmpl $0xc67ff800,(%esp)
  5257. + jb 2f # x > -16382
  5258. + movl $0x5f000000,(%esp)
  5259. + flds (%esp) # 0x1p63
  5260. + fld %st(1)
  5261. + fsub %st(1)
  5262. + faddp
  5263. + fucomp %st(1)
  5264. + fnstsw
  5265. + sahf
  5266. + je 2f # x - 0x1p63 + 0x1p63 == x
  5267. + movl $1,(%esp)
  5268. + flds (%esp) # 0x1p-149
  5269. + fdiv %st(1)
  5270. + fstps (%esp) # raise underflow
  5271. +2: fld1
  5272. fld %st(1)
  5273. frndint
  5274. fxch %st(2)
  5275. @@ -141,3 +131,19 @@
  5276. fstp %st(1)
  5277. add $12,%esp
  5278. ret
  5279. +3: xor %eax,%eax
  5280. +4: cmp $0x3fff-64,%ax
  5281. + fld1
  5282. + jb 1b # |x| < 0x1p-64
  5283. + fstpt (%esp)
  5284. + fistl 8(%esp)
  5285. + fildl 8(%esp)
  5286. + fsubrp %st(1)
  5287. + addl $0x3fff,8(%esp)
  5288. + f2xm1
  5289. + fld1
  5290. + faddp # 2^(x-rint(x))
  5291. + fldt (%esp) # 2^rint(x)
  5292. + fmulp
  5293. + add $12,%esp
  5294. + ret
  5295. diff -Nur musl-0.9.13/src/math/ilogb.c musl-git/src/math/ilogb.c
  5296. --- musl-0.9.13/src/math/ilogb.c 2013-08-30 23:30:53.000000000 +0200
  5297. +++ musl-git/src/math/ilogb.c 2013-09-16 20:31:39.000000000 +0200
  5298. @@ -3,22 +3,24 @@
  5299. int ilogb(double x)
  5300. {
  5301. - union dshape u = {x};
  5302. - int e = u.bits>>52 & 0x7ff;
  5303. + #pragma STDC FENV_ACCESS ON
  5304. + union {double f; uint64_t i;} u = {x};
  5305. + uint64_t i = u.i;
  5306. + int e = i>>52 & 0x7ff;
  5307. if (!e) {
  5308. - u.bits <<= 12;
  5309. - if (u.bits == 0) {
  5310. + i <<= 12;
  5311. + if (i == 0) {
  5312. FORCE_EVAL(0/0.0f);
  5313. return FP_ILOGB0;
  5314. }
  5315. /* subnormal x */
  5316. - for (e = -0x3ff; u.bits < (uint64_t)1<<63; e--, u.bits<<=1);
  5317. + for (e = -0x3ff; i>>63 == 0; e--, i<<=1);
  5318. return e;
  5319. }
  5320. if (e == 0x7ff) {
  5321. FORCE_EVAL(0/0.0f);
  5322. - return u.bits<<12 ? FP_ILOGBNAN : INT_MAX;
  5323. + return i<<12 ? FP_ILOGBNAN : INT_MAX;
  5324. }
  5325. return e - 0x3ff;
  5326. }
  5327. diff -Nur musl-0.9.13/src/math/ilogbf.c musl-git/src/math/ilogbf.c
  5328. --- musl-0.9.13/src/math/ilogbf.c 2013-08-30 23:30:53.000000000 +0200
  5329. +++ musl-git/src/math/ilogbf.c 2013-09-16 20:31:39.000000000 +0200
  5330. @@ -3,22 +3,24 @@
  5331. int ilogbf(float x)
  5332. {
  5333. - union fshape u = {x};
  5334. - int e = u.bits>>23 & 0xff;
  5335. + #pragma STDC FENV_ACCESS ON
  5336. + union {float f; uint32_t i;} u = {x};
  5337. + uint32_t i = u.i;
  5338. + int e = i>>23 & 0xff;
  5339. if (!e) {
  5340. - u.bits <<= 9;
  5341. - if (u.bits == 0) {
  5342. + i <<= 9;
  5343. + if (i == 0) {
  5344. FORCE_EVAL(0/0.0f);
  5345. return FP_ILOGB0;
  5346. }
  5347. /* subnormal x */
  5348. - for (e = -0x7f; u.bits < (uint32_t)1<<31; e--, u.bits<<=1);
  5349. + for (e = -0x7f; i>>31 == 0; e--, i<<=1);
  5350. return e;
  5351. }
  5352. if (e == 0xff) {
  5353. FORCE_EVAL(0/0.0f);
  5354. - return u.bits<<9 ? FP_ILOGBNAN : INT_MAX;
  5355. + return i<<9 ? FP_ILOGBNAN : INT_MAX;
  5356. }
  5357. return e - 0x7f;
  5358. }
  5359. diff -Nur musl-0.9.13/src/math/ilogbl.c musl-git/src/math/ilogbl.c
  5360. --- musl-0.9.13/src/math/ilogbl.c 2013-08-30 23:30:53.000000000 +0200
  5361. +++ musl-git/src/math/ilogbl.c 2013-09-16 20:31:39.000000000 +0200
  5362. @@ -9,9 +9,10 @@
  5363. #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  5364. int ilogbl(long double x)
  5365. {
  5366. + #pragma STDC FENV_ACCESS ON
  5367. union ldshape u = {x};
  5368. - uint64_t m = u.bits.m;
  5369. - int e = u.bits.exp;
  5370. + uint64_t m = u.i.m;
  5371. + int e = u.i.se & 0x7fff;
  5372. if (!e) {
  5373. if (m == 0) {
  5374. @@ -19,13 +20,35 @@
  5375. return FP_ILOGB0;
  5376. }
  5377. /* subnormal x */
  5378. - for (e = -0x3fff+1; m < (uint64_t)1<<63; e--, m<<=1);
  5379. + for (e = -0x3fff+1; m>>63 == 0; e--, m<<=1);
  5380. return e;
  5381. }
  5382. if (e == 0x7fff) {
  5383. FORCE_EVAL(0/0.0f);
  5384. - /* in ld80 msb is set in inf */
  5385. - return m & (uint64_t)-1>>1 ? FP_ILOGBNAN : INT_MAX;
  5386. + return m<<1 ? FP_ILOGBNAN : INT_MAX;
  5387. + }
  5388. + return e - 0x3fff;
  5389. +}
  5390. +#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
  5391. +int ilogbl(long double x)
  5392. +{
  5393. + #pragma STDC FENV_ACCESS ON
  5394. + union ldshape u = {x};
  5395. + int e = u.i.se & 0x7fff;
  5396. +
  5397. + if (!e) {
  5398. + if (x == 0) {
  5399. + FORCE_EVAL(0/0.0f);
  5400. + return FP_ILOGB0;
  5401. + }
  5402. + /* subnormal x */
  5403. + x *= 0x1p120;
  5404. + return ilogbl(x) - 120;
  5405. + }
  5406. + if (e == 0x7fff) {
  5407. + FORCE_EVAL(0/0.0f);
  5408. + u.i.se = 0;
  5409. + return u.f ? FP_ILOGBNAN : INT_MAX;
  5410. }
  5411. return e - 0x3fff;
  5412. }
  5413. diff -Nur musl-0.9.13/src/math/lgamma_r.c musl-git/src/math/lgamma_r.c
  5414. --- musl-0.9.13/src/math/lgamma_r.c 2013-08-30 23:30:53.000000000 +0200
  5415. +++ musl-git/src/math/lgamma_r.c 2013-09-16 20:31:39.000000000 +0200
  5416. @@ -79,6 +79,7 @@
  5417. */
  5418. #include "libm.h"
  5419. +#include "libc.h"
  5420. static const double
  5421. two52= 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
  5422. diff -Nur musl-0.9.13/src/math/lgammaf_r.c musl-git/src/math/lgammaf_r.c
  5423. --- musl-0.9.13/src/math/lgammaf_r.c 2013-08-30 23:30:53.000000000 +0200
  5424. +++ musl-git/src/math/lgammaf_r.c 2013-09-16 20:31:39.000000000 +0200
  5425. @@ -14,6 +14,7 @@
  5426. */
  5427. #include "libm.h"
  5428. +#include "libc.h"
  5429. static const float
  5430. two23= 8.3886080000e+06, /* 0x4b000000 */
  5431. diff -Nur musl-0.9.13/src/math/lgammal.c musl-git/src/math/lgammal.c
  5432. --- musl-0.9.13/src/math/lgammal.c 2013-08-30 23:30:53.000000000 +0200
  5433. +++ musl-git/src/math/lgammal.c 2013-09-16 20:31:39.000000000 +0200
  5434. @@ -87,6 +87,7 @@
  5435. #define _GNU_SOURCE
  5436. #include "libm.h"
  5437. +#include "libc.h"
  5438. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  5439. double __lgamma_r(double x, int *sg);
  5440. @@ -202,13 +203,11 @@
  5441. static long double sin_pi(long double x)
  5442. {
  5443. + union ldshape u = {x};
  5444. + uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48;
  5445. long double y, z;
  5446. - int n, ix;
  5447. - uint32_t se, i0, i1;
  5448. + int n;
  5449. - GET_LDOUBLE_WORDS(se, i0, i1, x);
  5450. - ix = se & 0x7fff;
  5451. - ix = (ix << 16) | (i0 >> 16);
  5452. if (ix < 0x3ffd8000) /* 0.25 */
  5453. return sinl(pi * x);
  5454. y = -x; /* x is assume negative */
  5455. @@ -229,8 +228,8 @@
  5456. } else {
  5457. if (ix < 0x403e8000) /* 2^63 */
  5458. z = y + two63; /* exact */
  5459. - GET_LDOUBLE_WORDS(se, i0, i1, z);
  5460. - n = i1 & 1;
  5461. + u.f = z;
  5462. + n = u.i.m & 1;
  5463. y = n;
  5464. n <<= 2;
  5465. }
  5466. @@ -261,33 +260,28 @@
  5467. long double __lgammal_r(long double x, int *sg) {
  5468. long double t, y, z, nadj, p, p1, p2, q, r, w;
  5469. - int i, ix;
  5470. - uint32_t se, i0, i1;
  5471. + union ldshape u = {x};
  5472. + uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48;
  5473. + int sign = u.i.se >> 15;
  5474. + int i;
  5475. *sg = 1;
  5476. - GET_LDOUBLE_WORDS(se, i0, i1, x);
  5477. - ix = se & 0x7fff;
  5478. -
  5479. - if ((ix | i0 | i1) == 0) {
  5480. - if (se & 0x8000)
  5481. - *sg = -1;
  5482. - return 1.0 / fabsl(x);
  5483. - }
  5484. -
  5485. - ix = (ix << 16) | (i0 >> 16);
  5486. /* purge off +-inf, NaN, +-0, and negative arguments */
  5487. if (ix >= 0x7fff0000)
  5488. return x * x;
  5489. -
  5490. + if (x == 0) {
  5491. + *sg -= 2*sign;
  5492. + return 1.0 / fabsl(x);
  5493. + }
  5494. if (ix < 0x3fc08000) { /* |x|<2**-63, return -log(|x|) */
  5495. - if (se & 0x8000) {
  5496. + if (sign) {
  5497. *sg = -1;
  5498. return -logl(-x);
  5499. }
  5500. return -logl(x);
  5501. }
  5502. - if (se & 0x8000) {
  5503. + if (sign) {
  5504. t = sin_pi (x);
  5505. if (t == 0.0)
  5506. return 1.0 / fabsl(t); /* -integer */
  5507. @@ -297,11 +291,7 @@
  5508. x = -x;
  5509. }
  5510. - /* purge off 1 and 2 */
  5511. - if ((((ix - 0x3fff8000) | i0 | i1) == 0) ||
  5512. - (((ix - 0x40008000) | i0 | i1) == 0))
  5513. - r = 0;
  5514. - else if (ix < 0x40008000) { /* x < 2.0 */
  5515. + if (ix < 0x40008000) { /* x < 2.0 */
  5516. if (ix <= 0x3ffee666) { /* 8.99993896484375e-1 */
  5517. /* lgamma(x) = lgamma(x+1) - log(x) */
  5518. r = -logl(x);
  5519. @@ -380,7 +370,7 @@
  5520. r = (x - 0.5) * (t - 1.0) + w;
  5521. } else /* 2**66 <= x <= inf */
  5522. r = x * (logl(x) - 1.0);
  5523. - if (se & 0x8000)
  5524. + if (sign)
  5525. r = nadj - r;
  5526. return r;
  5527. }
  5528. diff -Nur musl-0.9.13/src/math/log1p.c musl-git/src/math/log1p.c
  5529. --- musl-0.9.13/src/math/log1p.c 2013-08-30 23:30:53.000000000 +0200
  5530. +++ musl-git/src/math/log1p.c 2013-09-16 20:31:39.000000000 +0200
  5531. @@ -122,7 +122,7 @@
  5532. return x+x;
  5533. if (k != 0) {
  5534. if (hx < 0x43400000) {
  5535. - STRICT_ASSIGN(double, u, 1.0 + x);
  5536. + u = 1 + x;
  5537. GET_HIGH_WORD(hu, u);
  5538. k = (hu>>20) - 1023;
  5539. c = k > 0 ? 1.0-(u-x) : x-(u-1.0); /* correction term */
  5540. diff -Nur musl-0.9.13/src/math/log1pf.c musl-git/src/math/log1pf.c
  5541. --- musl-0.9.13/src/math/log1pf.c 2013-08-30 23:30:53.000000000 +0200
  5542. +++ musl-git/src/math/log1pf.c 2013-09-16 20:31:39.000000000 +0200
  5543. @@ -61,7 +61,7 @@
  5544. return x+x;
  5545. if (k != 0) {
  5546. if (hx < 0x5a000000) {
  5547. - STRICT_ASSIGN(float, u, 1.0f + x);
  5548. + u = 1 + x;
  5549. GET_FLOAT_WORD(hu, u);
  5550. k = (hu>>23) - 127;
  5551. /* correction term */
  5552. diff -Nur musl-0.9.13/src/math/logb.c musl-git/src/math/logb.c
  5553. --- musl-0.9.13/src/math/logb.c 2013-08-30 23:30:53.000000000 +0200
  5554. +++ musl-git/src/math/logb.c 2013-09-16 20:31:39.000000000 +0200
  5555. @@ -1,4 +1,4 @@
  5556. -#include "libm.h"
  5557. +#include <math.h>
  5558. /*
  5559. special cases:
  5560. @@ -12,6 +12,6 @@
  5561. if (!isfinite(x))
  5562. return x * x;
  5563. if (x == 0)
  5564. - return -1/(x+0);
  5565. + return -1/(x*x);
  5566. return ilogb(x);
  5567. }
  5568. diff -Nur musl-0.9.13/src/math/logbf.c musl-git/src/math/logbf.c
  5569. --- musl-0.9.13/src/math/logbf.c 2013-08-30 23:30:53.000000000 +0200
  5570. +++ musl-git/src/math/logbf.c 2013-09-16 20:31:39.000000000 +0200
  5571. @@ -1,10 +1,10 @@
  5572. -#include "libm.h"
  5573. +#include <math.h>
  5574. float logbf(float x)
  5575. {
  5576. if (!isfinite(x))
  5577. return x * x;
  5578. if (x == 0)
  5579. - return -1/(x+0);
  5580. + return -1/(x*x);
  5581. return ilogbf(x);
  5582. }
  5583. diff -Nur musl-0.9.13/src/math/logbl.c musl-git/src/math/logbl.c
  5584. --- musl-0.9.13/src/math/logbl.c 2013-08-30 23:30:53.000000000 +0200
  5585. +++ musl-git/src/math/logbl.c 2013-09-16 20:31:39.000000000 +0200
  5586. @@ -1,4 +1,4 @@
  5587. -#include "libm.h"
  5588. +#include <math.h>
  5589. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  5590. long double logbl(long double x)
  5591. {
  5592. @@ -10,7 +10,7 @@
  5593. if (!isfinite(x))
  5594. return x * x;
  5595. if (x == 0)
  5596. - return -1/(x+0);
  5597. + return -1/(x*x);
  5598. return ilogbl(x);
  5599. }
  5600. #endif
  5601. diff -Nur musl-0.9.13/src/math/modf.c musl-git/src/math/modf.c
  5602. --- musl-0.9.13/src/math/modf.c 2013-08-30 23:30:53.000000000 +0200
  5603. +++ musl-git/src/math/modf.c 2013-09-16 20:31:39.000000000 +0200
  5604. @@ -2,36 +2,33 @@
  5605. double modf(double x, double *iptr)
  5606. {
  5607. - union {double x; uint64_t n;} u = {x};
  5608. + union {double f; uint64_t i;} u = {x};
  5609. uint64_t mask;
  5610. - int e;
  5611. -
  5612. - e = (int)(u.n>>52 & 0x7ff) - 0x3ff;
  5613. + int e = (int)(u.i>>52 & 0x7ff) - 0x3ff;
  5614. /* no fractional part */
  5615. if (e >= 52) {
  5616. *iptr = x;
  5617. - if (e == 0x400 && u.n<<12 != 0) /* nan */
  5618. + if (e == 0x400 && u.i<<12 != 0) /* nan */
  5619. return x;
  5620. - u.n &= (uint64_t)1<<63;
  5621. - return u.x;
  5622. + u.i &= 1ULL<<63;
  5623. + return u.f;
  5624. }
  5625. /* no integral part*/
  5626. if (e < 0) {
  5627. - u.n &= (uint64_t)1<<63;
  5628. - *iptr = u.x;
  5629. + u.i &= 1ULL<<63;
  5630. + *iptr = u.f;
  5631. return x;
  5632. }
  5633. - mask = (uint64_t)-1>>12 >> e;
  5634. - if ((u.n & mask) == 0) {
  5635. + mask = -1ULL>>12>>e;
  5636. + if ((u.i & mask) == 0) {
  5637. *iptr = x;
  5638. - u.n &= (uint64_t)1<<63;
  5639. - return u.x;
  5640. + u.i &= 1ULL<<63;
  5641. + return u.f;
  5642. }
  5643. - u.n &= ~mask;
  5644. - *iptr = u.x;
  5645. - STRICT_ASSIGN(double, x, x - *iptr);
  5646. - return x;
  5647. + u.i &= ~mask;
  5648. + *iptr = u.f;
  5649. + return x - u.f;
  5650. }
  5651. diff -Nur musl-0.9.13/src/math/modff.c musl-git/src/math/modff.c
  5652. --- musl-0.9.13/src/math/modff.c 2013-08-30 23:30:53.000000000 +0200
  5653. +++ musl-git/src/math/modff.c 2013-09-16 20:31:39.000000000 +0200
  5654. @@ -2,36 +2,33 @@
  5655. float modff(float x, float *iptr)
  5656. {
  5657. - union {float x; uint32_t n;} u = {x};
  5658. + union {float f; uint32_t i;} u = {x};
  5659. uint32_t mask;
  5660. - int e;
  5661. -
  5662. - e = (int)(u.n>>23 & 0xff) - 0x7f;
  5663. + int e = (int)(u.i>>23 & 0xff) - 0x7f;
  5664. /* no fractional part */
  5665. if (e >= 23) {
  5666. *iptr = x;
  5667. - if (e == 0x80 && u.n<<9 != 0) { /* nan */
  5668. + if (e == 0x80 && u.i<<9 != 0) { /* nan */
  5669. return x;
  5670. }
  5671. - u.n &= 0x80000000;
  5672. - return u.x;
  5673. + u.i &= 0x80000000;
  5674. + return u.f;
  5675. }
  5676. /* no integral part */
  5677. if (e < 0) {
  5678. - u.n &= 0x80000000;
  5679. - *iptr = u.x;
  5680. + u.i &= 0x80000000;
  5681. + *iptr = u.f;
  5682. return x;
  5683. }
  5684. mask = 0x007fffff>>e;
  5685. - if ((u.n & mask) == 0) {
  5686. + if ((u.i & mask) == 0) {
  5687. *iptr = x;
  5688. - u.n &= 0x80000000;
  5689. - return u.x;
  5690. + u.i &= 0x80000000;
  5691. + return u.f;
  5692. }
  5693. - u.n &= ~mask;
  5694. - *iptr = u.x;
  5695. - STRICT_ASSIGN(float, x, x - *iptr);
  5696. - return x;
  5697. + u.i &= ~mask;
  5698. + *iptr = u.f;
  5699. + return x - u.f;
  5700. }
  5701. diff -Nur musl-0.9.13/src/math/modfl.c musl-git/src/math/modfl.c
  5702. --- musl-0.9.13/src/math/modfl.c 2013-08-30 23:30:53.000000000 +0200
  5703. +++ musl-git/src/math/modfl.c 2013-09-16 20:31:39.000000000 +0200
  5704. @@ -1,40 +1,3 @@
  5705. -/* origin: FreeBSD /usr/src/lib/msun/src/s_modfl.c */
  5706. -/*-
  5707. - * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
  5708. - * All rights reserved.
  5709. - *
  5710. - * Redistribution and use in source and binary forms, with or without
  5711. - * modification, are permitted provided that the following conditions
  5712. - * are met:
  5713. - * 1. Redistributions of source code must retain the above copyright
  5714. - * notice, this list of conditions and the following disclaimer.
  5715. - * 2. Redistributions in binary form must reproduce the above copyright
  5716. - * notice, this list of conditions and the following disclaimer in the
  5717. - * documentation and/or other materials provided with the distribution.
  5718. - *
  5719. - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  5720. - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  5721. - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  5722. - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  5723. - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  5724. - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  5725. - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  5726. - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  5727. - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  5728. - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  5729. - * SUCH DAMAGE.
  5730. - *
  5731. - * Derived from s_modf.c, which has the following Copyright:
  5732. - * ====================================================
  5733. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5734. - *
  5735. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  5736. - * Permission to use, copy, modify, and distribute this
  5737. - * software is freely granted, provided that this notice
  5738. - * is preserved.
  5739. - * ====================================================
  5740. - */
  5741. -
  5742. #include "libm.h"
  5743. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  5744. @@ -43,58 +6,46 @@
  5745. return modf(x, (double *)iptr);
  5746. }
  5747. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  5748. -
  5749. -#if LDBL_MANL_SIZE > 32
  5750. -#define MASK ((uint64_t)-1)
  5751. -#else
  5752. -#define MASK ((uint32_t)-1)
  5753. +#if LDBL_MANT_DIG == 64
  5754. +#define TOINT 0x1p63
  5755. +#elif LDBL_MANT_DIG == 113
  5756. +#define TOINT 0x1p112
  5757. #endif
  5758. -/* Return the last n bits of a word, representing the fractional part. */
  5759. -#define GETFRAC(bits, n) ((bits) & ~(MASK << (n)))
  5760. -/* The number of fraction bits in manh, not counting the integer bit */
  5761. -#define HIBITS (LDBL_MANT_DIG - LDBL_MANL_SIZE)
  5762. -
  5763. -static const long double zero[] = { 0.0, -0.0 };
  5764. -
  5765. long double modfl(long double x, long double *iptr)
  5766. {
  5767. - union IEEEl2bits ux;
  5768. - int e;
  5769. + union ldshape u = {x};
  5770. + uint64_t mask;
  5771. + int e = (u.i.se & 0x7fff) - 0x3fff;
  5772. + int s = u.i.se >> 15;
  5773. + long double absx;
  5774. + long double y;
  5775. - ux.e = x;
  5776. - e = ux.bits.exp - LDBL_MAX_EXP + 1;
  5777. - if (e < HIBITS) { /* Integer part is in manh. */
  5778. - if (e < 0) { /* |x|<1 */
  5779. - *iptr = zero[ux.bits.sign];
  5780. - return x;
  5781. - }
  5782. - if ((GETFRAC(ux.bits.manh, HIBITS - 1 - e)|ux.bits.manl) == 0) {
  5783. - /* x is an integer. */
  5784. - *iptr = x;
  5785. - return zero[ux.bits.sign];
  5786. - }
  5787. - /* Clear all but the top e+1 bits. */
  5788. - ux.bits.manh >>= HIBITS - 1 - e;
  5789. - ux.bits.manh <<= HIBITS - 1 - e;
  5790. - ux.bits.manl = 0;
  5791. - *iptr = ux.e;
  5792. - return x - ux.e;
  5793. - } else if (e >= LDBL_MANT_DIG - 1) { /* x has no fraction part. */
  5794. + /* no fractional part */
  5795. + if (e >= LDBL_MANT_DIG-1) {
  5796. *iptr = x;
  5797. - if (e == LDBL_MAX_EXP && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)) /* nan */
  5798. + if (isnan(x))
  5799. return x;
  5800. - return zero[ux.bits.sign];
  5801. - } else { /* Fraction part is in manl. */
  5802. - if (GETFRAC(ux.bits.manl, LDBL_MANT_DIG - 1 - e) == 0) {
  5803. - /* x is integral. */
  5804. - *iptr = x;
  5805. - return zero[ux.bits.sign];
  5806. - }
  5807. - /* Clear all but the top e+1 bits. */
  5808. - ux.bits.manl >>= LDBL_MANT_DIG - 1 - e;
  5809. - ux.bits.manl <<= LDBL_MANT_DIG - 1 - e;
  5810. - *iptr = ux.e;
  5811. - return x - ux.e;
  5812. + return s ? -0.0 : 0.0;
  5813. + }
  5814. +
  5815. + /* no integral part*/
  5816. + if (e < 0) {
  5817. + *iptr = s ? -0.0 : 0.0;
  5818. + return x;
  5819. + }
  5820. +
  5821. + /* raises spurious inexact */
  5822. + absx = s ? -x : x;
  5823. + y = absx + TOINT - TOINT - absx;
  5824. + if (y == 0) {
  5825. + *iptr = x;
  5826. + return s ? -0.0 : 0.0;
  5827. }
  5828. + if (y > 0)
  5829. + y -= 1;
  5830. + if (s)
  5831. + y = -y;
  5832. + *iptr = x + y;
  5833. + return -y;
  5834. }
  5835. #endif
  5836. diff -Nur musl-0.9.13/src/math/nextafter.c musl-git/src/math/nextafter.c
  5837. --- musl-0.9.13/src/math/nextafter.c 2013-08-30 23:30:53.000000000 +0200
  5838. +++ musl-git/src/math/nextafter.c 2013-09-16 20:31:39.000000000 +0200
  5839. @@ -1,35 +1,31 @@
  5840. #include "libm.h"
  5841. -#define SIGN ((uint64_t)1<<63)
  5842. -
  5843. double nextafter(double x, double y)
  5844. {
  5845. - union dshape ux, uy;
  5846. + union {double f; uint64_t i;} ux={x}, uy={y};
  5847. uint64_t ax, ay;
  5848. int e;
  5849. if (isnan(x) || isnan(y))
  5850. return x + y;
  5851. - ux.value = x;
  5852. - uy.value = y;
  5853. - if (ux.bits == uy.bits)
  5854. + if (ux.i == uy.i)
  5855. return y;
  5856. - ax = ux.bits & ~SIGN;
  5857. - ay = uy.bits & ~SIGN;
  5858. + ax = ux.i & -1ULL/2;
  5859. + ay = uy.i & -1ULL/2;
  5860. if (ax == 0) {
  5861. if (ay == 0)
  5862. return y;
  5863. - ux.bits = (uy.bits & SIGN) | 1;
  5864. - } else if (ax > ay || ((ux.bits ^ uy.bits) & SIGN))
  5865. - ux.bits--;
  5866. + ux.i = (uy.i & 1ULL<<63) | 1;
  5867. + } else if (ax > ay || ((ux.i ^ uy.i) & 1ULL<<63))
  5868. + ux.i--;
  5869. else
  5870. - ux.bits++;
  5871. - e = ux.bits >> 52 & 0x7ff;
  5872. - /* raise overflow if ux.value is infinite and x is finite */
  5873. + ux.i++;
  5874. + e = ux.i >> 52 & 0x7ff;
  5875. + /* raise overflow if ux.f is infinite and x is finite */
  5876. if (e == 0x7ff)
  5877. FORCE_EVAL(x+x);
  5878. - /* raise underflow if ux.value is subnormal or zero */
  5879. + /* raise underflow if ux.f is subnormal or zero */
  5880. if (e == 0)
  5881. - FORCE_EVAL(x*x + ux.value*ux.value);
  5882. - return ux.value;
  5883. + FORCE_EVAL(x*x + ux.f*ux.f);
  5884. + return ux.f;
  5885. }
  5886. diff -Nur musl-0.9.13/src/math/nextafterf.c musl-git/src/math/nextafterf.c
  5887. --- musl-0.9.13/src/math/nextafterf.c 2013-08-30 23:30:53.000000000 +0200
  5888. +++ musl-git/src/math/nextafterf.c 2013-09-16 20:31:39.000000000 +0200
  5889. @@ -1,34 +1,30 @@
  5890. #include "libm.h"
  5891. -#define SIGN 0x80000000
  5892. -
  5893. float nextafterf(float x, float y)
  5894. {
  5895. - union fshape ux, uy;
  5896. + union {float f; uint32_t i;} ux={x}, uy={y};
  5897. uint32_t ax, ay, e;
  5898. if (isnan(x) || isnan(y))
  5899. return x + y;
  5900. - ux.value = x;
  5901. - uy.value = y;
  5902. - if (ux.bits == uy.bits)
  5903. + if (ux.i == uy.i)
  5904. return y;
  5905. - ax = ux.bits & ~SIGN;
  5906. - ay = uy.bits & ~SIGN;
  5907. + ax = ux.i & 0x7fffffff;
  5908. + ay = uy.i & 0x7fffffff;
  5909. if (ax == 0) {
  5910. if (ay == 0)
  5911. return y;
  5912. - ux.bits = (uy.bits & SIGN) | 1;
  5913. - } else if (ax > ay || ((ux.bits ^ uy.bits) & SIGN))
  5914. - ux.bits--;
  5915. + ux.i = (uy.i & 0x80000000) | 1;
  5916. + } else if (ax > ay || ((ux.i ^ uy.i) & 0x80000000))
  5917. + ux.i--;
  5918. else
  5919. - ux.bits++;
  5920. - e = ux.bits & 0x7f800000;
  5921. - /* raise overflow if ux.value is infinite and x is finite */
  5922. + ux.i++;
  5923. + e = ux.i & 0x7f800000;
  5924. + /* raise overflow if ux.f is infinite and x is finite */
  5925. if (e == 0x7f800000)
  5926. FORCE_EVAL(x+x);
  5927. - /* raise underflow if ux.value is subnormal or zero */
  5928. + /* raise underflow if ux.f is subnormal or zero */
  5929. if (e == 0)
  5930. - FORCE_EVAL(x*x + ux.value*ux.value);
  5931. - return ux.value;
  5932. + FORCE_EVAL(x*x + ux.f*ux.f);
  5933. + return ux.f;
  5934. }
  5935. diff -Nur musl-0.9.13/src/math/nextafterl.c musl-git/src/math/nextafterl.c
  5936. --- musl-0.9.13/src/math/nextafterl.c 2013-08-30 23:30:53.000000000 +0200
  5937. +++ musl-git/src/math/nextafterl.c 2013-09-16 20:31:39.000000000 +0200
  5938. @@ -6,7 +6,6 @@
  5939. return nextafter(x, y);
  5940. }
  5941. #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  5942. -#define MSB ((uint64_t)1<<63)
  5943. long double nextafterl(long double x, long double y)
  5944. {
  5945. union ldshape ux, uy;
  5946. @@ -15,32 +14,32 @@
  5947. return x + y;
  5948. if (x == y)
  5949. return y;
  5950. - ux.value = x;
  5951. + ux.f = x;
  5952. if (x == 0) {
  5953. - uy.value = y;
  5954. - ux.bits.m = 1;
  5955. - ux.bits.sign = uy.bits.sign;
  5956. - } else if (x < y ^ ux.bits.sign) {
  5957. - ux.bits.m++;
  5958. - if ((ux.bits.m & ~MSB) == 0) {
  5959. - ux.bits.m = MSB;
  5960. - ux.bits.exp++;
  5961. + uy.f = y;
  5962. + ux.i.m = 1;
  5963. + ux.i.se = uy.i.se & 0x8000;
  5964. + } else if ((x < y) == !(ux.i.se & 0x8000)) {
  5965. + ux.i.m++;
  5966. + if (ux.i.m << 1 == 0) {
  5967. + ux.i.m = 1ULL << 63;
  5968. + ux.i.se++;
  5969. }
  5970. } else {
  5971. - if ((ux.bits.m & ~MSB) == 0) {
  5972. - ux.bits.exp--;
  5973. - if (ux.bits.exp)
  5974. - ux.bits.m = 0;
  5975. + if (ux.i.m << 1 == 0) {
  5976. + ux.i.se--;
  5977. + if (ux.i.se)
  5978. + ux.i.m = 0;
  5979. }
  5980. - ux.bits.m--;
  5981. + ux.i.m--;
  5982. }
  5983. - /* raise overflow if ux.value is infinite and x is finite */
  5984. - if (ux.bits.exp == 0x7fff)
  5985. + /* raise overflow if ux is infinite and x is finite */
  5986. + if ((ux.i.se & 0x7fff) == 0x7fff)
  5987. return x + x;
  5988. - /* raise underflow if ux.value is subnormal or zero */
  5989. - if (ux.bits.exp == 0)
  5990. - FORCE_EVAL(x*x + ux.value*ux.value);
  5991. - return ux.value;
  5992. + /* raise underflow if ux is subnormal or zero */
  5993. + if ((ux.i.se & 0x7fff) == 0)
  5994. + FORCE_EVAL(x*x + ux.f*ux.f);
  5995. + return ux.f;
  5996. }
  5997. #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
  5998. long double nextafterl(long double x, long double y)
  5999. @@ -51,32 +50,26 @@
  6000. return x + y;
  6001. if (x == y)
  6002. return y;
  6003. - ux.value = x;
  6004. + ux.f = x;
  6005. if (x == 0) {
  6006. - uy.value = y;
  6007. - ux.bits.mlo = 1;
  6008. - ux.bits.sign = uy.bits.sign;
  6009. - } else if (x < y ^ ux.bits.sign) {
  6010. - ux.bits.mlo++;
  6011. - if (ux.bits.mlo == 0) {
  6012. - ux.bits.mhi++;
  6013. - if (ux.bits.mhi == 0)
  6014. - ux.bits.exp++;
  6015. - }
  6016. + uy.f = y;
  6017. + ux.i.lo = 1;
  6018. + ux.i.se = uy.i.se & 0x8000;
  6019. + } else if ((x < y) == !(ux.i.se & 0x8000)) {
  6020. + ux.i2.lo++;
  6021. + if (ux.i2.lo == 0)
  6022. + ux.i2.hi++;
  6023. } else {
  6024. - if (ux.bits.mlo == 0) {
  6025. - if (ux.bits.mhi == 0)
  6026. - ux.bits.exp--;
  6027. - ux.bits.mhi--;
  6028. - }
  6029. - ux.bits.mlo--;
  6030. + if (ux.i2.lo == 0)
  6031. + ux.i2.hi--;
  6032. + ux.i2.lo--;
  6033. }
  6034. - /* raise overflow if ux.value is infinite and x is finite */
  6035. - if (ux.bits.exp == 0x7fff)
  6036. + /* raise overflow if ux is infinite and x is finite */
  6037. + if ((ux.i.se & 0x7fff) == 0x7fff)
  6038. return x + x;
  6039. - /* raise underflow if ux.value is subnormal or zero */
  6040. - if (ux.bits.exp == 0)
  6041. - FORCE_EVAL(x*x + ux.value*ux.value);
  6042. - return ux.value;
  6043. + /* raise underflow if ux is subnormal or zero */
  6044. + if ((ux.i.se & 0x7fff) == 0)
  6045. + FORCE_EVAL(x*x + ux.f*ux.f);
  6046. + return ux.f;
  6047. }
  6048. #endif
  6049. diff -Nur musl-0.9.13/src/math/nexttoward.c musl-git/src/math/nexttoward.c
  6050. --- musl-0.9.13/src/math/nexttoward.c 2013-08-30 23:30:53.000000000 +0200
  6051. +++ musl-git/src/math/nexttoward.c 2013-09-16 20:31:39.000000000 +0200
  6052. @@ -6,40 +6,37 @@
  6053. return nextafter(x, y);
  6054. }
  6055. #else
  6056. -#define SIGN ((uint64_t)1<<63)
  6057. -
  6058. double nexttoward(double x, long double y)
  6059. {
  6060. - union dshape ux;
  6061. + union {double f; uint64_t i;} ux = {x};
  6062. int e;
  6063. if (isnan(x) || isnan(y))
  6064. return x + y;
  6065. if (x == y)
  6066. return y;
  6067. - ux.value = x;
  6068. if (x == 0) {
  6069. - ux.bits = 1;
  6070. + ux.i = 1;
  6071. if (signbit(y))
  6072. - ux.bits |= SIGN;
  6073. + ux.i |= 1ULL<<63;
  6074. } else if (x < y) {
  6075. if (signbit(x))
  6076. - ux.bits--;
  6077. + ux.i--;
  6078. else
  6079. - ux.bits++;
  6080. + ux.i++;
  6081. } else {
  6082. if (signbit(x))
  6083. - ux.bits++;
  6084. + ux.i++;
  6085. else
  6086. - ux.bits--;
  6087. + ux.i--;
  6088. }
  6089. - e = ux.bits>>52 & 0x7ff;
  6090. - /* raise overflow if ux.value is infinite and x is finite */
  6091. + e = ux.i>>52 & 0x7ff;
  6092. + /* raise overflow if ux.f is infinite and x is finite */
  6093. if (e == 0x7ff)
  6094. FORCE_EVAL(x+x);
  6095. - /* raise underflow if ux.value is subnormal or zero */
  6096. + /* raise underflow if ux.f is subnormal or zero */
  6097. if (e == 0)
  6098. - FORCE_EVAL(x*x + ux.value*ux.value);
  6099. - return ux.value;
  6100. + FORCE_EVAL(x*x + ux.f*ux.f);
  6101. + return ux.f;
  6102. }
  6103. #endif
  6104. diff -Nur musl-0.9.13/src/math/nexttowardf.c musl-git/src/math/nexttowardf.c
  6105. --- musl-0.9.13/src/math/nexttowardf.c 2013-08-30 23:30:53.000000000 +0200
  6106. +++ musl-git/src/math/nexttowardf.c 2013-09-16 20:31:39.000000000 +0200
  6107. @@ -2,35 +2,34 @@
  6108. float nexttowardf(float x, long double y)
  6109. {
  6110. - union fshape ux;
  6111. + union {float f; uint32_t i;} ux = {x};
  6112. uint32_t e;
  6113. if (isnan(x) || isnan(y))
  6114. return x + y;
  6115. if (x == y)
  6116. return y;
  6117. - ux.value = x;
  6118. if (x == 0) {
  6119. - ux.bits = 1;
  6120. + ux.i = 1;
  6121. if (signbit(y))
  6122. - ux.bits |= 0x80000000;
  6123. + ux.i |= 0x80000000;
  6124. } else if (x < y) {
  6125. if (signbit(x))
  6126. - ux.bits--;
  6127. + ux.i--;
  6128. else
  6129. - ux.bits++;
  6130. + ux.i++;
  6131. } else {
  6132. if (signbit(x))
  6133. - ux.bits++;
  6134. + ux.i++;
  6135. else
  6136. - ux.bits--;
  6137. + ux.i--;
  6138. }
  6139. - e = ux.bits & 0x7f800000;
  6140. - /* raise overflow if ux.value is infinite and x is finite */
  6141. + e = ux.i & 0x7f800000;
  6142. + /* raise overflow if ux.f is infinite and x is finite */
  6143. if (e == 0x7f800000)
  6144. FORCE_EVAL(x+x);
  6145. - /* raise underflow if ux.value is subnormal or zero */
  6146. + /* raise underflow if ux.f is subnormal or zero */
  6147. if (e == 0)
  6148. - FORCE_EVAL(x*x + ux.value*ux.value);
  6149. - return ux.value;
  6150. + FORCE_EVAL(x*x + ux.f*ux.f);
  6151. + return ux.f;
  6152. }
  6153. diff -Nur musl-0.9.13/src/math/remainder.c musl-git/src/math/remainder.c
  6154. --- musl-0.9.13/src/math/remainder.c 2013-08-30 23:30:53.000000000 +0200
  6155. +++ musl-git/src/math/remainder.c 2013-09-16 20:31:39.000000000 +0200
  6156. @@ -1,66 +1,7 @@
  6157. -/* origin: FreeBSD /usr/src/lib/msun/src/e_remainder.c */
  6158. -/*
  6159. - * ====================================================
  6160. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6161. - *
  6162. - * Developed at SunSoft, a Sun Microsystems, Inc. business.
  6163. - * Permission to use, copy, modify, and distribute this
  6164. - * software is freely granted, provided that this notice
  6165. - * is preserved.
  6166. - * ====================================================
  6167. - */
  6168. -/* remainder(x,p)
  6169. - * Return :
  6170. - * returns x REM p = x - [x/p]*p as if in infinite
  6171. - * precise arithmetic, where [x/p] is the (infinite bit)
  6172. - * integer nearest x/p (in half way case choose the even one).
  6173. - * Method :
  6174. - * Based on fmod() return x-[x/p]chopped*p exactlp.
  6175. - */
  6176. +#include <math.h>
  6177. -#include "libm.h"
  6178. -
  6179. -double remainder(double x, double p)
  6180. +double remainder(double x, double y)
  6181. {
  6182. - int32_t hx,hp;
  6183. - uint32_t sx,lx,lp;
  6184. - double p_half;
  6185. -
  6186. - EXTRACT_WORDS(hx, lx, x);
  6187. - EXTRACT_WORDS(hp, lp, p);
  6188. - sx = hx & 0x80000000;
  6189. - hp &= 0x7fffffff;
  6190. - hx &= 0x7fffffff;
  6191. -
  6192. - /* purge off exception values */
  6193. - if ((hp|lp) == 0 || /* p = 0 */
  6194. - hx >= 0x7ff00000 || /* x not finite */
  6195. - (hp >= 0x7ff00000 && (hp-0x7ff00000 | lp) != 0)) /* p is NaN */
  6196. - return (x*p)/(x*p);
  6197. -
  6198. - if (hp <= 0x7fdfffff)
  6199. - x = fmod(x, p+p); /* now x < 2p */
  6200. - if (((hx-hp)|(lx-lp)) == 0)
  6201. - return 0.0*x;
  6202. - x = fabs(x);
  6203. - p = fabs(p);
  6204. - if (hp < 0x00200000) {
  6205. - if (x + x > p) {
  6206. - x -= p;
  6207. - if (x + x >= p)
  6208. - x -= p;
  6209. - }
  6210. - } else {
  6211. - p_half = 0.5*p;
  6212. - if (x > p_half) {
  6213. - x -= p;
  6214. - if (x >= p_half)
  6215. - x -= p;
  6216. - }
  6217. - }
  6218. - GET_HIGH_WORD(hx, x);
  6219. - if ((hx&0x7fffffff) == 0)
  6220. - hx = 0;
  6221. - SET_HIGH_WORD(x, hx^sx);
  6222. - return x;
  6223. + int q;
  6224. + return remquo(x, y, &q);
  6225. }
  6226. diff -Nur musl-0.9.13/src/math/remainderf.c musl-git/src/math/remainderf.c
  6227. --- musl-0.9.13/src/math/remainderf.c 2013-08-30 23:30:53.000000000 +0200
  6228. +++ musl-git/src/math/remainderf.c 2013-09-16 20:31:39.000000000 +0200
  6229. @@ -1,59 +1,7 @@
  6230. -/* origin: FreeBSD /usr/src/lib/msun/src/e_remainderf.c */
  6231. -/*
  6232. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  6233. - */
  6234. -/*
  6235. - * ====================================================
  6236. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6237. - *
  6238. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  6239. - * Permission to use, copy, modify, and distribute this
  6240. - * software is freely granted, provided that this notice
  6241. - * is preserved.
  6242. - * ====================================================
  6243. - */
  6244. +#include <math.h>
  6245. -#include "libm.h"
  6246. -
  6247. -float remainderf(float x, float p)
  6248. +float remainderf(float x, float y)
  6249. {
  6250. - int32_t hx,hp;
  6251. - uint32_t sx;
  6252. - float p_half;
  6253. -
  6254. - GET_FLOAT_WORD(hx, x);
  6255. - GET_FLOAT_WORD(hp, p);
  6256. - sx = hx & 0x80000000;
  6257. - hp &= 0x7fffffff;
  6258. - hx &= 0x7fffffff;
  6259. -
  6260. - /* purge off exception values */
  6261. - if (hp == 0 || hx >= 0x7f800000 || hp > 0x7f800000) /* p = 0, x not finite, p is NaN */
  6262. - return (x*p)/(x*p);
  6263. -
  6264. - if (hp <= 0x7effffff)
  6265. - x = fmodf(x, p + p); /* now x < 2p */
  6266. - if (hx - hp == 0)
  6267. - return 0.0f*x;
  6268. - x = fabsf(x);
  6269. - p = fabsf(p);
  6270. - if (hp < 0x01000000) {
  6271. - if (x + x > p) {
  6272. - x -= p;
  6273. - if (x + x >= p)
  6274. - x -= p;
  6275. - }
  6276. - } else {
  6277. - p_half = 0.5f*p;
  6278. - if (x > p_half) {
  6279. - x -= p;
  6280. - if (x >= p_half)
  6281. - x -= p;
  6282. - }
  6283. - }
  6284. - GET_FLOAT_WORD(hx, x);
  6285. - if ((hx & 0x7fffffff) == 0)
  6286. - hx = 0;
  6287. - SET_FLOAT_WORD(x, hx ^ sx);
  6288. - return x;
  6289. + int q;
  6290. + return remquof(x, y, &q);
  6291. }
  6292. diff -Nur musl-0.9.13/src/math/remquo.c musl-git/src/math/remquo.c
  6293. --- musl-0.9.13/src/math/remquo.c 2013-08-30 23:30:53.000000000 +0200
  6294. +++ musl-git/src/math/remquo.c 2013-09-16 20:31:39.000000000 +0200
  6295. @@ -1,171 +1,82 @@
  6296. -/* origin: FreeBSD /usr/src/lib/msun/src/s_remquo.c */
  6297. -/*-
  6298. - * ====================================================
  6299. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6300. - *
  6301. - * Developed at SunSoft, a Sun Microsystems, Inc. business.
  6302. - * Permission to use, copy, modify, and distribute this
  6303. - * software is freely granted, provided that this notice
  6304. - * is preserved.
  6305. - * ====================================================
  6306. - */
  6307. -/*
  6308. - * Return the IEEE remainder and set *quo to the last n bits of the
  6309. - * quotient, rounded to the nearest integer. We choose n=31 because
  6310. - * we wind up computing all the integer bits of the quotient anyway as
  6311. - * a side-effect of computing the remainder by the shift and subtract
  6312. - * method. In practice, this is far more bits than are needed to use
  6313. - * remquo in reduction algorithms.
  6314. - */
  6315. -
  6316. -#include "libm.h"
  6317. -
  6318. -static const double Zero[] = {0.0, -0.0,};
  6319. +#include <math.h>
  6320. +#include <stdint.h>
  6321. double remquo(double x, double y, int *quo)
  6322. {
  6323. - int32_t n,hx,hy,hz,ix,iy,sx,i;
  6324. - uint32_t lx,ly,lz,q,sxy;
  6325. -
  6326. - EXTRACT_WORDS(hx, lx, x);
  6327. - EXTRACT_WORDS(hy, ly, y);
  6328. - sxy = (hx ^ hy) & 0x80000000;
  6329. - sx = hx & 0x80000000; /* sign of x */
  6330. - hx ^= sx; /* |x| */
  6331. - hy &= 0x7fffffff; /* |y| */
  6332. + union {double f; uint64_t i;} ux = {x}, uy = {y};
  6333. + int ex = ux.i>>52 & 0x7ff;
  6334. + int ey = uy.i>>52 & 0x7ff;
  6335. + int sx = ux.i>>63;
  6336. + int sy = uy.i>>63;
  6337. + uint32_t q;
  6338. + uint64_t i;
  6339. + uint64_t uxi = ux.i;
  6340. - /* purge off exception values */
  6341. - if ((hy|ly) == 0 || hx >= 0x7ff00000 || /* y = 0, or x not finite */
  6342. - (hy|((ly|-ly)>>31)) > 0x7ff00000) /* or y is NaN */
  6343. + *quo = 0;
  6344. + if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff)
  6345. return (x*y)/(x*y);
  6346. - if (hx <= hy) {
  6347. - if (hx < hy || lx < ly) { /* |x| < |y| return x or x-y */
  6348. - q = 0;
  6349. - goto fixup;
  6350. - }
  6351. - if (lx == ly) { /* |x| = |y| return x*0 */
  6352. - *quo = sxy ? -1 : 1;
  6353. - return Zero[(uint32_t)sx>>31];
  6354. - }
  6355. - }
  6356. + if (ux.i<<1 == 0)
  6357. + return x;
  6358. - // FIXME: use ilogb?
  6359. -
  6360. - /* determine ix = ilogb(x) */
  6361. - if (hx < 0x00100000) { /* subnormal x */
  6362. - if (hx == 0) {
  6363. - for (ix = -1043, i=lx; i>0; i<<=1) ix--;
  6364. - } else {
  6365. - for (ix = -1022, i=hx<<11; i>0; i<<=1) ix--;
  6366. - }
  6367. - } else
  6368. - ix = (hx>>20) - 1023;
  6369. -
  6370. - /* determine iy = ilogb(y) */
  6371. - if (hy < 0x00100000) { /* subnormal y */
  6372. - if (hy == 0) {
  6373. - for (iy = -1043, i=ly; i>0; i<<=1) iy--;
  6374. - } else {
  6375. - for (iy = -1022, i=hy<<11; i>0; i<<=1) iy--;
  6376. - }
  6377. - } else
  6378. - iy = (hy>>20) - 1023;
  6379. -
  6380. - /* set up {hx,lx}, {hy,ly} and align y to x */
  6381. - if (ix >= -1022)
  6382. - hx = 0x00100000|(0x000fffff&hx);
  6383. - else { /* subnormal x, shift x to normal */
  6384. - n = -1022 - ix;
  6385. - if (n <= 31) {
  6386. - hx = (hx<<n)|(lx>>(32-n));
  6387. - lx <<= n;
  6388. - } else {
  6389. - hx = lx<<(n-32);
  6390. - lx = 0;
  6391. - }
  6392. - }
  6393. - if (iy >= -1022)
  6394. - hy = 0x00100000|(0x000fffff&hy);
  6395. - else { /* subnormal y, shift y to normal */
  6396. - n = -1022 - iy;
  6397. - if (n <= 31) {
  6398. - hy = (hy<<n)|(ly>>(32-n));
  6399. - ly <<= n;
  6400. - } else {
  6401. - hy = ly<<(n-32);
  6402. - ly = 0;
  6403. - }
  6404. + /* normalize x and y */
  6405. + if (!ex) {
  6406. + for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1);
  6407. + uxi <<= -ex + 1;
  6408. + } else {
  6409. + uxi &= -1ULL >> 12;
  6410. + uxi |= 1ULL << 52;
  6411. + }
  6412. + if (!ey) {
  6413. + for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1);
  6414. + uy.i <<= -ey + 1;
  6415. + } else {
  6416. + uy.i &= -1ULL >> 12;
  6417. + uy.i |= 1ULL << 52;
  6418. }
  6419. - /* fix point fmod */
  6420. - n = ix - iy;
  6421. q = 0;
  6422. - while (n--) {
  6423. - hz = hx - hy;
  6424. - lz = lx - ly;
  6425. - if (lx < ly)
  6426. - hz--;
  6427. - if (hz < 0) {
  6428. - hx = hx + hx + (lx>>31);
  6429. - lx = lx + lx;
  6430. - } else {
  6431. - hx = hz + hz + (lz>>31);
  6432. - lx = lz + lz;
  6433. + if (ex < ey) {
  6434. + if (ex+1 == ey)
  6435. + goto end;
  6436. + return x;
  6437. + }
  6438. +
  6439. + /* x mod y */
  6440. + for (; ex > ey; ex--) {
  6441. + i = uxi - uy.i;
  6442. + if (i >> 63 == 0) {
  6443. + uxi = i;
  6444. q++;
  6445. }
  6446. + uxi <<= 1;
  6447. q <<= 1;
  6448. }
  6449. - hz = hx - hy;
  6450. - lz = lx - ly;
  6451. - if (lx < ly)
  6452. - hz--;
  6453. - if (hz >= 0) {
  6454. - hx = hz;
  6455. - lx = lz;
  6456. + i = uxi - uy.i;
  6457. + if (i >> 63 == 0) {
  6458. + uxi = i;
  6459. q++;
  6460. }
  6461. -
  6462. - /* convert back to floating value and restore the sign */
  6463. - if ((hx|lx) == 0) { /* return sign(x)*0 */
  6464. - q &= 0x7fffffff;
  6465. - *quo = sxy ? -q : q;
  6466. - return Zero[(uint32_t)sx>>31];
  6467. - }
  6468. - while (hx < 0x00100000) { /* normalize x */
  6469. - hx = hx + hx + (lx>>31);
  6470. - lx = lx + lx;
  6471. - iy--;
  6472. - }
  6473. - if (iy >= -1022) { /* normalize output */
  6474. - hx = (hx-0x00100000)|((iy+1023)<<20);
  6475. - } else { /* subnormal output */
  6476. - n = -1022 - iy;
  6477. - if (n <= 20) {
  6478. - lx = (lx>>n)|((uint32_t)hx<<(32-n));
  6479. - hx >>= n;
  6480. - } else if (n <= 31) {
  6481. - lx = (hx<<(32-n))|(lx>>n);
  6482. - hx = 0;
  6483. - } else {
  6484. - lx = hx>>(n-32);
  6485. - hx = 0;
  6486. - }
  6487. - }
  6488. -fixup:
  6489. - INSERT_WORDS(x, hx, lx);
  6490. - y = fabs(y);
  6491. - if (y < 0x1p-1021) {
  6492. - if (x + x > y || (x + x == y && (q & 1))) {
  6493. - q++;
  6494. - x -= y;
  6495. - }
  6496. - } else if (x > 0.5*y || (x == 0.5*y && (q & 1))) {
  6497. - q++;
  6498. + if (uxi == 0)
  6499. + ex = -60;
  6500. + else
  6501. + for (; uxi>>52 == 0; uxi <<= 1, ex--);
  6502. +end:
  6503. + /* scale result and decide between |x| and |x|-|y| */
  6504. + if (ex > 0) {
  6505. + uxi -= 1ULL << 52;
  6506. + uxi |= (uint64_t)ex << 52;
  6507. + } else {
  6508. + uxi >>= -ex + 1;
  6509. + }
  6510. + ux.i = uxi;
  6511. + x = ux.f;
  6512. + if (sy)
  6513. + y = -y;
  6514. + if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) {
  6515. x -= y;
  6516. + q++;
  6517. }
  6518. - GET_HIGH_WORD(hx, x);
  6519. - SET_HIGH_WORD(x, hx ^ sx);
  6520. q &= 0x7fffffff;
  6521. - *quo = sxy ? -q : q;
  6522. - return x;
  6523. + *quo = sx^sy ? -(int)q : (int)q;
  6524. + return sx ? -x : x;
  6525. }
  6526. diff -Nur musl-0.9.13/src/math/remquof.c musl-git/src/math/remquof.c
  6527. --- musl-0.9.13/src/math/remquof.c 2013-08-30 23:30:53.000000000 +0200
  6528. +++ musl-git/src/math/remquof.c 2013-09-16 20:31:39.000000000 +0200
  6529. @@ -1,126 +1,82 @@
  6530. -/* origin: FreeBSD /usr/src/lib/msun/src/s_remquof.c */
  6531. -/*-
  6532. - * ====================================================
  6533. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6534. - *
  6535. - * Developed at SunSoft, a Sun Microsystems, Inc. business.
  6536. - * Permission to use, copy, modify, and distribute this
  6537. - * software is freely granted, provided that this notice
  6538. - * is preserved.
  6539. - * ====================================================
  6540. - */
  6541. -/*
  6542. - * Return the IEEE remainder and set *quo to the last n bits of the
  6543. - * quotient, rounded to the nearest integer. We choose n=31 because
  6544. - * we wind up computing all the integer bits of the quotient anyway as
  6545. - * a side-effect of computing the remainder by the shift and subtract
  6546. - * method. In practice, this is far more bits than are needed to use
  6547. - * remquo in reduction algorithms.
  6548. - */
  6549. -
  6550. -#include "libm.h"
  6551. -
  6552. -static const float Zero[] = {0.0, -0.0,};
  6553. +#include <math.h>
  6554. +#include <stdint.h>
  6555. float remquof(float x, float y, int *quo)
  6556. {
  6557. - int32_t n,hx,hy,hz,ix,iy,sx,i;
  6558. - uint32_t q,sxy;
  6559. + union {float f; uint32_t i;} ux = {x}, uy = {y};
  6560. + int ex = ux.i>>23 & 0xff;
  6561. + int ey = uy.i>>23 & 0xff;
  6562. + int sx = ux.i>>31;
  6563. + int sy = uy.i>>31;
  6564. + uint32_t q;
  6565. + uint32_t i;
  6566. + uint32_t uxi = ux.i;
  6567. - GET_FLOAT_WORD(hx, x);
  6568. - GET_FLOAT_WORD(hy, y);
  6569. - sxy = (hx ^ hy) & 0x80000000;
  6570. - sx = hx & 0x80000000; /* sign of x */
  6571. - hx ^= sx; /* |x| */
  6572. - hy &= 0x7fffffff; /* |y| */
  6573. -
  6574. - /* purge off exception values */
  6575. - if (hy == 0 || hx >= 0x7f800000 || hy > 0x7f800000) /* y=0,NaN;or x not finite */
  6576. + *quo = 0;
  6577. + if (uy.i<<1 == 0 || isnan(y) || ex == 0xff)
  6578. return (x*y)/(x*y);
  6579. - if (hx < hy) { /* |x| < |y| return x or x-y */
  6580. - q = 0;
  6581. - goto fixup;
  6582. - } else if(hx==hy) { /* |x| = |y| return x*0*/
  6583. - *quo = sxy ? -1 : 1;
  6584. - return Zero[(uint32_t)sx>>31];
  6585. - }
  6586. + if (ux.i<<1 == 0)
  6587. + return x;
  6588. - /* determine ix = ilogb(x) */
  6589. - if (hx < 0x00800000) { /* subnormal x */
  6590. - for (ix = -126, i=hx<<8; i>0; i<<=1) ix--;
  6591. - } else
  6592. - ix = (hx>>23) - 127;
  6593. -
  6594. - /* determine iy = ilogb(y) */
  6595. - if (hy < 0x00800000) { /* subnormal y */
  6596. - for (iy = -126, i=hy<<8; i>0; i<<=1) iy--;
  6597. - } else
  6598. - iy = (hy>>23) - 127;
  6599. -
  6600. - /* set up {hx,lx}, {hy,ly} and align y to x */
  6601. - if (ix >= -126)
  6602. - hx = 0x00800000|(0x007fffff&hx);
  6603. - else { /* subnormal x, shift x to normal */
  6604. - n = -126 - ix;
  6605. - hx <<= n;
  6606. - }
  6607. - if (iy >= -126)
  6608. - hy = 0x00800000|(0x007fffff&hy);
  6609. - else { /* subnormal y, shift y to normal */
  6610. - n = -126 - iy;
  6611. - hy <<= n;
  6612. + /* normalize x and y */
  6613. + if (!ex) {
  6614. + for (i = uxi<<9; i>>31 == 0; ex--, i <<= 1);
  6615. + uxi <<= -ex + 1;
  6616. + } else {
  6617. + uxi &= -1U >> 9;
  6618. + uxi |= 1U << 23;
  6619. + }
  6620. + if (!ey) {
  6621. + for (i = uy.i<<9; i>>31 == 0; ey--, i <<= 1);
  6622. + uy.i <<= -ey + 1;
  6623. + } else {
  6624. + uy.i &= -1U >> 9;
  6625. + uy.i |= 1U << 23;
  6626. }
  6627. - /* fix point fmod */
  6628. - n = ix - iy;
  6629. q = 0;
  6630. - while (n--) {
  6631. - hz = hx - hy;
  6632. - if (hz < 0)
  6633. - hx = hx << 1;
  6634. - else {
  6635. - hx = hz << 1;
  6636. + if (ex < ey) {
  6637. + if (ex+1 == ey)
  6638. + goto end;
  6639. + return x;
  6640. + }
  6641. +
  6642. + /* x mod y */
  6643. + for (; ex > ey; ex--) {
  6644. + i = uxi - uy.i;
  6645. + if (i >> 31 == 0) {
  6646. + uxi = i;
  6647. q++;
  6648. }
  6649. + uxi <<= 1;
  6650. q <<= 1;
  6651. }
  6652. - hz = hx - hy;
  6653. - if (hz >= 0) {
  6654. - hx = hz;
  6655. + i = uxi - uy.i;
  6656. + if (i >> 31 == 0) {
  6657. + uxi = i;
  6658. q++;
  6659. }
  6660. -
  6661. - /* convert back to floating value and restore the sign */
  6662. - if (hx == 0) { /* return sign(x)*0 */
  6663. - q &= 0x7fffffff;
  6664. - *quo = sxy ? -q : q;
  6665. - return Zero[(uint32_t)sx>>31];
  6666. - }
  6667. - while (hx < 0x00800000) { /* normalize x */
  6668. - hx <<= 1;
  6669. - iy--;
  6670. - }
  6671. - if (iy >= -126) { /* normalize output */
  6672. - hx = (hx-0x00800000)|((iy+127)<<23);
  6673. - } else { /* subnormal output */
  6674. - n = -126 - iy;
  6675. - hx >>= n;
  6676. - }
  6677. -fixup:
  6678. - SET_FLOAT_WORD(x,hx);
  6679. - y = fabsf(y);
  6680. - if (y < 0x1p-125f) {
  6681. - if (x + x > y || (x + x == y && (q & 1))) {
  6682. - q++;
  6683. - x -= y;
  6684. - }
  6685. - } else if (x > 0.5f*y || (x == 0.5f*y && (q & 1))) {
  6686. - q++;
  6687. + if (uxi == 0)
  6688. + ex = -30;
  6689. + else
  6690. + for (; uxi>>23 == 0; uxi <<= 1, ex--);
  6691. +end:
  6692. + /* scale result and decide between |x| and |x|-|y| */
  6693. + if (ex > 0) {
  6694. + uxi -= 1U << 23;
  6695. + uxi |= (uint32_t)ex << 23;
  6696. + } else {
  6697. + uxi >>= -ex + 1;
  6698. + }
  6699. + ux.i = uxi;
  6700. + x = ux.f;
  6701. + if (sy)
  6702. + y = -y;
  6703. + if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) {
  6704. x -= y;
  6705. + q++;
  6706. }
  6707. - GET_FLOAT_WORD(hx, x);
  6708. - SET_FLOAT_WORD(x, hx ^ sx);
  6709. q &= 0x7fffffff;
  6710. - *quo = sxy ? -q : q;
  6711. - return x;
  6712. + *quo = sx^sy ? -(int)q : (int)q;
  6713. + return sx ? -x : x;
  6714. }
  6715. diff -Nur musl-0.9.13/src/math/remquol.c musl-git/src/math/remquol.c
  6716. --- musl-0.9.13/src/math/remquol.c 2013-08-30 23:30:53.000000000 +0200
  6717. +++ musl-git/src/math/remquol.c 2013-09-16 20:31:39.000000000 +0200
  6718. @@ -1,15 +1,3 @@
  6719. -/* origin: FreeBSD /usr/src/lib/msun/src/s_remquol.c */
  6720. -/*-
  6721. - * ====================================================
  6722. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6723. - *
  6724. - * Developed at SunSoft, a Sun Microsystems, Inc. business.
  6725. - * Permission to use, copy, modify, and distribute this
  6726. - * software is freely granted, provided that this notice
  6727. - * is preserved.
  6728. - * ====================================================
  6729. - */
  6730. -
  6731. #include "libm.h"
  6732. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  6733. @@ -18,177 +6,119 @@
  6734. return remquo(x, y, quo);
  6735. }
  6736. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  6737. -
  6738. -#define BIAS (LDBL_MAX_EXP - 1)
  6739. -
  6740. -#if LDBL_MANL_SIZE > 32
  6741. -typedef uint64_t manl_t;
  6742. -#else
  6743. -typedef uint32_t manl_t;
  6744. -#endif
  6745. -
  6746. -#if LDBL_MANH_SIZE > 32
  6747. -typedef uint64_t manh_t;
  6748. -#else
  6749. -typedef uint32_t manh_t;
  6750. -#endif
  6751. -
  6752. -/*
  6753. - * These macros add and remove an explicit integer bit in front of the
  6754. - * fractional mantissa, if the architecture doesn't have such a bit by
  6755. - * default already.
  6756. - */
  6757. -#ifdef LDBL_IMPLICIT_NBIT
  6758. -#define SET_NBIT(hx) ((hx) | (1ULL << LDBL_MANH_SIZE))
  6759. -#define HFRAC_BITS LDBL_MANH_SIZE
  6760. -#else
  6761. -#define SET_NBIT(hx) (hx)
  6762. -#define HFRAC_BITS (LDBL_MANH_SIZE - 1)
  6763. -#endif
  6764. -
  6765. -#define MANL_SHIFT (LDBL_MANL_SIZE - 1)
  6766. -
  6767. -static const long double Zero[] = {0.0, -0.0};
  6768. -
  6769. -/*
  6770. - * Return the IEEE remainder and set *quo to the last n bits of the
  6771. - * quotient, rounded to the nearest integer. We choose n=31 because
  6772. - * we wind up computing all the integer bits of the quotient anyway as
  6773. - * a side-effect of computing the remainder by the shift and subtract
  6774. - * method. In practice, this is far more bits than are needed to use
  6775. - * remquo in reduction algorithms.
  6776. - *
  6777. - * Assumptions:
  6778. - * - The low part of the mantissa fits in a manl_t exactly.
  6779. - * - The high part of the mantissa fits in an int64_t with enough room
  6780. - * for an explicit integer bit in front of the fractional bits.
  6781. - */
  6782. long double remquol(long double x, long double y, int *quo)
  6783. {
  6784. - union IEEEl2bits ux, uy;
  6785. - int64_t hx,hz; /* We need a carry bit even if LDBL_MANH_SIZE is 32. */
  6786. - manh_t hy;
  6787. - manl_t lx,ly,lz;
  6788. - int ix,iy,n,q,sx,sxy;
  6789. + union ldshape ux = {x}, uy = {y};
  6790. + int ex = ux.i.se & 0x7fff;
  6791. + int ey = uy.i.se & 0x7fff;
  6792. + int sx = ux.i.se >> 15;
  6793. + int sy = uy.i.se >> 15;
  6794. + uint32_t q;
  6795. - ux.e = x;
  6796. - uy.e = y;
  6797. - sx = ux.bits.sign;
  6798. - sxy = sx ^ uy.bits.sign;
  6799. - ux.bits.sign = 0; /* |x| */
  6800. - uy.bits.sign = 0; /* |y| */
  6801. - x = ux.e;
  6802. -
  6803. - /* purge off exception values */
  6804. - if ((uy.bits.exp|uy.bits.manh|uy.bits.manl)==0 || /* y=0 */
  6805. - (ux.bits.exp == BIAS + LDBL_MAX_EXP) || /* or x not finite */
  6806. - (uy.bits.exp == BIAS + LDBL_MAX_EXP &&
  6807. - ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0)) /* or y is NaN */
  6808. + *quo = 0;
  6809. + if (y == 0 || isnan(y) || ex == 0x7fff)
  6810. return (x*y)/(x*y);
  6811. - if (ux.bits.exp <= uy.bits.exp) {
  6812. - if ((ux.bits.exp < uy.bits.exp) ||
  6813. - (ux.bits.manh <= uy.bits.manh &&
  6814. - (ux.bits.manh < uy.bits.manh ||
  6815. - ux.bits.manl < uy.bits.manl))) {
  6816. - q = 0;
  6817. - goto fixup; /* |x|<|y| return x or x-y */
  6818. - }
  6819. - if (ux.bits.manh == uy.bits.manh && ux.bits.manl == uy.bits.manl) {
  6820. - *quo = sxy ? -1 : 1;
  6821. - return Zero[sx]; /* |x|=|y| return x*0*/
  6822. - }
  6823. - }
  6824. -
  6825. - /* determine ix = ilogb(x) */
  6826. - if (ux.bits.exp == 0) { /* subnormal x */
  6827. - ux.e *= 0x1.0p512;
  6828. - ix = ux.bits.exp - (BIAS + 512);
  6829. - } else {
  6830. - ix = ux.bits.exp - BIAS;
  6831. - }
  6832. + if (x == 0)
  6833. + return x;
  6834. - /* determine iy = ilogb(y) */
  6835. - if (uy.bits.exp == 0) { /* subnormal y */
  6836. - uy.e *= 0x1.0p512;
  6837. - iy = uy.bits.exp - (BIAS + 512);
  6838. - } else {
  6839. - iy = uy.bits.exp - BIAS;
  6840. + /* normalize x and y */
  6841. + if (!ex) {
  6842. + ux.i.se = ex;
  6843. + ux.f *= 0x1p120f;
  6844. + ex = ux.i.se - 120;
  6845. + }
  6846. + if (!ey) {
  6847. + uy.i.se = ey;
  6848. + uy.f *= 0x1p120f;
  6849. + ey = uy.i.se - 120;
  6850. }
  6851. - /* set up {hx,lx}, {hy,ly} and align y to x */
  6852. - hx = SET_NBIT(ux.bits.manh);
  6853. - hy = SET_NBIT(uy.bits.manh);
  6854. - lx = ux.bits.manl;
  6855. - ly = uy.bits.manl;
  6856. -
  6857. - /* fix point fmod */
  6858. - n = ix - iy;
  6859. q = 0;
  6860. -
  6861. - while (n--) {
  6862. - hz = hx - hy;
  6863. - lz = lx - ly;
  6864. - if (lx < ly)
  6865. - hz -= 1;
  6866. - if (hz < 0) {
  6867. - hx = hx + hx + (lx>>MANL_SHIFT);
  6868. - lx = lx + lx;
  6869. - } else {
  6870. - hx = hz + hz + (lz>>MANL_SHIFT);
  6871. - lx = lz + lz;
  6872. + if (ex >= ey) {
  6873. + /* x mod y */
  6874. +#if LDBL_MANT_DIG == 64
  6875. + uint64_t i, mx, my;
  6876. + mx = ux.i.m;
  6877. + my = uy.i.m;
  6878. + for (; ex > ey; ex--) {
  6879. + i = mx - my;
  6880. + if (mx >= my) {
  6881. + mx = 2*i;
  6882. + q++;
  6883. + q <<= 1;
  6884. + } else if (2*mx < mx) {
  6885. + mx = 2*mx - my;
  6886. + q <<= 1;
  6887. + q++;
  6888. + } else {
  6889. + mx = 2*mx;
  6890. + q <<= 1;
  6891. + }
  6892. + }
  6893. + i = mx - my;
  6894. + if (mx >= my) {
  6895. + mx = i;
  6896. q++;
  6897. }
  6898. - q <<= 1;
  6899. - }
  6900. - hz = hx - hy;
  6901. - lz = lx - ly;
  6902. - if (lx < ly)
  6903. - hz -= 1;
  6904. - if (hz >= 0) {
  6905. - hx = hz;
  6906. - lx = lz;
  6907. - q++;
  6908. - }
  6909. -
  6910. - /* convert back to floating value and restore the sign */
  6911. - if ((hx|lx) == 0) { /* return sign(x)*0 */
  6912. - q &= 0x7fffffff;
  6913. - *quo = sxy ? -q : q;
  6914. - return Zero[sx];
  6915. - }
  6916. - while (hx < (1ULL<<HFRAC_BITS)) { /* normalize x */
  6917. - hx = hx + hx + (lx>>MANL_SHIFT);
  6918. - lx = lx + lx;
  6919. - iy -= 1;
  6920. - }
  6921. - ux.bits.manh = hx; /* The integer bit is truncated here if needed. */
  6922. - ux.bits.manl = lx;
  6923. - if (iy < LDBL_MIN_EXP) {
  6924. - ux.bits.exp = iy + (BIAS + 512);
  6925. - ux.e *= 0x1p-512;
  6926. - } else {
  6927. - ux.bits.exp = iy + BIAS;
  6928. - }
  6929. - ux.bits.sign = 0;
  6930. - x = ux.e;
  6931. -fixup:
  6932. - y = fabsl(y);
  6933. - if (y < LDBL_MIN * 2) {
  6934. - if (x + x > y || (x + x == y && (q & 1))) {
  6935. + if (mx == 0)
  6936. + ex = -120;
  6937. + else
  6938. + for (; mx >> 63 == 0; mx *= 2, ex--);
  6939. + ux.i.m = mx;
  6940. +#elif LDBL_MANT_DIG == 113
  6941. + uint64_t hi, lo, xhi, xlo, yhi, ylo;
  6942. + xhi = (ux.i2.hi & -1ULL>>16) | 1ULL<<48;
  6943. + yhi = (uy.i2.hi & -1ULL>>16) | 1ULL<<48;
  6944. + xlo = ux.i2.lo;
  6945. + ylo = ux.i2.lo;
  6946. + for (; ex > ey; ex--) {
  6947. + hi = xhi - yhi;
  6948. + lo = xlo - ylo;
  6949. + if (xlo < ylo)
  6950. + hi -= 1;
  6951. + if (hi >> 63 == 0) {
  6952. + xhi = 2*hi + (lo>>63);
  6953. + xlo = 2*lo;
  6954. + q++;
  6955. + } else {
  6956. + xhi = 2*xhi + (xlo>>63);
  6957. + xlo = 2*xlo;
  6958. + }
  6959. + q <<= 1;
  6960. + }
  6961. + hi = xhi - yhi;
  6962. + lo = xlo - ylo;
  6963. + if (xlo < ylo)
  6964. + hi -= 1;
  6965. + if (hi >> 63 == 0) {
  6966. + xhi = hi;
  6967. + xlo = lo;
  6968. q++;
  6969. - x-=y;
  6970. }
  6971. - } else if (x > 0.5*y || (x == 0.5*y && (q & 1))) {
  6972. - q++;
  6973. - x-=y;
  6974. + if ((xhi|xlo) == 0)
  6975. + ex = -120;
  6976. + else
  6977. + for (; xhi >> 48 == 0; xhi = 2*xhi + (xlo>>63), xlo = 2*xlo, ex--);
  6978. + ux.i2.hi = xhi;
  6979. + ux.i2.lo = xlo;
  6980. +#endif
  6981. }
  6982. - ux.e = x;
  6983. - ux.bits.sign ^= sx;
  6984. - x = ux.e;
  6985. -
  6986. + /* scale result and decide between |x| and |x|-|y| */
  6987. + if (ex <= 0) {
  6988. + ux.i.se = ex + 120;
  6989. + ux.f *= 0x1p-120f;
  6990. + } else
  6991. + ux.i.se = ex;
  6992. + x = ux.f;
  6993. + if (sy)
  6994. + y = -y;
  6995. + if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) {
  6996. + x -= y;
  6997. + q++;
  6998. + }
  6999. q &= 0x7fffffff;
  7000. - *quo = sxy ? -q : q;
  7001. - return x;
  7002. + *quo = sx^sy ? -(int)q : (int)q;
  7003. + return sx ? -x : x;
  7004. }
  7005. #endif
  7006. diff -Nur musl-0.9.13/src/math/rint.c musl-git/src/math/rint.c
  7007. --- musl-0.9.13/src/math/rint.c 2013-08-30 23:30:53.000000000 +0200
  7008. +++ musl-git/src/math/rint.c 2013-09-16 20:31:39.000000000 +0200
  7009. @@ -1,90 +1,20 @@
  7010. -/* origin: FreeBSD /usr/src/lib/msun/src/s_rint.c */
  7011. -/*
  7012. - * ====================================================
  7013. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7014. - *
  7015. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  7016. - * Permission to use, copy, modify, and distribute this
  7017. - * software is freely granted, provided that this notice
  7018. - * is preserved.
  7019. - * ====================================================
  7020. - */
  7021. -/*
  7022. - * rint(x)
  7023. - * Return x rounded to integral value according to the prevailing
  7024. - * rounding mode.
  7025. - * Method:
  7026. - * Using floating addition.
  7027. - * Exception:
  7028. - * Inexact flag raised if x not equal to rint(x).
  7029. - */
  7030. -
  7031. -#include "libm.h"
  7032. -
  7033. -static const double
  7034. -TWO52[2] = {
  7035. - 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
  7036. - -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
  7037. -};
  7038. +#include <math.h>
  7039. +#include <stdint.h>
  7040. double rint(double x)
  7041. {
  7042. - int32_t i0,j0,sx;
  7043. - uint32_t i,i1;
  7044. - double w,t;
  7045. + union {double f; uint64_t i;} u = {x};
  7046. + int e = u.i>>52 & 0x7ff;
  7047. + int s = u.i>>63;
  7048. + double_t y;
  7049. - EXTRACT_WORDS(i0, i1, x);
  7050. - // FIXME: signed shift
  7051. - sx = (i0>>31) & 1;
  7052. - j0 = ((i0>>20)&0x7ff) - 0x3ff;
  7053. - if (j0 < 20) {
  7054. - if (j0 < 0) {
  7055. - if (((i0&0x7fffffff)|i1) == 0)
  7056. - return x;
  7057. - i1 |= i0 & 0x0fffff;
  7058. - i0 &= 0xfffe0000;
  7059. - i0 |= ((i1|-i1)>>12) & 0x80000;
  7060. - SET_HIGH_WORD(x, i0);
  7061. - STRICT_ASSIGN(double, w, TWO52[sx] + x);
  7062. - t = w - TWO52[sx];
  7063. - GET_HIGH_WORD(i0, t);
  7064. - SET_HIGH_WORD(t, (i0&0x7fffffff)|(sx<<31));
  7065. - return t;
  7066. - } else {
  7067. - i = 0x000fffff>>j0;
  7068. - if (((i0&i)|i1) == 0)
  7069. - return x; /* x is integral */
  7070. - i >>= 1;
  7071. - if (((i0&i)|i1) != 0) {
  7072. - /*
  7073. - * Some bit is set after the 0.5 bit. To avoid the
  7074. - * possibility of errors from double rounding in
  7075. - * w = TWO52[sx]+x, adjust the 0.25 bit to a lower
  7076. - * guard bit. We do this for all j0<=51. The
  7077. - * adjustment is trickiest for j0==18 and j0==19
  7078. - * since then it spans the word boundary.
  7079. - */
  7080. - if (j0 == 19)
  7081. - i1 = 0x40000000;
  7082. - else if (j0 == 18)
  7083. - i1 = 0x80000000;
  7084. - else
  7085. - i0 = (i0 & ~i)|(0x20000>>j0);
  7086. - }
  7087. - }
  7088. - } else if (j0 > 51) {
  7089. - if (j0 == 0x400)
  7090. - return x+x; /* inf or NaN */
  7091. - return x; /* x is integral */
  7092. - } else {
  7093. - i = (uint32_t)0xffffffff>>(j0-20);
  7094. - if ((i1&i) == 0)
  7095. - return x; /* x is integral */
  7096. - i >>= 1;
  7097. - if ((i1&i) != 0)
  7098. - i1 = (i1 & ~i)|(0x40000000>>(j0-20));
  7099. - }
  7100. - INSERT_WORDS(x, i0, i1);
  7101. - STRICT_ASSIGN(double, w, TWO52[sx] + x);
  7102. - return w - TWO52[sx];
  7103. + if (e >= 0x3ff+52)
  7104. + return x;
  7105. + if (s)
  7106. + y = (double)(x - 0x1p52) + 0x1p52;
  7107. + else
  7108. + y = (double)(x + 0x1p52) - 0x1p52;
  7109. + if (y == 0)
  7110. + return s ? -0.0 : 0;
  7111. + return y;
  7112. }
  7113. diff -Nur musl-0.9.13/src/math/rintf.c musl-git/src/math/rintf.c
  7114. --- musl-0.9.13/src/math/rintf.c 2013-08-30 23:30:53.000000000 +0200
  7115. +++ musl-git/src/math/rintf.c 2013-09-16 20:31:39.000000000 +0200
  7116. @@ -1,48 +1,20 @@
  7117. -/* origin: FreeBSD /usr/src/lib/msun/src/s_rintf.c */
  7118. -/*
  7119. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  7120. - */
  7121. -/*
  7122. - * ====================================================
  7123. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7124. - *
  7125. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  7126. - * Permission to use, copy, modify, and distribute this
  7127. - * software is freely granted, provided that this notice
  7128. - * is preserved.
  7129. - * ====================================================
  7130. - */
  7131. -
  7132. -#include "libm.h"
  7133. -
  7134. -static const float
  7135. -TWO23[2] = {
  7136. - 8.3886080000e+06, /* 0x4b000000 */
  7137. - -8.3886080000e+06, /* 0xcb000000 */
  7138. -};
  7139. +#include <math.h>
  7140. +#include <stdint.h>
  7141. float rintf(float x)
  7142. {
  7143. - int32_t i0,j0,sx;
  7144. - float w,t;
  7145. + union {float f; uint32_t i;} u = {x};
  7146. + int e = u.i>>23 & 0xff;
  7147. + int s = u.i>>31;
  7148. + float_t y;
  7149. - GET_FLOAT_WORD(i0, x);
  7150. - sx = (i0>>31) & 1;
  7151. - j0 = ((i0>>23)&0xff) - 0x7f;
  7152. - if (j0 < 23) {
  7153. - if (j0 < 0) {
  7154. - if ((i0&0x7fffffff) == 0)
  7155. - return x;
  7156. - STRICT_ASSIGN(float, w, TWO23[sx] + x);
  7157. - t = w - TWO23[sx];
  7158. - GET_FLOAT_WORD(i0, t);
  7159. - SET_FLOAT_WORD(t, (i0&0x7fffffff)|(sx<<31));
  7160. - return t;
  7161. - }
  7162. - STRICT_ASSIGN(float, w, TWO23[sx] + x);
  7163. - return w - TWO23[sx];
  7164. - }
  7165. - if (j0 == 0x80)
  7166. - return x+x; /* inf or NaN */
  7167. - return x; /* x is integral */
  7168. + if (e >= 0x7f+23)
  7169. + return x;
  7170. + if (s)
  7171. + y = (float)(x - 0x1p23f) + 0x1p23f;
  7172. + else
  7173. + y = (float)(x + 0x1p23f) - 0x1p23f;
  7174. + if (y == 0)
  7175. + return s ? -0.0f : 0.0f;
  7176. + return y;
  7177. }
  7178. diff -Nur musl-0.9.13/src/math/rintl.c musl-git/src/math/rintl.c
  7179. --- musl-0.9.13/src/math/rintl.c 2013-08-30 23:30:53.000000000 +0200
  7180. +++ musl-git/src/math/rintl.c 2013-09-16 20:31:39.000000000 +0200
  7181. @@ -1,30 +1,3 @@
  7182. -/* origin: FreeBSD /usr/src/lib/msun/src/s_rintl.c */
  7183. -/*-
  7184. - * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
  7185. - * All rights reserved.
  7186. - *
  7187. - * Redistribution and use in source and binary forms, with or without
  7188. - * modification, are permitted provided that the following conditions
  7189. - * are met:
  7190. - * 1. Redistributions of source code must retain the above copyright
  7191. - * notice, this list of conditions and the following disclaimer.
  7192. - * 2. Redistributions in binary form must reproduce the above copyright
  7193. - * notice, this list of conditions and the following disclaimer in the
  7194. - * documentation and/or other materials provided with the distribution.
  7195. - *
  7196. - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  7197. - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7198. - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7199. - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  7200. - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  7201. - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  7202. - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  7203. - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  7204. - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  7205. - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  7206. - * SUCH DAMAGE.
  7207. - */
  7208. -
  7209. #include "libm.h"
  7210. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  7211. @@ -33,53 +6,26 @@
  7212. return rint(x);
  7213. }
  7214. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  7215. -
  7216. -#define BIAS (LDBL_MAX_EXP - 1)
  7217. -
  7218. -static const float
  7219. -shift[2] = {
  7220. #if LDBL_MANT_DIG == 64
  7221. - 0x1.0p63, -0x1.0p63
  7222. +#define TOINT 0x1p63
  7223. #elif LDBL_MANT_DIG == 113
  7224. - 0x1.0p112, -0x1.0p112
  7225. +#define TOINT 0x1p112
  7226. #endif
  7227. -};
  7228. -static const float zero[2] = { 0.0, -0.0 };
  7229. -
  7230. long double rintl(long double x)
  7231. {
  7232. - union IEEEl2bits u;
  7233. - uint32_t expsign;
  7234. - int ex, sign;
  7235. -
  7236. - u.e = x;
  7237. - expsign = u.xbits.expsign;
  7238. - ex = expsign & 0x7fff;
  7239. -
  7240. - if (ex >= BIAS + LDBL_MANT_DIG - 1) {
  7241. - if (ex == BIAS + LDBL_MAX_EXP)
  7242. - return x + x; /* Inf, NaN, or unsupported format */
  7243. - return x; /* finite and already an integer */
  7244. - }
  7245. - sign = expsign >> 15;
  7246. -
  7247. - /*
  7248. - * The following code assumes that intermediate results are
  7249. - * evaluated in long double precision. If they are evaluated in
  7250. - * greater precision, double rounding may occur, and if they are
  7251. - * evaluated in less precision (as on i386), results will be
  7252. - * wildly incorrect.
  7253. - */
  7254. - x += shift[sign];
  7255. - x -= shift[sign];
  7256. -
  7257. - /*
  7258. - * If the result is +-0, then it must have the same sign as x, but
  7259. - * the above calculation doesn't always give this. Fix up the sign.
  7260. - */
  7261. - if (ex < BIAS && x == 0.0)
  7262. - return zero[sign];
  7263. -
  7264. - return x;
  7265. + union ldshape u = {x};
  7266. + int e = u.i.se & 0x7fff;
  7267. + int s = u.i.se >> 15;
  7268. + long double y;
  7269. +
  7270. + if (e >= 0x3fff+LDBL_MANT_DIG-1)
  7271. + return x;
  7272. + if (s)
  7273. + y = x - TOINT + TOINT;
  7274. + else
  7275. + y = x + TOINT - TOINT;
  7276. + if (y == 0)
  7277. + return 0*x;
  7278. + return y;
  7279. }
  7280. #endif
  7281. diff -Nur musl-0.9.13/src/math/round.c musl-git/src/math/round.c
  7282. --- musl-0.9.13/src/math/round.c 2013-08-30 23:30:53.000000000 +0200
  7283. +++ musl-git/src/math/round.c 2013-09-16 20:31:39.000000000 +0200
  7284. @@ -1,48 +1,28 @@
  7285. -/* origin: FreeBSD /usr/src/lib/msun/src/s_round.c */
  7286. -/*-
  7287. - * Copyright (c) 2003, Steven G. Kargl
  7288. - * All rights reserved.
  7289. - *
  7290. - * Redistribution and use in source and binary forms, with or without
  7291. - * modification, are permitted provided that the following conditions
  7292. - * are met:
  7293. - * 1. Redistributions of source code must retain the above copyright
  7294. - * notice unmodified, this list of conditions, and the following
  7295. - * disclaimer.
  7296. - * 2. Redistributions in binary form must reproduce the above copyright
  7297. - * notice, this list of conditions and the following disclaimer in the
  7298. - * documentation and/or other materials provided with the distribution.
  7299. - *
  7300. - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  7301. - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7302. - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7303. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  7304. - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  7305. - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  7306. - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  7307. - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7308. - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7309. - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7310. - */
  7311. -
  7312. -#include <math.h>
  7313. +#include "libm.h"
  7314. double round(double x)
  7315. {
  7316. - double t;
  7317. + union {double f; uint64_t i;} u = {x};
  7318. + int e = u.i >> 52 & 0x7ff;
  7319. + double_t y;
  7320. - if (!isfinite(x))
  7321. + if (e >= 0x3ff+52)
  7322. return x;
  7323. -
  7324. - if (x >= 0.0) {
  7325. - t = floor(x);
  7326. - if (t - x <= -0.5)
  7327. - t += 1.0;
  7328. - return t;
  7329. - } else {
  7330. - t = floor(-x);
  7331. - if (t + x <= -0.5)
  7332. - t += 1.0;
  7333. - return -t;
  7334. + if (u.i >> 63)
  7335. + x = -x;
  7336. + if (e < 0x3ff-1) {
  7337. + /* raise inexact if x!=0 */
  7338. + FORCE_EVAL(x + 0x1p52);
  7339. + return 0*u.f;
  7340. }
  7341. + y = (double)(x + 0x1p52) - 0x1p52 - x;
  7342. + if (y > 0.5)
  7343. + y = y + x - 1;
  7344. + else if (y <= -0.5)
  7345. + y = y + x + 1;
  7346. + else
  7347. + y = y + x;
  7348. + if (u.i >> 63)
  7349. + y = -y;
  7350. + return y;
  7351. }
  7352. diff -Nur musl-0.9.13/src/math/roundf.c musl-git/src/math/roundf.c
  7353. --- musl-0.9.13/src/math/roundf.c 2013-08-30 23:30:53.000000000 +0200
  7354. +++ musl-git/src/math/roundf.c 2013-09-16 20:31:39.000000000 +0200
  7355. @@ -1,48 +1,27 @@
  7356. -/* origin: FreeBSD /usr/src/lib/msun/src/s_roundf.c */
  7357. -/*-
  7358. - * Copyright (c) 2003, Steven G. Kargl
  7359. - * All rights reserved.
  7360. - *
  7361. - * Redistribution and use in source and binary forms, with or without
  7362. - * modification, are permitted provided that the following conditions
  7363. - * are met:
  7364. - * 1. Redistributions of source code must retain the above copyright
  7365. - * notice unmodified, this list of conditions, and the following
  7366. - * disclaimer.
  7367. - * 2. Redistributions in binary form must reproduce the above copyright
  7368. - * notice, this list of conditions and the following disclaimer in the
  7369. - * documentation and/or other materials provided with the distribution.
  7370. - *
  7371. - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  7372. - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7373. - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7374. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  7375. - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  7376. - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  7377. - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  7378. - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7379. - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7380. - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7381. - */
  7382. -
  7383. -#include <math.h>
  7384. +#include "libm.h"
  7385. float roundf(float x)
  7386. {
  7387. - float t;
  7388. + union {float f; uint32_t i;} u = {x};
  7389. + int e = u.i >> 23 & 0xff;
  7390. + float_t y;
  7391. - if (!isfinite(x))
  7392. + if (e >= 0x7f+23)
  7393. return x;
  7394. -
  7395. - if (x >= 0.0) {
  7396. - t = floorf(x);
  7397. - if (t - x <= -0.5)
  7398. - t += 1.0;
  7399. - return t;
  7400. - } else {
  7401. - t = floorf(-x);
  7402. - if (t + x <= -0.5)
  7403. - t += 1.0;
  7404. - return -t;
  7405. + if (u.i >> 31)
  7406. + x = -x;
  7407. + if (e < 0x7f-1) {
  7408. + FORCE_EVAL(x + 0x1p23f);
  7409. + return 0*u.f;
  7410. }
  7411. + y = (float)(x + 0x1p23f) - 0x1p23f - x;
  7412. + if (y > 0.5f)
  7413. + y = y + x - 1;
  7414. + else if (y <= -0.5f)
  7415. + y = y + x + 1;
  7416. + else
  7417. + y = y + x;
  7418. + if (u.i >> 31)
  7419. + y = -y;
  7420. + return y;
  7421. }
  7422. diff -Nur musl-0.9.13/src/math/roundl.c musl-git/src/math/roundl.c
  7423. --- musl-0.9.13/src/math/roundl.c 2013-08-30 23:30:53.000000000 +0200
  7424. +++ musl-git/src/math/roundl.c 2013-09-16 20:31:39.000000000 +0200
  7425. @@ -1,56 +1,39 @@
  7426. -/* origin: FreeBSD /usr/src/lib/msun/src/s_roundl.c */
  7427. -/*-
  7428. - * Copyright (c) 2003, Steven G. Kargl
  7429. - * All rights reserved.
  7430. - *
  7431. - * Redistribution and use in source and binary forms, with or without
  7432. - * modification, are permitted provided that the following conditions
  7433. - * are met:
  7434. - * 1. Redistributions of source code must retain the above copyright
  7435. - * notice unmodified, this list of conditions, and the following
  7436. - * disclaimer.
  7437. - * 2. Redistributions in binary form must reproduce the above copyright
  7438. - * notice, this list of conditions and the following disclaimer in the
  7439. - * documentation and/or other materials provided with the distribution.
  7440. - *
  7441. - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  7442. - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7443. - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7444. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  7445. - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  7446. - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  7447. - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  7448. - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7449. - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7450. - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7451. - */
  7452. -
  7453. -#include <math.h>
  7454. -#include <float.h>
  7455. +#include "libm.h"
  7456. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  7457. long double roundl(long double x)
  7458. {
  7459. return round(x);
  7460. }
  7461. -#else
  7462. +#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  7463. +#if LDBL_MANT_DIG == 64
  7464. +#define TOINT 0x1p63
  7465. +#elif LDBL_MANT_DIG == 113
  7466. +#define TOINT 0x1p112
  7467. +#endif
  7468. long double roundl(long double x)
  7469. {
  7470. - long double t;
  7471. + union ldshape u = {x};
  7472. + int e = u.i.se & 0x7fff;
  7473. + long double y;
  7474. - if (!isfinite(x))
  7475. + if (e >= 0x3fff+LDBL_MANT_DIG-1)
  7476. return x;
  7477. -
  7478. - if (x >= 0.0) {
  7479. - t = floorl(x);
  7480. - if (t - x <= -0.5)
  7481. - t += 1.0;
  7482. - return t;
  7483. - } else {
  7484. - t = floorl(-x);
  7485. - if (t + x <= -0.5)
  7486. - t += 1.0;
  7487. - return -t;
  7488. + if (u.i.se >> 15)
  7489. + x = -x;
  7490. + if (e < 0x3fff-1) {
  7491. + FORCE_EVAL(x + TOINT);
  7492. + return 0*u.f;
  7493. }
  7494. + y = x + TOINT - TOINT - x;
  7495. + if (y > 0.5)
  7496. + y = y + x - 1;
  7497. + else if (y <= -0.5)
  7498. + y = y + x + 1;
  7499. + else
  7500. + y = y + x;
  7501. + if (u.i.se >> 15)
  7502. + y = -y;
  7503. + return y;
  7504. }
  7505. #endif
  7506. diff -Nur musl-0.9.13/src/math/scalbn.c musl-git/src/math/scalbn.c
  7507. --- musl-0.9.13/src/math/scalbn.c 2013-08-30 23:30:53.000000000 +0200
  7508. +++ musl-git/src/math/scalbn.c 2013-09-16 20:31:39.000000000 +0200
  7509. @@ -1,29 +1,31 @@
  7510. -#include "libm.h"
  7511. +#include <math.h>
  7512. +#include <stdint.h>
  7513. double scalbn(double x, int n)
  7514. {
  7515. - double scale;
  7516. + union {double f; uint64_t i;} u;
  7517. + double_t y = x;
  7518. if (n > 1023) {
  7519. - x *= 0x1p1023;
  7520. + y *= 0x1p1023;
  7521. n -= 1023;
  7522. if (n > 1023) {
  7523. - x *= 0x1p1023;
  7524. + y *= 0x1p1023;
  7525. n -= 1023;
  7526. if (n > 1023)
  7527. n = 1023;
  7528. }
  7529. } else if (n < -1022) {
  7530. - x *= 0x1p-1022;
  7531. + y *= 0x1p-1022;
  7532. n += 1022;
  7533. if (n < -1022) {
  7534. - x *= 0x1p-1022;
  7535. + y *= 0x1p-1022;
  7536. n += 1022;
  7537. if (n < -1022)
  7538. n = -1022;
  7539. }
  7540. }
  7541. - INSERT_WORDS(scale, (uint32_t)(0x3ff+n)<<20, 0);
  7542. - STRICT_ASSIGN(double, x, x * scale);
  7543. + u.i = (uint64_t)(0x3ff+n)<<52;
  7544. + x = y * u.f;
  7545. return x;
  7546. }
  7547. diff -Nur musl-0.9.13/src/math/scalbnf.c musl-git/src/math/scalbnf.c
  7548. --- musl-0.9.13/src/math/scalbnf.c 2013-08-30 23:30:53.000000000 +0200
  7549. +++ musl-git/src/math/scalbnf.c 2013-09-16 20:31:39.000000000 +0200
  7550. @@ -1,29 +1,31 @@
  7551. -#include "libm.h"
  7552. +#include <math.h>
  7553. +#include <stdint.h>
  7554. float scalbnf(float x, int n)
  7555. {
  7556. - float scale;
  7557. + union {float f; uint32_t i;} u;
  7558. + float_t y = x;
  7559. if (n > 127) {
  7560. - x *= 0x1p127f;
  7561. + y *= 0x1p127f;
  7562. n -= 127;
  7563. if (n > 127) {
  7564. - x *= 0x1p127f;
  7565. + y *= 0x1p127f;
  7566. n -= 127;
  7567. if (n > 127)
  7568. n = 127;
  7569. }
  7570. } else if (n < -126) {
  7571. - x *= 0x1p-126f;
  7572. + y *= 0x1p-126f;
  7573. n += 126;
  7574. if (n < -126) {
  7575. - x *= 0x1p-126f;
  7576. + y *= 0x1p-126f;
  7577. n += 126;
  7578. if (n < -126)
  7579. n = -126;
  7580. }
  7581. }
  7582. - SET_FLOAT_WORD(scale, (uint32_t)(0x7f+n)<<23);
  7583. - STRICT_ASSIGN(float, x, x * scale);
  7584. + u.i = (uint32_t)(0x7f+n)<<23;
  7585. + x = y * u.f;
  7586. return x;
  7587. }
  7588. diff -Nur musl-0.9.13/src/math/scalbnl.c musl-git/src/math/scalbnl.c
  7589. --- musl-0.9.13/src/math/scalbnl.c 2013-08-30 23:30:53.000000000 +0200
  7590. +++ musl-git/src/math/scalbnl.c 2013-09-16 20:31:39.000000000 +0200
  7591. @@ -8,7 +8,7 @@
  7592. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  7593. long double scalbnl(long double x, int n)
  7594. {
  7595. - union IEEEl2bits scale;
  7596. + union ldshape u;
  7597. if (n > 16383) {
  7598. x *= 0x1p16383L;
  7599. @@ -29,8 +29,8 @@
  7600. n = -16382;
  7601. }
  7602. }
  7603. - scale.e = 1.0;
  7604. - scale.bits.exp = 0x3fff + n;
  7605. - return x * scale.e;
  7606. + u.f = 1.0;
  7607. + u.i.se = 0x3fff + n;
  7608. + return x * u.f;
  7609. }
  7610. #endif
  7611. diff -Nur musl-0.9.13/src/math/signgam.c musl-git/src/math/signgam.c
  7612. --- musl-0.9.13/src/math/signgam.c 2013-08-30 23:30:53.000000000 +0200
  7613. +++ musl-git/src/math/signgam.c 2013-09-16 20:31:39.000000000 +0200
  7614. @@ -1,4 +1,5 @@
  7615. -#include "libm.h"
  7616. +#include <math.h>
  7617. +#include "libc.h"
  7618. int __signgam = 0;
  7619. diff -Nur musl-0.9.13/src/math/sincosl.c musl-git/src/math/sincosl.c
  7620. --- musl-0.9.13/src/math/sincosl.c 2013-08-30 23:30:53.000000000 +0200
  7621. +++ musl-git/src/math/sincosl.c 2013-09-16 20:31:39.000000000 +0200
  7622. @@ -9,25 +9,19 @@
  7623. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  7624. void sincosl(long double x, long double *sin, long double *cos)
  7625. {
  7626. - union IEEEl2bits u;
  7627. + union ldshape u = {x};
  7628. unsigned n;
  7629. long double y[2], s, c;
  7630. - u.e = x;
  7631. - u.bits.sign = 0;
  7632. -
  7633. - /* x = nan or inf */
  7634. - if (u.bits.exp == 0x7fff) {
  7635. + u.i.se &= 0x7fff;
  7636. + if (u.i.se == 0x7fff) {
  7637. *sin = *cos = x - x;
  7638. return;
  7639. }
  7640. -
  7641. - /* |x| < (double)pi/4 */
  7642. - if (u.e < M_PI_4) {
  7643. - /* |x| < 0x1p-64 */
  7644. - if (u.bits.exp < 0x3fff - 64) {
  7645. + if (u.f < M_PI_4) {
  7646. + if (u.i.se < 0x3fff - LDBL_MANT_DIG) {
  7647. /* raise underflow if subnormal */
  7648. - if (u.bits.exp == 0) FORCE_EVAL(x*0x1p-120f);
  7649. + if (u.i.se == 0) FORCE_EVAL(x*0x1p-120f);
  7650. *sin = x;
  7651. /* raise inexact if x!=0 */
  7652. *cos = 1.0 + x;
  7653. @@ -37,7 +31,6 @@
  7654. *cos = __cosl(x, 0);
  7655. return;
  7656. }
  7657. -
  7658. n = __rem_pio2l(x, y);
  7659. s = __sinl(y[0], y[1], 1);
  7660. c = __cosl(y[0], y[1]);
  7661. diff -Nur musl-0.9.13/src/math/sinhl.c musl-git/src/math/sinhl.c
  7662. --- musl-0.9.13/src/math/sinhl.c 2013-08-30 23:30:53.000000000 +0200
  7663. +++ musl-git/src/math/sinhl.c 2013-09-16 20:31:39.000000000 +0200
  7664. @@ -8,10 +8,7 @@
  7665. #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  7666. long double sinhl(long double x)
  7667. {
  7668. - union {
  7669. - long double f;
  7670. - struct{uint64_t m; uint16_t se; uint16_t pad;} i;
  7671. - } u = {.f = x};
  7672. + union ldshape u = {x};
  7673. unsigned ex = u.i.se & 0x7fff;
  7674. long double h, t, absx;
  7675. diff -Nur musl-0.9.13/src/math/sinl.c musl-git/src/math/sinl.c
  7676. --- musl-0.9.13/src/math/sinl.c 2013-08-30 23:30:53.000000000 +0200
  7677. +++ musl-git/src/math/sinl.c 2013-09-16 20:31:39.000000000 +0200
  7678. @@ -1,31 +1,3 @@
  7679. -/* origin: FreeBSD /usr/src/lib/msun/src/s_sinl.c */
  7680. -/*-
  7681. - * Copyright (c) 2007 Steven G. Kargl
  7682. - * All rights reserved.
  7683. - *
  7684. - * Redistribution and use in source and binary forms, with or without
  7685. - * modification, are permitted provided that the following conditions
  7686. - * are met:
  7687. - * 1. Redistributions of source code must retain the above copyright
  7688. - * notice unmodified, this list of conditions, and the following
  7689. - * disclaimer.
  7690. - * 2. Redistributions in binary form must reproduce the above copyright
  7691. - * notice, this list of conditions and the following disclaimer in the
  7692. - * documentation and/or other materials provided with the distribution.
  7693. - *
  7694. - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  7695. - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7696. - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7697. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  7698. - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  7699. - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  7700. - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  7701. - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7702. - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7703. - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7704. - */
  7705. -
  7706. -
  7707. #include "libm.h"
  7708. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  7709. @@ -36,46 +8,34 @@
  7710. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  7711. long double sinl(long double x)
  7712. {
  7713. - union IEEEl2bits z;
  7714. + union ldshape u = {x};
  7715. unsigned n;
  7716. - long double y[2];
  7717. - long double hi, lo;
  7718. -
  7719. - z.e = x;
  7720. - z.bits.sign = 0;
  7721. + long double y[2], hi, lo;
  7722. - /* If x = NaN or Inf, then sin(x) = NaN. */
  7723. - if (z.bits.exp == 0x7fff)
  7724. - return (x - x) / (x - x);
  7725. -
  7726. - /* |x| < (double)pi/4 */
  7727. - if (z.e < M_PI_4) {
  7728. - /* |x| < 0x1p-64 */
  7729. - if (z.bits.exp < 0x3fff - 64) {
  7730. + u.i.se &= 0x7fff;
  7731. + if (u.i.se == 0x7fff)
  7732. + return x - x;
  7733. + if (u.f < M_PI_4) {
  7734. + if (u.i.se < 0x3fff - LDBL_MANT_DIG/2) {
  7735. /* raise inexact if x!=0 and underflow if subnormal */
  7736. - FORCE_EVAL(z.bits.exp == 0 ? x/0x1p120f : x+0x1p120f);
  7737. + FORCE_EVAL(u.i.se == 0 ? x*0x1p-120f : x+0x1p120f);
  7738. return x;
  7739. }
  7740. return __sinl(x, 0.0, 0);
  7741. }
  7742. -
  7743. n = __rem_pio2l(x, y);
  7744. hi = y[0];
  7745. lo = y[1];
  7746. switch (n & 3) {
  7747. case 0:
  7748. - hi = __sinl(hi, lo, 1);
  7749. - break;
  7750. + return __sinl(hi, lo, 1);
  7751. case 1:
  7752. - hi = __cosl(hi, lo);
  7753. - break;
  7754. + return __cosl(hi, lo);
  7755. case 2:
  7756. - hi = -__sinl(hi, lo, 1);
  7757. - break;
  7758. + return -__sinl(hi, lo, 1);
  7759. case 3:
  7760. - hi = -__cosl(hi, lo);
  7761. - break;
  7762. + default:
  7763. + return -__cosl(hi, lo);
  7764. }
  7765. - return hi;
  7766. }
  7767. #endif
  7768. diff -Nur musl-0.9.13/src/math/sqrtl.c musl-git/src/math/sqrtl.c
  7769. --- musl-0.9.13/src/math/sqrtl.c 2013-08-30 23:30:53.000000000 +0200
  7770. +++ musl-git/src/math/sqrtl.c 2013-09-16 20:31:39.000000000 +0200
  7771. @@ -2,8 +2,6 @@
  7772. long double sqrtl(long double x)
  7773. {
  7774. - /* FIXME: implement sqrtl in C. At least this works for now on
  7775. - * ARM (which uses ld64), the only arch without sqrtl asm
  7776. - * that's supported so far. */
  7777. + /* FIXME: implement in C, this is for LDBL_MANT_DIG == 64 only */
  7778. return sqrt(x);
  7779. }
  7780. diff -Nur musl-0.9.13/src/math/tanhl.c musl-git/src/math/tanhl.c
  7781. --- musl-0.9.13/src/math/tanhl.c 2013-08-30 23:30:53.000000000 +0200
  7782. +++ musl-git/src/math/tanhl.c 2013-09-16 20:31:39.000000000 +0200
  7783. @@ -8,10 +8,7 @@
  7784. #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
  7785. long double tanhl(long double x)
  7786. {
  7787. - union {
  7788. - long double f;
  7789. - struct{uint64_t m; uint16_t se; uint16_t pad;} i;
  7790. - } u = {.f = x};
  7791. + union ldshape u = {x};
  7792. unsigned ex = u.i.se & 0x7fff;
  7793. unsigned sign = u.i.se & 0x8000;
  7794. uint32_t w;
  7795. diff -Nur musl-0.9.13/src/math/tanl.c musl-git/src/math/tanl.c
  7796. --- musl-0.9.13/src/math/tanl.c 2013-08-30 23:30:53.000000000 +0200
  7797. +++ musl-git/src/math/tanl.c 2013-09-16 20:31:39.000000000 +0200
  7798. @@ -1,35 +1,3 @@
  7799. -/* origin: FreeBSD /usr/src/lib/msun/src/s_tanl.c */
  7800. -/*-
  7801. - * Copyright (c) 2007 Steven G. Kargl
  7802. - * All rights reserved.
  7803. - *
  7804. - * Redistribution and use in source and binary forms, with or without
  7805. - * modification, are permitted provided that the following conditions
  7806. - * are met:
  7807. - * 1. Redistributions of source code must retain the above copyright
  7808. - * notice unmodified, this list of conditions, and the following
  7809. - * disclaimer.
  7810. - * 2. Redistributions in binary form must reproduce the above copyright
  7811. - * notice, this list of conditions and the following disclaimer in the
  7812. - * documentation and/or other materials provided with the distribution.
  7813. - *
  7814. - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  7815. - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  7816. - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7817. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  7818. - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  7819. - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  7820. - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  7821. - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7822. - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7823. - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7824. - */
  7825. -/*
  7826. - * Limited testing on pseudorandom numbers drawn within [0:4e8] shows
  7827. - * an accuracy of <= 1.5 ULP where 247024 values of x out of 40 million
  7828. - * possibles resulted in tan(x) that exceeded 0.5 ULP (ie., 0.6%).
  7829. - */
  7830. -
  7831. #include "libm.h"
  7832. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  7833. @@ -40,28 +8,21 @@
  7834. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  7835. long double tanl(long double x)
  7836. {
  7837. - union IEEEl2bits z;
  7838. + union ldshape u = {x};
  7839. long double y[2];
  7840. unsigned n;
  7841. - z.e = x;
  7842. - z.bits.sign = 0;
  7843. -
  7844. - /* If x = NaN or Inf, then tan(x) = NaN. */
  7845. - if (z.bits.exp == 0x7fff)
  7846. - return (x - x) / (x - x);
  7847. -
  7848. - /* |x| < (double)pi/4 */
  7849. - if (z.e < M_PI_4) {
  7850. - /* |x| < 0x1p-64 */
  7851. - if (z.bits.exp < 0x3fff - 64) {
  7852. + u.i.se &= 0x7fff;
  7853. + if (u.i.se == 0x7fff)
  7854. + return x - x;
  7855. + if (u.f < M_PI_4) {
  7856. + if (u.i.se < 0x3fff - LDBL_MANT_DIG/2) {
  7857. /* raise inexact if x!=0 and underflow if subnormal */
  7858. - FORCE_EVAL(z.bits.exp == 0 ? x/0x1p120f : x+0x1p120f);
  7859. + FORCE_EVAL(u.i.se == 0 ? x*0x1p-120f : x+0x1p120f);
  7860. return x;
  7861. }
  7862. return __tanl(x, 0, 0);
  7863. }
  7864. -
  7865. n = __rem_pio2l(x, y);
  7866. return __tanl(y[0], y[1], n&1);
  7867. }
  7868. diff -Nur musl-0.9.13/src/math/trunc.c musl-git/src/math/trunc.c
  7869. --- musl-0.9.13/src/math/trunc.c 2013-08-30 23:30:53.000000000 +0200
  7870. +++ musl-git/src/math/trunc.c 2013-09-16 20:31:39.000000000 +0200
  7871. @@ -1,63 +1,19 @@
  7872. -/* origin: FreeBSD /usr/src/lib/msun/src/s_trunc.c */
  7873. -/*
  7874. - * ====================================================
  7875. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7876. - *
  7877. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  7878. - * Permission to use, copy, modify, and distribute this
  7879. - * software is freely granted, provided that this notice
  7880. - * is preserved.
  7881. - * ====================================================
  7882. - */
  7883. -/*
  7884. - * trunc(x)
  7885. - * Return x rounded toward 0 to integral value
  7886. - * Method:
  7887. - * Bit twiddling.
  7888. - * Exception:
  7889. - * Inexact flag raised if x not equal to trunc(x).
  7890. - */
  7891. -
  7892. #include "libm.h"
  7893. -static const double huge = 1.0e300;
  7894. -
  7895. double trunc(double x)
  7896. {
  7897. - int32_t i0,i1,j0;
  7898. - uint32_t i;
  7899. + union {double f; uint64_t i;} u = {x};
  7900. + int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
  7901. + uint64_t m;
  7902. - EXTRACT_WORDS(i0, i1, x);
  7903. - j0 = ((i0>>20)&0x7ff) - 0x3ff;
  7904. - if (j0 < 20) {
  7905. - if (j0 < 0) { /* |x|<1, return 0*sign(x) */
  7906. - /* raise inexact if x != 0 */
  7907. - if (huge+x > 0.0) {
  7908. - i0 &= 0x80000000U;
  7909. - i1 = 0;
  7910. - }
  7911. - } else {
  7912. - i = 0x000fffff>>j0;
  7913. - if (((i0&i)|i1) == 0)
  7914. - return x; /* x is integral */
  7915. - /* raise inexact */
  7916. - if (huge+x > 0.0) {
  7917. - i0 &= ~i;
  7918. - i1 = 0;
  7919. - }
  7920. - }
  7921. - } else if (j0 > 51) {
  7922. - if (j0 == 0x400)
  7923. - return x + x; /* inf or NaN */
  7924. - return x; /* x is integral */
  7925. - } else {
  7926. - i = (uint32_t)0xffffffff>>(j0-20);
  7927. - if ((i1&i) == 0)
  7928. - return x; /* x is integral */
  7929. - /* raise inexact */
  7930. - if (huge+x > 0.0)
  7931. - i1 &= ~i;
  7932. - }
  7933. - INSERT_WORDS(x, i0, i1);
  7934. - return x;
  7935. + if (e >= 52 + 12)
  7936. + return x;
  7937. + if (e < 12)
  7938. + e = 1;
  7939. + m = -1ULL >> e;
  7940. + if ((u.i & m) == 0)
  7941. + return x;
  7942. + FORCE_EVAL(x + 0x1p120f);
  7943. + u.i &= ~m;
  7944. + return u.f;
  7945. }
  7946. diff -Nur musl-0.9.13/src/math/truncf.c musl-git/src/math/truncf.c
  7947. --- musl-0.9.13/src/math/truncf.c 2013-08-30 23:30:53.000000000 +0200
  7948. +++ musl-git/src/math/truncf.c 2013-09-16 20:31:39.000000000 +0200
  7949. @@ -1,52 +1,19 @@
  7950. -/* origin: FreeBSD /usr/src/lib/msun/src/s_truncf.c */
  7951. -/*
  7952. - * ====================================================
  7953. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7954. - *
  7955. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  7956. - * Permission to use, copy, modify, and distribute this
  7957. - * software is freely granted, provided that this notice
  7958. - * is preserved.
  7959. - * ====================================================
  7960. - */
  7961. -/*
  7962. - * truncf(x)
  7963. - * Return x rounded toward 0 to integral value
  7964. - * Method:
  7965. - * Bit twiddling.
  7966. - * Exception:
  7967. - * Inexact flag raised if x not equal to truncf(x).
  7968. - */
  7969. -
  7970. #include "libm.h"
  7971. -static const float huge = 1.0e30f;
  7972. -
  7973. float truncf(float x)
  7974. {
  7975. - int32_t i0,j0;
  7976. - uint32_t i;
  7977. + union {float f; uint32_t i;} u = {x};
  7978. + int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9;
  7979. + uint32_t m;
  7980. - GET_FLOAT_WORD(i0, x);
  7981. - j0 = ((i0>>23)&0xff) - 0x7f;
  7982. - if (j0 < 23) {
  7983. - if (j0 < 0) { /* |x|<1, return 0*sign(x) */
  7984. - /* raise inexact if x != 0 */
  7985. - if (huge+x > 0.0f)
  7986. - i0 &= 0x80000000;
  7987. - } else {
  7988. - i = 0x007fffff>>j0;
  7989. - if ((i0&i) == 0)
  7990. - return x; /* x is integral */
  7991. - /* raise inexact */
  7992. - if (huge+x > 0.0f)
  7993. - i0 &= ~i;
  7994. - }
  7995. - } else {
  7996. - if (j0 == 0x80)
  7997. - return x + x; /* inf or NaN */
  7998. - return x; /* x is integral */
  7999. - }
  8000. - SET_FLOAT_WORD(x, i0);
  8001. - return x;
  8002. + if (e >= 23 + 9)
  8003. + return x;
  8004. + if (e < 9)
  8005. + e = 1;
  8006. + m = -1U >> e;
  8007. + if ((u.i & m) == 0)
  8008. + return x;
  8009. + FORCE_EVAL(x + 0x1p120f);
  8010. + u.i &= ~m;
  8011. + return u.f;
  8012. }
  8013. diff -Nur musl-0.9.13/src/math/truncl.c musl-git/src/math/truncl.c
  8014. --- musl-0.9.13/src/math/truncl.c 2013-08-30 23:30:53.000000000 +0200
  8015. +++ musl-git/src/math/truncl.c 2013-09-16 20:31:39.000000000 +0200
  8016. @@ -1,23 +1,3 @@
  8017. -/* origin: FreeBSD /usr/src/lib/msun/src/s_truncl.c */
  8018. -/*
  8019. - * ====================================================
  8020. - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  8021. - *
  8022. - * Developed at SunPro, a Sun Microsystems, Inc. business.
  8023. - * Permission to use, copy, modify, and distribute this
  8024. - * software is freely granted, provided that this notice
  8025. - * is preserved.
  8026. - * ====================================================
  8027. - */
  8028. -/*
  8029. - * truncl(x)
  8030. - * Return x rounded toward 0 to integral value
  8031. - * Method:
  8032. - * Bit twiddling.
  8033. - * Exception:
  8034. - * Inexact flag raised if x not equal to truncl(x).
  8035. - */
  8036. -
  8037. #include "libm.h"
  8038. #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
  8039. @@ -26,43 +6,31 @@
  8040. return trunc(x);
  8041. }
  8042. #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
  8043. -#ifdef LDBL_IMPLICIT_NBIT
  8044. -#define MANH_SIZE (LDBL_MANH_SIZE + 1)
  8045. -#else
  8046. -#define MANH_SIZE LDBL_MANH_SIZE
  8047. +#if LDBL_MANT_DIG == 64
  8048. +#define TOINT 0x1p63
  8049. +#elif LDBL_MANT_DIG == 113
  8050. +#define TOINT 0x1p112
  8051. #endif
  8052. -
  8053. -static const long double huge = 1.0e300;
  8054. -static const float zero[] = { 0.0, -0.0 };
  8055. -
  8056. long double truncl(long double x)
  8057. {
  8058. - union IEEEl2bits u = { .e = x };
  8059. - int e = u.bits.exp - LDBL_MAX_EXP + 1;
  8060. + union ldshape u = {x};
  8061. + int e = u.i.se & 0x7fff;
  8062. + int s = u.i.se >> 15;
  8063. + long double y;
  8064. - if (e < MANH_SIZE - 1) {
  8065. - if (e < 0) {
  8066. - /* raise inexact if x != 0 */
  8067. - if (huge + x > 0.0)
  8068. - u.e = zero[u.bits.sign];
  8069. - } else {
  8070. - uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
  8071. - if (((u.bits.manh & m) | u.bits.manl) == 0)
  8072. - return x; /* x is integral */
  8073. - /* raise inexact */
  8074. - if (huge + x > 0.0) {
  8075. - u.bits.manh &= ~m;
  8076. - u.bits.manl = 0;
  8077. - }
  8078. - }
  8079. - } else if (e < LDBL_MANT_DIG - 1) {
  8080. - uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
  8081. - if ((u.bits.manl & m) == 0)
  8082. - return x; /* x is integral */
  8083. - /* raise inexact */
  8084. - if (huge + x > 0.0)
  8085. - u.bits.manl &= ~m;
  8086. + if (e >= 0x3fff+LDBL_MANT_DIG-1)
  8087. + return x;
  8088. + if (e <= 0x3fff-1) {
  8089. + FORCE_EVAL(x + 0x1p120f);
  8090. + return x*0;
  8091. }
  8092. - return u.e;
  8093. + /* y = int(|x|) - |x|, where int(|x|) is an integer neighbor of |x| */
  8094. + if (s)
  8095. + x = -x;
  8096. + y = x + TOINT - TOINT - x;
  8097. + if (y > 0)
  8098. + y -= 1;
  8099. + x += y;
  8100. + return s ? -x : x;
  8101. }
  8102. #endif
  8103. diff -Nur musl-0.9.13/src/math/x86_64/ceill.s musl-git/src/math/x86_64/ceill.s
  8104. --- musl-0.9.13/src/math/x86_64/ceill.s 2013-08-30 23:30:53.000000000 +0200
  8105. +++ musl-git/src/math/x86_64/ceill.s 2013-09-16 20:31:39.000000000 +0200
  8106. @@ -1 +1 @@
  8107. -# see floor.s
  8108. +# see floorl.s
  8109. diff -Nur musl-0.9.13/src/math/x86_64/exp2l.s musl-git/src/math/x86_64/exp2l.s
  8110. --- musl-0.9.13/src/math/x86_64/exp2l.s 2013-08-30 23:30:53.000000000 +0200
  8111. +++ musl-git/src/math/x86_64/exp2l.s 2013-09-16 20:31:39.000000000 +0200
  8112. @@ -4,8 +4,18 @@
  8113. fldt 8(%rsp)
  8114. fldl2e
  8115. fmulp
  8116. + movl $0xc2820000,-4(%rsp)
  8117. + flds -4(%rsp)
  8118. + fucomp %st(1)
  8119. + fnstsw %ax
  8120. + sahf
  8121. fld1
  8122. - fld %st(1)
  8123. + jb 1f
  8124. + # x*log2e <= -65, return -1 without underflow
  8125. + fstp %st(1)
  8126. + fchs
  8127. + ret
  8128. +1: fld %st(1)
  8129. fabs
  8130. fucom %st(1)
  8131. fnstsw %ax
  8132. @@ -26,44 +36,32 @@
  8133. .type exp2l,@function
  8134. exp2l:
  8135. fldt 8(%rsp)
  8136. -1: mov $0x467ff000,%eax
  8137. - mov %eax,-16(%rsp)
  8138. - mov $0x80000000,%eax
  8139. - mov %eax,-20(%rsp)
  8140. - xor %eax,%eax
  8141. - mov %eax,-24(%rsp)
  8142. - flds -16(%rsp) # 16380
  8143. +1: fld %st(0)
  8144. + sub $16,%rsp
  8145. + fstpt (%rsp)
  8146. + mov 8(%rsp),%ax
  8147. + and $0x7fff,%ax
  8148. + cmp $0x3fff+13,%ax
  8149. + jb 4f # |x| < 8192
  8150. + cmp $0x3fff+15,%ax
  8151. + jae 3f # |x| >= 32768
  8152. + fsts (%rsp)
  8153. + cmpl $0xc67ff800,(%rsp)
  8154. + jb 2f # x > -16382
  8155. + movl $0x5f000000,(%rsp)
  8156. + flds (%rsp) # 0x1p63
  8157. fld %st(1)
  8158. - fabs
  8159. - fucom %st(1)
  8160. + fsub %st(1)
  8161. + faddp
  8162. + fucomp %st(1)
  8163. fnstsw
  8164. - fstp %st(0)
  8165. - fstp %st(0)
  8166. sahf
  8167. - ja 3f # |x| > 16380
  8168. - jp 2f # x is nan (avoid invalid except in fistp)
  8169. - fld %st(0)
  8170. - fistpl -16(%rsp)
  8171. - fildl -16(%rsp)
  8172. - fxch %st(1)
  8173. - fsub %st(1)
  8174. - mov $0x3fff,%eax
  8175. - add %eax,-16(%rsp)
  8176. - f2xm1
  8177. - fld1
  8178. - faddp # 2^(x-rint(x))
  8179. - fldt -24(%rsp) # 2^rint(x)
  8180. - fmulp
  8181. -2: fstp %st(1)
  8182. - ret
  8183. -
  8184. -3: fld %st(0)
  8185. - fstpt -24(%rsp)
  8186. - fld1
  8187. - mov -15(%rsp),%ax
  8188. - and $0x7fff,%ax
  8189. - cmp $0x7fff,%ax
  8190. - je 1f # x = +-inf
  8191. + je 2f # x - 0x1p63 + 0x1p63 == x
  8192. + movl $1,(%rsp)
  8193. + flds (%rsp) # 0x1p-149
  8194. + fdiv %st(1)
  8195. + fstps (%rsp) # raise underflow
  8196. +2: fld1
  8197. fld %st(1)
  8198. frndint
  8199. fxch %st(2)
  8200. @@ -72,4 +70,21 @@
  8201. faddp # 2^(x-rint(x))
  8202. 1: fscale
  8203. fstp %st(1)
  8204. + add $16,%rsp
  8205. + ret
  8206. +3: xor %eax,%eax
  8207. +4: cmp $0x3fff-64,%ax
  8208. + fld1
  8209. + jb 1b # |x| < 0x1p-64
  8210. + fstpt (%rsp)
  8211. + fistl 8(%rsp)
  8212. + fildl 8(%rsp)
  8213. + fsubrp %st(1)
  8214. + addl $0x3fff,8(%rsp)
  8215. + f2xm1
  8216. + fld1
  8217. + faddp # 2^(x-rint(x))
  8218. + fldt (%rsp) # 2^rint(x)
  8219. + fmulp
  8220. + add $16,%rsp
  8221. ret
  8222. diff -Nur musl-0.9.13/src/math/x86_64/lrintl.s musl-git/src/math/x86_64/lrintl.s
  8223. --- musl-0.9.13/src/math/x86_64/lrintl.s 2013-08-30 23:30:53.000000000 +0200
  8224. +++ musl-git/src/math/x86_64/lrintl.s 2013-09-16 20:31:39.000000000 +0200
  8225. @@ -2,6 +2,6 @@
  8226. .type lrintl,@function
  8227. lrintl:
  8228. fldt 8(%rsp)
  8229. - fistpl 8(%rsp)
  8230. - mov 8(%rsp),%eax
  8231. + fistpll 8(%rsp)
  8232. + mov 8(%rsp),%rax
  8233. ret
  8234. diff -Nur musl-0.9.13/src/math/x86_64/truncl.s musl-git/src/math/x86_64/truncl.s
  8235. --- musl-0.9.13/src/math/x86_64/truncl.s 2013-08-30 23:30:53.000000000 +0200
  8236. +++ musl-git/src/math/x86_64/truncl.s 2013-09-16 20:31:39.000000000 +0200
  8237. @@ -1 +1 @@
  8238. -# see floor.s
  8239. +# see floorl.s
  8240. diff -Nur musl-0.9.13/src/misc/realpath.c musl-git/src/misc/realpath.c
  8241. --- musl-0.9.13/src/misc/realpath.c 2013-08-30 23:30:53.000000000 +0200
  8242. +++ musl-git/src/misc/realpath.c 2013-09-16 20:31:39.000000000 +0200
  8243. @@ -1,10 +1,11 @@
  8244. #include <stdlib.h>
  8245. -#include <stdio.h>
  8246. #include <limits.h>
  8247. #include <sys/stat.h>
  8248. #include <fcntl.h>
  8249. #include <errno.h>
  8250. #include <unistd.h>
  8251. +#include <string.h>
  8252. +#include "syscall.h"
  8253. void __procfdname(char *, unsigned);
  8254. @@ -14,38 +15,31 @@
  8255. ssize_t r;
  8256. struct stat st1, st2;
  8257. char buf[15+3*sizeof(int)];
  8258. - int alloc = 0;
  8259. + char tmp[PATH_MAX];
  8260. if (!filename) {
  8261. errno = EINVAL;
  8262. return 0;
  8263. }
  8264. - fd = open(filename, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
  8265. + fd = syscall(SYS_open, filename, O_PATH|O_NONBLOCK|O_CLOEXEC|O_LARGEFILE);
  8266. if (fd < 0) return 0;
  8267. __procfdname(buf, fd);
  8268. - if (!resolved) {
  8269. - alloc = 1;
  8270. - resolved = malloc(PATH_MAX);
  8271. - if (!resolved) return 0;
  8272. - }
  8273. -
  8274. - r = readlink(buf, resolved, PATH_MAX-1);
  8275. + r = readlink(buf, tmp, sizeof tmp - 1);
  8276. if (r < 0) goto err;
  8277. - resolved[r] = 0;
  8278. + tmp[r] = 0;
  8279. fstat(fd, &st1);
  8280. - r = stat(resolved, &st2);
  8281. + r = stat(tmp, &st2);
  8282. if (r<0 || st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) {
  8283. if (!r) errno = ELOOP;
  8284. goto err;
  8285. }
  8286. - close(fd);
  8287. - return resolved;
  8288. + __syscall(SYS_close, fd);
  8289. + return resolved ? strcpy(resolved, tmp) : strdup(tmp);
  8290. err:
  8291. - if (alloc) free(resolved);
  8292. - close(fd);
  8293. + __syscall(SYS_close, fd);
  8294. return 0;
  8295. }
  8296. diff -Nur musl-0.9.13/src/mman/mprotect.c musl-git/src/mman/mprotect.c
  8297. --- musl-0.9.13/src/mman/mprotect.c 2013-08-30 23:30:53.000000000 +0200
  8298. +++ musl-git/src/mman/mprotect.c 2013-09-16 20:31:39.000000000 +0200
  8299. @@ -1,5 +1,5 @@
  8300. #include <sys/mman.h>
  8301. -#include <limits.h>
  8302. +#include "libc.h"
  8303. #include "syscall.h"
  8304. int mprotect(void *addr, size_t len, int prot)
  8305. diff -Nur musl-0.9.13/src/signal/sigemptyset.c musl-git/src/signal/sigemptyset.c
  8306. --- musl-0.9.13/src/signal/sigemptyset.c 2013-08-30 23:30:53.000000000 +0200
  8307. +++ musl-git/src/signal/sigemptyset.c 2013-09-16 20:31:39.000000000 +0200
  8308. @@ -4,6 +4,10 @@
  8309. int sigemptyset(sigset_t *set)
  8310. {
  8311. set->__bits[0] = 0;
  8312. - if (sizeof(long)==4) set->__bits[1] = 0;
  8313. + if (sizeof(long)==4 || _NSIG > 65) set->__bits[1] = 0;
  8314. + if (sizeof(long)==4 && _NSIG > 65) {
  8315. + set->__bits[2] = 0;
  8316. + set->__bits[3] = 0;
  8317. + }
  8318. return 0;
  8319. }
  8320. diff -Nur musl-0.9.13/src/signal/sigfillset.c musl-git/src/signal/sigfillset.c
  8321. --- musl-0.9.13/src/signal/sigfillset.c 2013-08-30 23:30:53.000000000 +0200
  8322. +++ musl-git/src/signal/sigfillset.c 2013-09-16 20:31:39.000000000 +0200
  8323. @@ -7,8 +7,13 @@
  8324. #if ULONG_MAX == 0xffffffff
  8325. set->__bits[0] = 0x7ffffffful;
  8326. set->__bits[1] = 0xfffffffcul;
  8327. + if (_NSIG > 65) {
  8328. + set->__bits[2] = 0xfffffffful;
  8329. + set->__bits[3] = 0xfffffffful;
  8330. + }
  8331. #else
  8332. set->__bits[0] = 0xfffffffc7ffffffful;
  8333. + if (_NSIG > 65) set->__bits[1] = 0xfffffffffffffffful;
  8334. #endif
  8335. return 0;
  8336. }
  8337. diff -Nur musl-0.9.13/src/signal/sigqueue.c musl-git/src/signal/sigqueue.c
  8338. --- musl-0.9.13/src/signal/sigqueue.c 2013-08-30 23:30:53.000000000 +0200
  8339. +++ musl-git/src/signal/sigqueue.c 2013-09-16 20:31:39.000000000 +0200
  8340. @@ -3,6 +3,7 @@
  8341. #include <unistd.h>
  8342. #include <stdint.h>
  8343. #include "syscall.h"
  8344. +#include "pthread_impl.h"
  8345. int sigqueue(pid_t pid, int sig, const union sigval value)
  8346. {
  8347. @@ -14,9 +15,9 @@
  8348. si.si_code = SI_QUEUE;
  8349. si.si_value = value;
  8350. si.si_uid = getuid();
  8351. - pthread_sigmask(SIG_BLOCK, (void *)(uint64_t[1]){-1}, &set);
  8352. + __block_app_sigs(&set);
  8353. si.si_pid = getpid();
  8354. r = syscall(SYS_rt_sigqueueinfo, pid, sig, &si);
  8355. - pthread_sigmask(SIG_SETMASK, &set, 0);
  8356. + __restore_sigs(&set);
  8357. return r;
  8358. }
  8359. diff -Nur musl-0.9.13/src/stdio/popen.c musl-git/src/stdio/popen.c
  8360. --- musl-0.9.13/src/stdio/popen.c 2013-08-30 23:30:53.000000000 +0200
  8361. +++ musl-git/src/stdio/popen.c 2013-09-16 20:31:39.000000000 +0200
  8362. @@ -39,7 +39,7 @@
  8363. * remove the close-on-exec flag in the child without also creating
  8364. * a file descriptor leak race condition in the parent. */
  8365. if (p[1-op] == 1-op) {
  8366. - int tmp = fcntl(F_DUPFD_CLOEXEC, 1-op, 0);
  8367. + int tmp = fcntl(1-op, F_DUPFD_CLOEXEC, 0);
  8368. if (tmp < 0) {
  8369. e = errno;
  8370. goto fail;
  8371. diff -Nur musl-0.9.13/src/stdio/vfscanf.c musl-git/src/stdio/vfscanf.c
  8372. --- musl-0.9.13/src/stdio/vfscanf.c 2013-08-30 23:30:53.000000000 +0200
  8373. +++ musl-git/src/stdio/vfscanf.c 2013-09-16 20:31:39.000000000 +0200
  8374. @@ -118,6 +118,8 @@
  8375. }
  8376. if (*p=='m') {
  8377. + wcs = 0;
  8378. + s = 0;
  8379. alloc = !!dest;
  8380. p++;
  8381. } else {
  8382. diff -Nur musl-0.9.13/src/stdio/vfwscanf.c musl-git/src/stdio/vfwscanf.c
  8383. --- musl-0.9.13/src/stdio/vfwscanf.c 2013-08-30 23:30:53.000000000 +0200
  8384. +++ musl-git/src/stdio/vfwscanf.c 2013-09-16 20:31:39.000000000 +0200
  8385. @@ -143,6 +143,8 @@
  8386. }
  8387. if (*p=='m') {
  8388. + wcs = 0;
  8389. + s = 0;
  8390. alloc = !!dest;
  8391. p++;
  8392. } else {
  8393. diff -Nur musl-0.9.13/src/temp/__randname.c musl-git/src/temp/__randname.c
  8394. --- musl-0.9.13/src/temp/__randname.c 2013-08-30 23:30:53.000000000 +0200
  8395. +++ musl-git/src/temp/__randname.c 2013-09-16 20:31:39.000000000 +0200
  8396. @@ -5,7 +5,7 @@
  8397. int __clock_gettime(clockid_t, struct timespec *);
  8398. /* This assumes that a check for the
  8399. - template size has alrady been made */
  8400. + template size has already been made */
  8401. char *__randname(char *template)
  8402. {
  8403. int i;
  8404. diff -Nur musl-0.9.13/src/thread/mips/clone.s musl-git/src/thread/mips/clone.s
  8405. --- musl-0.9.13/src/thread/mips/clone.s 2013-08-30 23:30:53.000000000 +0200
  8406. +++ musl-git/src/thread/mips/clone.s 2013-09-16 20:31:39.000000000 +0200
  8407. @@ -3,6 +3,7 @@
  8408. .type __clone,@function
  8409. __clone:
  8410. # Save function pointer and argument pointer on new thread stack
  8411. + and $5, $5, -8
  8412. subu $5, $5, 16
  8413. sw $4, 0($5)
  8414. sw $7, 4($5)
  8415. @@ -11,15 +12,18 @@
  8416. lw $6, 16($sp)
  8417. lw $7, 20($sp)
  8418. lw $9, 24($sp)
  8419. + subu $sp, $sp, 16
  8420. sw $9, 16($sp)
  8421. li $2, 4120
  8422. syscall
  8423. beq $7, $0, 1f
  8424. nop
  8425. + addu $sp, $sp, 16
  8426. jr $ra
  8427. subu $2, $0, $2
  8428. 1: beq $2, $0, 1f
  8429. nop
  8430. + addu $sp, $sp, 16
  8431. jr $ra
  8432. nop
  8433. 1: lw $25, 0($sp)
  8434. diff -Nur musl-0.9.13/src/thread/pthread_create.c musl-git/src/thread/pthread_create.c
  8435. --- musl-0.9.13/src/thread/pthread_create.c 2013-08-30 23:30:53.000000000 +0200
  8436. +++ musl-git/src/thread/pthread_create.c 2013-09-16 20:31:39.000000000 +0200
  8437. @@ -1,5 +1,7 @@
  8438. +#define _GNU_SOURCE
  8439. #include "pthread_impl.h"
  8440. #include "stdio_impl.h"
  8441. +#include "libc.h"
  8442. #include <sys/mman.h>
  8443. static void dummy_0()
  8444. @@ -127,7 +129,9 @@
  8445. size_t size, guard;
  8446. struct pthread *self = pthread_self(), *new;
  8447. unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit;
  8448. - unsigned flags = 0x7d8f00;
  8449. + unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND
  8450. + | CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS
  8451. + | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED;
  8452. int do_sched = 0;
  8453. pthread_attr_t attr = {0};
  8454. @@ -197,7 +201,7 @@
  8455. new->tsd = (void *)tsd;
  8456. if (attr._a_detach) {
  8457. new->detached = 1;
  8458. - flags -= 0x200000;
  8459. + flags -= CLONE_CHILD_CLEARTID;
  8460. }
  8461. if (attr._a_sched) {
  8462. do_sched = new->startlock[0] = 1;
  8463. diff -Nur musl-0.9.13/src/thread/pthread_getattr_np.c musl-git/src/thread/pthread_getattr_np.c
  8464. --- musl-0.9.13/src/thread/pthread_getattr_np.c 2013-08-30 23:30:53.000000000 +0200
  8465. +++ musl-git/src/thread/pthread_getattr_np.c 2013-09-16 20:31:39.000000000 +0200
  8466. @@ -1,5 +1,6 @@
  8467. #define _GNU_SOURCE
  8468. #include "pthread_impl.h"
  8469. +#include "libc.h"
  8470. #include <sys/mman.h>
  8471. int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
  8472. diff -Nur musl-0.9.13/src/thread/synccall.c musl-git/src/thread/synccall.c
  8473. --- musl-0.9.13/src/thread/synccall.c 2013-08-30 23:30:53.000000000 +0200
  8474. +++ musl-git/src/thread/synccall.c 2013-09-16 20:31:39.000000000 +0200
  8475. @@ -43,7 +43,7 @@
  8476. pthread_t self;
  8477. struct sigaction sa;
  8478. struct chain *next;
  8479. - uint64_t oldmask;
  8480. + sigset_t oldmask;
  8481. if (!libc.threads_minus_1) {
  8482. func(ctx);
  8483. @@ -52,12 +52,12 @@
  8484. __inhibit_ptc();
  8485. - __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGALL_SET,
  8486. - &oldmask, _NSIG/8);
  8487. + __block_all_sigs(&oldmask);
  8488. sem_init(&chaindone, 0, 0);
  8489. sem_init(&chainlock, 0, 1);
  8490. chainlen = 0;
  8491. + head = 0;
  8492. callback = func;
  8493. context = ctx;
  8494. @@ -70,6 +70,10 @@
  8495. sigqueue(self->pid, SIGSYNCCALL, (union sigval){0});
  8496. while (sem_wait(&chaindone));
  8497. + sa.sa_flags = 0;
  8498. + sa.sa_handler = SIG_IGN;
  8499. + __libc_sigaction(SIGSYNCCALL, &sa, 0);
  8500. +
  8501. for (cur=head; cur; cur=cur->next) {
  8502. sem_post(&cur->sem);
  8503. while (sem_wait(&cur->sem2));
  8504. @@ -81,12 +85,7 @@
  8505. sem_post(&cur->sem);
  8506. }
  8507. - sa.sa_flags = 0;
  8508. - sa.sa_handler = SIG_IGN;
  8509. - __libc_sigaction(SIGSYNCCALL, &sa, 0);
  8510. -
  8511. - __syscall(SYS_rt_sigprocmask, SIG_SETMASK,
  8512. - &oldmask, 0, _NSIG/8);
  8513. + __restore_sigs(&oldmask);
  8514. __release_ptc();
  8515. }
  8516. diff -Nur musl-0.9.13/src/unistd/faccessat.c musl-git/src/unistd/faccessat.c
  8517. --- musl-0.9.13/src/unistd/faccessat.c 2013-08-30 23:30:53.000000000 +0200
  8518. +++ musl-git/src/unistd/faccessat.c 2013-09-16 20:31:39.000000000 +0200
  8519. @@ -19,7 +19,7 @@
  8520. __syscall(SYS_exit, 1);
  8521. ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
  8522. __syscall(SYS_write, c->p, &ret, sizeof ret);
  8523. - __syscall(SYS_exit, 0);
  8524. + return 0;
  8525. }
  8526. int faccessat(int fd, const char *filename, int amode, int flag)