Last active
October 9, 2020 00:19
-
-
Save Wren6991/58f2a8f8c263a5bb5c169de258ad3040 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module priority_select #( | |
parameter N = 16 // any positive integer | |
) ( | |
input wire [N-1:0] req, | |
output wire [N-1:0] gnt | |
); | |
generate | |
if (N == 1) begin: base_case0 | |
assign gnt = req; | |
end else if (N == 2) begin: base_case1 | |
assign gnt = {req[1] && !req[0], req[0]}; | |
end else begin: recurse | |
wire [1:0] coarse; | |
wire [N-1:0] fine; | |
priority_select #( | |
.N (N / 2) | |
) recurse_lower ( | |
.req (req [N/2-1:0]), | |
.gnt (fine[N/2-1:0]) | |
); | |
priority_select #( | |
.N (N - N / 2) | |
) recurse_upper ( | |
.req (req [N-1:N/2]), | |
.gnt (fine[N-1:N/2]) | |
); | |
assign coarse = {|req[N-1:N/2], |req[N/2-1:0]}; | |
assign gnt = fine & { | |
{N - N / 2{coarse[1] && !coarse[0]}}, | |
{ N / 2{ coarse[0]}} | |
}; | |
end | |
endgenerate | |
endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module priority_select #( | |
parameter N = 16 // any positive integer | |
) ( | |
input wire [N-1:0] req, | |
output wire [N-1:0] gnt | |
); | |
reg [N-1:0] deny; | |
integer i; | |
always @ (*) begin | |
deny[0] = 1'b0; | |
for (i = 1; i < N; i = i + 1) | |
deny[i] = deny[i - 1] || req[i - 1]; | |
end | |
assign gnt = req & ~deny; | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment