the ++ operator

Manolis Stamatogiannakis mstamat at csd.uoc.gr
Sun Nov 23 13:10:32 EET 2003



On Sun, 23 Nov 2003, Aggelos Economopoulos wrote:

> On Saturday 22 November 2003 14:36, Manolis Stamatogiannakis wrote:
> [snip]
> > Exw thn entypwsh pws mporei na ginei akoma pio grhgoro dhlwnontas thn
> > metavlhth p san register. Dhladh: register char *p;
> > To "register" pantws, apotelei hint ston compiler. An o compiler nomizei
> > pws tou 'perisevoun' registers, 8a afierwsei ena register gia na krataei
> > thn timh tou p. Alloiwtika to p 8a meinei aplh metavlhth kai h taxythta 8a
> > meinei h idia.
>
> Oi shmerinoi compilers agnooun to 'register' hint (kai me to dikio tous...).
> Sthn periptwsh tou gcc (apo to info page, 'C Implementation' -> 'Hints
> implementation'):
>

Teleutaia fora pou to dokimasa douleue pantws :) Prepei na htan omws
'97-'98 kai to mhxanhma na htan sparc.

Apo mia matia omws sto online documentation tou gcc, fainetai pws yparxei
akoma h dynatothta na dhlwseis mia metavlhth sa register mono pou exei
alla3ei h synta3h. Dhladh pleon prepei na katonomaseis kai ton register
pou 8eleis na kratietai h metavlhth (Explicit Reg Var [1] - 1h periptwsh
se auta pou aneferes).


>
> > Pantws Tom an 3ekinas na kaneis to programma sou grhgorotero kanontas
> > optimize to i++, mallon xaneis ton kairo sou. To i++ 8a einai to teleutaio
> > pragma pou 8a ginei optimize. Mesa ston kwdika sou/mou/tou yparxoun
> > sigoura poly xeirotera pragmata pou ta pairnoume oloi apshfista. P.x.
>
> Auto den einai kati polu xeirotero (see below). Polu xeiroterh einai h xrhsh
> non-optimal algori8mwn (kati pou to blepeis polu suxna - 90% of everything is
> crap[0] klp klp), giati auto einai kati pou oi compilers mporoun na to
> dior8wsoun mono se _polu_ aples periptwseis.
>

Safestata :) Panta kanoume optimizations se ena programma pou den pasxei
algori8mika. Giati an pasxei de se swzei kanena code optimization kai
kanenas compiler.

> > Kapoia wraia slides pou vrhka gia optimized C se x86 (kai apo opou eklepsa
> > kai to paradeigma), einai sto:
> > http://x86.ddj.com/ftp/manuals/686/iatips.pdf
>
> i) To ~80% apo ta optimizations pou proteinei einai *pararxaies*[1] texnikes,
> pou ginontai automata akoma kai apo tous pio aplous optimising compilers edw
> kai duo dekaeties kai sigoura *den* einai intel architecture specific.
>
> ii) To doc fainetai mallon palio kai kapoia pragmata pou proteinei den 8a
> einai pia polu apodotika - p.x. ta table lookups sunepagontai cache misses
> opote den sumferoun an to operation pou 8eleis na kaneis den einai arketa
> argo h den prokeitai na kaneis polla lookups.
>

Den eimai eidikos se compiler optimization kai den exw parakolou8hsei
idiaitera to ti yposthrizoun oi shmerinoi compilers, opote de mporw na
diafwnhsw. Kai omologoumenws to paradeigma pou epele3a apo ta slides htan
mallon apotyxhmeno (poly konta sto kerdos me to optimized i++).

Omws afou ta slides exoun kai ena '(c) Intel' apo katw, toulaxisto nomizw
pws den prokeitai na proteinoun pragmata pou 8a vgaloun pio argo kwdika.

Anaferontai epishs sta slides kai pragmata pou einai gnwsta, alla oi
compilers den prokeitai na peira3oun. Px an exeis ena mikro pinaka mikrwn
akairewn pou ginetai access poly syxna kai kaneis thn koutoponhrh epilogh
na ton dhlwseis 'short int', kerdizeis merika (f8hna shmera) bytes mnhmhs,
omws xaneis para poly se apodwsh e3aitias tou oti oi shorts den einai
32bit alligned. H' (klassika) na mh xrhsimopoieis tis memset, memcpy alla
na xrhsimopoieis for loops.

M.

PS. Yparxei pantws sto idio directory kai to pio hardcore guide gia
optimizations [2], pou mallon apeu8ynetai pio poly se syggrafeis
compilers.


[1] http://gcc.gnu.org/onlinedocs/gcc/Explicit-Reg-Vars.html#Explicit%20Reg%20Vars
[2] http://x86.ddj.com/ftp/manuals/686/optimgd.pdf




More information about the Linux-greek-users mailing list