added `full_case` and `parallel_case` attributes

This commit is contained in:
Ethan Sifferman 2024-01-22 18:47:35 -08:00
parent 9825bb9bcb
commit 28498b8d49
6 changed files with 159 additions and 2 deletions

View File

@ -21,6 +21,23 @@ convert =
convertStmt :: Stmt -> Stmt
convertStmt (If _ cc s1 s2) =
If NoCheck cc s1 s2
convertStmt (Case Priority kw expr cases) =
StmtAttr caseAttr caseStmt
where
caseAttr = Attr [("synthesis", Nil), ("full_case", Nil)]
caseStmt = Case NoCheck kw expr cases
convertStmt (Case Unique kw expr cases) =
StmtAttr caseAttr caseStmt
where
caseAttr = Attr [("synthesis", Nil), ("parallel_case", Nil)]
caseStmt = Case NoCheck kw expr cases
convertStmt (Case Unique0 kw expr cases) =
convertStmt (Case Unique kw expr cases)
convertStmt (Case _ kw expr cases) =
Case NoCheck kw expr cases
convertStmt other = other

View File

@ -0,0 +1,59 @@
module top;
logic [1:0] select;
logic [2:0][3:0] data;
UniqueCase case0(.select, .data(data[0]));
Unique0Case case1(.select, .data(data[1]));
PriorityCase case2(.select, .data(data[2]));
initial ;
endmodule
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

View File

@ -0,0 +1,76 @@
module top;
wire [1:0] select;
wire [11:0] data;
UniqueCase case0(
.select(select),
.data(data[0+:4])
);
Unique0Case case1(
.select(select),
.data(data[4+:4])
);
PriorityCase case2(
.select(select),
.data(data[8+:4])
);
endmodule
module UniqueCase (
select,
data
);
reg _sv2v_0;
input wire [1:0] select;
output reg [3:0] data;
always @(*) begin
if (_sv2v_0)
;
data = 4'b0000;
(* synthesis, parallel_case *)
case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
initial _sv2v_0 = 0;
endmodule
module Unique0Case (
select,
data
);
reg _sv2v_0;
input wire [1:0] select;
output reg [3:0] data;
always @(*) begin
if (_sv2v_0)
;
data = 4'b0000;
(* synthesis, parallel_case *)
case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
initial _sv2v_0 = 0;
endmodule
module PriorityCase (
select,
data
);
reg _sv2v_0;
input wire [1:0] select;
output reg [3:0] data;
always @(*) begin
if (_sv2v_0)
;
data = 4'b0000;
(* synthesis, full_case *)
case (select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
2'd2: data = 4'h3;
endcase
end
initial _sv2v_0 = 0;
endmodule

View File

@ -23,6 +23,7 @@ module UniqueCase(
always @* begin
data = 4'b0;
// Unique keyword doesn't exist in Verilog
(* synthesis, parallel_case *)
case(select)
2'd0: data = 4'ha;
2'd1: data = 4'h6;
@ -41,6 +42,7 @@ module WildcardCase(
data = 4'b0;
// Unique keyword doesn't exist in Verilog
// casez doesn't exist in VTR, so manually elaborating it
(* synthesis, parallel_case *)
case(select) // casez
2'b00: data = 4'h3;
// 2'b1?: data = 4'hd;

View File

@ -18,6 +18,7 @@ module FSM(
always @* begin
nextState = currentState;
(* synthesis, parallel_case *)
case(currentState)
S_A: nextState = a ? S_B : S_C;
S_B: nextState = a ? S_A : S_B;
@ -27,6 +28,7 @@ module FSM(
always @* begin
x = 1'b0;
(* synthesis, parallel_case *)
case(currentState)
S_A: x = ~a;
S_B: x = 1'b1;
@ -34,4 +36,4 @@ module FSM(
endcase
end
endmodule
endmodule

View File

@ -24,6 +24,7 @@ module Example(
// you expect a C function to do. Sadly VTR doesn't support the automatic
// keyword.
function [31:0] swapState(input [31:0] state);
(* synthesis, parallel_case *)
case(state)
// To return from a function assign the function name with a variable
FOO: swapState = BAR;
@ -77,4 +78,4 @@ module Example(
endmodule
endmodule