HLSM Lecturev4
HLSM Lecturev4
Inputs: B; Outputs: X
• Register-transfer level (RTL) design X=0
Verilog – Earlier example – 3 cycles high, used FSM X=1 X=1 X=1
– What if 512 cycles high? 512-state FSM? On1 On2 On3
– Better solution – High-level state machine
Verilog for Digital Design (Vahid, Lysecky): Ch. 5 that uses register to count cycles 3 cycles with X=1
• Declare explicit register Cnt (2 bits for 3-
cycles high) Inputs: B; Outputs: X; Register: Cnt(2)
• Initialize Cnt to 2 (2, 1, 0 Æ 3 counts) X=0
• "On" state Cnt=2
– Sets X=1
– Configures Cnt for decrement on next cycle Off B'
– Transitions to Off when Cnt is 0 Cnt=0
– Note that transition conditions use current B X=1
value of Cnt, not next (decremented) value Cnt=Cnt-1
• For 512 cycles high, just initialize Cnt to 511 On
(Cnt=0)'
outputs
outputs
inputs
HLSM
inputs
outputs
CntNext <= Cnt - 1;
HLSM
FSM
bB x X HLSM
FSM
B X
Combinational
Combinational
...
Combinational if (Cnt == 0) target
end
logic logic logic StateNext <= S_Off; architecture to
else
State
State Cnt // Regs State Cnt StateNext <= S_On;
understand
always @(posedge Clk) begin end why.
Clk
clk Stateregister
State register Cnt register ... Clk State register Cnt register endcase
end end
StateNext CntNext StateNext CntNext
StateNext endmodule ...
outputs
end
HLSM
B X
Combinational end clock after B becomes 1, causing Cnt to be 1 for 3 cycles
logic ...
initialized to 2 B
State Cnt
– Cnt is decremented in S_On x
X
Clk State register Cnt register – Cnt wrapped from 0 to 3, but the 3 was never
used Clk
StateNext CntNext
Rst
Cnt X
Verilog for Digital Design Verilog for Digital Design
Copyright © 2007 vldd_ch5_LaserTimerHLSM.v 5 Copyright © 2007 State X
6
Frank Vahid and Roman Lysecky Frank Vahid and Roman Lysecky
1
Top-Down Design: HLSM to Controller and Datapath Top-Down Design: HLSM to Controller and Datapath
Inputs: B; Outputs: X; Register: Cnt(2)
• Recall from Chapters 2 & 3 • Recall from Chapters 2 & 3 X=0
– Top-down design – Top-down design Cnt=2
K_s
• Capture behavior, and simulate Capture P_s • Capture behavior, and simulate Off B'
Simulate
• Capture structure (circuit), behavior S_s
• Capture structure (circuit),
W_s Cnt=0
simulate again Should be simulate again B X=1
the same Cnt=Cnt-1
• Gets behavior right first, K_s • Gets behavior right first,
Capture P_s
unfettered by complexity of Simulate S_s unfettered by complexity of On
structure (Cnt=0)'
creating structure W_s creating structure
• At RTL level
– Capture behavior Æ HLSM
– Capture structure: Controller and
datapath Controller Datapath
Top-Down Design: HLSM to Controller and Datapath Top-Down Design: HLSM to Controller and Datapath
Inputs: B; Outputs: X; Register: Cnt(2)
X=0
• Deriving a Inputs: B; Outputs: X; Register: Cnt(2)
• Deriving a controller Cnt=2
datapath from X=0
– Replace HLSM by Off B'
the HLSM Cnt=2 FSM that uses the
datapath Cnt=0
Off B' B X=1
Cnt=Cnt-1
Cnt=0
B X=1 On
Cnt=Cnt-1 (Cnt=0)'
On
(Cnt=0)' Datapath
Inputs: B, Cnt_Eq_0; Outputs: X, Cnt_Sel, Cnt_Ld;
Datapath
X=0 "10"
Cnt_Sel=1, Cnt_Ld=1 Cnt_Sel
"10"
Cnt_Sel S 1 2x1 0
Off B' Cnt_Eq_0
="00" -1
="00" S 1 2x1 0 -1 Cnt_Eq_0
Cnt_Eq_0
B X=1 Cnt_Ld
Cnt_Sel=0, Cnt_Ld=1 Ld
Cnt_Ld Cnt
Ld Clk
Cnt On
Clk (Cnt_Eq_0)' Controller
Describing a Datapath
Top-Down Design: HLSM to Controller and Datapath
Behaviorally ...
// Shared variables
• Describe controller and datapath in VHDL • Two procedures reg Cnt_Eq_0, Cnt_Sel, Cnt_Ld;
// Controller variables
– One option: structural datapath, behavioral (FSM) controller – Combinational part and reg [0:0] State, StateNext;
// Datapath variables
– Let's instead describe both behaviorally register part reg [1:0] Cnt, CntNext;
– Current and next signals // ------ Datapath Procedures ------ //
shared between the two parts // DP CombLogic
always @(Cnt_Sel, Cnt) begin
– Just like for FSM behavior if (Cnt_Sel==1)
Inputs: B, Cnt_Eq_0; Outputs: X, Cnt_Sel, Cnt_Ld;
Datapath CntNext <= 2;
Datapath else
X=0 "10" CntNext <= Cnt - 1;
Cnt_Sel=1, Cnt_Ld=1 Cnt_Sel DpCombLogic
"10" Cnt_Eq_0 <= (Cnt==0)?1:0;
S 1 2x1 0 Cnt_Sel
Off B' Cnt_Eq_0
="00" -1 end
="00" S 1 2x1 0 -1
Cnt_Eq_0 Cnt_Eq_0 // DP Regs
B X=1 Cnt_Ld always @(posedge Clk) begin
Cnt_Sel=0, Cnt_Ld=1 Ld CntNext Cnt if (Rst == 1 )
Cnt Cnt_Ld Cnt <= 0;
Clk Ld
On Cnt else if (Cnt_Ld==1)
(Cnt_Eq_0)'Controller Clk Cnt <= CntNext;
DpRegs end
...
Verilog for Digital Design Verilog for Digital Design Note use of previously-introduced conditional operator
Copyright © 2007 11 Copyright © 2007 vldd_ch5_LaserTimerCtrlDpBeh.v 12
Frank Vahid and Roman Lysecky Frank Vahid and Roman Lysecky
2
...
Behaviorally Behavior
// Ctrl CombLogic parameter S_Off = 0,
always @(State, Cnt_Eq_0, B) begin S_On = 1;
case (State)
• Standard approach for S_Off: begin • Result is one module with four // Shared variables
describing FSM X <= 0; Cnt_Sel <= 1; Cnt_Ld <= 1; procedures reg Cnt_Eq_0, Cnt_Sel, Cnt_Ld;
if (B == 0) // Controller variables
– Two procedures StateNext <= S_Off; – Datapath procedures (2) reg [0:0] State, StateNext;
else • Combinational logic // Datapath variables
StateNext <= S_On; reg [1:0] Cnt, CntNext;
• Registers
end
Inputs: B, Cnt_Eq_0; Outputs: X, Cnt_Sel, Cnt_Ld; S_On: begin – Controller procedures (2) // ------ Datapath Procedures ------ //
X <= 1; Cnt_Sel <= 0; Cnt_Ld <= 1; • Combinational logic // DP CombLogic
X=0 if (Cnt_Eq_0 == 1)
• Registers always @(Cnt_Sel, Cnt) begin
Cnt_Sel=1, Cnt_Ld=1 StateNext <= S_Off; ...
else end
Off B' StateNext <= S_On;
end // DP Regs
Cnt_Eq_0 endcase always @(posedge Clk) begin
B X=1 end Inputs: B, Cnt_Eq_0; Outputs: X, Cnt_Sel, Cnt_Ld;
Datapath
...
Cnt_Sel=0, Cnt_Ld=1 X=0 end
Cnt_Sel=1, Cnt_Ld=1 Cnt_Sel "10"
// Ctrl Regs
On always @(posedge Clk) begin Off B' Cnt_Eq_0
="00" S 1 2x1 0
-1 // ------ Controller Procedures ------ //
(Cnt_Eq_0)'Controller if (Rst == 1 ) begin Cnt_Eq_0 // Ctrl CombLogic
State <= S_Off; B X=1
Cnt_Sel=0, Cnt_Ld=1
Cnt_Ld
Ld
always @(State, Cnt_Eq_0, B) begin
end Cnt
Clk ...
else begin On
(Cnt_Eq_0)' Controller end
State <= StateNext;
end // Ctrl Regs
end always @(posedge Clk) begin
Verilog for Digital Design ... Verilog for Digital Design ...
Copyright © 2007 vldd_ch5_LaserTimerCtrlDpBeh.v 13 Copyright © 2007 end 14
Frank Vahid and Roman Lysecky Frank Vahid and Roman Lysecky endmodule vldd_ch5_LaserTimerCtrlDpBeh.v
Timing Differences Between Two and One Procedure One Procedure FSM Description
Descriptions
• Previous two procedure description
B
– Change in B immediately noticed by • Likewise, can describe FSM using one procedure rather than two
combinational logic procedure, X
– Same approach
which configures next state to be Clk
S_On. State changes to S_On (1) • One variable for state (rather than two)
Rst
on next rising clock (setting X=1). • One procedure, sensitive to clock only
State
• One procedure description – Same issues as with HLSM
– Change in B not noticed until next • Simpler, cleaner code: one procedure per FSM
rising clock, so next state still S_Off • Timing may change: makes inputs synchronous, may introduce extra cycles
(0). After rising clock, procedure B
configures next state to be S_On X
(1). State changes to S_On on the Clk
next rising clock (setting X=1) – two
Rst
rising clocks after b changed
State
• Likewise, initial reset also delayed
3
Improving Timing Realism Delay Control on Right Side of Assignment Statements
• Real components have delays • Delays can be described by including delay `timescale 1 ns/1 ns
control in assignment statement
• Suppose comparator has 7 ns delay – variablename <= # delay_value expression module LaserTimer(B, X, Clk, Rst);
...
• # delay_value –Time units into the future at
// DP CombLogic
which variable update should occur always @(Cnt_Sel, Cnt) begin
Suppose has 7 ns delay – Example gives comparator 7 time units of delay if (Cnt_Sel==1)
– And a time unit equals 1 ns, so 7 ns delay CntNext <= 2;
Datapath – Should also include delay for mux and subtractor else
Inputs: B, Cnt_Eq_0; Outputs: X, Cnt_Sel, Cnt_Ld; parts CntNext <= Cnt - 1;
Algorithmic-Level
`timescale 1 ns/1 ns
4
Algorithmic-Level
`timescale 1 ns/1 ns
5
Automated Synthesis from the Algorithmic Level Simulation Speed
• Behavioral synthesis (or high-level synthesis) tools • Higher-level descriptions yield faster simulations
– Introduced in the 1990s and 2000s – Due to fewer procedures, fewer variables, fewer events, ...
– Automatically synthesize algorithmic-code to RTL code or directly to circuits – 10x difference means difference between tens of minutes versus hours; 100x
– Not yet adopted as widely as RTL synthesis tools could mean days
– Each tool imposes strong requirements and restrictions on the algorithmic- – High-level descriptions (e.g., algorithmic) preferred early in design, and for
level code integrated systems with many (hundreds) of sub-systems
– The quality of RTL code or circuits created from such tools also varies • One-procedure clocked procedure state machine is also faster than
tremendously procedure approach where one procedure is combinational
– Interesting direction and may prove increasingly useful in coming years – Again, fewer procedures, fewer variables, fewer events, ...
• Differences become significant for very large systems, or for very lengthy
testbenches
SAD A SAD
A 256-byte memory
SAD_Out B SAD_Out
B 256-byte memory
Go Go
6
module Testbench();
reg Go_s;