Visible to Intel only — GUID: oon1675731152267
Ixiasoft
Visible to Intel only — GUID: oon1675731152267
Ixiasoft
3.1. Custom Instruction Software C Macro
The following examples illustrate how the Nios® V processor custom instruction software interface fits into the software code.
The example below shows a portion of the system.h header file that defines a macro for a custom instruction. The macros defined by the Board Support Package Editor use C integer types only.
Software C Macros with assigned funct3 and funct7 fields
#define CUSTOM_OPERATION(VAL_1, VAL_2) ({ \
int output; \
asm volatile (".insn r 0x0B, 0x1, 0x0, %[out], %[input1], %[input2]" \
: [out] "=r" (output) \
: [input1] "r" (VAL_1), [input2] "r" (VAL_2)); \
output; \
})
The example below shows an application code that uses the custom instruction and includes the system.h file. This example enables the application software to use the custom instruction macro definition. You are required to apply uint32_t variable type, along with inttypes.h header.
Software C Macros that includes system.h
#include "system.h"
#include <inttypes.h>
int main (void)
{
uint32_t val_1 = 0x12345678; //max 32-bit
uint32_t val_2 = 0x98765432; //max 32-bit
uint32_t result;
result = CUSTOM_OPERATION_1(val_1, val_2);
return 0;
}