News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

New C++ compiler with inline assembly support

Started by agner, June 20, 2005, 07:17:40 AM

Previous topic - Next topic

agner

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. 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 systems, function parameters are transferred in registers. If you know this, you can optimize the above example.

//For Windows, 64 bit:
int addnumbers (int a, int b) {
  __asm {
     lea eax, [rcx+rdx]
  }
}


// For Linux, 64 bit:
int addnumbers (int a, int b) {
  __asm {
     lea eax, [rdi+rsi]
  }
}


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

The Microsoft compiler doesn't support inline assembly in 64 bit code. The Intel compiler does. Microsoft doesn't support long double precision, Intel does.

The Intel compiler works nicely as a plug in to the Microsoft visual C++ IDE.

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


Vortex


Porkster

Quote from: agner on June 20, 2005, 07:17:40 AMThe Intel compiler works nicely as a plug in to the Microsoft visual C++ IDE.

Yeah I noticed that.  Isn't it a requirement to use MS VS IDE for the C++ package?

EDIT : Yep you do need it.

.