Skip to content

Instantly share code, notes, and snippets.

@ProgrammableGatorade
Last active January 1, 2016 15:49
Show Gist options
  • Save ProgrammableGatorade/8166933 to your computer and use it in GitHub Desktop.
Save ProgrammableGatorade/8166933 to your computer and use it in GitHub Desktop.
Code snippet from Node.v that constructs a node's distance matrix.
for (r=0; r<NumNodes; r=r+1) begin
for (c=0; c<NumNodes; c=c+1) begin
if (r == NodeID) begin
// this is our row in the distance matrix.
// we use the adjacency vector to update the matrix.
if (c == NodeID) begin
// the distance from a node to itself is 0
dist_matrix_lcl[r][`NODE_SEL(c)] <= 0;
end else if (adj_vec[c]) begin
// the distance from a node to its neighbor is 1
dist_matrix_lcl[r][`NODE_SEL(c)] <= 1;
end else begin
// we assume that there is no path to nodes other
// than ourselves and our immediate neighbors;
// the distance is infinite,
// but this is hardware so -1 will have to do.
dist_matrix_lcl[r][`NODE_SEL(c)] <= -1;
end
end else if (adj_vec[r]) begin
// this row belong to one of our neighbors
// we use their distance vector information
// to update our distance matrix.
if (dist_matrix_rmt[r][`NODE_SEL(c)] == -1) begin
// our neighrbor doesn't have a path to node c, so we assume that we don't either
dist_matrix_lcl[r][`NODE_SEL(c)] <= -1;
end else begin
// our neighbor says it has a path to node c.
// since our neighbor is 1 hop away we add one to whatever distance they report for node c
dist_matrix_lcl[r][`NODE_SEL(c)] <= dist_matrix_rmt[r][`NODE_SEL(c)] + 1;
end
end else begin
// this row doesn't belong to us or one of our immediate neighbors
// we keep this row blank (filled with infinite distances)
dist_matrix_lcl[r] <= {DistVecWidth{1'b1}};
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment