Solved
Code optimization
Posted on 2004-10-12
Dear all,
I have been trying to optimize the following code in assembly or sse/mmx.
Can anyone help?
THanks
With Beat Regards
HCK
typedef struct PslRbpFeature {
int noOfBlocks;
int* points;
int* specs;
int** sumPtr;
double** sqSumPtr;
float invArea;
int refWeight;
int id;
int winWidth;
int winHeight;
//precalculation
float normStFactor;
}PslRbpFeature;
int evalRbpFeature(
PslRbpFeature* rb,
int offset,
float* strength
){
*strength=0.0f;
float strength_plus=0.0f;
float strength_minus=0.0f;
int count_plus=0;
int count_minus=0;
int** sumPtr0=rb->sumPtr ;
int** sumPtr1=sumPtr0+1;
int** sumPtr2=sumPtr0+2;
int** sumPtr3=sumPtr0+3;
int* p0 = *sumPtr0 +offset;
int* p1 = *sumPtr1 +offset;
int* p2 = *sumPtr2 +offset;
int* p3 = *sumPtr3 +offset;
int sRef = *p0 - *p1 - *p2 + *p3 ;
int N=rb->noOfBlocks-1;
strength_plus=0.0;//sRef;
count_plus=N;
sRef/=N;
int key=0;
for(int n=0; n<N; n++){
sumPtr0 +=4;
sumPtr1 +=4;
sumPtr2 +=4;
sumPtr3 +=4;
p0=*sumPtr0 +offset;
p1=*sumPtr1 +offset;
p2=*sumPtr2 +offset;
p3=*sumPtr3 +offset;
int s = *p0 - *p1 - *p2 + *p3 ;
s -= sRef;
if(s<0) {
strength_minus += s;
count_minus++;
key |= 1 << n ;
}
}
if(!key) return key;
strength_plus -= strength_minus;
count_plus -= count_minus;
*strength=strength_plus/count_plus-strength_minus/count_minus;
*strength *= rb->normStFactor;
return key;
}