Skip to content

Instantly share code, notes, and snippets.

@mkvenkit
Created December 20, 2020 13:11
Show Gist options
  • Select an option

  • Save mkvenkit/d22d0e7d8e96f6578e25d619f8a03418 to your computer and use it in GitHub Desktop.

Select an option

Save mkvenkit/d22d0e7d8e96f6578e25d619f8a03418 to your computer and use it in GitHub Desktop.
icebling_snippet2.v
// handle state machine
case (curr_state)
sSTART:
begin
// start new frame
curr_state <= sNEW_FRAME;
end
sNEW_FRAME:
begin
// start new frame
if (!cnewframe)
begin
// copy grid
grid_cpy <= grid;
// reset current position
i <= 0;
// change state to compute sum
curr_state <= sCOMPUTE_8NN;
end
end
sUPDATE:
begin
// increment position
i <= i + 1;
// set grid value based on sum
if (grid[i])
begin
if (sum < 2 || sum > 3)
begin
grid[i] <= 0;
end
end
else if (sum == 3)
begin
grid[i] <= 1;
end
// done with frame?
if (i == 63)
begin
// go to new frame
curr_state <= sNEW_FRAME;
end
else
begin
// reset sum
sum <= 0;
// change state to compute
curr_state <= sCOMPUTE_8NN;
end
end
sCOMPUTE_8NN:
begin
// automatic toroidal boundary conditions because of
// index overflow
sum <= grid_cpy[i-N-1] + grid_cpy[i-N] +
grid_cpy[i-N+1] +
grid_cpy[i-1] + grid_cpy[i+1] +
grid_cpy[i+N-1] + grid_cpy[i+N] +
grid_cpy[i+N+1];
// change state to update
curr_state <= sUPDATE;
end
default:
curr_state <= sSTART;
endcase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment