flat assembler
Message board for the users of flat assembler.

Index > Windows > QueryPerformanceFrequency trashes XMM0-XMM5 registers

Author
Thread Post new topic Reply to topic
ejamesr



Joined: 04 Feb 2011
Posts: 52
Location: Provo, Utah, USA
ejamesr 13 Sep 2013, 03:17
I'm using 64-bit Windows 7 (SP1). The QueryPerformanceFrequency functions trashes xmm0 thru xmm5. Is anyone aware of other Windows functions that trash registers unexpectedly? Run this code on your system to see if it behaves. It sets all registers to known values; place a break point just before ExitProcess and look at the registers. I saw one blog comment about this a year ago, stating that 32-bit Windows 7 works properly.
Code:
format PE CONSOLE 4.0
display "Compression tool being compiled...", 13, 10
        stack   4000h, 4000h
        entry Start        
        include 'Win32A.Inc'

section '.data' data readable writeable
align 4
        PerfFrequency   dd      ?
align 16
label XmmData xword
        times 128 db %  ; load consecutive 8-bit values
label FpuData qword
        rept 8 n:1 { dq n#.0 }

section '.code' code readable executable
Start:
        ; Load all regs with known values...
        rept 8 n:0 {
          movdqa xmm#n, [XmmData + n*16]        ; Load xmm regs
        }
        rept 8 n:0 { fld   [FpuData + n*8] }
        irps reg, eax ebx ecx edx esi edi ebp
        { or reg, -1 }
        invoke  QueryPerformanceFrequency, PerfFrequency
        invoke  ExitProcess
        
section '.idata' import data readable writeable
        library kernel32,'KERNEL32.DLL',user32,'USER32.DLL',gdi32,'GDI32.DLL'
        include 'API\Kernel32.Inc'
    

After invoking QueryPerformanceFrequency, the lower 5 xmm registers are set to 0 (this is BAD!!), and eax, ecx, and edx are modified (this is OK). The FPU registers are not affected (this is good!).

Eric
Post 13 Sep 2013, 03:17
View user's profile Send private message Send e-mail Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 794
Location: Adelaide
sinsi 13 Sep 2013, 03:27
Post 13 Sep 2013, 03:27
View user's profile Send private message Reply with quote
ejamesr



Joined: 04 Feb 2011
Posts: 52
Location: Provo, Utah, USA
ejamesr 13 Sep 2013, 03:51
Thanks for the quick reply. I've just started using xmm registers and have yet to do 64-bit programming, so that was new to me that xmm0 - xmm5 were volatile.

Eric
Post 13 Sep 2013, 03:51
View user's profile Send private message Send e-mail Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 13 Sep 2013, 06:03
Are not they also volatile in 32 bit code as well?
I know that some of intel's opengl implementations trash xmm0-xmm6
Post 13 Sep 2013, 06:03
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.