On Tue, 5 May 1998, Glynn Clements wrote:
>
> Try using `gcc -S' to compile to assembler, both with and without
> optimisation, then compare the results.
>
Ok. I did it. I have *no* assembly knowledge so pleaz pardon my ignorance.
As u may see the only difference is that the O1 optimized code addresses
the 1st local variable pResTemp with -16(%ebp) instead of -4(%ebx).
Why?
/***************************************************************************/
void PrintStats(char* szStartDate)
{
PGresult* pResTemp = NULL;
... 3 more ints ...
long lTotalInc;
...
SQLexec(pConnection,szQuery,&pResTemp,PGRES_TUPLES_OK);
o0 code is
.L55:
pushl $2 //PGRES_TUPLES_OK = 2, 4th param
leal -4(%ebp),%eax //pResTemp is the 1st local...
pushl %eax //... and &pResTemp is 3rd param
pushl $szQuery //2ns param
movl pConnection,%eax
pushl %eax //1st param
call SQLexec
addl $16,%esp //clear params
01 code is
.L64:
pushl $2
leal -16(%ebp),%esi //huh? which local is this?
pushl %esi
pushl $szQuery
movl pConnection,%eax
pushl %eax
call SQLexec
sscanf(PQgetvalue(pResTemp,0,1),"%ld",&lTotalInc);
o0 code is
leal -20(%ebp),%eax //push &lTotalInc,3rd param of sscanf()
pushl %eax // ... and 5th local
pushl $.LC3 //this is for "%ld",2nd param of sscanf()
pushl $1 //3rd param of PQgetvalue()
pushl $0 //2ns param of PQgetavalue
movl -4(%ebp),%eax //pResTemp is the 1st local
pushl %eax // ... and 1st param of PQgetvalue
call PQgetvalue
addl $12,%esp //clear stack after PQgetvalue()
movl %eax,%eax //huh???
pushl %eax //the res from PQgetvalue is 1st param of sscanf
call sscanf
addl $12,%esp //clear stack after sscanf
01 code is
leal -20(%ebp),%eax
pushl %eax
pushl $.LC3
pushl $1
pushl $0
movl -16(%ebp),%eax //huh?this should be again the 1st local
pushl %eax
call PQgetvalue
addl $12,%esp
pushl %eax
call sscanf
printf("Net access income: %ld\n",lTotalInc);
o0 & o1 code
movl -20(%ebp),%eax
pushl %eax
pushl $.LC32
call printf
...
And dont bother for clearing the stack in the O1 code - it is cleared
after the printf for all the above pushes with
addl $36,%esp
Any ideas?
Thanx for the attention!
Marin
-= What was my .signature guys? =-