Author Topic: XMM regs destroyed.  (Read 8915 times)

KeepingRealBusy

  • Member
  • ***
  • Posts: 426
XMM regs destroyed.
« on: November 26, 2013, 08:37:14 AM »
I just ran into a problem. I do not remember that this was true before, at least with 512 sector files, but I just found out that an API CreateFile for read destroys at least xmm0, xmm1 and xmm2 when dealing with 4096 BYTE sector drives. Is this something  new with Win 7?

Does anyone know what other APIs may destroy the xmm regs?

Dave

qWord

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: XMM regs destroyed.
« Reply #1 on: November 26, 2013, 09:17:12 AM »
for x32 all XMM registers are volatile, thus any API can "destroy" the registers. For x64 XMM6-15 are nonvolatile (see fastcall).
MREAL macros - when you need floating point arithmetic while assembling!

KeepingRealBusy

  • Member
  • ***
  • Posts: 426
Re: XMM regs destroyed.
« Reply #2 on: November 26, 2013, 09:29:43 AM »
I don't know whether to thank you or not, but thank you for the info.

Yes, I'm using x32 code on my Win7 64 bit system. I have never tried 64 bit assembly.

I generally open a file, set up registers, then process the data. In my current case, I was trying to process many files one after the other and wanted to hold data in the xmms.

I guess, I will have to just use data storage. Would have been nice to be able to use regs.

Dave.

jj2007

  • Member
  • *****
  • Posts: 9686
  • Assembler is fun ;-)
    • MasmBasic
Re: XMM regs destroyed.
« Reply #3 on: November 26, 2013, 09:45:48 AM »
I don't know whether to thank you or not, but thank you for the info.

qWord is only the messenger ;)

Here is an old thread discussing this problem. It's indeed only x32 code on Win7-64 that trashes xmm regs.

KeepingRealBusy

  • Member
  • ***
  • Posts: 426
Re: XMM regs destroyed.
« Reply #4 on: November 26, 2013, 01:49:19 PM »
Oh, I'm not unhappy with QWord. I'm not unhappy with the messenger, just unhappy with the message. The fact that this is only with x32 code on an x64 platform explains why I have not see much of this as a problem before (since 2000 or so I have been on an XP system, just recently moved to this Win 7 laptop).

This is not a disaster, I just have to save and reload the registers around the file open call. I will, however, not embed this save/restore in my wrapper for the I/O since I do not
normally need to preserve the xmm regs around any API call.

Dave.

FORTRANS

  • Member
  • *****
  • Posts: 1056
Re: XMM regs destroyed.
« Reply #5 on: November 27, 2013, 12:26:10 AM »
Hi,

   Would running the programs in some sort of virtual PC have
any effect on preserving the registers?

Regards,

Steve N.

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: XMM regs destroyed.
« Reply #6 on: November 27, 2013, 03:06:05 AM »
i think it's a matter of knowing, in advance, that the registers are destroyed
he's now in a mode where he is trying to make his existing code work correctly
but, had he known, he would have designed the program differently

KeepingRealBusy

  • Member
  • ***
  • Posts: 426
Re: XMM regs destroyed.
« Reply #7 on: November 27, 2013, 03:10:01 AM »
Steve,

I haven't played around with virtual boxes. My impression is that executing in a virtual box would cause execution times to get longer. I am trying to get things to run faster, not slower.

My fixes for the problem worked.

dedndave,

You posted your reply as I was typing mine. Yes the fixes worked just fine.

Dave.

FORTRANS

  • Member
  • *****
  • Posts: 1056
Re: XMM regs destroyed.
« Reply #8 on: November 27, 2013, 03:19:07 AM »
Hi Dave

I haven't played around with virtual boxes. My impression is that executing in a virtual box would cause execution times to get longer. I am trying to get things to run faster, not slower.

   I think you are right in assuming it would be slower.  I guess
I was just curious as too how effective a virtual PC might be.

Quote
My fixes for the problem worked.

   Good.

Regards,

Steve N.

jj2007

  • Member
  • *****
  • Posts: 9686
  • Assembler is fun ;-)
    • MasmBasic
Re: XMM regs destroyed.
« Reply #9 on: November 27, 2013, 06:43:40 AM »
executing in a virtual box would cause execution times to get longer.

The speed loss is hardly measurable. Virtual PCs  and (slow) emulators are completely different animals.

raymond

  • Member
  • **
  • Posts: 234
    • Raymond's page
Re: XMM regs destroyed.
« Reply #10 on: November 27, 2013, 02:12:10 PM »
The XMM instructions are processed by the same registers as those used for processing floating point instructions (the FPU). Ever since those XMM instructions have been available, the MS staff have used them to perform most (if not all, even for 2+2) number crunching. Any API requiring whatever number crunching, such as sizing a window, would thus destroy any data in those registers. This has been reported many, many years ago in this forum.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: XMM regs destroyed.
« Reply #11 on: November 27, 2013, 02:20:36 PM »
you're thinking of MMX registers, Ray

raymond

  • Member
  • **
  • Posts: 234
    • Raymond's page
Re: XMM regs destroyed.
« Reply #12 on: November 27, 2013, 02:42:34 PM »
 :redface:
Must have been reading it backwards.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: XMM regs destroyed.
« Reply #13 on: November 28, 2013, 02:38:47 AM »
:redface:
Must have been reading it backwards.

This can sometimes happen. Never mind.

Gunther
Get your facts first, and then you can distort them.

Jean-Marie

  • Regular Member
  • *
  • Posts: 17
  • Waiting for TASM 6.0
Re: XMM regs destroyed.
« Reply #14 on: November 28, 2013, 04:31:37 PM »
Greetings to all,
I was not aware of this particularity either. In my (32 bits) project, I keep 2 variables in xmm0 & xmm2, and in some cases, I call ReadFile & Writefile APIs.
Could someone using Windows 64 bits confirm me if those 2 functions thrash xmm registers as well, please ?

Or better, run my compression program on enwik9 benchmarking file ( http://mattmahoney.net/dc/enwik9.zip ) , and tell me if the compressed filesize is still 183 459 153 bytes?
Syntax would be: SMAC /c enwik9
Look out: compression uses arithmetic coding+context mixing, so it is very slow (70 minutes on my Core 2 duo Merom).

Thanks for your help!