ASM - 使用扩展指令执行(int + int)* float常量的最佳方法是什么?

时间:2014-10-22 12:04:21

标签: c++ winapi assembly sse mmx

我正在响应WM_MOUSEMOVE在opengl应用程序中移动我的相机。

该函数采用STARTING POINT(来自wm_lbuttondown命令的旧lParam)并从STARTING POINT中减去CURRENT POINT,并将结果乘以某个浮点系数。

class cam
{
 int sp; //staring point saved here
 float x_coeff;//the addresses of sp and x_coeff are aligned , I can load them both as a quad-word later
}

case WM_LBUTTONDOWN:
    cam.sp=lParam;
    return 0;
case WM_MOUSEMOVE:
    cam.drag_camera(lParam);
    return 0;

cam::drag_camera(LPARAM lParam)
{
  float step=0.001;
  short old_x=sp&0xFFFF;
  short old_y=sp>>16;
  short current_x=lParam&0xFFFF;
  short curretn_y=lParam>>16;
  x_move=(old_x-current_x)*step;
  .... do something with the step
}

好的,它有效,但我正在尝试使用asm和所有那些不错的寄存器。 所以这是我的代码同样的东西,但使用mmx寄存器

cam::drag_camera(LPARAM lParam)
{
  _asm
  { 
    movd mm0,lParam       //MOVE current mouse LPARAM point to mm0    - mm0 = 00:00:cy:cx
    movq mm1,[ebx+40h]    //MOVE starting mouse point LPARAM to low dword of mm1 and x_coeff in  high dword of mm1   - mm1 = x_coeff:sy:sx
    psubw mm1,mm0         //SUB current - starting mm1 = x_coeff:(sy-cy):(sx-cx)
    punpcklwd mm2,mm1     //PUT packed word result to mm2 double words   m2=00:(sy-cy):00:(sx-cx)
    psrad mm2,16          //Sign extend both double words of the result  m2=(sy-cy):(sx-cx)
    cvtpi2ps xmm7,mm2     //MOVE X Y result to XMM7  xmm7 = 0000:0000:sy-cy:sx-cx
    psrlq mm1,32          //SHIFT the x_coeff from the high dword to the left m1=00:00:x_coeff 
    movq2dq  xmm6,mm1     //SEND coeff to xmm6 low dword    xmm6=0000:0000:0000:x_coeff
    shufps xmm6,xmm6,00h  //SHUFFLE x_coeff everywhere      xmm6=x_coeff:x_coeff:x_coeff:x_coeff
    mulps xmm7,xmm6       //MULTIPLY 0:0:Y:X by x_coeff     xmm7=0000:0000:(sy-cy)*x_coeff:(sx-cx)*x_coeff

  }
}

问题是 - 这是一种做这么简单的运动的快速方法,还是我可以选择其他方式做这些事情?感谢

0 个答案:

没有答案
相关问题