llvm / llvm/circt

[FIRRTL] Bitwidth conventions for artihmetic ops

Open
#2,669 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.2k
Forks
524
Avg merge
3d 2h
Merged PRs (30d)
46

Description

`firtool` bit extends each operand to the destination type. This seems to differ from `firrtl` output.
The output is semantically correct, but this might be a verilog output quality issue.
So, if a multiplication produces 3 bit result, then the input operands are extended to 3 bits.
This is the standard assumption for `HW` dialect, https://github.com/llvm/circt/blob/main/lib/Conversion/FIRRTLToHW/LowerToHW.cpp#L3005

Input `fir`
```python
circuit MyModule :

module MyModule :
input in1: UInt<1>
input in2: UInt<2>
output out: UInt<3>

out <= mul(in1, in2)
```
`firtool` output
``` verilog
module MyModule(
input in1,
input [1:0] in2,
output [2:0] out);
assign out = {2'h0, in1} * {1'h0, in2};
endmodule
```
`firrtl` output
```verilog
module MyModule(
input in1,
input [1:0] in2,
output [2:0] out
);
assign out = in1 * in2;
endmodule
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the FIRRTL-to-HW lowering logic in lib/Conversion/FIRRTLToHW/LowerToHW.cpp around the referenced line. Compare the generated Verilog operand extensions with FIRRTL behavior for arithmetic operations such as the supplied multiplication example. Done means the intended bitwidth convention is established and the resulting output behavior is validated by an appropriate regression.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.