What is the purpose of the movss command with [this] as the destination?

I found this line in the code generated by the MSVC compiler from Visual Studio 2008, trying to figure out what looks like a compiler error:

movss dword ptr [this], xmm2 

Although I do not think that this is due to the error I was looking for, it seemed to me what kind of sound it was? Saving a float value (not completely related to this btw) to [this] ?

What exactly does this line do? Because I can’t understand this! Or is it a kind of showdown in which tricks play?

+4
source share
3 answers

Providing some additional builds and / or source code will really help, but I see at least two possibilities:

  • this not this pointer, but just a random register pointing to some area of ​​memory. The disassembler called it that because it used to be used as that pointer in a function or for some other reason.

  • this points to an instance of the class, and the class has a floating point field as the first member and has no virtual methods.

+4
source

The xmm registers do not necessarily contain float values. They are 128-bit SIMD registers, which basically means that one or more values ​​can be stored inside the SIMD register; usual configurations - 8 16-bit ints, 4 32-ints, 4 floats, 2 two-local; etc.

However, the compiler has the right to place it where it likes, and as long as the first element of this is 32-bit, that you are good.

+3
source

According to Intel's x86 instruction manual , MOVSS copies the least significant 32 bits of the XMM register. (Each XMM register is 128 bits long.)

While the command is called "move scalar floating-point value with one precision", you should really treat it as "move 32-bit value." The instructions do not care if the data is really a float or not; it just copies the bit without interpretation.

In your case, the command copies the lowest 32 bits of XMM2 to the memory location indicated by this . I think this is because your compiler uses XMM2 as its storage register (instead of using a general register such as EAX).

+2
source

All Articles