Built-in functions and user-defined macros, Built-in functions and user-defined macros –2 – Altera Nios II Custom User Manual
Page 18

2–2
Chapter 2: Software Interface
Built-in Functions and User-defined Macros
Nios II Custom Instruction User Guide
January 2011
Altera Corporation
illustrates how most applications use custom instructions. The macros
defined by the Nios II software build tools use C integer types only. Occasionally,
applications require input types other than integers. In those cases, you can use a
custom instruction macro to process non-integer return values.
1
You can define custom macros for Nios II custom instructions that allow other 32-bit
input types to interface with custom instructions.
Built-in Functions and User-defined Macros
The Nios II processor uses
gcc
built-in functions to map to custom instructions. By
default, the integer type custom instruction is defined in a system.h file. However, by
using built-in functions, software can use non-integer types with custom instructions.
Fifty-two built-in functions are available to accommodate the different combinations
of supported types.
Built-in function names have the following format:
__builtin_custom_
<return type>
n
<parameter types>
lists the 32-bit types supported by custom instructions as parameters and
return types, as well as the abbreviations used in the built-in function names.
shows the prototype definitions for two built-in functions.
The built-in function
__builtin_custom_nf
takes a
float
as an input, and does not
return a value. In contrast, the built-in function
__builtin_custom_fnp
takes a pointer
as input, and returns a
float
.
To support non-integer input types, define macros with mnemonic names that map to
the specific built-in function required for the application.
f
Refer to
Appendix B, Custom Instruction Built-in Functions
for detailed information
and a list of built-in functions.
Table 2–1. 32-bit Types Supported by Custom Instructions
32-bit Type
Built-in Function Abbreviation
int
i
float
f
void *
p
Example 2–3. Two Example Built-in Function Prototypes
void __builtin_custom_nf (int n, float dataa);
float __builtin_custom_fnp (int n, void * dataa);