I found this line in code generated by the MSVC compiler from Visual Studio 2008, while trying to figure out what seems to be a compiler bug:
movss dword ptr [this], xmm2
Although I do not think it is related to the bug I was looking for, I was like what the bleep? Storing a float value (completely unrelated to this
btw) in [this]
?
What exactly does that line do? Because 开发者_运维知识库I sure can't make sense of it! Or is the disassembly view playing tricks on me?
Providing some more assembly and/or source code would really help, but I see at least two possibilities:
this
is not a this pointer, but just a random register pointing to some memory area. The disassembler named it such because it was used as a this pointer previously in the function or for some other reason.this
does point to a class instance, and the class has a floating-point field as a first member and no virtual methods.
According to the Intel manual on x86 instructions, MOVSS copies the lowest 32 bits of the XMM register. (Each XMM register is 128 bits long.)
While the instruction is called "move scalar single-precision floating-point value", you should really treat it as "move a 32-bit value". The instruction does not care if the data is actually a float or not; it just copies the bits without interpretation.
In your case, the instruction copies the lowest 32 bits of XMM2 to the memory location pointed by this
. I think this is because your compiler is using XMM2 as a storage register (instead of using a general register like EAX).
The xmm registers don't necessarily contain float values. They are 128-bit wide SIMD registers which basically means that one or more values can be stored inside the SIMD register; usual configurations are 8 16-bit ints, 4 32-ints, 4 floats, 2 doubles; etc.
However, the compiler is free to put whatever it likes in there and as long as the first element of 'this' is 32-bits you're good.
精彩评论