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 |
where can I download "Intel C/C++ compiler add-on for Visual Studio "?
|
on vdown for example
|
Quote:
-Fyyre |
Quote:
Could you show us correct syntax for inline assembler which will Intel C++ Compiler accept ? -- Jump |
Inline asm is forbidden in studio compiler only. Guess they are too lazy to implement it. GCC and intel support it just fine.
|
Quote:
__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) |
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 |
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 |
Quote:
|
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:
|
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 |
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... |
I agree gigaman. It even more true when you consider the difficulty in writing a true x64 full function properly.
Git |
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 10:34. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX