New C++ compiler with inline assembly support

Agner Fog <[email protected]>
Newsgroups org.kernel.vger.linux-assembly
Message-ID <[email protected]>
Intel have just released version 9.0 of their C++ compiler with better 
support for inline assembly.
It can compile for the following platforms
- Linux x86 32 bit
- Linux x86 64 bit
- Linux ia64 (Itanium)
- Windows x86 32 bit
- Windows x86 64 bit
- Windows ia64 (Itanium)
I haven't tested it on FreeBSD yet, but I assume that it works on 32 and 
64 bit FreeBSD as well.

In Linux, you now have the choice between MASM syntax and AT&T syntax 
for inline assembly. MASM syntax is almost the same as NASM. If you 
choose MASM syntax, you can use the same C++ file with inline assembly 
in both Linux and Windows. It can even translate MASM syntax assembly to 
AT&T syntax, and this more reliably than any other translation tools I 
have seen yet.

To use MASM syntax under Linux, simply use the command line option  
-use-msasm

Example:

int addnumbers (int a, int b) {
   return a+b;}

Same with inline assembly in MASM syntax:

int addnumbers (int a, int b) {
   __asm {
      mov eax, a
      add eax, b
   }
}

This will work in both Linux and Windows, 32 and 64 bit. So you can use 
the same C++/asm file on all platforms. It takes care of the differences 
in calling conventions between the different platforms, and it 
automatically pushes and pops any non-volatile registers that you use in 
your code. This makes Linux assembly much easier! You can make the most 
of your program in C++ and make the critical innermost loop with inline 
assembly.

In 64-bit Linux, function parameters are transferred in registers rdi, 
rsi, rdx, rcx, r8, r9, xmm0-xmm7. If you know this, you can optimize the 
above example:

int addnumbers (int a, int b) {
   __asm {
      lea eax, [rdi+rsi]
   }
}

But then your code is no longer platform independent, of course.

The C++ compiler for Linux is available for free for noncommercial 
users. Download it from http://www.intel.com/software/products/noncom/
The C++ compiler for Windows is available with a time limited free 
evaluation license from 
https://registrationcenter.intel.com/EvalCenter/EvalForm.aspx?ProductID=411

Agner Fog
www.agner.org/assem
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.