Exetools  

Go Back   Exetools > General > x64 OS

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2010, 07:28
Fyyre's Avatar
Fyyre Fyyre is offline
Fyyre
 
Join Date: Dec 2009
Location: 0°N 0°E / 0°N 0°E / 0; 0
Posts: 255
Rept. Given: 71
Rept. Rcvd 85 Times in 38 Posts
Thanks Given: 136
Thanks Rcvd at 331 Times in 110 Posts
Fyyre Reputation: 85
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
Reply With Quote
The Following User Says Thank You to Fyyre For This Useful Post:
Indigo (07-19-2019)
  #2  
Old 04-08-2010, 17:13
winndy winndy is online now
VIP
 
Join Date: Sep 2005
Posts: 236
Rept. Given: 104
Rept. Rcvd 26 Times in 12 Posts
Thanks Given: 27
Thanks Rcvd at 16 Times in 13 Posts
winndy Reputation: 26
where can I download "Intel C/C++ compiler add-on for Visual Studio "?
Reply With Quote
The Following User Says Thank You to winndy For This Useful Post:
Indigo (07-19-2019)
  #3  
Old 04-08-2010, 17:59
Av0id Av0id is offline
VIP
 
Join Date: Jan 2006
Posts: 399
Rept. Given: 112
Rept. Rcvd 111 Times in 69 Posts
Thanks Given: 0
Thanks Rcvd at 15 Times in 15 Posts
Av0id Reputation: 100-199 Av0id Reputation: 100-199
on vdown for example
Reply With Quote
The Following User Gave Reputation+1 to Av0id For This Useful Post:
winndy (04-09-2010)
The Following User Says Thank You to Av0id For This Useful Post:
Indigo (07-19-2019)
  #4  
Old 04-08-2010, 22:44
Fyyre's Avatar
Fyyre Fyyre is offline
Fyyre
 
Join Date: Dec 2009
Location: 0°N 0°E / 0°N 0°E / 0; 0
Posts: 255
Rept. Given: 71
Rept. Rcvd 85 Times in 38 Posts
Thanks Given: 136
Thanks Rcvd at 331 Times in 110 Posts
Fyyre Reputation: 85
Quote:
Originally Posted by winndy View Post
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
Reply With Quote
The Following User Gave Reputation+1 to Fyyre For This Useful Post:
winndy (04-09-2010)
The Following User Says Thank You to Fyyre For This Useful Post:
Indigo (07-19-2019)
  #5  
Old 04-08-2010, 23:10
jump jump is offline
VIP
 
Join Date: Jan 2009
Posts: 305
Rept. Given: 84
Rept. Rcvd 51 Times in 26 Posts
Thanks Given: 22
Thanks Rcvd at 41 Times in 27 Posts
jump Reputation: 51
Quote:
Originally Posted by Fyyre View Post
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
Reply With Quote
The Following User Says Thank You to jump For This Useful Post:
Indigo (07-19-2019)
  #6  
Old 04-09-2010, 00:43
Archer's Avatar
Archer Archer is offline
retired
 
Join Date: Aug 2005
Posts: 239
Rept. Given: 1
Rept. Rcvd 46 Times in 19 Posts
Thanks Given: 3
Thanks Rcvd at 387 Times in 57 Posts
Archer Reputation: 46
Inline asm is forbidden in studio compiler only. Guess they are too lazy to implement it. GCC and intel support it just fine.
Reply With Quote
The Following User Says Thank You to Archer For This Useful Post:
Indigo (07-19-2019)
  #7  
Old 04-09-2010, 10:56
Fyyre's Avatar
Fyyre Fyyre is offline
Fyyre
 
Join Date: Dec 2009
Location: 0°N 0°E / 0°N 0°E / 0; 0
Posts: 255
Rept. Given: 71
Rept. Rcvd 85 Times in 38 Posts
Thanks Given: 136
Thanks Rcvd at 331 Times in 110 Posts
Fyyre Reputation: 85
Quote:
Originally Posted by jump View Post
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
	}
}
Reply With Quote
The Following 2 Users Gave Reputation+1 to Fyyre For This Useful Post:
jump (04-09-2010)
The Following User Says Thank You to Fyyre For This Useful Post:
Indigo (07-19-2019)
  #8  
Old 04-09-2010, 16:08
jump jump is offline
VIP
 
Join Date: Jan 2009
Posts: 305
Rept. Given: 84
Rept. Rcvd 51 Times in 26 Posts
Thanks Given: 22
Thanks Rcvd at 41 Times in 27 Posts
jump Reputation: 51
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
Reply With Quote
The Following User Says Thank You to jump For This Useful Post:
Indigo (07-19-2019)
  #9  
Old 04-09-2010, 18:45
Git's Avatar
Git Git is offline
Old Git
 
Join Date: Mar 2002
Location: Torino
Posts: 1,114
Rept. Given: 220
Rept. Rcvd 265 Times in 157 Posts
Thanks Given: 108
Thanks Rcvd at 215 Times in 123 Posts
Git Reputation: 200-299 Git Reputation: 200-299 Git Reputation: 200-299
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
Reply With Quote
The Following User Says Thank You to Git For This Useful Post:
Indigo (07-19-2019)
  #10  
Old 04-09-2010, 20:39
Av0id Av0id is offline
VIP
 
Join Date: Jan 2006
Posts: 399
Rept. Given: 112
Rept. Rcvd 111 Times in 69 Posts
Thanks Given: 0
Thanks Rcvd at 15 Times in 15 Posts
Av0id Reputation: 100-199 Av0id Reputation: 100-199
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
Reply With Quote
The Following User Says Thank You to Av0id For This Useful Post:
Indigo (07-19-2019)
  #11  
Old 04-11-2010, 15:32
Fyyre's Avatar
Fyyre Fyyre is offline
Fyyre
 
Join Date: Dec 2009
Location: 0°N 0°E / 0°N 0°E / 0; 0
Posts: 255
Rept. Given: 71
Rept. Rcvd 85 Times in 38 Posts
Thanks Given: 136
Thanks Rcvd at 331 Times in 110 Posts
Fyyre Reputation: 85
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 View Post
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
Reply With Quote
The Following User Says Thank You to Fyyre For This Useful Post:
Indigo (07-19-2019)
  #12  
Old 04-11-2010, 18:38
Git's Avatar
Git Git is offline
Old Git
 
Join Date: Mar 2002
Location: Torino
Posts: 1,114
Rept. Given: 220
Rept. Rcvd 265 Times in 157 Posts
Thanks Given: 108
Thanks Rcvd at 215 Times in 123 Posts
Git Reputation: 200-299 Git Reputation: 200-299 Git Reputation: 200-299
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
Reply With Quote
The Following User Gave Reputation+1 to Git For This Useful Post:
The Following User Says Thank You to Git For This Useful Post:
Indigo (07-19-2019)
  #13  
Old 04-17-2010, 17:13
gigaman gigaman is offline
Friend
 
Join Date: Jun 2002
Posts: 87
Rept. Given: 0
Rept. Rcvd 3 Times in 2 Posts
Thanks Given: 0
Thanks Rcvd at 14 Times in 11 Posts
gigaman Reputation: 4
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...
Reply With Quote
The Following User Says Thank You to gigaman For This Useful Post:
Indigo (07-19-2019)
  #14  
Old 04-17-2010, 18:18
Git's Avatar
Git Git is offline
Old Git
 
Join Date: Mar 2002
Location: Torino
Posts: 1,114
Rept. Given: 220
Rept. Rcvd 265 Times in 157 Posts
Thanks Given: 108
Thanks Rcvd at 215 Times in 123 Posts
Git Reputation: 200-299 Git Reputation: 200-299 Git Reputation: 200-299
I agree gigaman. It even more true when you consider the difficulty in writing a true x64 full function properly.

Git
Reply With Quote
The Following User Says Thank You to Git For This Useful Post:
Indigo (07-19-2019)
  #15  
Old 04-21-2010, 04:37
gigaman gigaman is offline
Friend
 
Join Date: Jun 2002
Posts: 87
Rept. Given: 0
Rept. Rcvd 3 Times in 2 Posts
Thanks Given: 0
Thanks Rcvd at 14 Times in 11 Posts
gigaman Reputation: 4
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
Reply With Quote
The Following User Says Thank You to gigaman For This Useful Post:
Indigo (07-19-2019)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
inline patche hp3 Source Code 3 06-04-2021 14:48
How to inline x64 asm in vs2017 ? Mahmoudnia General Discussion 25 07-22-2018 01:04
Inline Patching MaRKuS-DJM General Discussion 1 01-24-2004 23:03


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


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )