Beruflich Dokumente
Kultur Dokumente
TM
Steve Hoover
Founder, Redwood EDA
July 31, 2020
2
TM
Redwood EDA
Agenda
● Logic gates
● Makerchip platform
● Combinational logic
● Sequential logic
● Pipelined logic
● State
3
TM
Redwood EDA
Logistics
https://github.com/stevehoover/RISC-V_MYTH_Workshop
4
Redwood EDA
Logic Gates
A
Symbol A X
B
X
A X A B X A B X A B X A B X A B X A B X
0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1
Truth 1 0 0 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 1 0
Table 1 0 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 0
1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1
5
Redwood EDA
Combinational Circuit
XOR
XOR
AND
OR
AND
CC BY-SA 3.0
en:User:Cburnett
6
Redwood EDA
Combinational Circuit
1
0
1 XOR
1 XOR
1 1
0 AND 0
1
OR
1
AND 1
1
CC BY-SA 3.0
en:User:Cburnett
7
Redwood EDA
Adder
S=A+B
A0B S0 A 1B 1 S1 A 2B 2 S2
0
...
8
Redwood EDA
Adder
9
Redwood EDA
Boolean Operators
10
Redwood EDA
Multiplexer (MUX)
0 Verilog:
assign f = s ? X1 : X2;
(boolean select)
11
Redwood EDA
Chaining Ternary Operator
sel[3:0]
(decoded Verilog:
a Equivalently:
select)
assign f =
assign f =
b 0 sel[0]
sel[0]
1 ? a
out ? a :
2 : (sel[1]
c 3 sel[1]
? b
? b :
: (sel[2]
d sel[2]
? c
? c :
: d
//default
sel[3:0] )
d;
);
a
(So, highest
b 0
1 priority first.)
2
out
c 3
d 12
Redwood EDA
Makerchip
13
Redwood EDA
Lab: Makerchip Platform
1. Reproduce this
screenshot:
2. Open “Tutorials” “Validity
Tutorial”.
3. In tutorial, click
Load Pythagorean Example
1. Open “Examples” (under There was no need to declare $out and $in1
“Tutorials”). (unlike Verilog).
2. Load “Default Template”.
3. Make an inverter. There was no need to assign $in1. Random
stimulus is provided, and a warning is
On line 16, in place of:
produced.
//...
type:
$out = ! $in1; B) Other logic
1. Try:
2. View Waveform.
16
Redwood EDA
Lab: Mux
$in1 $in1[7:0]
1 1
$out $out[7:0]
$in2 $in2[7:0]
0 0
$sel $sel
Note that bit ranges can generally be assumed on the left-hand side, but
with no assignments to these signals, they must be explicit.
17
Redwood EDA
Lab: Combinational Calculator
$val2[31:0] *
$prod[31:0] 3 “Save as new project”,
bookmark, and open a
$quot[31:0]
/ new Makerchip IDE in a
new tab. 18
Redwood EDA
Sequential Logic
clk
19
Redwood EDA
Sequential Logic
20
Redwood EDA
Sequential Logic - Fibonacci Series
$num
+
5 3 2 1 1
21
Redwood EDA
Fibonacci Series - Reset
1 $num
>>1$num >>2$num
+
(makerchip.com/sandbox/0/0wjhLP) 22
Redwood EDA
Lab: Counter
1 $num
0
1 $cnt
+
+
to be safe).
25
Redwood EDA
A Simple Pipeline
a ^2
c
+ sqrt
c
b b ^2
a
We distribute the calculation over three cycles.
c = sqrt(a^2 + b^2)
a ^2
c
+ sqrt
b ^2
26
Redwood EDA
A Simple Pipeline - Timing-Abstract
RTL:
a ^2
c
+ sqrt
b ^2
Timing-abstract:
|calc
➔ Flip-flops and
a ^2
+
c staged signals are
sqrt
b ^2 implied from
context.
Stage: 1 2 3
27
Redwood EDA
A Simple Pipeline - TL-Verilog
TL-Verilog
|calc |calc
@1
$aa ^2 $aa_sq[31:0] = $aa * $aa;
$cc $bb_sq[31:0] = $bb * $bb;
+ sqrt @2
$bb ^2 $cc_sq[31:0] = $aa_sq + $bb_sq;
@3
$cc[31:0] = sqrt($cc_sq);
Stage: 1 2 3
28
Redwood EDA
SystemVerilog vs. TL-Verilog
|calc System // Calc Pipeline
a ^2
Verilog logic [31:0] a_C1;
c
logic [31:0] b_C1;
+ sqrt logic [31:0] a_sq_C1,
b
a_sq_C2;
^2
logic [31:0] b_sq_C1,
b_sq_C2;
logic [31:0] c_sq_C2,
c_sq_C3;
~3.5x logic [31:0] c_C3;
TL-Verilog always_ff @(posedge clk) a_sq_C2 <= a_sq_C1;
always_ff @(posedge clk) b_sq_C2 <= b_sq_C1;
|calc always_ff @(posedge clk) c_sq_C3 <= c_sq_C2;
@1 // Stage 1
$aa_sq[31:0] = $aa * $aa; assign a_sq_C1 = a_C1 * a_C1;
$bb_sq[31:0] = $bb * $bb; assign b_sq_C1 = b_C1 * b_C1;
@2 // Stage 2
$cc_sq[31:0] = $aa_sq + $bb_sq; assign c_sq_C2 = a_sq_C2 + b_sq_C2;
@3 // Stage 3
$cc[31:0] = sqrt($cc_sq); assign c_C3 = sqrt(c_sq_C3);
29
Redwood EDA
Retiming -- Easy and Safe
|calc
@1 |calc
$aa_sq[31:0] = $aa * $aa; $aa_sq
$bb_sq[31:0] = $bb * $bb; $aa
^2 $cc_sq
@2 $cc
$bb_sq + sqrt
$cc_sq[31:0] = $aa_sq + $bb_sq; $bb ^2
@3
$cc[31:0] = sqrt($cc_sq);
0 1 2 3 4
|calc ==
@0
$aa_sq[31:0] = $aa * $aa; |calc
@1 $aa_sq
$aa ^2
$bb_sq[31:0] = $bb * $bb; $cc_sq $cc
@2 $bb_sq + sqrt
$cc_sq[31:0] = $aa_sq + $bb_sq; $bb ^2
@4
$cc[31:0] = sqrt($cc_sq); 0 1 2 3 4
clk
^2
+ sqrt
^2
clk
^2
+ sqrt
^2
32
Redwood EDA
Makerchip - a level deeper
33
Redwood EDA
Identifiers and Types
Numeric identifiers
● >>1: ahead by 1
34
Redwood EDA
Fibonacci Series in a Pipeline
Next value is sum of previous two: 1, 1, 2, 3, 5, 8, 13, ...
*reset
|fib
1 $num
1 2 3
|fib
@1
$num[31:0] = *reset ? 1 : (>>1$num + >>2$num);
35
Redwood EDA
Lab: Pipeline
See if you can produce this:
Error conditions (leave
unassigned)
ORs
which ORs together (||) various error conditions that can occur within a
computation pipeline.
Open in Makerchip
(makerchip.com/sandbox/0/0xGhJP)
36
Redwood EDA
Lab: Counter and Calculator in Pipeline
|calc
$op[1:0]
1. Put calculator and counter in
stage @1 of a |calc pipeline. +
2. Check log, diagram, and 0
-
waveform. $val1[31:0] 1
2
3. Confirm save. $val2[31:0] * 3
$out[31:0]
/ 32’b0
$reset
0 $cnt
1
+
@1
37
Redwood EDA
Lab: 2-Cycle Calculator
1
>>2
At high frequency, we might need to |calc
calculate every other cycle. $op[1:0]
39
Redwood EDA
Clock Gating
a ^2
c
+ sqrt
b ^2
● Motivation:
○ Clock signals are distributed to EVERY flip-flop.
○ Clocks toggle twice per cycle.
○ This consumes power.
● Clock gating avoids toggling clock signals.
● TL-Verilog can produce fine-grained gating (or enables).
40
Redwood EDA
Total Distance (Makerchip walkthrough)
*reset
41
Redwood EDA
Lab: 2-Cycle Calculator with Validity
>>2
1. Use: |calc
$valid_or_reset = $valid || $reset; $op[1:0]
For reference: 0
$val1[31:0]
- 1
|calc 2
@1
$valid = ...; $val2[31:0] * 3
$out[31:0]
?$valid
@1
$aa_sq[31:0] = $aa * $aa;
...
/ 32’b0
$reset
0
2. Verify behavior in waveform. 1 $valid
+
@1 @2
42
Redwood EDA
Lab: Calculator with Single-Value Memory
|calc >>2
>>2
Calculators support “mem” and “recall”,
$op[2:0]
to remember and recall a value. (mem) 5
0 $mem[31:0]
1. Extend $op to 3 bits. + (recall)
4
2. Add memory MUX. 0
$val1[31:0]
- 1
3. Select recall value in output MUX. 2
/ 32’b0
$reset
0 $valid
1
+
@1 @2
43
Redwood EDA
Hierarchy
|default
/yy[Y_SIZE-1:0]
/xx[X_SIZE-1:0]
@1
// Sum left + me + right.
$row_cnt[1:0] = ...;
// Sum three $row_cnt's: above + mine + below.
$cnt[3:0] = ...;
// Init state.
$init_alive[0:0] = ...;
|default
/yy[Y_SIZE-1:0]
/xx[X_SIZE-1:0]
@1
$alive = ...;
|somewhere_else
// ...
// “Lexical re-entrance”
|default
@1
/yy[*] // == [Y_SIZE-1:0]
// Row vector.
$row[X_SIZE-1:0] = /xx[*]$alive;
/xx[*]
$alive_to_right = /xx[(#xx + 1) % X_SIZE]$alive;
$reset = /top|reset>>1$reset;
// http://makerchip.com/sandbox/0/0y8h1B
45
Redwood EDA
Lab: Hierarchy
46
Redwood EDA
Arrays
A low-level implementation $reset 0
$wr_en
of a 1-read, 1-write, array:
...
$wr_index[5:0]
...
$wr_data[31:0] ==
== $rd_data
$rd_en
$rd_index[5:0]
...
|pipe
@1
// Write
/entry[63:0]
$wr = |pipe$wr_en && (#entry == |pipe$wr_index);
$value[31:0] = $reset
|pipe$reset ? 32’b0 : $wr_en
$wr ? |pipe$wr_data : $wr_index[5:0]
$rd_data
$RETAIN; // AKA: >>1$value $wr_data[31:0]
@2 $rd_en
// Read $rd_index[5:0]
?$rd_en
$rd_data[31:0] = /entry[$rd_index]$value;
47
Redwood EDA
Lab: Calculator with Memory
$reset 0
1. Replace single-entry memory $wr_en
...
$wr_index[5:0]
($mem[31:0]) with an 8-entry
...
$wr_data[31:0] ==
== $rd_data
memory. $rd_en
$rd_index[5:0]
2.
...
mem and recall are wr_en/rd_en.
3. Let $val1[2:0] provide the rd/wr
index.
>>2
4. Reference the previous slide to $op[2:0]
|calc >>1
48
Redwood EDA
/
GRAVEYARD
49
Redwood EDA
Founder Redwood
I was a circuit designer for companies like Intel for almost 20 yrs. How is.. and should be..
I believe with the right approach & tools digital design can be much easier to learn, easier to do, and a lot
more fun.
In this workshop, you’ll learn this methodology, you’ll learn the tools, and you’ll design your own
pipelined RISC-V CPU core from the ground up. These are skills generally learned over several college
courses.
You all should be commended for taking action not only learn circuit design, but to position yourselves
ahead of the curve.
50
TM
Redwood EDA
- Digital design tools using techniques that are not yet widely adopted in the
industry
-
51
Redwood EDA
Lab: Calculator with Single-Value Memory
>>2
Calculators support “mem” and “recall”, $op[2:0]
|calc >>1
to remember and recall a value. (mem) 5
0 $mem[31:0]
1. Extend $op to 3 bits. + (recall)
4
2. Add memory MUX. 0
$val1[31:0]
- 1
3. Select recall value in output MUX. 2
4. Verify behavior in waveform. $val2[31:0] * 3
$out[31:0]
/ 32’b0
$reset
0 $valid
1
+
@1 @2
52
Redwood EDA