c++ - Strange assembler generated by VS 2008 -
i have c++ function, looking like:
inline unsigned short function_name(float x, float y, somestruct *cfg)  {     int x_pos = (int)(x*2 + 0.5f);     int y_pos = (int)(y*2 + 0.5f);        int dict_index = x_pos + (y_pos * cfg->subdivisions_adj);      [...]   while somestruct declared as:
struct somestruct {  int subdivisions;  int subdivisions_adj;  [...] }   the generated assembly third line (int dict_index = [...]) is:
cvttss2si edi,xmm3 imul edi,[ecx+04h] movss xmm3,[ecx+0ch] movaps xmm4,xmm3 mulss xmm4,xmm0 addss xmm4,xmm1 cvttss2si eax,xmm4 add edi,eax   (see result amdcodeanalyst)
can explain assembly does? don't know why cvttss2si , movaps used @ all, aren't floating point numbers?
i using visual studio 2008 on windows 7, sse2 instruction set enabled.
what seeing compiler merges first 3 lines 1 intermingled sequence of instructions.
cvttss2si edi,xmm3   convert xmm3 float 32-bit int. presumably xmm3 contains float value of y_pos, , result of (int) on calculateion of y_pos. 
imul edi,[ecx+04h]   multiply cfg->subdivisions_adj (ecx = cfg, subdivisions_adj = offset of 4)
movss xmm3,[ecx+0ch]   would part of ... in cfg variable, suppose. 
movaps xmm4,xmm3 mulss xmm4,xmm0     adss xmm4,xmm1   calculate x_pos = x * 2 + 0.5
cvttss2si eax,xmm4   (int) x_pos;
add edi,eax   add x_pos y_pos * cfg->subdivisions_adj;
Comments
Post a Comment