Inline Assembly

By default, the compiler inlines a number of standard C, C++, and math library functions. This usually results in faster execution of your program.

Sometimes inline expansion of library functions can cause unexpected results. The inlined library functions do not set the errno variable. So, in code that relies upon the setting of the errno variable, you should use the -nolib_inline option, which turns off inline expansion of library functions. Also, if one of your functions has the same name as one of the compiler's supplied library functions, the compiler assumes that it is one of the latter and replaces the call with the inlined version. Consequently, if the program defines a function with the same name as one of the known library routines, you must use the -nolib_inline option to ensure that the program's function is the one used.

Note

Automatic inline expansion of library functions is not related to the inline expansion that the compiler does during interprocedural optimizations. For example, the following command compiles the program sum.c without expanding the library functions, but with inline expansion from interprocedural optimizations (IPO):

prompt>icpc -ip -nolib_inline sum.cpp

For details on IPO, see Interprocedural Optimizations.

MASM* Style Inline Assembly

The Intel® C++ Compiler supports MASM style inline assembly with the -use_msasm option. See your MASM documentation for the proper syntax.

GNU*-like Style Inline Assembly (IA-32 only)

The Intel® C++ Compiler supports GNU-like style inline assembly. The syntax is as follows:

asm-keyword [ volatile-keyword ] ( asm-template [ asm-interface ] ) ;

Caution

Under the -use_msasm compilation flag, Gnu asm aliases will only work if you use the __asm__ keyword, they will not work correctly if you use the alternate __asm or asm keywords.

Syntax Element Description
asm-keyword asm statements begin with the keyword asm. Alternatively, either __asm or __asm__ may be used for compatibility. See Caution statement.
volatile-keyword If the optional keyword volatile is given, the asm is volatile.  Two volatile asm statements will never be moved past each other, and a reference to a volatile variable will not be moved relative to a volatile asm.  Alternate keywords __volatile and __volatile__ may be used for compatibility.
asm-template The asm-template is a C language ASCII string which specifies how to output the assembly code for an instruction.  Most of the template is a fixed string; everything but the substitution-directives, if any, is passed through to the assembler. The syntax for a substitution directive is a % followed by one or two characters.  The supported substitution directives are specified in a subsequent section.
asm-interface The asm-interface consists of three parts:
1. an optional output-list
2. an optional input-list
3. an optional clobber-list
These are separated by colon (:) characters.  If the output-list is missing, but an input-list is given, the input list may be preceded by two colons (::)to take the place of the missing output-list.  If the asm-interface is omitted altogether, the asm statement is considered volatile regardless of whether a volatile-keyword was specified.
output-list An output-list consists of one or more output-specs separated by commas.  For the purposes of substitution in the asm-template, each output-spec is numbered.  The first operand in the output-list is numbered 0, the second is 1, and so on.  Numbering is continuous through the output-list and into the input-list.  The total number of operands is limited to 10 (i.e. 0-9).
input-list Similar to an output-list, an input-list consists of one or more input-specs separated by commas.  For the purposes of substitution in the asm-template, each input-spec is numbered, with the numbers continuing from those in the output-list.
clobber-list A clobber-list tells the compiler that the asm uses or changes a specific machine register that is either coded directly into the asm or is changed implicitly by the assembly instruction.  The clobber-list is a comma-separated list of clobber-specs.
input-spec The input-specs tell the compiler about expressions whose values may be needed by the inserted assembly instruction.  In order to describe fully the input requirements of the asm, you can list input-specs that are not actually referenced in the asm-template.
clobber-spec Each clobber-spec specifies the name of a single machine register that is clobbered.  The register name may optionally be preceded by a %.  The following are the valid register names: eax, ebx, ecx, edx, esi, edi, ebp, esp, ax, bx, cx, dx, si, di, bp, sp, al, bl, cl, dl, ah, bh, ch, dh, st, st(1) - st(7), mm0 - mm7, xmm0 - xmm7, and cc.  It is also legal to specify "memory" in a clobber-spec.  This prevents the compiler from keeping data cached in registers across the asm statement.