News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Windows trashes xmm regs but not the FPU

Started by jj2007, September 30, 2011, 07:54:21 PM

Previous topic - Next topic

jj2007

While playing with a new macro (more), I found out that Windows trashes practically all XMM regs in certain message handlers. FPU regs, on the other hand, seem not to be affected.

QuoteWndProc proc uses esi ebx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL rc:RECT
   movd eax, xmm0   ; variable whose changes are monitored is xmm0
   inc msgCount
   deb 4, "xmm0 change for ...", chg:eax
   SWITCH uMsg

Sample output:
xmm0 change for ...
chg:eax         -2142149313
msgCount        11
# uMsg #        WM_PARENTNOTIFY

xmm0 change for ...
chg:eax         0
msgCount        12
# uMsg #        WM_WINDOWPOSCHANGING

xmm0 change for ...
chg:eax         40
msgCount        20
# uMsg #        WM_IME_SETCONTEXT

xmm0 change for ...
chg:eax         -143169644
msgCount        31
# uMsg #        WM_WINDOWPOSCHANGING

xmm0 change for ...
chg:eax         -1080457848
msgCount        36
# uMsg #        WM_SIZE

xmm0 change for ...
chg:eax         305419896
msgCount        43
# uMsg #        WM_MOVE

xmm0 change for ...
chg:eax         -2141256048
msgCount        46
# uMsg #        WM_GETICON

xmm0 change for ...
chg:eax         -1082123948
msgCount        48
# uMsg #        WM_CTLCOLOREDIT

xmm0 change for ...
chg:eax         0
msgCount        51
# uMsg #        WM_CTLCOLORSTATIC


Example attached.

drizz

The truth cannot be learned ... it can only be recognized.

jj2007

Thanks, drizz. Strangely enough, Dave writes in that thread that a guy named Jochen has mentioned this problem in an older thread. It's called memory problems ::)

Here is a good description of FXSAVE/FXRSTOR, in case somebody needs to save those valuable xmm regs. Note that saving is easy, but restoring is a bit problematic because you get also your FPU set to previously stored values.