Skip to content

Commit

Permalink
Added full_case and parallel_case attributes (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
sifferman authored Mar 11, 2024
1 parent f454387 commit df01650
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

### New Features

* `unique`, `unique0`, and `priority` case statements now produce corresponding
`parallel_case` and `full_case` statement attributes
* Added support for attributes in unary, binary, and ternary expressions
* Added support for shadowing interface names with local typenames
* Added support for streaming concatenations within ternary expressions
Expand Down
23 changes: 18 additions & 5 deletions src/Convert/Unique.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
-
- Conversion for `unique`, `unique0`, and `priority` (verification checks)
-
- This conversion simply drops these keywords, as they are only used for
- optimization and verification. There may be ways to communicate these
- attributes to certain downstream toolchains.
- For `case`, these verification checks are replaced with equivalent
- `full_case` and `parallel_case` attributes. For `if`, they are simply
- dropped.
-}

module Convert.Unique (convert) where
Expand All @@ -21,6 +21,19 @@ convert =
convertStmt :: Stmt -> Stmt
convertStmt (If _ cc s1 s2) =
If NoCheck cc s1 s2
convertStmt (Case _ kw expr cases) =
Case NoCheck kw expr cases
convertStmt (Case Priority kw expr cases) =
StmtAttr caseAttr caseStmt
where
caseAttr = Attr [("full_case", Nil)]
caseStmt = Case NoCheck kw expr cases
convertStmt (Case Unique kw expr cases) =
StmtAttr caseAttr caseStmt
where
caseAttr = Attr [("full_case", Nil), ("parallel_case", Nil)]
caseStmt = Case NoCheck kw expr cases
convertStmt (Case Unique0 kw expr cases) =
StmtAttr caseAttr caseStmt
where
caseAttr = Attr [("parallel_case", Nil)]
caseStmt = Case NoCheck kw expr cases
convertStmt other = other
41 changes: 41 additions & 0 deletions test/core/case_violation_checks.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module UniqueCase(
input logic [1:0] select,
output logic [3:0] data
);
always_comb begin
data = 4'b0;
unique case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
endmodule

module Unique0Case(
input logic [1:0] select,
output logic [3:0] data
);
always_comb begin
data = 4'b0;
unique0 case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
endmodule

module PriorityCase(
input logic [1:0] select,
output logic [3:0] data
);
always_comb begin
data = 4'b0;
priority case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
endmodule
3 changes: 3 additions & 0 deletions test/core/case_violation_checks.sv.pat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
affirm (* full_case, parallel_case *)
affirm (* parallel_case *)
affirm (* full_case *)
41 changes: 41 additions & 0 deletions test/core/case_violation_checks.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module UniqueCase(
input wire [1:0] select,
output reg [3:0] data
);
always @* begin
data = 4'b0;
case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
endmodule

module Unique0Case(
input wire [1:0] select,
output reg [3:0] data
);
always @* begin
data = 4'b0;
case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
endmodule

module PriorityCase(
input wire [1:0] select,
output reg [3:0] data
);
always @* begin
data = 4'b0;
case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
endmodule
7 changes: 7 additions & 0 deletions test/core/case_violation_checks_tb.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module top;
reg [1:0] select;
wire [3:0] data [2:0];
UniqueCase case0(select, data[0]);
Unique0Case case1(select, data[1]);
PriorityCase case2(select, data[2]);
endmodule

0 comments on commit df01650

Please sign in to comment.