Re: [Dev-C++] Optimizing C code, what is best??
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-05-30 18:13:29
|
Some sugestions:
1 - you are summing 16-bit numbers into 32-bit, but returning 64-bit.
2 - you are sending in wRow,wColFrom,wColTo as references, despite not
having any intention of sending back any change.
3 - you are using a lot of variables in the loop.
4 - you are using a lot of indexing in the loop.
A suggested change might be:
DWORD CMyClass::computeDistSquare(const short *src,
const WORD wRow,
const WORD wColFrom,const
WORD wColTo) const
{
DWORD dwDist2 = 0;
int iA;
short *sp = sData[wRow] + wColFrom;
short *end = src + wColTo;
src += wColFrom;
while (src <= end) {
iA = *src++ - *sp++;
dwDist2 += iA*iA;
}
return dwDist2;
}
Now the loop uses 5 variables instead of 7 - each variable just 32-bit
large and fitting in a single register.
/Per W
On Fri, 30 May 2003, Zodiaq wrote:
> Hello All Dev-cpp-users,
>
> there is one function in my program that needs some optimization...
> the problem is about computing distance between parts of two
> vectors... currently it is done like this:
>
> DWORD64 computeDistance( short *src, const WORD &wRow, const WORD
> &wColFrom, const WORD &wColTo ) const
> {
> DWORD dwDist = 0;
> INT iA;
> short *sP = sData[ wRow ];
> for( WORD wCol = wColFrom; wCol <= wColTo; ++wCol )
> {
> iA = src[ wCol ] - sP[ wCol ];
> dwDist += iA * iA;
> }
> return dwDist;
> }
>
> src is element I want to compute distance from specified element of
> big array of rows... gprof shows that this function takes over 90% of
> total program time...
>
> well, I know it is not about DevC++, but since I made progs under it
> and this is quite simple problem, I hope that someone can and will
> help me...
>
> The best solution for me would be ASM code optimized for AMD Athlon
> processor (for my computer, which as only one will run this code). For
> someone with good knowledge of ASM this is only few moments, and for
> me great deal of work - I don't know ASM a bit... so please someone
> help me... thank you in advance!
>
> --
> regards, Zodiaq...
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: eBay
> Get office equipment for less on eBay!
> http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|