Thursday 15 April 2010

c++ - ASM - What is the best way to perform (int + int)* float constant with extended instructions? -



c++ - ASM - What is the best way to perform (int + int)* float constant with extended instructions? -

i'm doing function in responce wm_mousemove move photographic camera in opengl application.

the function take starting point (old lparam wm_lbuttondown command)and subtract current point starting point, , multiply result floating point coefficient.

class cam { int sp; //staring point saved here float x_coeff;//the addresses of sp , x_coeff aligned , can load them both quad-word later } case wm_lbuttondown: cam.sp=lparam; homecoming 0; case wm_mousemove: cam.drag_camera(lparam); homecoming 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; .... step }

ok, works, i'm trying practice in using asm , nice registers. here code same thing using mmx registers

cam::drag_camera(lparam lparam) { _asm { movd mm0,lparam //move current mouse lparam point mm0 - mm0 = 00:00:cy:cx movq mm1,[ebx+40h] //move starting mouse point lparam low dword of mm1 , 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 mm2 double words m2=00:(sy-cy):00:(sx-cx) psrad mm2,16 //sign extend both double words of result m2=(sy-cy):(sx-cx) cvtpi2ps xmm7,mm2 //move x y result xmm7 xmm7 = 0000:0000:sy-cy:sx-cx psrlq mm1,32 //shift x_coeff high dword left m1=00:00:x_coeff movq2dq xmm6,mm1 //send coeff 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 x_coeff xmm7=0000:0000:(sy-cy)*x_coeff:(sx-cx)*x_coeff } }

the question - quick method of doing such simple athirmetic or take other way of doing things? thanks

c++ winapi assembly sse mmx

No comments:

Post a Comment