The same operations performing different times

I am optimizing my code for my n-body simulator, and when profiling my code I saw this:

enter image description here

These two lines,


float diffX = (pNode->CenterOfMassx - pBody->posX);
float diffY = (pNode->CenterOfMassy - pBody->posY);

Where pNodeis a pointer to an object of the type Nodethat I defined and contains (with other things) 2 floats, CenterOfMassxandCenterOfMassy

Where pBodyis a pointer to an object of the type Bodythat I defined and contains (with other things) 2 floats, posXand posY.


It should take the same amount of time, but not do it. In fact, the first row takes into account 0.46% of the sample of functions, and the second - 5.20%.

Now I see that the second line contains 3 commands, and the first - only one.

My question is: why do they seem to do the same thing, but in practice different things?

+4
3

, , . , , . , , . , , (), (). , , , .

, . , . . , , . , , CPU, .

, , . , , 15 , .

, , , - , , , , . , .

, , 40-60 .

, , . , 4 .

+5

pNodes pBody. .

, C. 1 movss, 1- C 1 movss + 2 subss, 2- C, .

+3

. . , , , , .

, , , FP. , , , . .

, . , .

movq xmm0, [esi+30h]   # or movlps, but that wouldn't break the dep
movq xmm1, [edi]       # on the old value of xmm0 / xmm1
subps xmm0, xmm1

diffX diffY 0 1 xmm0, regs, .

+1

All Articles