OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_verilator/] [topology/] [tree.h] - Blame information for rev 54

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
#ifndef BINTREE_H
2
        #define BINTREE_H
3
 
4
 
5
 
6
 
7
#define ROOT_L  (L-1) 
8
#define ROOT_ID  0
9
 
10
 
11
 
12
unsigned int    Lw;
13
unsigned int    Kw;
14
unsigned int    LKw;
15
 
16
 
17
 
18
 
19
 
20
 
21
 
22
 
23
 
24
 
25
unsigned int bintree_addrencode( unsigned int pos, unsigned int k, unsigned int l){
26
        unsigned int pow,i,tmp=0;
27
        unsigned int addrencode=0;
28
        unsigned int kw=0;
29
        while((0x1<<kw) < k)kw++;
30
        pow=1;
31
        for (i = 0; i <l; i=i+1 ) {
32
                tmp=(pos/pow);
33
                tmp=tmp%k;
34
                tmp=tmp<<(i)*kw;
35
                addrencode=addrencode | tmp;
36
                pow=pow * k;
37
        }
38
         return addrencode;
39
}
40
 
41
 
42
unsigned int bintree_addrdecode(unsigned int addrencode , unsigned int k, unsigned int l){
43
        unsigned int kw=0;
44
        unsigned int mask=0;
45
        unsigned int pow,i,tmp;
46
        unsigned int pos=0;
47
        while((0x1<<kw) < k){
48
                kw++;
49
                mask<<=1;
50
                mask|=0x1;
51
        }
52
        pow=1;
53
        for (i = 0; i <l; i=i+1 ) {
54
                tmp = addrencode & mask;
55
                tmp=(tmp*pow);
56
                pos= pos + tmp;
57
                pow=pow * k;
58
                addrencode>>=kw;
59
        }
60
        return pos;
61
}
62
 
63
 
64
 
65
unsigned int endp_addr_encoder ( unsigned int id){
66
                        return bintree_addrencode(id, T1, T2);
67
}
68
 
69
unsigned int endp_addr_decoder (unsigned int code){
70
                return bintree_addrdecode(code, T1, T2);
71
}
72
 
73
 
74
 
75
void topology_init (void){
76
 
77
        Lw=Log2(L);
78
        Kw=Log2(K);
79
        LKw=L*Kw;
80
 
81
 
82
        //assign current_layer_addr [ROOT_ID] = ROOT_L;
83
        //assign current_pos_addr [ROOT_ID] = {LKw{1'b0}}; 
84
        unsigned int addr = ROOT_L << LKw;
85
        router1[ROOT_ID]->current_r_addr = addr;
86 54 alirezamon
        router1[ROOT_ID]->current_r_id   = ROOT_ID;
87 48 alirezamon
 
88 54 alirezamon
 
89 48 alirezamon
        unsigned int pos,level;
90
        unsigned int num = 0;
91
        //connect all up connections
92
        for (level = 1; level<L; level=level+1) { // : level_c          
93
                unsigned int L1 = L-1-level;
94
                unsigned int level2= level - 1;
95
                unsigned int L2 = L-1-level2;
96
                unsigned int NPOS = powi(K,level); // number of routers in this level
97
                for ( pos = 0; pos < NPOS; pos=pos+1 ) { // : pos_c
98
 
99
                        unsigned int ID1 = sum_powi ( K,level) + pos;
100
                        unsigned int BINTREE_EQ_POS1 = pos* powi(K,L1);
101
                        unsigned int ADR_CODE1=bintree_addrencode(BINTREE_EQ_POS1,K,L);
102
                        unsigned int POS2 = pos /K ;
103
                        unsigned int ID2 = sum_powi ( K,level-1) + (pos/K);
104
                        unsigned int PORT2= pos % K;
105
                        unsigned int BINTREE_EQ_POS2 = POS2*powi(K,L2);
106
                        unsigned int ADR_CODE2=bintree_addrencode(BINTREE_EQ_POS2,K,L);
107
 
108
 
109
 
110
                        // node_connection('Router[id1][k] to router[id2][pos%k];  
111
                        //assign  router_chan_out [ID1][K] = router_chan_in [ID2][PORT2];
112
                        //assign  router_chan_out [ID2][PORT2]= router_chan_in[ID1][K];  
113
                        //bintree_connect(Ti(ID1),Ri(ID1),port,Ti(ID2),Ri(ID2),PORT2);
114 54 alirezamon
                    r2r_cnt_all[num] =(r2r_cnt_table_t){.id1=ID1, .t1=Ti(ID1), .r1=Ri(ID1), .p1=K,.id2=ID2, .t2=Ti(ID2), .r2=Ri(ID2), .p2=PORT2 };
115 48 alirezamon
 
116
 
117
 
118
 
119
                        unsigned int current_layer_addr  = L1;
120
                        unsigned int current_pos_addr    = ADR_CODE1;
121
                        //assign current_r_addr [ID1] = {current_layer_addr [ID1],current_pos_addr[ID1]};
122
                        unsigned int addr = (current_layer_addr << LKw)| current_pos_addr;
123
 
124
                        router2[Ri(ID1)]->current_r_addr = addr;
125 54 alirezamon
                        router2[Ri(ID1)]->current_r_id   = ID1;
126
 
127 48 alirezamon
                        //printf( "[%u] =(addr=%x), t1=%u, r1=%u, p1=%u, t2=%u, r2=%u, p2=%u \n",  num,addr, r2r_cnt_all[num].t1, r2r_cnt_all[num].r1, r2r_cnt_all[num].p1, r2r_cnt_all[num].t2, r2r_cnt_all[num].r2, r2r_cnt_all[num].p2 );
128
 
129
 
130
 
131
 
132
 
133
 
134
 
135
                 num++;
136
                        }// pos
137
 
138
                } //level
139
 
140 54 alirezamon
                R2R_TABLE_SIZ=num;
141 48 alirezamon
 
142
                // connect }points 
143
 
144
                for ( pos = 0; pos <  NE; pos=pos+1 ) { // : }points
145
                        //  node_connection T[pos] R[rid][pos %k];
146
                        unsigned int RID= sum_powi(K,L-1)+(pos/K);
147
                        unsigned int RPORT = pos%K;
148
                unsigned int CURRENTPOS=   bintree_addrencode(pos/K,K,L);
149
 
150
                        //assign router_chan_out [RID][RPORT] =    chan_in_all [pos];                     
151
                        //assign chan_out_all [pos] = router_chan_in [RID][RPORT];
152
                        r2e_cnt_all[pos].r1=Ri(RID);
153
                        r2e_cnt_all[pos].p1=RPORT;
154
 
155
                        er_addr [pos] = CURRENTPOS;
156
 
157
                } //pos    
158
 
159
}
160
 
161
 
162 54 alirezamon
void topology_connect_r2r (int n){
163
        fattree_connect(r2r_cnt_all[n]);
164
}
165
 
166
void topology_connect_r2e (int n){
167
        connect_r2e(2,r2e_cnt_all[n].r1,r2e_cnt_all[n].p1,n);
168
}
169
 
170
/*
171 48 alirezamon
void topology_connect_all_nodes (void){
172
        unsigned int pos,level;
173
        unsigned int num=0;
174
        //connect all up connections
175
        for (level = 1; level<L; level=level+1) { // : level_c
176
                unsigned int NPOS = powi(K,level); // number of routers in this level
177
                for ( pos = 0; pos < NPOS; pos=pos+1 ) { // : pos_c
178
 
179
                          fattree_connect(r2r_cnt_all[num]);
180
                          num++;
181
 
182
                }// pos
183
 
184
        } //level
185
 
186
 
187
        // connect }points
188
 
189
        for ( pos = 0; pos <  NE; pos=pos+1 ) { // : }points
190
 
191
                        connect_r2e(2,r2e_cnt_all[pos].r1,r2e_cnt_all[pos].p1,pos);
192
 
193
 
194
        }
195
}
196
 
197 54 alirezamon
*/
198 48 alirezamon
 
199
unsigned int get_mah_distance ( unsigned int id1, unsigned int id2){
200
 
201
        unsigned int k =T1;
202
        unsigned int l =T2;
203
 
204
        unsigned int pow,tmp1,tmp2;
205
        unsigned int distance=0;
206
        pow=1;
207
        for (unsigned int i = 0; i <l; i=i+1 ) {
208
                tmp1=(id1/pow);
209
                tmp2=(id2/pow);
210
                tmp1=tmp1 % k;
211
                tmp2=tmp2 % k;
212
                pow=pow * k;
213
                if(tmp1!=tmp2) distance= (i+1)*2-1; //distance obtained based on the highest level index which differ
214
 
215
        }
216
         return distance;
217
}
218
 
219
 
220
 
221
 
222
#endif
223
 
224
 
225
 

powered by: WebSVN 2.1.0

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