Exetools

Exetools (https://forum.exetools.com/index.php)
-   x64 OS (https://forum.exetools.com/forumdisplay.php?f=44)
-   -   X64 inline asm (https://forum.exetools.com/showthread.php?t=12730)

Fyyre 04-08-2010 07:28

X64 inline asm
 
Hi all,

I discovered this for myself recently, and wanted to share. If this is already well known, disregard =)

The Intel C/C++ compiler add-on for Visual Studio will allow you to still use inline assembly language on the X64 platform. The syntax and such is close enough to MSVC that modifications needed to code to compile existing code with the Intel compiler are minimal at best, IMO.

-Fyyre

winndy 04-08-2010 17:13

where can I download "Intel C/C++ compiler add-on for Visual Studio "?

Av0id 04-08-2010 17:59

on vdown for example

Fyyre 04-08-2010 22:44

Quote:

Originally Posted by winndy (Post 67561)
where can I download "Intel C/C++ compiler add-on for Visual Studio "?

I recommend downloading it straight from Intel's site http://software.intel.com/en-us/arti...uation-center/ then use any TBE Intel.lic to activate it during the installation ;) Can PM me if you need one.

-Fyyre

jump 04-08-2010 23:10

Quote:

Originally Posted by Fyyre (Post 67554)
Hi all,

I discovered this for myself recently, and wanted to share. If this is already well known, disregard =)

The Intel C/C++ compiler add-on for Visual Studio will allow you to still use inline assembly language on the X64 platform. The syntax and such is close enough to MSVC that modifications needed to code to compile existing code with the Intel compiler are minimal at best, IMO.

-Fyyre

Very interesting news. I have read everywhere that inline assmbler isnt possible on x64 architecture.
Could you show us correct syntax for inline assembler which will Intel C++ Compiler accept ?

--
Jump

Archer 04-09-2010 00:43

Inline asm is forbidden in studio compiler only. Guess they are too lazy to implement it. GCC and intel support it just fine.

Fyyre 04-09-2010 10:56

Quote:

Originally Posted by jump (Post 67570)
Very interesting news. I have read everywhere that inline assmbler isnt possible on x64 architecture.
Could you show us correct syntax for inline assembler which will Intel C++ Compiler accept ?

--
Jump

It is virtually the same as MSVC:

__asm mov rbx, rax;

or

__asm
{
...
}

emit format is:

__asm __emit 0xCC;

sample function:

Code:

__declspec(naked) int __fastcall strcmpW(const wchar_t *s1, const wchar_t *s2)
{
        __asm {
        push rdi
        push rsi
        mov rdi, rdx
        mov rsi, rcx
        or rcx, -1
        xor rax, rax
        repne scasw
        not rcx
        mov rdi, rdx
        repe cmpsw
        xor rdx, rdx
        mov ax, [rsi - 2]
        mov dx, [rdi - 2]
        sub rax, rdx
        pop rsi
        pop rdi
        ret
        }
}


jump 04-09-2010 16:08

So if i understand correct, the inline assmbler have to be also x64 not x86,right?
So you cant tak source with inline x86 assembler and think it will be compileable for x64 architecture. You have to rewrite it, right?

--
Jump

Git 04-09-2010 18:45

I think if you are proposing to write a full function in asm as opposed to a small piece of inline code, then you have to be very careful with the prolog and epilog, and especially careful with the structured exception handling. In providing inline asm, Intel assume you are fully conversant with X64.

Git

Av0id 04-09-2010 20:39

Quote:

So if i understand correct, the inline assmbler have to be also x64 not x86,right?
intel compiler supports both x86 and x64 assembler code

Fyyre 04-11-2010 15:32

x86 or x64 depends upon your project (like Av0id said above).

Regarding re-writing of code, how big of task depends on the code itself...

i.e. the above strcmpW function, he only require change of registers from e*x to r*x....

AFAIK the calling covention always __fastcall on X64, more simple than x86 assembly, imo.

-Fyyre

Quote:

Originally Posted by jump (Post 67583)
So if i understand correct, the inline assmbler have to be also x64 not x86,right?
So you cant tak source with inline x86 assembler and think it will be compileable for x64 architecture. You have to rewrite it, right?
Jump


Git 04-11-2010 18:38

There's some good info on MSDN.

Calling convention
Parameter passing
Exception handling

The exception handling page has a link to MASM macros for Prolog and Epilog.

THE site for driver writers, OSR, has some info too. There is good info there in all the subtopics on exception handling, prolog & epilog, stack usagae, etc.

Git

gigaman 04-17-2010 17:13

For the inline assembler, keep in mind that it heavily "corrupts" the optimization of the surrounding C code (well, at least it always did for MSVC, donno about Intel, but would guess it's the same). When the compiler reaches the asm block, it's a "black box" for it... so it dumps all the register values into local variables, appends the assembler block... and then loads the register values back.
So, it's better to write the whole function in inline assembler - than just a part, in which case the result might be worse than keeping it all in C, because the rest of the function is optimized much worse than if it were all in C.

It would be interesting to know what led Microsoft to bad inline assembler in x64...

Git 04-17-2010 18:18

I agree gigaman. It even more true when you consider the difficulty in writing a true x64 full function properly.

Git

gigaman 04-21-2010 04:37

Well, I probably shouldn't have written "whole function"... let's say the whole block of code where the performance is of interest.
Sure, you may do basic parameter checking in C, allocate the local variables... and then use the inline asm to do the real job. So, you don't have to worry about stack allocation, you have access to fields of C structures... and x64 asm is basically the same as x86, so I wouldn't call it difficult ;)


All times are GMT +8. The time now is 19:09.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX