the ++ operator

Manolis Stamatogiannakis mstamat at csd.uoc.gr
Sat Nov 22 14:36:48 EET 2003



On Sat, 22 Nov 2003, V13 wrote:

> On Saturday 22 November 2003 11:47, Tom Diamond wrote:
> > >> Δεν είναι πιο γρήγορο - κάθε σύγχρονος compiler παράγει ακριβώς τον
> > >> ίδιο κώδικα και στις δυο περιπτώσεις.
> > >
> > > Missunderstanding, enoousa pio grigoro sto "na to grapseis" pio
> > > shorthand diladi. Profanos o kodikas einai akribos o idios...
> >
> > Αυτό ισχύει και για τους πίνακες φαντάζομαι(;). Δηλ. το a[i+1] είναι το
> > ίδιο γρήγορο με το a[i++].
> > Υπάρχει πιο γρήγορος τρόπος για τα παραπάνω;
>
> Ayta ta dyo den einai to idio se kamia periptosi.. to 2o tha epistrepsei to
> a[i] kai meta tha ayksisei to i... to 1o den tha kanei tipota apo ta dyo
> (oyte tha ayksisei to i, oyte tha epistrepsei to a[i])
>
> An enoeis gia taxythta ekteleshs, to :
>
> char *p;
> p=a;
>
> *p ; p++;
>
> (to char einai tyxaios typos)
>
> Tha einai poio grygoro stis perissoteres periptoseis *EKTOS* kai an to a einai
> global metablith-pinakas...
>
> <<V13>>
>

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.

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.

int mode;                  | int mode;
for(;;){                   | if (mode == 1){
	if (mode == 1){    | 	for(;;){
		...        |		...
	}                  | 	}
	else{              | }
		...        | else{
	}                  | 	for(;;){
}                          |		...
                           |	}
                           | }

To aristero loop 8a tre3ei pio arga, giati kanei perissoteres sygkriseis
alla kyriws giati kanei perissotra jumps. An exeis kanei loipon auto to
'la8os', tote to pws 8a kaneis super-optimize to i++ de 8a sou dwsei
tipota.

Epishs, oso pio aplo einai ena mh-optimized kommati kwdika, toso pio
eukolo einai gia ton compiler na to kanei optimize. Etsi to i++ mallon 8a
to kanei optimize o compiler oso kalytera ginetai, ane3arthta me to pws 8a
to grapseis esy. To loop pou anefera omws, de nomizw na to peira3ei kaneis
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

M.




More information about the Linux-greek-users mailing list