#pragma mc_func

Description

The #pragma mc_func directive lets you define a function containing a short sequence of machine instructions.

Syntax

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

where:

function Should specify a previously-defined function in a C or C++ program. If the function is not previously-defined, the compiler will treat the pragma as a function definition.
instruction_seq Is a string containing a sequence of zero or more hexadecimal digits. The number of digits must comprise an integral multiple of 32 bits.

Notes

The mc_func pragma lets you 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 the asm keyword found in this and other compilers.

The mc_func pragma defines a function and should appear in your program source only where functions are ordinarily defined. The function name defined by #pragma mc_func should be previously declared or prototyped.

The compiler passes parameters to the function in the same way as 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. See #pragma reg_killed_by for a list of volatile registers available on your system.

Code generated from instruction_seq 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.

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.

If an string literal exceeding 65535 bytes is specified with pragma map, an information message is emitted and the pragma is ignored.

Example

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 ints with so-called end-around carry; that is, if a carry out results from the add then add the carry to the sum. This is frequently used in checksum computations.

The example also shows the use of #pragma reg_killed_by to list a specific set of volatile registers that can be altered by the function defined by #pragma mc_func.

int add_logical(int, int);
#pragma mc_func add_logical {"7c632014" "7c630194"}
                /*   addc       r3 <- r3, r4           */
                /*   addze      r3 <- r3, carry bit    */

#pragma reg_killed_by add_logical gr3, xer
                /* only gpr3 and the xer are altered by this function */


main() {

      int i,j,k;

      i = 4;
      k = -4;
      j = add_logical(i,k);
      printf("\n\nresult = %d\n\n",j);
}

Related information