简体   繁体   中英

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. The -masm=intel flag works as long as I do not reference and address any variables, which however I need to do.

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

Consider these parts of code (inte style assembly):

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.

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. How can I do this with AT & T syntax, best: can I do this with a g++ compiler using the -masm flag?

Is there any way at all using one assembly code for both VS and a g++ 4.6.1 based compiler

You can certainly tell GCC which SSE register to use for each variable:

register __m128i x asm("xmm6");

But I guess VS does not support that. (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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