syntax converter for inline assembly?
I am porting my 3D simulation/graphics engine from windoze/OpenGL to fedora8-linux/OpenGL (with the eclipse IDE). The latest set of errors are caused by the SIMD/SSE2 inline assembly language I wrote for the most speed-critcal routines: (1) multiply two 4x4 matrices; (2) multiply 4x4 matrix times 4x1 vectors; (3) misc.
The inline assembly language syntax is wildly different, which makes me wonder. Has anyone written a converter from conventional "intel" syntax to "gcc" syntax? |
Quote:
Code:
asm("movl %ecx, %eax"); Code:
asm(".intel_syntax noprefix\n\t" As for 2., I am not aware of any tool which does this automatically. Personally, I am unfamiliar with using inline assembly in microsoft compilers. |
Within, say, the Linux source-code ("arch" subdirectory) there are plenty of examples of asm-routines in gcc.
One issue that you need to be very mindful of in Linux-land is the plethora of architectures that are supported! One version of your "speed-critical routines," available as a configure-option, must be straight-C that is guaranteed to work. You might also find that this version, with gcc, is fast enough... I trust that there will be no difficulties using your software with a usual configure/make sequence on my ... PowerPC based Macintosh. Or my 64-bit Intel uber-system. |
Quote:
Would like to use them, but having grown up and spent many, many years with Intel syntax, I find AT&T quite unwieldy :-) Would be nice to be able to get the tools to work the way I want them to... |
Quote:
|
Additionally, gcc has the “-masm=intel” switch which says to make the intermediary gcc output itself in intel syntax. I am not aware if there is clashing if you don’t specify this switch to gcc when you do as I showed in post 2. I think a more correct version (if you don’t use that switch) would be to tell gas that the rest of the code should be in att syntax. E.g.,
Code:
asm(".intel_syntax noprefix\n\t" Edit: that line is required. |
Okay, I did some experimenting with simple inline assembly, and here’s what I found out. I will give four different versions of the same program.
inline1.c Code:
int main() Code:
int main() Code:
int main() Code:
int main() The second version will do the exact same thing, but will temporarily change to intel syntax without prefixes, and subsequently change back to att syntax with prefixes. The third one will change to intel syntax without register prefixes, so in order to use it, you need to pass “-masm=intel”. Without that switch, the code will not correctly assembly. There is a commented line which tells the assembler that the following code has prefixed registers. This line might make the program more correct, but is not necessary, since a prefixed register is still accepted even in noprefix mode. The fourth program uses the compiler’s -masm=intel switch, which means that it will agree with all the code emitted by the compiler. Notice that I did use prefixes here, since -masm=intel only changes the addressing and operand order, but does not (by itself) remove prefixes. Had I neglected the prefixes, the assembler would have errored out. So if you followed that, these are some variations on simple gcc inline assembly in various syntaxes. I am not sure how this plays with extended inline assembly (where you normally have doubly-prefixed registers), but I suspect you use the form of the fourth program. |
basic versus extended assembly language
Quote:
Here is a question that may (or may not) make the "extended syntax" issue easy for me to deal with. I only have assembly language a few places, and every one is a long section of SIMD/SSE2+ math. Nonetheless, the first thing each section does is to load the addresses of 2 or 3 input arrays and 1 or 2 output arrays into registers, along with a couple counts. These are all addresses or values of C variables, assigned to the registers at the beginning of the assembly language section. Thus, all 6 of the x86 registers are clobbered (except ebp and esp, of course). I really don't know what I'm talking about here, so I want to ask whether the following makes sense. It seems to me that I can avoid the excrutiating hassle of converting ANY of my assembly language to "extended syntax" in one of two ways: 1: At the very end of the section, just add one assembly language statement with a "nop" --- but specify all 6 registers as "clobbered". Not sure whether this means I need to put all the code inside one literal string inside one one single asm("xxx") or not, but I would prefer NOT (I prefer doing a mass edit that puts one asm("xxx") on each line of assembly - though frankly, it should be okay either way). 2: These sections of assembly language are large (dozens of lines of assembly), AND typically execute/loop many times before they complete (transforming dozens of vertex coordinates/normal-vectors/tangent-vectors/bitangent-vectors from one coordinate system to another). Therefore, the overhead added to push all 6 registers at the beginning, then pop them back into place at the end imposes trivial overhead --- in which case the whole block of code clobbers no registers at all. Still, I may need to write a few lines of "extended assembly" at the beginning, since the C variables I need to put into registers are either local variables, or structure elements inside an array element (complex to compute in assembly). But that is a small price to pay, compared to converting the whole pile to "extended assembly". What say you about these ideas? Oh, I do need to make sure the C compiler doesn't try to jam any other code inside my assembly language OR change where the assembly language code happens inside my function! Hopefully it would not be so naughty as to do such a thing. Or would it? OOPS. Later worry... Will the .intex_syntax directive make the assembler correctly interpret all the other aspects of intel assembly language in the code - like array/offset addressing, etc? For example, will it assemble the following lines? <code> mov edi, r // r is a local variable mloopasm: // a label movddup xmm0, [edx + 0x20] // offset addressing add edx, 0x20 // hexadecimal value jnz mloopasm // label reference </code> |
Quote:
Quote:
Quote:
As for 2, it seems to accomplish what you want, but if you could accomplish the same thing by putting everything in extended assembly. Quote:
Code:
register int *foo asm ("edi"); Quote:
Quote:
|
can someone please tell me the inline assembly code to find the absolute value of a double variable ??
it is very urgent ... reply soon |
Quote:
|
i know, i thought of it.
if i and the number as follows: Number = Number AND $7FFFFFFFFFFFFFFF .. i'll probably get the result but i dont have any clue of the syntax .. could u help me out with that ? |
Quote:
|
All times are GMT -5. The time now is 03:47 PM. |