the ++ operator
Aggelos Economopoulos
aoiko at cc.ece.ntua.gr
Sun Nov 23 06:44:10 EET 2003
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'):
* `The extent to which suggestions made by using the `register'
storage-class specifier are effective (6.7.1).'
The `register' specifier affects code generation only in these
ways:
* When used as part of the register variable extension, see
Explicit Reg Vars.
* When `-O0' is in use, the compiler allocates distinct stack
memory for all variables that do not have the `register'
storage-class specifier; if `register' is specified, the
variable may have a shorter lifespan than the code would
indicate and may never be placed in memory.
* On some rare x86 targets, `setjmp' doesn't save the registers
in all circumstances. In those cases, GCC doesn't allocate
any variables in registers unless they are marked `register'.
> 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.
> int mode; | int mode;
> for(;;){ | if (mode == 1){
> if (mode == 1){ | for(;;){
> ... | ...
> } | }
> else{ | }
> ... | else{
> } | for(;;){
> } | ...
>
> | }
> | }
An to mode den allazei sto '...' kommati (pou den allazei, giati tote to
transformation einai la8os), tote me to branch prediction twn shmerinwn
epe3ergastwn den 8a parathrhseis kamia diafora sto performance. Isa isa, an,
opws sumbanei kapoies fores, ta loop bodies kanoun kati paromoio kai
diaforopoiountai mono apo thn timh tou mode, exeis code duplication me ta
gnwsta problhmata pou sou dhmiourgei (prepei na ta kratas in-sync, spatalas
xwro sthn icache).
[snip]
> 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.
[0] parathrhsh pou einai gnwsth san "Sturgeon's law". Egw toulaxiston eimai
pio konta sto prosfato a3iwma tou Viro:
"And folks, let's be honest. Sturgeon was an optimist."
[1] apo otan den uphrxan Unix/C
More information about the Linux-greek-users
mailing list