Skip to content

Commit

Permalink
Add a documentation for CombInit
Browse files Browse the repository at this point in the history
  • Loading branch information
ronan-lashermes authored Nov 9, 2023
1 parent c1513e2 commit 145ffeb
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions source/SpinalHDL/Semantic/assignments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,51 @@ Combinatorial loops

SpinalHDL checks that there are no combinatorial loops (latches) in your design.
If one is detected, it raises an error and SpinalHDL will print the path of the loop.

CombInit
--------

The special ``CombInit`` method can be used to "clone" a combinatorial value for latter modification.

.. code-block:: scala
val a = UInt(8 bits)
a := 1
val b = a
when(sel) {
b := 2
//At this point, a and b are evaluated to 2 : they represent the same set of wire
}
val c = UInt(8 bits)
c := 1
val d = CombInit(c)
// Here c and d are evaluated to 1
when(sel) {
d := 2
// At this point c === 1 and d === 2.
}
``CombInit`` clones a circuit, and initially drive it with the same input at the cloned value.
But you can now update the circuit without impacting the initial value.

If we look at the resulting Verilog, ``b`` is not present :

.. code-block:: verilog
always @(*) begin
a = 8'h01;
if(sel) begin
a = 8'h02;
end
end
assign c = 8'h01;
always @(*) begin
d = c;
if(sel) begin
d = 8'h02;
end
end

0 comments on commit 145ffeb

Please sign in to comment.