汇编掩码逻辑问题
这很简单,但我还没有弄清楚。
这个问题是关于程序集mmx,但它是纯粹的逻辑。
想象一下以下场景:
MM0: 04 03 02 01 04 03 02 01 <-- input
MM1: 02 02 02 02 02 02 02 02
MM2: 04 03 02 01 04 03 02 01 <-- copy of input
after pcmpgtw MM0, MM1
MM0: FF FF 00 00 FF FF 00 00 <-- words where MM0 is greater than MM1 (comparing words)
MM1: 02 02 02 02 02 02 02 02
MM2: 04 03 02 01 04 03 02 01
after pand MM0, MM2
MM0: 04 03 00 00 04 03 00 00 <-- almost there...
MM1: 02 02 02 02 02 02 02 02
MM2: 04 03 02 01 04 03 02 01
我想要知道用 02 填充 MM0 的零。我想我必须在步骤 2 中反转 MM0 寄存器,将 FF 更改为 00,将 00 更改为 FF,然后对 MM1 执行 a 和 最后a 或 将两者合并。
如果我能够得到:
MM3: 00 00 FF FF 00 00 FF FF
then, pand MM2, MM3
MM1: 04 03 00 00 04 03 00 00
MM2: 00 00 02 02 00 00 02 02
finally por MM0, MM1 would give me the desired outcome:
MM0: 04 03 02 02 04 03 02 02 <-- Aha!
总结一下,如何将 MM3 寄存器设置为 00 00 FF FF 00 00 FF ?如何反转这些位,证明 MMX 寄存器中只有 AND、OR、XOR 和 NAND 指令可用?
任何答案都将不胜感激。谢谢。
This is very simple, but I haven't been able to figure it out yet.
This question is regarding a assembly mmx, but it's pure logic.
Imagine the following scenario:
MM0: 04 03 02 01 04 03 02 01 <-- input
MM1: 02 02 02 02 02 02 02 02
MM2: 04 03 02 01 04 03 02 01 <-- copy of input
after pcmpgtw MM0, MM1
MM0: FF FF 00 00 FF FF 00 00 <-- words where MM0 is greater than MM1 (comparing words)
MM1: 02 02 02 02 02 02 02 02
MM2: 04 03 02 01 04 03 02 01
after pand MM0, MM2
MM0: 04 03 00 00 04 03 00 00 <-- almost there...
MM1: 02 02 02 02 02 02 02 02
MM2: 04 03 02 01 04 03 02 01
What I want is to know fill the zeros of MM0 with 02. I suppose I would have to invert MM0 register in step2, changing the FF's to 00's and the 00's to FF's and then do a and to MM1 and finally a or to merge the two.
If I was able to get:
MM3: 00 00 FF FF 00 00 FF FF
then, pand MM2, MM3
MM1: 04 03 00 00 04 03 00 00
MM2: 00 00 02 02 00 00 02 02
finally por MM0, MM1 would give me the desired outcome:
MM0: 04 03 02 02 04 03 02 02 <-- Aha!
Summing up, how can I get that MM3 register as 00 00 FF FF 00 00 FF ? How can I invert the bits, proving I only have AND, OR, XOR and NAND instructions available in MMX registers?
Any answer is greatly appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用 pcmpgtw 生成掩码并交换参数的顺序。这样您就可以保存寄存器:
您可能必须复制 MM1 参数,因为它会在掩码生成期间被破坏,但这通常比加载/生成 64 位常量更快。
另一种方法是使用 PNAND:
You can also generate the mask using pcmpgtw and swap the order of the arguments. That way you can save a register:
You may have to make a copy of the MM1 argument because it will get destroyed during mask generation, but this is often faster than loading/generating a 64 bit constant.
A alternative way would be to use PNAND:
所以你有一个
mask = 0xFFFF0000FFFF0000;
然后:合并M0和M1是:
这会就地编辑M0和M1,因此它们的值被破坏。如果你想保留 M1 那么你需要将中间结果存储到临时变量/寄存器/内存中:
So you have a
mask = 0xFFFF0000FFFF0000;
then:merging M0 and M1 is:
this edits M0 and M1 in place so their values are destroyed. If you want to preserve M1 then you need to store the intermediate result into a temporary variable/register/memory: