Gates
In the circuit abstraction, hardware is described as a graph of connected components.
Operations on PyHGL signals usually generate a hardware gate.
Directional assignment
<==to a signal will automatically insert aWireif the signal is not assignable.
Functions
Unary functions:
Not,Bool,LogicNot,AndR,OrR,XorRBinary functions:
Lshift,Rshift,Eq,Ne,Lt,Gt,Le,Ge,Floordiv,ModMulti-inputs functions:
And,Or,Xor,Nand,Nor,Nxor,Cat,Pow,LogicAnd,LogicOr,Add,Sub,Mul
Function |
Description |
Operator |
Output Width |
|---|---|---|---|
|
bitwise not |
|
|
|
logic bool |
1 |
|
|
logic not |
|
1 |
|
and reduce |
1 |
|
|
or reduce |
1 |
|
|
xor reduce |
1 |
|
|
left shift |
|
|
|
right shift |
|
|
|
comparation |
|
1 |
|
divide |
|
|
|
mod |
|
|
|
bitwise and |
|
|
|
bitwise nand |
|
|
|
concatenation |
|
|
|
bits duplication |
|
|
|
logic and |
|
1 |
|
logic or |
`x |
|
|
add |
|
|
|
add |
|
|
|
mul |
|
|
Netlist
Netlists are gate that is assignable. Unlike Verilog, registers and latches should be explicitly declared, while wires are usually implicitly generated.
Function |
Description |
|---|---|
|
connect a wire behind x if x is not assignable |
|
connect a wire after x and return new signal |
|
a register whose input/output is x, reset/init is current value of x |
|
a register whose input is x, output is new signal |
|
latch |
|
tri-state wire |
ClockDomain
Reg will get the default clock and reset signals, which can be set by ClockDomain.
# negedge clk, asynchronous low-valid rst_n
with ClockDomain(clock=(clk,1), reset=(rst_n,0)):
register = Reg(UInt[8](0))
Examples
FullAdder
@module FullAdder:
a, b, cin = UInt.zeros(3)
s = a ^ b ^ cin
cout = a & b | (a ^ b) & cin
D flip flop
@module Register:
data, clk, set, reset = UInt.zeros(4)
nand1, nand2, nand3, nand4, Q, Qn = UInt.zeros(6)
nand1 <== Nand(set, nand4, nand2)
nand2 <== Nand(nand1, clk, reset)
nand3 <== Nand(nand2, clk, nand4)
nand4 <== Nand(nand3, data, reset)
Q <== Nand(set, nand2, Qn)
Qn <== Nand(Q, nand3, reset)