OpenCores
URL https://opencores.org/ocsvn/spacewiresystemc/spacewiresystemc/trunk

Subversion Repositories spacewiresystemc

[/] [spacewiresystemc/] [trunk/] [altera_work/] [spw_fifo_ulight/] [ulight_fifo/] [synthesis/] [submodules/] [altera_merlin_arbitrator.sv] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 32 redbear
// (C) 2001-2017 Intel Corporation. All rights reserved.
2
// Your use of Intel Corporation's design tools, logic functions and other
3
// software and tools, and its AMPP partner logic functions, and any output
4 40 redbear
// files from any of the foregoing (including device programming or simulation
5 32 redbear
// files), and any associated documentation or information are expressly subject
6
// to the terms and conditions of the Intel Program License Subscription
7 40 redbear
// Agreement, Intel FPGA IP License Agreement, or other applicable
8 32 redbear
// license agreement, including, without limitation, that your use is for the
9
// sole purpose of programming logic devices manufactured by Intel and sold by
10
// Intel or its authorized distributors.  Please refer to the applicable
11
// agreement for further details.
12
 
13
 
14
// (C) 2001-2010 Altera Corporation. All rights reserved.
15
// Your use of Altera Corporation's design tools, logic functions and other
16
// software and tools, and its AMPP partner logic functions, and any output
17
// files any of the foregoing (including device programming or simulation
18
// files), and any associated documentation or information are expressly subject
19
// to the terms and conditions of the Altera Program License Subscription
20
// Agreement, Altera MegaCore Function License Agreement, or other applicable
21
// license agreement, including, without limitation, that your use is for the
22
// sole purpose of programming logic devices manufactured by Altera and sold by
23
// Altera or its authorized distributors.  Please refer to the applicable
24
// agreement for further details.
25
 
26
 
27
// $Id: //acds/main/ip/merlin/altera_merlin_std_arbitrator/altera_merlin_std_arbitrator_core.sv#3 $
28
// $Revision: #3 $
29
// $Date: 2010/07/07 $
30
// $Author: jyeap $
31
 
32
/* -----------------------------------------------------------------------
33
Round-robin/fixed arbitration implementation.
34
 
35
Q: how do you find the least-significant set-bit in an n-bit binary number, X?
36
 
37
A: M = X & (~X + 1)
38
 
39
Example: X = 101000100
40
 101000100 &
41
 010111011 + 1 =
42
 
43
 101000100 &
44
 010111100 =
45
 -----------
46
 000000100
47
 
48
The method can be generalized to find the first set-bit
49
at a bit index no lower than bit-index N, simply by adding
50
2**N rather than 1.
51
 
52
 
53
Q: how does this relate to round-robin arbitration?
54
A:
55
Let X be the concatenation of all request signals.
56
Let the number to be added to X (hereafter called the
57
top_priority) initialize to 1, and be assigned from the
58
concatenation of the previous saved-grant, left-rotated
59
by one position, each time arbitration occurs.  The
60
concatenation of grants is then M.
61
 
62
Problem: consider this case:
63
 
64
top_priority            = 010000
65
request                 = 001001
66
~request + top_priority = 000110
67
next_grant              = 000000 <- no one is granted!
68
 
69
There was no "set bit at a bit index no lower than bit-index 4", so
70
the result was 0.
71
 
72
We need to propagate the carry out from (~request + top_priority) to the LSB, so
73
that the sum becomes 000111, and next_grant is 000001.  This operation could be
74
called a "circular add".
75
 
76
A bit of experimentation on the circular add reveals a significant amount of
77
delay in exiting and re-entering the carry chain - this will vary with device
78
family.  Quartus also reports a combinational loop warning.  Finally,
79
Modelsim 6.3g has trouble with the expression, evaluating it to 'X'.  But
80
Modelsim _doesn't_ report a combinational loop!)
81
 
82
An alternate solution: concatenate the request vector with itself, and OR
83
corresponding bits from the top and bottom halves to determine next_grant.
84
 
85
Example:
86
 
87
top_priority                        =        010000
88
{request, request}                  = 001001 001001
89
{~request, ~request} + top_priority = 110111 000110
90
result of & operation               = 000001 000000
91
next_grant                          =        000001
92
 
93
Notice that if request = 0, the sum operation will overflow, but we can ignore
94
this; the next_grant result is 0 (no one granted), as you might expect.
95
In the implementation, the last-granted value must be maintained as
96
a non-zero value - best probably simply not to update it when no requests
97
occur.
98
 
99
----------------------------------------------------------------------- */
100
 
101
`timescale 1 ns / 1 ns
102
 
103
module altera_merlin_arbitrator
104
#(
105
    parameter NUM_REQUESTERS = 8,
106
    // --------------------------------------
107
    // Implemented schemes
108
    // "round-robin"
109
    // "fixed-priority"
110
    // "no-arb"
111
    // --------------------------------------
112
    parameter SCHEME         = "round-robin",
113
    parameter PIPELINE       = 0
114
)
115
(
116
    input clk,
117
    input reset,
118
 
119
    // --------------------------------------
120
    // Requests
121
    // --------------------------------------
122
    input [NUM_REQUESTERS-1:0]  request,
123
 
124
    // --------------------------------------
125
    // Grants
126
    // --------------------------------------
127
    output [NUM_REQUESTERS-1:0] grant,
128
 
129
    // --------------------------------------
130
    // Control Signals
131
    // --------------------------------------
132
    input                       increment_top_priority,
133
    input                       save_top_priority
134
);
135
 
136
    // --------------------------------------
137
    // Signals
138
    // --------------------------------------
139
    wire [NUM_REQUESTERS-1:0]   top_priority;
140
    reg  [NUM_REQUESTERS-1:0]   top_priority_reg;
141
    reg  [NUM_REQUESTERS-1:0]   last_grant;
142
    wire [2*NUM_REQUESTERS-1:0] result;
143
 
144
    // --------------------------------------
145
    // Scheme Selection
146
    // --------------------------------------
147
    generate
148
        if (SCHEME == "round-robin" && NUM_REQUESTERS > 1) begin
149
            assign top_priority = top_priority_reg;
150
        end
151
        else begin
152
            // Fixed arbitration (or single-requester corner case)
153
            assign top_priority = 1'b1;
154
        end
155
    endgenerate
156
 
157
    // --------------------------------------
158
    // Decision Logic
159
    // --------------------------------------
160
    altera_merlin_arb_adder
161
    #(
162
        .WIDTH (2 * NUM_REQUESTERS)
163
    )
164
    adder
165
    (
166
        .a ({ ~request, ~request }),
167
        .b ({{NUM_REQUESTERS{1'b0}}, top_priority}),
168
        .sum (result)
169
    );
170
 
171
 
172
    generate if (SCHEME == "no-arb") begin
173
 
174
        // --------------------------------------
175
        // No arbitration: just wire request directly to grant
176
        // --------------------------------------
177
        assign grant = request;
178
 
179
    end else begin
180
        // Do the math in double-vector domain
181
        wire [2*NUM_REQUESTERS-1:0] grant_double_vector;
182
        assign grant_double_vector = {request, request} & result;
183
 
184
        // --------------------------------------
185
        // Extract grant from the top and bottom halves
186
        // of the double vector.
187
        // --------------------------------------
188
        assign grant =
189
            grant_double_vector[NUM_REQUESTERS - 1 : 0] |
190
            grant_double_vector[2 * NUM_REQUESTERS - 1 : NUM_REQUESTERS];
191
 
192
    end
193
    endgenerate
194
 
195
    // --------------------------------------
196
    // Left-rotate the last grant vector to create top_priority.
197
    // --------------------------------------
198
    always @(posedge clk or posedge reset) begin
199
        if (reset) begin
200
            top_priority_reg <= 1'b1;
201
        end
202
        else begin
203
            if (PIPELINE) begin
204
                if (increment_top_priority) begin
205
                    top_priority_reg <= (|request) ? {grant[NUM_REQUESTERS-2:0],
206
                        grant[NUM_REQUESTERS-1]} : top_priority_reg;
207
                end
208
            end else begin
209
                if (increment_top_priority) begin
210
                    if (|request)
211
                        top_priority_reg <= { grant[NUM_REQUESTERS-2:0],
212
                            grant[NUM_REQUESTERS-1] };
213
                    else
214
                        top_priority_reg <= { top_priority_reg[NUM_REQUESTERS-2:0], top_priority_reg[NUM_REQUESTERS-1] };
215
                end
216
                else if (save_top_priority) begin
217
                    top_priority_reg <= grant;
218
                end
219
            end
220
        end
221
    end
222
 
223
endmodule
224
 
225
// ----------------------------------------------
226
// Adder for the standard arbitrator
227
// ----------------------------------------------
228
module altera_merlin_arb_adder
229
#(
230
    parameter WIDTH = 8
231
)
232
(
233
    input [WIDTH-1:0] a,
234
    input [WIDTH-1:0] b,
235
 
236
    output [WIDTH-1:0] sum
237
);
238
 
239
    wire [WIDTH:0] sum_lint;
240
    // ----------------------------------------------
241
    // Benchmarks indicate that for small widths, the full
242
    // adder has higher fmax because synthesis can merge
243
    // it with the mux, allowing partial decisions to be
244
    // made early.
245
    //
246
    // The magic number is 4 requesters, which means an
247
    // 8 bit adder.
248
    // ----------------------------------------------
249
    genvar i;
250
    generate if (WIDTH <= 8) begin : full_adder
251
 
252
        wire cout[WIDTH-1:0];
253
 
254
        assign sum[0]  = (a[0] ^ b[0]);
255
        assign cout[0] = (a[0] & b[0]);
256
 
257
        for (i = 1; i < WIDTH; i = i+1) begin : arb
258
 
259
            assign sum[i] = (a[i] ^ b[i]) ^ cout[i-1];
260
            assign cout[i] = (a[i] & b[i]) | (cout[i-1] & (a[i] ^ b[i]));
261
 
262
        end
263
 
264
    end else begin : carry_chain
265
 
266
        assign sum_lint = a + b;
267
        assign sum = sum_lint[WIDTH-1:0];
268
 
269
    end
270
    endgenerate
271
 
272
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.