News:

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

ABI/calling conventions for XMM registers

Started by jj2007, April 12, 2010, 08:55:05 AM

Previous topic - Next topic

jj2007

Just reading my way through Agner Fog's Calling conventions for different C++ compilers and operating systems (No. 5). In calling_conventions.pdf, chapter 6, Register Usage, you will find Table 4 explaining what are scratch registers (eax, edx, ...) and what are callee-save registers (esi, edi, ...).

Unfortunately, the doc is not so explicit on the use of xmm registers. For 32-bit Windows, they are declared scratch registers, i.e. they have the same status as eax, ecx, edx. However, that would imply they can be destroyed by a call to a Windows API, analogously to what happens to eax, ecx, edx. My impression is that this is not the case. Is anybody aware of a document saying they are safe (or unsafe)?

sinsi

I think you said it yourself - they 'can' be destroyed. Sounds like MS reserving them forever.
The 64-bit ABI is different though.

edit: http://msdn.microsoft.com/en-us/library/9z1stfyw(v=VS.80).aspx
Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007

Quote from: sinsi on April 12, 2010, 09:05:43 AM
I think you said it yourself - they 'can' be destroyed. Sounds like MS reserving them forever.

Nasty. I checked MasmBasic, and it seems ok - no API calls in between. Fortunately, most people would use xmm regs only in speed-critical parts of their code; and it's unlikely that you call Windows in any loop where speed matters :bg

hutch--

JJ,

I gather there is some Windows code OS code) that uses MMX registers and does not clean up with EMMS so if you are not careful it messes up FP values you may have had in FP registers.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: hutch-- on April 12, 2010, 10:46:47 AM
JJ,

I gather there is some Windows code OS code) that uses MMX registers and does not clean up with EMMS so if you are not careful it messes up FP values you may have had in FP registers.

Hutch,
I never use MMX. The EMMS is just too expensive.

hutch--

JJ,

Its only a problem if you mix FP and MMX otherwise you can just use MMX registers like anything else. I confess I do the same and just use XMM registers but as long as you are not using FP and don't need 128 bit sized registers MMX is fine.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php