#pragma mc_func

Category

Language element control

Purpose

Allows you to embed a short sequence of machine instructions "inline" within your program source code.

The pragma instructs the compiler to generate specified instructions in place rather than the usual linkage code. Using this pragma avoids performance penalties associated with making a call to an assembler-coded external function. This pragma is similar in function to inline asm statements supported in this and other compilers; see Inline assembly statements for more information.

Syntax

Read syntax diagramSkip visual syntax diagram
                                         .----------------------.      
                                         V                      |      
>>-#--pragma--mc_func--function_name--{----instruction_sequence-+--}-><

Parameters

function_name
The name of a previously-defined function containing machine instructions. If the function is not previously-defined, the compiler will treat the pragma as a function definition.
instruction_sequence
A string containing a sequence of zero or more hexadecimal digits. The number of digits must comprise an integral multiple of 32 bits. If the string exceeds 16384 bytes, a warning message is emitted and the pragma is ignored.

Usage

This pragma defines a function and should appear in your program source only where functions are ordinarily defined.

The compiler passes parameters to the function in the same way as to any other function. For example, in functions taking integer-type arguments, the first parameter is passed to GPR3, the second to GPR4, and so on. Values returned by the function will be in GPR3 for integer values, and FPR1 for float or double values.

Code generated from instruction_sequence may use any and all volatile registers available on your system unless you use #pragma reg_killed_by to list a specific register set for use by the function. See #pragma reg_killed_by for a list of volatile registers available on your system.

Inlining options do not affect functions defined by #pragma mc_func. However, you may be able to improve runtime performance of such functions with #pragma isolated_call.

Examples

In the following example, #pragma mc_func is used to define a function called add_logical. The function consists of machine instructions to add 2 integers with so-called end-around carry; that is, if a carry out results from the add then add the carry to the sum. This formula is frequently used in checksum computations.
int add_logical(int, int);
#pragma mc_func add_logical {"7c632014" "7c630194"}
                /*   addc       r3 <- r3, r4           */
                /*   addze      r3 <- r3, carry bit    */


main() {

      int i,j,k;

      i = 4;
      k = -4;
      j = add_logical(i,k);
      printf("\n\nresult = %d\n\n",j);
}
The result of running the program is:
result = 1

Related information