• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jul 11th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. module priority_select #(
2.     parameter W_REQ = 32 // must be of form 2**m * 3**n, m >= 0, n >= 0
3. ) (
4.     input  wire [W_REQ-1:0] req,
5.     output wire [W_REQ-1:0] gnt
6. );
7.
8. generate
9. if (W_REQ <= 4) begin: base
10.     reg [W_REQ-1:0] deny;
11.     always @ (*) begin: smear
12.         integer i;
13.         deny[0] = 1'b0;
14.         for (i = 1; i < W_REQ; i = i + 1)
15.             deny[i] = deny[i - 1] || req[i - 1];
16.     end
17.     assign gnt = req & ~deny;
18.
19. end else begin: recurse
20.     localparam SPLIT =
21.         W_REQ % 4 == 0 ? 4 :
22.         W_REQ % 3 == 0 ? 3 :
23.                          2 ;
24.     localparam PART_SIZE = W_REQ / SPLIT;
25.     wire [W_REQ-1:0] partial_gnts;
26.
27.     priority_select #(
28.         .W_REQ (PART_SIZE)
29.     ) inner_select [SPLIT-1:0] (
30.         .req (req),
31.         .gnt (partial_gnts)
32.     );
33.
34.     integer i;
35.     reg  [SPLIT-1:0] coarse_req;
36.     wire [SPLIT-1:0] coarse_gnt;
37.     always @ (*)
38.         for (i = 0; i < SPLIT; i = i + 1)
39.             coarse_req[i] = |(partial_gnts[i * PART_SIZE +: PART_SIZE]);
40.
41.     priority_select #(
42.         .W_REQ (SPLIT)
43.     ) outer_select (
44.         .req (coarse_req),
45.         .gnt (coarse_gnt)
46.     );
47.
48.     reg [W_REQ-1:0] masked_gnt;
49.     always @ (*)
50.         for (i = 0; i < SPLIT; i = i + 1)
51.             masked_gnt[i * PART_SIZE +: PART_SIZE] =
52.                 partial_gnts[i * PART_SIZE +: PART_SIZE]
53.                 & {PART_SIZE{coarse_gnt[i]}};
54.
55.     assign gnt = masked_gnt;
56. end
57. endgenerate
58.
59. endmodule
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top