Professional Documents
Culture Documents
RISC1
RISC1
EKE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Behavioral
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Relevant Questions
How should a datapath and its controller be modeled to avoid race
conditions? How can simulation mismatches be prevented?
Data inputs
Datapath Unit
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Datapath Unit Control Unit External Control Inputs Finite-State Machine Clock Datapath Registers Status signals Clock Datapath Logic Control signals
Process:
Annotate the ASM chart to indicate the concurrent register operations operations that occur in
the associated datapath unit when (1) the controller is in a state (Moore output signal), or (2) when the state makes a transition along a path (Mealy output signal)
Edit the chart (add output signals) to identify the signals that launch the indicated
datapath operations Benefits:
Clarifies a design of a sequential machine by separating the design design of its datapath
from the design of its controller
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Load, clear, shift contents of registers Fetch instructions from memory Store data in memory Steer signals through muxes Control threethree-state devices Select/execute ALU operations
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Application-Driven Design
Application
Architecture (Implementation)
Control Sequence
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
0000
0001
0010
rst
S_running 0
rst
S_running
0111
enable
0110
enable
0101
enable
0100
enable
enable
enable 1 enable_DP
1
1000
enable
1001
enable
1010
enable
1011
enable
1111
enable
1110
enable
1101
enable
1100
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Named block
always begin: Cycle_by_3 @ (posedge clk) enable_DP <= 0; if ((rst == 1) || (enable != 1)) disable Cycle_by_3; else @ (posedge clk) if ((rst == 1) || (enable != 1)) disable Cycle_by_3; else @ (posedge clk) if ((rst == 1) || (enable != 1)) disable Cycle_by_3; else enable_DP <= 1; end // Cycle_by_3 Caution: Model has pipeline endmodule effect one extra cycle to recover from reset.
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
osu05_stdcells Implementation
P1[7: 0]
P0[7: 0]
8
S_idle
P1[7: 0]
P0[7: 0]
R0[15: 0]
rst
En
1 S_1
S_full
enable enable_DP dfnf311 rst clk dfnf311 dfnf311
S_wait
Ld
1 1
Ld
En
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ASMDASMD-Based Datapath Controller Design Methodology Clarify the design of a sequential machine by separating the design design
of its datapath from the design of the controller
rst
Specify register operations for the datapath Define the ASM chart of the controller (primary inputs and feedback feedback
from datapath)
En
P1 <= Data P0 <= P1 1 load_P1_P0 S_1 /load_P1_P0 S_full
Annotate the arcs of the ASM chart with the datapath operations
associated with the state transitions of the controller
Include conditional boxes (Mealy) for the signals generated by the the
controller to control the datapath.
S_wait
Ld
1
load_P1_P0 1 load_R0
Verify the controller Verify the datapath Verify the integrated units
Ld
En
module Datapath ( output reg q, output q_bar, input data, R, S); always @ (posedge clock) if (R) q <= 1'b0; else if (S) q <= 1'b1; else q <= data; assign q_bar = q; endmodule
Operations
Datapath logic
Copyright 2007 Michael D. Ciletti 25
The description of a controller that has only combinational logic (i.e., no states) can be embedded in the datapath logic.
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 26
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Race?
Status signals Clock
Race?
Status signals Clock
Datapath Registers
state
Control
Status
state ?
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
data temp_gt_1
Datapath temp
bit_count
Data slip: q_bar is pipelined from q and will lag by one cycle.
q data
D Q D Q
q_bar
clock reset
Smart Counter of 1s (1 of 5)
module count_ones_SM # (parameter counter_size = 3, word_size = 4) ( output [counter_size -1: 0] bit_count, output busy, done, input [word_size[word_size-1: 0] data, input start, clk, reset ); wire load_temp, shift_add, clear, temp_0, temp_gt_1; controller M0 (load_temp, shift_add, clear, busy, done, start, temp_gt_1, clk, reset); datapath M1 (temp_gt_1, temp_0, data, load_temp, shift_add, clk, clk, reset); bit_counter_unit M2 (bit_count, temp_0, clear, clk, reset); endmodule Note: Bit Counter is separate - for convenience.
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 31
Smart Counter of 1s (2 of 5)
module controller # (parameter state_size = 2; S_idle = 0, S_counting = 1, S_waiting = 2) ( output reg load_temp, shift_add, clear, busy, done, input start, temp_gt_1, clk, reset); reg bit_count; reg [state_sizestate, next_state; [state_size-1 : 0] always @ (posedge clk) // state transitions if (reset) state <= S_idle; else state <= next_state; always @ (state, start, temp_gt_1) begin load_temp = 0; shift_add = 0; done = 0; busy = 0; clear = 0; next_state = S_idle; // Comb Logic
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Smart Counter of 1s (3 of 5)
case (state) S_idle: S_counting: if (start) begin next_state = S_counting; load_temp = 1; end begin busy = 1; if (temp_gt_1) begin next_state = S_counting; shift_add = 1; end else begin next_state = S_waiting; shift_add = 1; end end begin done = 1; if (start) begin next_state = S_counting; load_temp = 1; clear = 1; end else next_state = S_waiting; end begin clear = 1; next_state = S_idle; end
Smart Counter of 1s (4 of 5)
module datapath # (parameter word_size = 4) (output temp_gt_1, temp_0, input, load_temp, shift_add, clk, reset, input [word_size[word_size-1: 0] data ); reg [word_sizetemp; [word_size-1: 0] wire temp_gt_1 = (temp > 1); wire temp_0 = temp[0]; always @ (posedge clk) // state and register transfers if (reset) begin temp <= 0; end else begin if (load_temp) temp <= data; if (shift_add) begin temp <= temp >> 1; end end endmodule
S_waiting:
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Smart Counter of 1s (5 of 5)
module bit_counter_unit (bit_count, temp_0, clear, clk, reset); parameter counter_size = 3; output [counter_size -1 : 0] bit_count; input temp_0; input clear, clk, reset; reg bit_count; always @ (posedge clk) // state and register transfers if (reset || clear) bit_count <= 0; else bit_count <= bit_count + temp_0; endmodule
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Datapath: Datapath
Controller:
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Bit Counter
Sequential multiplier: Add and shift algorithm Separate registers Long adder Shift multiplicand and multiplier ReducedReduced-register alternative machine Form product in multiplier reg Hardwired multiplicand Load multiplier in right side Form row sums in left side Eliminate register Shorter adder Fewer shift registers Adapted from Ciletti, M D. Advanced Digital Design with the Verilog
HDL. Upper Saddle River, NJ: PrenticePrentice-Hall, 2003
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 40
clk
xnor2_a xor2_a
nor2_a
dffspqb_a
nand2_a
xor2_a
nor2_a
dffspqb_a
and2i_a
nor2_a
dffspqb_a
bit_count<2:0>
bit_count<2>
bit_count<1> bit_count<0>
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
S_running:
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
j=1 i=2 7
j=2 6
j=3 5
j=4 4
for i=2 to N_key begin for j = N_key downto i do if a[j-1] > a[j] then begin temp= a[j-1]; a[j-1]=a[j]; a[j]=temp end end
Adapted from Ciletti, M D. Advanced Digital Design with the Verilog HDL. Upper Saddle River, NJ: Prentice-Hall, 2003
Architecture
i =3 4
incr_i
decr_i
decr_j
incr_j
swap
i =4 4
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Datapath operations
Sorted data
module Bubble_Sort (A1, A2, A3, A4, A5, A6, A7, A8,En, Ld, clk, rst); output [3:0] A1, A2, A3, A4, A5, A6, A7, A8; input En, Ld, clk, rst; parameter N = 8; parameter word_size = 4; parameter a1 = 8, a2 = 1, a3 = 8, a4 = 1, a5 = 8, a6 = 1, a7 = 8, a8 = 1; reg [word_size -1: 0] A [1: N]; // Array of words wire [3:0] A1 = A[1], A2 = A[2], A3 = A[3], A4 = A[4]; wire [3:0] A5 = A[5], A6 = A[6], A7 = A[7], A8 = A[8]; parameter S_idle = 0, S_run = 1; reg [3: 0] i, j; reg swap, decr_j, incr_i, set_i, set_j; reg state, next_state; wire gt = (A[j-1] > A[j]); // compares words
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
always @ (posedge clk) if (rst) state <= S_idle; else state <= next_state; always @ (state or En or Ld or gt or i or j) begin swap = 0; decr_j = 0; incr_i = 0; set_j = 0; set_i = 0; case (state) S_idle: if (Ld) begin next_state = S_idle; end else if (En) begin next_state = S_run; if (gt) begin swap = 1; decr_j = 1; end else next_state = S_idle; end S_run: if (j >= i) begin next_state = S_run; decr_j = 1; if (gt) swap = 1; end else if (i <= N) begin next_state = S_run; set_j = 1; incr_i = 1; end else begin next_state = S_idle; set_j = 1; set_i = 1; end
endcase end
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 51 ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 52
Adapted from: M. D. Ciletti, Advanced Digital Design with the Verilog HDL, Upper Saddle River, Prentice-Hall, Inc., NJ. 2003
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
RISC: Opcodes
Reg_Y Reg_Y
Instr
Instruction Word opcode src ?? src src src src ?? src ?? ?? ?? dest ?? dest dest dest dest dest ?? ?? ?? ??
Action none dest <= src + dest dest <= dest - src dest <= src && dest dest <= ~src dest <= memory[Add_R] memory[Add_R] <= src PC <= memory[Add_R] PC <= memory[Add_R] Halts execution until reset
opcode opcode
ALU ALU
NOP ADD SUB AND NOT RD* WR* BR* BRZ* HALT
0000 0001 0010 0011 0100 0101 0110 0111 1000 1111
alu_zero_flag alu_zero_flag
Adds the datapaths to form data_1 + data_2 Subtracts the datapaths to form data_1 - data_2 Takes the bitwise-and of the datapaths, data_1 & data_2 Takes the bitwise Boolean complement of data_1
Copyright 2007 Michael D. Ciletti 55
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Short instruction (SUB) (Single byte): Long instruction (WR) (Two bytes):
opcode 0 0 1 0
source 0 1
destination 1 0
Loads the address register Loads Bus_2 to the program counter Loads Bus_2 to the instruction register Increments the program counter Selects among the Program_Counter, R0, R1, R2, and R3 to drive Bus_1 Selects among Alu_out, Bus_1, and memory to drive Bus_2
Sel_Bus_2_Mux
address 0 0 0 1 1 1 0 1
The control unit (1) determines when to load registers, (2) selects the path of data through the multiplexers, (3) determines when data should be written to memory, and (4) controls the three-state busses in the architecture.
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 58
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Loads general purpose register R0 Loads general purpose register R1 Loads general purpose register R2 Loads general purpose register R3 Loads Bus_2 to the register Reg_Y Stores output of ALU in register Reg_Z Loads Bus_1 into the SRAM memory at the location specified by the address register
// Control Nets wire Load_R0, Load_R1, Load_R2, Load_R3; wire Load_PC, Inc_PC, Load_IR; wire Load_Add_R, Load_Reg_Y, Load_Reg_Z; wire write;
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 59 ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 60
Processing_Unit M0_Processor (instruction, zero, address, Bus_1, mem_word, Load_R0, Load_R1, Load_R2, Load_R3, Load_PC, Inc_PC, Sel_Bus_1_Mux, Load_IR, Load_Add_R, Load_Reg_Y, Load_Reg_Z, Sel_Bus_2_Mux, clk, rst); Control_Unit M1_Controller (Load_R0, Load_R1, Load_R2, Load_R3, Load_PC, Inc_PC, Sel_Bus_1_Mux, Sel_Bus_2_Mux , Load_IR, Load_Add_R, Load_Reg_Y, Load_Reg_Z, write, instruction, zero, clk, rst); Memory_Unit M2_MEM ( .data_out (mem_word), .data_in (Bus_1), .address (address), .clk (clk), .write (write)); endmodule // RISC_SPM
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
wire wire [word_size-1: 0] wire [word_size-1: 0] wire [word_size-1: 0] wire wire [op_size-1 : 0]
Load_R0, Load_R1, Load_R2, Load_R3; Bus_2; R0_out, R1_out, R2_out, R3_out; PC_count, Y_value, alu_out; alu_zero_flag; opcode = instruction [word_size-1: word_size-op_size];
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Register Unit
module Register_Unit # (parameter word_size = 8)( output reg [word_sizedata_out, [word_size-1: 0] input [word_sizedata_in, [word_size-1: 0] input load, input clk, rst, ); always @ (posedge clk, negedge rst) if (rst == 0) data_out <= 0; else if (load) data_out <= data_in; endmodule
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Flip-Flop Model
module D_flop ( output reg data_out, input data_in, input load, input clk, rst, ); always @ (posedge clk, negedge rst) if (rst == 0) data_out <= 0; else if (load == 1)data_out <= data_in; endmodule
always @ (posedge clk, negedge rst) if (rst == 0) data_out <= 0; else if (load == 1) data_out <= data_in; endmodule module Address_Register # (parameter word_size = 8)( output reg [word_size-1: 0] data_out, input [word_size-1: 0] data_in, input load, clk, rst ); always @ (posedge clk, negedge rst) if (rst == 0) data_out <= 0; else if (load) data_out <= data_in; endmodule
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 68
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
RISC: ALU (1 of 2)
module Alu_RISC (alu_zero_flag, alu_out, data_1, data_2, sel); parameter word_size = 8; parameter op_size = 4; // Opcodes parameter NOP parameter ADD parameter SUB parameter AND parameter NOT parameter RD parameter WR parameter BR parameter BRZ
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
RISC: ALU (2 of 2)
output output input input reg [word_size-1: 0] [word_size-1: 0] [op_size-1: 0] alu_zero_flag; alu_out; data_1, data_2; sel; alu_out;
assign alu_zero_flag = ~|alu_out; always @ (sel or data_1 or data_2) case (sel) NOP: alu_out = 0; ADD: alu_out = data_1 + data_2; // Reg_Y + Bus_1 SUB: alu_out = data_2 - data_1; AND: alu_out = data_1 & data_2; NOT: alu_out = ~ data_2; // Gets data from Bus_1 default: alu_out = 0; endcase endmodule
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 73
Develop Verilog model directly from the ASM or ASMD chart State machine (Mealy/Moore) Output signals control the datapath operations of the processor Uses feedback from the processor
Load_R0 Load_R1 Load_R2 Load_R3 Load_PC Inc_PC instruction Sel_Bus_1_Mux Load_IR Load_Add_Reg Load_Reg_Y
01 2 34 Mux_1 Bus_1
Reg_Y
opcode
ALU
alu_zero_flag
Memory
mem_word
Reg_Z
Zflag
1 2 Mux_2
Add_R
Bus_2 write
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
Mealy outputs
Moore outputs
...
Strategy: Develop the state machine directly from the ASM chart
...
...
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
/* always @ (state, instruction, zero) begin: Output_and_next_state Note: The above event control expression leads to incorrect operation. operation. The state transition causes the activity to be evaluated once, then the resulting instruction change causes it to be evaluated again, but with the residual value of opcode. On the second pass the value seen is the value opcode had before the state change, which results in Sel_PC = 0 in state 3, which will cause a return to state 1 at the next clock. Finally, opcode is changed, but this does not trigger a rere-evaluation because it is not in the event control expression. So, the caution is to be sure to use opcode in the event control expression. That way, the final execution of the behavior uses the the value of opcode that results from the state change, and leads to the correct value value of Sel_PC. */
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers Copyright 2007 Michael D. Ciletti 80
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
case (state)
S_idle: next_state = S_fet1; S_fet1: begin next_state = S_fet2; Sel_PC = 1; Sel_Bus_1 = 1; ASM chart states Load_Add_R = 1; end S_fet2: begin next_state = S_dec; Sel_Mem = 1; Load_IR = 1; Inc_PC = 1; end
Decode the state and generate the next state and the outputs.
Assignment by exception reduces the complexity of the code and reduces the chances of making an error in the logic.
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
NOT Instruction
S_dec 3
NOP
src = R0 1
S_ex1 4
Develop similar descriptions for the remaining states of the ASMD chart
ADD
src = R1 1
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
01 2 34 Mux_1 Bus_1
ALU
alu_zero_flag
Memory
mem_word
Reg_Z
Zflag
1 2 Mux_2
Add_R
Bus_2 write
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers
ECE 4242 / 5242 Advanced Digital Design Methodology: Synthesis of Datapath Controllers