AN 977: Nios® V Processor Custom Instruction

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

2.3. Extended Custom Instruction

Extended custom instruction is an extension to multicycle custom instructions. An extended custom instruction allows a single custom logic block to implement several different operations.

Extended custom instruction components implement multiple indexes, comprised of opcode, funct7, and funct3. These indexes are determined when the custom instruction hardware block is instantiated in the system using Platform Designer.

While the selector indexes (opcode and funct7[6:4]) are required to select the correct logic block, extended custom instructions decode extension indexes (funct7[3:0] and funct3[2:0]) to specify which operation in the logic block to perform. The extension index can be up to seven bits wide, allowing a single custom logic block to implement as many as 128 different operations. Paired with 32 logic blocks in a single Nios® V processor, this enables up to 4096 custom instructions per processor.

The following logic block shows an extended custom instruction with bit-swap, byte-swap, and half-word swap operations. This block performs all swap operations on data received at the data0 port. The instruction hardware uses the two-bits wide funct3 port to select the output from a multiplexer, determining which result is presented to the result port.
Figure 7. Extended Custom Instruction with Swap Operations
Note: The logic in the figure above is a simple example using a multiplexer on the output. You can implement function selection based on any extension indexes in any way that is appropriate for your application.

To implement an extended custom instruction, apply the ctrl port to your custom instruction logic. The total bit width of the funct7[3:0] and funct3[2:0] port is a function of the number of operations the custom logic block can perform.

Table 3.  32-bit Custom Instruction Word (ctrl)
32-bit Custom Instruction Bit Field
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
funct7[6:0] rs2 rs1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rs1 funct3[2:0] rd opcode
Table 4.  Example of Selector and Extension Index Application
Selector Index Extension Index Supported Custom Instructions (per opcode)
opcode funct7[6:4] funct7[3:0] funct3[2:0]
custom-0 1 custom logic blocks Idle Idle 1 custom instructions
custom-1 8 custom logic blocks Idle Idle

8 custom instructions

(1 per logic block)

custom-2 8 custom logic blocks As extension index Idle

128 custom instructions

(16 per logic block)

custom-3 8 custom logic blocks As extension index As extension index

1024 custom instructions

(128 per logic block)

Total custom instruction in this processor 1161 custom instructions