Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create chisel3-vs-compat.md #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions docs/src/main/tut/chisel3/chisel3-vs-compat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
---
layout: docs
title: "chisel3 vs. compatibility mode"
section: "chisel3"
---

Chisel 3 supports "compatibility mode" which serves the purpose of bridging
the semantic gap between Chisel 2 and Chisel 3 with Chisel2-like semantics.
Chisel code using this mode depends on Chisel 3, yet the Scala code has
`import Chisel._` instead of the normal `import chisel3._`. This page serves
to document the differences for helping migrate from compatibility mode to the
safer and more modern Chisel 3 semantics.

### Connections

#### Compatibility mode

In compatibility mode, both connection operators `:=` and `<>` are actually the same.
They both are bidirectional and noncommutative--the right side will be treated as
the source and the left side will be treated as the sink.

```scala
import Chisel._
class MyModule extends Module {
val io = new Bundle {
val in = Decoupled(UInt(width = 4)).flip
val out = Decoupled(UInt(width = 4))
}
io.in <> io.out // This works
io.in := io.out // This is equivalent
io.out <> io.in // This will error
}
```
Furthermore, error detection and reporting is defered to FIRRTL compilation.

#### Chisel 3

In Chisel 3, `:=` is refered to as "monoconnect" and `<>` is called "bulkconnect".

* Monoconnect
`:=` treats everything on the left-hand side as a sink, even if the type is
bidirectional. This means it cannot be used to drive bidirectional output ports,
but can be used to drive wires from bidirectional inputs or outputs to "monitor"
the the full aggregate, ignoring directions.

* Bulkconnect
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is actually BiConnect, yes? Or should this be referred to as Bulk Connect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traditionally people called it "bulk connect" but I agree "biconnect" is better anyway

`<>` performs bidirectional connections and is commutative. At least one of the
arguments must be a port.
It will determine the correct leaf-level connections based on the directions of
its port arguments.
It cannot be used to connect two components _inside_ of a module.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So.... how are you supposed to do that? Do you have to use two monoconnects?

a := b
b := a


```scala
import chisel3._
import chisel3.util._
class MyModule extends Module {
val io = IO(new Bundle {
val in = Flipped(Decoupled(UInt(4.W)))
val out = Decoupled(UInt(4.W))
val x = Output(UInt(8.W))
})
io.out <> io.in // This works
io.in <> io.out // So does this
io.out := io.in // Error, cannot drive io.out.ready

val w = Wire(Decoupled(UInt(4.W)))
w := io.in // This works, w can be seen as "monitoring" io.in
4.U <> io.x // This also works but is stylistically suspect
}
```

### Width Declaration

#### Compatibility mode
```scala
val x = UInt(width = 8)
```
#### Chisel 3
```scala
val x = UInt(8.W)
```
Notably, widths are now a type rather than a byname argument to the `UInt`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Notably, widths are now a type rather than a byname argument to the `UInt`
Notably, widths are now a type rather than a by-name argument to the `UInt`

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I just realized that what I really mean is "named argument", by-name is when you put => in front of the type 🤦‍♂

constructor.


### Literals

#### Compatibility mode
```scala
val x = UInt(2)
val y = SInt(-1, width = 8)
```
#### Chisel 3
```scala
val x = 2.U
val y = 0.S(8.W)
jackkoenig marked this conversation as resolved.
Show resolved Hide resolved
```

### Direction

#### Compatibility mode
```scala
val x = UInt(INPUT, 8)
val y = Bool(OUTPUT)
val z = (new MyBundle).flip
```
#### Chisel 3
```scala
val x = Input(UInt(8.W))
val y = Output(Bool())
val z = Flipped(new MyBundle)
```

### Module IO
#### Compatibility mode
```scala
class MyModule extends Module {
val io = new Bundle { ... }
}
```
#### Chisel 3

In Chisel 3, all declared ports must be wrapped in `IO(...)`. For `Modules`,
this is just `val io`.
```scala
class MyModule extends Module {
val io = IO(new Bundle { ... } )
}
```
But in Chisel 3, `MultiIOModules` have the ability to declare multiple "ios".
While `val io` is not required, the implicit `clock` and `reset` are still there.
```scala
class MyModule2 extends MultiIOModule {
val foo = IO(Input(UInt(8.W)))
}
```
Chisel 3 also has `RawModule` which allows arbitrary ports and has no implicit
`clock` nor `reset`.
```scala
class MyModule3 extends RawModule {
val foo = IO(Output(Vec(8, Bool())))
}
```

### Utilities

Many constructs originally available via `import Chisel._` are now located in
`chisel3.util`. They can be imported
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there text missing? They can be imported doesn't convey much information.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sorry, this is a WIP and I jumped around, sorry I should've made this a draft PR