900-nios2.patch 275 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211
  1. --- gcc-3.4.3/gcc/Makefile.in
  2. +++ gcc-3.4.3-nios2/gcc/Makefile.in
  3. @@ -3085,7 +3085,7 @@ install-mkheaders: stmp-int-hdrs $(STMP_
  4. $(INSTALL_DATA) $(srcdir)/README-fixinc \
  5. $(DESTDIR)$(itoolsdatadir)/include/README ; \
  6. $(INSTALL_SCRIPT) fixinc.sh $(DESTDIR)$(itoolsdir)/fixinc.sh ; \
  7. - $(INSTALL_PROGRAM) fixinc/fixincl $(DESTDIR)$(itoolsdir)/fixincl ; \
  8. + $(INSTALL_PROGRAM) fixinc/fixincl$(build_exeext) $(DESTDIR)$(itoolsdir)/fixincl$(build_exeext) ; \
  9. $(INSTALL_DATA) $(srcdir)/gsyslimits.h \
  10. $(DESTDIR)$(itoolsdatadir)/gsyslimits.h ; \
  11. else :; fi
  12. --- gcc-3.4.3/gcc/combine.c
  13. +++ gcc-3.4.3-nios2/gcc/combine.c
  14. @@ -4380,6 +4380,14 @@ combine_simplify_rtx (rtx x, enum machin
  15. mode);
  16. }
  17. +#ifndef __nios2__
  18. +/* This screws up Nios II in this test case:
  19. +
  20. +if (x & 1)
  21. + return 2;
  22. +else
  23. + return 3;
  24. +*/
  25. else if (STORE_FLAG_VALUE == 1
  26. && new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT
  27. && op1 == const0_rtx
  28. @@ -4391,6 +4399,7 @@ combine_simplify_rtx (rtx x, enum machin
  29. gen_lowpart_for_combine (mode, op0),
  30. const1_rtx);
  31. }
  32. +#endif
  33. else if (STORE_FLAG_VALUE == 1
  34. && new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT
  35. --- gcc-3.4.3/gcc/config/nios2/crti.asm
  36. +++ gcc-3.4.3-nios2/gcc/config/nios2/crti.asm
  37. @@ -0,0 +1,88 @@
  38. +/*
  39. + Copyright (C) 2003
  40. + by Jonah Graham (jgraham@altera.com)
  41. +
  42. +This file is free software; you can redistribute it and/or modify it
  43. +under the terms of the GNU General Public License as published by the
  44. +Free Software Foundation; either version 2, or (at your option) any
  45. +later version.
  46. +
  47. +In addition to the permissions in the GNU General Public License, the
  48. +Free Software Foundation gives you unlimited permission to link the
  49. +compiled version of this file with other programs, and to distribute
  50. +those programs without any restriction coming from the use of this
  51. +file. (The General Public License restrictions do apply in other
  52. +respects; for example, they cover modification of the file, and
  53. +distribution when not linked into another program.)
  54. +
  55. +This file is distributed in the hope that it will be useful, but
  56. +WITHOUT ANY WARRANTY; without even the implied warranty of
  57. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  58. +General Public License for more details.
  59. +
  60. +You should have received a copy of the GNU General Public License
  61. +along with this program; see the file COPYING. If not, write to
  62. +the Free Software Foundation, 59 Temple Place - Suite 330,
  63. +Boston, MA 02111-1307, USA.
  64. +
  65. + As a special exception, if you link this library with files
  66. + compiled with GCC to produce an executable, this does not cause
  67. + the resulting executable to be covered by the GNU General Public License.
  68. + This exception does not however invalidate any other reasons why
  69. + the executable file might be covered by the GNU General Public License.
  70. +
  71. +
  72. +This file just make a stack frame for the contents of the .fini and
  73. +.init sections. Users may put any desired instructions in those
  74. +sections.
  75. +
  76. +
  77. +While technically any code can be put in the init and fini sections
  78. +most stuff will not work other than stuff which obeys the call frame
  79. +and ABI. All the call-preserved registers are saved, the call clobbered
  80. +registers should have been saved by the code calling init and fini.
  81. +
  82. +See crtstuff.c for an example of code that inserts itself in the
  83. +init and fini sections.
  84. +
  85. +See crt0.s for the code that calls init and fini.
  86. +*/
  87. +
  88. + .file "crti.asm"
  89. +
  90. + .section ".init"
  91. + .align 2
  92. + .global _init
  93. +_init:
  94. + addi sp, sp, -48
  95. + stw ra, 44(sp)
  96. + stw r23, 40(sp)
  97. + stw r22, 36(sp)
  98. + stw r21, 32(sp)
  99. + stw r20, 28(sp)
  100. + stw r19, 24(sp)
  101. + stw r18, 20(sp)
  102. + stw r17, 16(sp)
  103. + stw r16, 12(sp)
  104. + stw fp, 8(sp)
  105. + mov fp, sp
  106. +
  107. +
  108. + .section ".fini"
  109. + .align 2
  110. + .global _fini
  111. +_fini:
  112. + addi sp, sp, -48
  113. + stw ra, 44(sp)
  114. + stw r23, 40(sp)
  115. + stw r22, 36(sp)
  116. + stw r21, 32(sp)
  117. + stw r20, 28(sp)
  118. + stw r19, 24(sp)
  119. + stw r18, 20(sp)
  120. + stw r17, 16(sp)
  121. + stw r16, 12(sp)
  122. + stw fp, 8(sp)
  123. + mov fp, sp
  124. +
  125. +
  126. --- gcc-3.4.3/gcc/config/nios2/crtn.asm
  127. +++ gcc-3.4.3-nios2/gcc/config/nios2/crtn.asm
  128. @@ -0,0 +1,70 @@
  129. +/*
  130. + Copyright (C) 2003
  131. + by Jonah Graham (jgraham@altera.com)
  132. +
  133. +This file is free software; you can redistribute it and/or modify it
  134. +under the terms of the GNU General Public License as published by the
  135. +Free Software Foundation; either version 2, or (at your option) any
  136. +later version.
  137. +
  138. +In addition to the permissions in the GNU General Public License, the
  139. +Free Software Foundation gives you unlimited permission to link the
  140. +compiled version of this file with other programs, and to distribute
  141. +those programs without any restriction coming from the use of this
  142. +file. (The General Public License restrictions do apply in other
  143. +respects; for example, they cover modification of the file, and
  144. +distribution when not linked into another program.)
  145. +
  146. +This file is distributed in the hope that it will be useful, but
  147. +WITHOUT ANY WARRANTY; without even the implied warranty of
  148. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  149. +General Public License for more details.
  150. +
  151. +You should have received a copy of the GNU General Public License
  152. +along with this program; see the file COPYING. If not, write to
  153. +the Free Software Foundation, 59 Temple Place - Suite 330,
  154. +Boston, MA 02111-1307, USA.
  155. +
  156. + As a special exception, if you link this library with files
  157. + compiled with GCC to produce an executable, this does not cause
  158. + the resulting executable to be covered by the GNU General Public License.
  159. + This exception does not however invalidate any other reasons why
  160. + the executable file might be covered by the GNU General Public License.
  161. +
  162. +
  163. +This file just makes sure that the .fini and .init sections do in
  164. +fact return. Users may put any desired instructions in those sections.
  165. +This file is the last thing linked into any executable.
  166. +*/
  167. + .file "crtn.asm"
  168. +
  169. +
  170. +
  171. + .section ".init"
  172. + ldw ra, 44(sp)
  173. + ldw r23, 40(sp)
  174. + ldw r22, 36(sp)
  175. + ldw r21, 32(sp)
  176. + ldw r20, 28(sp)
  177. + ldw r19, 24(sp)
  178. + ldw r18, 20(sp)
  179. + ldw r17, 16(sp)
  180. + ldw r16, 12(sp)
  181. + ldw fp, 8(sp)
  182. + addi sp, sp, -48
  183. + ret
  184. +
  185. + .section ".fini"
  186. + ldw ra, 44(sp)
  187. + ldw r23, 40(sp)
  188. + ldw r22, 36(sp)
  189. + ldw r21, 32(sp)
  190. + ldw r20, 28(sp)
  191. + ldw r19, 24(sp)
  192. + ldw r18, 20(sp)
  193. + ldw r17, 16(sp)
  194. + ldw r16, 12(sp)
  195. + ldw fp, 8(sp)
  196. + addi sp, sp, -48
  197. + ret
  198. +
  199. --- gcc-3.4.3/gcc/config/nios2/lib2-divmod-hi.c
  200. +++ gcc-3.4.3-nios2/gcc/config/nios2/lib2-divmod-hi.c
  201. @@ -0,0 +1,123 @@
  202. +
  203. +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
  204. + supposedly valid even though this is a "target" file. */
  205. +#include "auto-host.h"
  206. +
  207. +
  208. +#include "tconfig.h"
  209. +#include "tsystem.h"
  210. +#include "coretypes.h"
  211. +#include "tm.h"
  212. +
  213. +
  214. +/* Don't use `fancy_abort' here even if config.h says to use it. */
  215. +#ifdef abort
  216. +#undef abort
  217. +#endif
  218. +
  219. +
  220. +#ifdef HAVE_GAS_HIDDEN
  221. +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
  222. +#else
  223. +#define ATTRIBUTE_HIDDEN
  224. +#endif
  225. +
  226. +#include "libgcc2.h"
  227. +
  228. +extern HItype __modhi3 (HItype, HItype);
  229. +extern HItype __divhi3 (HItype, HItype);
  230. +extern HItype __umodhi3 (HItype, HItype);
  231. +extern HItype __udivhi3 (HItype, HItype);
  232. +
  233. +static UHItype udivmodhi4(UHItype, UHItype, word_type);
  234. +
  235. +static UHItype
  236. +udivmodhi4(UHItype num, UHItype den, word_type modwanted)
  237. +{
  238. + UHItype bit = 1;
  239. + UHItype res = 0;
  240. +
  241. + while (den < num && bit && !(den & (1L<<15)))
  242. + {
  243. + den <<=1;
  244. + bit <<=1;
  245. + }
  246. + while (bit)
  247. + {
  248. + if (num >= den)
  249. + {
  250. + num -= den;
  251. + res |= bit;
  252. + }
  253. + bit >>=1;
  254. + den >>=1;
  255. + }
  256. + if (modwanted) return num;
  257. + return res;
  258. +}
  259. +
  260. +
  261. +HItype
  262. +__divhi3 (HItype a, HItype b)
  263. +{
  264. + word_type neg = 0;
  265. + HItype res;
  266. +
  267. + if (a < 0)
  268. + {
  269. + a = -a;
  270. + neg = !neg;
  271. + }
  272. +
  273. + if (b < 0)
  274. + {
  275. + b = -b;
  276. + neg = !neg;
  277. + }
  278. +
  279. + res = udivmodhi4 (a, b, 0);
  280. +
  281. + if (neg)
  282. + res = -res;
  283. +
  284. + return res;
  285. +}
  286. +
  287. +
  288. +HItype
  289. +__modhi3 (HItype a, HItype b)
  290. +{
  291. + word_type neg = 0;
  292. + HItype res;
  293. +
  294. + if (a < 0)
  295. + {
  296. + a = -a;
  297. + neg = 1;
  298. + }
  299. +
  300. + if (b < 0)
  301. + b = -b;
  302. +
  303. + res = udivmodhi4 (a, b, 1);
  304. +
  305. + if (neg)
  306. + res = -res;
  307. +
  308. + return res;
  309. +}
  310. +
  311. +
  312. +HItype
  313. +__udivhi3 (HItype a, HItype b)
  314. +{
  315. + return udivmodhi4 (a, b, 0);
  316. +}
  317. +
  318. +
  319. +HItype
  320. +__umodhi3 (HItype a, HItype b)
  321. +{
  322. + return udivmodhi4 (a, b, 1);
  323. +}
  324. +
  325. --- gcc-3.4.3/gcc/config/nios2/lib2-divmod.c
  326. +++ gcc-3.4.3-nios2/gcc/config/nios2/lib2-divmod.c
  327. @@ -0,0 +1,126 @@
  328. +
  329. +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
  330. + supposedly valid even though this is a "target" file. */
  331. +#include "auto-host.h"
  332. +
  333. +
  334. +#include "tconfig.h"
  335. +#include "tsystem.h"
  336. +#include "coretypes.h"
  337. +#include "tm.h"
  338. +
  339. +
  340. +/* Don't use `fancy_abort' here even if config.h says to use it. */
  341. +#ifdef abort
  342. +#undef abort
  343. +#endif
  344. +
  345. +
  346. +#ifdef HAVE_GAS_HIDDEN
  347. +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
  348. +#else
  349. +#define ATTRIBUTE_HIDDEN
  350. +#endif
  351. +
  352. +#include "libgcc2.h"
  353. +
  354. +extern SItype __modsi3 (SItype, SItype);
  355. +extern SItype __divsi3 (SItype, SItype);
  356. +extern SItype __umodsi3 (SItype, SItype);
  357. +extern SItype __udivsi3 (SItype, SItype);
  358. +
  359. +static USItype udivmodsi4(USItype, USItype, word_type);
  360. +
  361. +/* 16-bit SI divide and modulo as used in NIOS */
  362. +
  363. +
  364. +static USItype
  365. +udivmodsi4(USItype num, USItype den, word_type modwanted)
  366. +{
  367. + USItype bit = 1;
  368. + USItype res = 0;
  369. +
  370. + while (den < num && bit && !(den & (1L<<31)))
  371. + {
  372. + den <<=1;
  373. + bit <<=1;
  374. + }
  375. + while (bit)
  376. + {
  377. + if (num >= den)
  378. + {
  379. + num -= den;
  380. + res |= bit;
  381. + }
  382. + bit >>=1;
  383. + den >>=1;
  384. + }
  385. + if (modwanted) return num;
  386. + return res;
  387. +}
  388. +
  389. +
  390. +SItype
  391. +__divsi3 (SItype a, SItype b)
  392. +{
  393. + word_type neg = 0;
  394. + SItype res;
  395. +
  396. + if (a < 0)
  397. + {
  398. + a = -a;
  399. + neg = !neg;
  400. + }
  401. +
  402. + if (b < 0)
  403. + {
  404. + b = -b;
  405. + neg = !neg;
  406. + }
  407. +
  408. + res = udivmodsi4 (a, b, 0);
  409. +
  410. + if (neg)
  411. + res = -res;
  412. +
  413. + return res;
  414. +}
  415. +
  416. +
  417. +SItype
  418. +__modsi3 (SItype a, SItype b)
  419. +{
  420. + word_type neg = 0;
  421. + SItype res;
  422. +
  423. + if (a < 0)
  424. + {
  425. + a = -a;
  426. + neg = 1;
  427. + }
  428. +
  429. + if (b < 0)
  430. + b = -b;
  431. +
  432. + res = udivmodsi4 (a, b, 1);
  433. +
  434. + if (neg)
  435. + res = -res;
  436. +
  437. + return res;
  438. +}
  439. +
  440. +
  441. +SItype
  442. +__udivsi3 (SItype a, SItype b)
  443. +{
  444. + return udivmodsi4 (a, b, 0);
  445. +}
  446. +
  447. +
  448. +SItype
  449. +__umodsi3 (SItype a, SItype b)
  450. +{
  451. + return udivmodsi4 (a, b, 1);
  452. +}
  453. +
  454. --- gcc-3.4.3/gcc/config/nios2/lib2-divtable.c
  455. +++ gcc-3.4.3-nios2/gcc/config/nios2/lib2-divtable.c
  456. @@ -0,0 +1,46 @@
  457. +
  458. +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
  459. + supposedly valid even though this is a "target" file. */
  460. +#include "auto-host.h"
  461. +
  462. +
  463. +#include "tconfig.h"
  464. +#include "tsystem.h"
  465. +#include "coretypes.h"
  466. +#include "tm.h"
  467. +
  468. +
  469. +/* Don't use `fancy_abort' here even if config.h says to use it. */
  470. +#ifdef abort
  471. +#undef abort
  472. +#endif
  473. +
  474. +
  475. +#ifdef HAVE_GAS_HIDDEN
  476. +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
  477. +#else
  478. +#define ATTRIBUTE_HIDDEN
  479. +#endif
  480. +
  481. +#include "libgcc2.h"
  482. +
  483. +UQItype __divsi3_table[] =
  484. +{
  485. + 0, 0/1, 0/2, 0/3, 0/4, 0/5, 0/6, 0/7, 0/8, 0/9, 0/10, 0/11, 0/12, 0/13, 0/14, 0/15,
  486. + 0, 1/1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15,
  487. + 0, 2/1, 2/2, 2/3, 2/4, 2/5, 2/6, 2/7, 2/8, 2/9, 2/10, 2/11, 2/12, 2/13, 2/14, 2/15,
  488. + 0, 3/1, 3/2, 3/3, 3/4, 3/5, 3/6, 3/7, 3/8, 3/9, 3/10, 3/11, 3/12, 3/13, 3/14, 3/15,
  489. + 0, 4/1, 4/2, 4/3, 4/4, 4/5, 4/6, 4/7, 4/8, 4/9, 4/10, 4/11, 4/12, 4/13, 4/14, 4/15,
  490. + 0, 5/1, 5/2, 5/3, 5/4, 5/5, 5/6, 5/7, 5/8, 5/9, 5/10, 5/11, 5/12, 5/13, 5/14, 5/15,
  491. + 0, 6/1, 6/2, 6/3, 6/4, 6/5, 6/6, 6/7, 6/8, 6/9, 6/10, 6/11, 6/12, 6/13, 6/14, 6/15,
  492. + 0, 7/1, 7/2, 7/3, 7/4, 7/5, 7/6, 7/7, 7/8, 7/9, 7/10, 7/11, 7/12, 7/13, 7/14, 7/15,
  493. + 0, 8/1, 8/2, 8/3, 8/4, 8/5, 8/6, 8/7, 8/8, 8/9, 8/10, 8/11, 8/12, 8/13, 8/14, 8/15,
  494. + 0, 9/1, 9/2, 9/3, 9/4, 9/5, 9/6, 9/7, 9/8, 9/9, 9/10, 9/11, 9/12, 9/13, 9/14, 9/15,
  495. + 0, 10/1, 10/2, 10/3, 10/4, 10/5, 10/6, 10/7, 10/8, 10/9, 10/10, 10/11, 10/12, 10/13, 10/14, 10/15,
  496. + 0, 11/1, 11/2, 11/3, 11/4, 11/5, 11/6, 11/7, 11/8, 11/9, 11/10, 11/11, 11/12, 11/13, 11/14, 11/15,
  497. + 0, 12/1, 12/2, 12/3, 12/4, 12/5, 12/6, 12/7, 12/8, 12/9, 12/10, 12/11, 12/12, 12/13, 12/14, 12/15,
  498. + 0, 13/1, 13/2, 13/3, 13/4, 13/5, 13/6, 13/7, 13/8, 13/9, 13/10, 13/11, 13/12, 13/13, 13/14, 13/15,
  499. + 0, 14/1, 14/2, 14/3, 14/4, 14/5, 14/6, 14/7, 14/8, 14/9, 14/10, 14/11, 14/12, 14/13, 14/14, 14/15,
  500. + 0, 15/1, 15/2, 15/3, 15/4, 15/5, 15/6, 15/7, 15/8, 15/9, 15/10, 15/11, 15/12, 15/13, 15/14, 15/15,
  501. +};
  502. +
  503. --- gcc-3.4.3/gcc/config/nios2/lib2-mul.c
  504. +++ gcc-3.4.3-nios2/gcc/config/nios2/lib2-mul.c
  505. @@ -0,0 +1,103 @@
  506. +/* while we are debugging (ie compile outside of gcc build)
  507. + disable gcc specific headers */
  508. +#ifndef DEBUG_MULSI3
  509. +
  510. +
  511. +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
  512. + supposedly valid even though this is a "target" file. */
  513. +#include "auto-host.h"
  514. +
  515. +
  516. +#include "tconfig.h"
  517. +#include "tsystem.h"
  518. +#include "coretypes.h"
  519. +#include "tm.h"
  520. +
  521. +
  522. +/* Don't use `fancy_abort' here even if config.h says to use it. */
  523. +#ifdef abort
  524. +#undef abort
  525. +#endif
  526. +
  527. +
  528. +#ifdef HAVE_GAS_HIDDEN
  529. +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
  530. +#else
  531. +#define ATTRIBUTE_HIDDEN
  532. +#endif
  533. +
  534. +#include "libgcc2.h"
  535. +
  536. +#else
  537. +#define SItype int
  538. +#define USItype unsigned int
  539. +#endif
  540. +
  541. +
  542. +extern SItype __mulsi3 (SItype, SItype);
  543. +
  544. +SItype
  545. +__mulsi3 (SItype a, SItype b)
  546. +{
  547. + SItype res = 0;
  548. + USItype cnt = a;
  549. +
  550. + while (cnt)
  551. + {
  552. + if (cnt & 1)
  553. + {
  554. + res += b;
  555. + }
  556. + b <<= 1;
  557. + cnt >>= 1;
  558. + }
  559. +
  560. + return res;
  561. +}
  562. +/*
  563. +TODO: Choose best alternative implementation.
  564. +
  565. +SItype
  566. +__divsi3 (SItype a, SItype b)
  567. +{
  568. + SItype res = 0;
  569. + USItype cnt = 0;
  570. +
  571. + while (cnt < 32)
  572. + {
  573. + if (a & (1L << cnt))
  574. + {
  575. + res += b;
  576. + }
  577. + b <<= 1;
  578. + cnt++;
  579. + }
  580. +
  581. + return res;
  582. +}
  583. +*/
  584. +
  585. +
  586. +#ifdef DEBUG_MULSI3
  587. +
  588. +int
  589. +main ()
  590. +{
  591. + int i, j;
  592. + int error = 0;
  593. +
  594. + for (i = -1000; i < 1000; i++)
  595. + for (j = -1000; j < 1000; j++)
  596. + {
  597. + int expect = i * j;
  598. + int actual = A__divsi3 (i, j);
  599. + if (expect != actual)
  600. + {
  601. + printf ("error: %d * %d = %d not %d\n", i, j, expect, actual);
  602. + error = 1;
  603. + }
  604. + }
  605. +
  606. + return error;
  607. +}
  608. +#endif
  609. --- gcc-3.4.3/gcc/config/nios2/nios2-dp-bit.c
  610. +++ gcc-3.4.3-nios2/gcc/config/nios2/nios2-dp-bit.c
  611. @@ -0,0 +1,1652 @@
  612. +
  613. +/* This is a software floating point library which can be used
  614. + for targets without hardware floating point.
  615. + Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
  616. + Free Software Foundation, Inc.
  617. +
  618. +This file is free software; you can redistribute it and/or modify it
  619. +under the terms of the GNU General Public License as published by the
  620. +Free Software Foundation; either version 2, or (at your option) any
  621. +later version.
  622. +
  623. +In addition to the permissions in the GNU General Public License, the
  624. +Free Software Foundation gives you unlimited permission to link the
  625. +compiled version of this file with other programs, and to distribute
  626. +those programs without any restriction coming from the use of this
  627. +file. (The General Public License restrictions do apply in other
  628. +respects; for example, they cover modification of the file, and
  629. +distribution when not linked into another program.)
  630. +
  631. +This file is distributed in the hope that it will be useful, but
  632. +WITHOUT ANY WARRANTY; without even the implied warranty of
  633. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  634. +General Public License for more details.
  635. +
  636. +You should have received a copy of the GNU General Public License
  637. +along with this program; see the file COPYING. If not, write to
  638. +the Free Software Foundation, 59 Temple Place - Suite 330,
  639. +Boston, MA 02111-1307, USA. */
  640. +
  641. +/* As a special exception, if you link this library with other files,
  642. + some of which are compiled with GCC, to produce an executable,
  643. + this library does not by itself cause the resulting executable
  644. + to be covered by the GNU General Public License.
  645. + This exception does not however invalidate any other reasons why
  646. + the executable file might be covered by the GNU General Public License. */
  647. +
  648. +/* This implements IEEE 754 format arithmetic, but does not provide a
  649. + mechanism for setting the rounding mode, or for generating or handling
  650. + exceptions.
  651. +
  652. + The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
  653. + Wilson, all of Cygnus Support. */
  654. +
  655. +/* The intended way to use this file is to make two copies, add `#define FLOAT'
  656. + to one copy, then compile both copies and add them to libgcc.a. */
  657. +
  658. +#include "tconfig.h"
  659. +#include "coretypes.h"
  660. +#include "tm.h"
  661. +#include "config/fp-bit.h"
  662. +
  663. +/* The following macros can be defined to change the behavior of this file:
  664. + FLOAT: Implement a `float', aka SFmode, fp library. If this is not
  665. + defined, then this file implements a `double', aka DFmode, fp library.
  666. + FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
  667. + don't include float->double conversion which requires the double library.
  668. + This is useful only for machines which can't support doubles, e.g. some
  669. + 8-bit processors.
  670. + CMPtype: Specify the type that floating point compares should return.
  671. + This defaults to SItype, aka int.
  672. + US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
  673. + US Software goFast library.
  674. + _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
  675. + two integers to the FLO_union_type.
  676. + NO_DENORMALS: Disable handling of denormals.
  677. + NO_NANS: Disable nan and infinity handling
  678. + SMALL_MACHINE: Useful when operations on QIs and HIs are faster
  679. + than on an SI */
  680. +
  681. +/* We don't currently support extended floats (long doubles) on machines
  682. + without hardware to deal with them.
  683. +
  684. + These stubs are just to keep the linker from complaining about unresolved
  685. + references which can be pulled in from libio & libstdc++, even if the
  686. + user isn't using long doubles. However, they may generate an unresolved
  687. + external to abort if abort is not used by the function, and the stubs
  688. + are referenced from within libc, since libgcc goes before and after the
  689. + system library. */
  690. +
  691. +#ifdef DECLARE_LIBRARY_RENAMES
  692. + DECLARE_LIBRARY_RENAMES
  693. +#endif
  694. +
  695. +#ifdef EXTENDED_FLOAT_STUBS
  696. +extern void abort (void);
  697. +void __extendsfxf2 (void) { abort(); }
  698. +void __extenddfxf2 (void) { abort(); }
  699. +void __truncxfdf2 (void) { abort(); }
  700. +void __truncxfsf2 (void) { abort(); }
  701. +void __fixxfsi (void) { abort(); }
  702. +void __floatsixf (void) { abort(); }
  703. +void __addxf3 (void) { abort(); }
  704. +void __subxf3 (void) { abort(); }
  705. +void __mulxf3 (void) { abort(); }
  706. +void __divxf3 (void) { abort(); }
  707. +void __negxf2 (void) { abort(); }
  708. +void __eqxf2 (void) { abort(); }
  709. +void __nexf2 (void) { abort(); }
  710. +void __gtxf2 (void) { abort(); }
  711. +void __gexf2 (void) { abort(); }
  712. +void __lexf2 (void) { abort(); }
  713. +void __ltxf2 (void) { abort(); }
  714. +
  715. +void __extendsftf2 (void) { abort(); }
  716. +void __extenddftf2 (void) { abort(); }
  717. +void __trunctfdf2 (void) { abort(); }
  718. +void __trunctfsf2 (void) { abort(); }
  719. +void __fixtfsi (void) { abort(); }
  720. +void __floatsitf (void) { abort(); }
  721. +void __addtf3 (void) { abort(); }
  722. +void __subtf3 (void) { abort(); }
  723. +void __multf3 (void) { abort(); }
  724. +void __divtf3 (void) { abort(); }
  725. +void __negtf2 (void) { abort(); }
  726. +void __eqtf2 (void) { abort(); }
  727. +void __netf2 (void) { abort(); }
  728. +void __gttf2 (void) { abort(); }
  729. +void __getf2 (void) { abort(); }
  730. +void __letf2 (void) { abort(); }
  731. +void __lttf2 (void) { abort(); }
  732. +#else /* !EXTENDED_FLOAT_STUBS, rest of file */
  733. +
  734. +/* IEEE "special" number predicates */
  735. +
  736. +#ifdef NO_NANS
  737. +
  738. +#define nan() 0
  739. +#define isnan(x) 0
  740. +#define isinf(x) 0
  741. +#else
  742. +
  743. +#if defined L_thenan_sf
  744. +const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
  745. +#elif defined L_thenan_df
  746. +const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
  747. +#elif defined L_thenan_tf
  748. +const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
  749. +#elif defined TFLOAT
  750. +extern const fp_number_type __thenan_tf;
  751. +#elif defined FLOAT
  752. +extern const fp_number_type __thenan_sf;
  753. +#else
  754. +extern const fp_number_type __thenan_df;
  755. +#endif
  756. +
  757. +INLINE
  758. +static fp_number_type *
  759. +nan (void)
  760. +{
  761. + /* Discard the const qualifier... */
  762. +#ifdef TFLOAT
  763. + return (fp_number_type *) (& __thenan_tf);
  764. +#elif defined FLOAT
  765. + return (fp_number_type *) (& __thenan_sf);
  766. +#else
  767. + return (fp_number_type *) (& __thenan_df);
  768. +#endif
  769. +}
  770. +
  771. +INLINE
  772. +static int
  773. +isnan ( fp_number_type * x)
  774. +{
  775. + return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
  776. +}
  777. +
  778. +INLINE
  779. +static int
  780. +isinf ( fp_number_type * x)
  781. +{
  782. + return x->class == CLASS_INFINITY;
  783. +}
  784. +
  785. +#endif /* NO_NANS */
  786. +
  787. +INLINE
  788. +static int
  789. +iszero ( fp_number_type * x)
  790. +{
  791. + return x->class == CLASS_ZERO;
  792. +}
  793. +
  794. +INLINE
  795. +static void
  796. +flip_sign ( fp_number_type * x)
  797. +{
  798. + x->sign = !x->sign;
  799. +}
  800. +
  801. +extern FLO_type pack_d ( fp_number_type * );
  802. +
  803. +#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
  804. +FLO_type
  805. +pack_d ( fp_number_type * src)
  806. +{
  807. + FLO_union_type dst;
  808. + fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
  809. + int sign = src->sign;
  810. + int exp = 0;
  811. +
  812. + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
  813. + {
  814. + /* We can't represent these values accurately. By using the
  815. + largest possible magnitude, we guarantee that the conversion
  816. + of infinity is at least as big as any finite number. */
  817. + exp = EXPMAX;
  818. + fraction = ((fractype) 1 << FRACBITS) - 1;
  819. + }
  820. + else if (isnan (src))
  821. + {
  822. + exp = EXPMAX;
  823. + if (src->class == CLASS_QNAN || 1)
  824. + {
  825. +#ifdef QUIET_NAN_NEGATED
  826. + fraction |= QUIET_NAN - 1;
  827. +#else
  828. + fraction |= QUIET_NAN;
  829. +#endif
  830. + }
  831. + }
  832. + else if (isinf (src))
  833. + {
  834. + exp = EXPMAX;
  835. + fraction = 0;
  836. + }
  837. + else if (iszero (src))
  838. + {
  839. + exp = 0;
  840. + fraction = 0;
  841. + }
  842. + else if (fraction == 0)
  843. + {
  844. + exp = 0;
  845. + }
  846. + else
  847. + {
  848. + if (src->normal_exp < NORMAL_EXPMIN)
  849. + {
  850. +#ifdef NO_DENORMALS
  851. + /* Go straight to a zero representation if denormals are not
  852. + supported. The denormal handling would be harmless but
  853. + isn't unnecessary. */
  854. + exp = 0;
  855. + fraction = 0;
  856. +#else /* NO_DENORMALS */
  857. + /* This number's exponent is too low to fit into the bits
  858. + available in the number, so we'll store 0 in the exponent and
  859. + shift the fraction to the right to make up for it. */
  860. +
  861. + int shift = NORMAL_EXPMIN - src->normal_exp;
  862. +
  863. + exp = 0;
  864. +
  865. + if (shift > FRAC_NBITS - NGARDS)
  866. + {
  867. + /* No point shifting, since it's more that 64 out. */
  868. + fraction = 0;
  869. + }
  870. + else
  871. + {
  872. + int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
  873. + fraction = (fraction >> shift) | lowbit;
  874. + }
  875. + if ((fraction & GARDMASK) == GARDMSB)
  876. + {
  877. + if ((fraction & (1 << NGARDS)))
  878. + fraction += GARDROUND + 1;
  879. + }
  880. + else
  881. + {
  882. + /* Add to the guards to round up. */
  883. + fraction += GARDROUND;
  884. + }
  885. + /* Perhaps the rounding means we now need to change the
  886. + exponent, because the fraction is no longer denormal. */
  887. + if (fraction >= IMPLICIT_1)
  888. + {
  889. + exp += 1;
  890. + }
  891. + fraction >>= NGARDS;
  892. +#endif /* NO_DENORMALS */
  893. + }
  894. + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
  895. + && src->normal_exp > EXPBIAS)
  896. + {
  897. + exp = EXPMAX;
  898. + fraction = 0;
  899. + }
  900. + else
  901. + {
  902. + exp = src->normal_exp + EXPBIAS;
  903. + if (!ROUND_TOWARDS_ZERO)
  904. + {
  905. + /* IF the gard bits are the all zero, but the first, then we're
  906. + half way between two numbers, choose the one which makes the
  907. + lsb of the answer 0. */
  908. + if ((fraction & GARDMASK) == GARDMSB)
  909. + {
  910. + if (fraction & (1 << NGARDS))
  911. + fraction += GARDROUND + 1;
  912. + }
  913. + else
  914. + {
  915. + /* Add a one to the guards to round up */
  916. + fraction += GARDROUND;
  917. + }
  918. + if (fraction >= IMPLICIT_2)
  919. + {
  920. + fraction >>= 1;
  921. + exp += 1;
  922. + }
  923. + }
  924. + fraction >>= NGARDS;
  925. +
  926. + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
  927. + {
  928. + /* Saturate on overflow. */
  929. + exp = EXPMAX;
  930. + fraction = ((fractype) 1 << FRACBITS) - 1;
  931. + }
  932. + }
  933. + }
  934. +
  935. + /* We previously used bitfields to store the number, but this doesn't
  936. + handle little/big endian systems conveniently, so use shifts and
  937. + masks */
  938. +#ifdef FLOAT_BIT_ORDER_MISMATCH
  939. + dst.bits.fraction = fraction;
  940. + dst.bits.exp = exp;
  941. + dst.bits.sign = sign;
  942. +#else
  943. +# if defined TFLOAT && defined HALFFRACBITS
  944. + {
  945. + halffractype high, low, unity;
  946. + int lowsign, lowexp;
  947. +
  948. + unity = (halffractype) 1 << HALFFRACBITS;
  949. +
  950. + /* Set HIGH to the high double's significand, masking out the implicit 1.
  951. + Set LOW to the low double's full significand. */
  952. + high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
  953. + low = fraction & (unity * 2 - 1);
  954. +
  955. + /* Get the initial sign and exponent of the low double. */
  956. + lowexp = exp - HALFFRACBITS - 1;
  957. + lowsign = sign;
  958. +
  959. + /* HIGH should be rounded like a normal double, making |LOW| <=
  960. + 0.5 ULP of HIGH. Assume round-to-nearest. */
  961. + if (exp < EXPMAX)
  962. + if (low > unity || (low == unity && (high & 1) == 1))
  963. + {
  964. + /* Round HIGH up and adjust LOW to match. */
  965. + high++;
  966. + if (high == unity)
  967. + {
  968. + /* May make it infinite, but that's OK. */
  969. + high = 0;
  970. + exp++;
  971. + }
  972. + low = unity * 2 - low;
  973. + lowsign ^= 1;
  974. + }
  975. +
  976. + high |= (halffractype) exp << HALFFRACBITS;
  977. + high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
  978. +
  979. + if (exp == EXPMAX || exp == 0 || low == 0)
  980. + low = 0;
  981. + else
  982. + {
  983. + while (lowexp > 0 && low < unity)
  984. + {
  985. + low <<= 1;
  986. + lowexp--;
  987. + }
  988. +
  989. + if (lowexp <= 0)
  990. + {
  991. + halffractype roundmsb, round;
  992. + int shift;
  993. +
  994. + shift = 1 - lowexp;
  995. + roundmsb = (1 << (shift - 1));
  996. + round = low & ((roundmsb << 1) - 1);
  997. +
  998. + low >>= shift;
  999. + lowexp = 0;
  1000. +
  1001. + if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
  1002. + {
  1003. + low++;
  1004. + if (low == unity)
  1005. + /* LOW rounds up to the smallest normal number. */
  1006. + lowexp++;
  1007. + }
  1008. + }
  1009. +
  1010. + low &= unity - 1;
  1011. + low |= (halffractype) lowexp << HALFFRACBITS;
  1012. + low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
  1013. + }
  1014. + dst.value_raw = ((fractype) high << HALFSHIFT) | low;
  1015. + }
  1016. +# else
  1017. + dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
  1018. + dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
  1019. + dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
  1020. +# endif
  1021. +#endif
  1022. +
  1023. +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
  1024. +#ifdef TFLOAT
  1025. + {
  1026. + qrtrfractype tmp1 = dst.words[0];
  1027. + qrtrfractype tmp2 = dst.words[1];
  1028. + dst.words[0] = dst.words[3];
  1029. + dst.words[1] = dst.words[2];
  1030. + dst.words[2] = tmp2;
  1031. + dst.words[3] = tmp1;
  1032. + }
  1033. +#else
  1034. + {
  1035. + halffractype tmp = dst.words[0];
  1036. + dst.words[0] = dst.words[1];
  1037. + dst.words[1] = tmp;
  1038. + }
  1039. +#endif
  1040. +#endif
  1041. +
  1042. + return dst.value;
  1043. +}
  1044. +#endif
  1045. +
  1046. +#if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
  1047. +void
  1048. +unpack_d (FLO_union_type * src, fp_number_type * dst)
  1049. +{
  1050. + /* We previously used bitfields to store the number, but this doesn't
  1051. + handle little/big endian systems conveniently, so use shifts and
  1052. + masks */
  1053. + fractype fraction;
  1054. + int exp;
  1055. + int sign;
  1056. +
  1057. +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
  1058. + FLO_union_type swapped;
  1059. +
  1060. +#ifdef TFLOAT
  1061. + swapped.words[0] = src->words[3];
  1062. + swapped.words[1] = src->words[2];
  1063. + swapped.words[2] = src->words[1];
  1064. + swapped.words[3] = src->words[0];
  1065. +#else
  1066. + swapped.words[0] = src->words[1];
  1067. + swapped.words[1] = src->words[0];
  1068. +#endif
  1069. + src = &swapped;
  1070. +#endif
  1071. +
  1072. +#ifdef FLOAT_BIT_ORDER_MISMATCH
  1073. + fraction = src->bits.fraction;
  1074. + exp = src->bits.exp;
  1075. + sign = src->bits.sign;
  1076. +#else
  1077. +# if defined TFLOAT && defined HALFFRACBITS
  1078. + {
  1079. + halffractype high, low;
  1080. +
  1081. + high = src->value_raw >> HALFSHIFT;
  1082. + low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
  1083. +
  1084. + fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
  1085. + fraction <<= FRACBITS - HALFFRACBITS;
  1086. + exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
  1087. + sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
  1088. +
  1089. + if (exp != EXPMAX && exp != 0 && low != 0)
  1090. + {
  1091. + int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
  1092. + int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
  1093. + int shift;
  1094. + fractype xlow;
  1095. +
  1096. + xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
  1097. + if (lowexp)
  1098. + xlow |= (((halffractype)1) << HALFFRACBITS);
  1099. + else
  1100. + lowexp = 1;
  1101. + shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
  1102. + if (shift > 0)
  1103. + xlow <<= shift;
  1104. + else if (shift < 0)
  1105. + xlow >>= -shift;
  1106. + if (sign == lowsign)
  1107. + fraction += xlow;
  1108. + else if (fraction >= xlow)
  1109. + fraction -= xlow;
  1110. + else
  1111. + {
  1112. + /* The high part is a power of two but the full number is lower.
  1113. + This code will leave the implicit 1 in FRACTION, but we'd
  1114. + have added that below anyway. */
  1115. + fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
  1116. + exp--;
  1117. + }
  1118. + }
  1119. + }
  1120. +# else
  1121. + fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
  1122. + exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
  1123. + sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
  1124. +# endif
  1125. +#endif
  1126. +
  1127. + dst->sign = sign;
  1128. + if (exp == 0)
  1129. + {
  1130. + /* Hmm. Looks like 0 */
  1131. + if (fraction == 0
  1132. +#ifdef NO_DENORMALS
  1133. + || 1
  1134. +#endif
  1135. + )
  1136. + {
  1137. + /* tastes like zero */
  1138. + dst->class = CLASS_ZERO;
  1139. + }
  1140. + else
  1141. + {
  1142. + /* Zero exponent with nonzero fraction - it's denormalized,
  1143. + so there isn't a leading implicit one - we'll shift it so
  1144. + it gets one. */
  1145. + dst->normal_exp = exp - EXPBIAS + 1;
  1146. + fraction <<= NGARDS;
  1147. +
  1148. + dst->class = CLASS_NUMBER;
  1149. +#if 1
  1150. + while (fraction < IMPLICIT_1)
  1151. + {
  1152. + fraction <<= 1;
  1153. + dst->normal_exp--;
  1154. + }
  1155. +#endif
  1156. + dst->fraction.ll = fraction;
  1157. + }
  1158. + }
  1159. + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
  1160. + {
  1161. + /* Huge exponent*/
  1162. + if (fraction == 0)
  1163. + {
  1164. + /* Attached to a zero fraction - means infinity */
  1165. + dst->class = CLASS_INFINITY;
  1166. + }
  1167. + else
  1168. + {
  1169. + /* Nonzero fraction, means nan */
  1170. +#ifdef QUIET_NAN_NEGATED
  1171. + if ((fraction & QUIET_NAN) == 0)
  1172. +#else
  1173. + if (fraction & QUIET_NAN)
  1174. +#endif
  1175. + {
  1176. + dst->class = CLASS_QNAN;
  1177. + }
  1178. + else
  1179. + {
  1180. + dst->class = CLASS_SNAN;
  1181. + }
  1182. + /* Keep the fraction part as the nan number */
  1183. + dst->fraction.ll = fraction;
  1184. + }
  1185. + }
  1186. + else
  1187. + {
  1188. + /* Nothing strange about this number */
  1189. + dst->normal_exp = exp - EXPBIAS;
  1190. + dst->class = CLASS_NUMBER;
  1191. + dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
  1192. + }
  1193. +}
  1194. +#endif /* L_unpack_df || L_unpack_sf */
  1195. +
  1196. +#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
  1197. +static fp_number_type *
  1198. +_fpadd_parts (fp_number_type * a,
  1199. + fp_number_type * b,
  1200. + fp_number_type * tmp)
  1201. +{
  1202. + intfrac tfraction;
  1203. +
  1204. + /* Put commonly used fields in local variables. */
  1205. + int a_normal_exp;
  1206. + int b_normal_exp;
  1207. + fractype a_fraction;
  1208. + fractype b_fraction;
  1209. +
  1210. + if (isnan (a))
  1211. + {
  1212. + return a;
  1213. + }
  1214. + if (isnan (b))
  1215. + {
  1216. + return b;
  1217. + }
  1218. + if (isinf (a))
  1219. + {
  1220. + /* Adding infinities with opposite signs yields a NaN. */
  1221. + if (isinf (b) && a->sign != b->sign)
  1222. + return nan ();
  1223. + return a;
  1224. + }
  1225. + if (isinf (b))
  1226. + {
  1227. + return b;
  1228. + }
  1229. + if (iszero (b))
  1230. + {
  1231. + if (iszero (a))
  1232. + {
  1233. + *tmp = *a;
  1234. + tmp->sign = a->sign & b->sign;
  1235. + return tmp;
  1236. + }
  1237. + return a;
  1238. + }
  1239. + if (iszero (a))
  1240. + {
  1241. + return b;
  1242. + }
  1243. +
  1244. + /* Got two numbers. shift the smaller and increment the exponent till
  1245. + they're the same */
  1246. + {
  1247. + int diff;
  1248. +
  1249. + a_normal_exp = a->normal_exp;
  1250. + b_normal_exp = b->normal_exp;
  1251. + a_fraction = a->fraction.ll;
  1252. + b_fraction = b->fraction.ll;
  1253. +
  1254. + diff = a_normal_exp - b_normal_exp;
  1255. +
  1256. + if (diff < 0)
  1257. + diff = -diff;
  1258. + if (diff < FRAC_NBITS)
  1259. + {
  1260. + /* ??? This does shifts one bit at a time. Optimize. */
  1261. + while (a_normal_exp > b_normal_exp)
  1262. + {
  1263. + b_normal_exp++;
  1264. + LSHIFT (b_fraction);
  1265. + }
  1266. + while (b_normal_exp > a_normal_exp)
  1267. + {
  1268. + a_normal_exp++;
  1269. + LSHIFT (a_fraction);
  1270. + }
  1271. + }
  1272. + else
  1273. + {
  1274. + /* Somethings's up.. choose the biggest */
  1275. + if (a_normal_exp > b_normal_exp)
  1276. + {
  1277. + b_normal_exp = a_normal_exp;
  1278. + b_fraction = 0;
  1279. + }
  1280. + else
  1281. + {
  1282. + a_normal_exp = b_normal_exp;
  1283. + a_fraction = 0;
  1284. + }
  1285. + }
  1286. + }
  1287. +
  1288. + if (a->sign != b->sign)
  1289. + {
  1290. + if (a->sign)
  1291. + {
  1292. + tfraction = -a_fraction + b_fraction;
  1293. + }
  1294. + else
  1295. + {
  1296. + tfraction = a_fraction - b_fraction;
  1297. + }
  1298. + if (tfraction >= 0)
  1299. + {
  1300. + tmp->sign = 0;
  1301. + tmp->normal_exp = a_normal_exp;
  1302. + tmp->fraction.ll = tfraction;
  1303. + }
  1304. + else
  1305. + {
  1306. + tmp->sign = 1;
  1307. + tmp->normal_exp = a_normal_exp;
  1308. + tmp->fraction.ll = -tfraction;
  1309. + }
  1310. + /* and renormalize it */
  1311. +
  1312. + while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
  1313. + {
  1314. + tmp->fraction.ll <<= 1;
  1315. + tmp->normal_exp--;
  1316. + }
  1317. + }
  1318. + else
  1319. + {
  1320. + tmp->sign = a->sign;
  1321. + tmp->normal_exp = a_normal_exp;
  1322. + tmp->fraction.ll = a_fraction + b_fraction;
  1323. + }
  1324. + tmp->class = CLASS_NUMBER;
  1325. + /* Now the fraction is added, we have to shift down to renormalize the
  1326. + number */
  1327. +
  1328. + if (tmp->fraction.ll >= IMPLICIT_2)
  1329. + {
  1330. + LSHIFT (tmp->fraction.ll);
  1331. + tmp->normal_exp++;
  1332. + }
  1333. + return tmp;
  1334. +
  1335. +}
  1336. +
  1337. +FLO_type
  1338. +add (FLO_type arg_a, FLO_type arg_b)
  1339. +{
  1340. + fp_number_type a;
  1341. + fp_number_type b;
  1342. + fp_number_type tmp;
  1343. + fp_number_type *res;
  1344. + FLO_union_type au, bu;
  1345. +
  1346. + au.value = arg_a;
  1347. + bu.value = arg_b;
  1348. +
  1349. + unpack_d (&au, &a);
  1350. + unpack_d (&bu, &b);
  1351. +
  1352. + res = _fpadd_parts (&a, &b, &tmp);
  1353. +
  1354. + return pack_d (res);
  1355. +}
  1356. +
  1357. +FLO_type
  1358. +sub (FLO_type arg_a, FLO_type arg_b)
  1359. +{
  1360. + fp_number_type a;
  1361. + fp_number_type b;
  1362. + fp_number_type tmp;
  1363. + fp_number_type *res;
  1364. + FLO_union_type au, bu;
  1365. +
  1366. + au.value = arg_a;
  1367. + bu.value = arg_b;
  1368. +
  1369. + unpack_d (&au, &a);
  1370. + unpack_d (&bu, &b);
  1371. +
  1372. + b.sign ^= 1;
  1373. +
  1374. + res = _fpadd_parts (&a, &b, &tmp);
  1375. +
  1376. + return pack_d (res);
  1377. +}
  1378. +#endif /* L_addsub_sf || L_addsub_df */
  1379. +
  1380. +#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
  1381. +static inline __attribute__ ((__always_inline__)) fp_number_type *
  1382. +_fpmul_parts ( fp_number_type * a,
  1383. + fp_number_type * b,
  1384. + fp_number_type * tmp)
  1385. +{
  1386. + fractype low = 0;
  1387. + fractype high = 0;
  1388. +
  1389. + if (isnan (a))
  1390. + {
  1391. + a->sign = a->sign != b->sign;
  1392. + return a;
  1393. + }
  1394. + if (isnan (b))
  1395. + {
  1396. + b->sign = a->sign != b->sign;
  1397. + return b;
  1398. + }
  1399. + if (isinf (a))
  1400. + {
  1401. + if (iszero (b))
  1402. + return nan ();
  1403. + a->sign = a->sign != b->sign;
  1404. + return a;
  1405. + }
  1406. + if (isinf (b))
  1407. + {
  1408. + if (iszero (a))
  1409. + {
  1410. + return nan ();
  1411. + }
  1412. + b->sign = a->sign != b->sign;
  1413. + return b;
  1414. + }
  1415. + if (iszero (a))
  1416. + {
  1417. + a->sign = a->sign != b->sign;
  1418. + return a;
  1419. + }
  1420. + if (iszero (b))
  1421. + {
  1422. + b->sign = a->sign != b->sign;
  1423. + return b;
  1424. + }
  1425. +
  1426. + /* Calculate the mantissa by multiplying both numbers to get a
  1427. + twice-as-wide number. */
  1428. + {
  1429. +#if defined(NO_DI_MODE) || defined(TFLOAT)
  1430. + {
  1431. + fractype x = a->fraction.ll;
  1432. + fractype ylow = b->fraction.ll;
  1433. + fractype yhigh = 0;
  1434. + int bit;
  1435. +
  1436. + /* ??? This does multiplies one bit at a time. Optimize. */
  1437. + for (bit = 0; bit < FRAC_NBITS; bit++)
  1438. + {
  1439. + int carry;
  1440. +
  1441. + if (x & 1)
  1442. + {
  1443. + carry = (low += ylow) < ylow;
  1444. + high += yhigh + carry;
  1445. + }
  1446. + yhigh <<= 1;
  1447. + if (ylow & FRACHIGH)
  1448. + {
  1449. + yhigh |= 1;
  1450. + }
  1451. + ylow <<= 1;
  1452. + x >>= 1;
  1453. + }
  1454. + }
  1455. +#elif defined(FLOAT)
  1456. + /* Multiplying two USIs to get a UDI, we're safe. */
  1457. + {
  1458. + UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
  1459. +
  1460. + high = answer >> BITS_PER_SI;
  1461. + low = answer;
  1462. + }
  1463. +#else
  1464. + /* fractype is DImode, but we need the result to be twice as wide.
  1465. + Assuming a widening multiply from DImode to TImode is not
  1466. + available, build one by hand. */
  1467. + {
  1468. + USItype nl = a->fraction.ll;
  1469. + USItype nh = a->fraction.ll >> BITS_PER_SI;
  1470. + USItype ml = b->fraction.ll;
  1471. + USItype mh = b->fraction.ll >> BITS_PER_SI;
  1472. + UDItype pp_ll = (UDItype) ml * nl;
  1473. + UDItype pp_hl = (UDItype) mh * nl;
  1474. + UDItype pp_lh = (UDItype) ml * nh;
  1475. + UDItype pp_hh = (UDItype) mh * nh;
  1476. + UDItype res2 = 0;
  1477. + UDItype res0 = 0;
  1478. + UDItype ps_hh__ = pp_hl + pp_lh;
  1479. + if (ps_hh__ < pp_hl)
  1480. + res2 += (UDItype)1 << BITS_PER_SI;
  1481. + pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
  1482. + res0 = pp_ll + pp_hl;
  1483. + if (res0 < pp_ll)
  1484. + res2++;
  1485. + res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
  1486. + high = res2;
  1487. + low = res0;
  1488. + }
  1489. +#endif
  1490. + }
  1491. +
  1492. + tmp->normal_exp = a->normal_exp + b->normal_exp
  1493. + + FRAC_NBITS - (FRACBITS + NGARDS);
  1494. + tmp->sign = a->sign != b->sign;
  1495. + while (high >= IMPLICIT_2)
  1496. + {
  1497. + tmp->normal_exp++;
  1498. + if (high & 1)
  1499. + {
  1500. + low >>= 1;
  1501. + low |= FRACHIGH;
  1502. + }
  1503. + high >>= 1;
  1504. + }
  1505. + while (high < IMPLICIT_1)
  1506. + {
  1507. + tmp->normal_exp--;
  1508. +
  1509. + high <<= 1;
  1510. + if (low & FRACHIGH)
  1511. + high |= 1;
  1512. + low <<= 1;
  1513. + }
  1514. + /* rounding is tricky. if we only round if it won't make us round later. */
  1515. +#if 0
  1516. + if (low & FRACHIGH2)
  1517. + {
  1518. + if (((high & GARDMASK) != GARDMSB)
  1519. + && (((high + 1) & GARDMASK) == GARDMSB))
  1520. + {
  1521. + /* don't round, it gets done again later. */
  1522. + }
  1523. + else
  1524. + {
  1525. + high++;
  1526. + }
  1527. + }
  1528. +#endif
  1529. + if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
  1530. + {
  1531. + if (high & (1 << NGARDS))
  1532. + {
  1533. + /* half way, so round to even */
  1534. + high += GARDROUND + 1;
  1535. + }
  1536. + else if (low)
  1537. + {
  1538. + /* but we really weren't half way */
  1539. + high += GARDROUND + 1;
  1540. + }
  1541. + }
  1542. + tmp->fraction.ll = high;
  1543. + tmp->class = CLASS_NUMBER;
  1544. + return tmp;
  1545. +}
  1546. +
  1547. +FLO_type
  1548. +multiply (FLO_type arg_a, FLO_type arg_b)
  1549. +{
  1550. + fp_number_type a;
  1551. + fp_number_type b;
  1552. + fp_number_type tmp;
  1553. + fp_number_type *res;
  1554. + FLO_union_type au, bu;
  1555. +
  1556. + au.value = arg_a;
  1557. + bu.value = arg_b;
  1558. +
  1559. + unpack_d (&au, &a);
  1560. + unpack_d (&bu, &b);
  1561. +
  1562. + res = _fpmul_parts (&a, &b, &tmp);
  1563. +
  1564. + return pack_d (res);
  1565. +}
  1566. +#endif /* L_mul_sf || L_mul_df */
  1567. +
  1568. +#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
  1569. +static inline __attribute__ ((__always_inline__)) fp_number_type *
  1570. +_fpdiv_parts (fp_number_type * a,
  1571. + fp_number_type * b)
  1572. +{
  1573. + fractype bit;
  1574. + fractype numerator;
  1575. + fractype denominator;
  1576. + fractype quotient;
  1577. +
  1578. + if (isnan (a))
  1579. + {
  1580. + return a;
  1581. + }
  1582. + if (isnan (b))
  1583. + {
  1584. + return b;
  1585. + }
  1586. +
  1587. + a->sign = a->sign ^ b->sign;
  1588. +
  1589. + if (isinf (a) || iszero (a))
  1590. + {
  1591. + if (a->class == b->class)
  1592. + return nan ();
  1593. + return a;
  1594. + }
  1595. +
  1596. + if (isinf (b))
  1597. + {
  1598. + a->fraction.ll = 0;
  1599. + a->normal_exp = 0;
  1600. + return a;
  1601. + }
  1602. + if (iszero (b))
  1603. + {
  1604. + a->class = CLASS_INFINITY;
  1605. + return a;
  1606. + }
  1607. +
  1608. + /* Calculate the mantissa by multiplying both 64bit numbers to get a
  1609. + 128 bit number */
  1610. + {
  1611. + /* quotient =
  1612. + ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
  1613. + */
  1614. +
  1615. + a->normal_exp = a->normal_exp - b->normal_exp;
  1616. + numerator = a->fraction.ll;
  1617. + denominator = b->fraction.ll;
  1618. +
  1619. + if (numerator < denominator)
  1620. + {
  1621. + /* Fraction will be less than 1.0 */
  1622. + numerator *= 2;
  1623. + a->normal_exp--;
  1624. + }
  1625. + bit = IMPLICIT_1;
  1626. + quotient = 0;
  1627. + /* ??? Does divide one bit at a time. Optimize. */
  1628. + while (bit)
  1629. + {
  1630. + if (numerator >= denominator)
  1631. + {
  1632. + quotient |= bit;
  1633. + numerator -= denominator;
  1634. + }
  1635. + bit >>= 1;
  1636. + numerator *= 2;
  1637. + }
  1638. +
  1639. + if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
  1640. + {
  1641. + if (quotient & (1 << NGARDS))
  1642. + {
  1643. + /* half way, so round to even */
  1644. + quotient += GARDROUND + 1;
  1645. + }
  1646. + else if (numerator)
  1647. + {
  1648. + /* but we really weren't half way, more bits exist */
  1649. + quotient += GARDROUND + 1;
  1650. + }
  1651. + }
  1652. +
  1653. + a->fraction.ll = quotient;
  1654. + return (a);
  1655. + }
  1656. +}
  1657. +
  1658. +FLO_type
  1659. +divide (FLO_type arg_a, FLO_type arg_b)
  1660. +{
  1661. + fp_number_type a;
  1662. + fp_number_type b;
  1663. + fp_number_type *res;
  1664. + FLO_union_type au, bu;
  1665. +
  1666. + au.value = arg_a;
  1667. + bu.value = arg_b;
  1668. +
  1669. + unpack_d (&au, &a);
  1670. + unpack_d (&bu, &b);
  1671. +
  1672. + res = _fpdiv_parts (&a, &b);
  1673. +
  1674. + return pack_d (res);
  1675. +}
  1676. +#endif /* L_div_sf || L_div_df */
  1677. +
  1678. +#if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
  1679. + || defined(L_fpcmp_parts_tf)
  1680. +/* according to the demo, fpcmp returns a comparison with 0... thus
  1681. + a<b -> -1
  1682. + a==b -> 0
  1683. + a>b -> +1
  1684. + */
  1685. +
  1686. +int
  1687. +__fpcmp_parts (fp_number_type * a, fp_number_type * b)
  1688. +{
  1689. +#if 0
  1690. + /* either nan -> unordered. Must be checked outside of this routine. */
  1691. + if (isnan (a) && isnan (b))
  1692. + {
  1693. + return 1; /* still unordered! */
  1694. + }
  1695. +#endif
  1696. +
  1697. + if (isnan (a) || isnan (b))
  1698. + {
  1699. + return 1; /* how to indicate unordered compare? */
  1700. + }
  1701. + if (isinf (a) && isinf (b))
  1702. + {
  1703. + /* +inf > -inf, but +inf != +inf */
  1704. + /* b \a| +inf(0)| -inf(1)
  1705. + ______\+--------+--------
  1706. + +inf(0)| a==b(0)| a<b(-1)
  1707. + -------+--------+--------
  1708. + -inf(1)| a>b(1) | a==b(0)
  1709. + -------+--------+--------
  1710. + So since unordered must be nonzero, just line up the columns...
  1711. + */
  1712. + return b->sign - a->sign;
  1713. + }
  1714. + /* but not both... */
  1715. + if (isinf (a))
  1716. + {
  1717. + return a->sign ? -1 : 1;
  1718. + }
  1719. + if (isinf (b))
  1720. + {
  1721. + return b->sign ? 1 : -1;
  1722. + }
  1723. + if (iszero (a) && iszero (b))
  1724. + {
  1725. + return 0;
  1726. + }
  1727. + if (iszero (a))
  1728. + {
  1729. + return b->sign ? 1 : -1;
  1730. + }
  1731. + if (iszero (b))
  1732. + {
  1733. + return a->sign ? -1 : 1;
  1734. + }
  1735. + /* now both are "normal". */
  1736. + if (a->sign != b->sign)
  1737. + {
  1738. + /* opposite signs */
  1739. + return a->sign ? -1 : 1;
  1740. + }
  1741. + /* same sign; exponents? */
  1742. + if (a->normal_exp > b->normal_exp)
  1743. + {
  1744. + return a->sign ? -1 : 1;
  1745. + }
  1746. + if (a->normal_exp < b->normal_exp)
  1747. + {
  1748. + return a->sign ? 1 : -1;
  1749. + }
  1750. + /* same exponents; check size. */
  1751. + if (a->fraction.ll > b->fraction.ll)
  1752. + {
  1753. + return a->sign ? -1 : 1;
  1754. + }
  1755. + if (a->fraction.ll < b->fraction.ll)
  1756. + {
  1757. + return a->sign ? 1 : -1;
  1758. + }
  1759. + /* after all that, they're equal. */
  1760. + return 0;
  1761. +}
  1762. +#endif
  1763. +
  1764. +#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
  1765. +CMPtype
  1766. +compare (FLO_type arg_a, FLO_type arg_b)
  1767. +{
  1768. + fp_number_type a;
  1769. + fp_number_type b;
  1770. + FLO_union_type au, bu;
  1771. +
  1772. + au.value = arg_a;
  1773. + bu.value = arg_b;
  1774. +
  1775. + unpack_d (&au, &a);
  1776. + unpack_d (&bu, &b);
  1777. +
  1778. + return __fpcmp_parts (&a, &b);
  1779. +}
  1780. +#endif /* L_compare_sf || L_compare_df */
  1781. +
  1782. +#ifndef US_SOFTWARE_GOFAST
  1783. +
  1784. +/* These should be optimized for their specific tasks someday. */
  1785. +
  1786. +#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
  1787. +CMPtype
  1788. +_eq_f2 (FLO_type arg_a, FLO_type arg_b)
  1789. +{
  1790. + fp_number_type a;
  1791. + fp_number_type b;
  1792. + FLO_union_type au, bu;
  1793. +
  1794. + au.value = arg_a;
  1795. + bu.value = arg_b;
  1796. +
  1797. + unpack_d (&au, &a);
  1798. + unpack_d (&bu, &b);
  1799. +
  1800. + if (isnan (&a) || isnan (&b))
  1801. + return 1; /* false, truth == 0 */
  1802. +
  1803. + return __fpcmp_parts (&a, &b) ;
  1804. +}
  1805. +#endif /* L_eq_sf || L_eq_df */
  1806. +
  1807. +#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
  1808. +CMPtype
  1809. +_ne_f2 (FLO_type arg_a, FLO_type arg_b)
  1810. +{
  1811. + fp_number_type a;
  1812. + fp_number_type b;
  1813. + FLO_union_type au, bu;
  1814. +
  1815. + au.value = arg_a;
  1816. + bu.value = arg_b;
  1817. +
  1818. + unpack_d (&au, &a);
  1819. + unpack_d (&bu, &b);
  1820. +
  1821. + if (isnan (&a) || isnan (&b))
  1822. + return 1; /* true, truth != 0 */
  1823. +
  1824. + return __fpcmp_parts (&a, &b) ;
  1825. +}
  1826. +#endif /* L_ne_sf || L_ne_df */
  1827. +
  1828. +#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
  1829. +CMPtype
  1830. +_gt_f2 (FLO_type arg_a, FLO_type arg_b)
  1831. +{
  1832. + fp_number_type a;
  1833. + fp_number_type b;
  1834. + FLO_union_type au, bu;
  1835. +
  1836. + au.value = arg_a;
  1837. + bu.value = arg_b;
  1838. +
  1839. + unpack_d (&au, &a);
  1840. + unpack_d (&bu, &b);
  1841. +
  1842. + if (isnan (&a) || isnan (&b))
  1843. + return -1; /* false, truth > 0 */
  1844. +
  1845. + return __fpcmp_parts (&a, &b);
  1846. +}
  1847. +#endif /* L_gt_sf || L_gt_df */
  1848. +
  1849. +#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
  1850. +CMPtype
  1851. +_ge_f2 (FLO_type arg_a, FLO_type arg_b)
  1852. +{
  1853. + fp_number_type a;
  1854. + fp_number_type b;
  1855. + FLO_union_type au, bu;
  1856. +
  1857. + au.value = arg_a;
  1858. + bu.value = arg_b;
  1859. +
  1860. + unpack_d (&au, &a);
  1861. + unpack_d (&bu, &b);
  1862. +
  1863. + if (isnan (&a) || isnan (&b))
  1864. + return -1; /* false, truth >= 0 */
  1865. + return __fpcmp_parts (&a, &b) ;
  1866. +}
  1867. +#endif /* L_ge_sf || L_ge_df */
  1868. +
  1869. +#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
  1870. +CMPtype
  1871. +_lt_f2 (FLO_type arg_a, FLO_type arg_b)
  1872. +{
  1873. + fp_number_type a;
  1874. + fp_number_type b;
  1875. + FLO_union_type au, bu;
  1876. +
  1877. + au.value = arg_a;
  1878. + bu.value = arg_b;
  1879. +
  1880. + unpack_d (&au, &a);
  1881. + unpack_d (&bu, &b);
  1882. +
  1883. + if (isnan (&a) || isnan (&b))
  1884. + return 1; /* false, truth < 0 */
  1885. +
  1886. + return __fpcmp_parts (&a, &b);
  1887. +}
  1888. +#endif /* L_lt_sf || L_lt_df */
  1889. +
  1890. +#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
  1891. +CMPtype
  1892. +_le_f2 (FLO_type arg_a, FLO_type arg_b)
  1893. +{
  1894. + fp_number_type a;
  1895. + fp_number_type b;
  1896. + FLO_union_type au, bu;
  1897. +
  1898. + au.value = arg_a;
  1899. + bu.value = arg_b;
  1900. +
  1901. + unpack_d (&au, &a);
  1902. + unpack_d (&bu, &b);
  1903. +
  1904. + if (isnan (&a) || isnan (&b))
  1905. + return 1; /* false, truth <= 0 */
  1906. +
  1907. + return __fpcmp_parts (&a, &b) ;
  1908. +}
  1909. +#endif /* L_le_sf || L_le_df */
  1910. +
  1911. +#endif /* ! US_SOFTWARE_GOFAST */
  1912. +
  1913. +#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
  1914. +CMPtype
  1915. +_unord_f2 (FLO_type arg_a, FLO_type arg_b)
  1916. +{
  1917. + fp_number_type a;
  1918. + fp_number_type b;
  1919. + FLO_union_type au, bu;
  1920. +
  1921. + au.value = arg_a;
  1922. + bu.value = arg_b;
  1923. +
  1924. + unpack_d (&au, &a);
  1925. + unpack_d (&bu, &b);
  1926. +
  1927. + return (isnan (&a) || isnan (&b));
  1928. +}
  1929. +#endif /* L_unord_sf || L_unord_df */
  1930. +
  1931. +#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
  1932. +FLO_type
  1933. +si_to_float (SItype arg_a)
  1934. +{
  1935. + fp_number_type in;
  1936. +
  1937. + in.class = CLASS_NUMBER;
  1938. + in.sign = arg_a < 0;
  1939. + if (!arg_a)
  1940. + {
  1941. + in.class = CLASS_ZERO;
  1942. + }
  1943. + else
  1944. + {
  1945. + in.normal_exp = FRACBITS + NGARDS;
  1946. + if (in.sign)
  1947. + {
  1948. + /* Special case for minint, since there is no +ve integer
  1949. + representation for it */
  1950. + if (arg_a == (- MAX_SI_INT - 1))
  1951. + {
  1952. + return (FLO_type)(- MAX_SI_INT - 1);
  1953. + }
  1954. + in.fraction.ll = (-arg_a);
  1955. + }
  1956. + else
  1957. + in.fraction.ll = arg_a;
  1958. +
  1959. + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
  1960. + {
  1961. + in.fraction.ll <<= 1;
  1962. + in.normal_exp -= 1;
  1963. + }
  1964. + }
  1965. + return pack_d (&in);
  1966. +}
  1967. +#endif /* L_si_to_sf || L_si_to_df */
  1968. +
  1969. +#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
  1970. +FLO_type
  1971. +usi_to_float (USItype arg_a)
  1972. +{
  1973. + fp_number_type in;
  1974. +
  1975. + in.sign = 0;
  1976. + if (!arg_a)
  1977. + {
  1978. + in.class = CLASS_ZERO;
  1979. + }
  1980. + else
  1981. + {
  1982. + in.class = CLASS_NUMBER;
  1983. + in.normal_exp = FRACBITS + NGARDS;
  1984. + in.fraction.ll = arg_a;
  1985. +
  1986. + while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
  1987. + {
  1988. + in.fraction.ll >>= 1;
  1989. + in.normal_exp += 1;
  1990. + }
  1991. + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
  1992. + {
  1993. + in.fraction.ll <<= 1;
  1994. + in.normal_exp -= 1;
  1995. + }
  1996. + }
  1997. + return pack_d (&in);
  1998. +}
  1999. +#endif
  2000. +
  2001. +#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
  2002. +SItype
  2003. +float_to_si (FLO_type arg_a)
  2004. +{
  2005. + fp_number_type a;
  2006. + SItype tmp;
  2007. + FLO_union_type au;
  2008. +
  2009. + au.value = arg_a;
  2010. + unpack_d (&au, &a);
  2011. +
  2012. + if (iszero (&a))
  2013. + return 0;
  2014. + if (isnan (&a))
  2015. + return 0;
  2016. + /* get reasonable MAX_SI_INT... */
  2017. + if (isinf (&a))
  2018. + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
  2019. + /* it is a number, but a small one */
  2020. + if (a.normal_exp < 0)
  2021. + return 0;
  2022. + if (a.normal_exp > BITS_PER_SI - 2)
  2023. + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
  2024. + tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
  2025. + return a.sign ? (-tmp) : (tmp);
  2026. +}
  2027. +#endif /* L_sf_to_si || L_df_to_si */
  2028. +
  2029. +#if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
  2030. +#if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
  2031. +/* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
  2032. + we also define them for GOFAST because the ones in libgcc2.c have the
  2033. + wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
  2034. + out of libgcc2.c. We can't define these here if not GOFAST because then
  2035. + there'd be duplicate copies. */
  2036. +
  2037. +USItype
  2038. +float_to_usi (FLO_type arg_a)
  2039. +{
  2040. + fp_number_type a;
  2041. + FLO_union_type au;
  2042. +
  2043. + au.value = arg_a;
  2044. + unpack_d (&au, &a);
  2045. +
  2046. + if (iszero (&a))
  2047. + return 0;
  2048. + if (isnan (&a))
  2049. + return 0;
  2050. + /* it is a negative number */
  2051. + if (a.sign)
  2052. + return 0;
  2053. + /* get reasonable MAX_USI_INT... */
  2054. + if (isinf (&a))
  2055. + return MAX_USI_INT;
  2056. + /* it is a number, but a small one */
  2057. + if (a.normal_exp < 0)
  2058. + return 0;
  2059. + if (a.normal_exp > BITS_PER_SI - 1)
  2060. + return MAX_USI_INT;
  2061. + else if (a.normal_exp > (FRACBITS + NGARDS))
  2062. + return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
  2063. + else
  2064. + return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
  2065. +}
  2066. +#endif /* US_SOFTWARE_GOFAST */
  2067. +#endif /* L_sf_to_usi || L_df_to_usi */
  2068. +
  2069. +#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
  2070. +FLO_type
  2071. +negate (FLO_type arg_a)
  2072. +{
  2073. + fp_number_type a;
  2074. + FLO_union_type au;
  2075. +
  2076. + au.value = arg_a;
  2077. + unpack_d (&au, &a);
  2078. +
  2079. + flip_sign (&a);
  2080. + return pack_d (&a);
  2081. +}
  2082. +#endif /* L_negate_sf || L_negate_df */
  2083. +
  2084. +#ifdef FLOAT
  2085. +
  2086. +#if defined(L_make_sf)
  2087. +SFtype
  2088. +__make_fp(fp_class_type class,
  2089. + unsigned int sign,
  2090. + int exp,
  2091. + USItype frac)
  2092. +{
  2093. + fp_number_type in;
  2094. +
  2095. + in.class = class;
  2096. + in.sign = sign;
  2097. + in.normal_exp = exp;
  2098. + in.fraction.ll = frac;
  2099. + return pack_d (&in);
  2100. +}
  2101. +#endif /* L_make_sf */
  2102. +
  2103. +#ifndef FLOAT_ONLY
  2104. +
  2105. +/* This enables one to build an fp library that supports float but not double.
  2106. + Otherwise, we would get an undefined reference to __make_dp.
  2107. + This is needed for some 8-bit ports that can't handle well values that
  2108. + are 8-bytes in size, so we just don't support double for them at all. */
  2109. +
  2110. +#if defined(L_sf_to_df)
  2111. +DFtype
  2112. +sf_to_df (SFtype arg_a)
  2113. +{
  2114. + fp_number_type in;
  2115. + FLO_union_type au;
  2116. +
  2117. + au.value = arg_a;
  2118. + unpack_d (&au, &in);
  2119. +
  2120. + return __make_dp (in.class, in.sign, in.normal_exp,
  2121. + ((UDItype) in.fraction.ll) << F_D_BITOFF);
  2122. +}
  2123. +#endif /* L_sf_to_df */
  2124. +
  2125. +#if defined(L_sf_to_tf) && defined(TMODES)
  2126. +TFtype
  2127. +sf_to_tf (SFtype arg_a)
  2128. +{
  2129. + fp_number_type in;
  2130. + FLO_union_type au;
  2131. +
  2132. + au.value = arg_a;
  2133. + unpack_d (&au, &in);
  2134. +
  2135. + return __make_tp (in.class, in.sign, in.normal_exp,
  2136. + ((UTItype) in.fraction.ll) << F_T_BITOFF);
  2137. +}
  2138. +#endif /* L_sf_to_df */
  2139. +
  2140. +#endif /* ! FLOAT_ONLY */
  2141. +#endif /* FLOAT */
  2142. +
  2143. +#ifndef FLOAT
  2144. +
  2145. +extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
  2146. +
  2147. +#if defined(L_make_df)
  2148. +DFtype
  2149. +__make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
  2150. +{
  2151. + fp_number_type in;
  2152. +
  2153. + in.class = class;
  2154. + in.sign = sign;
  2155. + in.normal_exp = exp;
  2156. + in.fraction.ll = frac;
  2157. + return pack_d (&in);
  2158. +}
  2159. +#endif /* L_make_df */
  2160. +
  2161. +#if defined(L_df_to_sf)
  2162. +SFtype
  2163. +df_to_sf (DFtype arg_a)
  2164. +{
  2165. + fp_number_type in;
  2166. + USItype sffrac;
  2167. + FLO_union_type au;
  2168. +
  2169. + au.value = arg_a;
  2170. + unpack_d (&au, &in);
  2171. +
  2172. + sffrac = in.fraction.ll >> F_D_BITOFF;
  2173. +
  2174. + /* We set the lowest guard bit in SFFRAC if we discarded any non
  2175. + zero bits. */
  2176. + if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
  2177. + sffrac |= 1;
  2178. +
  2179. + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
  2180. +}
  2181. +#endif /* L_df_to_sf */
  2182. +
  2183. +#if defined(L_df_to_tf) && defined(TMODES) \
  2184. + && !defined(FLOAT) && !defined(TFLOAT)
  2185. +TFtype
  2186. +df_to_tf (DFtype arg_a)
  2187. +{
  2188. + fp_number_type in;
  2189. + FLO_union_type au;
  2190. +
  2191. + au.value = arg_a;
  2192. + unpack_d (&au, &in);
  2193. +
  2194. + return __make_tp (in.class, in.sign, in.normal_exp,
  2195. + ((UTItype) in.fraction.ll) << D_T_BITOFF);
  2196. +}
  2197. +#endif /* L_sf_to_df */
  2198. +
  2199. +#ifdef TFLOAT
  2200. +#if defined(L_make_tf)
  2201. +TFtype
  2202. +__make_tp(fp_class_type class,
  2203. + unsigned int sign,
  2204. + int exp,
  2205. + UTItype frac)
  2206. +{
  2207. + fp_number_type in;
  2208. +
  2209. + in.class = class;
  2210. + in.sign = sign;
  2211. + in.normal_exp = exp;
  2212. + in.fraction.ll = frac;
  2213. + return pack_d (&in);
  2214. +}
  2215. +#endif /* L_make_tf */
  2216. +
  2217. +#if defined(L_tf_to_df)
  2218. +DFtype
  2219. +tf_to_df (TFtype arg_a)
  2220. +{
  2221. + fp_number_type in;
  2222. + UDItype sffrac;
  2223. + FLO_union_type au;
  2224. +
  2225. + au.value = arg_a;
  2226. + unpack_d (&au, &in);
  2227. +
  2228. + sffrac = in.fraction.ll >> D_T_BITOFF;
  2229. +
  2230. + /* We set the lowest guard bit in SFFRAC if we discarded any non
  2231. + zero bits. */
  2232. + if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
  2233. + sffrac |= 1;
  2234. +
  2235. + return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
  2236. +}
  2237. +#endif /* L_tf_to_df */
  2238. +
  2239. +#if defined(L_tf_to_sf)
  2240. +SFtype
  2241. +tf_to_sf (TFtype arg_a)
  2242. +{
  2243. + fp_number_type in;
  2244. + USItype sffrac;
  2245. + FLO_union_type au;
  2246. +
  2247. + au.value = arg_a;
  2248. + unpack_d (&au, &in);
  2249. +
  2250. + sffrac = in.fraction.ll >> F_T_BITOFF;
  2251. +
  2252. + /* We set the lowest guard bit in SFFRAC if we discarded any non
  2253. + zero bits. */
  2254. + if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
  2255. + sffrac |= 1;
  2256. +
  2257. + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
  2258. +}
  2259. +#endif /* L_tf_to_sf */
  2260. +#endif /* TFLOAT */
  2261. +
  2262. +#endif /* ! FLOAT */
  2263. +#endif /* !EXTENDED_FLOAT_STUBS */
  2264. --- gcc-3.4.3/gcc/config/nios2/nios2-fp-bit.c
  2265. +++ gcc-3.4.3-nios2/gcc/config/nios2/nios2-fp-bit.c
  2266. @@ -0,0 +1,1652 @@
  2267. +#define FLOAT
  2268. +/* This is a software floating point library which can be used
  2269. + for targets without hardware floating point.
  2270. + Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
  2271. + Free Software Foundation, Inc.
  2272. +
  2273. +This file is free software; you can redistribute it and/or modify it
  2274. +under the terms of the GNU General Public License as published by the
  2275. +Free Software Foundation; either version 2, or (at your option) any
  2276. +later version.
  2277. +
  2278. +In addition to the permissions in the GNU General Public License, the
  2279. +Free Software Foundation gives you unlimited permission to link the
  2280. +compiled version of this file with other programs, and to distribute
  2281. +those programs without any restriction coming from the use of this
  2282. +file. (The General Public License restrictions do apply in other
  2283. +respects; for example, they cover modification of the file, and
  2284. +distribution when not linked into another program.)
  2285. +
  2286. +This file is distributed in the hope that it will be useful, but
  2287. +WITHOUT ANY WARRANTY; without even the implied warranty of
  2288. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2289. +General Public License for more details.
  2290. +
  2291. +You should have received a copy of the GNU General Public License
  2292. +along with this program; see the file COPYING. If not, write to
  2293. +the Free Software Foundation, 59 Temple Place - Suite 330,
  2294. +Boston, MA 02111-1307, USA. */
  2295. +
  2296. +/* As a special exception, if you link this library with other files,
  2297. + some of which are compiled with GCC, to produce an executable,
  2298. + this library does not by itself cause the resulting executable
  2299. + to be covered by the GNU General Public License.
  2300. + This exception does not however invalidate any other reasons why
  2301. + the executable file might be covered by the GNU General Public License. */
  2302. +
  2303. +/* This implements IEEE 754 format arithmetic, but does not provide a
  2304. + mechanism for setting the rounding mode, or for generating or handling
  2305. + exceptions.
  2306. +
  2307. + The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
  2308. + Wilson, all of Cygnus Support. */
  2309. +
  2310. +/* The intended way to use this file is to make two copies, add `#define FLOAT'
  2311. + to one copy, then compile both copies and add them to libgcc.a. */
  2312. +
  2313. +#include "tconfig.h"
  2314. +#include "coretypes.h"
  2315. +#include "tm.h"
  2316. +#include "config/fp-bit.h"
  2317. +
  2318. +/* The following macros can be defined to change the behavior of this file:
  2319. + FLOAT: Implement a `float', aka SFmode, fp library. If this is not
  2320. + defined, then this file implements a `double', aka DFmode, fp library.
  2321. + FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
  2322. + don't include float->double conversion which requires the double library.
  2323. + This is useful only for machines which can't support doubles, e.g. some
  2324. + 8-bit processors.
  2325. + CMPtype: Specify the type that floating point compares should return.
  2326. + This defaults to SItype, aka int.
  2327. + US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
  2328. + US Software goFast library.
  2329. + _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
  2330. + two integers to the FLO_union_type.
  2331. + NO_DENORMALS: Disable handling of denormals.
  2332. + NO_NANS: Disable nan and infinity handling
  2333. + SMALL_MACHINE: Useful when operations on QIs and HIs are faster
  2334. + than on an SI */
  2335. +
  2336. +/* We don't currently support extended floats (long doubles) on machines
  2337. + without hardware to deal with them.
  2338. +
  2339. + These stubs are just to keep the linker from complaining about unresolved
  2340. + references which can be pulled in from libio & libstdc++, even if the
  2341. + user isn't using long doubles. However, they may generate an unresolved
  2342. + external to abort if abort is not used by the function, and the stubs
  2343. + are referenced from within libc, since libgcc goes before and after the
  2344. + system library. */
  2345. +
  2346. +#ifdef DECLARE_LIBRARY_RENAMES
  2347. + DECLARE_LIBRARY_RENAMES
  2348. +#endif
  2349. +
  2350. +#ifdef EXTENDED_FLOAT_STUBS
  2351. +extern void abort (void);
  2352. +void __extendsfxf2 (void) { abort(); }
  2353. +void __extenddfxf2 (void) { abort(); }
  2354. +void __truncxfdf2 (void) { abort(); }
  2355. +void __truncxfsf2 (void) { abort(); }
  2356. +void __fixxfsi (void) { abort(); }
  2357. +void __floatsixf (void) { abort(); }
  2358. +void __addxf3 (void) { abort(); }
  2359. +void __subxf3 (void) { abort(); }
  2360. +void __mulxf3 (void) { abort(); }
  2361. +void __divxf3 (void) { abort(); }
  2362. +void __negxf2 (void) { abort(); }
  2363. +void __eqxf2 (void) { abort(); }
  2364. +void __nexf2 (void) { abort(); }
  2365. +void __gtxf2 (void) { abort(); }
  2366. +void __gexf2 (void) { abort(); }
  2367. +void __lexf2 (void) { abort(); }
  2368. +void __ltxf2 (void) { abort(); }
  2369. +
  2370. +void __extendsftf2 (void) { abort(); }
  2371. +void __extenddftf2 (void) { abort(); }
  2372. +void __trunctfdf2 (void) { abort(); }
  2373. +void __trunctfsf2 (void) { abort(); }
  2374. +void __fixtfsi (void) { abort(); }
  2375. +void __floatsitf (void) { abort(); }
  2376. +void __addtf3 (void) { abort(); }
  2377. +void __subtf3 (void) { abort(); }
  2378. +void __multf3 (void) { abort(); }
  2379. +void __divtf3 (void) { abort(); }
  2380. +void __negtf2 (void) { abort(); }
  2381. +void __eqtf2 (void) { abort(); }
  2382. +void __netf2 (void) { abort(); }
  2383. +void __gttf2 (void) { abort(); }
  2384. +void __getf2 (void) { abort(); }
  2385. +void __letf2 (void) { abort(); }
  2386. +void __lttf2 (void) { abort(); }
  2387. +#else /* !EXTENDED_FLOAT_STUBS, rest of file */
  2388. +
  2389. +/* IEEE "special" number predicates */
  2390. +
  2391. +#ifdef NO_NANS
  2392. +
  2393. +#define nan() 0
  2394. +#define isnan(x) 0
  2395. +#define isinf(x) 0
  2396. +#else
  2397. +
  2398. +#if defined L_thenan_sf
  2399. +const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
  2400. +#elif defined L_thenan_df
  2401. +const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
  2402. +#elif defined L_thenan_tf
  2403. +const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
  2404. +#elif defined TFLOAT
  2405. +extern const fp_number_type __thenan_tf;
  2406. +#elif defined FLOAT
  2407. +extern const fp_number_type __thenan_sf;
  2408. +#else
  2409. +extern const fp_number_type __thenan_df;
  2410. +#endif
  2411. +
  2412. +INLINE
  2413. +static fp_number_type *
  2414. +nan (void)
  2415. +{
  2416. + /* Discard the const qualifier... */
  2417. +#ifdef TFLOAT
  2418. + return (fp_number_type *) (& __thenan_tf);
  2419. +#elif defined FLOAT
  2420. + return (fp_number_type *) (& __thenan_sf);
  2421. +#else
  2422. + return (fp_number_type *) (& __thenan_df);
  2423. +#endif
  2424. +}
  2425. +
  2426. +INLINE
  2427. +static int
  2428. +isnan ( fp_number_type * x)
  2429. +{
  2430. + return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
  2431. +}
  2432. +
  2433. +INLINE
  2434. +static int
  2435. +isinf ( fp_number_type * x)
  2436. +{
  2437. + return x->class == CLASS_INFINITY;
  2438. +}
  2439. +
  2440. +#endif /* NO_NANS */
  2441. +
  2442. +INLINE
  2443. +static int
  2444. +iszero ( fp_number_type * x)
  2445. +{
  2446. + return x->class == CLASS_ZERO;
  2447. +}
  2448. +
  2449. +INLINE
  2450. +static void
  2451. +flip_sign ( fp_number_type * x)
  2452. +{
  2453. + x->sign = !x->sign;
  2454. +}
  2455. +
  2456. +extern FLO_type pack_d ( fp_number_type * );
  2457. +
  2458. +#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
  2459. +FLO_type
  2460. +pack_d ( fp_number_type * src)
  2461. +{
  2462. + FLO_union_type dst;
  2463. + fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
  2464. + int sign = src->sign;
  2465. + int exp = 0;
  2466. +
  2467. + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
  2468. + {
  2469. + /* We can't represent these values accurately. By using the
  2470. + largest possible magnitude, we guarantee that the conversion
  2471. + of infinity is at least as big as any finite number. */
  2472. + exp = EXPMAX;
  2473. + fraction = ((fractype) 1 << FRACBITS) - 1;
  2474. + }
  2475. + else if (isnan (src))
  2476. + {
  2477. + exp = EXPMAX;
  2478. + if (src->class == CLASS_QNAN || 1)
  2479. + {
  2480. +#ifdef QUIET_NAN_NEGATED
  2481. + fraction |= QUIET_NAN - 1;
  2482. +#else
  2483. + fraction |= QUIET_NAN;
  2484. +#endif
  2485. + }
  2486. + }
  2487. + else if (isinf (src))
  2488. + {
  2489. + exp = EXPMAX;
  2490. + fraction = 0;
  2491. + }
  2492. + else if (iszero (src))
  2493. + {
  2494. + exp = 0;
  2495. + fraction = 0;
  2496. + }
  2497. + else if (fraction == 0)
  2498. + {
  2499. + exp = 0;
  2500. + }
  2501. + else
  2502. + {
  2503. + if (src->normal_exp < NORMAL_EXPMIN)
  2504. + {
  2505. +#ifdef NO_DENORMALS
  2506. + /* Go straight to a zero representation if denormals are not
  2507. + supported. The denormal handling would be harmless but
  2508. + isn't unnecessary. */
  2509. + exp = 0;
  2510. + fraction = 0;
  2511. +#else /* NO_DENORMALS */
  2512. + /* This number's exponent is too low to fit into the bits
  2513. + available in the number, so we'll store 0 in the exponent and
  2514. + shift the fraction to the right to make up for it. */
  2515. +
  2516. + int shift = NORMAL_EXPMIN - src->normal_exp;
  2517. +
  2518. + exp = 0;
  2519. +
  2520. + if (shift > FRAC_NBITS - NGARDS)
  2521. + {
  2522. + /* No point shifting, since it's more that 64 out. */
  2523. + fraction = 0;
  2524. + }
  2525. + else
  2526. + {
  2527. + int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
  2528. + fraction = (fraction >> shift) | lowbit;
  2529. + }
  2530. + if ((fraction & GARDMASK) == GARDMSB)
  2531. + {
  2532. + if ((fraction & (1 << NGARDS)))
  2533. + fraction += GARDROUND + 1;
  2534. + }
  2535. + else
  2536. + {
  2537. + /* Add to the guards to round up. */
  2538. + fraction += GARDROUND;
  2539. + }
  2540. + /* Perhaps the rounding means we now need to change the
  2541. + exponent, because the fraction is no longer denormal. */
  2542. + if (fraction >= IMPLICIT_1)
  2543. + {
  2544. + exp += 1;
  2545. + }
  2546. + fraction >>= NGARDS;
  2547. +#endif /* NO_DENORMALS */
  2548. + }
  2549. + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
  2550. + && src->normal_exp > EXPBIAS)
  2551. + {
  2552. + exp = EXPMAX;
  2553. + fraction = 0;
  2554. + }
  2555. + else
  2556. + {
  2557. + exp = src->normal_exp + EXPBIAS;
  2558. + if (!ROUND_TOWARDS_ZERO)
  2559. + {
  2560. + /* IF the gard bits are the all zero, but the first, then we're
  2561. + half way between two numbers, choose the one which makes the
  2562. + lsb of the answer 0. */
  2563. + if ((fraction & GARDMASK) == GARDMSB)
  2564. + {
  2565. + if (fraction & (1 << NGARDS))
  2566. + fraction += GARDROUND + 1;
  2567. + }
  2568. + else
  2569. + {
  2570. + /* Add a one to the guards to round up */
  2571. + fraction += GARDROUND;
  2572. + }
  2573. + if (fraction >= IMPLICIT_2)
  2574. + {
  2575. + fraction >>= 1;
  2576. + exp += 1;
  2577. + }
  2578. + }
  2579. + fraction >>= NGARDS;
  2580. +
  2581. + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
  2582. + {
  2583. + /* Saturate on overflow. */
  2584. + exp = EXPMAX;
  2585. + fraction = ((fractype) 1 << FRACBITS) - 1;
  2586. + }
  2587. + }
  2588. + }
  2589. +
  2590. + /* We previously used bitfields to store the number, but this doesn't
  2591. + handle little/big endian systems conveniently, so use shifts and
  2592. + masks */
  2593. +#ifdef FLOAT_BIT_ORDER_MISMATCH
  2594. + dst.bits.fraction = fraction;
  2595. + dst.bits.exp = exp;
  2596. + dst.bits.sign = sign;
  2597. +#else
  2598. +# if defined TFLOAT && defined HALFFRACBITS
  2599. + {
  2600. + halffractype high, low, unity;
  2601. + int lowsign, lowexp;
  2602. +
  2603. + unity = (halffractype) 1 << HALFFRACBITS;
  2604. +
  2605. + /* Set HIGH to the high double's significand, masking out the implicit 1.
  2606. + Set LOW to the low double's full significand. */
  2607. + high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
  2608. + low = fraction & (unity * 2 - 1);
  2609. +
  2610. + /* Get the initial sign and exponent of the low double. */
  2611. + lowexp = exp - HALFFRACBITS - 1;
  2612. + lowsign = sign;
  2613. +
  2614. + /* HIGH should be rounded like a normal double, making |LOW| <=
  2615. + 0.5 ULP of HIGH. Assume round-to-nearest. */
  2616. + if (exp < EXPMAX)
  2617. + if (low > unity || (low == unity && (high & 1) == 1))
  2618. + {
  2619. + /* Round HIGH up and adjust LOW to match. */
  2620. + high++;
  2621. + if (high == unity)
  2622. + {
  2623. + /* May make it infinite, but that's OK. */
  2624. + high = 0;
  2625. + exp++;
  2626. + }
  2627. + low = unity * 2 - low;
  2628. + lowsign ^= 1;
  2629. + }
  2630. +
  2631. + high |= (halffractype) exp << HALFFRACBITS;
  2632. + high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
  2633. +
  2634. + if (exp == EXPMAX || exp == 0 || low == 0)
  2635. + low = 0;
  2636. + else
  2637. + {
  2638. + while (lowexp > 0 && low < unity)
  2639. + {
  2640. + low <<= 1;
  2641. + lowexp--;
  2642. + }
  2643. +
  2644. + if (lowexp <= 0)
  2645. + {
  2646. + halffractype roundmsb, round;
  2647. + int shift;
  2648. +
  2649. + shift = 1 - lowexp;
  2650. + roundmsb = (1 << (shift - 1));
  2651. + round = low & ((roundmsb << 1) - 1);
  2652. +
  2653. + low >>= shift;
  2654. + lowexp = 0;
  2655. +
  2656. + if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
  2657. + {
  2658. + low++;
  2659. + if (low == unity)
  2660. + /* LOW rounds up to the smallest normal number. */
  2661. + lowexp++;
  2662. + }
  2663. + }
  2664. +
  2665. + low &= unity - 1;
  2666. + low |= (halffractype) lowexp << HALFFRACBITS;
  2667. + low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
  2668. + }
  2669. + dst.value_raw = ((fractype) high << HALFSHIFT) | low;
  2670. + }
  2671. +# else
  2672. + dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
  2673. + dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
  2674. + dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
  2675. +# endif
  2676. +#endif
  2677. +
  2678. +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
  2679. +#ifdef TFLOAT
  2680. + {
  2681. + qrtrfractype tmp1 = dst.words[0];
  2682. + qrtrfractype tmp2 = dst.words[1];
  2683. + dst.words[0] = dst.words[3];
  2684. + dst.words[1] = dst.words[2];
  2685. + dst.words[2] = tmp2;
  2686. + dst.words[3] = tmp1;
  2687. + }
  2688. +#else
  2689. + {
  2690. + halffractype tmp = dst.words[0];
  2691. + dst.words[0] = dst.words[1];
  2692. + dst.words[1] = tmp;
  2693. + }
  2694. +#endif
  2695. +#endif
  2696. +
  2697. + return dst.value;
  2698. +}
  2699. +#endif
  2700. +
  2701. +#if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
  2702. +void
  2703. +unpack_d (FLO_union_type * src, fp_number_type * dst)
  2704. +{
  2705. + /* We previously used bitfields to store the number, but this doesn't
  2706. + handle little/big endian systems conveniently, so use shifts and
  2707. + masks */
  2708. + fractype fraction;
  2709. + int exp;
  2710. + int sign;
  2711. +
  2712. +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
  2713. + FLO_union_type swapped;
  2714. +
  2715. +#ifdef TFLOAT
  2716. + swapped.words[0] = src->words[3];
  2717. + swapped.words[1] = src->words[2];
  2718. + swapped.words[2] = src->words[1];
  2719. + swapped.words[3] = src->words[0];
  2720. +#else
  2721. + swapped.words[0] = src->words[1];
  2722. + swapped.words[1] = src->words[0];
  2723. +#endif
  2724. + src = &swapped;
  2725. +#endif
  2726. +
  2727. +#ifdef FLOAT_BIT_ORDER_MISMATCH
  2728. + fraction = src->bits.fraction;
  2729. + exp = src->bits.exp;
  2730. + sign = src->bits.sign;
  2731. +#else
  2732. +# if defined TFLOAT && defined HALFFRACBITS
  2733. + {
  2734. + halffractype high, low;
  2735. +
  2736. + high = src->value_raw >> HALFSHIFT;
  2737. + low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
  2738. +
  2739. + fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
  2740. + fraction <<= FRACBITS - HALFFRACBITS;
  2741. + exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
  2742. + sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
  2743. +
  2744. + if (exp != EXPMAX && exp != 0 && low != 0)
  2745. + {
  2746. + int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
  2747. + int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
  2748. + int shift;
  2749. + fractype xlow;
  2750. +
  2751. + xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
  2752. + if (lowexp)
  2753. + xlow |= (((halffractype)1) << HALFFRACBITS);
  2754. + else
  2755. + lowexp = 1;
  2756. + shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
  2757. + if (shift > 0)
  2758. + xlow <<= shift;
  2759. + else if (shift < 0)
  2760. + xlow >>= -shift;
  2761. + if (sign == lowsign)
  2762. + fraction += xlow;
  2763. + else if (fraction >= xlow)
  2764. + fraction -= xlow;
  2765. + else
  2766. + {
  2767. + /* The high part is a power of two but the full number is lower.
  2768. + This code will leave the implicit 1 in FRACTION, but we'd
  2769. + have added that below anyway. */
  2770. + fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
  2771. + exp--;
  2772. + }
  2773. + }
  2774. + }
  2775. +# else
  2776. + fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
  2777. + exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
  2778. + sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
  2779. +# endif
  2780. +#endif
  2781. +
  2782. + dst->sign = sign;
  2783. + if (exp == 0)
  2784. + {
  2785. + /* Hmm. Looks like 0 */
  2786. + if (fraction == 0
  2787. +#ifdef NO_DENORMALS
  2788. + || 1
  2789. +#endif
  2790. + )
  2791. + {
  2792. + /* tastes like zero */
  2793. + dst->class = CLASS_ZERO;
  2794. + }
  2795. + else
  2796. + {
  2797. + /* Zero exponent with nonzero fraction - it's denormalized,
  2798. + so there isn't a leading implicit one - we'll shift it so
  2799. + it gets one. */
  2800. + dst->normal_exp = exp - EXPBIAS + 1;
  2801. + fraction <<= NGARDS;
  2802. +
  2803. + dst->class = CLASS_NUMBER;
  2804. +#if 1
  2805. + while (fraction < IMPLICIT_1)
  2806. + {
  2807. + fraction <<= 1;
  2808. + dst->normal_exp--;
  2809. + }
  2810. +#endif
  2811. + dst->fraction.ll = fraction;
  2812. + }
  2813. + }
  2814. + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
  2815. + {
  2816. + /* Huge exponent*/
  2817. + if (fraction == 0)
  2818. + {
  2819. + /* Attached to a zero fraction - means infinity */
  2820. + dst->class = CLASS_INFINITY;
  2821. + }
  2822. + else
  2823. + {
  2824. + /* Nonzero fraction, means nan */
  2825. +#ifdef QUIET_NAN_NEGATED
  2826. + if ((fraction & QUIET_NAN) == 0)
  2827. +#else
  2828. + if (fraction & QUIET_NAN)
  2829. +#endif
  2830. + {
  2831. + dst->class = CLASS_QNAN;
  2832. + }
  2833. + else
  2834. + {
  2835. + dst->class = CLASS_SNAN;
  2836. + }
  2837. + /* Keep the fraction part as the nan number */
  2838. + dst->fraction.ll = fraction;
  2839. + }
  2840. + }
  2841. + else
  2842. + {
  2843. + /* Nothing strange about this number */
  2844. + dst->normal_exp = exp - EXPBIAS;
  2845. + dst->class = CLASS_NUMBER;
  2846. + dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
  2847. + }
  2848. +}
  2849. +#endif /* L_unpack_df || L_unpack_sf */
  2850. +
  2851. +#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
  2852. +static fp_number_type *
  2853. +_fpadd_parts (fp_number_type * a,
  2854. + fp_number_type * b,
  2855. + fp_number_type * tmp)
  2856. +{
  2857. + intfrac tfraction;
  2858. +
  2859. + /* Put commonly used fields in local variables. */
  2860. + int a_normal_exp;
  2861. + int b_normal_exp;
  2862. + fractype a_fraction;
  2863. + fractype b_fraction;
  2864. +
  2865. + if (isnan (a))
  2866. + {
  2867. + return a;
  2868. + }
  2869. + if (isnan (b))
  2870. + {
  2871. + return b;
  2872. + }
  2873. + if (isinf (a))
  2874. + {
  2875. + /* Adding infinities with opposite signs yields a NaN. */
  2876. + if (isinf (b) && a->sign != b->sign)
  2877. + return nan ();
  2878. + return a;
  2879. + }
  2880. + if (isinf (b))
  2881. + {
  2882. + return b;
  2883. + }
  2884. + if (iszero (b))
  2885. + {
  2886. + if (iszero (a))
  2887. + {
  2888. + *tmp = *a;
  2889. + tmp->sign = a->sign & b->sign;
  2890. + return tmp;
  2891. + }
  2892. + return a;
  2893. + }
  2894. + if (iszero (a))
  2895. + {
  2896. + return b;
  2897. + }
  2898. +
  2899. + /* Got two numbers. shift the smaller and increment the exponent till
  2900. + they're the same */
  2901. + {
  2902. + int diff;
  2903. +
  2904. + a_normal_exp = a->normal_exp;
  2905. + b_normal_exp = b->normal_exp;
  2906. + a_fraction = a->fraction.ll;
  2907. + b_fraction = b->fraction.ll;
  2908. +
  2909. + diff = a_normal_exp - b_normal_exp;
  2910. +
  2911. + if (diff < 0)
  2912. + diff = -diff;
  2913. + if (diff < FRAC_NBITS)
  2914. + {
  2915. + /* ??? This does shifts one bit at a time. Optimize. */
  2916. + while (a_normal_exp > b_normal_exp)
  2917. + {
  2918. + b_normal_exp++;
  2919. + LSHIFT (b_fraction);
  2920. + }
  2921. + while (b_normal_exp > a_normal_exp)
  2922. + {
  2923. + a_normal_exp++;
  2924. + LSHIFT (a_fraction);
  2925. + }
  2926. + }
  2927. + else
  2928. + {
  2929. + /* Somethings's up.. choose the biggest */
  2930. + if (a_normal_exp > b_normal_exp)
  2931. + {
  2932. + b_normal_exp = a_normal_exp;
  2933. + b_fraction = 0;
  2934. + }
  2935. + else
  2936. + {
  2937. + a_normal_exp = b_normal_exp;
  2938. + a_fraction = 0;
  2939. + }
  2940. + }
  2941. + }
  2942. +
  2943. + if (a->sign != b->sign)
  2944. + {
  2945. + if (a->sign)
  2946. + {
  2947. + tfraction = -a_fraction + b_fraction;
  2948. + }
  2949. + else
  2950. + {
  2951. + tfraction = a_fraction - b_fraction;
  2952. + }
  2953. + if (tfraction >= 0)
  2954. + {
  2955. + tmp->sign = 0;
  2956. + tmp->normal_exp = a_normal_exp;
  2957. + tmp->fraction.ll = tfraction;
  2958. + }
  2959. + else
  2960. + {
  2961. + tmp->sign = 1;
  2962. + tmp->normal_exp = a_normal_exp;
  2963. + tmp->fraction.ll = -tfraction;
  2964. + }
  2965. + /* and renormalize it */
  2966. +
  2967. + while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
  2968. + {
  2969. + tmp->fraction.ll <<= 1;
  2970. + tmp->normal_exp--;
  2971. + }
  2972. + }
  2973. + else
  2974. + {
  2975. + tmp->sign = a->sign;
  2976. + tmp->normal_exp = a_normal_exp;
  2977. + tmp->fraction.ll = a_fraction + b_fraction;
  2978. + }
  2979. + tmp->class = CLASS_NUMBER;
  2980. + /* Now the fraction is added, we have to shift down to renormalize the
  2981. + number */
  2982. +
  2983. + if (tmp->fraction.ll >= IMPLICIT_2)
  2984. + {
  2985. + LSHIFT (tmp->fraction.ll);
  2986. + tmp->normal_exp++;
  2987. + }
  2988. + return tmp;
  2989. +
  2990. +}
  2991. +
  2992. +FLO_type
  2993. +add (FLO_type arg_a, FLO_type arg_b)
  2994. +{
  2995. + fp_number_type a;
  2996. + fp_number_type b;
  2997. + fp_number_type tmp;
  2998. + fp_number_type *res;
  2999. + FLO_union_type au, bu;
  3000. +
  3001. + au.value = arg_a;
  3002. + bu.value = arg_b;
  3003. +
  3004. + unpack_d (&au, &a);
  3005. + unpack_d (&bu, &b);
  3006. +
  3007. + res = _fpadd_parts (&a, &b, &tmp);
  3008. +
  3009. + return pack_d (res);
  3010. +}
  3011. +
  3012. +FLO_type
  3013. +sub (FLO_type arg_a, FLO_type arg_b)
  3014. +{
  3015. + fp_number_type a;
  3016. + fp_number_type b;
  3017. + fp_number_type tmp;
  3018. + fp_number_type *res;
  3019. + FLO_union_type au, bu;
  3020. +
  3021. + au.value = arg_a;
  3022. + bu.value = arg_b;
  3023. +
  3024. + unpack_d (&au, &a);
  3025. + unpack_d (&bu, &b);
  3026. +
  3027. + b.sign ^= 1;
  3028. +
  3029. + res = _fpadd_parts (&a, &b, &tmp);
  3030. +
  3031. + return pack_d (res);
  3032. +}
  3033. +#endif /* L_addsub_sf || L_addsub_df */
  3034. +
  3035. +#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
  3036. +static inline __attribute__ ((__always_inline__)) fp_number_type *
  3037. +_fpmul_parts ( fp_number_type * a,
  3038. + fp_number_type * b,
  3039. + fp_number_type * tmp)
  3040. +{
  3041. + fractype low = 0;
  3042. + fractype high = 0;
  3043. +
  3044. + if (isnan (a))
  3045. + {
  3046. + a->sign = a->sign != b->sign;
  3047. + return a;
  3048. + }
  3049. + if (isnan (b))
  3050. + {
  3051. + b->sign = a->sign != b->sign;
  3052. + return b;
  3053. + }
  3054. + if (isinf (a))
  3055. + {
  3056. + if (iszero (b))
  3057. + return nan ();
  3058. + a->sign = a->sign != b->sign;
  3059. + return a;
  3060. + }
  3061. + if (isinf (b))
  3062. + {
  3063. + if (iszero (a))
  3064. + {
  3065. + return nan ();
  3066. + }
  3067. + b->sign = a->sign != b->sign;
  3068. + return b;
  3069. + }
  3070. + if (iszero (a))
  3071. + {
  3072. + a->sign = a->sign != b->sign;
  3073. + return a;
  3074. + }
  3075. + if (iszero (b))
  3076. + {
  3077. + b->sign = a->sign != b->sign;
  3078. + return b;
  3079. + }
  3080. +
  3081. + /* Calculate the mantissa by multiplying both numbers to get a
  3082. + twice-as-wide number. */
  3083. + {
  3084. +#if defined(NO_DI_MODE) || defined(TFLOAT)
  3085. + {
  3086. + fractype x = a->fraction.ll;
  3087. + fractype ylow = b->fraction.ll;
  3088. + fractype yhigh = 0;
  3089. + int bit;
  3090. +
  3091. + /* ??? This does multiplies one bit at a time. Optimize. */
  3092. + for (bit = 0; bit < FRAC_NBITS; bit++)
  3093. + {
  3094. + int carry;
  3095. +
  3096. + if (x & 1)
  3097. + {
  3098. + carry = (low += ylow) < ylow;
  3099. + high += yhigh + carry;
  3100. + }
  3101. + yhigh <<= 1;
  3102. + if (ylow & FRACHIGH)
  3103. + {
  3104. + yhigh |= 1;
  3105. + }
  3106. + ylow <<= 1;
  3107. + x >>= 1;
  3108. + }
  3109. + }
  3110. +#elif defined(FLOAT)
  3111. + /* Multiplying two USIs to get a UDI, we're safe. */
  3112. + {
  3113. + UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
  3114. +
  3115. + high = answer >> BITS_PER_SI;
  3116. + low = answer;
  3117. + }
  3118. +#else
  3119. + /* fractype is DImode, but we need the result to be twice as wide.
  3120. + Assuming a widening multiply from DImode to TImode is not
  3121. + available, build one by hand. */
  3122. + {
  3123. + USItype nl = a->fraction.ll;
  3124. + USItype nh = a->fraction.ll >> BITS_PER_SI;
  3125. + USItype ml = b->fraction.ll;
  3126. + USItype mh = b->fraction.ll >> BITS_PER_SI;
  3127. + UDItype pp_ll = (UDItype) ml * nl;
  3128. + UDItype pp_hl = (UDItype) mh * nl;
  3129. + UDItype pp_lh = (UDItype) ml * nh;
  3130. + UDItype pp_hh = (UDItype) mh * nh;
  3131. + UDItype res2 = 0;
  3132. + UDItype res0 = 0;
  3133. + UDItype ps_hh__ = pp_hl + pp_lh;
  3134. + if (ps_hh__ < pp_hl)
  3135. + res2 += (UDItype)1 << BITS_PER_SI;
  3136. + pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
  3137. + res0 = pp_ll + pp_hl;
  3138. + if (res0 < pp_ll)
  3139. + res2++;
  3140. + res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
  3141. + high = res2;
  3142. + low = res0;
  3143. + }
  3144. +#endif
  3145. + }
  3146. +
  3147. + tmp->normal_exp = a->normal_exp + b->normal_exp
  3148. + + FRAC_NBITS - (FRACBITS + NGARDS);
  3149. + tmp->sign = a->sign != b->sign;
  3150. + while (high >= IMPLICIT_2)
  3151. + {
  3152. + tmp->normal_exp++;
  3153. + if (high & 1)
  3154. + {
  3155. + low >>= 1;
  3156. + low |= FRACHIGH;
  3157. + }
  3158. + high >>= 1;
  3159. + }
  3160. + while (high < IMPLICIT_1)
  3161. + {
  3162. + tmp->normal_exp--;
  3163. +
  3164. + high <<= 1;
  3165. + if (low & FRACHIGH)
  3166. + high |= 1;
  3167. + low <<= 1;
  3168. + }
  3169. + /* rounding is tricky. if we only round if it won't make us round later. */
  3170. +#if 0
  3171. + if (low & FRACHIGH2)
  3172. + {
  3173. + if (((high & GARDMASK) != GARDMSB)
  3174. + && (((high + 1) & GARDMASK) == GARDMSB))
  3175. + {
  3176. + /* don't round, it gets done again later. */
  3177. + }
  3178. + else
  3179. + {
  3180. + high++;
  3181. + }
  3182. + }
  3183. +#endif
  3184. + if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
  3185. + {
  3186. + if (high & (1 << NGARDS))
  3187. + {
  3188. + /* half way, so round to even */
  3189. + high += GARDROUND + 1;
  3190. + }
  3191. + else if (low)
  3192. + {
  3193. + /* but we really weren't half way */
  3194. + high += GARDROUND + 1;
  3195. + }
  3196. + }
  3197. + tmp->fraction.ll = high;
  3198. + tmp->class = CLASS_NUMBER;
  3199. + return tmp;
  3200. +}
  3201. +
  3202. +FLO_type
  3203. +multiply (FLO_type arg_a, FLO_type arg_b)
  3204. +{
  3205. + fp_number_type a;
  3206. + fp_number_type b;
  3207. + fp_number_type tmp;
  3208. + fp_number_type *res;
  3209. + FLO_union_type au, bu;
  3210. +
  3211. + au.value = arg_a;
  3212. + bu.value = arg_b;
  3213. +
  3214. + unpack_d (&au, &a);
  3215. + unpack_d (&bu, &b);
  3216. +
  3217. + res = _fpmul_parts (&a, &b, &tmp);
  3218. +
  3219. + return pack_d (res);
  3220. +}
  3221. +#endif /* L_mul_sf || L_mul_df */
  3222. +
  3223. +#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
  3224. +static inline __attribute__ ((__always_inline__)) fp_number_type *
  3225. +_fpdiv_parts (fp_number_type * a,
  3226. + fp_number_type * b)
  3227. +{
  3228. + fractype bit;
  3229. + fractype numerator;
  3230. + fractype denominator;
  3231. + fractype quotient;
  3232. +
  3233. + if (isnan (a))
  3234. + {
  3235. + return a;
  3236. + }
  3237. + if (isnan (b))
  3238. + {
  3239. + return b;
  3240. + }
  3241. +
  3242. + a->sign = a->sign ^ b->sign;
  3243. +
  3244. + if (isinf (a) || iszero (a))
  3245. + {
  3246. + if (a->class == b->class)
  3247. + return nan ();
  3248. + return a;
  3249. + }
  3250. +
  3251. + if (isinf (b))
  3252. + {
  3253. + a->fraction.ll = 0;
  3254. + a->normal_exp = 0;
  3255. + return a;
  3256. + }
  3257. + if (iszero (b))
  3258. + {
  3259. + a->class = CLASS_INFINITY;
  3260. + return a;
  3261. + }
  3262. +
  3263. + /* Calculate the mantissa by multiplying both 64bit numbers to get a
  3264. + 128 bit number */
  3265. + {
  3266. + /* quotient =
  3267. + ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
  3268. + */
  3269. +
  3270. + a->normal_exp = a->normal_exp - b->normal_exp;
  3271. + numerator = a->fraction.ll;
  3272. + denominator = b->fraction.ll;
  3273. +
  3274. + if (numerator < denominator)
  3275. + {
  3276. + /* Fraction will be less than 1.0 */
  3277. + numerator *= 2;
  3278. + a->normal_exp--;
  3279. + }
  3280. + bit = IMPLICIT_1;
  3281. + quotient = 0;
  3282. + /* ??? Does divide one bit at a time. Optimize. */
  3283. + while (bit)
  3284. + {
  3285. + if (numerator >= denominator)
  3286. + {
  3287. + quotient |= bit;
  3288. + numerator -= denominator;
  3289. + }
  3290. + bit >>= 1;
  3291. + numerator *= 2;
  3292. + }
  3293. +
  3294. + if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
  3295. + {
  3296. + if (quotient & (1 << NGARDS))
  3297. + {
  3298. + /* half way, so round to even */
  3299. + quotient += GARDROUND + 1;
  3300. + }
  3301. + else if (numerator)
  3302. + {
  3303. + /* but we really weren't half way, more bits exist */
  3304. + quotient += GARDROUND + 1;
  3305. + }
  3306. + }
  3307. +
  3308. + a->fraction.ll = quotient;
  3309. + return (a);
  3310. + }
  3311. +}
  3312. +
  3313. +FLO_type
  3314. +divide (FLO_type arg_a, FLO_type arg_b)
  3315. +{
  3316. + fp_number_type a;
  3317. + fp_number_type b;
  3318. + fp_number_type *res;
  3319. + FLO_union_type au, bu;
  3320. +
  3321. + au.value = arg_a;
  3322. + bu.value = arg_b;
  3323. +
  3324. + unpack_d (&au, &a);
  3325. + unpack_d (&bu, &b);
  3326. +
  3327. + res = _fpdiv_parts (&a, &b);
  3328. +
  3329. + return pack_d (res);
  3330. +}
  3331. +#endif /* L_div_sf || L_div_df */
  3332. +
  3333. +#if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
  3334. + || defined(L_fpcmp_parts_tf)
  3335. +/* according to the demo, fpcmp returns a comparison with 0... thus
  3336. + a<b -> -1
  3337. + a==b -> 0
  3338. + a>b -> +1
  3339. + */
  3340. +
  3341. +int
  3342. +__fpcmp_parts (fp_number_type * a, fp_number_type * b)
  3343. +{
  3344. +#if 0
  3345. + /* either nan -> unordered. Must be checked outside of this routine. */
  3346. + if (isnan (a) && isnan (b))
  3347. + {
  3348. + return 1; /* still unordered! */
  3349. + }
  3350. +#endif
  3351. +
  3352. + if (isnan (a) || isnan (b))
  3353. + {
  3354. + return 1; /* how to indicate unordered compare? */
  3355. + }
  3356. + if (isinf (a) && isinf (b))
  3357. + {
  3358. + /* +inf > -inf, but +inf != +inf */
  3359. + /* b \a| +inf(0)| -inf(1)
  3360. + ______\+--------+--------
  3361. + +inf(0)| a==b(0)| a<b(-1)
  3362. + -------+--------+--------
  3363. + -inf(1)| a>b(1) | a==b(0)
  3364. + -------+--------+--------
  3365. + So since unordered must be nonzero, just line up the columns...
  3366. + */
  3367. + return b->sign - a->sign;
  3368. + }
  3369. + /* but not both... */
  3370. + if (isinf (a))
  3371. + {
  3372. + return a->sign ? -1 : 1;
  3373. + }
  3374. + if (isinf (b))
  3375. + {
  3376. + return b->sign ? 1 : -1;
  3377. + }
  3378. + if (iszero (a) && iszero (b))
  3379. + {
  3380. + return 0;
  3381. + }
  3382. + if (iszero (a))
  3383. + {
  3384. + return b->sign ? 1 : -1;
  3385. + }
  3386. + if (iszero (b))
  3387. + {
  3388. + return a->sign ? -1 : 1;
  3389. + }
  3390. + /* now both are "normal". */
  3391. + if (a->sign != b->sign)
  3392. + {
  3393. + /* opposite signs */
  3394. + return a->sign ? -1 : 1;
  3395. + }
  3396. + /* same sign; exponents? */
  3397. + if (a->normal_exp > b->normal_exp)
  3398. + {
  3399. + return a->sign ? -1 : 1;
  3400. + }
  3401. + if (a->normal_exp < b->normal_exp)
  3402. + {
  3403. + return a->sign ? 1 : -1;
  3404. + }
  3405. + /* same exponents; check size. */
  3406. + if (a->fraction.ll > b->fraction.ll)
  3407. + {
  3408. + return a->sign ? -1 : 1;
  3409. + }
  3410. + if (a->fraction.ll < b->fraction.ll)
  3411. + {
  3412. + return a->sign ? 1 : -1;
  3413. + }
  3414. + /* after all that, they're equal. */
  3415. + return 0;
  3416. +}
  3417. +#endif
  3418. +
  3419. +#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
  3420. +CMPtype
  3421. +compare (FLO_type arg_a, FLO_type arg_b)
  3422. +{
  3423. + fp_number_type a;
  3424. + fp_number_type b;
  3425. + FLO_union_type au, bu;
  3426. +
  3427. + au.value = arg_a;
  3428. + bu.value = arg_b;
  3429. +
  3430. + unpack_d (&au, &a);
  3431. + unpack_d (&bu, &b);
  3432. +
  3433. + return __fpcmp_parts (&a, &b);
  3434. +}
  3435. +#endif /* L_compare_sf || L_compare_df */
  3436. +
  3437. +#ifndef US_SOFTWARE_GOFAST
  3438. +
  3439. +/* These should be optimized for their specific tasks someday. */
  3440. +
  3441. +#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
  3442. +CMPtype
  3443. +_eq_f2 (FLO_type arg_a, FLO_type arg_b)
  3444. +{
  3445. + fp_number_type a;
  3446. + fp_number_type b;
  3447. + FLO_union_type au, bu;
  3448. +
  3449. + au.value = arg_a;
  3450. + bu.value = arg_b;
  3451. +
  3452. + unpack_d (&au, &a);
  3453. + unpack_d (&bu, &b);
  3454. +
  3455. + if (isnan (&a) || isnan (&b))
  3456. + return 1; /* false, truth == 0 */
  3457. +
  3458. + return __fpcmp_parts (&a, &b) ;
  3459. +}
  3460. +#endif /* L_eq_sf || L_eq_df */
  3461. +
  3462. +#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
  3463. +CMPtype
  3464. +_ne_f2 (FLO_type arg_a, FLO_type arg_b)
  3465. +{
  3466. + fp_number_type a;
  3467. + fp_number_type b;
  3468. + FLO_union_type au, bu;
  3469. +
  3470. + au.value = arg_a;
  3471. + bu.value = arg_b;
  3472. +
  3473. + unpack_d (&au, &a);
  3474. + unpack_d (&bu, &b);
  3475. +
  3476. + if (isnan (&a) || isnan (&b))
  3477. + return 1; /* true, truth != 0 */
  3478. +
  3479. + return __fpcmp_parts (&a, &b) ;
  3480. +}
  3481. +#endif /* L_ne_sf || L_ne_df */
  3482. +
  3483. +#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
  3484. +CMPtype
  3485. +_gt_f2 (FLO_type arg_a, FLO_type arg_b)
  3486. +{
  3487. + fp_number_type a;
  3488. + fp_number_type b;
  3489. + FLO_union_type au, bu;
  3490. +
  3491. + au.value = arg_a;
  3492. + bu.value = arg_b;
  3493. +
  3494. + unpack_d (&au, &a);
  3495. + unpack_d (&bu, &b);
  3496. +
  3497. + if (isnan (&a) || isnan (&b))
  3498. + return -1; /* false, truth > 0 */
  3499. +
  3500. + return __fpcmp_parts (&a, &b);
  3501. +}
  3502. +#endif /* L_gt_sf || L_gt_df */
  3503. +
  3504. +#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
  3505. +CMPtype
  3506. +_ge_f2 (FLO_type arg_a, FLO_type arg_b)
  3507. +{
  3508. + fp_number_type a;
  3509. + fp_number_type b;
  3510. + FLO_union_type au, bu;
  3511. +
  3512. + au.value = arg_a;
  3513. + bu.value = arg_b;
  3514. +
  3515. + unpack_d (&au, &a);
  3516. + unpack_d (&bu, &b);
  3517. +
  3518. + if (isnan (&a) || isnan (&b))
  3519. + return -1; /* false, truth >= 0 */
  3520. + return __fpcmp_parts (&a, &b) ;
  3521. +}
  3522. +#endif /* L_ge_sf || L_ge_df */
  3523. +
  3524. +#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
  3525. +CMPtype
  3526. +_lt_f2 (FLO_type arg_a, FLO_type arg_b)
  3527. +{
  3528. + fp_number_type a;
  3529. + fp_number_type b;
  3530. + FLO_union_type au, bu;
  3531. +
  3532. + au.value = arg_a;
  3533. + bu.value = arg_b;
  3534. +
  3535. + unpack_d (&au, &a);
  3536. + unpack_d (&bu, &b);
  3537. +
  3538. + if (isnan (&a) || isnan (&b))
  3539. + return 1; /* false, truth < 0 */
  3540. +
  3541. + return __fpcmp_parts (&a, &b);
  3542. +}
  3543. +#endif /* L_lt_sf || L_lt_df */
  3544. +
  3545. +#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
  3546. +CMPtype
  3547. +_le_f2 (FLO_type arg_a, FLO_type arg_b)
  3548. +{
  3549. + fp_number_type a;
  3550. + fp_number_type b;
  3551. + FLO_union_type au, bu;
  3552. +
  3553. + au.value = arg_a;
  3554. + bu.value = arg_b;
  3555. +
  3556. + unpack_d (&au, &a);
  3557. + unpack_d (&bu, &b);
  3558. +
  3559. + if (isnan (&a) || isnan (&b))
  3560. + return 1; /* false, truth <= 0 */
  3561. +
  3562. + return __fpcmp_parts (&a, &b) ;
  3563. +}
  3564. +#endif /* L_le_sf || L_le_df */
  3565. +
  3566. +#endif /* ! US_SOFTWARE_GOFAST */
  3567. +
  3568. +#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
  3569. +CMPtype
  3570. +_unord_f2 (FLO_type arg_a, FLO_type arg_b)
  3571. +{
  3572. + fp_number_type a;
  3573. + fp_number_type b;
  3574. + FLO_union_type au, bu;
  3575. +
  3576. + au.value = arg_a;
  3577. + bu.value = arg_b;
  3578. +
  3579. + unpack_d (&au, &a);
  3580. + unpack_d (&bu, &b);
  3581. +
  3582. + return (isnan (&a) || isnan (&b));
  3583. +}
  3584. +#endif /* L_unord_sf || L_unord_df */
  3585. +
  3586. +#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
  3587. +FLO_type
  3588. +si_to_float (SItype arg_a)
  3589. +{
  3590. + fp_number_type in;
  3591. +
  3592. + in.class = CLASS_NUMBER;
  3593. + in.sign = arg_a < 0;
  3594. + if (!arg_a)
  3595. + {
  3596. + in.class = CLASS_ZERO;
  3597. + }
  3598. + else
  3599. + {
  3600. + in.normal_exp = FRACBITS + NGARDS;
  3601. + if (in.sign)
  3602. + {
  3603. + /* Special case for minint, since there is no +ve integer
  3604. + representation for it */
  3605. + if (arg_a == (- MAX_SI_INT - 1))
  3606. + {
  3607. + return (FLO_type)(- MAX_SI_INT - 1);
  3608. + }
  3609. + in.fraction.ll = (-arg_a);
  3610. + }
  3611. + else
  3612. + in.fraction.ll = arg_a;
  3613. +
  3614. + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
  3615. + {
  3616. + in.fraction.ll <<= 1;
  3617. + in.normal_exp -= 1;
  3618. + }
  3619. + }
  3620. + return pack_d (&in);
  3621. +}
  3622. +#endif /* L_si_to_sf || L_si_to_df */
  3623. +
  3624. +#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
  3625. +FLO_type
  3626. +usi_to_float (USItype arg_a)
  3627. +{
  3628. + fp_number_type in;
  3629. +
  3630. + in.sign = 0;
  3631. + if (!arg_a)
  3632. + {
  3633. + in.class = CLASS_ZERO;
  3634. + }
  3635. + else
  3636. + {
  3637. + in.class = CLASS_NUMBER;
  3638. + in.normal_exp = FRACBITS + NGARDS;
  3639. + in.fraction.ll = arg_a;
  3640. +
  3641. + while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
  3642. + {
  3643. + in.fraction.ll >>= 1;
  3644. + in.normal_exp += 1;
  3645. + }
  3646. + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
  3647. + {
  3648. + in.fraction.ll <<= 1;
  3649. + in.normal_exp -= 1;
  3650. + }
  3651. + }
  3652. + return pack_d (&in);
  3653. +}
  3654. +#endif
  3655. +
  3656. +#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
  3657. +SItype
  3658. +float_to_si (FLO_type arg_a)
  3659. +{
  3660. + fp_number_type a;
  3661. + SItype tmp;
  3662. + FLO_union_type au;
  3663. +
  3664. + au.value = arg_a;
  3665. + unpack_d (&au, &a);
  3666. +
  3667. + if (iszero (&a))
  3668. + return 0;
  3669. + if (isnan (&a))
  3670. + return 0;
  3671. + /* get reasonable MAX_SI_INT... */
  3672. + if (isinf (&a))
  3673. + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
  3674. + /* it is a number, but a small one */
  3675. + if (a.normal_exp < 0)
  3676. + return 0;
  3677. + if (a.normal_exp > BITS_PER_SI - 2)
  3678. + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
  3679. + tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
  3680. + return a.sign ? (-tmp) : (tmp);
  3681. +}
  3682. +#endif /* L_sf_to_si || L_df_to_si */
  3683. +
  3684. +#if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
  3685. +#if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
  3686. +/* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
  3687. + we also define them for GOFAST because the ones in libgcc2.c have the
  3688. + wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
  3689. + out of libgcc2.c. We can't define these here if not GOFAST because then
  3690. + there'd be duplicate copies. */
  3691. +
  3692. +USItype
  3693. +float_to_usi (FLO_type arg_a)
  3694. +{
  3695. + fp_number_type a;
  3696. + FLO_union_type au;
  3697. +
  3698. + au.value = arg_a;
  3699. + unpack_d (&au, &a);
  3700. +
  3701. + if (iszero (&a))
  3702. + return 0;
  3703. + if (isnan (&a))
  3704. + return 0;
  3705. + /* it is a negative number */
  3706. + if (a.sign)
  3707. + return 0;
  3708. + /* get reasonable MAX_USI_INT... */
  3709. + if (isinf (&a))
  3710. + return MAX_USI_INT;
  3711. + /* it is a number, but a small one */
  3712. + if (a.normal_exp < 0)
  3713. + return 0;
  3714. + if (a.normal_exp > BITS_PER_SI - 1)
  3715. + return MAX_USI_INT;
  3716. + else if (a.normal_exp > (FRACBITS + NGARDS))
  3717. + return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
  3718. + else
  3719. + return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
  3720. +}
  3721. +#endif /* US_SOFTWARE_GOFAST */
  3722. +#endif /* L_sf_to_usi || L_df_to_usi */
  3723. +
  3724. +#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
  3725. +FLO_type
  3726. +negate (FLO_type arg_a)
  3727. +{
  3728. + fp_number_type a;
  3729. + FLO_union_type au;
  3730. +
  3731. + au.value = arg_a;
  3732. + unpack_d (&au, &a);
  3733. +
  3734. + flip_sign (&a);
  3735. + return pack_d (&a);
  3736. +}
  3737. +#endif /* L_negate_sf || L_negate_df */
  3738. +
  3739. +#ifdef FLOAT
  3740. +
  3741. +#if defined(L_make_sf)
  3742. +SFtype
  3743. +__make_fp(fp_class_type class,
  3744. + unsigned int sign,
  3745. + int exp,
  3746. + USItype frac)
  3747. +{
  3748. + fp_number_type in;
  3749. +
  3750. + in.class = class;
  3751. + in.sign = sign;
  3752. + in.normal_exp = exp;
  3753. + in.fraction.ll = frac;
  3754. + return pack_d (&in);
  3755. +}
  3756. +#endif /* L_make_sf */
  3757. +
  3758. +#ifndef FLOAT_ONLY
  3759. +
  3760. +/* This enables one to build an fp library that supports float but not double.
  3761. + Otherwise, we would get an undefined reference to __make_dp.
  3762. + This is needed for some 8-bit ports that can't handle well values that
  3763. + are 8-bytes in size, so we just don't support double for them at all. */
  3764. +
  3765. +#if defined(L_sf_to_df)
  3766. +DFtype
  3767. +sf_to_df (SFtype arg_a)
  3768. +{
  3769. + fp_number_type in;
  3770. + FLO_union_type au;
  3771. +
  3772. + au.value = arg_a;
  3773. + unpack_d (&au, &in);
  3774. +
  3775. + return __make_dp (in.class, in.sign, in.normal_exp,
  3776. + ((UDItype) in.fraction.ll) << F_D_BITOFF);
  3777. +}
  3778. +#endif /* L_sf_to_df */
  3779. +
  3780. +#if defined(L_sf_to_tf) && defined(TMODES)
  3781. +TFtype
  3782. +sf_to_tf (SFtype arg_a)
  3783. +{
  3784. + fp_number_type in;
  3785. + FLO_union_type au;
  3786. +
  3787. + au.value = arg_a;
  3788. + unpack_d (&au, &in);
  3789. +
  3790. + return __make_tp (in.class, in.sign, in.normal_exp,
  3791. + ((UTItype) in.fraction.ll) << F_T_BITOFF);
  3792. +}
  3793. +#endif /* L_sf_to_df */
  3794. +
  3795. +#endif /* ! FLOAT_ONLY */
  3796. +#endif /* FLOAT */
  3797. +
  3798. +#ifndef FLOAT
  3799. +
  3800. +extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
  3801. +
  3802. +#if defined(L_make_df)
  3803. +DFtype
  3804. +__make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
  3805. +{
  3806. + fp_number_type in;
  3807. +
  3808. + in.class = class;
  3809. + in.sign = sign;
  3810. + in.normal_exp = exp;
  3811. + in.fraction.ll = frac;
  3812. + return pack_d (&in);
  3813. +}
  3814. +#endif /* L_make_df */
  3815. +
  3816. +#if defined(L_df_to_sf)
  3817. +SFtype
  3818. +df_to_sf (DFtype arg_a)
  3819. +{
  3820. + fp_number_type in;
  3821. + USItype sffrac;
  3822. + FLO_union_type au;
  3823. +
  3824. + au.value = arg_a;
  3825. + unpack_d (&au, &in);
  3826. +
  3827. + sffrac = in.fraction.ll >> F_D_BITOFF;
  3828. +
  3829. + /* We set the lowest guard bit in SFFRAC if we discarded any non
  3830. + zero bits. */
  3831. + if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
  3832. + sffrac |= 1;
  3833. +
  3834. + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
  3835. +}
  3836. +#endif /* L_df_to_sf */
  3837. +
  3838. +#if defined(L_df_to_tf) && defined(TMODES) \
  3839. + && !defined(FLOAT) && !defined(TFLOAT)
  3840. +TFtype
  3841. +df_to_tf (DFtype arg_a)
  3842. +{
  3843. + fp_number_type in;
  3844. + FLO_union_type au;
  3845. +
  3846. + au.value = arg_a;
  3847. + unpack_d (&au, &in);
  3848. +
  3849. + return __make_tp (in.class, in.sign, in.normal_exp,
  3850. + ((UTItype) in.fraction.ll) << D_T_BITOFF);
  3851. +}
  3852. +#endif /* L_sf_to_df */
  3853. +
  3854. +#ifdef TFLOAT
  3855. +#if defined(L_make_tf)
  3856. +TFtype
  3857. +__make_tp(fp_class_type class,
  3858. + unsigned int sign,
  3859. + int exp,
  3860. + UTItype frac)
  3861. +{
  3862. + fp_number_type in;
  3863. +
  3864. + in.class = class;
  3865. + in.sign = sign;
  3866. + in.normal_exp = exp;
  3867. + in.fraction.ll = frac;
  3868. + return pack_d (&in);
  3869. +}
  3870. +#endif /* L_make_tf */
  3871. +
  3872. +#if defined(L_tf_to_df)
  3873. +DFtype
  3874. +tf_to_df (TFtype arg_a)
  3875. +{
  3876. + fp_number_type in;
  3877. + UDItype sffrac;
  3878. + FLO_union_type au;
  3879. +
  3880. + au.value = arg_a;
  3881. + unpack_d (&au, &in);
  3882. +
  3883. + sffrac = in.fraction.ll >> D_T_BITOFF;
  3884. +
  3885. + /* We set the lowest guard bit in SFFRAC if we discarded any non
  3886. + zero bits. */
  3887. + if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
  3888. + sffrac |= 1;
  3889. +
  3890. + return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
  3891. +}
  3892. +#endif /* L_tf_to_df */
  3893. +
  3894. +#if defined(L_tf_to_sf)
  3895. +SFtype
  3896. +tf_to_sf (TFtype arg_a)
  3897. +{
  3898. + fp_number_type in;
  3899. + USItype sffrac;
  3900. + FLO_union_type au;
  3901. +
  3902. + au.value = arg_a;
  3903. + unpack_d (&au, &in);
  3904. +
  3905. + sffrac = in.fraction.ll >> F_T_BITOFF;
  3906. +
  3907. + /* We set the lowest guard bit in SFFRAC if we discarded any non
  3908. + zero bits. */
  3909. + if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
  3910. + sffrac |= 1;
  3911. +
  3912. + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
  3913. +}
  3914. +#endif /* L_tf_to_sf */
  3915. +#endif /* TFLOAT */
  3916. +
  3917. +#endif /* ! FLOAT */
  3918. +#endif /* !EXTENDED_FLOAT_STUBS */
  3919. --- gcc-3.4.3/gcc/config/nios2/nios2-protos.h
  3920. +++ gcc-3.4.3-nios2/gcc/config/nios2/nios2-protos.h
  3921. @@ -0,0 +1,70 @@
  3922. +/* Subroutines for assembler code output for Altera NIOS 2G NIOS2 version.
  3923. + Copyright (C) 2003 Altera
  3924. + Contributed by Jonah Graham (jgraham@altera.com).
  3925. +
  3926. +This file is part of GNU CC.
  3927. +
  3928. +GNU CC is free software; you can redistribute it and/or modify
  3929. +it under the terms of the GNU General Public License as published by
  3930. +the Free Software Foundation; either version 2, or (at your option)
  3931. +any later version.
  3932. +
  3933. +GNU CC is distributed in the hope that it will be useful,
  3934. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  3935. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3936. +GNU General Public License for more details.
  3937. +
  3938. +You should have received a copy of the GNU General Public License
  3939. +along with GNU CC; see the file COPYING. If not, write to
  3940. +the Free Software Foundation, 59 Temple Place - Suite 330,
  3941. +Boston, MA 02111-1307, USA. */
  3942. +
  3943. +extern void dump_frame_size (FILE *);
  3944. +extern HOST_WIDE_INT compute_frame_size (void);
  3945. +extern int nios2_initial_elimination_offset (int, int);
  3946. +extern void override_options (void);
  3947. +extern void optimization_options (int, int);
  3948. +extern int nios2_can_use_return_insn (void);
  3949. +extern void expand_prologue (void);
  3950. +extern void expand_epilogue (bool);
  3951. +extern void function_profiler (FILE *, int);
  3952. +
  3953. +
  3954. +#ifdef RTX_CODE
  3955. +extern int nios2_legitimate_address (rtx, enum machine_mode, int);
  3956. +extern void nios2_print_operand (FILE *, rtx, int);
  3957. +extern void nios2_print_operand_address (FILE *, rtx);
  3958. +
  3959. +extern int nios2_emit_move_sequence (rtx *, enum machine_mode);
  3960. +extern int nios2_emit_expensive_div (rtx *, enum machine_mode);
  3961. +
  3962. +extern void gen_int_relational (enum rtx_code, rtx, rtx, rtx, rtx);
  3963. +extern void gen_conditional_move (rtx *, enum machine_mode);
  3964. +extern const char *asm_output_opcode (FILE *, const char *);
  3965. +
  3966. +/* predicates */
  3967. +extern int arith_operand (rtx, enum machine_mode);
  3968. +extern int uns_arith_operand (rtx, enum machine_mode);
  3969. +extern int logical_operand (rtx, enum machine_mode);
  3970. +extern int shift_operand (rtx, enum machine_mode);
  3971. +extern int reg_or_0_operand (rtx, enum machine_mode);
  3972. +extern int equality_op (rtx, enum machine_mode);
  3973. +extern int custom_insn_opcode (rtx, enum machine_mode);
  3974. +extern int rdwrctl_operand (rtx, enum machine_mode);
  3975. +
  3976. +# ifdef HAVE_MACHINE_MODES
  3977. +# if defined TREE_CODE
  3978. +extern void function_arg_advance (CUMULATIVE_ARGS *, enum machine_mode, tree, int);
  3979. +extern rtx function_arg (const CUMULATIVE_ARGS *, enum machine_mode, tree, int);
  3980. +extern int function_arg_partial_nregs (const CUMULATIVE_ARGS *, enum machine_mode, tree, int);
  3981. +extern void init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, tree, int);
  3982. +extern int nios2_setup_incoming_varargs (const CUMULATIVE_ARGS *, enum machine_mode, tree, int);
  3983. +
  3984. +# endif /* TREE_CODE */
  3985. +# endif /* HAVE_MACHINE_MODES */
  3986. +#endif
  3987. +
  3988. +#ifdef TREE_CODE
  3989. +extern int nios2_return_in_memory (tree);
  3990. +
  3991. +#endif /* TREE_CODE */
  3992. --- gcc-3.4.3/gcc/config/nios2/nios2.c
  3993. +++ gcc-3.4.3-nios2/gcc/config/nios2/nios2.c
  3994. @@ -0,0 +1,2853 @@
  3995. +/* Subroutines for assembler code output for Altera NIOS 2G NIOS2 version.
  3996. + Copyright (C) 2003 Altera
  3997. + Contributed by Jonah Graham (jgraham@altera.com).
  3998. +
  3999. +This file is part of GNU CC.
  4000. +
  4001. +GNU CC is free software; you can redistribute it and/or modify
  4002. +it under the terms of the GNU General Public License as published by
  4003. +the Free Software Foundation; either version 2, or (at your option)
  4004. +any later version.
  4005. +
  4006. +GNU CC is distributed in the hope that it will be useful,
  4007. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  4008. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4009. +GNU General Public License for more details.
  4010. +
  4011. +You should have received a copy of the GNU General Public License
  4012. +along with GNU CC; see the file COPYING. If not, write to
  4013. +the Free Software Foundation, 59 Temple Place - Suite 330,
  4014. +Boston, MA 02111-1307, USA. */
  4015. +
  4016. +
  4017. +#include <stdio.h>
  4018. +#include "config.h"
  4019. +#include "system.h"
  4020. +#include "coretypes.h"
  4021. +#include "tm.h"
  4022. +#include "rtl.h"
  4023. +#include "tree.h"
  4024. +#include "tm_p.h"
  4025. +#include "regs.h"
  4026. +#include "hard-reg-set.h"
  4027. +#include "real.h"
  4028. +#include "insn-config.h"
  4029. +#include "conditions.h"
  4030. +#include "output.h"
  4031. +#include "insn-attr.h"
  4032. +#include "flags.h"
  4033. +#include "recog.h"
  4034. +#include "expr.h"
  4035. +#include "toplev.h"
  4036. +#include "basic-block.h"
  4037. +#include "function.h"
  4038. +#include "ggc.h"
  4039. +#include "reload.h"
  4040. +#include "debug.h"
  4041. +#include "optabs.h"
  4042. +#include "target.h"
  4043. +#include "target-def.h"
  4044. +
  4045. +/* local prototypes */
  4046. +static bool nios2_rtx_costs (rtx, int, int, int *);
  4047. +
  4048. +static void nios2_asm_function_prologue (FILE *, HOST_WIDE_INT);
  4049. +static int nios2_use_dfa_pipeline_interface (void);
  4050. +static int nios2_issue_rate (void);
  4051. +static struct machine_function *nios2_init_machine_status (void);
  4052. +static bool nios2_in_small_data_p (tree);
  4053. +static rtx save_reg (int, HOST_WIDE_INT, rtx);
  4054. +static rtx restore_reg (int, HOST_WIDE_INT);
  4055. +static unsigned int nios2_section_type_flags (tree, const char *, int);
  4056. +static void nios2_init_builtins (void);
  4057. +static rtx nios2_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
  4058. +static bool nios2_function_ok_for_sibcall (tree, tree);
  4059. +static void nios2_encode_section_info (tree, rtx, int);
  4060. +
  4061. +/* Initialize the GCC target structure. */
  4062. +#undef TARGET_ASM_FUNCTION_PROLOGUE
  4063. +#define TARGET_ASM_FUNCTION_PROLOGUE nios2_asm_function_prologue
  4064. +
  4065. +#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
  4066. +#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE \
  4067. + nios2_use_dfa_pipeline_interface
  4068. +#undef TARGET_SCHED_ISSUE_RATE
  4069. +#define TARGET_SCHED_ISSUE_RATE nios2_issue_rate
  4070. +#undef TARGET_IN_SMALL_DATA_P
  4071. +#define TARGET_IN_SMALL_DATA_P nios2_in_small_data_p
  4072. +#undef TARGET_ENCODE_SECTION_INFO
  4073. +#define TARGET_ENCODE_SECTION_INFO nios2_encode_section_info
  4074. +#undef TARGET_SECTION_TYPE_FLAGS
  4075. +#define TARGET_SECTION_TYPE_FLAGS nios2_section_type_flags
  4076. +
  4077. +#undef TARGET_INIT_BUILTINS
  4078. +#define TARGET_INIT_BUILTINS nios2_init_builtins
  4079. +#undef TARGET_EXPAND_BUILTIN
  4080. +#define TARGET_EXPAND_BUILTIN nios2_expand_builtin
  4081. +
  4082. +#undef TARGET_FUNCTION_OK_FOR_SIBCALL
  4083. +#define TARGET_FUNCTION_OK_FOR_SIBCALL nios2_function_ok_for_sibcall
  4084. +
  4085. +#undef TARGET_RTX_COSTS
  4086. +#define TARGET_RTX_COSTS nios2_rtx_costs
  4087. +
  4088. +
  4089. +struct gcc_target targetm = TARGET_INITIALIZER;
  4090. +
  4091. +
  4092. +
  4093. +/* Threshold for data being put into the small data/bss area, instead
  4094. + of the normal data area (references to the small data/bss area take
  4095. + 1 instruction, and use the global pointer, references to the normal
  4096. + data area takes 2 instructions). */
  4097. +unsigned HOST_WIDE_INT nios2_section_threshold = NIOS2_DEFAULT_GVALUE;
  4098. +
  4099. +
  4100. +/* Structure to be filled in by compute_frame_size with register
  4101. + save masks, and offsets for the current function. */
  4102. +
  4103. +struct nios2_frame_info
  4104. +GTY (())
  4105. +{
  4106. + long total_size; /* # bytes that the entire frame takes up */
  4107. + long var_size; /* # bytes that variables take up */
  4108. + long args_size; /* # bytes that outgoing arguments take up */
  4109. + int save_reg_size; /* # bytes needed to store gp regs */
  4110. + int save_reg_rounded; /* # bytes needed to store gp regs */
  4111. + long save_regs_offset; /* offset from new sp to store gp registers */
  4112. + int initialized; /* != 0 if frame size already calculated */
  4113. + int num_regs; /* number of gp registers saved */
  4114. +};
  4115. +
  4116. +struct machine_function
  4117. +GTY (())
  4118. +{
  4119. +
  4120. + /* Current frame information, calculated by compute_frame_size. */
  4121. + struct nios2_frame_info frame;
  4122. +};
  4123. +
  4124. +
  4125. +/***************************************
  4126. + * Section encodings
  4127. + ***************************************/
  4128. +
  4129. +
  4130. +
  4131. +
  4132. +
  4133. +/***************************************
  4134. + * Stack Layout and Calling Conventions
  4135. + ***************************************/
  4136. +
  4137. +
  4138. +#define TOO_BIG_OFFSET(X) ((X) > ((1 << 15) - 1))
  4139. +#define TEMP_REG_NUM 8
  4140. +
  4141. +static void
  4142. +nios2_asm_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
  4143. +{
  4144. + if (flag_verbose_asm || flag_debug_asm)
  4145. + {
  4146. + compute_frame_size ();
  4147. + dump_frame_size (file);
  4148. + }
  4149. +}
  4150. +
  4151. +static rtx
  4152. +save_reg (int regno, HOST_WIDE_INT offset, rtx cfa_store_reg)
  4153. +{
  4154. + rtx insn, stack_slot;
  4155. +
  4156. + stack_slot = gen_rtx_PLUS (SImode,
  4157. + cfa_store_reg,
  4158. + GEN_INT (offset));
  4159. +
  4160. + insn = emit_insn (gen_rtx_SET (SImode,
  4161. + gen_rtx_MEM (SImode, stack_slot),
  4162. + gen_rtx_REG (SImode, regno)));
  4163. +
  4164. + RTX_FRAME_RELATED_P (insn) = 1;
  4165. +
  4166. + return insn;
  4167. +}
  4168. +
  4169. +static rtx
  4170. +restore_reg (int regno, HOST_WIDE_INT offset)
  4171. +{
  4172. + rtx insn, stack_slot;
  4173. +
  4174. + if (TOO_BIG_OFFSET (offset))
  4175. + {
  4176. + stack_slot = gen_rtx_REG (SImode, TEMP_REG_NUM);
  4177. + insn = emit_insn (gen_rtx_SET (SImode,
  4178. + stack_slot,
  4179. + GEN_INT (offset)));
  4180. +
  4181. + insn = emit_insn (gen_rtx_SET (SImode,
  4182. + stack_slot,
  4183. + gen_rtx_PLUS (SImode,
  4184. + stack_slot,
  4185. + stack_pointer_rtx)));
  4186. + }
  4187. + else
  4188. + {
  4189. + stack_slot = gen_rtx_PLUS (SImode,
  4190. + stack_pointer_rtx,
  4191. + GEN_INT (offset));
  4192. + }
  4193. +
  4194. + stack_slot = gen_rtx_MEM (SImode, stack_slot);
  4195. +
  4196. + insn = emit_move_insn (gen_rtx_REG (SImode, regno), stack_slot);
  4197. +
  4198. + return insn;
  4199. +}
  4200. +
  4201. +
  4202. +/* There are two possible paths for prologue expansion,
  4203. +- the first is if the total frame size is < 2^15-1. In that
  4204. +case all the immediates will fit into the 16-bit immediate
  4205. +fields.
  4206. +- the second is when the frame size is too big, in that
  4207. +case an additional temporary register is used, first
  4208. +as a cfa_temp to offset the sp, second as the cfa_store
  4209. +register.
  4210. +
  4211. +See the comment above dwarf2out_frame_debug_expr in
  4212. +dwarf2out.c for more explanation of the "rules."
  4213. +
  4214. +
  4215. +Case 1:
  4216. +Rule # Example Insn Effect
  4217. +2 addi sp, sp, -total_frame_size cfa.reg=sp, cfa.offset=total_frame_size
  4218. + cfa_store.reg=sp, cfa_store.offset=total_frame_size
  4219. +12 stw ra, offset(sp)
  4220. +12 stw r16, offset(sp)
  4221. +1 mov fp, sp
  4222. +
  4223. +Case 2:
  4224. +Rule # Example Insn Effect
  4225. +6 movi r8, total_frame_size cfa_temp.reg=r8, cfa_temp.offset=total_frame_size
  4226. +2 sub sp, sp, r8 cfa.reg=sp, cfa.offset=total_frame_size
  4227. + cfa_store.reg=sp, cfa_store.offset=total_frame_size
  4228. +5 add r8, r8, sp cfa_store.reg=r8, cfa_store.offset=0
  4229. +12 stw ra, offset(r8)
  4230. +12 stw r16, offset(r8)
  4231. +1 mov fp, sp
  4232. +
  4233. +*/
  4234. +
  4235. +void
  4236. +expand_prologue ()
  4237. +{
  4238. + int i;
  4239. + HOST_WIDE_INT total_frame_size;
  4240. + int cfa_store_offset;
  4241. + rtx insn;
  4242. + rtx cfa_store_reg = 0;
  4243. +
  4244. + total_frame_size = compute_frame_size ();
  4245. +
  4246. + if (total_frame_size)
  4247. + {
  4248. +
  4249. + if (TOO_BIG_OFFSET (total_frame_size))
  4250. + {
  4251. + /* cfa_temp and cfa_store_reg are the same register,
  4252. + cfa_store_reg overwrites cfa_temp */
  4253. + cfa_store_reg = gen_rtx_REG (SImode, TEMP_REG_NUM);
  4254. + insn = emit_insn (gen_rtx_SET (SImode,
  4255. + cfa_store_reg,
  4256. + GEN_INT (total_frame_size)));
  4257. +
  4258. + RTX_FRAME_RELATED_P (insn) = 1;
  4259. +
  4260. +
  4261. + insn = gen_rtx_SET (SImode,
  4262. + stack_pointer_rtx,
  4263. + gen_rtx_MINUS (SImode,
  4264. + stack_pointer_rtx,
  4265. + cfa_store_reg));
  4266. +
  4267. + insn = emit_insn (insn);
  4268. + RTX_FRAME_RELATED_P (insn) = 1;
  4269. +
  4270. +
  4271. + /* if there are no registers to save, I don't need to
  4272. + create a cfa_store */
  4273. + if (cfun->machine->frame.save_reg_size)
  4274. + {
  4275. + insn = gen_rtx_SET (SImode,
  4276. + cfa_store_reg,
  4277. + gen_rtx_PLUS (SImode,
  4278. + cfa_store_reg,
  4279. + stack_pointer_rtx));
  4280. +
  4281. + insn = emit_insn (insn);
  4282. + RTX_FRAME_RELATED_P (insn) = 1;
  4283. + }
  4284. +
  4285. + cfa_store_offset
  4286. + = total_frame_size
  4287. + - (cfun->machine->frame.save_regs_offset
  4288. + + cfun->machine->frame.save_reg_rounded);
  4289. + }
  4290. + else
  4291. + {
  4292. + insn = gen_rtx_SET (SImode,
  4293. + stack_pointer_rtx,
  4294. + gen_rtx_PLUS (SImode,
  4295. + stack_pointer_rtx,
  4296. + GEN_INT (-total_frame_size)));
  4297. + insn = emit_insn (insn);
  4298. + RTX_FRAME_RELATED_P (insn) = 1;
  4299. +
  4300. + cfa_store_reg = stack_pointer_rtx;
  4301. + cfa_store_offset
  4302. + = cfun->machine->frame.save_regs_offset
  4303. + + cfun->machine->frame.save_reg_rounded;
  4304. + }
  4305. + }
  4306. +
  4307. + if (MUST_SAVE_REGISTER (RA_REGNO))
  4308. + {
  4309. + cfa_store_offset -= 4;
  4310. + save_reg (RA_REGNO, cfa_store_offset, cfa_store_reg);
  4311. + }
  4312. + if (MUST_SAVE_REGISTER (FP_REGNO))
  4313. + {
  4314. + cfa_store_offset -= 4;
  4315. + save_reg (FP_REGNO, cfa_store_offset, cfa_store_reg);
  4316. + }
  4317. +
  4318. + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  4319. + {
  4320. + if (MUST_SAVE_REGISTER (i) && i != FP_REGNO && i != RA_REGNO)
  4321. + {
  4322. + cfa_store_offset -= 4;
  4323. + save_reg (i, cfa_store_offset, cfa_store_reg);
  4324. + }
  4325. + }
  4326. +
  4327. + if (frame_pointer_needed)
  4328. + {
  4329. + insn = emit_insn (gen_rtx_SET (SImode,
  4330. + gen_rtx_REG (SImode, FP_REGNO),
  4331. + gen_rtx_REG (SImode, SP_REGNO)));
  4332. +
  4333. + RTX_FRAME_RELATED_P (insn) = 1;
  4334. + }
  4335. +
  4336. + /* If we are profiling, make sure no instructions are scheduled before
  4337. + the call to mcount. */
  4338. + if (current_function_profile)
  4339. + emit_insn (gen_blockage ());
  4340. +}
  4341. +
  4342. +void
  4343. +expand_epilogue (bool sibcall_p)
  4344. +{
  4345. + rtx insn;
  4346. + int i;
  4347. + HOST_WIDE_INT total_frame_size;
  4348. + int register_store_offset;
  4349. +
  4350. + total_frame_size = compute_frame_size ();
  4351. +
  4352. + if (!sibcall_p && nios2_can_use_return_insn ())
  4353. + {
  4354. + insn = emit_jump_insn (gen_return ());
  4355. + return;
  4356. + }
  4357. +
  4358. + emit_insn (gen_blockage ());
  4359. +
  4360. + register_store_offset =
  4361. + cfun->machine->frame.save_regs_offset +
  4362. + cfun->machine->frame.save_reg_rounded;
  4363. +
  4364. + if (MUST_SAVE_REGISTER (RA_REGNO))
  4365. + {
  4366. + register_store_offset -= 4;
  4367. + restore_reg (RA_REGNO, register_store_offset);
  4368. + }
  4369. +
  4370. + if (MUST_SAVE_REGISTER (FP_REGNO))
  4371. + {
  4372. + register_store_offset -= 4;
  4373. + restore_reg (FP_REGNO, register_store_offset);
  4374. + }
  4375. +
  4376. + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  4377. + {
  4378. + if (MUST_SAVE_REGISTER (i) && i != FP_REGNO && i != RA_REGNO)
  4379. + {
  4380. + register_store_offset -= 4;
  4381. + restore_reg (i, register_store_offset);
  4382. + }
  4383. + }
  4384. +
  4385. + if (total_frame_size)
  4386. + {
  4387. + rtx sp_adjust;
  4388. +
  4389. + if (TOO_BIG_OFFSET (total_frame_size))
  4390. + {
  4391. + sp_adjust = gen_rtx_REG (SImode, TEMP_REG_NUM);
  4392. + insn = emit_insn (gen_rtx_SET (SImode,
  4393. + sp_adjust,
  4394. + GEN_INT (total_frame_size)));
  4395. +
  4396. + }
  4397. + else
  4398. + {
  4399. + sp_adjust = GEN_INT (total_frame_size);
  4400. + }
  4401. +
  4402. + insn = gen_rtx_SET (SImode,
  4403. + stack_pointer_rtx,
  4404. + gen_rtx_PLUS (SImode,
  4405. + stack_pointer_rtx,
  4406. + sp_adjust));
  4407. + insn = emit_insn (insn);
  4408. + }
  4409. +
  4410. +
  4411. + if (!sibcall_p)
  4412. + {
  4413. + insn = emit_jump_insn (gen_return_from_epilogue (gen_rtx (REG, Pmode,
  4414. + RA_REGNO)));
  4415. + }
  4416. +}
  4417. +
  4418. +
  4419. +bool
  4420. +nios2_function_ok_for_sibcall (tree a ATTRIBUTE_UNUSED, tree b ATTRIBUTE_UNUSED)
  4421. +{
  4422. + return true;
  4423. +}
  4424. +
  4425. +
  4426. +
  4427. +
  4428. +
  4429. +/* ----------------------- *
  4430. + * Profiling
  4431. + * ----------------------- */
  4432. +
  4433. +void
  4434. +function_profiler (FILE *file, int labelno)
  4435. +{
  4436. + fprintf (file, "\t%s mcount begin, label: .LP%d\n",
  4437. + ASM_COMMENT_START, labelno);
  4438. + fprintf (file, "\tnextpc\tr8\n");
  4439. + fprintf (file, "\tmov\tr9, ra\n");
  4440. + fprintf (file, "\tmovhi\tr10, %%hiadj(.LP%d)\n", labelno);
  4441. + fprintf (file, "\taddi\tr10, r10, %%lo(.LP%d)\n", labelno);
  4442. + fprintf (file, "\tcall\tmcount\n");
  4443. + fprintf (file, "\tmov\tra, r9\n");
  4444. + fprintf (file, "\t%s mcount end\n", ASM_COMMENT_START);
  4445. +}
  4446. +
  4447. +
  4448. +/***************************************
  4449. + * Stack Layout
  4450. + ***************************************/
  4451. +
  4452. +
  4453. +void
  4454. +dump_frame_size (FILE *file)
  4455. +{
  4456. + fprintf (file, "\t%s Current Frame Info\n", ASM_COMMENT_START);
  4457. +
  4458. + fprintf (file, "\t%s total_size = %ld\n", ASM_COMMENT_START,
  4459. + cfun->machine->frame.total_size);
  4460. + fprintf (file, "\t%s var_size = %ld\n", ASM_COMMENT_START,
  4461. + cfun->machine->frame.var_size);
  4462. + fprintf (file, "\t%s args_size = %ld\n", ASM_COMMENT_START,
  4463. + cfun->machine->frame.args_size);
  4464. + fprintf (file, "\t%s save_reg_size = %d\n", ASM_COMMENT_START,
  4465. + cfun->machine->frame.save_reg_size);
  4466. + fprintf (file, "\t%s save_reg_rounded = %d\n", ASM_COMMENT_START,
  4467. + cfun->machine->frame.save_reg_rounded);
  4468. + fprintf (file, "\t%s initialized = %d\n", ASM_COMMENT_START,
  4469. + cfun->machine->frame.initialized);
  4470. + fprintf (file, "\t%s num_regs = %d\n", ASM_COMMENT_START,
  4471. + cfun->machine->frame.num_regs);
  4472. + fprintf (file, "\t%s save_regs_offset = %ld\n", ASM_COMMENT_START,
  4473. + cfun->machine->frame.save_regs_offset);
  4474. + fprintf (file, "\t%s current_function_is_leaf = %d\n", ASM_COMMENT_START,
  4475. + current_function_is_leaf);
  4476. + fprintf (file, "\t%s frame_pointer_needed = %d\n", ASM_COMMENT_START,
  4477. + frame_pointer_needed);
  4478. + fprintf (file, "\t%s pretend_args_size = %d\n", ASM_COMMENT_START,
  4479. + current_function_pretend_args_size);
  4480. +
  4481. +}
  4482. +
  4483. +
  4484. +/* Return the bytes needed to compute the frame pointer from the current
  4485. + stack pointer.
  4486. +*/
  4487. +
  4488. +HOST_WIDE_INT
  4489. +compute_frame_size ()
  4490. +{
  4491. + unsigned int regno;
  4492. + HOST_WIDE_INT var_size; /* # of var. bytes allocated */
  4493. + HOST_WIDE_INT total_size; /* # bytes that the entire frame takes up */
  4494. + HOST_WIDE_INT save_reg_size; /* # bytes needed to store callee save regs */
  4495. + HOST_WIDE_INT save_reg_rounded;
  4496. + /* # bytes needed to store callee save regs (rounded) */
  4497. + HOST_WIDE_INT out_args_size; /* # bytes needed for outgoing args */
  4498. +
  4499. + save_reg_size = 0;
  4500. + var_size = STACK_ALIGN (get_frame_size ());
  4501. + out_args_size = STACK_ALIGN (current_function_outgoing_args_size);
  4502. +
  4503. + total_size = var_size + out_args_size;
  4504. +
  4505. + /* Calculate space needed for gp registers. */
  4506. + for (regno = 0; regno <= FIRST_PSEUDO_REGISTER; regno++)
  4507. + {
  4508. + if (MUST_SAVE_REGISTER (regno))
  4509. + {
  4510. + save_reg_size += 4;
  4511. + }
  4512. + }
  4513. +
  4514. + save_reg_rounded = STACK_ALIGN (save_reg_size);
  4515. + total_size += save_reg_rounded;
  4516. +
  4517. + total_size += STACK_ALIGN (current_function_pretend_args_size);
  4518. +
  4519. + /* Save other computed information. */
  4520. + cfun->machine->frame.total_size = total_size;
  4521. + cfun->machine->frame.var_size = var_size;
  4522. + cfun->machine->frame.args_size = current_function_outgoing_args_size;
  4523. + cfun->machine->frame.save_reg_size = save_reg_size;
  4524. + cfun->machine->frame.save_reg_rounded = save_reg_rounded;
  4525. + cfun->machine->frame.initialized = reload_completed;
  4526. + cfun->machine->frame.num_regs = save_reg_size / UNITS_PER_WORD;
  4527. +
  4528. + cfun->machine->frame.save_regs_offset
  4529. + = save_reg_rounded ? current_function_outgoing_args_size + var_size : 0;
  4530. +
  4531. + return total_size;
  4532. +}
  4533. +
  4534. +
  4535. +int
  4536. +nios2_initial_elimination_offset (int from, int to ATTRIBUTE_UNUSED)
  4537. +{
  4538. + int offset;
  4539. +
  4540. + /* Set OFFSET to the offset from the stack pointer. */
  4541. + switch (from)
  4542. + {
  4543. + case FRAME_POINTER_REGNUM:
  4544. + offset = 0;
  4545. + break;
  4546. +
  4547. + case ARG_POINTER_REGNUM:
  4548. + compute_frame_size ();
  4549. + offset = cfun->machine->frame.total_size;
  4550. + offset -= current_function_pretend_args_size;
  4551. + break;
  4552. +
  4553. + case RETURN_ADDRESS_POINTER_REGNUM:
  4554. + compute_frame_size ();
  4555. + /* since the return address is always the first of the
  4556. + saved registers, return the offset to the beginning
  4557. + of the saved registers block */
  4558. + offset = cfun->machine->frame.save_regs_offset;
  4559. + break;
  4560. +
  4561. + default:
  4562. + abort ();
  4563. + }
  4564. +
  4565. + return offset;
  4566. +}
  4567. +
  4568. +/* Return nonzero if this function is known to have a null epilogue.
  4569. + This allows the optimizer to omit jumps to jumps if no stack
  4570. + was created. */
  4571. +int
  4572. +nios2_can_use_return_insn ()
  4573. +{
  4574. + if (!reload_completed)
  4575. + return 0;
  4576. +
  4577. + if (regs_ever_live[RA_REGNO] || current_function_profile)
  4578. + return 0;
  4579. +
  4580. + if (cfun->machine->frame.initialized)
  4581. + return cfun->machine->frame.total_size == 0;
  4582. +
  4583. + return compute_frame_size () == 0;
  4584. +}
  4585. +
  4586. +
  4587. +
  4588. +
  4589. +
  4590. +/***************************************
  4591. + *
  4592. + ***************************************/
  4593. +
  4594. +const char *nios2_sys_nosys_string; /* for -msys=nosys */
  4595. +const char *nios2_sys_lib_string; /* for -msys-lib= */
  4596. +const char *nios2_sys_crt0_string; /* for -msys-crt0= */
  4597. +
  4598. +void
  4599. +override_options ()
  4600. +{
  4601. + /* Function to allocate machine-dependent function status. */
  4602. + init_machine_status = &nios2_init_machine_status;
  4603. +
  4604. + nios2_section_threshold
  4605. + = g_switch_set ? g_switch_value : NIOS2_DEFAULT_GVALUE;
  4606. +
  4607. + if (nios2_sys_nosys_string && *nios2_sys_nosys_string)
  4608. + {
  4609. + error ("invalid option '-msys=nosys%s'", nios2_sys_nosys_string);
  4610. + }
  4611. +
  4612. + /* If we don't have mul, we don't have mulx either! */
  4613. + if (!TARGET_HAS_MUL && TARGET_HAS_MULX)
  4614. + {
  4615. + target_flags &= ~HAS_MULX_FLAG;
  4616. + }
  4617. +
  4618. +}
  4619. +
  4620. +void
  4621. +optimization_options (int level, int size)
  4622. +{
  4623. + if (level || size)
  4624. + {
  4625. + target_flags |= INLINE_MEMCPY_FLAG;
  4626. + }
  4627. +
  4628. + if (level >= 3 && !size)
  4629. + {
  4630. + target_flags |= FAST_SW_DIV_FLAG;
  4631. + }
  4632. +}
  4633. +
  4634. +/* Allocate a chunk of memory for per-function machine-dependent data. */
  4635. +static struct machine_function *
  4636. +nios2_init_machine_status ()
  4637. +{
  4638. + return ((struct machine_function *)
  4639. + ggc_alloc_cleared (sizeof (struct machine_function)));
  4640. +}
  4641. +
  4642. +
  4643. +
  4644. +/*****************
  4645. + * Describing Relative Costs of Operations
  4646. + *****************/
  4647. +
  4648. +/* Compute a (partial) cost for rtx X. Return true if the complete
  4649. + cost has been computed, and false if subexpressions should be
  4650. + scanned. In either case, *TOTAL contains the cost result. */
  4651. +
  4652. +
  4653. +
  4654. +static bool
  4655. +nios2_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, int *total)
  4656. +{
  4657. + switch (code)
  4658. + {
  4659. + case CONST_INT:
  4660. + if (INTVAL (x) == 0)
  4661. + {
  4662. + *total = COSTS_N_INSNS (0);
  4663. + return true;
  4664. + }
  4665. + else if (SMALL_INT (INTVAL (x))
  4666. + || SMALL_INT_UNSIGNED (INTVAL (x))
  4667. + || UPPER16_INT (INTVAL (x)))
  4668. + {
  4669. + *total = COSTS_N_INSNS (2);
  4670. + return true;
  4671. + }
  4672. + else
  4673. + {
  4674. + *total = COSTS_N_INSNS (4);
  4675. + return true;
  4676. + }
  4677. +
  4678. + case LABEL_REF:
  4679. + case SYMBOL_REF:
  4680. + /* ??? gp relative stuff will fit in here */
  4681. + /* fall through */
  4682. + case CONST:
  4683. + case CONST_DOUBLE:
  4684. + {
  4685. + *total = COSTS_N_INSNS (4);
  4686. + return true;
  4687. + }
  4688. +
  4689. + case MULT:
  4690. + {
  4691. + *total = COSTS_N_INSNS (1);
  4692. + return false;
  4693. + }
  4694. + case SIGN_EXTEND:
  4695. + {
  4696. + *total = COSTS_N_INSNS (3);
  4697. + return false;
  4698. + }
  4699. + case ZERO_EXTEND:
  4700. + {
  4701. + *total = COSTS_N_INSNS (1);
  4702. + return false;
  4703. + }
  4704. +
  4705. + default:
  4706. + return false;
  4707. + }
  4708. +}
  4709. +
  4710. +
  4711. +/***************************************
  4712. + * INSTRUCTION SUPPORT
  4713. + *
  4714. + * These functions are used within the Machine Description to
  4715. + * handle common or complicated output and expansions from
  4716. + * instructions.
  4717. + ***************************************/
  4718. +
  4719. +int
  4720. +nios2_emit_move_sequence (rtx *operands, enum machine_mode mode)
  4721. +{
  4722. + rtx to = operands[0];
  4723. + rtx from = operands[1];
  4724. +
  4725. + if (!register_operand (to, mode) && !reg_or_0_operand (from, mode))
  4726. + {
  4727. + if (no_new_pseudos)
  4728. + internal_error ("Trying to force_reg no_new_pseudos == 1");
  4729. + from = copy_to_mode_reg (mode, from);
  4730. + }
  4731. +
  4732. + operands[0] = to;
  4733. + operands[1] = from;
  4734. + return 0;
  4735. +}
  4736. +
  4737. +/* Divide Support */
  4738. +
  4739. +/*
  4740. + If -O3 is used, we want to output a table lookup for
  4741. + divides between small numbers (both num and den >= 0
  4742. + and < 0x10). The overhead of this method in the worse
  4743. + case is 40 bytes in the text section (10 insns) and
  4744. + 256 bytes in the data section. Additional divides do
  4745. + not incur additional penalties in the data section.
  4746. +
  4747. + Code speed is improved for small divides by about 5x
  4748. + when using this method in the worse case (~9 cycles
  4749. + vs ~45). And in the worse case divides not within the
  4750. + table are penalized by about 10% (~5 cycles vs ~45).
  4751. + However in the typical case the penalty is not as bad
  4752. + because doing the long divide in only 45 cycles is
  4753. + quite optimistic.
  4754. +
  4755. + ??? It would be nice to have some benchmarks other
  4756. + than Dhrystone to back this up.
  4757. +
  4758. + This bit of expansion is to create this instruction
  4759. + sequence as rtl.
  4760. + or $8, $4, $5
  4761. + slli $9, $4, 4
  4762. + cmpgeui $3, $8, 16
  4763. + beq $3, $0, .L3
  4764. + or $10, $9, $5
  4765. + add $12, $11, divide_table
  4766. + ldbu $2, 0($12)
  4767. + br .L1
  4768. +.L3:
  4769. + call slow_div
  4770. +.L1:
  4771. +# continue here with result in $2
  4772. +
  4773. + ??? Ideally I would like the emit libcall block to contain
  4774. + all of this code, but I don't know how to do that. What it
  4775. + means is that if the divide can be eliminated, it may not
  4776. + completely disappear.
  4777. +
  4778. + ??? The __divsi3_table label should ideally be moved out
  4779. + of this block and into a global. If it is placed into the
  4780. + sdata section we can save even more cycles by doing things
  4781. + gp relative.
  4782. +*/
  4783. +int
  4784. +nios2_emit_expensive_div (rtx *operands, enum machine_mode mode)
  4785. +{
  4786. + rtx or_result, shift_left_result;
  4787. + rtx lookup_value;
  4788. + rtx lab1, lab3;
  4789. + rtx insns;
  4790. + rtx libfunc;
  4791. + rtx final_result;
  4792. + rtx tmp;
  4793. +
  4794. + /* it may look a little generic, but only SImode
  4795. + is supported for now */
  4796. + if (mode != SImode)
  4797. + abort ();
  4798. +
  4799. + libfunc = sdiv_optab->handlers[(int) SImode].libfunc;
  4800. +
  4801. +
  4802. +
  4803. + lab1 = gen_label_rtx ();
  4804. + lab3 = gen_label_rtx ();
  4805. +
  4806. + or_result = expand_simple_binop (SImode, IOR,
  4807. + operands[1], operands[2],
  4808. + 0, 0, OPTAB_LIB_WIDEN);
  4809. +
  4810. + emit_cmp_and_jump_insns (or_result, GEN_INT (15), GTU, 0,
  4811. + GET_MODE (or_result), 0, lab3);
  4812. + JUMP_LABEL (get_last_insn ()) = lab3;
  4813. +
  4814. + shift_left_result = expand_simple_binop (SImode, ASHIFT,
  4815. + operands[1], GEN_INT (4),
  4816. + 0, 0, OPTAB_LIB_WIDEN);
  4817. +
  4818. + lookup_value = expand_simple_binop (SImode, IOR,
  4819. + shift_left_result, operands[2],
  4820. + 0, 0, OPTAB_LIB_WIDEN);
  4821. +
  4822. + convert_move (operands[0],
  4823. + gen_rtx (MEM, QImode,
  4824. + gen_rtx (PLUS, SImode,
  4825. + lookup_value,
  4826. + gen_rtx_SYMBOL_REF (SImode, "__divsi3_table"))),
  4827. + 1);
  4828. +
  4829. +
  4830. + tmp = emit_jump_insn (gen_jump (lab1));
  4831. + JUMP_LABEL (tmp) = lab1;
  4832. + emit_barrier ();
  4833. +
  4834. + emit_label (lab3);
  4835. + LABEL_NUSES (lab3) = 1;
  4836. +
  4837. + start_sequence ();
  4838. + final_result = emit_library_call_value (libfunc, NULL_RTX,
  4839. + LCT_CONST, SImode, 2,
  4840. + operands[1], SImode,
  4841. + operands[2], SImode);
  4842. +
  4843. +
  4844. + insns = get_insns ();
  4845. + end_sequence ();
  4846. + emit_libcall_block (insns, operands[0], final_result,
  4847. + gen_rtx (DIV, SImode, operands[1], operands[2]));
  4848. +
  4849. + emit_label (lab1);
  4850. + LABEL_NUSES (lab1) = 1;
  4851. + return 1;
  4852. +}
  4853. +
  4854. +/* Branches/Compares */
  4855. +
  4856. +/* the way of handling branches/compares
  4857. + in gcc is heavily borrowed from MIPS */
  4858. +
  4859. +enum internal_test
  4860. +{
  4861. + ITEST_EQ,
  4862. + ITEST_NE,
  4863. + ITEST_GT,
  4864. + ITEST_GE,
  4865. + ITEST_LT,
  4866. + ITEST_LE,
  4867. + ITEST_GTU,
  4868. + ITEST_GEU,
  4869. + ITEST_LTU,
  4870. + ITEST_LEU,
  4871. + ITEST_MAX
  4872. +};
  4873. +
  4874. +static enum internal_test map_test_to_internal_test (enum rtx_code);
  4875. +
  4876. +/* Cached operands, and operator to compare for use in set/branch/trap
  4877. + on condition codes. */
  4878. +rtx branch_cmp[2];
  4879. +enum cmp_type branch_type;
  4880. +
  4881. +/* Make normal rtx_code into something we can index from an array */
  4882. +
  4883. +static enum internal_test
  4884. +map_test_to_internal_test (enum rtx_code test_code)
  4885. +{
  4886. + enum internal_test test = ITEST_MAX;
  4887. +
  4888. + switch (test_code)
  4889. + {
  4890. + case EQ:
  4891. + test = ITEST_EQ;
  4892. + break;
  4893. + case NE:
  4894. + test = ITEST_NE;
  4895. + break;
  4896. + case GT:
  4897. + test = ITEST_GT;
  4898. + break;
  4899. + case GE:
  4900. + test = ITEST_GE;
  4901. + break;
  4902. + case LT:
  4903. + test = ITEST_LT;
  4904. + break;
  4905. + case LE:
  4906. + test = ITEST_LE;
  4907. + break;
  4908. + case GTU:
  4909. + test = ITEST_GTU;
  4910. + break;
  4911. + case GEU:
  4912. + test = ITEST_GEU;
  4913. + break;
  4914. + case LTU:
  4915. + test = ITEST_LTU;
  4916. + break;
  4917. + case LEU:
  4918. + test = ITEST_LEU;
  4919. + break;
  4920. + default:
  4921. + break;
  4922. + }
  4923. +
  4924. + return test;
  4925. +}
  4926. +
  4927. +/* Generate the code to compare (and possibly branch) two integer values
  4928. + TEST_CODE is the comparison code we are trying to emulate
  4929. + (or implement directly)
  4930. + RESULT is where to store the result of the comparison,
  4931. + or null to emit a branch
  4932. + CMP0 CMP1 are the two comparison operands
  4933. + DESTINATION is the destination of the branch, or null to only compare
  4934. + */
  4935. +
  4936. +void
  4937. +gen_int_relational (enum rtx_code test_code, /* relational test (EQ, etc) */
  4938. + rtx result, /* result to store comp. or 0 if branch */
  4939. + rtx cmp0, /* first operand to compare */
  4940. + rtx cmp1, /* second operand to compare */
  4941. + rtx destination) /* destination of the branch, or 0 if compare */
  4942. +{
  4943. + struct cmp_info
  4944. + {
  4945. + /* for register (or 0) compares */
  4946. + enum rtx_code test_code_reg; /* code to use in instruction (LT vs. LTU) */
  4947. + int reverse_regs; /* reverse registers in test */
  4948. +
  4949. + /* for immediate compares */
  4950. + enum rtx_code test_code_const;
  4951. + /* code to use in instruction (LT vs. LTU) */
  4952. + int const_low; /* low bound of constant we can accept */
  4953. + int const_high; /* high bound of constant we can accept */
  4954. + int const_add; /* constant to add */
  4955. +
  4956. + /* generic info */
  4957. + int unsignedp; /* != 0 for unsigned comparisons. */
  4958. + };
  4959. +
  4960. + static const struct cmp_info info[(int) ITEST_MAX] = {
  4961. +
  4962. + {EQ, 0, EQ, -32768, 32767, 0, 0}, /* EQ */
  4963. + {NE, 0, NE, -32768, 32767, 0, 0}, /* NE */
  4964. +
  4965. + {LT, 1, GE, -32769, 32766, 1, 0}, /* GT */
  4966. + {GE, 0, GE, -32768, 32767, 0, 0}, /* GE */
  4967. + {LT, 0, LT, -32768, 32767, 0, 0}, /* LT */
  4968. + {GE, 1, LT, -32769, 32766, 1, 0}, /* LE */
  4969. +
  4970. + {LTU, 1, GEU, 0, 65534, 1, 0}, /* GTU */
  4971. + {GEU, 0, GEU, 0, 65535, 0, 0}, /* GEU */
  4972. + {LTU, 0, LTU, 0, 65535, 0, 0}, /* LTU */
  4973. + {GEU, 1, LTU, 0, 65534, 1, 0}, /* LEU */
  4974. + };
  4975. +
  4976. + enum internal_test test;
  4977. + enum machine_mode mode;
  4978. + const struct cmp_info *p_info;
  4979. + int branch_p;
  4980. +
  4981. +
  4982. +
  4983. +
  4984. + test = map_test_to_internal_test (test_code);
  4985. + if (test == ITEST_MAX)
  4986. + abort ();
  4987. +
  4988. + p_info = &info[(int) test];
  4989. +
  4990. + mode = GET_MODE (cmp0);
  4991. + if (mode == VOIDmode)
  4992. + mode = GET_MODE (cmp1);
  4993. +
  4994. + branch_p = (destination != 0);
  4995. +
  4996. + /* We can't, under any circumstances, have const_ints in cmp0
  4997. + ??? Actually we could have const0 */
  4998. + if (GET_CODE (cmp0) == CONST_INT)
  4999. + cmp0 = force_reg (mode, cmp0);
  5000. +
  5001. + /* if the comparison is against an int not in legal range
  5002. + move it into a register */
  5003. + if (GET_CODE (cmp1) == CONST_INT)
  5004. + {
  5005. + HOST_WIDE_INT value = INTVAL (cmp1);
  5006. +
  5007. + if (value < p_info->const_low || value > p_info->const_high)
  5008. + cmp1 = force_reg (mode, cmp1);
  5009. + }
  5010. +
  5011. + /* Comparison to constants, may involve adding 1 to change a GT into GE.
  5012. + Comparison between two registers, may involve switching operands. */
  5013. + if (GET_CODE (cmp1) == CONST_INT)
  5014. + {
  5015. + if (p_info->const_add != 0)
  5016. + {
  5017. + HOST_WIDE_INT new = INTVAL (cmp1) + p_info->const_add;
  5018. +
  5019. + /* If modification of cmp1 caused overflow,
  5020. + we would get the wrong answer if we follow the usual path;
  5021. + thus, x > 0xffffffffU would turn into x > 0U. */
  5022. + if ((p_info->unsignedp
  5023. + ? (unsigned HOST_WIDE_INT) new >
  5024. + (unsigned HOST_WIDE_INT) INTVAL (cmp1)
  5025. + : new > INTVAL (cmp1)) != (p_info->const_add > 0))
  5026. + {
  5027. + /* ??? This case can never happen with the current numbers,
  5028. + but I am paranoid and would rather an abort than
  5029. + a bug I will never find */
  5030. + abort ();
  5031. + }
  5032. + else
  5033. + cmp1 = GEN_INT (new);
  5034. + }
  5035. + }
  5036. +
  5037. + else if (p_info->reverse_regs)
  5038. + {
  5039. + rtx temp = cmp0;
  5040. + cmp0 = cmp1;
  5041. + cmp1 = temp;
  5042. + }
  5043. +
  5044. +
  5045. +
  5046. + if (branch_p)
  5047. + {
  5048. + if (register_operand (cmp0, mode) && register_operand (cmp1, mode))
  5049. + {
  5050. + rtx insn;
  5051. + rtx cond = gen_rtx (p_info->test_code_reg, mode, cmp0, cmp1);
  5052. + rtx label = gen_rtx_LABEL_REF (VOIDmode, destination);
  5053. +
  5054. + insn = gen_rtx_SET (VOIDmode, pc_rtx,
  5055. + gen_rtx_IF_THEN_ELSE (VOIDmode,
  5056. + cond, label, pc_rtx));
  5057. + emit_jump_insn (insn);
  5058. + }
  5059. + else
  5060. + {
  5061. + rtx cond, label;
  5062. +
  5063. + result = gen_reg_rtx (mode);
  5064. +
  5065. + emit_move_insn (result,
  5066. + gen_rtx (p_info->test_code_const, mode, cmp0,
  5067. + cmp1));
  5068. +
  5069. + cond = gen_rtx (NE, mode, result, const0_rtx);
  5070. + label = gen_rtx_LABEL_REF (VOIDmode, destination);
  5071. +
  5072. + emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
  5073. + gen_rtx_IF_THEN_ELSE (VOIDmode,
  5074. + cond,
  5075. + label, pc_rtx)));
  5076. + }
  5077. + }
  5078. + else
  5079. + {
  5080. + if (register_operand (cmp0, mode) && register_operand (cmp1, mode))
  5081. + {
  5082. + emit_move_insn (result,
  5083. + gen_rtx (p_info->test_code_reg, mode, cmp0, cmp1));
  5084. + }
  5085. + else
  5086. + {
  5087. + emit_move_insn (result,
  5088. + gen_rtx (p_info->test_code_const, mode, cmp0,
  5089. + cmp1));
  5090. + }
  5091. + }
  5092. +
  5093. +}
  5094. +
  5095. +
  5096. +/* ??? For now conditional moves are only supported
  5097. + when the mode of the operands being compared are
  5098. + the same as the ones being moved */
  5099. +
  5100. +void
  5101. +gen_conditional_move (rtx *operands, enum machine_mode mode)
  5102. +{
  5103. + rtx insn, cond;
  5104. + rtx cmp_reg = gen_reg_rtx (mode);
  5105. + enum rtx_code cmp_code = GET_CODE (operands[1]);
  5106. + enum rtx_code move_code = EQ;
  5107. +
  5108. + /* emit a comparison if it is not "simple".
  5109. + Simple comparisons are X eq 0 and X ne 0 */
  5110. + if ((cmp_code == EQ || cmp_code == NE) && branch_cmp[1] == const0_rtx)
  5111. + {
  5112. + cmp_reg = branch_cmp[0];
  5113. + move_code = cmp_code;
  5114. + }
  5115. + else if ((cmp_code == EQ || cmp_code == NE) && branch_cmp[0] == const0_rtx)
  5116. + {
  5117. + cmp_reg = branch_cmp[1];
  5118. + move_code = cmp_code == EQ ? NE : EQ;
  5119. + }
  5120. + else
  5121. + gen_int_relational (cmp_code, cmp_reg, branch_cmp[0], branch_cmp[1],
  5122. + NULL_RTX);
  5123. +
  5124. + cond = gen_rtx (move_code, VOIDmode, cmp_reg, CONST0_RTX (mode));
  5125. + insn = gen_rtx_SET (mode, operands[0],
  5126. + gen_rtx_IF_THEN_ELSE (mode,
  5127. + cond, operands[2], operands[3]));
  5128. + emit_insn (insn);
  5129. +}
  5130. +
  5131. +/*******************
  5132. + * Addressing Modes
  5133. + *******************/
  5134. +
  5135. +int
  5136. +nios2_legitimate_address (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED,
  5137. + int strict)
  5138. +{
  5139. + int ret_val = 0;
  5140. +
  5141. + switch (GET_CODE (operand))
  5142. + {
  5143. + /* direct. */
  5144. + case SYMBOL_REF:
  5145. + if (SYMBOL_REF_IN_NIOS2_SMALL_DATA_P (operand))
  5146. + {
  5147. + ret_val = 1;
  5148. + break;
  5149. + }
  5150. + /* else, fall through */
  5151. + case LABEL_REF:
  5152. + case CONST_INT:
  5153. + case CONST:
  5154. + case CONST_DOUBLE:
  5155. + /* ??? In here I need to add gp addressing */
  5156. + ret_val = 0;
  5157. +
  5158. + break;
  5159. +
  5160. + /* Register indirect. */
  5161. + case REG:
  5162. + ret_val = REG_OK_FOR_BASE_P2 (operand, strict);
  5163. + break;
  5164. +
  5165. + /* Register indirect with displacement */
  5166. + case PLUS:
  5167. + {
  5168. + rtx op0 = XEXP (operand, 0);
  5169. + rtx op1 = XEXP (operand, 1);
  5170. +
  5171. + if (REG_P (op0) && REG_P (op1))
  5172. + ret_val = 0;
  5173. + else if (REG_P (op0) && CONSTANT_P (op1))
  5174. + ret_val = REG_OK_FOR_BASE_P2 (op0, strict)
  5175. + && SMALL_INT (INTVAL (op1));
  5176. + else if (REG_P (op1) && CONSTANT_P (op0))
  5177. + ret_val = REG_OK_FOR_BASE_P2 (op1, strict)
  5178. + && SMALL_INT (INTVAL (op0));
  5179. + else
  5180. + ret_val = 0;
  5181. + }
  5182. + break;
  5183. +
  5184. + default:
  5185. + ret_val = 0;
  5186. + break;
  5187. + }
  5188. +
  5189. + return ret_val;
  5190. +}
  5191. +
  5192. +/* Return true if EXP should be placed in the small data section. */
  5193. +
  5194. +static bool
  5195. +nios2_in_small_data_p (tree exp)
  5196. +{
  5197. + /* We want to merge strings, so we never consider them small data. */
  5198. + if (TREE_CODE (exp) == STRING_CST)
  5199. + return false;
  5200. +
  5201. + if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
  5202. + {
  5203. + const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
  5204. + /* ??? these string names need moving into
  5205. + an array in some header file */
  5206. + if (nios2_section_threshold > 0
  5207. + && (strcmp (section, ".sbss") == 0
  5208. + || strncmp (section, ".sbss.", 6) == 0
  5209. + || strcmp (section, ".sdata") == 0
  5210. + || strncmp (section, ".sdata.", 7) == 0))
  5211. + return true;
  5212. + }
  5213. + else if (TREE_CODE (exp) == VAR_DECL)
  5214. + {
  5215. + HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
  5216. +
  5217. + /* If this is an incomplete type with size 0, then we can't put it
  5218. + in sdata because it might be too big when completed. */
  5219. + if (size > 0 && size <= nios2_section_threshold)
  5220. + return true;
  5221. + }
  5222. +
  5223. + return false;
  5224. +}
  5225. +
  5226. +static void
  5227. +nios2_encode_section_info (tree decl, rtx rtl, int first)
  5228. +{
  5229. +
  5230. + rtx symbol;
  5231. + int flags;
  5232. +
  5233. + default_encode_section_info (decl, rtl, first);
  5234. +
  5235. + /* Careful not to prod global register variables. */
  5236. + if (GET_CODE (rtl) != MEM)
  5237. + return;
  5238. + symbol = XEXP (rtl, 0);
  5239. + if (GET_CODE (symbol) != SYMBOL_REF)
  5240. + return;
  5241. +
  5242. + flags = SYMBOL_REF_FLAGS (symbol);
  5243. +
  5244. + /* We don't want weak variables to be addressed with gp in case they end up with
  5245. + value 0 which is not within 2^15 of $gp */
  5246. + if (DECL_P (decl) && DECL_WEAK (decl))
  5247. + flags |= SYMBOL_FLAG_WEAK_DECL;
  5248. +
  5249. + SYMBOL_REF_FLAGS (symbol) = flags;
  5250. +}
  5251. +
  5252. +
  5253. +static unsigned int
  5254. +nios2_section_type_flags (tree decl, const char *name, int reloc)
  5255. +{
  5256. + unsigned int flags;
  5257. +
  5258. + flags = default_section_type_flags (decl, name, reloc);
  5259. +
  5260. + /* ??? these string names need moving into an array in some header file */
  5261. + if (strcmp (name, ".sbss") == 0
  5262. + || strncmp (name, ".sbss.", 6) == 0
  5263. + || strcmp (name, ".sdata") == 0
  5264. + || strncmp (name, ".sdata.", 7) == 0)
  5265. + flags |= SECTION_SMALL;
  5266. +
  5267. + return flags;
  5268. +}
  5269. +
  5270. +
  5271. +
  5272. +
  5273. +/*****************************************
  5274. + * Defining the Output Assembler Language
  5275. + *****************************************/
  5276. +
  5277. +/* -------------- *
  5278. + * Output of Data
  5279. + * -------------- */
  5280. +
  5281. +
  5282. +/* -------------------------------- *
  5283. + * Output of Assembler Instructions
  5284. + * -------------------------------- */
  5285. +
  5286. +
  5287. +/* print the operand OP to file stream
  5288. + FILE modified by LETTER. LETTER
  5289. + can be one of:
  5290. + i: print "i" if OP is an immediate, except 0
  5291. + o: print "io" if OP is volatile
  5292. +
  5293. + z: for const0_rtx print $0 instead of 0
  5294. + H: for %hiadj
  5295. + L: for %lo
  5296. + U: for upper half of 32 bit value
  5297. + */
  5298. +
  5299. +void
  5300. +nios2_print_operand (FILE *file, rtx op, int letter)
  5301. +{
  5302. +
  5303. + switch (letter)
  5304. + {
  5305. + case 'i':
  5306. + if (CONSTANT_P (op) && (op != const0_rtx))
  5307. + fprintf (file, "i");
  5308. + return;
  5309. +
  5310. + case 'o':
  5311. + if (GET_CODE (op) == MEM
  5312. + && ((MEM_VOLATILE_P (op) && !TARGET_CACHE_VOLATILE)
  5313. + || TARGET_BYPASS_CACHE))
  5314. + fprintf (file, "io");
  5315. + return;
  5316. +
  5317. + default:
  5318. + break;
  5319. + }
  5320. +
  5321. + if (comparison_operator (op, VOIDmode))
  5322. + {
  5323. + if (letter == 0)
  5324. + {
  5325. + fprintf (file, "%s", GET_RTX_NAME (GET_CODE (op)));
  5326. + return;
  5327. + }
  5328. + }
  5329. +
  5330. +
  5331. + switch (GET_CODE (op))
  5332. + {
  5333. + case REG:
  5334. + if (letter == 0 || letter == 'z')
  5335. + {
  5336. + fprintf (file, "%s", reg_names[REGNO (op)]);
  5337. + return;
  5338. + }
  5339. +
  5340. + case CONST_INT:
  5341. + if (INTVAL (op) == 0 && letter == 'z')
  5342. + {
  5343. + fprintf (file, "zero");
  5344. + return;
  5345. + }
  5346. + else if (letter == 'U')
  5347. + {
  5348. + HOST_WIDE_INT val = INTVAL (op);
  5349. + rtx new_op;
  5350. + val = (val / 65536) & 0xFFFF;
  5351. + new_op = GEN_INT (val);
  5352. + output_addr_const (file, new_op);
  5353. + return;
  5354. + }
  5355. +
  5356. + /* else, fall through */
  5357. + case CONST:
  5358. + case LABEL_REF:
  5359. + case SYMBOL_REF:
  5360. + case CONST_DOUBLE:
  5361. + if (letter == 0 || letter == 'z')
  5362. + {
  5363. + output_addr_const (file, op);
  5364. + return;
  5365. + }
  5366. + else if (letter == 'H')
  5367. + {
  5368. + fprintf (file, "%%hiadj(");
  5369. + output_addr_const (file, op);
  5370. + fprintf (file, ")");
  5371. + return;
  5372. + }
  5373. + else if (letter == 'L')
  5374. + {
  5375. + fprintf (file, "%%lo(");
  5376. + output_addr_const (file, op);
  5377. + fprintf (file, ")");
  5378. + return;
  5379. + }
  5380. +
  5381. +
  5382. + case SUBREG:
  5383. + case MEM:
  5384. + if (letter == 0)
  5385. + {
  5386. + output_address (op);
  5387. + return;
  5388. + }
  5389. +
  5390. + case CODE_LABEL:
  5391. + if (letter == 0)
  5392. + {
  5393. + output_addr_const (file, op);
  5394. + return;
  5395. + }
  5396. +
  5397. + default:
  5398. + break;
  5399. + }
  5400. +
  5401. + fprintf (stderr, "Missing way to print (%c) ", letter);
  5402. + debug_rtx (op);
  5403. + abort ();
  5404. +}
  5405. +
  5406. +static int gprel_constant (rtx);
  5407. +
  5408. +static int
  5409. +gprel_constant (rtx op)
  5410. +{
  5411. + if (GET_CODE (op) == SYMBOL_REF
  5412. + && SYMBOL_REF_IN_NIOS2_SMALL_DATA_P (op))
  5413. + {
  5414. + return 1;
  5415. + }
  5416. + else if (GET_CODE (op) == CONST
  5417. + && GET_CODE (XEXP (op, 0)) == PLUS)
  5418. + {
  5419. + return gprel_constant (XEXP (XEXP (op, 0), 0));
  5420. + }
  5421. + else
  5422. + {
  5423. + return 0;
  5424. + }
  5425. +}
  5426. +
  5427. +void
  5428. +nios2_print_operand_address (FILE *file, rtx op)
  5429. +{
  5430. + switch (GET_CODE (op))
  5431. + {
  5432. + case CONST:
  5433. + case CONST_INT:
  5434. + case LABEL_REF:
  5435. + case CONST_DOUBLE:
  5436. + case SYMBOL_REF:
  5437. + if (gprel_constant (op))
  5438. + {
  5439. + fprintf (file, "%%gprel(");
  5440. + output_addr_const (file, op);
  5441. + fprintf (file, ")(%s)", reg_names[GP_REGNO]);
  5442. + return;
  5443. + }
  5444. +
  5445. + break;
  5446. +
  5447. + case PLUS:
  5448. + {
  5449. + rtx op0 = XEXP (op, 0);
  5450. + rtx op1 = XEXP (op, 1);
  5451. +
  5452. + if (REG_P (op0) && CONSTANT_P (op1))
  5453. + {
  5454. + output_addr_const (file, op1);
  5455. + fprintf (file, "(%s)", reg_names[REGNO (op0)]);
  5456. + return;
  5457. + }
  5458. + else if (REG_P (op1) && CONSTANT_P (op0))
  5459. + {
  5460. + output_addr_const (file, op0);
  5461. + fprintf (file, "(%s)", reg_names[REGNO (op1)]);
  5462. + return;
  5463. + }
  5464. + }
  5465. + break;
  5466. +
  5467. + case REG:
  5468. + fprintf (file, "0(%s)", reg_names[REGNO (op)]);
  5469. + return;
  5470. +
  5471. + case MEM:
  5472. + {
  5473. + rtx base = XEXP (op, 0);
  5474. + PRINT_OPERAND_ADDRESS (file, base);
  5475. + return;
  5476. + }
  5477. + default:
  5478. + break;
  5479. + }
  5480. +
  5481. + fprintf (stderr, "Missing way to print address\n");
  5482. + debug_rtx (op);
  5483. + abort ();
  5484. +}
  5485. +
  5486. +
  5487. +
  5488. +
  5489. +
  5490. +/****************************
  5491. + * Predicates
  5492. + ****************************/
  5493. +
  5494. +int
  5495. +arith_operand (rtx op, enum machine_mode mode)
  5496. +{
  5497. + if (GET_CODE (op) == CONST_INT && SMALL_INT (INTVAL (op)))
  5498. + return 1;
  5499. +
  5500. + return register_operand (op, mode);
  5501. +}
  5502. +
  5503. +int
  5504. +uns_arith_operand (rtx op, enum machine_mode mode)
  5505. +{
  5506. + if (GET_CODE (op) == CONST_INT && SMALL_INT_UNSIGNED (INTVAL (op)))
  5507. + return 1;
  5508. +
  5509. + return register_operand (op, mode);
  5510. +}
  5511. +
  5512. +int
  5513. +logical_operand (rtx op, enum machine_mode mode)
  5514. +{
  5515. + if (GET_CODE (op) == CONST_INT
  5516. + && (SMALL_INT_UNSIGNED (INTVAL (op)) || UPPER16_INT (INTVAL (op))))
  5517. + return 1;
  5518. +
  5519. + return register_operand (op, mode);
  5520. +}
  5521. +
  5522. +int
  5523. +shift_operand (rtx op, enum machine_mode mode)
  5524. +{
  5525. + if (GET_CODE (op) == CONST_INT && SHIFT_INT (INTVAL (op)))
  5526. + return 1;
  5527. +
  5528. + return register_operand (op, mode);
  5529. +}
  5530. +
  5531. +int
  5532. +rdwrctl_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
  5533. +{
  5534. + return GET_CODE (op) == CONST_INT && RDWRCTL_INT (INTVAL (op));
  5535. +}
  5536. +
  5537. +/* Return truth value of whether OP is a register or the constant 0. */
  5538. +
  5539. +int
  5540. +reg_or_0_operand (rtx op, enum machine_mode mode)
  5541. +{
  5542. + switch (GET_CODE (op))
  5543. + {
  5544. + case CONST_INT:
  5545. + return INTVAL (op) == 0;
  5546. +
  5547. + case CONST_DOUBLE:
  5548. + return op == CONST0_RTX (mode);
  5549. +
  5550. + default:
  5551. + break;
  5552. + }
  5553. +
  5554. + return register_operand (op, mode);
  5555. +}
  5556. +
  5557. +
  5558. +int
  5559. +equality_op (rtx op, enum machine_mode mode)
  5560. +{
  5561. + if (mode != GET_MODE (op))
  5562. + return 0;
  5563. +
  5564. + return GET_CODE (op) == EQ || GET_CODE (op) == NE;
  5565. +}
  5566. +
  5567. +int
  5568. +custom_insn_opcode (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
  5569. +{
  5570. + return GET_CODE (op) == CONST_INT && CUSTOM_INSN_OPCODE (INTVAL (op));
  5571. +}
  5572. +
  5573. +
  5574. +
  5575. +
  5576. +
  5577. +
  5578. +
  5579. +/*****************************************************************************
  5580. +**
  5581. +** instruction scheduler
  5582. +**
  5583. +*****************************************************************************/
  5584. +static int
  5585. +nios2_use_dfa_pipeline_interface ()
  5586. +{
  5587. + return 1;
  5588. +}
  5589. +
  5590. +
  5591. +static int
  5592. +nios2_issue_rate ()
  5593. +{
  5594. +#ifdef MAX_DFA_ISSUE_RATE
  5595. + return MAX_DFA_ISSUE_RATE;
  5596. +#else
  5597. + return 1;
  5598. +#endif
  5599. +}
  5600. +
  5601. +
  5602. +const char *
  5603. +asm_output_opcode (FILE *file ATTRIBUTE_UNUSED,
  5604. + const char *ptr ATTRIBUTE_UNUSED)
  5605. +{
  5606. + const char *p;
  5607. +
  5608. + p = ptr;
  5609. + return ptr;
  5610. +}
  5611. +
  5612. +
  5613. +
  5614. +/*****************************************************************************
  5615. +**
  5616. +** function arguments
  5617. +**
  5618. +*****************************************************************************/
  5619. +
  5620. +void
  5621. +init_cumulative_args (CUMULATIVE_ARGS *cum,
  5622. + tree fntype ATTRIBUTE_UNUSED,
  5623. + rtx libname ATTRIBUTE_UNUSED,
  5624. + tree fndecl ATTRIBUTE_UNUSED,
  5625. + int n_named_args ATTRIBUTE_UNUSED)
  5626. +{
  5627. + cum->regs_used = 0;
  5628. +}
  5629. +
  5630. +
  5631. +/* Update the data in CUM to advance over an argument
  5632. + of mode MODE and data type TYPE.
  5633. + (TYPE is null for libcalls where that information may not be available.) */
  5634. +
  5635. +void
  5636. +function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
  5637. + tree type ATTRIBUTE_UNUSED, int named ATTRIBUTE_UNUSED)
  5638. +{
  5639. + HOST_WIDE_INT param_size;
  5640. +
  5641. + if (mode == BLKmode)
  5642. + {
  5643. + param_size = int_size_in_bytes (type);
  5644. + if (param_size < 0)
  5645. + internal_error
  5646. + ("Do not know how to handle large structs or variable length types");
  5647. + }
  5648. + else
  5649. + {
  5650. + param_size = GET_MODE_SIZE (mode);
  5651. + }
  5652. +
  5653. + /* convert to words (round up) */
  5654. + param_size = (3 + param_size) / 4;
  5655. +
  5656. + if (cum->regs_used + param_size > NUM_ARG_REGS)
  5657. + {
  5658. + cum->regs_used = NUM_ARG_REGS;
  5659. + }
  5660. + else
  5661. + {
  5662. + cum->regs_used += param_size;
  5663. + }
  5664. +
  5665. + return;
  5666. +}
  5667. +
  5668. +/* Define where to put the arguments to a function. Value is zero to
  5669. + push the argument on the stack, or a hard register in which to
  5670. + store the argument.
  5671. +
  5672. + MODE is the argument's machine mode.
  5673. + TYPE is the data type of the argument (as a tree).
  5674. + This is null for libcalls where that information may
  5675. + not be available.
  5676. + CUM is a variable of type CUMULATIVE_ARGS which gives info about
  5677. + the preceding args and about the function being called.
  5678. + NAMED is nonzero if this argument is a named parameter
  5679. + (otherwise it is an extra parameter matching an ellipsis). */
  5680. +rtx
  5681. +function_arg (const CUMULATIVE_ARGS *cum, enum machine_mode mode,
  5682. + tree type ATTRIBUTE_UNUSED, int named ATTRIBUTE_UNUSED)
  5683. +{
  5684. + rtx return_rtx = NULL_RTX;
  5685. +
  5686. + if (cum->regs_used < NUM_ARG_REGS)
  5687. + {
  5688. + return_rtx = gen_rtx_REG (mode, FIRST_ARG_REGNO + cum->regs_used);
  5689. + }
  5690. +
  5691. + return return_rtx;
  5692. +}
  5693. +
  5694. +int
  5695. +function_arg_partial_nregs (const CUMULATIVE_ARGS *cum,
  5696. + enum machine_mode mode, tree type,
  5697. + int named ATTRIBUTE_UNUSED)
  5698. +{
  5699. + HOST_WIDE_INT param_size;
  5700. +
  5701. + if (mode == BLKmode)
  5702. + {
  5703. + param_size = int_size_in_bytes (type);
  5704. + if (param_size < 0)
  5705. + internal_error
  5706. + ("Do not know how to handle large structs or variable length types");
  5707. + }
  5708. + else
  5709. + {
  5710. + param_size = GET_MODE_SIZE (mode);
  5711. + }
  5712. +
  5713. + /* convert to words (round up) */
  5714. + param_size = (3 + param_size) / 4;
  5715. +
  5716. + if (cum->regs_used < NUM_ARG_REGS
  5717. + && cum->regs_used + param_size > NUM_ARG_REGS)
  5718. + {
  5719. + return NUM_ARG_REGS - cum->regs_used;
  5720. + }
  5721. + else
  5722. + {
  5723. + return 0;
  5724. + }
  5725. +}
  5726. +
  5727. +
  5728. +int
  5729. +nios2_return_in_memory (tree type)
  5730. +{
  5731. + int res = ((int_size_in_bytes (type) > (2 * UNITS_PER_WORD))
  5732. + || (int_size_in_bytes (type) == -1));
  5733. +
  5734. + return res;
  5735. +}
  5736. +
  5737. +/* ??? It may be possible to eliminate the copyback and implement
  5738. + my own va_arg type, but that is more work for now. */
  5739. +int
  5740. +nios2_setup_incoming_varargs (const CUMULATIVE_ARGS *cum,
  5741. + enum machine_mode mode, tree type,
  5742. + int no_rtl)
  5743. +{
  5744. + CUMULATIVE_ARGS local_cum;
  5745. + int regs_to_push;
  5746. +
  5747. + local_cum = *cum;
  5748. + FUNCTION_ARG_ADVANCE (local_cum, mode, type, 1);
  5749. +
  5750. + regs_to_push = NUM_ARG_REGS - local_cum.regs_used;
  5751. +
  5752. + if (!no_rtl)
  5753. + {
  5754. + if (regs_to_push > 0)
  5755. + {
  5756. + rtx ptr, mem;
  5757. +
  5758. + ptr = virtual_incoming_args_rtx;
  5759. + mem = gen_rtx_MEM (BLKmode, ptr);
  5760. +
  5761. + /* va_arg is an array access in this case, which causes
  5762. + it to get MEM_IN_STRUCT_P set. We must set it here
  5763. + so that the insn scheduler won't assume that these
  5764. + stores can't possibly overlap with the va_arg loads. */
  5765. + MEM_SET_IN_STRUCT_P (mem, 1);
  5766. +
  5767. + emit_insn (gen_blockage ());
  5768. + move_block_from_reg (local_cum.regs_used + FIRST_ARG_REGNO, mem,
  5769. + regs_to_push);
  5770. + emit_insn (gen_blockage ());
  5771. + }
  5772. + }
  5773. +
  5774. + return regs_to_push * UNITS_PER_WORD;
  5775. +
  5776. +}
  5777. +
  5778. +
  5779. +
  5780. +/*****************************************************************************
  5781. +**
  5782. +** builtins
  5783. +**
  5784. +** This method for handling builtins is from CSP where _many_ more types of
  5785. +** expanders have already been written. Check there first before writing
  5786. +** new ones.
  5787. +**
  5788. +*****************************************************************************/
  5789. +
  5790. +enum nios2_builtins
  5791. +{
  5792. + NIOS2_BUILTIN_LDBIO,
  5793. + NIOS2_BUILTIN_LDBUIO,
  5794. + NIOS2_BUILTIN_LDHIO,
  5795. + NIOS2_BUILTIN_LDHUIO,
  5796. + NIOS2_BUILTIN_LDWIO,
  5797. + NIOS2_BUILTIN_STBIO,
  5798. + NIOS2_BUILTIN_STHIO,
  5799. + NIOS2_BUILTIN_STWIO,
  5800. + NIOS2_BUILTIN_SYNC,
  5801. + NIOS2_BUILTIN_RDCTL,
  5802. + NIOS2_BUILTIN_WRCTL,
  5803. +
  5804. + NIOS2_BUILTIN_CUSTOM_N,
  5805. + NIOS2_BUILTIN_CUSTOM_NI,
  5806. + NIOS2_BUILTIN_CUSTOM_NF,
  5807. + NIOS2_BUILTIN_CUSTOM_NP,
  5808. + NIOS2_BUILTIN_CUSTOM_NII,
  5809. + NIOS2_BUILTIN_CUSTOM_NIF,
  5810. + NIOS2_BUILTIN_CUSTOM_NIP,
  5811. + NIOS2_BUILTIN_CUSTOM_NFI,
  5812. + NIOS2_BUILTIN_CUSTOM_NFF,
  5813. + NIOS2_BUILTIN_CUSTOM_NFP,
  5814. + NIOS2_BUILTIN_CUSTOM_NPI,
  5815. + NIOS2_BUILTIN_CUSTOM_NPF,
  5816. + NIOS2_BUILTIN_CUSTOM_NPP,
  5817. + NIOS2_BUILTIN_CUSTOM_IN,
  5818. + NIOS2_BUILTIN_CUSTOM_INI,
  5819. + NIOS2_BUILTIN_CUSTOM_INF,
  5820. + NIOS2_BUILTIN_CUSTOM_INP,
  5821. + NIOS2_BUILTIN_CUSTOM_INII,
  5822. + NIOS2_BUILTIN_CUSTOM_INIF,
  5823. + NIOS2_BUILTIN_CUSTOM_INIP,
  5824. + NIOS2_BUILTIN_CUSTOM_INFI,
  5825. + NIOS2_BUILTIN_CUSTOM_INFF,
  5826. + NIOS2_BUILTIN_CUSTOM_INFP,
  5827. + NIOS2_BUILTIN_CUSTOM_INPI,
  5828. + NIOS2_BUILTIN_CUSTOM_INPF,
  5829. + NIOS2_BUILTIN_CUSTOM_INPP,
  5830. + NIOS2_BUILTIN_CUSTOM_FN,
  5831. + NIOS2_BUILTIN_CUSTOM_FNI,
  5832. + NIOS2_BUILTIN_CUSTOM_FNF,
  5833. + NIOS2_BUILTIN_CUSTOM_FNP,
  5834. + NIOS2_BUILTIN_CUSTOM_FNII,
  5835. + NIOS2_BUILTIN_CUSTOM_FNIF,
  5836. + NIOS2_BUILTIN_CUSTOM_FNIP,
  5837. + NIOS2_BUILTIN_CUSTOM_FNFI,
  5838. + NIOS2_BUILTIN_CUSTOM_FNFF,
  5839. + NIOS2_BUILTIN_CUSTOM_FNFP,
  5840. + NIOS2_BUILTIN_CUSTOM_FNPI,
  5841. + NIOS2_BUILTIN_CUSTOM_FNPF,
  5842. + NIOS2_BUILTIN_CUSTOM_FNPP,
  5843. + NIOS2_BUILTIN_CUSTOM_PN,
  5844. + NIOS2_BUILTIN_CUSTOM_PNI,
  5845. + NIOS2_BUILTIN_CUSTOM_PNF,
  5846. + NIOS2_BUILTIN_CUSTOM_PNP,
  5847. + NIOS2_BUILTIN_CUSTOM_PNII,
  5848. + NIOS2_BUILTIN_CUSTOM_PNIF,
  5849. + NIOS2_BUILTIN_CUSTOM_PNIP,
  5850. + NIOS2_BUILTIN_CUSTOM_PNFI,
  5851. + NIOS2_BUILTIN_CUSTOM_PNFF,
  5852. + NIOS2_BUILTIN_CUSTOM_PNFP,
  5853. + NIOS2_BUILTIN_CUSTOM_PNPI,
  5854. + NIOS2_BUILTIN_CUSTOM_PNPF,
  5855. + NIOS2_BUILTIN_CUSTOM_PNPP,
  5856. +
  5857. +
  5858. + LIM_NIOS2_BUILTINS
  5859. +};
  5860. +
  5861. +struct builtin_description
  5862. +{
  5863. + const enum insn_code icode;
  5864. + const char *const name;
  5865. + const enum nios2_builtins code;
  5866. + const tree *type;
  5867. + rtx (* expander) PARAMS ((const struct builtin_description *,
  5868. + tree, rtx, rtx, enum machine_mode, int));
  5869. +};
  5870. +
  5871. +static rtx nios2_expand_STXIO (const struct builtin_description *,
  5872. + tree, rtx, rtx, enum machine_mode, int);
  5873. +static rtx nios2_expand_LDXIO (const struct builtin_description *,
  5874. + tree, rtx, rtx, enum machine_mode, int);
  5875. +static rtx nios2_expand_sync (const struct builtin_description *,
  5876. + tree, rtx, rtx, enum machine_mode, int);
  5877. +static rtx nios2_expand_rdctl (const struct builtin_description *,
  5878. + tree, rtx, rtx, enum machine_mode, int);
  5879. +static rtx nios2_expand_wrctl (const struct builtin_description *,
  5880. + tree, rtx, rtx, enum machine_mode, int);
  5881. +
  5882. +static rtx nios2_expand_custom_n (const struct builtin_description *,
  5883. + tree, rtx, rtx, enum machine_mode, int);
  5884. +static rtx nios2_expand_custom_Xn (const struct builtin_description *,
  5885. + tree, rtx, rtx, enum machine_mode, int);
  5886. +static rtx nios2_expand_custom_nX (const struct builtin_description *,
  5887. + tree, rtx, rtx, enum machine_mode, int);
  5888. +static rtx nios2_expand_custom_XnX (const struct builtin_description *,
  5889. + tree, rtx, rtx, enum machine_mode, int);
  5890. +static rtx nios2_expand_custom_nXX (const struct builtin_description *,
  5891. + tree, rtx, rtx, enum machine_mode, int);
  5892. +static rtx nios2_expand_custom_XnXX (const struct builtin_description *,
  5893. + tree, rtx, rtx, enum machine_mode, int);
  5894. +
  5895. +static tree endlink;
  5896. +
  5897. +/* int fn (volatile const void *)
  5898. + */
  5899. +static tree int_ftype_volatile_const_void_p;
  5900. +
  5901. +/* int fn (int)
  5902. + */
  5903. +static tree int_ftype_int;
  5904. +
  5905. +/* void fn (int, int)
  5906. + */
  5907. +static tree void_ftype_int_int;
  5908. +
  5909. +/* void fn (volatile void *, int)
  5910. + */
  5911. +static tree void_ftype_volatile_void_p_int;
  5912. +
  5913. +/* void fn (void)
  5914. + */
  5915. +static tree void_ftype_void;
  5916. +
  5917. +static tree custom_n;
  5918. +static tree custom_ni;
  5919. +static tree custom_nf;
  5920. +static tree custom_np;
  5921. +static tree custom_nii;
  5922. +static tree custom_nif;
  5923. +static tree custom_nip;
  5924. +static tree custom_nfi;
  5925. +static tree custom_nff;
  5926. +static tree custom_nfp;
  5927. +static tree custom_npi;
  5928. +static tree custom_npf;
  5929. +static tree custom_npp;
  5930. +static tree custom_in;
  5931. +static tree custom_ini;
  5932. +static tree custom_inf;
  5933. +static tree custom_inp;
  5934. +static tree custom_inii;
  5935. +static tree custom_inif;
  5936. +static tree custom_inip;
  5937. +static tree custom_infi;
  5938. +static tree custom_inff;
  5939. +static tree custom_infp;
  5940. +static tree custom_inpi;
  5941. +static tree custom_inpf;
  5942. +static tree custom_inpp;
  5943. +static tree custom_fn;
  5944. +static tree custom_fni;
  5945. +static tree custom_fnf;
  5946. +static tree custom_fnp;
  5947. +static tree custom_fnii;
  5948. +static tree custom_fnif;
  5949. +static tree custom_fnip;
  5950. +static tree custom_fnfi;
  5951. +static tree custom_fnff;
  5952. +static tree custom_fnfp;
  5953. +static tree custom_fnpi;
  5954. +static tree custom_fnpf;
  5955. +static tree custom_fnpp;
  5956. +static tree custom_pn;
  5957. +static tree custom_pni;
  5958. +static tree custom_pnf;
  5959. +static tree custom_pnp;
  5960. +static tree custom_pnii;
  5961. +static tree custom_pnif;
  5962. +static tree custom_pnip;
  5963. +static tree custom_pnfi;
  5964. +static tree custom_pnff;
  5965. +static tree custom_pnfp;
  5966. +static tree custom_pnpi;
  5967. +static tree custom_pnpf;
  5968. +static tree custom_pnpp;
  5969. +
  5970. +
  5971. +static const struct builtin_description bdesc[] = {
  5972. + {CODE_FOR_ldbio, "__builtin_ldbio", NIOS2_BUILTIN_LDBIO, &int_ftype_volatile_const_void_p, nios2_expand_LDXIO},
  5973. + {CODE_FOR_ldbuio, "__builtin_ldbuio", NIOS2_BUILTIN_LDBUIO, &int_ftype_volatile_const_void_p, nios2_expand_LDXIO},
  5974. + {CODE_FOR_ldhio, "__builtin_ldhio", NIOS2_BUILTIN_LDHIO, &int_ftype_volatile_const_void_p, nios2_expand_LDXIO},
  5975. + {CODE_FOR_ldhuio, "__builtin_ldhuio", NIOS2_BUILTIN_LDHUIO, &int_ftype_volatile_const_void_p, nios2_expand_LDXIO},
  5976. + {CODE_FOR_ldwio, "__builtin_ldwio", NIOS2_BUILTIN_LDWIO, &int_ftype_volatile_const_void_p, nios2_expand_LDXIO},
  5977. +
  5978. + {CODE_FOR_stbio, "__builtin_stbio", NIOS2_BUILTIN_STBIO, &void_ftype_volatile_void_p_int, nios2_expand_STXIO},
  5979. + {CODE_FOR_sthio, "__builtin_sthio", NIOS2_BUILTIN_STHIO, &void_ftype_volatile_void_p_int, nios2_expand_STXIO},
  5980. + {CODE_FOR_stwio, "__builtin_stwio", NIOS2_BUILTIN_STWIO, &void_ftype_volatile_void_p_int, nios2_expand_STXIO},
  5981. +
  5982. + {CODE_FOR_sync, "__builtin_sync", NIOS2_BUILTIN_SYNC, &void_ftype_void, nios2_expand_sync},
  5983. + {CODE_FOR_rdctl, "__builtin_rdctl", NIOS2_BUILTIN_RDCTL, &int_ftype_int, nios2_expand_rdctl},
  5984. + {CODE_FOR_wrctl, "__builtin_wrctl", NIOS2_BUILTIN_WRCTL, &void_ftype_int_int, nios2_expand_wrctl},
  5985. +
  5986. + {CODE_FOR_custom_n, "__builtin_custom_n", NIOS2_BUILTIN_CUSTOM_N, &custom_n, nios2_expand_custom_n},
  5987. + {CODE_FOR_custom_ni, "__builtin_custom_ni", NIOS2_BUILTIN_CUSTOM_NI, &custom_ni, nios2_expand_custom_nX},
  5988. + {CODE_FOR_custom_nf, "__builtin_custom_nf", NIOS2_BUILTIN_CUSTOM_NF, &custom_nf, nios2_expand_custom_nX},
  5989. + {CODE_FOR_custom_np, "__builtin_custom_np", NIOS2_BUILTIN_CUSTOM_NP, &custom_np, nios2_expand_custom_nX},
  5990. + {CODE_FOR_custom_nii, "__builtin_custom_nii", NIOS2_BUILTIN_CUSTOM_NII, &custom_nii, nios2_expand_custom_nXX},
  5991. + {CODE_FOR_custom_nif, "__builtin_custom_nif", NIOS2_BUILTIN_CUSTOM_NIF, &custom_nif, nios2_expand_custom_nXX},
  5992. + {CODE_FOR_custom_nip, "__builtin_custom_nip", NIOS2_BUILTIN_CUSTOM_NIP, &custom_nip, nios2_expand_custom_nXX},
  5993. + {CODE_FOR_custom_nfi, "__builtin_custom_nfi", NIOS2_BUILTIN_CUSTOM_NFI, &custom_nfi, nios2_expand_custom_nXX},
  5994. + {CODE_FOR_custom_nff, "__builtin_custom_nff", NIOS2_BUILTIN_CUSTOM_NFF, &custom_nff, nios2_expand_custom_nXX},
  5995. + {CODE_FOR_custom_nfp, "__builtin_custom_nfp", NIOS2_BUILTIN_CUSTOM_NFP, &custom_nfp, nios2_expand_custom_nXX},
  5996. + {CODE_FOR_custom_npi, "__builtin_custom_npi", NIOS2_BUILTIN_CUSTOM_NPI, &custom_npi, nios2_expand_custom_nXX},
  5997. + {CODE_FOR_custom_npf, "__builtin_custom_npf", NIOS2_BUILTIN_CUSTOM_NPF, &custom_npf, nios2_expand_custom_nXX},
  5998. + {CODE_FOR_custom_npp, "__builtin_custom_npp", NIOS2_BUILTIN_CUSTOM_NPP, &custom_npp, nios2_expand_custom_nXX},
  5999. + {CODE_FOR_custom_in, "__builtin_custom_in", NIOS2_BUILTIN_CUSTOM_IN, &custom_in, nios2_expand_custom_Xn},
  6000. + {CODE_FOR_custom_ini, "__builtin_custom_ini", NIOS2_BUILTIN_CUSTOM_INI, &custom_ini, nios2_expand_custom_XnX},
  6001. + {CODE_FOR_custom_inf, "__builtin_custom_inf", NIOS2_BUILTIN_CUSTOM_INF, &custom_inf, nios2_expand_custom_XnX},
  6002. + {CODE_FOR_custom_inp, "__builtin_custom_inp", NIOS2_BUILTIN_CUSTOM_INP, &custom_inp, nios2_expand_custom_XnX},
  6003. + {CODE_FOR_custom_inii, "__builtin_custom_inii", NIOS2_BUILTIN_CUSTOM_INII, &custom_inii, nios2_expand_custom_XnXX},
  6004. + {CODE_FOR_custom_inif, "__builtin_custom_inif", NIOS2_BUILTIN_CUSTOM_INIF, &custom_inif, nios2_expand_custom_XnXX},
  6005. + {CODE_FOR_custom_inip, "__builtin_custom_inip", NIOS2_BUILTIN_CUSTOM_INIP, &custom_inip, nios2_expand_custom_XnXX},
  6006. + {CODE_FOR_custom_infi, "__builtin_custom_infi", NIOS2_BUILTIN_CUSTOM_INFI, &custom_infi, nios2_expand_custom_XnXX},
  6007. + {CODE_FOR_custom_inff, "__builtin_custom_inff", NIOS2_BUILTIN_CUSTOM_INFF, &custom_inff, nios2_expand_custom_XnXX},
  6008. + {CODE_FOR_custom_infp, "__builtin_custom_infp", NIOS2_BUILTIN_CUSTOM_INFP, &custom_infp, nios2_expand_custom_XnXX},
  6009. + {CODE_FOR_custom_inpi, "__builtin_custom_inpi", NIOS2_BUILTIN_CUSTOM_INPI, &custom_inpi, nios2_expand_custom_XnXX},
  6010. + {CODE_FOR_custom_inpf, "__builtin_custom_inpf", NIOS2_BUILTIN_CUSTOM_INPF, &custom_inpf, nios2_expand_custom_XnXX},
  6011. + {CODE_FOR_custom_inpp, "__builtin_custom_inpp", NIOS2_BUILTIN_CUSTOM_INPP, &custom_inpp, nios2_expand_custom_XnXX},
  6012. + {CODE_FOR_custom_fn, "__builtin_custom_fn", NIOS2_BUILTIN_CUSTOM_FN, &custom_fn, nios2_expand_custom_Xn},
  6013. + {CODE_FOR_custom_fni, "__builtin_custom_fni", NIOS2_BUILTIN_CUSTOM_FNI, &custom_fni, nios2_expand_custom_XnX},
  6014. + {CODE_FOR_custom_fnf, "__builtin_custom_fnf", NIOS2_BUILTIN_CUSTOM_FNF, &custom_fnf, nios2_expand_custom_XnX},
  6015. + {CODE_FOR_custom_fnp, "__builtin_custom_fnp", NIOS2_BUILTIN_CUSTOM_FNP, &custom_fnp, nios2_expand_custom_XnX},
  6016. + {CODE_FOR_custom_fnii, "__builtin_custom_fnii", NIOS2_BUILTIN_CUSTOM_FNII, &custom_fnii, nios2_expand_custom_XnXX},
  6017. + {CODE_FOR_custom_fnif, "__builtin_custom_fnif", NIOS2_BUILTIN_CUSTOM_FNIF, &custom_fnif, nios2_expand_custom_XnXX},
  6018. + {CODE_FOR_custom_fnip, "__builtin_custom_fnip", NIOS2_BUILTIN_CUSTOM_FNIP, &custom_fnip, nios2_expand_custom_XnXX},
  6019. + {CODE_FOR_custom_fnfi, "__builtin_custom_fnfi", NIOS2_BUILTIN_CUSTOM_FNFI, &custom_fnfi, nios2_expand_custom_XnXX},
  6020. + {CODE_FOR_custom_fnff, "__builtin_custom_fnff", NIOS2_BUILTIN_CUSTOM_FNFF, &custom_fnff, nios2_expand_custom_XnXX},
  6021. + {CODE_FOR_custom_fnfp, "__builtin_custom_fnfp", NIOS2_BUILTIN_CUSTOM_FNFP, &custom_fnfp, nios2_expand_custom_XnXX},
  6022. + {CODE_FOR_custom_fnpi, "__builtin_custom_fnpi", NIOS2_BUILTIN_CUSTOM_FNPI, &custom_fnpi, nios2_expand_custom_XnXX},
  6023. + {CODE_FOR_custom_fnpf, "__builtin_custom_fnpf", NIOS2_BUILTIN_CUSTOM_FNPF, &custom_fnpf, nios2_expand_custom_XnXX},
  6024. + {CODE_FOR_custom_fnpp, "__builtin_custom_fnpp", NIOS2_BUILTIN_CUSTOM_FNPP, &custom_fnpp, nios2_expand_custom_XnXX},
  6025. + {CODE_FOR_custom_pn, "__builtin_custom_pn", NIOS2_BUILTIN_CUSTOM_PN, &custom_pn, nios2_expand_custom_Xn},
  6026. + {CODE_FOR_custom_pni, "__builtin_custom_pni", NIOS2_BUILTIN_CUSTOM_PNI, &custom_pni, nios2_expand_custom_XnX},
  6027. + {CODE_FOR_custom_pnf, "__builtin_custom_pnf", NIOS2_BUILTIN_CUSTOM_PNF, &custom_pnf, nios2_expand_custom_XnX},
  6028. + {CODE_FOR_custom_pnp, "__builtin_custom_pnp", NIOS2_BUILTIN_CUSTOM_PNP, &custom_pnp, nios2_expand_custom_XnX},
  6029. + {CODE_FOR_custom_pnii, "__builtin_custom_pnii", NIOS2_BUILTIN_CUSTOM_PNII, &custom_pnii, nios2_expand_custom_XnXX},
  6030. + {CODE_FOR_custom_pnif, "__builtin_custom_pnif", NIOS2_BUILTIN_CUSTOM_PNIF, &custom_pnif, nios2_expand_custom_XnXX},
  6031. + {CODE_FOR_custom_pnip, "__builtin_custom_pnip", NIOS2_BUILTIN_CUSTOM_PNIP, &custom_pnip, nios2_expand_custom_XnXX},
  6032. + {CODE_FOR_custom_pnfi, "__builtin_custom_pnfi", NIOS2_BUILTIN_CUSTOM_PNFI, &custom_pnfi, nios2_expand_custom_XnXX},
  6033. + {CODE_FOR_custom_pnff, "__builtin_custom_pnff", NIOS2_BUILTIN_CUSTOM_PNFF, &custom_pnff, nios2_expand_custom_XnXX},
  6034. + {CODE_FOR_custom_pnfp, "__builtin_custom_pnfp", NIOS2_BUILTIN_CUSTOM_PNFP, &custom_pnfp, nios2_expand_custom_XnXX},
  6035. + {CODE_FOR_custom_pnpi, "__builtin_custom_pnpi", NIOS2_BUILTIN_CUSTOM_PNPI, &custom_pnpi, nios2_expand_custom_XnXX},
  6036. + {CODE_FOR_custom_pnpf, "__builtin_custom_pnpf", NIOS2_BUILTIN_CUSTOM_PNPF, &custom_pnpf, nios2_expand_custom_XnXX},
  6037. + {CODE_FOR_custom_pnpp, "__builtin_custom_pnpp", NIOS2_BUILTIN_CUSTOM_PNPP, &custom_pnpp, nios2_expand_custom_XnXX},
  6038. +
  6039. +
  6040. + {0, 0, 0, 0, 0},
  6041. +};
  6042. +
  6043. +/* This does not have a closing bracket on purpose (see use) */
  6044. +#define def_param(TYPE) \
  6045. + tree_cons (NULL_TREE, TYPE,
  6046. +
  6047. +static void
  6048. +nios2_init_builtins ()
  6049. +{
  6050. + const struct builtin_description *d;
  6051. +
  6052. +
  6053. + endlink = void_list_node;
  6054. +
  6055. + /* Special indenting here because one of the brackets is in def_param */
  6056. + /* *INDENT-OFF* */
  6057. +
  6058. + /* int fn (volatile const void *)
  6059. + */
  6060. + int_ftype_volatile_const_void_p
  6061. + = build_function_type (integer_type_node,
  6062. + def_param (build_qualified_type (ptr_type_node,
  6063. + TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE))
  6064. + endlink));
  6065. +
  6066. +
  6067. + /* void fn (volatile void *, int)
  6068. + */
  6069. + void_ftype_volatile_void_p_int
  6070. + = build_function_type (void_type_node,
  6071. + def_param (build_qualified_type (ptr_type_node,
  6072. + TYPE_QUAL_VOLATILE))
  6073. + def_param (integer_type_node)
  6074. + endlink)));
  6075. +
  6076. + /* void fn (void)
  6077. + */
  6078. + void_ftype_void
  6079. + = build_function_type (void_type_node,
  6080. + endlink);
  6081. +
  6082. + /* int fn (int)
  6083. + */
  6084. + int_ftype_int
  6085. + = build_function_type (integer_type_node,
  6086. + def_param (integer_type_node)
  6087. + endlink));
  6088. +
  6089. + /* void fn (int, int)
  6090. + */
  6091. + void_ftype_int_int
  6092. + = build_function_type (void_type_node,
  6093. + def_param (integer_type_node)
  6094. + def_param (integer_type_node)
  6095. + endlink)));
  6096. +
  6097. +
  6098. +#define CUSTOM_NUM def_param (integer_type_node)
  6099. +
  6100. + custom_n
  6101. + = build_function_type (void_type_node,
  6102. + CUSTOM_NUM
  6103. + endlink));
  6104. + custom_ni
  6105. + = build_function_type (void_type_node,
  6106. + CUSTOM_NUM
  6107. + def_param (integer_type_node)
  6108. + endlink)));
  6109. + custom_nf
  6110. + = build_function_type (void_type_node,
  6111. + CUSTOM_NUM
  6112. + def_param (float_type_node)
  6113. + endlink)));
  6114. + custom_np
  6115. + = build_function_type (void_type_node,
  6116. + CUSTOM_NUM
  6117. + def_param (ptr_type_node)
  6118. + endlink)));
  6119. + custom_nii
  6120. + = build_function_type (void_type_node,
  6121. + CUSTOM_NUM
  6122. + def_param (integer_type_node)
  6123. + def_param (integer_type_node)
  6124. + endlink))));
  6125. + custom_nif
  6126. + = build_function_type (void_type_node,
  6127. + CUSTOM_NUM
  6128. + def_param (integer_type_node)
  6129. + def_param (float_type_node)
  6130. + endlink))));
  6131. + custom_nip
  6132. + = build_function_type (void_type_node,
  6133. + CUSTOM_NUM
  6134. + def_param (integer_type_node)
  6135. + def_param (ptr_type_node)
  6136. + endlink))));
  6137. + custom_nfi
  6138. + = build_function_type (void_type_node,
  6139. + CUSTOM_NUM
  6140. + def_param (float_type_node)
  6141. + def_param (integer_type_node)
  6142. + endlink))));
  6143. + custom_nff
  6144. + = build_function_type (void_type_node,
  6145. + CUSTOM_NUM
  6146. + def_param (float_type_node)
  6147. + def_param (float_type_node)
  6148. + endlink))));
  6149. + custom_nfp
  6150. + = build_function_type (void_type_node,
  6151. + CUSTOM_NUM
  6152. + def_param (float_type_node)
  6153. + def_param (ptr_type_node)
  6154. + endlink))));
  6155. + custom_npi
  6156. + = build_function_type (void_type_node,
  6157. + CUSTOM_NUM
  6158. + def_param (ptr_type_node)
  6159. + def_param (integer_type_node)
  6160. + endlink))));
  6161. + custom_npf
  6162. + = build_function_type (void_type_node,
  6163. + CUSTOM_NUM
  6164. + def_param (ptr_type_node)
  6165. + def_param (float_type_node)
  6166. + endlink))));
  6167. + custom_npp
  6168. + = build_function_type (void_type_node,
  6169. + CUSTOM_NUM
  6170. + def_param (ptr_type_node)
  6171. + def_param (ptr_type_node)
  6172. + endlink))));
  6173. +
  6174. + custom_in
  6175. + = build_function_type (integer_type_node,
  6176. + CUSTOM_NUM
  6177. + endlink));
  6178. + custom_ini
  6179. + = build_function_type (integer_type_node,
  6180. + CUSTOM_NUM
  6181. + def_param (integer_type_node)
  6182. + endlink)));
  6183. + custom_inf
  6184. + = build_function_type (integer_type_node,
  6185. + CUSTOM_NUM
  6186. + def_param (float_type_node)
  6187. + endlink)));
  6188. + custom_inp
  6189. + = build_function_type (integer_type_node,
  6190. + CUSTOM_NUM
  6191. + def_param (ptr_type_node)
  6192. + endlink)));
  6193. + custom_inii
  6194. + = build_function_type (integer_type_node,
  6195. + CUSTOM_NUM
  6196. + def_param (integer_type_node)
  6197. + def_param (integer_type_node)
  6198. + endlink))));
  6199. + custom_inif
  6200. + = build_function_type (integer_type_node,
  6201. + CUSTOM_NUM
  6202. + def_param (integer_type_node)
  6203. + def_param (float_type_node)
  6204. + endlink))));
  6205. + custom_inip
  6206. + = build_function_type (integer_type_node,
  6207. + CUSTOM_NUM
  6208. + def_param (integer_type_node)
  6209. + def_param (ptr_type_node)
  6210. + endlink))));
  6211. + custom_infi
  6212. + = build_function_type (integer_type_node,
  6213. + CUSTOM_NUM
  6214. + def_param (float_type_node)
  6215. + def_param (integer_type_node)
  6216. + endlink))));
  6217. + custom_inff
  6218. + = build_function_type (integer_type_node,
  6219. + CUSTOM_NUM
  6220. + def_param (float_type_node)
  6221. + def_param (float_type_node)
  6222. + endlink))));
  6223. + custom_infp
  6224. + = build_function_type (integer_type_node,
  6225. + CUSTOM_NUM
  6226. + def_param (float_type_node)
  6227. + def_param (ptr_type_node)
  6228. + endlink))));
  6229. + custom_inpi
  6230. + = build_function_type (integer_type_node,
  6231. + CUSTOM_NUM
  6232. + def_param (ptr_type_node)
  6233. + def_param (integer_type_node)
  6234. + endlink))));
  6235. + custom_inpf
  6236. + = build_function_type (integer_type_node,
  6237. + CUSTOM_NUM
  6238. + def_param (ptr_type_node)
  6239. + def_param (float_type_node)
  6240. + endlink))));
  6241. + custom_inpp
  6242. + = build_function_type (integer_type_node,
  6243. + CUSTOM_NUM
  6244. + def_param (ptr_type_node)
  6245. + def_param (ptr_type_node)
  6246. + endlink))));
  6247. +
  6248. + custom_fn
  6249. + = build_function_type (float_type_node,
  6250. + CUSTOM_NUM
  6251. + endlink));
  6252. + custom_fni
  6253. + = build_function_type (float_type_node,
  6254. + CUSTOM_NUM
  6255. + def_param (integer_type_node)
  6256. + endlink)));
  6257. + custom_fnf
  6258. + = build_function_type (float_type_node,
  6259. + CUSTOM_NUM
  6260. + def_param (float_type_node)
  6261. + endlink)));
  6262. + custom_fnp
  6263. + = build_function_type (float_type_node,
  6264. + CUSTOM_NUM
  6265. + def_param (ptr_type_node)
  6266. + endlink)));
  6267. + custom_fnii
  6268. + = build_function_type (float_type_node,
  6269. + CUSTOM_NUM
  6270. + def_param (integer_type_node)
  6271. + def_param (integer_type_node)
  6272. + endlink))));
  6273. + custom_fnif
  6274. + = build_function_type (float_type_node,
  6275. + CUSTOM_NUM
  6276. + def_param (integer_type_node)
  6277. + def_param (float_type_node)
  6278. + endlink))));
  6279. + custom_fnip
  6280. + = build_function_type (float_type_node,
  6281. + CUSTOM_NUM
  6282. + def_param (integer_type_node)
  6283. + def_param (ptr_type_node)
  6284. + endlink))));
  6285. + custom_fnfi
  6286. + = build_function_type (float_type_node,
  6287. + CUSTOM_NUM
  6288. + def_param (float_type_node)
  6289. + def_param (integer_type_node)
  6290. + endlink))));
  6291. + custom_fnff
  6292. + = build_function_type (float_type_node,
  6293. + CUSTOM_NUM
  6294. + def_param (float_type_node)
  6295. + def_param (float_type_node)
  6296. + endlink))));
  6297. + custom_fnfp
  6298. + = build_function_type (float_type_node,
  6299. + CUSTOM_NUM
  6300. + def_param (float_type_node)
  6301. + def_param (ptr_type_node)
  6302. + endlink))));
  6303. + custom_fnpi
  6304. + = build_function_type (float_type_node,
  6305. + CUSTOM_NUM
  6306. + def_param (ptr_type_node)
  6307. + def_param (integer_type_node)
  6308. + endlink))));
  6309. + custom_fnpf
  6310. + = build_function_type (float_type_node,
  6311. + CUSTOM_NUM
  6312. + def_param (ptr_type_node)
  6313. + def_param (float_type_node)
  6314. + endlink))));
  6315. + custom_fnpp
  6316. + = build_function_type (float_type_node,
  6317. + CUSTOM_NUM
  6318. + def_param (ptr_type_node)
  6319. + def_param (ptr_type_node)
  6320. + endlink))));
  6321. +
  6322. +
  6323. + custom_pn
  6324. + = build_function_type (ptr_type_node,
  6325. + CUSTOM_NUM
  6326. + endlink));
  6327. + custom_pni
  6328. + = build_function_type (ptr_type_node,
  6329. + CUSTOM_NUM
  6330. + def_param (integer_type_node)
  6331. + endlink)));
  6332. + custom_pnf
  6333. + = build_function_type (ptr_type_node,
  6334. + CUSTOM_NUM
  6335. + def_param (float_type_node)
  6336. + endlink)));
  6337. + custom_pnp
  6338. + = build_function_type (ptr_type_node,
  6339. + CUSTOM_NUM
  6340. + def_param (ptr_type_node)
  6341. + endlink)));
  6342. + custom_pnii
  6343. + = build_function_type (ptr_type_node,
  6344. + CUSTOM_NUM
  6345. + def_param (integer_type_node)
  6346. + def_param (integer_type_node)
  6347. + endlink))));
  6348. + custom_pnif
  6349. + = build_function_type (ptr_type_node,
  6350. + CUSTOM_NUM
  6351. + def_param (integer_type_node)
  6352. + def_param (float_type_node)
  6353. + endlink))));
  6354. + custom_pnip
  6355. + = build_function_type (ptr_type_node,
  6356. + CUSTOM_NUM
  6357. + def_param (integer_type_node)
  6358. + def_param (ptr_type_node)
  6359. + endlink))));
  6360. + custom_pnfi
  6361. + = build_function_type (ptr_type_node,
  6362. + CUSTOM_NUM
  6363. + def_param (float_type_node)
  6364. + def_param (integer_type_node)
  6365. + endlink))));
  6366. + custom_pnff
  6367. + = build_function_type (ptr_type_node,
  6368. + CUSTOM_NUM
  6369. + def_param (float_type_node)
  6370. + def_param (float_type_node)
  6371. + endlink))));
  6372. + custom_pnfp
  6373. + = build_function_type (ptr_type_node,
  6374. + CUSTOM_NUM
  6375. + def_param (float_type_node)
  6376. + def_param (ptr_type_node)
  6377. + endlink))));
  6378. + custom_pnpi
  6379. + = build_function_type (ptr_type_node,
  6380. + CUSTOM_NUM
  6381. + def_param (ptr_type_node)
  6382. + def_param (integer_type_node)
  6383. + endlink))));
  6384. + custom_pnpf
  6385. + = build_function_type (ptr_type_node,
  6386. + CUSTOM_NUM
  6387. + def_param (ptr_type_node)
  6388. + def_param (float_type_node)
  6389. + endlink))));
  6390. + custom_pnpp
  6391. + = build_function_type (ptr_type_node,
  6392. + CUSTOM_NUM
  6393. + def_param (ptr_type_node)
  6394. + def_param (ptr_type_node)
  6395. + endlink))));
  6396. +
  6397. +
  6398. +
  6399. + /* *INDENT-ON* */
  6400. +
  6401. +
  6402. + for (d = bdesc; d->name; d++)
  6403. + {
  6404. + builtin_function (d->name, *d->type, d->code,
  6405. + BUILT_IN_MD, NULL, NULL);
  6406. + }
  6407. +}
  6408. +
  6409. +/* Expand an expression EXP that calls a built-in function,
  6410. + with result going to TARGET if that's convenient
  6411. + (and in mode MODE if that's convenient).
  6412. + SUBTARGET may be used as the target for computing one of EXP's operands.
  6413. + IGNORE is nonzero if the value is to be ignored. */
  6414. +
  6415. +static rtx
  6416. +nios2_expand_builtin (tree exp, rtx target, rtx subtarget,
  6417. + enum machine_mode mode, int ignore)
  6418. +{
  6419. + const struct builtin_description *d;
  6420. + tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
  6421. + unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
  6422. +
  6423. + for (d = bdesc; d->name; d++)
  6424. + if (d->code == fcode)
  6425. + return (d->expander) (d, exp, target, subtarget, mode, ignore);
  6426. +
  6427. + /* we should have seen one of the functins we registered */
  6428. + abort ();
  6429. +}
  6430. +
  6431. +static rtx nios2_create_target (const struct builtin_description *, rtx);
  6432. +
  6433. +
  6434. +static rtx
  6435. +nios2_create_target (const struct builtin_description *d, rtx target)
  6436. +{
  6437. + if (!target
  6438. + || !(*insn_data[d->icode].operand[0].predicate) (target,
  6439. + insn_data[d->icode].operand[0].mode))
  6440. + {
  6441. + target = gen_reg_rtx (insn_data[d->icode].operand[0].mode);
  6442. + }
  6443. +
  6444. + return target;
  6445. +}
  6446. +
  6447. +
  6448. +static rtx nios2_extract_opcode (const struct builtin_description *, int, tree);
  6449. +static rtx nios2_extract_operand (const struct builtin_description *, int, int, tree);
  6450. +
  6451. +static rtx
  6452. +nios2_extract_opcode (const struct builtin_description *d, int op, tree arglist)
  6453. +{
  6454. + enum machine_mode mode = insn_data[d->icode].operand[op].mode;
  6455. + tree arg = TREE_VALUE (arglist);
  6456. + rtx opcode = expand_expr (arg, NULL_RTX, mode, 0);
  6457. + opcode = protect_from_queue (opcode, 0);
  6458. +
  6459. + if (!(*insn_data[d->icode].operand[op].predicate) (opcode, mode))
  6460. + error ("Custom instruction opcode must be compile time constant in the range 0-255 for %s", d->name);
  6461. +
  6462. + return opcode;
  6463. +}
  6464. +
  6465. +static rtx
  6466. +nios2_extract_operand (const struct builtin_description *d, int op, int argnum, tree arglist)
  6467. +{
  6468. + enum machine_mode mode = insn_data[d->icode].operand[op].mode;
  6469. + tree arg = TREE_VALUE (arglist);
  6470. + rtx operand = expand_expr (arg, NULL_RTX, mode, 0);
  6471. + operand = protect_from_queue (operand, 0);
  6472. +
  6473. + if (!(*insn_data[d->icode].operand[op].predicate) (operand, mode))
  6474. + operand = copy_to_mode_reg (mode, operand);
  6475. +
  6476. + /* ??? Better errors would be nice */
  6477. + if (!(*insn_data[d->icode].operand[op].predicate) (operand, mode))
  6478. + error ("Invalid argument %d to %s", argnum, d->name);
  6479. +
  6480. + return operand;
  6481. +}
  6482. +
  6483. +
  6484. +static rtx
  6485. +nios2_expand_custom_n (const struct builtin_description *d, tree exp,
  6486. + rtx target ATTRIBUTE_UNUSED, rtx subtarget ATTRIBUTE_UNUSED,
  6487. + enum machine_mode mode ATTRIBUTE_UNUSED, int ignore ATTRIBUTE_UNUSED)
  6488. +{
  6489. + tree arglist = TREE_OPERAND (exp, 1);
  6490. + rtx pat;
  6491. + rtx opcode;
  6492. +
  6493. + /* custom_n should have exactly one operand */
  6494. + if (insn_data[d->icode].n_operands != 1)
  6495. + abort ();
  6496. +
  6497. + opcode = nios2_extract_opcode (d, 0, arglist);
  6498. +
  6499. + pat = GEN_FCN (d->icode) (opcode);
  6500. + if (!pat)
  6501. + return 0;
  6502. + emit_insn (pat);
  6503. + return 0;
  6504. +}
  6505. +
  6506. +static rtx
  6507. +nios2_expand_custom_Xn (const struct builtin_description *d, tree exp,
  6508. + rtx target, rtx subtarget ATTRIBUTE_UNUSED,
  6509. + enum machine_mode mode ATTRIBUTE_UNUSED,
  6510. + int ignore ATTRIBUTE_UNUSED)
  6511. +{
  6512. + tree arglist = TREE_OPERAND (exp, 1);
  6513. + rtx pat;
  6514. + rtx opcode;
  6515. +
  6516. + /* custom_Xn should have exactly two operands */
  6517. + if (insn_data[d->icode].n_operands != 2)
  6518. + abort ();
  6519. +
  6520. + target = nios2_create_target (d, target);
  6521. + opcode = nios2_extract_opcode (d, 1, arglist);
  6522. +
  6523. + pat = GEN_FCN (d->icode) (target, opcode);
  6524. + if (!pat)
  6525. + return 0;
  6526. + emit_insn (pat);
  6527. + return target;
  6528. +}
  6529. +
  6530. +static rtx
  6531. +nios2_expand_custom_nX (const struct builtin_description *d, tree exp,
  6532. + rtx target ATTRIBUTE_UNUSED, rtx subtarget ATTRIBUTE_UNUSED,
  6533. + enum machine_mode mode ATTRIBUTE_UNUSED, int ignore ATTRIBUTE_UNUSED)
  6534. +{
  6535. + tree arglist = TREE_OPERAND (exp, 1);
  6536. + rtx pat;
  6537. + rtx opcode;
  6538. + rtx operands[1];
  6539. + int i;
  6540. +
  6541. +
  6542. + /* custom_nX should have exactly two operands */
  6543. + if (insn_data[d->icode].n_operands != 2)
  6544. + abort ();
  6545. +
  6546. + opcode = nios2_extract_opcode (d, 0, arglist);
  6547. + for (i = 0; i < 1; i++)
  6548. + {
  6549. + arglist = TREE_CHAIN (arglist);
  6550. + operands[i] = nios2_extract_operand (d, i + 1, i + 1, arglist);
  6551. + }
  6552. +
  6553. + pat = GEN_FCN (d->icode) (opcode, operands[0]);
  6554. + if (!pat)
  6555. + return 0;
  6556. + emit_insn (pat);
  6557. + return 0;
  6558. +}
  6559. +
  6560. +static rtx
  6561. +nios2_expand_custom_XnX (const struct builtin_description *d, tree exp, rtx target,
  6562. + rtx subtarget ATTRIBUTE_UNUSED, enum machine_mode mode ATTRIBUTE_UNUSED,
  6563. + int ignore ATTRIBUTE_UNUSED)
  6564. +{
  6565. + tree arglist = TREE_OPERAND (exp, 1);
  6566. + rtx pat;
  6567. + rtx opcode;
  6568. + rtx operands[1];
  6569. + int i;
  6570. +
  6571. + /* custom_Xn should have exactly three operands */
  6572. + if (insn_data[d->icode].n_operands != 3)
  6573. + abort ();
  6574. +
  6575. + target = nios2_create_target (d, target);
  6576. + opcode = nios2_extract_opcode (d, 1, arglist);
  6577. +
  6578. + for (i = 0; i < 1; i++)
  6579. + {
  6580. + arglist = TREE_CHAIN (arglist);
  6581. + operands[i] = nios2_extract_operand (d, i + 2, i + 1, arglist);
  6582. + }
  6583. +
  6584. + pat = GEN_FCN (d->icode) (target, opcode, operands[0]);
  6585. +
  6586. + if (!pat)
  6587. + return 0;
  6588. + emit_insn (pat);
  6589. + return target;
  6590. +}
  6591. +
  6592. +static rtx
  6593. +nios2_expand_custom_nXX (const struct builtin_description *d, tree exp, rtx target ATTRIBUTE_UNUSED,
  6594. + rtx subtarget ATTRIBUTE_UNUSED, enum machine_mode mode ATTRIBUTE_UNUSED,
  6595. + int ignore ATTRIBUTE_UNUSED)
  6596. +{
  6597. + tree arglist = TREE_OPERAND (exp, 1);
  6598. + rtx pat;
  6599. + rtx opcode;
  6600. + rtx operands[2];
  6601. + int i;
  6602. +
  6603. +
  6604. + /* custom_nX should have exactly three operands */
  6605. + if (insn_data[d->icode].n_operands != 3)
  6606. + abort ();
  6607. +
  6608. + opcode = nios2_extract_opcode (d, 0, arglist);
  6609. + for (i = 0; i < 2; i++)
  6610. + {
  6611. + arglist = TREE_CHAIN (arglist);
  6612. + operands[i] = nios2_extract_operand (d, i + 1, i + 1, arglist);
  6613. + }
  6614. +
  6615. + pat = GEN_FCN (d->icode) (opcode, operands[0], operands[1]);
  6616. + if (!pat)
  6617. + return 0;
  6618. + emit_insn (pat);
  6619. + return 0;
  6620. +}
  6621. +
  6622. +static rtx
  6623. +nios2_expand_custom_XnXX (const struct builtin_description *d, tree exp, rtx target,
  6624. + rtx subtarget ATTRIBUTE_UNUSED, enum machine_mode mode ATTRIBUTE_UNUSED,
  6625. + int ignore ATTRIBUTE_UNUSED)
  6626. +{
  6627. + tree arglist = TREE_OPERAND (exp, 1);
  6628. + rtx pat;
  6629. + rtx opcode;
  6630. + rtx operands[2];
  6631. + int i;
  6632. +
  6633. +
  6634. + /* custom_XnX should have exactly four operands */
  6635. + if (insn_data[d->icode].n_operands != 4)
  6636. + abort ();
  6637. +
  6638. + target = nios2_create_target (d, target);
  6639. + opcode = nios2_extract_opcode (d, 1, arglist);
  6640. + for (i = 0; i < 2; i++)
  6641. + {
  6642. + arglist = TREE_CHAIN (arglist);
  6643. + operands[i] = nios2_extract_operand (d, i + 2, i + 1, arglist);
  6644. + }
  6645. +
  6646. + pat = GEN_FCN (d->icode) (target, opcode, operands[0], operands[1]);
  6647. +
  6648. + if (!pat)
  6649. + return 0;
  6650. + emit_insn (pat);
  6651. + return target;
  6652. +}
  6653. +
  6654. +
  6655. +
  6656. +static rtx
  6657. +nios2_expand_STXIO (const struct builtin_description *d, tree exp, rtx target ATTRIBUTE_UNUSED,
  6658. + rtx subtarget ATTRIBUTE_UNUSED, enum machine_mode mode ATTRIBUTE_UNUSED,
  6659. + int ignore ATTRIBUTE_UNUSED)
  6660. +{
  6661. + tree arglist = TREE_OPERAND (exp, 1);
  6662. + rtx pat;
  6663. + rtx store_dest, store_val;
  6664. + enum insn_code icode = d->icode;
  6665. +
  6666. + /* stores should have exactly two operands */
  6667. + if (insn_data[icode].n_operands != 2)
  6668. + abort ();
  6669. +
  6670. + /* process the destination of the store */
  6671. + {
  6672. + enum machine_mode mode = insn_data[icode].operand[0].mode;
  6673. + tree arg = TREE_VALUE (arglist);
  6674. + store_dest = expand_expr (arg, NULL_RTX, VOIDmode, 0);
  6675. + store_dest = protect_from_queue (store_dest, 0);
  6676. +
  6677. + store_dest = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, store_dest));
  6678. +
  6679. + /* ??? Better errors would be nice */
  6680. + if (!(*insn_data[icode].operand[0].predicate) (store_dest, mode))
  6681. + error ("Invalid argument 1 to %s", d->name);
  6682. + }
  6683. +
  6684. +
  6685. + /* process the value to store */
  6686. + {
  6687. + enum machine_mode mode = insn_data[icode].operand[1].mode;
  6688. + tree arg = TREE_VALUE (TREE_CHAIN (arglist));
  6689. + store_val = expand_expr (arg, NULL_RTX, mode, 0);
  6690. + store_val = protect_from_queue (store_val, 0);
  6691. +
  6692. + if (!(*insn_data[icode].operand[1].predicate) (store_val, mode))
  6693. + store_val = copy_to_mode_reg (mode, store_val);
  6694. +
  6695. + /* ??? Better errors would be nice */
  6696. + if (!(*insn_data[icode].operand[1].predicate) (store_val, mode))
  6697. + error ("Invalid argument 2 to %s", d->name);
  6698. + }
  6699. +
  6700. + pat = GEN_FCN (d->icode) (store_dest, store_val);
  6701. + if (!pat)
  6702. + return 0;
  6703. + emit_insn (pat);
  6704. + return 0;
  6705. +}
  6706. +
  6707. +
  6708. +static rtx
  6709. +nios2_expand_LDXIO (const struct builtin_description * d, tree exp, rtx target,
  6710. + rtx subtarget ATTRIBUTE_UNUSED, enum machine_mode mode ATTRIBUTE_UNUSED,
  6711. + int ignore ATTRIBUTE_UNUSED)
  6712. +{
  6713. + tree arglist = TREE_OPERAND (exp, 1);
  6714. + rtx pat;
  6715. + rtx ld_src;
  6716. + enum insn_code icode = d->icode;
  6717. +
  6718. + /* loads should have exactly two operands */
  6719. + if (insn_data[icode].n_operands != 2)
  6720. + abort ();
  6721. +
  6722. + target = nios2_create_target (d, target);
  6723. +
  6724. + {
  6725. + enum machine_mode mode = insn_data[icode].operand[1].mode;
  6726. + tree arg = TREE_VALUE (arglist);
  6727. + ld_src = expand_expr (arg, NULL_RTX, VOIDmode, 0);
  6728. + ld_src = protect_from_queue (ld_src, 0);
  6729. +
  6730. + ld_src = gen_rtx_MEM (mode, copy_to_mode_reg (Pmode, ld_src));
  6731. +
  6732. + /* ??? Better errors would be nice */
  6733. + if (!(*insn_data[icode].operand[1].predicate) (ld_src, mode))
  6734. + {
  6735. + error ("Invalid argument 1 to %s", d->name);
  6736. + }
  6737. + }
  6738. +
  6739. + pat = GEN_FCN (d->icode) (target, ld_src);
  6740. + if (!pat)
  6741. + return 0;
  6742. + emit_insn (pat);
  6743. + return target;
  6744. +}
  6745. +
  6746. +
  6747. +static rtx
  6748. +nios2_expand_sync (const struct builtin_description * d ATTRIBUTE_UNUSED,
  6749. + tree exp ATTRIBUTE_UNUSED, rtx target ATTRIBUTE_UNUSED,
  6750. + rtx subtarget ATTRIBUTE_UNUSED,
  6751. + enum machine_mode mode ATTRIBUTE_UNUSED,
  6752. + int ignore ATTRIBUTE_UNUSED)
  6753. +{
  6754. + emit_insn (gen_sync ());
  6755. + return 0;
  6756. +}
  6757. +
  6758. +static rtx
  6759. +nios2_expand_rdctl (const struct builtin_description * d ATTRIBUTE_UNUSED,
  6760. + tree exp ATTRIBUTE_UNUSED, rtx target ATTRIBUTE_UNUSED,
  6761. + rtx subtarget ATTRIBUTE_UNUSED,
  6762. + enum machine_mode mode ATTRIBUTE_UNUSED,
  6763. + int ignore ATTRIBUTE_UNUSED)
  6764. +{
  6765. + tree arglist = TREE_OPERAND (exp, 1);
  6766. + rtx pat;
  6767. + rtx rdctl_reg;
  6768. + enum insn_code icode = d->icode;
  6769. +
  6770. + /* rdctl should have exactly two operands */
  6771. + if (insn_data[icode].n_operands != 2)
  6772. + abort ();
  6773. +
  6774. + target = nios2_create_target (d, target);
  6775. +
  6776. + {
  6777. + enum machine_mode mode = insn_data[icode].operand[1].mode;
  6778. + tree arg = TREE_VALUE (arglist);
  6779. + rdctl_reg = expand_expr (arg, NULL_RTX, VOIDmode, 0);
  6780. + rdctl_reg = protect_from_queue (rdctl_reg, 0);
  6781. +
  6782. + if (!(*insn_data[icode].operand[1].predicate) (rdctl_reg, mode))
  6783. + {
  6784. + error ("Control register number must be in range 0-31 for %s", d->name);
  6785. + }
  6786. + }
  6787. +
  6788. + pat = GEN_FCN (d->icode) (target, rdctl_reg);
  6789. + if (!pat)
  6790. + return 0;
  6791. + emit_insn (pat);
  6792. + return target;
  6793. +}
  6794. +
  6795. +static rtx
  6796. +nios2_expand_wrctl (const struct builtin_description * d ATTRIBUTE_UNUSED,
  6797. + tree exp ATTRIBUTE_UNUSED, rtx target ATTRIBUTE_UNUSED,
  6798. + rtx subtarget ATTRIBUTE_UNUSED,
  6799. + enum machine_mode mode ATTRIBUTE_UNUSED,
  6800. + int ignore ATTRIBUTE_UNUSED)
  6801. +{
  6802. + tree arglist = TREE_OPERAND (exp, 1);
  6803. + rtx pat;
  6804. + rtx wrctl_reg, store_val;
  6805. + enum insn_code icode = d->icode;
  6806. +
  6807. + /* stores should have exactly two operands */
  6808. + if (insn_data[icode].n_operands != 2)
  6809. + abort ();
  6810. +
  6811. + /* process the destination of the store */
  6812. + {
  6813. + enum machine_mode mode = insn_data[icode].operand[0].mode;
  6814. + tree arg = TREE_VALUE (arglist);
  6815. + wrctl_reg = expand_expr (arg, NULL_RTX, VOIDmode, 0);
  6816. + wrctl_reg = protect_from_queue (wrctl_reg, 0);
  6817. +
  6818. + if (!(*insn_data[icode].operand[0].predicate) (wrctl_reg, mode))
  6819. + error ("Control register number must be in range 0-31 for %s", d->name);
  6820. + }
  6821. +
  6822. +
  6823. + /* process the value to store */
  6824. + {
  6825. + enum machine_mode mode = insn_data[icode].operand[1].mode;
  6826. + tree arg = TREE_VALUE (TREE_CHAIN (arglist));
  6827. + store_val = expand_expr (arg, NULL_RTX, mode, 0);
  6828. + store_val = protect_from_queue (store_val, 0);
  6829. +
  6830. + if (!(*insn_data[icode].operand[1].predicate) (store_val, mode))
  6831. + store_val = copy_to_mode_reg (mode, store_val);
  6832. +
  6833. + /* ??? Better errors would be nice */
  6834. + if (!(*insn_data[icode].operand[1].predicate) (store_val, mode))
  6835. + error ("Invalid argument 2 to %s", d->name);
  6836. + }
  6837. +
  6838. + pat = GEN_FCN (d->icode) (wrctl_reg, store_val);
  6839. + if (!pat)
  6840. + return 0;
  6841. + emit_insn (pat);
  6842. + return 0;
  6843. +}
  6844. +
  6845. +
  6846. +#include "gt-nios2.h"
  6847. +
  6848. --- gcc-3.4.3/gcc/config/nios2/nios2.h
  6849. +++ gcc-3.4.3-nios2/gcc/config/nios2/nios2.h
  6850. @@ -0,0 +1,824 @@
  6851. +/* Definitions of target machine for Altera NIOS 2G NIOS2 version.
  6852. + Copyright (C) 2003 Altera
  6853. + Contributed by Jonah Graham (jgraham@altera.com).
  6854. +
  6855. +This file is part of GNU CC.
  6856. +
  6857. +GNU CC is free software; you can redistribute it and/or modify
  6858. +it under the terms of the GNU General Public License as published by
  6859. +the Free Software Foundation; either version 2, or (at your option)
  6860. +any later version.
  6861. +
  6862. +GNU CC is distributed in the hope that it will be useful,
  6863. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  6864. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6865. +GNU General Public License for more details.
  6866. +
  6867. +You should have received a copy of the GNU General Public License
  6868. +along with GNU CC; see the file COPYING. If not, write to
  6869. +the Free Software Foundation, 59 Temple Place - Suite 330,
  6870. +Boston, MA 02111-1307, USA. */
  6871. +
  6872. +
  6873. +
  6874. +#define TARGET_CPU_CPP_BUILTINS() \
  6875. + do \
  6876. + { \
  6877. + builtin_define_std ("NIOS2"); \
  6878. + builtin_define_std ("nios2"); \
  6879. + builtin_define ("_GNU_SOURCE"); \
  6880. + } \
  6881. + while (0)
  6882. +#define TARGET_VERSION fprintf (stderr, " (Altera Nios II)")
  6883. +
  6884. +
  6885. +
  6886. +
  6887. +
  6888. +/*********************************
  6889. + * Run-time Target Specification
  6890. + *********************************/
  6891. +
  6892. +#define HAS_DIV_FLAG 0x0001
  6893. +#define HAS_MUL_FLAG 0x0002
  6894. +#define HAS_MULX_FLAG 0x0004
  6895. +#define FAST_SW_DIV_FLAG 0x0008
  6896. +#define INLINE_MEMCPY_FLAG 0x00010
  6897. +#define CACHE_VOLATILE_FLAG 0x0020
  6898. +#define BYPASS_CACHE_FLAG 0x0040
  6899. +
  6900. +extern int target_flags;
  6901. +#define TARGET_HAS_DIV (target_flags & HAS_DIV_FLAG)
  6902. +#define TARGET_HAS_MUL (target_flags & HAS_MUL_FLAG)
  6903. +#define TARGET_HAS_MULX (target_flags & HAS_MULX_FLAG)
  6904. +#define TARGET_FAST_SW_DIV (target_flags & FAST_SW_DIV_FLAG)
  6905. +#define TARGET_INLINE_MEMCPY (target_flags & INLINE_MEMCPY_FLAG)
  6906. +#define TARGET_CACHE_VOLATILE (target_flags & CACHE_VOLATILE_FLAG)
  6907. +#define TARGET_BYPASS_CACHE (target_flags & BYPASS_CACHE_FLAG)
  6908. +
  6909. +#define TARGET_SWITCHES \
  6910. +{ \
  6911. + { "hw-div", HAS_DIV_FLAG, \
  6912. + N_("Enable DIV, DIVU") }, \
  6913. + { "no-hw-div", -HAS_DIV_FLAG, \
  6914. + N_("Disable DIV, DIVU (default)") }, \
  6915. + { "hw-mul", HAS_MUL_FLAG, \
  6916. + N_("Enable MUL instructions (default)") }, \
  6917. + { "hw-mulx", HAS_MULX_FLAG, \
  6918. + N_("Enable MULX instructions, assume fast shifter") }, \
  6919. + { "no-hw-mul", -HAS_MUL_FLAG, \
  6920. + N_("Disable MUL instructions") }, \
  6921. + { "no-hw-mulx", -HAS_MULX_FLAG, \
  6922. + N_("Disable MULX instructions, assume slow shifter (default and implied by -mno-hw-mul)") }, \
  6923. + { "fast-sw-div", FAST_SW_DIV_FLAG, \
  6924. + N_("Use table based fast divide (default at -O3)") }, \
  6925. + { "no-fast-sw-div", -FAST_SW_DIV_FLAG, \
  6926. + N_("Don't use table based fast divide ever") }, \
  6927. + { "inline-memcpy", INLINE_MEMCPY_FLAG, \
  6928. + N_("Inline small memcpy (default when optimizing)") }, \
  6929. + { "no-inline-memcpy", -INLINE_MEMCPY_FLAG, \
  6930. + N_("Don't Inline small memcpy") }, \
  6931. + { "cache-volatile", CACHE_VOLATILE_FLAG, \
  6932. + N_("Volatile accesses use non-io variants of instructions (default)") }, \
  6933. + { "no-cache-volatile", -CACHE_VOLATILE_FLAG, \
  6934. + N_("Volatile accesses use io variants of instructions") }, \
  6935. + { "bypass-cache", BYPASS_CACHE_FLAG, \
  6936. + N_("All ld/st instructins use io variants") }, \
  6937. + { "no-bypass-cache", -BYPASS_CACHE_FLAG, \
  6938. + N_("All ld/st instructins do not use io variants (default)") }, \
  6939. + { "smallc", 0, \
  6940. + N_("Link with a limited version of the C library") }, \
  6941. + { "ctors-in-init", 0, \
  6942. + "" /* undocumented: N_("Link with static constructors and destructors in init") */ }, \
  6943. + { "", TARGET_DEFAULT, 0 } \
  6944. +}
  6945. +
  6946. +
  6947. +extern const char *nios2_sys_nosys_string; /* for -msys=nosys */
  6948. +extern const char *nios2_sys_lib_string; /* for -msys-lib= */
  6949. +extern const char *nios2_sys_crt0_string; /* for -msys-crt0= */
  6950. +
  6951. +#define TARGET_OPTIONS \
  6952. +{ \
  6953. + { "sys=nosys", &nios2_sys_nosys_string, \
  6954. + N_("Use stub versions of OS library calls (default)"), 0}, \
  6955. + { "sys-lib=", &nios2_sys_lib_string, \
  6956. + N_("Name of System Library to link against. (Converted to a -l option)"), 0}, \
  6957. + { "sys-crt0=", &nios2_sys_crt0_string, \
  6958. + N_("Name of the startfile. (default is a crt0 for the ISS only)"), 0}, \
  6959. +}
  6960. +
  6961. +
  6962. +/* Default target_flags if no switches specified. */
  6963. +#ifndef TARGET_DEFAULT
  6964. +# define TARGET_DEFAULT (HAS_MUL_FLAG | CACHE_VOLATILE_FLAG)
  6965. +#endif
  6966. +
  6967. +/* Switch Recognition by gcc.c. Add -G xx support */
  6968. +#undef SWITCH_TAKES_ARG
  6969. +#define SWITCH_TAKES_ARG(CHAR) \
  6970. + (DEFAULT_SWITCH_TAKES_ARG (CHAR) || (CHAR) == 'G')
  6971. +
  6972. +#define OVERRIDE_OPTIONS override_options ()
  6973. +#define OPTIMIZATION_OPTIONS(LEVEL, SIZE) optimization_options (LEVEL, SIZE)
  6974. +#define CAN_DEBUG_WITHOUT_FP
  6975. +
  6976. +#define CC1_SPEC "\
  6977. +%{G*}"
  6978. +
  6979. +#undef LIB_SPEC
  6980. +#define LIB_SPEC \
  6981. +"--start-group %{msmallc: -lsmallc} %{!msmallc: -lc} -lgcc \
  6982. + %{msys-lib=*: -l%*} \
  6983. + %{!msys-lib=*: -lc } \
  6984. + --end-group \
  6985. + %{msys-lib=: %eYou need a library name for -msys-lib=} \
  6986. +"
  6987. +
  6988. +
  6989. +#undef STARTFILE_SPEC
  6990. +#define STARTFILE_SPEC \
  6991. +"%{msys-crt0=*: %*} %{!msys-crt0=*: crt1%O%s} \
  6992. + %{msys-crt0=: %eYou need a C startup file for -msys-crt0=} \
  6993. + %{mctors-in-init: crti%O%s crtbegin%O%s} \
  6994. +"
  6995. +
  6996. +#undef ENDFILE_SPEC
  6997. +#define ENDFILE_SPEC \
  6998. + "%{mctors-in-init: crtend%O%s crtn%O%s}"
  6999. +
  7000. +
  7001. +/***********************
  7002. + * Storage Layout
  7003. + ***********************/
  7004. +
  7005. +#define DEFAULT_SIGNED_CHAR 1
  7006. +#define BITS_BIG_ENDIAN 0
  7007. +#define BYTES_BIG_ENDIAN 0
  7008. +#define WORDS_BIG_ENDIAN 0
  7009. +#define BITS_PER_UNIT 8
  7010. +#define BITS_PER_WORD 32
  7011. +#define UNITS_PER_WORD 4
  7012. +#define POINTER_SIZE 32
  7013. +#define BIGGEST_ALIGNMENT 32
  7014. +#define STRICT_ALIGNMENT 1
  7015. +#define FUNCTION_BOUNDARY 32
  7016. +#define PARM_BOUNDARY 32
  7017. +#define STACK_BOUNDARY 32
  7018. +#define PREFERRED_STACK_BOUNDARY 32
  7019. +#define MAX_FIXED_MODE_SIZE 64
  7020. +
  7021. +#define CONSTANT_ALIGNMENT(EXP, ALIGN) \
  7022. + ((TREE_CODE (EXP) == STRING_CST) \
  7023. + && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN))
  7024. +
  7025. +
  7026. +/**********************
  7027. + * Layout of Source Language Data Types
  7028. + **********************/
  7029. +
  7030. +#define INT_TYPE_SIZE 32
  7031. +#define SHORT_TYPE_SIZE 16
  7032. +#define LONG_TYPE_SIZE 32
  7033. +#define LONG_LONG_TYPE_SIZE 64
  7034. +#define FLOAT_TYPE_SIZE 32
  7035. +#define DOUBLE_TYPE_SIZE 64
  7036. +#define LONG_DOUBLE_TYPE_SIZE DOUBLE_TYPE_SIZE
  7037. +
  7038. +
  7039. +/*************************
  7040. + * Condition Code Status
  7041. + ************************/
  7042. +
  7043. +/* comparison type */
  7044. +/* ??? currently only CMP_SI is used */
  7045. +enum cmp_type {
  7046. + CMP_SI, /* compare four byte integers */
  7047. + CMP_DI, /* compare eight byte integers */
  7048. + CMP_SF, /* compare single precision floats */
  7049. + CMP_DF, /* compare double precision floats */
  7050. + CMP_MAX /* max comparison type */
  7051. +};
  7052. +
  7053. +extern GTY(()) rtx branch_cmp[2]; /* operands for compare */
  7054. +extern enum cmp_type branch_type; /* what type of branch to use */
  7055. +
  7056. +/**********************
  7057. + * Register Usage
  7058. + **********************/
  7059. +
  7060. +/* ---------------------------------- *
  7061. + * Basic Characteristics of Registers
  7062. + * ---------------------------------- */
  7063. +
  7064. +/*
  7065. +Register Number
  7066. + Register Name
  7067. + Alternate Name
  7068. + Purpose
  7069. +0 r0 zero always zero
  7070. +1 r1 at Assembler Temporary
  7071. +2-3 r2-r3 Return Location
  7072. +4-7 r4-r7 Register Arguments
  7073. +8-15 r8-r15 Caller Saved Registers
  7074. +16-22 r16-r22 Callee Saved Registers
  7075. +23 r23 sc Static Chain (Callee Saved)
  7076. + ??? Does $sc want to be caller or callee
  7077. + saved. If caller, 15, else 23.
  7078. +24 r24 Exception Temporary
  7079. +25 r25 Breakpoint Temporary
  7080. +26 r26 gp Global Pointer
  7081. +27 r27 sp Stack Pointer
  7082. +28 r28 fp Frame Pointer
  7083. +29 r29 ea Exception Return Address
  7084. +30 r30 ba Breakpoint Return Address
  7085. +31 r31 ra Return Address
  7086. +
  7087. +32 ctl0 status
  7088. +33 ctl1 estatus STATUS saved by exception ?
  7089. +34 ctl2 bstatus STATUS saved by break ?
  7090. +35 ctl3 ipri Interrupt Priority Mask ?
  7091. +36 ctl4 ecause Exception Cause ?
  7092. +
  7093. +37 pc Not an actual register
  7094. +
  7095. +38 rap Return address pointer, this does not
  7096. + actually exist and will be eliminated
  7097. +
  7098. +39 fake_fp Fake Frame Pointer which will always be eliminated.
  7099. +40 fake_ap Fake Argument Pointer which will always be eliminated.
  7100. +
  7101. +41 First Pseudo Register
  7102. +
  7103. +
  7104. +The definitions for all the hard register numbers
  7105. +are located in nios2.md.
  7106. +*/
  7107. +
  7108. +#define FIRST_PSEUDO_REGISTER 41
  7109. +#define NUM_ARG_REGS (LAST_ARG_REGNO - FIRST_ARG_REGNO + 1)
  7110. +
  7111. +
  7112. +
  7113. +/* also see CONDITIONAL_REGISTER_USAGE */
  7114. +#define FIXED_REGISTERS \
  7115. + { \
  7116. +/* +0 1 2 3 4 5 6 7 8 9 */ \
  7117. +/* 0 */ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, \
  7118. +/* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
  7119. +/* 20 */ 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, \
  7120. +/* 30 */ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, \
  7121. +/* 40 */ 1, \
  7122. + }
  7123. +
  7124. +/* call used is the same as caller saved
  7125. + + fixed regs + args + ret vals */
  7126. +#define CALL_USED_REGISTERS \
  7127. + { \
  7128. +/* +0 1 2 3 4 5 6 7 8 9 */ \
  7129. +/* 0 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
  7130. +/* 10 */ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, \
  7131. +/* 20 */ 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, \
  7132. +/* 30 */ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, \
  7133. +/* 40 */ 1, \
  7134. + }
  7135. +
  7136. +#define HARD_REGNO_NREGS(REGNO, MODE) \
  7137. + ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
  7138. + / UNITS_PER_WORD)
  7139. +
  7140. +/* --------------------------- *
  7141. + * How Values Fit in Registers
  7142. + * --------------------------- */
  7143. +
  7144. +#define HARD_REGNO_MODE_OK(REGNO, MODE) 1
  7145. +
  7146. +#define MODES_TIEABLE_P(MODE1, MODE2) 1
  7147. +
  7148. +
  7149. +/*************************
  7150. + * Register Classes
  7151. + *************************/
  7152. +
  7153. +enum reg_class
  7154. +{
  7155. + NO_REGS,
  7156. + ALL_REGS,
  7157. + LIM_REG_CLASSES
  7158. +};
  7159. +
  7160. +#define N_REG_CLASSES (int) LIM_REG_CLASSES
  7161. +
  7162. +#define REG_CLASS_NAMES \
  7163. + {"NO_REGS", \
  7164. + "ALL_REGS"}
  7165. +
  7166. +#define GENERAL_REGS ALL_REGS
  7167. +
  7168. +#define REG_CLASS_CONTENTS \
  7169. +/* NO_REGS */ {{ 0, 0}, \
  7170. +/* ALL_REGS */ {~0,~0}} \
  7171. +
  7172. +#define REGNO_REG_CLASS(REGNO) ALL_REGS
  7173. +
  7174. +#define BASE_REG_CLASS ALL_REGS
  7175. +#define INDEX_REG_CLASS ALL_REGS
  7176. +
  7177. +/* only one reg class, 'r', is handled automatically */
  7178. +#define REG_CLASS_FROM_LETTER(CHAR) NO_REGS
  7179. +
  7180. +#define REGNO_OK_FOR_BASE_P2(REGNO, STRICT) \
  7181. + ((STRICT) \
  7182. + ? (REGNO) < FIRST_PSEUDO_REGISTER \
  7183. + : (REGNO) < FIRST_PSEUDO_REGISTER || (reg_renumber && reg_renumber[REGNO] < FIRST_PSEUDO_REGISTER))
  7184. +
  7185. +#define REGNO_OK_FOR_INDEX_P2(REGNO, STRICT) \
  7186. + (REGNO_OK_FOR_BASE_P2 (REGNO, STRICT))
  7187. +
  7188. +#define REGNO_OK_FOR_BASE_P(REGNO) \
  7189. + (REGNO_OK_FOR_BASE_P2 (REGNO, 1))
  7190. +
  7191. +#define REGNO_OK_FOR_INDEX_P(REGNO) \
  7192. + (REGNO_OK_FOR_INDEX_P2 (REGNO, 1))
  7193. +
  7194. +#define REG_OK_FOR_BASE_P2(X, STRICT) \
  7195. + (STRICT \
  7196. + ? REGNO_OK_FOR_BASE_P2 (REGNO (X), 1) \
  7197. + : REGNO_OK_FOR_BASE_P2 (REGNO (X), 1) || REGNO(X) >= FIRST_PSEUDO_REGISTER)
  7198. +
  7199. +#define REG_OK_FOR_INDEX_P2(X, STRICT) \
  7200. + (STRICT \
  7201. + ? REGNO_OK_FOR_INDEX_P2 (REGNO (X), 1) \
  7202. + : REGNO_OK_FOR_INDEX_P2 (REGNO (X), 1) || REGNO(X) >= FIRST_PSEUDO_REGISTER)
  7203. +
  7204. +#define CLASS_MAX_NREGS(CLASS, MODE) \
  7205. + ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
  7206. + / UNITS_PER_WORD)
  7207. +
  7208. +
  7209. +#define SMALL_INT(X) ((unsigned HOST_WIDE_INT) ((X) + 0x8000) < 0x10000)
  7210. +#define SMALL_INT_UNSIGNED(X) ((unsigned HOST_WIDE_INT) (X) < 0x10000)
  7211. +#define UPPER16_INT(X) (((X) & 0xffff) == 0)
  7212. +#define SHIFT_INT(X) ((X) >= 0 && (X) <= 31)
  7213. +#define RDWRCTL_INT(X) ((X) >= 0 && (X) <= 31)
  7214. +#define CUSTOM_INSN_OPCODE(X) ((X) >= 0 && (X) <= 255)
  7215. +
  7216. +#define CONST_OK_FOR_LETTER_P(VALUE, C) \
  7217. + ( \
  7218. + (C) == 'I' ? SMALL_INT (VALUE) : \
  7219. + (C) == 'J' ? SMALL_INT_UNSIGNED (VALUE) : \
  7220. + (C) == 'K' ? UPPER16_INT (VALUE) : \
  7221. + (C) == 'L' ? SHIFT_INT (VALUE) : \
  7222. + (C) == 'M' ? (VALUE) == 0 : \
  7223. + (C) == 'N' ? CUSTOM_INSN_OPCODE (VALUE) : \
  7224. + (C) == 'O' ? RDWRCTL_INT (VALUE) : \
  7225. + 0)
  7226. +
  7227. +#define CONST_DOUBLE_OK_FOR_LETTER_P(VALUE, C) 0
  7228. +
  7229. +#define PREFERRED_RELOAD_CLASS(X, CLASS) \
  7230. + ((CLASS) == NO_REGS ? GENERAL_REGS : (CLASS))
  7231. +
  7232. +/* 'S' matches immediates which are in small data
  7233. + and therefore can be added to gp to create a
  7234. + 32-bit value. */
  7235. +#define EXTRA_CONSTRAINT(VALUE, C) \
  7236. + ((C) == 'S' \
  7237. + && (GET_CODE (VALUE) == SYMBOL_REF) \
  7238. + && SYMBOL_REF_IN_NIOS2_SMALL_DATA_P (VALUE))
  7239. +
  7240. +
  7241. +
  7242. +
  7243. +/* Say that the epilogue uses the return address register. Note that
  7244. + in the case of sibcalls, the values "used by the epilogue" are
  7245. + considered live at the start of the called function. */
  7246. +#define EPILOGUE_USES(REGNO) ((REGNO) == RA_REGNO)
  7247. +
  7248. +
  7249. +#define DEFAULT_MAIN_RETURN c_expand_return (integer_zero_node)
  7250. +
  7251. +/**********************************
  7252. + * Trampolines for Nested Functions
  7253. + ***********************************/
  7254. +
  7255. +#define TRAMPOLINE_TEMPLATE(FILE) \
  7256. + error ("trampolines not yet implemented")
  7257. +#define TRAMPOLINE_SIZE 20
  7258. +#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) \
  7259. + error ("trampolines not yet implemented")
  7260. +
  7261. +/***************************
  7262. + * Stack Layout and Calling Conventions
  7263. + ***************************/
  7264. +
  7265. +/* ------------------ *
  7266. + * Basic Stack Layout
  7267. + * ------------------ */
  7268. +
  7269. +/* The downward variants are used by the compiler,
  7270. + the upward ones serve as documentation */
  7271. +#define STACK_GROWS_DOWNWARD
  7272. +#define FRAME_GROWS_UPWARD
  7273. +#define ARGS_GROW_UPWARD
  7274. +
  7275. +#define STARTING_FRAME_OFFSET current_function_outgoing_args_size
  7276. +#define FIRST_PARM_OFFSET(FUNDECL) 0
  7277. +
  7278. +/* Before the prologue, RA lives in r31. */
  7279. +#define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (VOIDmode, RA_REGNO)
  7280. +
  7281. +/* -------------------------------------- *
  7282. + * Registers That Address the Stack Frame
  7283. + * -------------------------------------- */
  7284. +
  7285. +#define STACK_POINTER_REGNUM SP_REGNO
  7286. +#define STATIC_CHAIN_REGNUM SC_REGNO
  7287. +#define PC_REGNUM PC_REGNO
  7288. +#define DWARF_FRAME_RETURN_COLUMN RA_REGNO
  7289. +
  7290. +/* Base register for access to local variables of the function. We
  7291. + pretend that the frame pointer is a non-existent hard register, and
  7292. + then eliminate it to HARD_FRAME_POINTER_REGNUM. */
  7293. +#define FRAME_POINTER_REGNUM FAKE_FP_REGNO
  7294. +
  7295. +#define HARD_FRAME_POINTER_REGNUM FP_REGNO
  7296. +#define RETURN_ADDRESS_POINTER_REGNUM RAP_REGNO
  7297. +/* the argumnet pointer needs to always be eliminated
  7298. + so it is set to a fake hard register. */
  7299. +#define ARG_POINTER_REGNUM FAKE_AP_REGNO
  7300. +
  7301. +/* ----------------------------------------- *
  7302. + * Eliminating Frame Pointer and Arg Pointer
  7303. + * ----------------------------------------- */
  7304. +
  7305. +#define FRAME_POINTER_REQUIRED 0
  7306. +
  7307. +#define ELIMINABLE_REGS \
  7308. +{{ ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
  7309. + { ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
  7310. + { RETURN_ADDRESS_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
  7311. + { RETURN_ADDRESS_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
  7312. + { FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
  7313. + { FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}}
  7314. +
  7315. +#define CAN_ELIMINATE(FROM, TO) 1
  7316. +
  7317. +#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
  7318. + (OFFSET) = nios2_initial_elimination_offset ((FROM), (TO))
  7319. +
  7320. +#define MUST_SAVE_REGISTER(regno) \
  7321. + ((regs_ever_live[regno] && !call_used_regs[regno]) \
  7322. + || (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed) \
  7323. + || (regno == RA_REGNO && regs_ever_live[RA_REGNO]))
  7324. +
  7325. +/* Treat LOC as a byte offset from the stack pointer and round it up
  7326. + to the next fully-aligned offset. */
  7327. +#define STACK_ALIGN(LOC) \
  7328. + (((LOC) + ((PREFERRED_STACK_BOUNDARY / 8) - 1)) & ~((PREFERRED_STACK_BOUNDARY / 8) - 1))
  7329. +
  7330. +
  7331. +/* ------------------------------ *
  7332. + * Passing Arguments in Registers
  7333. + * ------------------------------ */
  7334. +
  7335. +/* see nios2.c */
  7336. +#define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
  7337. + (function_arg (&CUM, MODE, TYPE, NAMED))
  7338. +
  7339. +#define FUNCTION_ARG_PARTIAL_NREGS(CUM, MODE, TYPE, NAMED) \
  7340. + (function_arg_partial_nregs (&CUM, MODE, TYPE, NAMED))
  7341. +
  7342. +#define FUNCTION_ARG_PASS_BY_REFERENCE(CUM, MODE, TYPE, NAMED) 0
  7343. +
  7344. +#define FUNCTION_ARG_CALLEE_COPIES(CUM, MODE, TYPE, NAMED) 0
  7345. +
  7346. +typedef struct nios2_args
  7347. +{
  7348. + int regs_used;
  7349. +} CUMULATIVE_ARGS;
  7350. +
  7351. +/* This is to initialize the above unused CUM data type */
  7352. +#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS) \
  7353. + (init_cumulative_args (&CUM, FNTYPE, LIBNAME, FNDECL, N_NAMED_ARGS))
  7354. +
  7355. +#define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED) \
  7356. + (function_arg_advance (&CUM, MODE, TYPE, NAMED))
  7357. +
  7358. +#define FUNCTION_ARG_REGNO_P(REGNO) \
  7359. + ((REGNO) >= FIRST_ARG_REGNO && (REGNO) <= LAST_ARG_REGNO)
  7360. +
  7361. +#define SETUP_INCOMING_VARARGS(CUM,MODE,TYPE,PRETEND_SIZE,NO_RTL) \
  7362. + { \
  7363. + int pret_size = nios2_setup_incoming_varargs (&(CUM), (MODE), \
  7364. + (TYPE), (NO_RTL)); \
  7365. + if (pret_size) \
  7366. + (PRETEND_SIZE) = pret_size; \
  7367. + }
  7368. +
  7369. +/* ----------------------------- *
  7370. + * Generating Code for Profiling
  7371. + * ----------------------------- */
  7372. +
  7373. +#define PROFILE_BEFORE_PROLOGUE
  7374. +
  7375. +#define FUNCTION_PROFILER(FILE, LABELNO) \
  7376. + function_profiler ((FILE), (LABELNO))
  7377. +
  7378. +/* --------------------------------------- *
  7379. + * Passing Function Arguments on the Stack
  7380. + * --------------------------------------- */
  7381. +
  7382. +#define PROMOTE_PROTOTYPES 1
  7383. +
  7384. +#define PUSH_ARGS 0
  7385. +#define ACCUMULATE_OUTGOING_ARGS 1
  7386. +
  7387. +#define RETURN_POPS_ARGS(FUNDECL, FUNTYPE, STACKSIZE) 0
  7388. +
  7389. +/* --------------------------------------- *
  7390. + * How Scalar Function Values Are Returned
  7391. + * --------------------------------------- */
  7392. +
  7393. +#define FUNCTION_VALUE(VALTYPE, FUNC) \
  7394. + gen_rtx(REG, TYPE_MODE(VALTYPE), FIRST_RETVAL_REGNO)
  7395. +
  7396. +#define LIBCALL_VALUE(MODE) \
  7397. + gen_rtx(REG, MODE, FIRST_RETVAL_REGNO)
  7398. +
  7399. +#define FUNCTION_VALUE_REGNO_P(REGNO) ((REGNO) == FIRST_RETVAL_REGNO)
  7400. +
  7401. +/* ----------------------------- *
  7402. + * How Large Values Are Returned
  7403. + * ----------------------------- */
  7404. +
  7405. +
  7406. +#define RETURN_IN_MEMORY(TYPE) \
  7407. + nios2_return_in_memory (TYPE)
  7408. +
  7409. +
  7410. +#define STRUCT_VALUE 0
  7411. +
  7412. +#define DEFAULT_PCC_STRUCT_RETURN 0
  7413. +
  7414. +/*******************
  7415. + * Addressing Modes
  7416. + *******************/
  7417. +
  7418. +
  7419. +#define LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN)
  7420. +
  7421. +#define CONSTANT_ADDRESS_P(X) (CONSTANT_P (X))
  7422. +
  7423. +#define MAX_REGS_PER_ADDRESS 1
  7424. +
  7425. +/* Go to ADDR if X is a valid address. */
  7426. +#ifndef REG_OK_STRICT
  7427. +#define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR) \
  7428. + { \
  7429. + if (nios2_legitimate_address ((X), (MODE), 0)) \
  7430. + goto ADDR; \
  7431. + }
  7432. +#else
  7433. +#define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR) \
  7434. + { \
  7435. + if (nios2_legitimate_address ((X), (MODE), 1)) \
  7436. + goto ADDR; \
  7437. + }
  7438. +#endif
  7439. +
  7440. +#ifndef REG_OK_STRICT
  7441. +#define REG_OK_FOR_BASE_P(X) REGNO_OK_FOR_BASE_P2 (REGNO (X), 0)
  7442. +#define REG_OK_FOR_INDEX_P(X) REGNO_OK_FOR_INDEX_P2 (REGNO (X), 0)
  7443. +#else
  7444. +#define REG_OK_FOR_BASE_P(X) REGNO_OK_FOR_BASE_P2 (REGNO (X), 1)
  7445. +#define REG_OK_FOR_INDEX_P(X) REGNO_OK_FOR_INDEX_P2 (REGNO (X), 1)
  7446. +#endif
  7447. +
  7448. +#define LEGITIMATE_CONSTANT_P(X) 1
  7449. +
  7450. +/* Nios II has no mode dependent addresses. */
  7451. +#define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR, LABEL)
  7452. +
  7453. +/* Set if this has a weak declaration */
  7454. +#define SYMBOL_FLAG_WEAK_DECL (1 << SYMBOL_FLAG_MACH_DEP_SHIFT)
  7455. +#define SYMBOL_REF_WEAK_DECL_P(RTX) \
  7456. + ((SYMBOL_REF_FLAGS (RTX) & SYMBOL_FLAG_WEAK_DECL) != 0)
  7457. +
  7458. +
  7459. +/* true if a symbol is both small and not weak. In this case, gp
  7460. + relative access can be used */
  7461. +#define SYMBOL_REF_IN_NIOS2_SMALL_DATA_P(RTX) \
  7462. + (SYMBOL_REF_SMALL_P(RTX) && !SYMBOL_REF_WEAK_DECL_P(RTX))
  7463. +
  7464. +/*****************
  7465. + * Describing Relative Costs of Operations
  7466. + *****************/
  7467. +
  7468. +#define SLOW_BYTE_ACCESS 1
  7469. +
  7470. +/* It is as good to call a constant function address as to call an address
  7471. + kept in a register.
  7472. + ??? Not true anymore really. Now that call cannot address full range
  7473. + of memory callr may need to be used */
  7474. +
  7475. +#define NO_FUNCTION_CSE
  7476. +#define NO_RECURSIVE_FUNCTION_CSE
  7477. +
  7478. +
  7479. +
  7480. +/*****************************************
  7481. + * Defining the Output Assembler Language
  7482. + *****************************************/
  7483. +
  7484. +/* ------------------------------------------ *
  7485. + * The Overall Framework of an Assembler File
  7486. + * ------------------------------------------ */
  7487. +
  7488. +#define ASM_APP_ON "#APP\n"
  7489. +#define ASM_APP_OFF "#NO_APP\n"
  7490. +
  7491. +#define ASM_COMMENT_START "# "
  7492. +
  7493. +/* ------------------------------- *
  7494. + * Output and Generation of Labels
  7495. + * ------------------------------- */
  7496. +
  7497. +#define GLOBAL_ASM_OP "\t.global\t"
  7498. +
  7499. +
  7500. +/* -------------- *
  7501. + * Output of Data
  7502. + * -------------- */
  7503. +
  7504. +#define DWARF2_UNWIND_INFO 0
  7505. +
  7506. +
  7507. +/* -------------------------------- *
  7508. + * Assembler Commands for Alignment
  7509. + * -------------------------------- */
  7510. +
  7511. +#define ASM_OUTPUT_ALIGN(FILE, LOG) \
  7512. + do { \
  7513. + fprintf ((FILE), "%s%d\n", ALIGN_ASM_OP, (LOG)); \
  7514. + } while (0)
  7515. +
  7516. +
  7517. +/* -------------------------------- *
  7518. + * Output of Assembler Instructions
  7519. + * -------------------------------- */
  7520. +
  7521. +#define REGISTER_NAMES \
  7522. +{ \
  7523. + "zero", \
  7524. + "at", \
  7525. + "r2", \
  7526. + "r3", \
  7527. + "r4", \
  7528. + "r5", \
  7529. + "r6", \
  7530. + "r7", \
  7531. + "r8", \
  7532. + "r9", \
  7533. + "r10", \
  7534. + "r11", \
  7535. + "r12", \
  7536. + "r13", \
  7537. + "r14", \
  7538. + "r15", \
  7539. + "r16", \
  7540. + "r17", \
  7541. + "r18", \
  7542. + "r19", \
  7543. + "r20", \
  7544. + "r21", \
  7545. + "r22", \
  7546. + "r23", \
  7547. + "r24", \
  7548. + "r25", \
  7549. + "gp", \
  7550. + "sp", \
  7551. + "fp", \
  7552. + "ta", \
  7553. + "ba", \
  7554. + "ra", \
  7555. + "status", \
  7556. + "estatus", \
  7557. + "bstatus", \
  7558. + "ipri", \
  7559. + "ecause", \
  7560. + "pc", \
  7561. + "rap", \
  7562. + "fake_fp", \
  7563. + "fake_ap", \
  7564. +}
  7565. +
  7566. +#define ASM_OUTPUT_OPCODE(STREAM, PTR)\
  7567. + (PTR) = asm_output_opcode (STREAM, PTR)
  7568. +
  7569. +#define PRINT_OPERAND(STREAM, X, CODE) \
  7570. + nios2_print_operand (STREAM, X, CODE)
  7571. +
  7572. +#define PRINT_OPERAND_ADDRESS(STREAM, X) \
  7573. + nios2_print_operand_address (STREAM, X)
  7574. +
  7575. +#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
  7576. +do { fputs (integer_asm_op (POINTER_SIZE / BITS_PER_UNIT, TRUE), FILE); \
  7577. + fprintf (FILE, ".L%u\n", (unsigned) (VALUE)); \
  7578. + } while (0)
  7579. +
  7580. +
  7581. +/* ------------ *
  7582. + * Label Output
  7583. + * ------------ */
  7584. +
  7585. +
  7586. +/* ---------------------------------------------------- *
  7587. + * Dividing the Output into Sections (Texts, Data, ...)
  7588. + * ---------------------------------------------------- */
  7589. +
  7590. +/* Output before read-only data. */
  7591. +#define TEXT_SECTION_ASM_OP ("\t.section\t.text")
  7592. +
  7593. +/* Output before writable data. */
  7594. +#define DATA_SECTION_ASM_OP ("\t.section\t.data")
  7595. +
  7596. +
  7597. +/* Default the definition of "small data" to 8 bytes. */
  7598. +/* ??? How come I can't use HOST_WIDE_INT here? */
  7599. +extern unsigned long nios2_section_threshold;
  7600. +#define NIOS2_DEFAULT_GVALUE 8
  7601. +
  7602. +
  7603. +
  7604. +/* This says how to output assembler code to declare an
  7605. + uninitialized external linkage data object. Under SVR4,
  7606. + the linker seems to want the alignment of data objects
  7607. + to depend on their types. We do exactly that here. */
  7608. +
  7609. +#undef COMMON_ASM_OP
  7610. +#define COMMON_ASM_OP "\t.comm\t"
  7611. +
  7612. +#undef ASM_OUTPUT_ALIGNED_COMMON
  7613. +#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
  7614. +do \
  7615. +{ \
  7616. + if ((SIZE) <= nios2_section_threshold) \
  7617. + { \
  7618. + named_section (0, ".sbss", 0); \
  7619. + (*targetm.asm_out.globalize_label) (FILE, NAME); \
  7620. + ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
  7621. + if (!flag_inhibit_size_directive) \
  7622. + ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
  7623. + ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
  7624. + ASM_OUTPUT_LABEL(FILE, NAME); \
  7625. + ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
  7626. + } \
  7627. + else \
  7628. + { \
  7629. + fprintf ((FILE), "%s", COMMON_ASM_OP); \
  7630. + assemble_name ((FILE), (NAME)); \
  7631. + fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT); \
  7632. + } \
  7633. +} \
  7634. +while (0)
  7635. +
  7636. +
  7637. +/* This says how to output assembler code to declare an
  7638. + uninitialized internal linkage data object. Under SVR4,
  7639. + the linker seems to want the alignment of data objects
  7640. + to depend on their types. We do exactly that here. */
  7641. +
  7642. +#undef ASM_OUTPUT_ALIGNED_LOCAL
  7643. +#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
  7644. +do { \
  7645. + if ((SIZE) <= nios2_section_threshold) \
  7646. + named_section (0, ".sbss", 0); \
  7647. + else \
  7648. + named_section (0, ".bss", 0); \
  7649. + ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
  7650. + if (!flag_inhibit_size_directive) \
  7651. + ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \
  7652. + ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \
  7653. + ASM_OUTPUT_LABEL(FILE, NAME); \
  7654. + ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \
  7655. +} while (0)
  7656. +
  7657. +
  7658. +
  7659. +/***************************
  7660. + * Miscellaneous Parameters
  7661. + ***************************/
  7662. +
  7663. +#define MOVE_MAX 4
  7664. +
  7665. +#define Pmode SImode
  7666. +#define FUNCTION_MODE QImode
  7667. +
  7668. +#define CASE_VECTOR_MODE Pmode
  7669. +
  7670. +#define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1
  7671. +
  7672. +#define LOAD_EXTEND_OP(MODE) (ZERO_EXTEND)
  7673. +
  7674. +#define WORD_REGISTER_OPERATIONS
  7675. --- gcc-3.4.3/gcc/config/nios2/nios2.md
  7676. +++ gcc-3.4.3-nios2/gcc/config/nios2/nios2.md
  7677. @@ -0,0 +1,2078 @@
  7678. +;; Machine Description for Altera NIOS 2G NIOS2 version.
  7679. +;; Copyright (C) 2003 Altera
  7680. +;; Contributed by Jonah Graham (jgraham@altera.com).
  7681. +;;
  7682. +;; This file is part of GNU CC.
  7683. +;;
  7684. +;; GNU CC is free software; you can redistribute it and/or modify
  7685. +;; it under the terms of the GNU General Public License as published by
  7686. +;; the Free Software Foundation; either version 2, or (at your option)
  7687. +;; any later version.
  7688. +;;
  7689. +;; GNU CC is distributed in the hope that it will be useful,
  7690. +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  7691. +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7692. +;; GNU General Public License for more details.
  7693. +;;
  7694. +;; You should have received a copy of the GNU General Public License
  7695. +;; along with GNU CC; see the file COPYING. If not, write to
  7696. +;; the Free Software Foundation, 59 Temple Place - Suite 330,
  7697. +;; Boston, MA 02111-1307, USA. */
  7698. +
  7699. +
  7700. +
  7701. +;*****************************************************************************
  7702. +;*
  7703. +;* constants
  7704. +;*
  7705. +;*****************************************************************************
  7706. +(define_constants [
  7707. + (GP_REGNO 26)
  7708. + (SP_REGNO 27)
  7709. + (FP_REGNO 28)
  7710. + (RA_REGNO 31)
  7711. + (RAP_REGNO 38)
  7712. + (FIRST_RETVAL_REGNO 2)
  7713. + (LAST_RETVAL_REGNO 3)
  7714. + (FIRST_ARG_REGNO 4)
  7715. + (LAST_ARG_REGNO 7)
  7716. + (SC_REGNO 23)
  7717. + (PC_REGNO 37)
  7718. + (FAKE_FP_REGNO 39)
  7719. + (FAKE_AP_REGNO 40)
  7720. +
  7721. +
  7722. + (UNSPEC_BLOCKAGE 0)
  7723. + (UNSPEC_LDBIO 1)
  7724. + (UNSPEC_LDBUIO 2)
  7725. + (UNSPEC_LDHIO 3)
  7726. + (UNSPEC_LDHUIO 4)
  7727. + (UNSPEC_LDWIO 5)
  7728. + (UNSPEC_STBIO 6)
  7729. + (UNSPEC_STHIO 7)
  7730. + (UNSPEC_STWIO 8)
  7731. + (UNSPEC_SYNC 9)
  7732. + (UNSPEC_WRCTL 10)
  7733. + (UNSPEC_RDCTL 11)
  7734. +
  7735. +])
  7736. +
  7737. +
  7738. +
  7739. +;*****************************************************************************
  7740. +;*
  7741. +;* instruction scheduler
  7742. +;*
  7743. +;*****************************************************************************
  7744. +
  7745. +; No schedule info is currently available, using an assumption that no
  7746. +; instruction can use the results of the previous instruction without
  7747. +; incuring a stall.
  7748. +
  7749. +; length of an instruction (in bytes)
  7750. +(define_attr "length" "" (const_int 4))
  7751. +(define_attr "type" "unknown,complex,control,alu,cond_alu,st,ld,shift,mul,div,custom" (const_string "complex"))
  7752. +
  7753. +(define_asm_attributes
  7754. + [(set_attr "length" "4")
  7755. + (set_attr "type" "complex")])
  7756. +
  7757. +(define_automaton "nios2")
  7758. +(automata_option "v")
  7759. +;(automata_option "no-minimization")
  7760. +(automata_option "ndfa")
  7761. +
  7762. +; The nios2 pipeline is fairly straightforward for the fast model.
  7763. +; Every alu operation is pipelined so that an instruction can
  7764. +; be issued every cycle. However, there are still potential
  7765. +; stalls which this description tries to deal with.
  7766. +
  7767. +(define_cpu_unit "cpu" "nios2")
  7768. +
  7769. +(define_insn_reservation "complex" 1
  7770. + (eq_attr "type" "complex")
  7771. + "cpu")
  7772. +
  7773. +(define_insn_reservation "control" 1
  7774. + (eq_attr "type" "control")
  7775. + "cpu")
  7776. +
  7777. +(define_insn_reservation "alu" 1
  7778. + (eq_attr "type" "alu")
  7779. + "cpu")
  7780. +
  7781. +(define_insn_reservation "cond_alu" 1
  7782. + (eq_attr "type" "cond_alu")
  7783. + "cpu")
  7784. +
  7785. +(define_insn_reservation "st" 1
  7786. + (eq_attr "type" "st")
  7787. + "cpu")
  7788. +
  7789. +(define_insn_reservation "custom" 1
  7790. + (eq_attr "type" "custom")
  7791. + "cpu")
  7792. +
  7793. +; shifts, muls and lds have three cycle latency
  7794. +(define_insn_reservation "ld" 3
  7795. + (eq_attr "type" "ld")
  7796. + "cpu")
  7797. +
  7798. +(define_insn_reservation "shift" 3
  7799. + (eq_attr "type" "shift")
  7800. + "cpu")
  7801. +
  7802. +(define_insn_reservation "mul" 3
  7803. + (eq_attr "type" "mul")
  7804. + "cpu")
  7805. +
  7806. +(define_insn_reservation "div" 1
  7807. + (eq_attr "type" "div")
  7808. + "cpu")
  7809. +
  7810. +
  7811. +;*****************************************************************************
  7812. +;*
  7813. +;* MOV Instructions
  7814. +;*
  7815. +;*****************************************************************************
  7816. +
  7817. +(define_expand "movqi"
  7818. + [(set (match_operand:QI 0 "nonimmediate_operand" "")
  7819. + (match_operand:QI 1 "general_operand" ""))]
  7820. + ""
  7821. +{
  7822. + if (nios2_emit_move_sequence (operands, QImode))
  7823. + DONE;
  7824. +})
  7825. +
  7826. +(define_insn "movqi_internal"
  7827. + [(set (match_operand:QI 0 "nonimmediate_operand" "=m, r,r, r")
  7828. + (match_operand:QI 1 "general_operand" "rM,m,rM,I"))]
  7829. + "(register_operand (operands[0], QImode)
  7830. + || register_operand (operands[1], QImode)
  7831. + || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
  7832. + "@
  7833. + stb%o0\\t%z1, %0
  7834. + ldbu%o1\\t%0, %1
  7835. + mov\\t%0, %z1
  7836. + movi\\t%0, %1"
  7837. + [(set_attr "type" "st,ld,alu,alu")])
  7838. +
  7839. +(define_insn "ldbio"
  7840. + [(set (match_operand:SI 0 "register_operand" "=r")
  7841. + (unspec_volatile:SI [(const_int 0)] UNSPEC_LDBIO))
  7842. + (use (match_operand:SI 1 "memory_operand" "m"))]
  7843. + ""
  7844. + "ldbio\\t%0, %1"
  7845. + [(set_attr "type" "ld")])
  7846. +
  7847. +(define_insn "ldbuio"
  7848. + [(set (match_operand:SI 0 "register_operand" "=r")
  7849. + (unspec_volatile:SI [(const_int 0)] UNSPEC_LDBUIO))
  7850. + (use (match_operand:SI 1 "memory_operand" "m"))]
  7851. + ""
  7852. + "ldbuio\\t%0, %1"
  7853. + [(set_attr "type" "ld")])
  7854. +
  7855. +(define_insn "stbio"
  7856. + [(set (match_operand:SI 0 "memory_operand" "=m")
  7857. + (match_operand:SI 1 "register_operand" "r"))
  7858. + (unspec_volatile:SI [(const_int 0)] UNSPEC_STBIO)]
  7859. + ""
  7860. + "stbio\\t%z1, %0"
  7861. + [(set_attr "type" "st")])
  7862. +
  7863. +
  7864. +(define_expand "movhi"
  7865. + [(set (match_operand:HI 0 "nonimmediate_operand" "")
  7866. + (match_operand:HI 1 "general_operand" ""))]
  7867. + ""
  7868. +{
  7869. + if (nios2_emit_move_sequence (operands, HImode))
  7870. + DONE;
  7871. +})
  7872. +
  7873. +(define_insn "movhi_internal"
  7874. + [(set (match_operand:HI 0 "nonimmediate_operand" "=m, r,r, r,r")
  7875. + (match_operand:HI 1 "general_operand" "rM,m,rM,I,J"))]
  7876. + "(register_operand (operands[0], HImode)
  7877. + || register_operand (operands[1], HImode)
  7878. + || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
  7879. + "@
  7880. + sth%o0\\t%z1, %0
  7881. + ldhu%o1\\t%0, %1
  7882. + mov\\t%0, %z1
  7883. + movi\\t%0, %1
  7884. + movui\\t%0, %1"
  7885. + [(set_attr "type" "st,ld,alu,alu,alu")])
  7886. +
  7887. +(define_insn "ldhio"
  7888. + [(set (match_operand:SI 0 "register_operand" "=r")
  7889. + (unspec_volatile:SI [(const_int 0)] UNSPEC_LDHIO))
  7890. + (use (match_operand:SI 1 "memory_operand" "m"))]
  7891. + ""
  7892. + "ldhio\\t%0, %1"
  7893. + [(set_attr "type" "ld")])
  7894. +
  7895. +(define_insn "ldhuio"
  7896. + [(set (match_operand:SI 0 "register_operand" "=r")
  7897. + (unspec_volatile:SI [(const_int 0)] UNSPEC_LDHUIO))
  7898. + (use (match_operand:SI 1 "memory_operand" "m"))]
  7899. + ""
  7900. + "ldhuio\\t%0, %1"
  7901. + [(set_attr "type" "ld")])
  7902. +
  7903. +(define_insn "sthio"
  7904. + [(set (match_operand:SI 0 "memory_operand" "=m")
  7905. + (match_operand:SI 1 "register_operand" "r"))
  7906. + (unspec_volatile:SI [(const_int 0)] UNSPEC_STHIO)]
  7907. + ""
  7908. + "sthio\\t%z1, %0"
  7909. + [(set_attr "type" "st")])
  7910. +
  7911. +(define_expand "movsi"
  7912. + [(set (match_operand:SI 0 "nonimmediate_operand" "")
  7913. + (match_operand:SI 1 "general_operand" ""))]
  7914. + ""
  7915. +{
  7916. + if (nios2_emit_move_sequence (operands, SImode))
  7917. + DONE;
  7918. +})
  7919. +
  7920. +(define_insn "movsi_internal"
  7921. + [(set (match_operand:SI 0 "nonimmediate_operand" "=m, r,r, r,r,r,r")
  7922. + (match_operand:SI 1 "general_operand" "rM,m,rM,I,J,S,i"))]
  7923. + "(register_operand (operands[0], SImode)
  7924. + || register_operand (operands[1], SImode)
  7925. + || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
  7926. + "@
  7927. + stw%o0\\t%z1, %0
  7928. + ldw%o1\\t%0, %1
  7929. + mov\\t%0, %z1
  7930. + movi\\t%0, %1
  7931. + movui\\t%0, %1
  7932. + addi\\t%0, gp, %%gprel(%1)
  7933. + movhi\\t%0, %H1\;addi\\t%0, %0, %L1"
  7934. + [(set_attr "type" "st,ld,alu,alu,alu,alu,alu")])
  7935. +
  7936. +(define_insn "ldwio"
  7937. + [(set (match_operand:SI 0 "register_operand" "=r")
  7938. + (unspec_volatile:SI [(const_int 0)] UNSPEC_LDWIO))
  7939. + (use (match_operand:SI 1 "memory_operand" "m"))]
  7940. + ""
  7941. + "ldwio\\t%0, %1"
  7942. + [(set_attr "type" "ld")])
  7943. +
  7944. +(define_insn "stwio"
  7945. + [(set (match_operand:SI 0 "memory_operand" "=m")
  7946. + (match_operand:SI 1 "register_operand" "r"))
  7947. + (unspec_volatile:SI [(const_int 0)] UNSPEC_STWIO)]
  7948. + ""
  7949. + "stwio\\t%z1, %0"
  7950. + [(set_attr "type" "st")])
  7951. +
  7952. +
  7953. +
  7954. +;*****************************************************************************
  7955. +;*
  7956. +;* zero extension
  7957. +;*
  7958. +;*****************************************************************************
  7959. +
  7960. +
  7961. +(define_insn "zero_extendhisi2"
  7962. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  7963. + (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
  7964. + ""
  7965. + "@
  7966. + andi\\t%0, %1, 0xffff
  7967. + ldhu%o1\\t%0, %1"
  7968. + [(set_attr "type" "alu,ld")])
  7969. +
  7970. +(define_insn "zero_extendqihi2"
  7971. + [(set (match_operand:HI 0 "register_operand" "=r,r")
  7972. + (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
  7973. + ""
  7974. + "@
  7975. + andi\\t%0, %1, 0xff
  7976. + ldbu%o1\\t%0, %1"
  7977. + [(set_attr "type" "alu,ld")])
  7978. +
  7979. +(define_insn "zero_extendqisi2"
  7980. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  7981. + (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
  7982. + ""
  7983. + "@
  7984. + andi\\t%0, %1, 0xff
  7985. + ldbu%o1\\t%0, %1"
  7986. + [(set_attr "type" "alu,ld")])
  7987. +
  7988. +
  7989. +
  7990. +;*****************************************************************************
  7991. +;*
  7992. +;* sign extension
  7993. +;*
  7994. +;*****************************************************************************
  7995. +
  7996. +(define_expand "extendhisi2"
  7997. + [(set (match_operand:SI 0 "register_operand" "")
  7998. + (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
  7999. + ""
  8000. +{
  8001. + if (optimize && GET_CODE (operands[1]) == MEM)
  8002. + operands[1] = force_not_mem (operands[1]);
  8003. +
  8004. + if (GET_CODE (operands[1]) != MEM)
  8005. + {
  8006. + rtx op1 = gen_lowpart (SImode, operands[1]);
  8007. + rtx temp = gen_reg_rtx (SImode);
  8008. + rtx shift = GEN_INT (16);
  8009. +
  8010. + emit_insn (gen_ashlsi3 (temp, op1, shift));
  8011. + emit_insn (gen_ashrsi3 (operands[0], temp, shift));
  8012. + DONE;
  8013. + }
  8014. +})
  8015. +
  8016. +(define_insn "extendhisi2_internal"
  8017. + [(set (match_operand:SI 0 "register_operand" "=r")
  8018. + (sign_extend:SI (match_operand:HI 1 "memory_operand" "m")))]
  8019. + ""
  8020. + "ldh%o1\\t%0, %1"
  8021. + [(set_attr "type" "ld")])
  8022. +
  8023. +(define_expand "extendqihi2"
  8024. + [(set (match_operand:HI 0 "register_operand" "")
  8025. + (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))]
  8026. + ""
  8027. +{
  8028. + if (optimize && GET_CODE (operands[1]) == MEM)
  8029. + operands[1] = force_not_mem (operands[1]);
  8030. +
  8031. + if (GET_CODE (operands[1]) != MEM)
  8032. + {
  8033. + rtx op0 = gen_lowpart (SImode, operands[0]);
  8034. + rtx op1 = gen_lowpart (SImode, operands[1]);
  8035. + rtx temp = gen_reg_rtx (SImode);
  8036. + rtx shift = GEN_INT (24);
  8037. +
  8038. + emit_insn (gen_ashlsi3 (temp, op1, shift));
  8039. + emit_insn (gen_ashrsi3 (op0, temp, shift));
  8040. + DONE;
  8041. + }
  8042. +})
  8043. +
  8044. +(define_insn "extendqihi2_internal"
  8045. + [(set (match_operand:HI 0 "register_operand" "=r")
  8046. + (sign_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
  8047. + ""
  8048. + "ldb%o1\\t%0, %1"
  8049. + [(set_attr "type" "ld")])
  8050. +
  8051. +
  8052. +(define_expand "extendqisi2"
  8053. + [(set (match_operand:SI 0 "register_operand" "")
  8054. + (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
  8055. + ""
  8056. +{
  8057. + if (optimize && GET_CODE (operands[1]) == MEM)
  8058. + operands[1] = force_not_mem (operands[1]);
  8059. +
  8060. + if (GET_CODE (operands[1]) != MEM)
  8061. + {
  8062. + rtx op1 = gen_lowpart (SImode, operands[1]);
  8063. + rtx temp = gen_reg_rtx (SImode);
  8064. + rtx shift = GEN_INT (24);
  8065. +
  8066. + emit_insn (gen_ashlsi3 (temp, op1, shift));
  8067. + emit_insn (gen_ashrsi3 (operands[0], temp, shift));
  8068. + DONE;
  8069. + }
  8070. +})
  8071. +
  8072. +(define_insn "extendqisi2_insn"
  8073. + [(set (match_operand:SI 0 "register_operand" "=r")
  8074. + (sign_extend:SI (match_operand:QI 1 "memory_operand" "m")))]
  8075. + ""
  8076. + "ldb%o1\\t%0, %1"
  8077. + [(set_attr "type" "ld")])
  8078. +
  8079. +
  8080. +
  8081. +;*****************************************************************************
  8082. +;*
  8083. +;* Arithmetic Operations
  8084. +;*
  8085. +;*****************************************************************************
  8086. +
  8087. +(define_insn "addsi3"
  8088. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  8089. + (plus:SI (match_operand:SI 1 "register_operand" "%r,r")
  8090. + (match_operand:SI 2 "arith_operand" "r,I")))]
  8091. + ""
  8092. + "add%i2\\t%0, %1, %z2"
  8093. + [(set_attr "type" "alu")])
  8094. +
  8095. +(define_insn "subsi3"
  8096. + [(set (match_operand:SI 0 "register_operand" "=r")
  8097. + (minus:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8098. + (match_operand:SI 2 "register_operand" "r")))]
  8099. + ""
  8100. + "sub\\t%0, %z1, %2"
  8101. + [(set_attr "type" "alu")])
  8102. +
  8103. +(define_insn "mulsi3"
  8104. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  8105. + (mult:SI (match_operand:SI 1 "register_operand" "r,r")
  8106. + (match_operand:SI 2 "arith_operand" "r,I")))]
  8107. + "TARGET_HAS_MUL"
  8108. + "mul%i2\\t%0, %1, %z2"
  8109. + [(set_attr "type" "mul")])
  8110. +
  8111. +(define_expand "divsi3"
  8112. + [(set (match_operand:SI 0 "register_operand" "=r")
  8113. + (div:SI (match_operand:SI 1 "register_operand" "r")
  8114. + (match_operand:SI 2 "register_operand" "r")))]
  8115. + ""
  8116. +{
  8117. + if (!TARGET_HAS_DIV)
  8118. + {
  8119. + if (!TARGET_FAST_SW_DIV)
  8120. + FAIL;
  8121. + else
  8122. + {
  8123. + if (nios2_emit_expensive_div (operands, SImode))
  8124. + DONE;
  8125. + }
  8126. + }
  8127. +})
  8128. +
  8129. +(define_insn "divsi3_insn"
  8130. + [(set (match_operand:SI 0 "register_operand" "=r")
  8131. + (div:SI (match_operand:SI 1 "register_operand" "r")
  8132. + (match_operand:SI 2 "register_operand" "r")))]
  8133. + "TARGET_HAS_DIV"
  8134. + "div\\t%0, %1, %2"
  8135. + [(set_attr "type" "div")])
  8136. +
  8137. +(define_insn "udivsi3"
  8138. + [(set (match_operand:SI 0 "register_operand" "=r")
  8139. + (udiv:SI (match_operand:SI 1 "register_operand" "r")
  8140. + (match_operand:SI 2 "register_operand" "r")))]
  8141. + "TARGET_HAS_DIV"
  8142. + "divu\\t%0, %1, %2"
  8143. + [(set_attr "type" "div")])
  8144. +
  8145. +(define_insn "smulsi3_highpart"
  8146. + [(set (match_operand:SI 0 "register_operand" "=r")
  8147. + (truncate:SI
  8148. + (lshiftrt:DI
  8149. + (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r"))
  8150. + (sign_extend:DI (match_operand:SI 2 "register_operand" "r")))
  8151. + (const_int 32))))]
  8152. + "TARGET_HAS_MULX"
  8153. + "mulxss\\t%0, %1, %2"
  8154. + [(set_attr "type" "mul")])
  8155. +
  8156. +(define_insn "umulsi3_highpart"
  8157. + [(set (match_operand:SI 0 "register_operand" "=r")
  8158. + (truncate:SI
  8159. + (lshiftrt:DI
  8160. + (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "r"))
  8161. + (zero_extend:DI (match_operand:SI 2 "register_operand" "r")))
  8162. + (const_int 32))))]
  8163. + "TARGET_HAS_MULX"
  8164. + "mulxuu\\t%0, %1, %2"
  8165. + [(set_attr "type" "mul")])
  8166. +
  8167. +
  8168. +(define_expand "mulsidi3"
  8169. + [(set (subreg:SI (match_operand:DI 0 "register_operand" "") 0)
  8170. + (mult:SI (match_operand:SI 1 "register_operand" "")
  8171. + (match_operand:SI 2 "register_operand" "")))
  8172. + (set (subreg:SI (match_dup 0) 4)
  8173. + (truncate:SI (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
  8174. + (sign_extend:DI (match_dup 2)))
  8175. + (const_int 32))))]
  8176. + "TARGET_HAS_MULX"
  8177. + "")
  8178. +
  8179. +(define_expand "umulsidi3"
  8180. + [(set (subreg:SI (match_operand:DI 0 "register_operand" "") 0)
  8181. + (mult:SI (match_operand:SI 1 "register_operand" "")
  8182. + (match_operand:SI 2 "register_operand" "")))
  8183. + (set (subreg:SI (match_dup 0) 4)
  8184. + (truncate:SI (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
  8185. + (zero_extend:DI (match_dup 2)))
  8186. + (const_int 32))))]
  8187. + "TARGET_HAS_MULX"
  8188. + "")
  8189. +
  8190. +
  8191. +
  8192. +;*****************************************************************************
  8193. +;*
  8194. +;* Negate and ones complement
  8195. +;*
  8196. +;*****************************************************************************
  8197. +
  8198. +(define_insn "negsi2"
  8199. + [(set (match_operand:SI 0 "register_operand" "=r")
  8200. + (neg:SI (match_operand:SI 1 "register_operand" "r")))]
  8201. + ""
  8202. +{
  8203. + operands[2] = const0_rtx;
  8204. + return "sub\\t%0, %z2, %1";
  8205. +}
  8206. + [(set_attr "type" "alu")])
  8207. +
  8208. +(define_insn "one_cmplsi2"
  8209. + [(set (match_operand:SI 0 "register_operand" "=r")
  8210. + (not:SI (match_operand:SI 1 "register_operand" "r")))]
  8211. + ""
  8212. +{
  8213. + operands[2] = const0_rtx;
  8214. + return "nor\\t%0, %z2, %1";
  8215. +}
  8216. + [(set_attr "type" "alu")])
  8217. +
  8218. +
  8219. +
  8220. +; Logical Operantions
  8221. +
  8222. +(define_insn "andsi3"
  8223. + [(set (match_operand:SI 0 "register_operand" "=r, r,r")
  8224. + (and:SI (match_operand:SI 1 "register_operand" "%r, r,r")
  8225. + (match_operand:SI 2 "logical_operand" "rM,J,K")))]
  8226. + ""
  8227. + "@
  8228. + and\\t%0, %1, %z2
  8229. + and%i2\\t%0, %1, %2
  8230. + andh%i2\\t%0, %1, %U2"
  8231. + [(set_attr "type" "alu")])
  8232. +
  8233. +(define_insn "iorsi3"
  8234. + [(set (match_operand:SI 0 "register_operand" "=r, r,r")
  8235. + (ior:SI (match_operand:SI 1 "register_operand" "%r, r,r")
  8236. + (match_operand:SI 2 "logical_operand" "rM,J,K")))]
  8237. + ""
  8238. + "@
  8239. + or\\t%0, %1, %z2
  8240. + or%i2\\t%0, %1, %2
  8241. + orh%i2\\t%0, %1, %U2"
  8242. + [(set_attr "type" "alu")])
  8243. +
  8244. +(define_insn "*norsi3"
  8245. + [(set (match_operand:SI 0 "register_operand" "=r")
  8246. + (and:SI (not:SI (match_operand:SI 1 "register_operand" "%r"))
  8247. + (not:SI (match_operand:SI 2 "reg_or_0_operand" "rM"))))]
  8248. + ""
  8249. + "nor\\t%0, %1, %z2"
  8250. + [(set_attr "type" "alu")])
  8251. +
  8252. +(define_insn "xorsi3"
  8253. + [(set (match_operand:SI 0 "register_operand" "=r, r,r")
  8254. + (xor:SI (match_operand:SI 1 "register_operand" "%r, r,r")
  8255. + (match_operand:SI 2 "logical_operand" "rM,J,K")))]
  8256. + ""
  8257. + "@
  8258. + xor\\t%0, %1, %z2
  8259. + xor%i2\\t%0, %1, %2
  8260. + xorh%i2\\t%0, %1, %U2"
  8261. + [(set_attr "type" "alu")])
  8262. +
  8263. +
  8264. +
  8265. +;*****************************************************************************
  8266. +;*
  8267. +;* Shifts
  8268. +;*
  8269. +;*****************************************************************************
  8270. +
  8271. +(define_insn "ashlsi3"
  8272. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  8273. + (ashift:SI (match_operand:SI 1 "register_operand" "r,r")
  8274. + (match_operand:SI 2 "shift_operand" "r,L")))]
  8275. + ""
  8276. + "sll%i2\\t%0, %1, %z2"
  8277. + [(set_attr "type" "shift")])
  8278. +
  8279. +(define_insn "ashrsi3"
  8280. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  8281. + (ashiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
  8282. + (match_operand:SI 2 "shift_operand" "r,L")))]
  8283. + ""
  8284. + "sra%i2\\t%0, %1, %z2"
  8285. + [(set_attr "type" "shift")])
  8286. +
  8287. +(define_insn "lshrsi3"
  8288. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  8289. + (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,r")
  8290. + (match_operand:SI 2 "shift_operand" "r,L")))]
  8291. + ""
  8292. + "srl%i2\\t%0, %1, %z2"
  8293. + [(set_attr "type" "shift")])
  8294. +
  8295. +(define_insn "rotlsi3"
  8296. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  8297. + (rotate:SI (match_operand:SI 1 "register_operand" "r,r")
  8298. + (match_operand:SI 2 "shift_operand" "r,L")))]
  8299. + ""
  8300. + "rol%i2\\t%0, %1, %z2"
  8301. + [(set_attr "type" "shift")])
  8302. +
  8303. +(define_insn "rotrsi3"
  8304. + [(set (match_operand:SI 0 "register_operand" "=r,r")
  8305. + (rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
  8306. + (match_operand:SI 2 "register_operand" "r,r")))]
  8307. + ""
  8308. + "ror\\t%0, %1, %2"
  8309. + [(set_attr "type" "shift")])
  8310. +
  8311. +(define_insn "*shift_mul_constants"
  8312. + [(set (match_operand:SI 0 "register_operand" "=r")
  8313. + (ashift:SI (mult:SI (match_operand:SI 1 "register_operand" "r")
  8314. + (match_operand:SI 2 "const_int_operand" "I"))
  8315. + (match_operand:SI 3 "const_int_operand" "I")))]
  8316. + "TARGET_HAS_MUL && SMALL_INT (INTVAL (operands[2]) << INTVAL (operands[3]))"
  8317. +{
  8318. + HOST_WIDE_INT mul = INTVAL (operands[2]) << INTVAL (operands[3]);
  8319. + rtx ops[3];
  8320. +
  8321. + ops[0] = operands[0];
  8322. + ops[1] = operands[1];
  8323. + ops[2] = GEN_INT (mul);
  8324. +
  8325. + output_asm_insn ("muli\t%0, %1, %2", ops);
  8326. + return "";
  8327. +}
  8328. + [(set_attr "type" "mul")])
  8329. +
  8330. +
  8331. +
  8332. +
  8333. +;*****************************************************************************
  8334. +;*
  8335. +;* Prologue, Epilogue and Return
  8336. +;*
  8337. +;*****************************************************************************
  8338. +
  8339. +(define_expand "prologue"
  8340. + [(const_int 1)]
  8341. + ""
  8342. +{
  8343. + expand_prologue ();
  8344. + DONE;
  8345. +})
  8346. +
  8347. +(define_expand "epilogue"
  8348. + [(return)]
  8349. + ""
  8350. +{
  8351. + expand_epilogue (false);
  8352. + DONE;
  8353. +})
  8354. +
  8355. +(define_expand "sibcall_epilogue"
  8356. + [(return)]
  8357. + ""
  8358. +{
  8359. + expand_epilogue (true);
  8360. + DONE;
  8361. +})
  8362. +
  8363. +(define_insn "return"
  8364. + [(return)]
  8365. + "reload_completed && nios2_can_use_return_insn ()"
  8366. + "ret\\t"
  8367. +)
  8368. +
  8369. +(define_insn "return_from_epilogue"
  8370. + [(use (match_operand 0 "pmode_register_operand" ""))
  8371. + (return)]
  8372. + "reload_completed"
  8373. + "ret\\t"
  8374. +)
  8375. +
  8376. +;; Block any insns from being moved before this point, since the
  8377. +;; profiling call to mcount can use various registers that aren't
  8378. +;; saved or used to pass arguments.
  8379. +
  8380. +(define_insn "blockage"
  8381. + [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
  8382. + ""
  8383. + ""
  8384. + [(set_attr "type" "unknown")
  8385. + (set_attr "length" "0")])
  8386. +
  8387. +
  8388. +
  8389. +;*****************************************************************************
  8390. +;*
  8391. +;* Jumps and Calls
  8392. +;*
  8393. +;*****************************************************************************
  8394. +
  8395. +(define_insn "indirect_jump"
  8396. + [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
  8397. + ""
  8398. + "jmp\\t%0"
  8399. + [(set_attr "type" "control")])
  8400. +
  8401. +(define_insn "jump"
  8402. + [(set (pc)
  8403. + (label_ref (match_operand 0 "" "")))]
  8404. + ""
  8405. + "br\\t%0"
  8406. + [(set_attr "type" "control")])
  8407. +
  8408. +
  8409. +(define_insn "indirect_call"
  8410. + [(call (mem:QI (match_operand:SI 0 "register_operand" "r"))
  8411. + (match_operand 1 "" ""))
  8412. + (clobber (reg:SI RA_REGNO))]
  8413. + ""
  8414. + "callr\\t%0"
  8415. + [(set_attr "type" "control")])
  8416. +
  8417. +(define_insn "indirect_call_value"
  8418. + [(set (match_operand 0 "" "")
  8419. + (call (mem:QI (match_operand:SI 1 "register_operand" "r"))
  8420. + (match_operand 2 "" "")))
  8421. + (clobber (reg:SI RA_REGNO))]
  8422. + ""
  8423. + "callr\\t%1"
  8424. +)
  8425. +
  8426. +(define_expand "call"
  8427. + [(parallel [(call (match_operand 0 "" "")
  8428. + (match_operand 1 "" ""))
  8429. + (clobber (reg:SI RA_REGNO))])]
  8430. + ""
  8431. + "")
  8432. +
  8433. +(define_expand "call_value"
  8434. + [(parallel [(set (match_operand 0 "" "")
  8435. + (call (match_operand 1 "" "")
  8436. + (match_operand 2 "" "")))
  8437. + (clobber (reg:SI RA_REGNO))])]
  8438. + ""
  8439. + "")
  8440. +
  8441. +(define_insn "*call"
  8442. + [(call (mem:QI (match_operand:SI 0 "immediate_operand" "i"))
  8443. + (match_operand 1 "" ""))
  8444. + (clobber (match_operand:SI 2 "register_operand" "=r"))]
  8445. + ""
  8446. + "call\\t%0"
  8447. + [(set_attr "type" "control")])
  8448. +
  8449. +(define_insn "*call_value"
  8450. + [(set (match_operand 0 "" "")
  8451. + (call (mem:QI (match_operand:SI 1 "immediate_operand" "i"))
  8452. + (match_operand 2 "" "")))
  8453. + (clobber (match_operand:SI 3 "register_operand" "=r"))]
  8454. + ""
  8455. + "call\\t%1"
  8456. + [(set_attr "type" "control")])
  8457. +
  8458. +(define_expand "sibcall"
  8459. + [(parallel [(call (match_operand 0 "" "")
  8460. + (match_operand 1 "" ""))
  8461. + (return)
  8462. + (use (match_operand 2 "" ""))])]
  8463. + ""
  8464. + {
  8465. + XEXP (operands[0], 0) = copy_to_mode_reg (SImode, XEXP (operands[0], 0));
  8466. +
  8467. + if (operands[2] == NULL_RTX)
  8468. + operands[2] = const0_rtx;
  8469. + }
  8470. +)
  8471. +
  8472. +(define_expand "sibcall_value"
  8473. + [(parallel [(set (match_operand 0 "" "")
  8474. + (call (match_operand 1 "" "")
  8475. + (match_operand 2 "" "")))
  8476. + (return)
  8477. + (use (match_operand 3 "" ""))])]
  8478. + ""
  8479. + {
  8480. + XEXP (operands[1], 0) = copy_to_mode_reg (SImode, XEXP (operands[1], 0));
  8481. +
  8482. + if (operands[3] == NULL_RTX)
  8483. + operands[3] = const0_rtx;
  8484. + }
  8485. +)
  8486. +
  8487. +(define_insn "sibcall_insn"
  8488. + [(call (mem:QI (match_operand:SI 0 "register_operand" "r"))
  8489. + (match_operand 1 "" ""))
  8490. + (return)
  8491. + (use (match_operand 2 "" ""))]
  8492. + ""
  8493. + "jmp\\t%0"
  8494. +)
  8495. +
  8496. +(define_insn "sibcall_value_insn"
  8497. + [(set (match_operand 0 "register_operand" "")
  8498. + (call (mem:QI (match_operand:SI 1 "register_operand" "r"))
  8499. + (match_operand 2 "" "")))
  8500. + (return)
  8501. + (use (match_operand 3 "" ""))]
  8502. + ""
  8503. + "jmp\\t%1"
  8504. +)
  8505. +
  8506. +
  8507. +
  8508. +
  8509. +(define_expand "tablejump"
  8510. + [(parallel [(set (pc) (match_operand 0 "register_operand" "r"))
  8511. + (use (label_ref (match_operand 1 "" "")))])]
  8512. + ""
  8513. + ""
  8514. +)
  8515. +
  8516. +(define_insn "*tablejump"
  8517. + [(set (pc)
  8518. + (match_operand:SI 0 "register_operand" "r"))
  8519. + (use (label_ref (match_operand 1 "" "")))]
  8520. + ""
  8521. + "jmp\\t%0"
  8522. + [(set_attr "type" "control")])
  8523. +
  8524. +
  8525. +
  8526. +;*****************************************************************************
  8527. +;*
  8528. +;* Comparisons
  8529. +;*
  8530. +;*****************************************************************************
  8531. +;; Flow here is rather complex (based on MIPS):
  8532. +;;
  8533. +;; 1) The cmp{si,di,sf,df} routine is called. It deposits the
  8534. +;; arguments into the branch_cmp array, and the type into
  8535. +;; branch_type. No RTL is generated.
  8536. +;;
  8537. +;; 2) The appropriate branch define_expand is called, which then
  8538. +;; creates the appropriate RTL for the comparison and branch.
  8539. +;; Different CC modes are used, based on what type of branch is
  8540. +;; done, so that we can constrain things appropriately. There
  8541. +;; are assumptions in the rest of GCC that break if we fold the
  8542. +;; operands into the branchs for integer operations, and use cc0
  8543. +;; for floating point, so we use the fp status register instead.
  8544. +;; If needed, an appropriate temporary is created to hold the
  8545. +;; of the integer compare.
  8546. +
  8547. +(define_expand "cmpsi"
  8548. + [(set (cc0)
  8549. + (compare:CC (match_operand:SI 0 "register_operand" "")
  8550. + (match_operand:SI 1 "arith_operand" "")))]
  8551. + ""
  8552. +{
  8553. + branch_cmp[0] = operands[0];
  8554. + branch_cmp[1] = operands[1];
  8555. + branch_type = CMP_SI;
  8556. + DONE;
  8557. +})
  8558. +
  8559. +(define_expand "tstsi"
  8560. + [(set (cc0)
  8561. + (match_operand:SI 0 "register_operand" ""))]
  8562. + ""
  8563. +{
  8564. + branch_cmp[0] = operands[0];
  8565. + branch_cmp[1] = const0_rtx;
  8566. + branch_type = CMP_SI;
  8567. + DONE;
  8568. +})
  8569. +
  8570. +
  8571. +;*****************************************************************************
  8572. +;*
  8573. +;* setting a register from a comparison
  8574. +;*
  8575. +;*****************************************************************************
  8576. +
  8577. +(define_expand "seq"
  8578. + [(set (match_operand:SI 0 "register_operand" "=r")
  8579. + (eq:SI (match_dup 1)
  8580. + (match_dup 2)))]
  8581. + ""
  8582. +{
  8583. + if (branch_type != CMP_SI)
  8584. + FAIL;
  8585. +
  8586. + /* set up operands from compare. */
  8587. + operands[1] = branch_cmp[0];
  8588. + operands[2] = branch_cmp[1];
  8589. +
  8590. + gen_int_relational (EQ, operands[0], operands[1], operands[2], NULL_RTX);
  8591. + DONE;
  8592. +})
  8593. +
  8594. +
  8595. +(define_insn "*seq"
  8596. + [(set (match_operand:SI 0 "register_operand" "=r")
  8597. + (eq:SI (match_operand:SI 1 "reg_or_0_operand" "%rM")
  8598. + (match_operand:SI 2 "arith_operand" "rI")))]
  8599. + ""
  8600. + "cmpeq%i2\\t%0, %z1, %z2"
  8601. + [(set_attr "type" "alu")])
  8602. +
  8603. +
  8604. +(define_expand "sne"
  8605. + [(set (match_operand:SI 0 "register_operand" "=r")
  8606. + (ne:SI (match_dup 1)
  8607. + (match_dup 2)))]
  8608. + ""
  8609. +{
  8610. + if (branch_type != CMP_SI)
  8611. + FAIL;
  8612. +
  8613. + /* set up operands from compare. */
  8614. + operands[1] = branch_cmp[0];
  8615. + operands[2] = branch_cmp[1];
  8616. +
  8617. + gen_int_relational (NE, operands[0], operands[1], operands[2], NULL_RTX);
  8618. + DONE;
  8619. +})
  8620. +
  8621. +
  8622. +(define_insn "*sne"
  8623. + [(set (match_operand:SI 0 "register_operand" "=r")
  8624. + (ne:SI (match_operand:SI 1 "reg_or_0_operand" "%rM")
  8625. + (match_operand:SI 2 "arith_operand" "rI")))]
  8626. + ""
  8627. + "cmpne%i2\\t%0, %z1, %z2"
  8628. + [(set_attr "type" "alu")])
  8629. +
  8630. +
  8631. +(define_expand "sgt"
  8632. + [(set (match_operand:SI 0 "register_operand" "=r")
  8633. + (gt:SI (match_dup 1)
  8634. + (match_dup 2)))]
  8635. + ""
  8636. +{
  8637. + if (branch_type != CMP_SI)
  8638. + FAIL;
  8639. +
  8640. + /* set up operands from compare. */
  8641. + operands[1] = branch_cmp[0];
  8642. + operands[2] = branch_cmp[1];
  8643. +
  8644. + gen_int_relational (GT, operands[0], operands[1], operands[2], NULL_RTX);
  8645. + DONE;
  8646. +})
  8647. +
  8648. +
  8649. +(define_insn "*sgt"
  8650. + [(set (match_operand:SI 0 "register_operand" "=r")
  8651. + (gt:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8652. + (match_operand:SI 2 "reg_or_0_operand" "rM")))]
  8653. + ""
  8654. + "cmplt\\t%0, %z2, %z1"
  8655. + [(set_attr "type" "alu")])
  8656. +
  8657. +
  8658. +(define_expand "sge"
  8659. + [(set (match_operand:SI 0 "register_operand" "=r")
  8660. + (ge:SI (match_dup 1)
  8661. + (match_dup 2)))]
  8662. + ""
  8663. +{
  8664. + if (branch_type != CMP_SI)
  8665. + FAIL;
  8666. +
  8667. + /* set up operands from compare. */
  8668. + operands[1] = branch_cmp[0];
  8669. + operands[2] = branch_cmp[1];
  8670. +
  8671. + gen_int_relational (GE, operands[0], operands[1], operands[2], NULL_RTX);
  8672. + DONE;
  8673. +})
  8674. +
  8675. +
  8676. +(define_insn "*sge"
  8677. + [(set (match_operand:SI 0 "register_operand" "=r")
  8678. + (ge:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8679. + (match_operand:SI 2 "arith_operand" "rI")))]
  8680. + ""
  8681. + "cmpge%i2\\t%0, %z1, %z2"
  8682. + [(set_attr "type" "alu")])
  8683. +
  8684. +(define_expand "sle"
  8685. + [(set (match_operand:SI 0 "register_operand" "=r")
  8686. + (le:SI (match_dup 1)
  8687. + (match_dup 2)))]
  8688. + ""
  8689. +{
  8690. + if (branch_type != CMP_SI)
  8691. + FAIL;
  8692. +
  8693. + /* set up operands from compare. */
  8694. + operands[1] = branch_cmp[0];
  8695. + operands[2] = branch_cmp[1];
  8696. +
  8697. + gen_int_relational (LE, operands[0], operands[1], operands[2], NULL_RTX);
  8698. + DONE;
  8699. +})
  8700. +
  8701. +
  8702. +(define_insn "*sle"
  8703. + [(set (match_operand:SI 0 "register_operand" "=r")
  8704. + (le:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8705. + (match_operand:SI 2 "reg_or_0_operand" "rM")))]
  8706. + ""
  8707. + "cmpge\\t%0, %z2, %z1"
  8708. + [(set_attr "type" "alu")])
  8709. +
  8710. +
  8711. +(define_expand "slt"
  8712. + [(set (match_operand:SI 0 "register_operand" "=r")
  8713. + (lt:SI (match_dup 1)
  8714. + (match_dup 2)))]
  8715. + ""
  8716. +{
  8717. + if (branch_type != CMP_SI)
  8718. + FAIL;
  8719. +
  8720. + /* set up operands from compare. */
  8721. + operands[1] = branch_cmp[0];
  8722. + operands[2] = branch_cmp[1];
  8723. +
  8724. + gen_int_relational (LT, operands[0], operands[1], operands[2], NULL_RTX);
  8725. + DONE;
  8726. +})
  8727. +
  8728. +
  8729. +(define_insn "*slt"
  8730. + [(set (match_operand:SI 0 "register_operand" "=r")
  8731. + (lt:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8732. + (match_operand:SI 2 "arith_operand" "rI")))]
  8733. + ""
  8734. + "cmplt%i2\\t%0, %z1, %z2"
  8735. + [(set_attr "type" "alu")])
  8736. +
  8737. +
  8738. +(define_expand "sgtu"
  8739. + [(set (match_operand:SI 0 "register_operand" "=r")
  8740. + (gtu:SI (match_dup 1)
  8741. + (match_dup 2)))]
  8742. + ""
  8743. +{
  8744. + if (branch_type != CMP_SI)
  8745. + FAIL;
  8746. +
  8747. + /* set up operands from compare. */
  8748. + operands[1] = branch_cmp[0];
  8749. + operands[2] = branch_cmp[1];
  8750. +
  8751. + gen_int_relational (GTU, operands[0], operands[1], operands[2], NULL_RTX);
  8752. + DONE;
  8753. +})
  8754. +
  8755. +
  8756. +(define_insn "*sgtu"
  8757. + [(set (match_operand:SI 0 "register_operand" "=r")
  8758. + (gtu:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8759. + (match_operand:SI 2 "reg_or_0_operand" "rM")))]
  8760. + ""
  8761. + "cmpltu\\t%0, %z2, %z1"
  8762. + [(set_attr "type" "alu")])
  8763. +
  8764. +
  8765. +(define_expand "sgeu"
  8766. + [(set (match_operand:SI 0 "register_operand" "=r")
  8767. + (geu:SI (match_dup 1)
  8768. + (match_dup 2)))]
  8769. + ""
  8770. +{
  8771. + if (branch_type != CMP_SI)
  8772. + FAIL;
  8773. +
  8774. + /* set up operands from compare. */
  8775. + operands[1] = branch_cmp[0];
  8776. + operands[2] = branch_cmp[1];
  8777. +
  8778. + gen_int_relational (GEU, operands[0], operands[1], operands[2], NULL_RTX);
  8779. + DONE;
  8780. +})
  8781. +
  8782. +
  8783. +(define_insn "*sgeu"
  8784. + [(set (match_operand:SI 0 "register_operand" "=r")
  8785. + (geu:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8786. + (match_operand:SI 2 "uns_arith_operand" "rJ")))]
  8787. + ""
  8788. + "cmpgeu%i2\\t%0, %z1, %z2"
  8789. + [(set_attr "type" "alu")])
  8790. +
  8791. +(define_expand "sleu"
  8792. + [(set (match_operand:SI 0 "register_operand" "=r")
  8793. + (leu:SI (match_dup 1)
  8794. + (match_dup 2)))]
  8795. + ""
  8796. +{
  8797. + if (branch_type != CMP_SI)
  8798. + FAIL;
  8799. +
  8800. + /* set up operands from compare. */
  8801. + operands[1] = branch_cmp[0];
  8802. + operands[2] = branch_cmp[1];
  8803. +
  8804. + gen_int_relational (LEU, operands[0], operands[1], operands[2], NULL_RTX);
  8805. + DONE;
  8806. +})
  8807. +
  8808. +
  8809. +(define_insn "*sleu"
  8810. + [(set (match_operand:SI 0 "register_operand" "=r")
  8811. + (leu:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8812. + (match_operand:SI 2 "reg_or_0_operand" "rM")))]
  8813. + ""
  8814. + "cmpgeu\\t%0, %z2, %z1"
  8815. + [(set_attr "type" "alu")])
  8816. +
  8817. +
  8818. +(define_expand "sltu"
  8819. + [(set (match_operand:SI 0 "register_operand" "=r")
  8820. + (ltu:SI (match_dup 1)
  8821. + (match_dup 2)))]
  8822. + ""
  8823. +{
  8824. + if (branch_type != CMP_SI)
  8825. + FAIL;
  8826. +
  8827. + /* set up operands from compare. */
  8828. + operands[1] = branch_cmp[0];
  8829. + operands[2] = branch_cmp[1];
  8830. +
  8831. + gen_int_relational (LTU, operands[0], operands[1], operands[2], NULL_RTX);
  8832. + DONE;
  8833. +})
  8834. +
  8835. +
  8836. +(define_insn "*sltu"
  8837. + [(set (match_operand:SI 0 "register_operand" "=r")
  8838. + (ltu:SI (match_operand:SI 1 "reg_or_0_operand" "rM")
  8839. + (match_operand:SI 2 "uns_arith_operand" "rJ")))]
  8840. + ""
  8841. + "cmpltu%i2\\t%0, %z1, %z2"
  8842. + [(set_attr "type" "alu")])
  8843. +
  8844. +
  8845. +
  8846. +
  8847. +;*****************************************************************************
  8848. +;*
  8849. +;* branches
  8850. +;*
  8851. +;*****************************************************************************
  8852. +
  8853. +(define_insn "*cbranch"
  8854. + [(set (pc)
  8855. + (if_then_else
  8856. + (match_operator:SI 0 "comparison_operator"
  8857. + [(match_operand:SI 2 "reg_or_0_operand" "rM")
  8858. + (match_operand:SI 3 "reg_or_0_operand" "rM")])
  8859. + (label_ref (match_operand 1 "" ""))
  8860. + (pc)))]
  8861. + ""
  8862. + "b%0\\t%z2, %z3, %l1"
  8863. + [(set_attr "type" "control")])
  8864. +
  8865. +
  8866. +(define_expand "beq"
  8867. + [(set (pc)
  8868. + (if_then_else (eq:CC (cc0)
  8869. + (const_int 0))
  8870. + (label_ref (match_operand 0 "" ""))
  8871. + (pc)))]
  8872. + ""
  8873. +{
  8874. + gen_int_relational (EQ, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8875. + DONE;
  8876. +})
  8877. +
  8878. +
  8879. +(define_expand "bne"
  8880. + [(set (pc)
  8881. + (if_then_else (ne:CC (cc0)
  8882. + (const_int 0))
  8883. + (label_ref (match_operand 0 "" ""))
  8884. + (pc)))]
  8885. + ""
  8886. +{
  8887. + gen_int_relational (NE, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8888. + DONE;
  8889. +})
  8890. +
  8891. +
  8892. +(define_expand "bgt"
  8893. + [(set (pc)
  8894. + (if_then_else (gt:CC (cc0)
  8895. + (const_int 0))
  8896. + (label_ref (match_operand 0 "" ""))
  8897. + (pc)))]
  8898. + ""
  8899. +{
  8900. + gen_int_relational (GT, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8901. + DONE;
  8902. +})
  8903. +
  8904. +(define_expand "bge"
  8905. + [(set (pc)
  8906. + (if_then_else (ge:CC (cc0)
  8907. + (const_int 0))
  8908. + (label_ref (match_operand 0 "" ""))
  8909. + (pc)))]
  8910. + ""
  8911. +{
  8912. + gen_int_relational (GE, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8913. + DONE;
  8914. +})
  8915. +
  8916. +(define_expand "ble"
  8917. + [(set (pc)
  8918. + (if_then_else (le:CC (cc0)
  8919. + (const_int 0))
  8920. + (label_ref (match_operand 0 "" ""))
  8921. + (pc)))]
  8922. + ""
  8923. +{
  8924. + gen_int_relational (LE, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8925. + DONE;
  8926. +})
  8927. +
  8928. +(define_expand "blt"
  8929. + [(set (pc)
  8930. + (if_then_else (lt:CC (cc0)
  8931. + (const_int 0))
  8932. + (label_ref (match_operand 0 "" ""))
  8933. + (pc)))]
  8934. + ""
  8935. +{
  8936. + gen_int_relational (LT, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8937. + DONE;
  8938. +})
  8939. +
  8940. +
  8941. +(define_expand "bgtu"
  8942. + [(set (pc)
  8943. + (if_then_else (gtu:CC (cc0)
  8944. + (const_int 0))
  8945. + (label_ref (match_operand 0 "" ""))
  8946. + (pc)))]
  8947. + ""
  8948. +{
  8949. + gen_int_relational (GTU, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8950. + DONE;
  8951. +})
  8952. +
  8953. +(define_expand "bgeu"
  8954. + [(set (pc)
  8955. + (if_then_else (geu:CC (cc0)
  8956. + (const_int 0))
  8957. + (label_ref (match_operand 0 "" ""))
  8958. + (pc)))]
  8959. + ""
  8960. +{
  8961. + gen_int_relational (GEU, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8962. + DONE;
  8963. +})
  8964. +
  8965. +(define_expand "bleu"
  8966. + [(set (pc)
  8967. + (if_then_else (leu:CC (cc0)
  8968. + (const_int 0))
  8969. + (label_ref (match_operand 0 "" ""))
  8970. + (pc)))]
  8971. + ""
  8972. +{
  8973. + gen_int_relational (LEU, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8974. + DONE;
  8975. +})
  8976. +
  8977. +(define_expand "bltu"
  8978. + [(set (pc)
  8979. + (if_then_else (ltu:CC (cc0)
  8980. + (const_int 0))
  8981. + (label_ref (match_operand 0 "" ""))
  8982. + (pc)))]
  8983. + ""
  8984. +{
  8985. + gen_int_relational (LTU, NULL_RTX, branch_cmp[0], branch_cmp[1], operands[0]);
  8986. + DONE;
  8987. +})
  8988. +
  8989. +
  8990. +;*****************************************************************************
  8991. +;*
  8992. +;* String and Block Operations
  8993. +;*
  8994. +;*****************************************************************************
  8995. +
  8996. +; ??? This is all really a hack to get Dhrystone to work as fast as possible
  8997. +; things to be fixed:
  8998. +; * let the compiler core handle all of this, for that to work the extra
  8999. +; aliasing needs to be addressed.
  9000. +; * we use three temporary registers for loading and storing to ensure no
  9001. +; ld use stalls, this is excessive, because after the first ld/st only
  9002. +; two are needed. Only two would be needed all the way through if
  9003. +; we could schedule with other code. Consider:
  9004. +; 1 ld $1, 0($src)
  9005. +; 2 ld $2, 4($src)
  9006. +; 3 ld $3, 8($src)
  9007. +; 4 st $1, 0($dest)
  9008. +; 5 ld $1, 12($src)
  9009. +; 6 st $2, 4($src)
  9010. +; 7 etc.
  9011. +; The first store has to wait until 4. If it does not there will be one
  9012. +; cycle of stalling. However, if any other instruction could be placed
  9013. +; between 1 and 4, $3 would not be needed.
  9014. +; * In small we probably don't want to ever do this ourself because there
  9015. +; is no ld use stall.
  9016. +
  9017. +(define_expand "movstrsi"
  9018. + [(parallel [(set (match_operand:BLK 0 "general_operand" "")
  9019. + (match_operand:BLK 1 "general_operand" ""))
  9020. + (use (match_operand:SI 2 "const_int_operand" ""))
  9021. + (use (match_operand:SI 3 "const_int_operand" ""))
  9022. + (clobber (match_scratch:SI 4 "=&r"))
  9023. + (clobber (match_scratch:SI 5 "=&r"))
  9024. + (clobber (match_scratch:SI 6 "=&r"))])]
  9025. + "TARGET_INLINE_MEMCPY"
  9026. +{
  9027. + rtx ld_addr_reg, st_addr_reg;
  9028. +
  9029. + /* If the predicate for op2 fails in expr.c:emit_block_move_via_movstr
  9030. + it trys to copy to a register, but does not re-try the predicate.
  9031. + ??? Intead of fixing expr.c, I fix it here. */
  9032. + if (!const_int_operand (operands[2], SImode))
  9033. + FAIL;
  9034. +
  9035. + /* ??? there are some magic numbers which need to be sorted out here.
  9036. + the basis for them is not increasing code size hugely or going
  9037. + out of range of offset addressing */
  9038. + if (INTVAL (operands[3]) < 4)
  9039. + FAIL;
  9040. + if (!optimize
  9041. + || (optimize_size && INTVAL (operands[2]) > 12)
  9042. + || (optimize < 3 && INTVAL (operands[2]) > 100)
  9043. + || INTVAL (operands[2]) > 200)
  9044. + FAIL;
  9045. +
  9046. + st_addr_reg
  9047. + = replace_equiv_address (operands[0],
  9048. + copy_to_mode_reg (Pmode, XEXP (operands[0], 0)));
  9049. + ld_addr_reg
  9050. + = replace_equiv_address (operands[1],
  9051. + copy_to_mode_reg (Pmode, XEXP (operands[1], 0)));
  9052. + emit_insn (gen_movstrsi_internal (st_addr_reg, ld_addr_reg,
  9053. + operands[2], operands[3]));
  9054. +
  9055. + DONE;
  9056. +})
  9057. +
  9058. +
  9059. +(define_insn "movstrsi_internal"
  9060. + [(set (match_operand:BLK 0 "memory_operand" "=o")
  9061. + (match_operand:BLK 1 "memory_operand" "o"))
  9062. + (use (match_operand:SI 2 "const_int_operand" "i"))
  9063. + (use (match_operand:SI 3 "const_int_operand" "i"))
  9064. + (clobber (match_scratch:SI 4 "=&r"))
  9065. + (clobber (match_scratch:SI 5 "=&r"))
  9066. + (clobber (match_scratch:SI 6 "=&r"))]
  9067. + "TARGET_INLINE_MEMCPY"
  9068. +{
  9069. + int ld_offset = INTVAL (operands[2]);
  9070. + int ld_len = INTVAL (operands[2]);
  9071. + int ld_reg = 0;
  9072. + rtx ld_addr_reg = XEXP (operands[1], 0);
  9073. + int st_offset = INTVAL (operands[2]);
  9074. + int st_len = INTVAL (operands[2]);
  9075. + int st_reg = 0;
  9076. + rtx st_addr_reg = XEXP (operands[0], 0);
  9077. + int delay_count = 0;
  9078. +
  9079. + /* ops[0] is the address used by the insn
  9080. + ops[1] is the register being loaded or stored */
  9081. + rtx ops[2];
  9082. +
  9083. + if (INTVAL (operands[3]) < 4)
  9084. + abort ();
  9085. +
  9086. + while (ld_offset >= 4)
  9087. + {
  9088. + /* if the load use delay has been met, I can start
  9089. + storing */
  9090. + if (delay_count >= 3)
  9091. + {
  9092. + ops[0] = gen_rtx (MEM, SImode,
  9093. + plus_constant (st_addr_reg, st_len - st_offset));
  9094. + ops[1] = operands[st_reg + 4];
  9095. + output_asm_insn ("stw\t%1, %0", ops);
  9096. +
  9097. + st_reg = (st_reg + 1) % 3;
  9098. + st_offset -= 4;
  9099. + }
  9100. +
  9101. + ops[0] = gen_rtx (MEM, SImode,
  9102. + plus_constant (ld_addr_reg, ld_len - ld_offset));
  9103. + ops[1] = operands[ld_reg + 4];
  9104. + output_asm_insn ("ldw\t%1, %0", ops);
  9105. +
  9106. + ld_reg = (ld_reg + 1) % 3;
  9107. + ld_offset -= 4;
  9108. + delay_count++;
  9109. + }
  9110. +
  9111. + if (ld_offset >= 2)
  9112. + {
  9113. + /* if the load use delay has been met, I can start
  9114. + storing */
  9115. + if (delay_count >= 3)
  9116. + {
  9117. + ops[0] = gen_rtx (MEM, SImode,
  9118. + plus_constant (st_addr_reg, st_len - st_offset));
  9119. + ops[1] = operands[st_reg + 4];
  9120. + output_asm_insn ("stw\t%1, %0", ops);
  9121. +
  9122. + st_reg = (st_reg + 1) % 3;
  9123. + st_offset -= 4;
  9124. + }
  9125. +
  9126. + ops[0] = gen_rtx (MEM, HImode,
  9127. + plus_constant (ld_addr_reg, ld_len - ld_offset));
  9128. + ops[1] = operands[ld_reg + 4];
  9129. + output_asm_insn ("ldh\t%1, %0", ops);
  9130. +
  9131. + ld_reg = (ld_reg + 1) % 3;
  9132. + ld_offset -= 2;
  9133. + delay_count++;
  9134. + }
  9135. +
  9136. + if (ld_offset >= 1)
  9137. + {
  9138. + /* if the load use delay has been met, I can start
  9139. + storing */
  9140. + if (delay_count >= 3)
  9141. + {
  9142. + ops[0] = gen_rtx (MEM, SImode,
  9143. + plus_constant (st_addr_reg, st_len - st_offset));
  9144. + ops[1] = operands[st_reg + 4];
  9145. + output_asm_insn ("stw\t%1, %0", ops);
  9146. +
  9147. + st_reg = (st_reg + 1) % 3;
  9148. + st_offset -= 4;
  9149. + }
  9150. +
  9151. + ops[0] = gen_rtx (MEM, QImode,
  9152. + plus_constant (ld_addr_reg, ld_len - ld_offset));
  9153. + ops[1] = operands[ld_reg + 4];
  9154. + output_asm_insn ("ldb\t%1, %0", ops);
  9155. +
  9156. + ld_reg = (ld_reg + 1) % 3;
  9157. + ld_offset -= 1;
  9158. + delay_count++;
  9159. + }
  9160. +
  9161. + while (st_offset >= 4)
  9162. + {
  9163. + ops[0] = gen_rtx (MEM, SImode,
  9164. + plus_constant (st_addr_reg, st_len - st_offset));
  9165. + ops[1] = operands[st_reg + 4];
  9166. + output_asm_insn ("stw\t%1, %0", ops);
  9167. +
  9168. + st_reg = (st_reg + 1) % 3;
  9169. + st_offset -= 4;
  9170. + }
  9171. +
  9172. + while (st_offset >= 2)
  9173. + {
  9174. + ops[0] = gen_rtx (MEM, HImode,
  9175. + plus_constant (st_addr_reg, st_len - st_offset));
  9176. + ops[1] = operands[st_reg + 4];
  9177. + output_asm_insn ("sth\t%1, %0", ops);
  9178. +
  9179. + st_reg = (st_reg + 1) % 3;
  9180. + st_offset -= 2;
  9181. + }
  9182. +
  9183. + while (st_offset >= 1)
  9184. + {
  9185. + ops[0] = gen_rtx (MEM, QImode,
  9186. + plus_constant (st_addr_reg, st_len - st_offset));
  9187. + ops[1] = operands[st_reg + 4];
  9188. + output_asm_insn ("stb\t%1, %0", ops);
  9189. +
  9190. + st_reg = (st_reg + 1) % 3;
  9191. + st_offset -= 1;
  9192. + }
  9193. +
  9194. + return "";
  9195. +}
  9196. +; ??? lengths are not being used yet, but I will probably forget
  9197. +; to update this once I am using lengths, so set it to something
  9198. +; definetely big enough to cover it. 400 allows for 200 bytes
  9199. +; of motion.
  9200. + [(set_attr "length" "400")])
  9201. +
  9202. +
  9203. +
  9204. +;*****************************************************************************
  9205. +;*
  9206. +;* Custom instructions
  9207. +;*
  9208. +;*****************************************************************************
  9209. +
  9210. +(define_constants [
  9211. + (CUSTOM_N 100)
  9212. + (CUSTOM_NI 101)
  9213. + (CUSTOM_NF 102)
  9214. + (CUSTOM_NP 103)
  9215. + (CUSTOM_NII 104)
  9216. + (CUSTOM_NIF 105)
  9217. + (CUSTOM_NIP 106)
  9218. + (CUSTOM_NFI 107)
  9219. + (CUSTOM_NFF 108)
  9220. + (CUSTOM_NFP 109)
  9221. + (CUSTOM_NPI 110)
  9222. + (CUSTOM_NPF 111)
  9223. + (CUSTOM_NPP 112)
  9224. + (CUSTOM_IN 113)
  9225. + (CUSTOM_INI 114)
  9226. + (CUSTOM_INF 115)
  9227. + (CUSTOM_INP 116)
  9228. + (CUSTOM_INII 117)
  9229. + (CUSTOM_INIF 118)
  9230. + (CUSTOM_INIP 119)
  9231. + (CUSTOM_INFI 120)
  9232. + (CUSTOM_INFF 121)
  9233. + (CUSTOM_INFP 122)
  9234. + (CUSTOM_INPI 123)
  9235. + (CUSTOM_INPF 124)
  9236. + (CUSTOM_INPP 125)
  9237. + (CUSTOM_FN 126)
  9238. + (CUSTOM_FNI 127)
  9239. + (CUSTOM_FNF 128)
  9240. + (CUSTOM_FNP 129)
  9241. + (CUSTOM_FNII 130)
  9242. + (CUSTOM_FNIF 131)
  9243. + (CUSTOM_FNIP 132)
  9244. + (CUSTOM_FNFI 133)
  9245. + (CUSTOM_FNFF 134)
  9246. + (CUSTOM_FNFP 135)
  9247. + (CUSTOM_FNPI 136)
  9248. + (CUSTOM_FNPF 137)
  9249. + (CUSTOM_FNPP 138)
  9250. + (CUSTOM_PN 139)
  9251. + (CUSTOM_PNI 140)
  9252. + (CUSTOM_PNF 141)
  9253. + (CUSTOM_PNP 142)
  9254. + (CUSTOM_PNII 143)
  9255. + (CUSTOM_PNIF 144)
  9256. + (CUSTOM_PNIP 145)
  9257. + (CUSTOM_PNFI 146)
  9258. + (CUSTOM_PNFF 147)
  9259. + (CUSTOM_PNFP 148)
  9260. + (CUSTOM_PNPI 149)
  9261. + (CUSTOM_PNPF 150)
  9262. + (CUSTOM_PNPP 151)
  9263. +])
  9264. +
  9265. +
  9266. +(define_insn "custom_n"
  9267. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")] CUSTOM_N)]
  9268. + ""
  9269. + "custom\\t%0, zero, zero, zero"
  9270. + [(set_attr "type" "custom")])
  9271. +
  9272. +(define_insn "custom_ni"
  9273. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9274. + (match_operand:SI 1 "register_operand" "r")] CUSTOM_NI)]
  9275. + ""
  9276. + "custom\\t%0, zero, %1, zero"
  9277. + [(set_attr "type" "custom")])
  9278. +
  9279. +(define_insn "custom_nf"
  9280. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9281. + (match_operand:SF 1 "register_operand" "r")] CUSTOM_NF)]
  9282. + ""
  9283. + "custom\\t%0, zero, %1, zero"
  9284. + [(set_attr "type" "custom")])
  9285. +
  9286. +(define_insn "custom_np"
  9287. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9288. + (match_operand:SI 1 "register_operand" "r")] CUSTOM_NP)]
  9289. + ""
  9290. + "custom\\t%0, zero, %1, zero"
  9291. + [(set_attr "type" "custom")])
  9292. +
  9293. +(define_insn "custom_nii"
  9294. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9295. + (match_operand:SI 1 "register_operand" "r")
  9296. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_NII)]
  9297. + ""
  9298. + "custom\\t%0, zero, %1, %2"
  9299. + [(set_attr "type" "custom")])
  9300. +
  9301. +(define_insn "custom_nif"
  9302. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9303. + (match_operand:SI 1 "register_operand" "r")
  9304. + (match_operand:SF 2 "register_operand" "r")] CUSTOM_NIF)]
  9305. + ""
  9306. + "custom\\t%0, zero, %1, %2"
  9307. + [(set_attr "type" "custom")])
  9308. +
  9309. +(define_insn "custom_nip"
  9310. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9311. + (match_operand:SI 1 "register_operand" "r")
  9312. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_NIP)]
  9313. + ""
  9314. + "custom\\t%0, zero, %1, %2"
  9315. + [(set_attr "type" "custom")])
  9316. +
  9317. +(define_insn "custom_nfi"
  9318. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9319. + (match_operand:SF 1 "register_operand" "r")
  9320. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_NFI)]
  9321. + ""
  9322. + "custom\\t%0, zero, %1, %2"
  9323. + [(set_attr "type" "custom")])
  9324. +
  9325. +(define_insn "custom_nff"
  9326. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9327. + (match_operand:SF 1 "register_operand" "r")
  9328. + (match_operand:SF 2 "register_operand" "r")] CUSTOM_NFF)]
  9329. + ""
  9330. + "custom\\t%0, zero, %1, %2"
  9331. + [(set_attr "type" "custom")])
  9332. +
  9333. +(define_insn "custom_nfp"
  9334. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9335. + (match_operand:SF 1 "register_operand" "r")
  9336. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_NFP)]
  9337. + ""
  9338. + "custom\\t%0, zero, %1, %2"
  9339. + [(set_attr "type" "custom")])
  9340. +
  9341. +(define_insn "custom_npi"
  9342. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9343. + (match_operand:SI 1 "register_operand" "r")
  9344. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_NPI)]
  9345. + ""
  9346. + "custom\\t%0, zero, %1, %2"
  9347. + [(set_attr "type" "custom")])
  9348. +
  9349. +(define_insn "custom_npf"
  9350. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9351. + (match_operand:SI 1 "register_operand" "r")
  9352. + (match_operand:SF 2 "register_operand" "r")] CUSTOM_NPF)]
  9353. + ""
  9354. + "custom\\t%0, zero, %1, %2"
  9355. + [(set_attr "type" "custom")])
  9356. +
  9357. +(define_insn "custom_npp"
  9358. + [(unspec_volatile [(match_operand:SI 0 "custom_insn_opcode" "N")
  9359. + (match_operand:SI 1 "register_operand" "r")
  9360. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_NPP)]
  9361. + ""
  9362. + "custom\\t%0, zero, %1, %2"
  9363. + [(set_attr "type" "custom")])
  9364. +
  9365. +
  9366. +
  9367. +(define_insn "custom_in"
  9368. + [(set (match_operand:SI 0 "register_operand" "=r")
  9369. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")] CUSTOM_IN))]
  9370. + ""
  9371. + "custom\\t%1, %0, zero, zero"
  9372. + [(set_attr "type" "custom")])
  9373. +
  9374. +(define_insn "custom_ini"
  9375. + [(set (match_operand:SI 0 "register_operand" "=r")
  9376. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9377. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_INI))]
  9378. + ""
  9379. + "custom\\t%1, %0, %2, zero"
  9380. + [(set_attr "type" "custom")])
  9381. +
  9382. +(define_insn "custom_inf"
  9383. + [(set (match_operand:SI 0 "register_operand" "=r")
  9384. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9385. + (match_operand:SF 2 "register_operand" "r")] CUSTOM_INF))]
  9386. + ""
  9387. + "custom\\t%1, %0, %2, zero"
  9388. + [(set_attr "type" "custom")])
  9389. +
  9390. +(define_insn "custom_inp"
  9391. + [(set (match_operand:SI 0 "register_operand" "=r")
  9392. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9393. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_INP))]
  9394. + ""
  9395. + "custom\\t%1, %0, %2, zero"
  9396. + [(set_attr "type" "custom")])
  9397. +
  9398. +(define_insn "custom_inii"
  9399. + [(set (match_operand:SI 0 "register_operand" "=r")
  9400. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9401. + (match_operand:SI 2 "register_operand" "r")
  9402. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_INII))]
  9403. + ""
  9404. + "custom\\t%1, %0, %2, %3"
  9405. + [(set_attr "type" "custom")])
  9406. +
  9407. +(define_insn "custom_inif"
  9408. + [(set (match_operand:SI 0 "register_operand" "=r")
  9409. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9410. + (match_operand:SI 2 "register_operand" "r")
  9411. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_INIF))]
  9412. + ""
  9413. + "custom\\t%1, %0, %2, %3"
  9414. + [(set_attr "type" "custom")])
  9415. +
  9416. +(define_insn "custom_inip"
  9417. + [(set (match_operand:SI 0 "register_operand" "=r")
  9418. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9419. + (match_operand:SI 2 "register_operand" "r")
  9420. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_INIP))]
  9421. + ""
  9422. + "custom\\t%1, %0, %2, %3"
  9423. + [(set_attr "type" "custom")])
  9424. +
  9425. +(define_insn "custom_infi"
  9426. + [(set (match_operand:SI 0 "register_operand" "=r")
  9427. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9428. + (match_operand:SF 2 "register_operand" "r")
  9429. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_INFI))]
  9430. + ""
  9431. + "custom\\t%1, %0, %2, %3"
  9432. + [(set_attr "type" "custom")])
  9433. +
  9434. +(define_insn "custom_inff"
  9435. + [(set (match_operand:SI 0 "register_operand" "=r")
  9436. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9437. + (match_operand:SF 2 "register_operand" "r")
  9438. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_INFF))]
  9439. + ""
  9440. + "custom\\t%1, %0, %2, %3"
  9441. + [(set_attr "type" "custom")])
  9442. +
  9443. +(define_insn "custom_infp"
  9444. + [(set (match_operand:SI 0 "register_operand" "=r")
  9445. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9446. + (match_operand:SF 2 "register_operand" "r")
  9447. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_INFP))]
  9448. + ""
  9449. + "custom\\t%1, %0, %2, %3"
  9450. + [(set_attr "type" "custom")])
  9451. +
  9452. +(define_insn "custom_inpi"
  9453. + [(set (match_operand:SI 0 "register_operand" "=r")
  9454. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9455. + (match_operand:SI 2 "register_operand" "r")
  9456. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_INPI))]
  9457. + ""
  9458. + "custom\\t%1, %0, %2, %3"
  9459. + [(set_attr "type" "custom")])
  9460. +
  9461. +(define_insn "custom_inpf"
  9462. + [(set (match_operand:SI 0 "register_operand" "=r")
  9463. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9464. + (match_operand:SI 2 "register_operand" "r")
  9465. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_INPF))]
  9466. + ""
  9467. + "custom\\t%1, %0, %2, %3"
  9468. + [(set_attr "type" "custom")])
  9469. +
  9470. +(define_insn "custom_inpp"
  9471. + [(set (match_operand:SI 0 "register_operand" "=r")
  9472. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9473. + (match_operand:SI 2 "register_operand" "r")
  9474. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_INPP))]
  9475. + ""
  9476. + "custom\\t%1, %0, %2, %3"
  9477. + [(set_attr "type" "custom")])
  9478. +
  9479. +
  9480. +
  9481. +
  9482. +
  9483. +(define_insn "custom_fn"
  9484. + [(set (match_operand:SF 0 "register_operand" "=r")
  9485. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")] CUSTOM_FN))]
  9486. + ""
  9487. + "custom\\t%1, %0, zero, zero"
  9488. + [(set_attr "type" "custom")])
  9489. +
  9490. +(define_insn "custom_fni"
  9491. + [(set (match_operand:SF 0 "register_operand" "=r")
  9492. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9493. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_FNI))]
  9494. + ""
  9495. + "custom\\t%1, %0, %2, zero"
  9496. + [(set_attr "type" "custom")])
  9497. +
  9498. +(define_insn "custom_fnf"
  9499. + [(set (match_operand:SF 0 "register_operand" "=r")
  9500. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9501. + (match_operand:SF 2 "register_operand" "r")] CUSTOM_FNF))]
  9502. + ""
  9503. + "custom\\t%1, %0, %2, zero"
  9504. + [(set_attr "type" "custom")])
  9505. +
  9506. +(define_insn "custom_fnp"
  9507. + [(set (match_operand:SF 0 "register_operand" "=r")
  9508. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9509. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_FNP))]
  9510. + ""
  9511. + "custom\\t%1, %0, %2, zero"
  9512. + [(set_attr "type" "custom")])
  9513. +
  9514. +(define_insn "custom_fnii"
  9515. + [(set (match_operand:SF 0 "register_operand" "=r")
  9516. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9517. + (match_operand:SI 2 "register_operand" "r")
  9518. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_FNII))]
  9519. + ""
  9520. + "custom\\t%1, %0, %2, %3"
  9521. + [(set_attr "type" "custom")])
  9522. +
  9523. +(define_insn "custom_fnif"
  9524. + [(set (match_operand:SF 0 "register_operand" "=r")
  9525. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9526. + (match_operand:SI 2 "register_operand" "r")
  9527. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_FNIF))]
  9528. + ""
  9529. + "custom\\t%1, %0, %2, %3"
  9530. + [(set_attr "type" "custom")])
  9531. +
  9532. +(define_insn "custom_fnip"
  9533. + [(set (match_operand:SF 0 "register_operand" "=r")
  9534. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9535. + (match_operand:SI 2 "register_operand" "r")
  9536. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_FNIP))]
  9537. + ""
  9538. + "custom\\t%1, %0, %2, %3"
  9539. + [(set_attr "type" "custom")])
  9540. +
  9541. +(define_insn "custom_fnfi"
  9542. + [(set (match_operand:SF 0 "register_operand" "=r")
  9543. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9544. + (match_operand:SF 2 "register_operand" "r")
  9545. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_FNFI))]
  9546. + ""
  9547. + "custom\\t%1, %0, %2, %3"
  9548. + [(set_attr "type" "custom")])
  9549. +
  9550. +(define_insn "custom_fnff"
  9551. + [(set (match_operand:SF 0 "register_operand" "=r")
  9552. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9553. + (match_operand:SF 2 "register_operand" "r")
  9554. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_FNFF))]
  9555. + ""
  9556. + "custom\\t%1, %0, %2, %3"
  9557. + [(set_attr "type" "custom")])
  9558. +
  9559. +(define_insn "custom_fnfp"
  9560. + [(set (match_operand:SF 0 "register_operand" "=r")
  9561. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9562. + (match_operand:SF 2 "register_operand" "r")
  9563. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_FNFP))]
  9564. + ""
  9565. + "custom\\t%1, %0, %2, %3"
  9566. + [(set_attr "type" "custom")])
  9567. +
  9568. +(define_insn "custom_fnpi"
  9569. + [(set (match_operand:SF 0 "register_operand" "=r")
  9570. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9571. + (match_operand:SI 2 "register_operand" "r")
  9572. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_FNPI))]
  9573. + ""
  9574. + "custom\\t%1, %0, %2, %3"
  9575. + [(set_attr "type" "custom")])
  9576. +
  9577. +(define_insn "custom_fnpf"
  9578. + [(set (match_operand:SF 0 "register_operand" "=r")
  9579. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9580. + (match_operand:SI 2 "register_operand" "r")
  9581. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_FNPF))]
  9582. + ""
  9583. + "custom\\t%1, %0, %2, %3"
  9584. + [(set_attr "type" "custom")])
  9585. +
  9586. +(define_insn "custom_fnpp"
  9587. + [(set (match_operand:SF 0 "register_operand" "=r")
  9588. + (unspec_volatile:SF [(match_operand:SI 1 "custom_insn_opcode" "N")
  9589. + (match_operand:SI 2 "register_operand" "r")
  9590. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_FNPP))]
  9591. + ""
  9592. + "custom\\t%1, %0, %2, %3"
  9593. + [(set_attr "type" "custom")])
  9594. +
  9595. +
  9596. +
  9597. +(define_insn "custom_pn"
  9598. + [(set (match_operand:SI 0 "register_operand" "=r")
  9599. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")] CUSTOM_PN))]
  9600. + ""
  9601. + "custom\\t%1, %0, zero, zero"
  9602. + [(set_attr "type" "custom")])
  9603. +
  9604. +(define_insn "custom_pni"
  9605. + [(set (match_operand:SI 0 "register_operand" "=r")
  9606. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9607. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_PNI))]
  9608. + ""
  9609. + "custom\\t%1, %0, %2, zero"
  9610. + [(set_attr "type" "custom")])
  9611. +
  9612. +(define_insn "custom_pnf"
  9613. + [(set (match_operand:SI 0 "register_operand" "=r")
  9614. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9615. + (match_operand:SF 2 "register_operand" "r")] CUSTOM_PNF))]
  9616. + ""
  9617. + "custom\\t%1, %0, %2, zero"
  9618. + [(set_attr "type" "custom")])
  9619. +
  9620. +(define_insn "custom_pnp"
  9621. + [(set (match_operand:SI 0 "register_operand" "=r")
  9622. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9623. + (match_operand:SI 2 "register_operand" "r")] CUSTOM_PNP))]
  9624. + ""
  9625. + "custom\\t%1, %0, %2, zero"
  9626. + [(set_attr "type" "custom")])
  9627. +
  9628. +(define_insn "custom_pnii"
  9629. + [(set (match_operand:SI 0 "register_operand" "=r")
  9630. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9631. + (match_operand:SI 2 "register_operand" "r")
  9632. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_PNII))]
  9633. + ""
  9634. + "custom\\t%1, %0, %2, %3"
  9635. + [(set_attr "type" "custom")])
  9636. +
  9637. +(define_insn "custom_pnif"
  9638. + [(set (match_operand:SI 0 "register_operand" "=r")
  9639. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9640. + (match_operand:SI 2 "register_operand" "r")
  9641. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_PNIF))]
  9642. + ""
  9643. + "custom\\t%1, %0, %2, %3"
  9644. + [(set_attr "type" "custom")])
  9645. +
  9646. +(define_insn "custom_pnip"
  9647. + [(set (match_operand:SI 0 "register_operand" "=r")
  9648. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9649. + (match_operand:SI 2 "register_operand" "r")
  9650. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_PNIP))]
  9651. + ""
  9652. + "custom\\t%1, %0, %2, %3"
  9653. + [(set_attr "type" "custom")])
  9654. +
  9655. +(define_insn "custom_pnfi"
  9656. + [(set (match_operand:SI 0 "register_operand" "=r")
  9657. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9658. + (match_operand:SF 2 "register_operand" "r")
  9659. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_PNFI))]
  9660. + ""
  9661. + "custom\\t%1, %0, %2, %3"
  9662. + [(set_attr "type" "custom")])
  9663. +
  9664. +(define_insn "custom_pnff"
  9665. + [(set (match_operand:SI 0 "register_operand" "=r")
  9666. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9667. + (match_operand:SF 2 "register_operand" "r")
  9668. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_PNFF))]
  9669. + ""
  9670. + "custom\\t%1, %0, %2, %3"
  9671. + [(set_attr "type" "custom")])
  9672. +
  9673. +(define_insn "custom_pnfp"
  9674. + [(set (match_operand:SI 0 "register_operand" "=r")
  9675. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9676. + (match_operand:SF 2 "register_operand" "r")
  9677. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_PNFP))]
  9678. + ""
  9679. + "custom\\t%1, %0, %2, %3"
  9680. + [(set_attr "type" "custom")])
  9681. +
  9682. +(define_insn "custom_pnpi"
  9683. + [(set (match_operand:SI 0 "register_operand" "=r")
  9684. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9685. + (match_operand:SI 2 "register_operand" "r")
  9686. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_PNPI))]
  9687. + ""
  9688. + "custom\\t%1, %0, %2, %3"
  9689. + [(set_attr "type" "custom")])
  9690. +
  9691. +(define_insn "custom_pnpf"
  9692. + [(set (match_operand:SI 0 "register_operand" "=r")
  9693. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9694. + (match_operand:SI 2 "register_operand" "r")
  9695. + (match_operand:SF 3 "register_operand" "r")] CUSTOM_PNPF))]
  9696. + ""
  9697. + "custom\\t%1, %0, %2, %3"
  9698. + [(set_attr "type" "custom")])
  9699. +
  9700. +(define_insn "custom_pnpp"
  9701. + [(set (match_operand:SI 0 "register_operand" "=r")
  9702. + (unspec_volatile:SI [(match_operand:SI 1 "custom_insn_opcode" "N")
  9703. + (match_operand:SI 2 "register_operand" "r")
  9704. + (match_operand:SI 3 "register_operand" "r")] CUSTOM_PNPP))]
  9705. + ""
  9706. + "custom\\t%1, %0, %2, %3"
  9707. + [(set_attr "type" "custom")])
  9708. +
  9709. +
  9710. +
  9711. +
  9712. +
  9713. +
  9714. +;*****************************************************************************
  9715. +;*
  9716. +;* Misc
  9717. +;*
  9718. +;*****************************************************************************
  9719. +
  9720. +(define_insn "nop"
  9721. + [(const_int 0)]
  9722. + ""
  9723. + "nop\\t"
  9724. + [(set_attr "type" "alu")])
  9725. +
  9726. +(define_insn "sync"
  9727. + [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
  9728. + ""
  9729. + "sync\\t"
  9730. + [(set_attr "type" "control")])
  9731. +
  9732. +
  9733. +(define_insn "rdctl"
  9734. + [(set (match_operand:SI 0 "register_operand" "=r")
  9735. + (unspec_volatile:SI [(match_operand:SI 1 "rdwrctl_operand" "O")] UNSPEC_RDCTL))]
  9736. + ""
  9737. + "rdctl\\t%0, ctl%1"
  9738. + [(set_attr "type" "control")])
  9739. +
  9740. +(define_insn "wrctl"
  9741. + [(unspec_volatile:SI [(match_operand:SI 0 "rdwrctl_operand" "O")
  9742. + (match_operand:SI 1 "register_operand" "r")] UNSPEC_WRCTL)]
  9743. + ""
  9744. + "wrctl\\tctl%0, %1"
  9745. + [(set_attr "type" "control")])
  9746. +
  9747. +
  9748. +
  9749. +;*****************************************************************************
  9750. +;*
  9751. +;* Peepholes
  9752. +;*
  9753. +;*****************************************************************************
  9754. +
  9755. +
  9756. --- gcc-3.4.3/gcc/config/nios2/t-nios2
  9757. +++ gcc-3.4.3-nios2/gcc/config/nios2/t-nios2
  9758. @@ -0,0 +1,123 @@
  9759. +##
  9760. +## Compiler flags to use when compiling libgcc2.c.
  9761. +##
  9762. +## LIB2FUNCS_EXTRA
  9763. +## A list of source file names to be compiled or assembled and inserted into libgcc.a.
  9764. +
  9765. +LIB2FUNCS_EXTRA=$(srcdir)/config/nios2/lib2-divmod.c \
  9766. + $(srcdir)/config/nios2/lib2-divmod-hi.c \
  9767. + $(srcdir)/config/nios2/lib2-divtable.c \
  9768. + $(srcdir)/config/nios2/lib2-mul.c
  9769. +
  9770. +##
  9771. +## Floating Point Emulation
  9772. +## To have GCC include software floating point libraries in libgcc.a define FPBIT
  9773. +## and DPBIT along with a few rules as follows:
  9774. +##
  9775. +## # We want fine grained libraries, so use the new code
  9776. +## # to build the floating point emulation libraries.
  9777. +FPBIT=$(srcdir)/config/nios2/nios2-fp-bit.c
  9778. +DPBIT=$(srcdir)/config/nios2/nios2-dp-bit.c
  9779. +
  9780. +TARGET_LIBGCC2_CFLAGS = -O2
  9781. +
  9782. +# FLOAT_ONLY - no doubles
  9783. +# SMALL_MACHINE - QI/HI is faster than SI
  9784. +# Actually SMALL_MACHINE uses chars and shorts instead of ints
  9785. +# since ints (16-bit ones as they are today) are at least as fast
  9786. +# as chars and shorts, don't define SMALL_MACHINE
  9787. +# CMPtype - type returned by FP compare, i.e. INT (hard coded in fp-bit - see code )
  9788. +
  9789. +$(FPBIT): $(srcdir)/config/fp-bit.c Makefile
  9790. + echo '#define FLOAT' > ${FPBIT}
  9791. + cat $(srcdir)/config/fp-bit.c >> ${FPBIT}
  9792. +
  9793. +$(DPBIT): $(srcdir)/config/fp-bit.c Makefile
  9794. + echo '' > ${DPBIT}
  9795. + cat $(srcdir)/config/fp-bit.c >> ${DPBIT}
  9796. +
  9797. +EXTRA_MULTILIB_PARTS = crtbegin.o crtend.o crti.o crtn.o
  9798. +
  9799. +# Assemble startup files.
  9800. +$(T)crti.o: $(srcdir)/config/nios2/crti.asm $(GCC_PASSES)
  9801. + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(MULTILIB_CFLAGS) $(INCLUDES) \
  9802. + -c -o $(T)crti.o -x assembler-with-cpp $(srcdir)/config/nios2/crti.asm
  9803. +
  9804. +$(T)crtn.o: $(srcdir)/config/nios2/crtn.asm $(GCC_PASSES)
  9805. + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(MULTILIB_CFLAGS) $(INCLUDES) \
  9806. + -c -o $(T)crtn.o -x assembler-with-cpp $(srcdir)/config/nios2/crtn.asm
  9807. +
  9808. +
  9809. +## You may need to provide additional #defines at the beginning of
  9810. +## fp-bit.c and dp-bit.c to control target endianness and other options
  9811. +##
  9812. +## CRTSTUFF_T_CFLAGS
  9813. +## Special flags used when compiling crtstuff.c. See Initialization.
  9814. +##
  9815. +## CRTSTUFF_T_CFLAGS_S
  9816. +## Special flags used when compiling crtstuff.c for shared linking. Used
  9817. +## if you use crtbeginS.o and crtendS.o in EXTRA-PARTS. See Initialization.
  9818. +##
  9819. +## MULTILIB_OPTIONS
  9820. +## For some targets, invoking GCC in different ways produces objects that
  9821. +## can not be linked together. For example, for some targets GCC produces
  9822. +## both big and little endian code. For these targets, you must arrange
  9823. +## for multiple versions of libgcc.a to be compiled, one for each set of
  9824. +## incompatible options. When GCC invokes the linker, it arranges to link
  9825. +## in the right version of libgcc.a, based on the command line options
  9826. +## used.
  9827. +## The MULTILIB_OPTIONS macro lists the set of options for which special
  9828. +## versions of libgcc.a must be built. Write options that are mutually
  9829. +## incompatible side by side, separated by a slash. Write options that may
  9830. +## be used together separated by a space. The build procedure will build
  9831. +## all combinations of compatible options.
  9832. +##
  9833. +## For example, if you set MULTILIB_OPTIONS to m68000/m68020 msoft-float,
  9834. +## Makefile will build special versions of libgcc.a using the following
  9835. +## sets of options: -m68000, -m68020, -msoft-float, -m68000 -msoft-float,
  9836. +## and -m68020 -msoft-float.
  9837. +
  9838. +MULTILIB_OPTIONS = mno-hw-mul mhw-mulx
  9839. +
  9840. +## MULTILIB_DIRNAMES
  9841. +## If MULTILIB_OPTIONS is used, this variable specifies the directory names
  9842. +## that should be used to hold the various libraries. Write one element in
  9843. +## MULTILIB_DIRNAMES for each element in MULTILIB_OPTIONS. If
  9844. +## MULTILIB_DIRNAMES is not used, the default value will be
  9845. +## MULTILIB_OPTIONS, with all slashes treated as spaces.
  9846. +## For example, if MULTILIB_OPTIONS is set to m68000/m68020 msoft-float,
  9847. +## then the default value of MULTILIB_DIRNAMES is m68000 m68020
  9848. +## msoft-float. You may specify a different value if you desire a
  9849. +## different set of directory names.
  9850. +
  9851. +# MULTILIB_DIRNAMES =
  9852. +
  9853. +## MULTILIB_MATCHES
  9854. +## Sometimes the same option may be written in two different ways. If an
  9855. +## option is listed in MULTILIB_OPTIONS, GCC needs to know about any
  9856. +## synonyms. In that case, set MULTILIB_MATCHES to a list of items of the
  9857. +## form option=option to describe all relevant synonyms. For example,
  9858. +## m68000=mc68000 m68020=mc68020.
  9859. +##
  9860. +## MULTILIB_EXCEPTIONS
  9861. +## Sometimes when there are multiple sets of MULTILIB_OPTIONS being
  9862. +## specified, there are combinations that should not be built. In that
  9863. +## case, set MULTILIB_EXCEPTIONS to be all of the switch exceptions in
  9864. +## shell case syntax that should not be built.
  9865. +## For example, in the PowerPC embedded ABI support, it is not desirable to
  9866. +## build libraries compiled with the -mcall-aix option and either of the
  9867. +## -fleading-underscore or -mlittle options at the same time. Therefore
  9868. +## MULTILIB_EXCEPTIONS is set to
  9869. +##
  9870. +## *mcall-aix/*fleading-underscore* *mlittle/*mcall-aix*
  9871. +##
  9872. +
  9873. +MULTILIB_EXCEPTIONS = *mno-hw-mul/*mhw-mulx*
  9874. +
  9875. +##
  9876. +## MULTILIB_EXTRA_OPTS Sometimes it is desirable that when building
  9877. +## multiple versions of libgcc.a certain options should always be passed on
  9878. +## to the compiler. In that case, set MULTILIB_EXTRA_OPTS to be the list
  9879. +## of options to be used for all builds.
  9880. +##
  9881. +
  9882. --- gcc-3.4.3/gcc/config.gcc
  9883. +++ gcc-3.4.3-nios2/gcc/config.gcc
  9884. @@ -1321,6 +1321,10 @@ m32rle-*-linux*)
  9885. thread_file='posix'
  9886. fi
  9887. ;;
  9888. +# JBG
  9889. +nios2-*-* | nios2-*-*)
  9890. + tm_file="elfos.h ${tm_file}"
  9891. + ;;
  9892. # m68hc11 and m68hc12 share the same machine description.
  9893. m68hc11-*-*|m6811-*-*)
  9894. tm_file="dbxelf.h elfos.h m68hc11/m68hc11.h"
  9895. --- gcc-3.4.3/gcc/cse.c
  9896. +++ gcc-3.4.3-nios2/gcc/cse.c
  9897. @@ -3134,6 +3134,10 @@ find_comparison_args (enum rtx_code code
  9898. #ifdef FLOAT_STORE_FLAG_VALUE
  9899. REAL_VALUE_TYPE fsfv;
  9900. #endif
  9901. +#ifdef __nios2__
  9902. + if (p->is_const)
  9903. + break;
  9904. +#endif
  9905. /* If the entry isn't valid, skip it. */
  9906. if (! exp_equiv_p (p->exp, p->exp, 1, 0))
  9907. --- gcc-3.4.3/gcc/doc/extend.texi
  9908. +++ gcc-3.4.3-nios2/gcc/doc/extend.texi
  9909. @@ -5636,12 +5636,118 @@ to those machines. Generally these gene
  9910. instructions, but allow the compiler to schedule those calls.
  9911. @menu
  9912. +* Altera Nios II Built-in Functions::
  9913. * Alpha Built-in Functions::
  9914. * ARM Built-in Functions::
  9915. * X86 Built-in Functions::
  9916. * PowerPC AltiVec Built-in Functions::
  9917. @end menu
  9918. +@node Altera Nios II Built-in Functions
  9919. +@subsection Altera Nios II Built-in Functions
  9920. +
  9921. +These built-in functions are available for the Altera Nios II
  9922. +family of processors.
  9923. +
  9924. +The following built-in functions are always available. They
  9925. +all generate the machine instruction that is part of the name.
  9926. +
  9927. +@example
  9928. +int __builtin_ldbio (volatile const void *)
  9929. +int __builtin_ldbuio (volatile const void *)
  9930. +int __builtin_ldhio (volatile const void *)
  9931. +int __builtin_ldhuio (volatile const void *)
  9932. +int __builtin_ldwio (volatile const void *)
  9933. +void __builtin_stbio (volatile void *, int)
  9934. +void __builtin_sthio (volatile void *, int)
  9935. +void __builtin_stwio (volatile void *, int)
  9936. +void __builtin_sync (void)
  9937. +int __builtin_rdctl (int)
  9938. +void __builtin_wrctl (int, int)
  9939. +@end example
  9940. +
  9941. +The following built-in functions are always available. They
  9942. +all generate a Nios II Custom Instruction. The name of the
  9943. +function represents the types that the function takes and
  9944. +returns. The letter before the @code{n} is the return type
  9945. +or void if absent. The @code{n} represnts the first parameter
  9946. +to all the custom instructions, the custom instruction number.
  9947. +The two letters after the @code{n} represent the up to two
  9948. +parameters to the function.
  9949. +
  9950. +The letters reprsent the following data types:
  9951. +@table @code
  9952. +@item <no letter>
  9953. +@code{void} for return type and no parameter for parameter types.
  9954. +
  9955. +@item i
  9956. +@code{int} for return type and parameter type
  9957. +
  9958. +@item f
  9959. +@code{float} for return type and parameter type
  9960. +
  9961. +@item p
  9962. +@code{void *} for return type and parameter type
  9963. +
  9964. +@end table
  9965. +
  9966. +And the function names are:
  9967. +@example
  9968. +void __builtin_custom_n (void)
  9969. +void __builtin_custom_ni (int)
  9970. +void __builtin_custom_nf (float)
  9971. +void __builtin_custom_np (void *)
  9972. +void __builtin_custom_nii (int, int)
  9973. +void __builtin_custom_nif (int, float)
  9974. +void __builtin_custom_nip (int, void *)
  9975. +void __builtin_custom_nfi (float, int)
  9976. +void __builtin_custom_nff (float, float)
  9977. +void __builtin_custom_nfp (float, void *)
  9978. +void __builtin_custom_npi (void *, int)
  9979. +void __builtin_custom_npf (void *, float)
  9980. +void __builtin_custom_npp (void *, void *)
  9981. +int __builtin_custom_in (void)
  9982. +int __builtin_custom_ini (int)
  9983. +int __builtin_custom_inf (float)
  9984. +int __builtin_custom_inp (void *)
  9985. +int __builtin_custom_inii (int, int)
  9986. +int __builtin_custom_inif (int, float)
  9987. +int __builtin_custom_inip (int, void *)
  9988. +int __builtin_custom_infi (float, int)
  9989. +int __builtin_custom_inff (float, float)
  9990. +int __builtin_custom_infp (float, void *)
  9991. +int __builtin_custom_inpi (void *, int)
  9992. +int __builtin_custom_inpf (void *, float)
  9993. +int __builtin_custom_inpp (void *, void *)
  9994. +float __builtin_custom_fn (void)
  9995. +float __builtin_custom_fni (int)
  9996. +float __builtin_custom_fnf (float)
  9997. +float __builtin_custom_fnp (void *)
  9998. +float __builtin_custom_fnii (int, int)
  9999. +float __builtin_custom_fnif (int, float)
  10000. +float __builtin_custom_fnip (int, void *)
  10001. +float __builtin_custom_fnfi (float, int)
  10002. +float __builtin_custom_fnff (float, float)
  10003. +float __builtin_custom_fnfp (float, void *)
  10004. +float __builtin_custom_fnpi (void *, int)
  10005. +float __builtin_custom_fnpf (void *, float)
  10006. +float __builtin_custom_fnpp (void *, void *)
  10007. +void * __builtin_custom_pn (void)
  10008. +void * __builtin_custom_pni (int)
  10009. +void * __builtin_custom_pnf (float)
  10010. +void * __builtin_custom_pnp (void *)
  10011. +void * __builtin_custom_pnii (int, int)
  10012. +void * __builtin_custom_pnif (int, float)
  10013. +void * __builtin_custom_pnip (int, void *)
  10014. +void * __builtin_custom_pnfi (float, int)
  10015. +void * __builtin_custom_pnff (float, float)
  10016. +void * __builtin_custom_pnfp (float, void *)
  10017. +void * __builtin_custom_pnpi (void *, int)
  10018. +void * __builtin_custom_pnpf (void *, float)
  10019. +void * __builtin_custom_pnpp (void *, void *)
  10020. +@end example
  10021. +
  10022. +
  10023. @node Alpha Built-in Functions
  10024. @subsection Alpha Built-in Functions
  10025. --- gcc-3.4.3/gcc/doc/invoke.texi
  10026. +++ gcc-3.4.3-nios2/gcc/doc/invoke.texi
  10027. @@ -337,6 +337,14 @@ in the following sections.
  10028. @item Machine Dependent Options
  10029. @xref{Submodel Options,,Hardware Models and Configurations}.
  10030. +@emph{Altera Nios II Options}
  10031. +@gccoptlist{-msmallc -mno-bypass-cache -mbypass-cache @gol
  10032. +-mno-cache-volatile -mcache-volatile -mno-inline-memcpy @gol
  10033. +-minline-memcpy -mno-fast-sw-div -mfast-sw-div @gol
  10034. +-mhw-mul -mno-hw-mul -mhw-mulx -mno-hw-mulx @gol
  10035. +-mno-hw-div -mhw-div @gol
  10036. +-msys-crt0= -msys-lib= -msys=nosys }
  10037. +
  10038. @emph{M680x0 Options}
  10039. @gccoptlist{-m68000 -m68020 -m68020-40 -m68020-60 -m68030 -m68040 @gol
  10040. -m68060 -mcpu32 -m5200 -m68881 -mbitfield -mc68000 -mc68020 @gol
  10041. @@ -5836,6 +5844,7 @@ machine description. The default for th
  10042. that macro, which enables you to change the defaults.
  10043. @menu
  10044. +* Altera Nios II Options::
  10045. * M680x0 Options::
  10046. * M68hc1x Options::
  10047. * VAX Options::
  10048. @@ -5871,6 +5880,103 @@ that macro, which enables you to change
  10049. * FRV Options::
  10050. @end menu
  10051. +
  10052. +@node Altera Nios II Options
  10053. +@subsection Altera Nios II Options
  10054. +@cindex Altera Nios II options
  10055. +
  10056. +These are the @samp{-m} options defined for the Altera Nios II
  10057. +processor.
  10058. +
  10059. +@table @gcctabopt
  10060. +
  10061. +@item -msmallc
  10062. +@opindex msmallc
  10063. +
  10064. +Link with a limited version of the C library, -lsmallc. For more
  10065. +information see the C Library Documentation.
  10066. +
  10067. +
  10068. +@item -mbypass-cache
  10069. +@itemx -mno-bypass-cache
  10070. +@opindex mno-bypass-cache
  10071. +@opindex mbypass-cache
  10072. +
  10073. +Force all load and store instructions to always bypass cache by
  10074. +using io variants of the instructions. The default is to not
  10075. +bypass the cache.
  10076. +
  10077. +@item -mno-cache-volatile
  10078. +@itemx -mcache-volatile
  10079. +@opindex mcache-volatile
  10080. +@opindex mno-cache-volatile
  10081. +
  10082. +Volatile memory access bypass the cache using the io variants of
  10083. +the ld and st instructions. The default is to cache volatile
  10084. +accesses.
  10085. +
  10086. +-mno-cache-volatile is deprecated and will be deleted in a
  10087. +future GCC release.
  10088. +
  10089. +
  10090. +@item -mno-inline-memcpy
  10091. +@itemx -minline-memcpy
  10092. +@opindex mno-inline-memcpy
  10093. +@opindex minline-memcpy
  10094. +
  10095. +Do not inline memcpy. The default is to inline when -O is on.
  10096. +
  10097. +
  10098. +@item -mno-fast-sw-div
  10099. +@itemx -mfast-sw-div
  10100. +@opindex mno-fast-sw-div
  10101. +@opindex mfast-sw-div
  10102. +
  10103. +Do no use table based fast divide for small numbers. The default
  10104. +is to use the fast divide at -O3 and above.
  10105. +
  10106. +
  10107. +@item -mno-hw-mul
  10108. +@itemx -mhw-mul
  10109. +@itemx -mno-hw-mulx
  10110. +@itemx -mhw-mulx
  10111. +@itemx -mno-hw-div
  10112. +@itemx -mhw-div
  10113. +@opindex mno-hw-mul
  10114. +@opindex mhw-mul
  10115. +@opindex mno-hw-mulx
  10116. +@opindex mhw-mulx
  10117. +@opindex mno-hw-div
  10118. +@opindex mhw-div
  10119. +
  10120. +Enable or disable emitting @code{mul}, @code{mulx} and @code{div} family of
  10121. +instructions by the compiler. The default is to emit @code{mul}
  10122. +and not emit @code{div} and @code{mulx}.
  10123. +
  10124. +The different combinations of @code{mul} and @code{mulx} instructions
  10125. +generate a different multilib options.
  10126. +
  10127. +
  10128. +@item -msys-crt0=@var{startfile}
  10129. +@opindex msys-crt0
  10130. +
  10131. +@var{startfile} is the file name of the startfile (crt0) to use
  10132. +when linking. The default is crt0.o that comes with libgloss
  10133. +and is only suitable for use with the instruction set
  10134. +simulator.
  10135. +
  10136. +@item -msys-lib=@var{systemlib}
  10137. +@itemx -msys-lib=nosys
  10138. +@opindex msys-lib
  10139. +
  10140. +@var{systemlib} is the library name of the library which provides
  10141. +the system calls required by the C library, e.g. @code{read}, @code{write}
  10142. +etc. The default is to use nosys, this library provides
  10143. +stub implementations of the calls and is part of libgloss.
  10144. +
  10145. +@end table
  10146. +
  10147. +
  10148. @node M680x0 Options
  10149. @subsection M680x0 Options
  10150. @cindex M680x0 options
  10151. --- gcc-3.4.3/gcc/doc/md.texi
  10152. +++ gcc-3.4.3-nios2/gcc/doc/md.texi
  10153. @@ -1335,6 +1335,49 @@ However, here is a summary of the machin
  10154. available on some particular machines.
  10155. @table @emph
  10156. +
  10157. +@item Altera Nios II family---@file{nios2.h}
  10158. +@table @code
  10159. +
  10160. +@item I
  10161. +Integer that is valid as an immediate operand in an
  10162. +instruction taking a signed 16-bit number. Range
  10163. +@minus{}32768 to 32767.
  10164. +
  10165. +@item J
  10166. +Integer that is valid as an immediate operand in an
  10167. +instruction taking an unsigned 16-bit number. Range
  10168. +0 to 65535.
  10169. +
  10170. +@item K
  10171. +Integer that is valid as an immediate operand in an
  10172. +instruction taking only the upper 16-bits of a
  10173. +32-bit number. Range 32-bit numbers with the lower
  10174. +16-bits being 0.
  10175. +
  10176. +@item L
  10177. +Integer that is valid as an immediate operand for a
  10178. +shift instruction. Range 0 to 31.
  10179. +
  10180. +
  10181. +@item M
  10182. +Integer that is valid as an immediate operand for
  10183. +only the value 0. Can be used in conjunction with
  10184. +the format modifier @code{z} to use @code{r0}
  10185. +instead of @code{0} in the assembly output.
  10186. +
  10187. +@item N
  10188. +Integer that is valid as an immediate operand for
  10189. +a custom instruction opcode. Range 0 to 255.
  10190. +
  10191. +@item S
  10192. +Matches immediates which are addresses in the small
  10193. +data section and therefore can be added to @code{gp}
  10194. +as a 16-bit immediate to re-create their 32-bit value.
  10195. +
  10196. +@end table
  10197. +
  10198. +
  10199. @item ARM family---@file{arm.h}
  10200. @table @code
  10201. @item f