summaryrefslogtreecommitdiff
path: root/docs/src/explanations/naming.md
diff options
context:
space:
mode:
authormergify[bot]2022-06-16 23:15:42 +0000
committerGitHub2022-06-16 23:15:42 +0000
commitd001b34f816f1f65d0625aebf33e5cfc5ba93e49 (patch)
tree7145978904fea41e4a61a14ff3b08d3b243cf951 /docs/src/explanations/naming.md
parent13641d95951b189d7f5b0d4d99ace45f8b8f6282 (diff)
Define leading '_' as API for creating temporaries (backport #2580) (#2581)
* Define leading '_' as API for creating temporaries Chisel and FIRRTL have long used signals with names beginning with an underscore as an API to specify that the name does not really matter. Tools like Verilator follow a similar convention and exclude signals with underscore names from waveform dumps by default. With the introduction of compiler-plugin prefixing in Chisel 3.4, the convention remained but was hard for users to use unless the unnnamed signal existed outside of any prefix domain. Notably, unnamed signals are most useful when creating wires inside of utility methods which almost always results in the signal ending up with a prefix. With this commit, Chisel explicitly recognizes signals whos val names start with an underscore and preserve that underscore regardless of any prefixing. Chisel will also ignore such underscores when generating prefixes based on the temporary signal, preventing accidental double underscores in the names of signals that are prefixed by the temporary. (cherry picked from commit bd94366290886f3489d58f88b9768c7c11fa2cb6) * Remove unused defaultPrefix argument from _computeName (cherry picked from commit ec178aa20a830df2c8c756b9e569709a59073554) # Conflicts: # core/src/main/scala/chisel3/Module.scala # core/src/main/scala/chisel3/experimental/hierarchy/ModuleClone.scala * Resolve backport conflicts * Waive false positive binary compatibility errors Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'docs/src/explanations/naming.md')
-rw-r--r--docs/src/explanations/naming.md121
1 files changed, 117 insertions, 4 deletions
diff --git a/docs/src/explanations/naming.md b/docs/src/explanations/naming.md
index a9f21936..99797cb2 100644
--- a/docs/src/explanations/naming.md
+++ b/docs/src/explanations/naming.md
@@ -24,11 +24,11 @@ import chisel3.experimental.{prefix, noPrefix}
import chisel3.stage.ChiselStage
```
-With the release of Chisel 3.4, users should add the following line to their build.sbt settings to get the improved
-naming:
+With the release of Chisel 3.5, users are required to add the following line to
+their build.sbt settings:
```scala
-// chiselVersion is the String version (eg. "3.4.0")
+// chiselVersion is the String version (eg. "3.5.3")
addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % chiselVersion cross CrossVersion.full)
```
@@ -78,6 +78,29 @@ class Example2 extends Module {
ChiselStage.emitVerilog(new Example2)
```
+Prefixing can also be derived from the name of signals on the left-hand side of a connection.
+While this is not implemented via the compiler plugin, the behavior should feel similar:
+
+```scala mdoc
+class ConnectPrefixing extends Module {
+ val in = IO(Input(UInt(2.W)))
+ // val in = autoNameRecursively("in")(prefix("in")(IO(Input(UInt(2.W)))))
+
+ val out = IO(Output(UInt(2.W)))
+ // val out = autoNameRecursively("out")(prefix("out")(IO(Output(UInt(2.W)))))
+
+ out := { // technically this is not wrapped in autoNameRecursively nor prefix
+ // But the Chisel runtime will still use the name of `out` as a prefix
+ val double = in * in
+ // val double = autoNameRecursively("double")(prefix("double")(in * in))
+ double + 1.U
+ }
+}
+```
+```scala mdoc:verilog
+ChiselStage.emitVerilog(new ConnectPrefixing)
+```
+
Note that the naming also works if the hardware type is nested in an `Option` or a subtype of `Iterable`:
```scala mdoc
@@ -121,7 +144,7 @@ Users who desire a prefix are encouraged to provide one as [described below](#pr
### Prefixing
As shown above, the compiler plugin automatically attempts to prefix some of your signals for you. However, you as a
-user can also add your own prefixes. This is especially for ECO-type fixes where you need to add some logic to a module
+user can also add your own prefixes. This is especially useful for ECO-type fixes where you need to add some logic to a module
but don't want to influence other names in the module.
In the following example, we prefix additional logic with "ECO", where `Example4` is pre-ECO and `Example5` is post-ECO:
@@ -202,6 +225,96 @@ class Example8 extends Module {
ChiselStage.emitVerilog(new Example8)
```
+Note that using `.suggestName` does **not** affect prefixes derived from val names;
+however, it _can_ affect prefixes derived from connections (eg. `:=`):
+
+```scala mdoc
+class ConnectionPrefixExample extends Module {
+ val in0 = IO(Input(UInt(2.W)))
+ val in1 = IO(Input(UInt(2.W)))
+
+ val out0 = {
+ val port = IO(Output(UInt()))
+ // Even though this suggestName is before mul, the prefix used in this scope
+ // is derived from `val out0`, so this does not affect the name of mul
+ port.suggestName("foo")
+ // out0_mul
+ val mul = in0 * in1
+ port := mul + 1.U
+ port
+ }
+
+ val out1 = IO(Output(UInt()))
+ val out2 = IO(Output(UInt()))
+
+ out1 := {
+ // out1_sum
+ val sum = in0 + in1
+ sum + 1.U
+ }
+ // Comes after so does *not* affect prefix above
+ out1.suggestName("bar")
+
+ // Comes before so *does* affect prefix below
+ out2.suggestName("fizz")
+ out2 := {
+ // fizz_diff
+ val diff = in0 - in1
+ diff + 1.U
+ }
+}
+```
+```scala mdoc:verilog
+ChiselStage.emitVerilog(new ConnectionPrefixExample)
+```
+
+As this example illustrates, this behavior is slightly inconsistent so is subject to change in a future version of Chisel.
+
+
+### Behavior for "Unnamed signals" (aka "Temporaries")
+
+If you want to signify that the name of a signal does not matter, you can prefix the name of your val with `_`.
+Chisel will preserve the convention of leading `_` signifying an unnamed signal across prefixes.
+For example:
+
+```scala mdoc
+class TemporaryExample extends Module {
+ val in0 = IO(Input(UInt(2.W)))
+ val in1 = IO(Input(UInt(2.W)))
+
+ val out = {
+ val port = IO(Output(UInt()))
+ val _sum = in0 + in1
+ port := _sum + 1.U
+ port
+ }
+}
+```
+```scala mdoc:verilog
+ChiselStage.emitVerilog(new TemporaryExample)
+```
+
+If an unnamed signal is itself used to generate a prefix, the leading `_` will be ignored to avoid double `__` in the names of further nested signals.
+
+
+```scala mdoc
+class TemporaryPrefixExample extends Module {
+ val in0 = IO(Input(UInt(2.W)))
+ val in1 = IO(Input(UInt(2.W)))
+ val out = IO(Output(UInt()))
+
+ val _sum = {
+ val x = in0 + in1
+ x + 1.U
+ }
+ out := _sum & 0x2.U
+}
+```
+```scala mdoc:verilog
+ChiselStage.emitVerilog(new TemporaryPrefixExample)
+```
+
+
### Set a Module Name
If you want to specify the module's name (not the instance name of a module), you can always override the `desiredName`