简体   繁体   English

Intel 风格内联汇编和 AT&T 风格、C++ 中的变量引用

[英]Variable references in Intel style inline assembly and AT&T style, C++

I need to compile some assembly code in both Visual Studio and an IDE using G++ 4.6.1.我需要使用 G++ 4.6.1 在 Visual Studio 和 IDE 中编译一些汇编代码。 The -masm=intel flag works as long as I do not reference and address any variables, which however I need to do.只要我不引用和寻址任何变量,-masm=intel 标志就可以工作,但是我需要这样做。

I considered using intrinsics, but the compiled assembly is not optimal at all (for instance I cannot define the sse-register to be used and thus no pipe optimization is possible).我考虑过使用内在函数,但编译后的程序集根本不是最优的(例如,我无法定义要使用的 sse-register,因此不可能进行管道优化)。

Consider these parts of code (inte style assembly):考虑代码的这些部分(inte 样式程序集):

mov       ecx, dword ptr [p_pXcoords]
mov       edx, dword ptr [p_pYcoords]
movhpd    xmm6, qword ptr [oAvgX]
movhpd    xmm7, qword ptr [oAvgY]
movlpd    xmm6, qword ptr [oAvgX]
movlpd    xmm7, qword ptr [oAvgY]

where p_pXcoords and p_pYcoords are doublde* arrays and function parameters, oAvgX and oAvgY simpled double values.其中 p_pXcoords 和 p_pYcoords 是双精度数组和函数参数,oAvgX 和 oAvgY 是简单的双精度值。

Another line of code is this, which is in the middle of an assembly block:另一行代码是这样的,它位于汇编块的中间:

movhpd    xmm6, qword ptr [oAvgY]

in other words, I need to access variables and use them within specific sse registers in the middle of the code.换句话说,我需要访问变量并在代码中间的特定 sse 寄存器中使用它们。 How can I do this with AT & T syntax, best: can I do this with a g++ compiler using the -masm flag?我怎样才能用 AT & T 语法做到这一点,最好:我可以使用 -masm 标志用 g++ 编译器做到这一点吗?

Is there any way at all using one assembly code for both VS and a g++ 4.6.1 based compiler有没有办法对 VS 和基于 g++ 4.6.1 的编译器使用一个汇编代码

You can certainly tell GCC which SSE register to use for each variable:您当然可以告诉 GCC 为每个变量使用哪个 SSE 寄存器:

register __m128i x asm("xmm6");

But I guess VS does not support that.但我猜 VS 不支持。 (I am also a little surprised you need it for decent performance. Register assignment and instruction scheduling are two of the most basic things an optimizing compiler knows. You sure you enabled optimization :-) ?) (我也有点惊讶你需要它以获得良好的性能。寄存器分配和指令调度是优化编译器知道的两个最基本的事情。你确定你启用了优化:-)?)

I would probably just write two functions, one using intrinsics, and one using asm for whichever compiler does not know how to schedule instructions properly.我可能只写两个函数,一个使用内在函数,一个使用 asm 来处理不知道如何正确安排指令的编译器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM