Il 0% ha trovato utile questo documento (0 voti)
32 visualizzazioni15 pagine

MC Assi

Il documento discute tecniche di ottimizzazione del codice, inclusi loop unrolling e inline functions, per migliorare l'efficienza in linguaggi di programmazione come C. Viene evidenziata l'importanza di scegliere i tipi di dati appropriati e di gestire correttamente le variabili per ridurre l'overhead e migliorare le prestazioni. Inoltre, si menzionano le differenze tra architetture e convenzioni di chiamata, sottolineando la necessità di ottimizzare il codice per specifici processori.

Caricato da

gg620785
Copyright
© © All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo, rivendicalo qui.
Formati disponibili
Scarica in formato PDF o leggi online su Scribd
Il 0% ha trovato utile questo documento (0 voti)
32 visualizzazioni15 pagine

MC Assi

Il documento discute tecniche di ottimizzazione del codice, inclusi loop unrolling e inline functions, per migliorare l'efficienza in linguaggi di programmazione come C. Viene evidenziata l'importanza di scegliere i tipi di dati appropriati e di gestire correttamente le variabili per ridurre l'overhead e migliorare le prestazioni. Inoltre, si menzionano le differenze tra architetture e convenzioni di chiamata, sottolineando la necessità di ottimizzare il codice per specifici processori.

Caricato da

gg620785
Copyright
© © All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo, rivendicalo qui.
Formati disponibili
Scarica in formato PDF o leggi online su Scribd
Sei sulla pagina 1/ 15
Zhtn & Compile encom Wey nummer Of iterations 4 RNR Ro9 car ance power Level code Caire cusemuiy oe ait Mgh> A b 1 conditional jumps YM Pytecoas ye Wing ante ample Loop_exampleCint ni) { , for CiNt i 0% jamgin edd > ’ " y compileA handling? Lthe fox 200p: gor Cint i=Os1CNS ItDK OY By eqwivatent tot int 1 = 05 while Cicn de some cod ins y # 9ni tralizaten: % Condition Check > 1-0 (sets up the Loup count A) icN (Check S if oop should continues iA oe Tuntime vari able). 2 Bod Execution: Executes the Loop body if Condition tx! TeaCincsements Me countAy compile time - bts determned Ot runt to Peteh ancl compare N on x dncrement * ¥N tH not known OF a The compiler gennotes code i tab on. comp lar ee) a i ral techniqea dite “goop unrolli’ each anotyze Loop behov © & Optimizing a atrength * To Ube. & OU =oit Neias aca By to em Fs Ge eay zoo mat occurs in & fox Loop Bumper Ff ipnations?, s onsemoxe: Sie sb peony ting the Soop. gms before Se aaieee Fee in a Way that Aeede OtEW pirat ie matiens ie Howevar, 42 prey eo aime’ arm i Auge —T 4 byte ment supperts IE rt ve Ebticient code code using Chor: void cum. array char (cnr #a%, int size) P# Coch Access to aM iy 2 {i} Loads only 4 byte tficient FR EPU % pucsent un (3% harderate HARM needs £0 sig "GN - extend the value tO Qg-pit, wohich Adel, evehhead, a mov 7 check cum. ve - 200 P Ao. 4S a : : tase bok ea 7(ms*4 , aaa ;4 x CO Apo its1i et 3 att : cmp rh, 4 OsHO 5 compare i, 64 sae pop 10473350 s sum +2 O3 i v5 —ROOP : x dn pce checks” _V5- 5 pe Ciccad gore loop Mov pt 14 y rervan dum _¥N yt take an ree instruct ons to + mpiement whe fot Doo p seructies, * 7 ean ADD increment ¢ - 20 tw check if ' in Sux nan 6A Bac eontin senate foop if iee4 ta @ A compart conditional branch to not efeicient > On ne instruct ers’ OA sGubrract +0 decrement the Loop counted which > i Map enets the conch em Coe e+ @ A Conditional branch ee on the TRUE ee me acm, a oop Shovtal ony a £ misA '% use tw0 6. Hew Co = . mpiles ha nO of iteations ny ea tor 0p con 00 p with = vaniab trolling with a e@ Misal ° bee EES accor (e-g Ace ORIN int #49 vdd addrasdc v ; ov ™ on Joan Cowe faults en some AEM CPUS, , ¥% Inline and 0 ssem r extenal A mobly, fox wee Ce Qa = asm —~ locks) wai etniine asrzembly vo Titien mot wort en ARM. earm com plet ey cligperent instr uchen get Ond register # Punch en Calli , we anrcs CAgm Proced Xe aaj) §eondenenm in RoR vetwn volue has a model 4 Conven tian . 2arm follo o Arguments ane passed ‘ Uniile e 286: oA tects gp vo -hevel code and mixed C/ Ose #% Stack mignment - Some ARM ABIS 7 OQ UI e g- byte ¢ con 200d Sones a Mi sabigned Bracks mena y access needed for arg = quent parsing(upte sore ane erase veran via BX LR(branch to dmk reginter) | minimad stack wage, unas mee arguments A Local steroga ve needed - soncy and modulanity while ry 4 ty wt ALaying Sighturght ing veent 4 unction cali ng in ARI byt a maint enables eggicient ences Agumen nd yhan vo h h a passing arguments and vet values thro Tegintor ocieasly deeining cabten/ cattee e Avot ding Unnecessary memehy aca? ano fast . wlibe and making code a exponai com pack « compila inine small functions wit 1a. Explain how the how to inline Large functions. an Example: Discuss EArt Hy eCritical functions can be infined wring tne —infine xeyword. ¥Tniining % an optimization whe the compiler replaces a the actuol code 6p the function - i func’ en coll with eunction call ovanead (saving pres ning ’ ethis removes the Tew stack frame), specially or Amol and £req ale (e-g., simple arithmetic 1 4 pat are rn ¥ Compile fags like [* excomples = Small Fun ction rnting ing , C coder inline nt squoreCin® O¢ yetunn XH? y int maint) ¢ ci = ——= 31a ; ; egg icienty 10. Explain in wrief writing doops se isienaige ion eI a re jown +O ZexD. Then the compile dow gintes ¥0 hold tne tamination th zo is $ree. fu y comparisen uv Joop countos by default and the continuation, rather Man i> Oo. This will ensur € that the x unaot impor © cto -anite ane” . gimpit ids scpdaeenie™ wot nor ci gum int 129% : vecn ort “, nwo e i gov CN aomle cio NY ae i a ; Lee oop entry Aavant companrsen (ic) > aemoved som the 09% ny faa #€ Zecluc x the frat point , reducing le the check tor a tance the Loop, only pale tes ager One de aHOM- ivionad branch 2 outside the L0oP: ny Siicien c3omoinsCicND, ® Bett cero ont eniteancok N>o the prove pagamance in tignk Bv0Ps »by # Few 4 This can slightly i ducing ee Tumba og. concitvenad branches » White i mplem ening the Coop, there ae ADme Additienad’ ~& instructions y to alex on | ne tv body 9, the Soop hg thar instruction os oop Count’ and a eonditienag el YAK cabled f ovearheaol — ~ etd ror PocaP VONAbIE heig char A AMAL type amelie. (S NGcensas inated. Unig in Teparax Car eds is UKE the ey weet Te tyPA are Mavoil ehar anc short ex eur VOLURs URC opin, weeyange ¢& the An Outer, modular net A Nsigned int Fasvo, when we use g, typa tor we vig, Puneet On - arguments a! wnt type even (# the Tange o ae Parameter is xmatter: THX preven ob the COMPA POLAMing Unnecers ary casts Seaplane Quen ae ————— y explain the eticient wea oC Datatypes efor tecal variable held in TORO, we ghouldn'at wie achok & short Pe uMlcs 8. bit eRe eEe emocut Cintnenete ih NECHAAY, VAL the Zignet a unsigned int ypu initead « unsign ta typ ts are fasten when we use divisions. ‘ yr GARQY ENtriA anol global vahiabla held im main me ot). ee ae with the eerie AiTe possible to hold tee oe ae ata THA Raves MEMMY Footprint. The ARMvA : anchitectWre ih eggicient at Moding and Ateing ee sts iatha provided we travere anha. by tnsrremitn tiny th = eae pointer. Avoid using Oresers ror sabe cco Toney with Ahort pe Kory, a4 ee 1 Sup eUae explicit cats when ee amo into Local variable, th writing Lo: variables : gy entris 7 « th:8 Spe aaT ee cit Gh explicit Narrowing: ache a Impl che a cyc * Avoi ty cose eattr oes | be cause they wally re free because Pe x sore one aay og i — wie 2 aint WO at opaotienr “get of rs a+b or ae ok geet typ for 4un ction Co eo" we ae pent onl nen - ne anive value f 4 i, wed oy positive yolu & O35 Pas syrem): ae usage Wher vs 2 Sno inafees, B26 ce secompler void com pare) { gigned int = ~ 105 unbign eat int b= 805 ipa sod nate * pate Coa is tus Bron bln D3 usef qintt (7 14 no £ Lesa than b\n")+ # Tn thin co Ae, he & : COm pari Mix parison | ce ie 1.8 onda ta valid. » especi ey heen can 2 negative iii il session code using int ae © qed. Ba wry Jak Chk waa Fr size) { sat um = 03 we cint t= 05 ie sizes tsar gum 42 on(ids A y y ne eye A extenaion eaugned acess aa bit data, optimized for ARM core wight, dota. ype 4 cruti al gor writing efgicieny achovsing the pAem microcontrollers + c code om eink Oe pit tyr are gquenty tre MOAL eqgicient cue to arenitecture’s aesign pe convensiont and Ges Seaninieni 2.09 ey ods to Ose hh, small, and mare power “h explain which clata ty pe must be use for = Function odgumeat with an Example. eror function ang uments, We aroull “wsebicia tay yps ethan moteh the Proce sOT'S mative word ize. gon ARM (Ba-bit)s using Int O% We Wink B&-t 1B BEAL for pergehmon #ayoid using Ghar ge short unless needed : promotien ee extra proces ag, edna ae ae a Convertir Jocal voriablr f10r ty increases porformanc é and Teducd e the same hore for function proper azignment ye ~_ efhicint code ws chord ed she waa size. cd WN AR ma processors the Sub tract S tore » On Ceregaemartacem oer thee c oe tour cel pe oop yetess Qing an overntod dhene cycle bY ow roll ng « fo p's) some og nosp vody several Eentds anid asd! sedtuci we can save name propertien . pening the sige itaahem by tne wecuce PACAMANe b e the cache ¢ " cps * anenn + Te qre UMA OF may even | # Unvolling code ¢20mM impor ant x g:comple!= simple loop gor Cint 120, 1¢ > int gum += atid: edt soop- Cry % fot of D4 fees uae Add eats afcrel vnv ‘Bor Cink 120% ‘ ~ otieede cum 42 O0) y f Aavant veo lling }— ezicuced 200P overhead + cewer Jumps and condition checks PA eement- + cru can penedube Fra sucti t iy ve paralle Liam tions mere ef eg Tepe pranch Pr e care): Fewer Le cauction -Le instruc ficiently. # Betta ind edicti on, ¥ e! , 2 Fewer bIANH ermproved cache wage(in hom tocatity - Se prownaces of Soop UNETIND” ai increases ¢ Longe unsolling x code size ) Cincs eoned binary size)- # Dimini shia wexurs > Beyors a po piareau A TEVAKE - © * Reduced ee ada bi i EY and main make code nord +O 2

Potrebbero piacerti anche