以 [this] 作为目标的 movss 指令的目的是什么?

发布于 2024-11-23 19:25:39 字数 263 浏览 3 评论 0原文

我在 Visual Studio 2008 的 MSVC 编译器生成的代码中发现了这一行,同时试图找出似乎是编译器错误的内容:

movss dword ptr [this], xmm2

虽然我不认为它与我正在寻找的错误有关,但我就像哔?在 [this] 中存储浮点值(顺便说一句,与 this 完全无关)?

那条线到底有什么作用?因为我确实无法理解!或者是反汇编视图在欺骗我?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

弱骨蛰伏 2024-11-30 19:25:39

提供更多的汇编和/或源代码确实会有所帮助,但我至少看到两种可能性:

  1. this 不是 this 指针,而只是指向某个内存区域的随机寄存器。反汇编程序如此命名它是因为它之前在函数中用作 this 指针或出于其他原因。

  2. this 确实指向一个类实例,并且该类有一个浮点字段作为第一个成员,并且没有虚方法。

Providing some more assembly and/or source code would really help, but I see at least two possibilities:

  1. 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.

  2. this does point to a class instance, and the class has a floating-point field as a first member and no virtual methods.

不回头走下去 2024-11-30 19:25:39

根据Intel x86指令手册,MOVSS复制最低32位XMM 寄存器。 (每个 XMM 寄存器都是 128 位长。)

虽然该指令称为“移动标量单精度浮点值”,但您实际上应该将其视为“移动 32 位值”。该指令并不关心数据是否实际上是浮点数;它只是复制这些位而不进行解释。

在您的例子中,指令将 XMM2 的最低 32 位复制到 this 指向的内存位置。我认为这是因为你的编译器使用 XMM2 作为存储寄存器(而不是使用像 EAX 这样的通用寄存器)。

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).

南烟 2024-11-30 19:25:39

xmm 寄存器不一定包含浮点值。它们是 128 位宽的 SIMD 寄存器,这基本上意味着一个或多个值可以存储在 SIMD 寄存器内;通常的配置是 8 个 16 位整型、4 个 32 位整型、4 个浮点型、2 个双精度型;然而

,编译器可以自由地在其中放置任何它喜欢的内容,只要“this”的第一个元素是 32 位就可以了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文