Skip to content

Instantly share code, notes, and snippets.

View ProgrammableGatorade's full-sized avatar

ProgrammableGatorade

View GitHub Profile
@ProgrammableGatorade
ProgrammableGatorade / GraphRadius_GenerateNodes.v
Created December 29, 2013 13:03
Snippet from GraphRadius.v that instantiates the network of nodes.
genvar n;
generate
for (n=0; n<NumNodes; n=n+1)
begin: GEN_NODES
Node #(
.NodeID ( n ),
.NumNodes ( NumNodes ),
.L2NumNodes ( L2NumNodes ),
.DistVecWidth ( DistVecWidth ),
.DistMatrixPkdWidth ( DistMatrixPkdWidth )
@ProgrammableGatorade
ProgrammableGatorade / Node_ReportDistVec.v
Created December 29, 2013 12:56
Snippet from Node.v that reports our current distance vector.
always@(*)
begin : REPORT_DIST_VECTOR
integer r,c;
dist_vec_o = {DistVecWidth{1'b1}};
for (c=0; c<NumNodes; c=c+1) begin
for (r=0; r<NumNodes; r=r+1) begin
if (dist_matrix_lcl[r][`NODE_SEL(c)] < dist_vec_o[`NODE_SEL(c)]) begin
dist_vec_o[`NODE_SEL(c)] = dist_matrix_lcl[r][`NODE_SEL(c)];
end
end
@ProgrammableGatorade
ProgrammableGatorade / Node_Header.v
Created December 29, 2013 12:52
Module header for Node.v
// macro to select a node's distance in a packed distance vector
`define NODE_SEL(node_num) (node_num)*L2NumNodes +: L2NumNodes
module Node #(
parameter NodeID = 0, // identifier for this node
parameter NumNodes = 10, // total number of nodes in graph
parameter L2NumNodes = Log2(NumNodes), // number of bits we need to store a node id
parameter DistVecWidth = NumNodes * L2NumNodes, // number of bits we need to store a dist vec
parameter DistMatrixPkdWidth = NumNodes * DistVecWidth // number of bits we need to store a dist matrix
)(
@ProgrammableGatorade
ProgrammableGatorade / Node_MatrixUpdateSnipper.v
Last active January 1, 2016 15:49
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
module GraphRadius #(
parameter NumNodes = 10,
parameter L2NumNodes = Log2(NumNodes),
parameter DistVecWidth = NumNodes * L2NumNodes,
parameter DistMatrixPkdWidth = NumNodes * DistVecWidth,
parameter CHARS_PER_LINE = 16,
parameter CYCLES_PER_IDLE = 375000,
parameter CYCLES_PER_CMD = 25000,
parameter CYCLE_ENA_ASSERT = 25,
parameter CYCLE_ENA_DEASSERT = 50