google / google/xls

Verilog output: Emit constant values only once, ideally as localparam

Open
#1,267 0 comments 0 reactions 0 assignees View on GitHub
codegen
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

Looking at Verilog output, the same constant is proliferated and assigned to wires in slightly different names.

Here an example from the apfloat.x adder; there is one constant ...

```rust
const MAX_EXPONENT = std::mask_bits();
```

... which then shows up in the generated verilog multiple times (here the output of a grep that only contains these values:)

```verilog
wire [7:0] p1_MAX_EXPONENT_comb;
wire [7:0] p1_MAX_EXPONENT__5_comb;
wire [7:0] p1_MAX_EXPONENT__7_comb;
wire [7:0] p1_MAX_EXPONENT__8_comb;
wire [7:0] p1_MAX_EXPONENT__6_comb;
assign p1_MAX_EXPONENT_comb = 8'hff;
assign p1_MAX_EXPONENT__5_comb = 8'hff;
assign p1_MAX_EXPONENT__7_comb = 8'hff;
assign p1_MAX_EXPONENT__8_comb = 8'hff;
assign p1_MAX_EXPONENT__6_comb = 8'hff;
```

### Expected
Ideally, these would be emitted only _once_ as a readable constant and possibly as `localparam` of sorts.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.