AN 977: Nios® V Processor Custom Instruction

ID 773194
Date 4/14/2023
Public
Document Table of Contents

4.2.2. Software C-Macro Table

Unlike the Hardware Interfaces Table, the Software C-Macro Table configures the custom instruction software C Macro for software development. Note that, any assignment made need to correlates to the earlier assignments in Hardware Interfaces Table.

Select the symbol + to add new assignment, and - to delete it. Each assignment results in a single Nios® V processor custom instruction Software C Macro in the system.h file.

Table 12.  Software C-Macro Table Parameter
Parameter Description
Opcode
  • Correlate to the Hardware Interfaces Table.
  • The required selector index.
  • String assignment, with CUSTOM0, CUSTOM1, , CUSTOM2, or CUSTOM3 as options.
funct7[6:4]
  • Correlate to the Hardware Interfaces Table.
  • As optional selector index, or user-defined immediate.
  • 3-bits assignment, with available logic of 0, 1, or x.
  • Assign any bits as x to register it as input argument in the C Macro.
funct7[3:0]
  • As extension index, or user-defined immediate.
  • 4-bits assignment, with available logic of 0, 1, or x.
  • Assign any bits as x to register it as input argument in the C Macro.
funct3[2:0]
  • As extension index, ALU switch, or user-defined immediate.
  • 3-bits assignment, with available logic of 0, 1, or x.
  • Assign any bits as x to register it as input argument in the C Macro.
mnemonic
  • Define the mnemonic name of the custom instruction.
  • Intel recommends you to capitalize the name.
Figure 16. Example Assignments in Software C-Macro Table

C Macros in system.h

#define CUSTOM_0_000(VAL_1, VAL_2) ({ \
 int output; \
 asm volatile (".insn r 0x0B, 0x0, 0x0, %[out], %[input1], %[input2]" \
    : [out] "=r" (output) \
    : [input1] "r" (VAL_1), [input2] "r" (VAL_2)); \
    output;  \
})

#define CUSTOM_0_111(VAL_1, VAL_2) ({ \
 int output; \
 asm volatile (".insn r 0x0B, 0x0, 0x70, %[out], %[input1], %[input2]" \
    : [out] "=r" (output) \
    : [input1] "r" (VAL_1), [input2] "r" (VAL_2)); \
    output;  \
})

#define CUSTOM_1_XXX(VAL_1, VAL_2, F3, F7) ({ \
 int output; \
 asm volatile (".insn r 0x2B, %[FUNCT3], (0x0 | (%[FUNCT7]<<0)), %[out], %[input1], %[input2]" \
    : [out] "=r" (output) \
    : [input1] "r" (VAL_1), [input2] "r" (VAL_2), [FUNCT3] "i" (F3), [FUNCT7] "i" (F7)); \
    output;  \
})

#define CUSTOM_2_0XX(VAL_1, VAL_2, F3, F7) ({ \
 int output; \
 asm volatile (".insn r 0x5B, %[FUNCT3], (0x10 | (%[FUNCT7]<<0)), %[out], %[input1], %[input2]" \
    : [out] "=r" (output) \
    : [input1] "r" (VAL_1), [input2] "r" (VAL_2), [FUNCT3] "i" (F3), [FUNCT7] "i" (F7)); \
    output;  \
})

#define CUSTOM_3_10X(VAL_1, VAL_2) ({ \
 int output; \
 asm volatile (".insn r 0x7B, 0x0, 0x50, %[out], %[input1], %[input2]" \
    : [out] "=r" (output) \
    : [input1] "r" (VAL_1), [input2] "r" (VAL_2)); \
    output;  \
})