public
Created

Verilog sudoku feedback loop

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
module trigger(clk, rxReady, rxData, txBusy, txStart, txData);
input clk;
input [7:0] rxData;
input rxReady;
input txBusy;
output reg txStart;
output reg[7:0] txData;
 
integer count81; // Number of cells received/sent over serial
reg[8:0] possible[0:8][0:8];
reg[8:0] initialx[0:8][0:8];
 
wire solved[0:8][0:8];
wire[8:0] elim[0:8][0:8];
wire[8:0] cellElim[0:8][0:8];
wire finished;
 
assign cellElim[0][0] = elim[1][0] | elim[2][0] | elim[3][0] | elim[4][0] | elim[5][0] | elim[6][0] | elim[7][0] | elim[8][0] | elim[0][1] | elim[0][2] | elim[0][3] | elim[0][4] | elim[0][5] | elim[0][6] | elim[0][7] | elim[0][8] | elim[1][1] | elim[1][2] | elim[2][1] | elim[2][2];
assign cellElim[0][1] = elim[1][1] | elim[2][1] | elim[3][1] | elim[4][1] | elim[5][1] | elim[6][1] | elim[7][1] | elim[8][1] | elim[0][0] | elim[0][2] | elim[0][3] | elim[0][4] | elim[0][5] | elim[0][6] | elim[0][7] | elim[0][8] | elim[1][0] | elim[1][2] | elim[2][0] | elim[2][2];
assign cellElim[0][2] = elim[1][2] | elim[2][2] | elim[3][2] | elim[4][2] | elim[5][2] | elim[6][2] | elim[7][2] | elim[8][2] | elim[0][0] | elim[0][1] | elim[0][3] | elim[0][4] | elim[0][5] | elim[0][6] | elim[0][7] | elim[0][8] | elim[1][0] | elim[1][1] | elim[2][0] | elim[2][1];
assign cellElim[0][3] = elim[1][3] | elim[2][3] | elim[3][3] | elim[4][3] | elim[5][3] | elim[6][3] | elim[7][3] | elim[8][3] | elim[0][0] | elim[0][1] | elim[0][2] | elim[0][4] | elim[0][5] | elim[0][6] | elim[0][7] | elim[0][8] | elim[1][4] | elim[1][5] | elim[2][4] | elim[2][5];
assign cellElim[0][4] = elim[1][4] | elim[2][4] | elim[3][4] | elim[4][4] | elim[5][4] | elim[6][4] | elim[7][4] | elim[8][4] | elim[0][0] | elim[0][1] | elim[0][2] | elim[0][3] | elim[0][5] | elim[0][6] | elim[0][7] | elim[0][8] | elim[1][3] | elim[1][5] | elim[2][3] | elim[2][5];
assign cellElim[0][5] = elim[1][5] | elim[2][5] | elim[3][5] | elim[4][5] | elim[5][5] | elim[6][5] | elim[7][5] | elim[8][5] | elim[0][0] | elim[0][1] | elim[0][2] | elim[0][3] | elim[0][4] | elim[0][6] | elim[0][7] | elim[0][8] | elim[1][3] | elim[1][4] | elim[2][3] | elim[2][4];
assign cellElim[0][6] = elim[1][6] | elim[2][6] | elim[3][6] | elim[4][6] | elim[5][6] | elim[6][6] | elim[7][6] | elim[8][6] | elim[0][0] | elim[0][1] | elim[0][2] | elim[0][3] | elim[0][4] | elim[0][5] | elim[0][7] | elim[0][8] | elim[1][7] | elim[1][8] | elim[2][7] | elim[2][8];
assign cellElim[0][7] = elim[1][7] | elim[2][7] | elim[3][7] | elim[4][7] | elim[5][7] | elim[6][7] | elim[7][7] | elim[8][7] | elim[0][0] | elim[0][1] | elim[0][2] | elim[0][3] | elim[0][4] | elim[0][5] | elim[0][6] | elim[0][8] | elim[1][6] | elim[1][8] | elim[2][6] | elim[2][8];
assign cellElim[0][8] = elim[1][8] | elim[2][8] | elim[3][8] | elim[4][8] | elim[5][8] | elim[6][8] | elim[7][8] | elim[8][8] | elim[0][0] | elim[0][1] | elim[0][2] | elim[0][3] | elim[0][4] | elim[0][5] | elim[0][6] | elim[0][7] | elim[1][6] | elim[1][7] | elim[2][6] | elim[2][7];
assign cellElim[1][0] = elim[0][0] | elim[2][0] | elim[3][0] | elim[4][0] | elim[5][0] | elim[6][0] | elim[7][0] | elim[8][0] | elim[1][1] | elim[1][2] | elim[1][3] | elim[1][4] | elim[1][5] | elim[1][6] | elim[1][7] | elim[1][8] | elim[0][1] | elim[0][2] | elim[2][1] | elim[2][2];
assign cellElim[1][1] = elim[0][1] | elim[2][1] | elim[3][1] | elim[4][1] | elim[5][1] | elim[6][1] | elim[7][1] | elim[8][1] | elim[1][0] | elim[1][2] | elim[1][3] | elim[1][4] | elim[1][5] | elim[1][6] | elim[1][7] | elim[1][8] | elim[0][0] | elim[0][2] | elim[2][0] | elim[2][2];
assign cellElim[1][2] = elim[0][2] | elim[2][2] | elim[3][2] | elim[4][2] | elim[5][2] | elim[6][2] | elim[7][2] | elim[8][2] | elim[1][0] | elim[1][1] | elim[1][3] | elim[1][4] | elim[1][5] | elim[1][6] | elim[1][7] | elim[1][8] | elim[0][0] | elim[0][1] | elim[2][0] | elim[2][1];
assign cellElim[1][3] = elim[0][3] | elim[2][3] | elim[3][3] | elim[4][3] | elim[5][3] | elim[6][3] | elim[7][3] | elim[8][3] | elim[1][0] | elim[1][1] | elim[1][2] | elim[1][4] | elim[1][5] | elim[1][6] | elim[1][7] | elim[1][8] | elim[0][4] | elim[0][5] | elim[2][4] | elim[2][5];
assign cellElim[1][4] = elim[0][4] | elim[2][4] | elim[3][4] | elim[4][4] | elim[5][4] | elim[6][4] | elim[7][4] | elim[8][4] | elim[1][0] | elim[1][1] | elim[1][2] | elim[1][3] | elim[1][5] | elim[1][6] | elim[1][7] | elim[1][8] | elim[0][3] | elim[0][5] | elim[2][3] | elim[2][5];
assign cellElim[1][5] = elim[0][5] | elim[2][5] | elim[3][5] | elim[4][5] | elim[5][5] | elim[6][5] | elim[7][5] | elim[8][5] | elim[1][0] | elim[1][1] | elim[1][2] | elim[1][3] | elim[1][4] | elim[1][6] | elim[1][7] | elim[1][8] | elim[0][3] | elim[0][4] | elim[2][3] | elim[2][4];
assign cellElim[1][6] = elim[0][6] | elim[2][6] | elim[3][6] | elim[4][6] | elim[5][6] | elim[6][6] | elim[7][6] | elim[8][6] | elim[1][0] | elim[1][1] | elim[1][2] | elim[1][3] | elim[1][4] | elim[1][5] | elim[1][7] | elim[1][8] | elim[0][7] | elim[0][8] | elim[2][7] | elim[2][8];
assign cellElim[1][7] = elim[0][7] | elim[2][7] | elim[3][7] | elim[4][7] | elim[5][7] | elim[6][7] | elim[7][7] | elim[8][7] | elim[1][0] | elim[1][1] | elim[1][2] | elim[1][3] | elim[1][4] | elim[1][5] | elim[1][6] | elim[1][8] | elim[0][6] | elim[0][8] | elim[2][6] | elim[2][8];
assign cellElim[1][8] = elim[0][8] | elim[2][8] | elim[3][8] | elim[4][8] | elim[5][8] | elim[6][8] | elim[7][8] | elim[8][8] | elim[1][0] | elim[1][1] | elim[1][2] | elim[1][3] | elim[1][4] | elim[1][5] | elim[1][6] | elim[1][7] | elim[0][6] | elim[0][7] | elim[2][6] | elim[2][7];
assign cellElim[2][0] = elim[0][0] | elim[1][0] | elim[3][0] | elim[4][0] | elim[5][0] | elim[6][0] | elim[7][0] | elim[8][0] | elim[2][1] | elim[2][2] | elim[2][3] | elim[2][4] | elim[2][5] | elim[2][6] | elim[2][7] | elim[2][8] | elim[0][1] | elim[0][2] | elim[1][1] | elim[1][2];
assign cellElim[2][1] = elim[0][1] | elim[1][1] | elim[3][1] | elim[4][1] | elim[5][1] | elim[6][1] | elim[7][1] | elim[8][1] | elim[2][0] | elim[2][2] | elim[2][3] | elim[2][4] | elim[2][5] | elim[2][6] | elim[2][7] | elim[2][8] | elim[0][0] | elim[0][2] | elim[1][0] | elim[1][2];
assign cellElim[2][2] = elim[0][2] | elim[1][2] | elim[3][2] | elim[4][2] | elim[5][2] | elim[6][2] | elim[7][2] | elim[8][2] | elim[2][0] | elim[2][1] | elim[2][3] | elim[2][4] | elim[2][5] | elim[2][6] | elim[2][7] | elim[2][8] | elim[0][0] | elim[0][1] | elim[1][0] | elim[1][1];
assign cellElim[2][3] = elim[0][3] | elim[1][3] | elim[3][3] | elim[4][3] | elim[5][3] | elim[6][3] | elim[7][3] | elim[8][3] | elim[2][0] | elim[2][1] | elim[2][2] | elim[2][4] | elim[2][5] | elim[2][6] | elim[2][7] | elim[2][8] | elim[0][4] | elim[0][5] | elim[1][4] | elim[1][5];
assign cellElim[2][4] = elim[0][4] | elim[1][4] | elim[3][4] | elim[4][4] | elim[5][4] | elim[6][4] | elim[7][4] | elim[8][4] | elim[2][0] | elim[2][1] | elim[2][2] | elim[2][3] | elim[2][5] | elim[2][6] | elim[2][7] | elim[2][8] | elim[0][3] | elim[0][5] | elim[1][3] | elim[1][5];
assign cellElim[2][5] = elim[0][5] | elim[1][5] | elim[3][5] | elim[4][5] | elim[5][5] | elim[6][5] | elim[7][5] | elim[8][5] | elim[2][0] | elim[2][1] | elim[2][2] | elim[2][3] | elim[2][4] | elim[2][6] | elim[2][7] | elim[2][8] | elim[0][3] | elim[0][4] | elim[1][3] | elim[1][4];
assign cellElim[2][6] = elim[0][6] | elim[1][6] | elim[3][6] | elim[4][6] | elim[5][6] | elim[6][6] | elim[7][6] | elim[8][6] | elim[2][0] | elim[2][1] | elim[2][2] | elim[2][3] | elim[2][4] | elim[2][5] | elim[2][7] | elim[2][8] | elim[0][7] | elim[0][8] | elim[1][7] | elim[1][8];
assign cellElim[2][7] = elim[0][7] | elim[1][7] | elim[3][7] | elim[4][7] | elim[5][7] | elim[6][7] | elim[7][7] | elim[8][7] | elim[2][0] | elim[2][1] | elim[2][2] | elim[2][3] | elim[2][4] | elim[2][5] | elim[2][6] | elim[2][8] | elim[0][6] | elim[0][8] | elim[1][6] | elim[1][8];
assign cellElim[2][8] = elim[0][8] | elim[1][8] | elim[3][8] | elim[4][8] | elim[5][8] | elim[6][8] | elim[7][8] | elim[8][8] | elim[2][0] | elim[2][1] | elim[2][2] | elim[2][3] | elim[2][4] | elim[2][5] | elim[2][6] | elim[2][7] | elim[0][6] | elim[0][7] | elim[1][6] | elim[1][7];
assign cellElim[3][0] = elim[0][0] | elim[1][0] | elim[2][0] | elim[4][0] | elim[5][0] | elim[6][0] | elim[7][0] | elim[8][0] | elim[3][1] | elim[3][2] | elim[3][3] | elim[3][4] | elim[3][5] | elim[3][6] | elim[3][7] | elim[3][8] | elim[4][1] | elim[4][2] | elim[5][1] | elim[5][2];
assign cellElim[3][1] = elim[0][1] | elim[1][1] | elim[2][1] | elim[4][1] | elim[5][1] | elim[6][1] | elim[7][1] | elim[8][1] | elim[3][0] | elim[3][2] | elim[3][3] | elim[3][4] | elim[3][5] | elim[3][6] | elim[3][7] | elim[3][8] | elim[4][0] | elim[4][2] | elim[5][0] | elim[5][2];
assign cellElim[3][2] = elim[0][2] | elim[1][2] | elim[2][2] | elim[4][2] | elim[5][2] | elim[6][2] | elim[7][2] | elim[8][2] | elim[3][0] | elim[3][1] | elim[3][3] | elim[3][4] | elim[3][5] | elim[3][6] | elim[3][7] | elim[3][8] | elim[4][0] | elim[4][1] | elim[5][0] | elim[5][1];
assign cellElim[3][3] = elim[0][3] | elim[1][3] | elim[2][3] | elim[4][3] | elim[5][3] | elim[6][3] | elim[7][3] | elim[8][3] | elim[3][0] | elim[3][1] | elim[3][2] | elim[3][4] | elim[3][5] | elim[3][6] | elim[3][7] | elim[3][8] | elim[4][4] | elim[4][5] | elim[5][4] | elim[5][5];
assign cellElim[3][4] = elim[0][4] | elim[1][4] | elim[2][4] | elim[4][4] | elim[5][4] | elim[6][4] | elim[7][4] | elim[8][4] | elim[3][0] | elim[3][1] | elim[3][2] | elim[3][3] | elim[3][5] | elim[3][6] | elim[3][7] | elim[3][8] | elim[4][3] | elim[4][5] | elim[5][3] | elim[5][5];
assign cellElim[3][5] = elim[0][5] | elim[1][5] | elim[2][5] | elim[4][5] | elim[5][5] | elim[6][5] | elim[7][5] | elim[8][5] | elim[3][0] | elim[3][1] | elim[3][2] | elim[3][3] | elim[3][4] | elim[3][6] | elim[3][7] | elim[3][8] | elim[4][3] | elim[4][4] | elim[5][3] | elim[5][4];
assign cellElim[3][6] = elim[0][6] | elim[1][6] | elim[2][6] | elim[4][6] | elim[5][6] | elim[6][6] | elim[7][6] | elim[8][6] | elim[3][0] | elim[3][1] | elim[3][2] | elim[3][3] | elim[3][4] | elim[3][5] | elim[3][7] | elim[3][8] | elim[4][7] | elim[4][8] | elim[5][7] | elim[5][8];
assign cellElim[3][7] = elim[0][7] | elim[1][7] | elim[2][7] | elim[4][7] | elim[5][7] | elim[6][7] | elim[7][7] | elim[8][7] | elim[3][0] | elim[3][1] | elim[3][2] | elim[3][3] | elim[3][4] | elim[3][5] | elim[3][6] | elim[3][8] | elim[4][6] | elim[4][8] | elim[5][6] | elim[5][8];
assign cellElim[3][8] = elim[0][8] | elim[1][8] | elim[2][8] | elim[4][8] | elim[5][8] | elim[6][8] | elim[7][8] | elim[8][8] | elim[3][0] | elim[3][1] | elim[3][2] | elim[3][3] | elim[3][4] | elim[3][5] | elim[3][6] | elim[3][7] | elim[4][6] | elim[4][7] | elim[5][6] | elim[5][7];
assign cellElim[4][0] = elim[0][0] | elim[1][0] | elim[2][0] | elim[3][0] | elim[5][0] | elim[6][0] | elim[7][0] | elim[8][0] | elim[4][1] | elim[4][2] | elim[4][3] | elim[4][4] | elim[4][5] | elim[4][6] | elim[4][7] | elim[4][8] | elim[3][1] | elim[3][2] | elim[5][1] | elim[5][2];
assign cellElim[4][1] = elim[0][1] | elim[1][1] | elim[2][1] | elim[3][1] | elim[5][1] | elim[6][1] | elim[7][1] | elim[8][1] | elim[4][0] | elim[4][2] | elim[4][3] | elim[4][4] | elim[4][5] | elim[4][6] | elim[4][7] | elim[4][8] | elim[3][0] | elim[3][2] | elim[5][0] | elim[5][2];
assign cellElim[4][2] = elim[0][2] | elim[1][2] | elim[2][2] | elim[3][2] | elim[5][2] | elim[6][2] | elim[7][2] | elim[8][2] | elim[4][0] | elim[4][1] | elim[4][3] | elim[4][4] | elim[4][5] | elim[4][6] | elim[4][7] | elim[4][8] | elim[3][0] | elim[3][1] | elim[5][0] | elim[5][1];
assign cellElim[4][3] = elim[0][3] | elim[1][3] | elim[2][3] | elim[3][3] | elim[5][3] | elim[6][3] | elim[7][3] | elim[8][3] | elim[4][0] | elim[4][1] | elim[4][2] | elim[4][4] | elim[4][5] | elim[4][6] | elim[4][7] | elim[4][8] | elim[3][4] | elim[3][5] | elim[5][4] | elim[5][5];
assign cellElim[4][4] = elim[0][4] | elim[1][4] | elim[2][4] | elim[3][4] | elim[5][4] | elim[6][4] | elim[7][4] | elim[8][4] | elim[4][0] | elim[4][1] | elim[4][2] | elim[4][3] | elim[4][5] | elim[4][6] | elim[4][7] | elim[4][8] | elim[3][3] | elim[3][5] | elim[5][3] | elim[5][5];
assign cellElim[4][5] = elim[0][5] | elim[1][5] | elim[2][5] | elim[3][5] | elim[5][5] | elim[6][5] | elim[7][5] | elim[8][5] | elim[4][0] | elim[4][1] | elim[4][2] | elim[4][3] | elim[4][4] | elim[4][6] | elim[4][7] | elim[4][8] | elim[3][3] | elim[3][4] | elim[5][3] | elim[5][4];
assign cellElim[4][6] = elim[0][6] | elim[1][6] | elim[2][6] | elim[3][6] | elim[5][6] | elim[6][6] | elim[7][6] | elim[8][6] | elim[4][0] | elim[4][1] | elim[4][2] | elim[4][3] | elim[4][4] | elim[4][5] | elim[4][7] | elim[4][8] | elim[3][7] | elim[3][8] | elim[5][7] | elim[5][8];
assign cellElim[4][7] = elim[0][7] | elim[1][7] | elim[2][7] | elim[3][7] | elim[5][7] | elim[6][7] | elim[7][7] | elim[8][7] | elim[4][0] | elim[4][1] | elim[4][2] | elim[4][3] | elim[4][4] | elim[4][5] | elim[4][6] | elim[4][8] | elim[3][6] | elim[3][8] | elim[5][6] | elim[5][8];
assign cellElim[4][8] = elim[0][8] | elim[1][8] | elim[2][8] | elim[3][8] | elim[5][8] | elim[6][8] | elim[7][8] | elim[8][8] | elim[4][0] | elim[4][1] | elim[4][2] | elim[4][3] | elim[4][4] | elim[4][5] | elim[4][6] | elim[4][7] | elim[3][6] | elim[3][7] | elim[5][6] | elim[5][7];
assign cellElim[5][0] = elim[0][0] | elim[1][0] | elim[2][0] | elim[3][0] | elim[4][0] | elim[6][0] | elim[7][0] | elim[8][0] | elim[5][1] | elim[5][2] | elim[5][3] | elim[5][4] | elim[5][5] | elim[5][6] | elim[5][7] | elim[5][8] | elim[3][1] | elim[3][2] | elim[4][1] | elim[4][2];
assign cellElim[5][1] = elim[0][1] | elim[1][1] | elim[2][1] | elim[3][1] | elim[4][1] | elim[6][1] | elim[7][1] | elim[8][1] | elim[5][0] | elim[5][2] | elim[5][3] | elim[5][4] | elim[5][5] | elim[5][6] | elim[5][7] | elim[5][8] | elim[3][0] | elim[3][2] | elim[4][0] | elim[4][2];
assign cellElim[5][2] = elim[0][2] | elim[1][2] | elim[2][2] | elim[3][2] | elim[4][2] | elim[6][2] | elim[7][2] | elim[8][2] | elim[5][0] | elim[5][1] | elim[5][3] | elim[5][4] | elim[5][5] | elim[5][6] | elim[5][7] | elim[5][8] | elim[3][0] | elim[3][1] | elim[4][0] | elim[4][1];
assign cellElim[5][3] = elim[0][3] | elim[1][3] | elim[2][3] | elim[3][3] | elim[4][3] | elim[6][3] | elim[7][3] | elim[8][3] | elim[5][0] | elim[5][1] | elim[5][2] | elim[5][4] | elim[5][5] | elim[5][6] | elim[5][7] | elim[5][8] | elim[3][4] | elim[3][5] | elim[4][4] | elim[4][5];
assign cellElim[5][4] = elim[0][4] | elim[1][4] | elim[2][4] | elim[3][4] | elim[4][4] | elim[6][4] | elim[7][4] | elim[8][4] | elim[5][0] | elim[5][1] | elim[5][2] | elim[5][3] | elim[5][5] | elim[5][6] | elim[5][7] | elim[5][8] | elim[3][3] | elim[3][5] | elim[4][3] | elim[4][5];
assign cellElim[5][5] = elim[0][5] | elim[1][5] | elim[2][5] | elim[3][5] | elim[4][5] | elim[6][5] | elim[7][5] | elim[8][5] | elim[5][0] | elim[5][1] | elim[5][2] | elim[5][3] | elim[5][4] | elim[5][6] | elim[5][7] | elim[5][8] | elim[3][3] | elim[3][4] | elim[4][3] | elim[4][4];
assign cellElim[5][6] = elim[0][6] | elim[1][6] | elim[2][6] | elim[3][6] | elim[4][6] | elim[6][6] | elim[7][6] | elim[8][6] | elim[5][0] | elim[5][1] | elim[5][2] | elim[5][3] | elim[5][4] | elim[5][5] | elim[5][7] | elim[5][8] | elim[3][7] | elim[3][8] | elim[4][7] | elim[4][8];
assign cellElim[5][7] = elim[0][7] | elim[1][7] | elim[2][7] | elim[3][7] | elim[4][7] | elim[6][7] | elim[7][7] | elim[8][7] | elim[5][0] | elim[5][1] | elim[5][2] | elim[5][3] | elim[5][4] | elim[5][5] | elim[5][6] | elim[5][8] | elim[3][6] | elim[3][8] | elim[4][6] | elim[4][8];
assign cellElim[5][8] = elim[0][8] | elim[1][8] | elim[2][8] | elim[3][8] | elim[4][8] | elim[6][8] | elim[7][8] | elim[8][8] | elim[5][0] | elim[5][1] | elim[5][2] | elim[5][3] | elim[5][4] | elim[5][5] | elim[5][6] | elim[5][7] | elim[3][6] | elim[3][7] | elim[4][6] | elim[4][7];
assign cellElim[6][0] = elim[0][0] | elim[1][0] | elim[2][0] | elim[3][0] | elim[4][0] | elim[5][0] | elim[7][0] | elim[8][0] | elim[6][1] | elim[6][2] | elim[6][3] | elim[6][4] | elim[6][5] | elim[6][6] | elim[6][7] | elim[6][8] | elim[7][1] | elim[7][2] | elim[8][1] | elim[8][2];
assign cellElim[6][1] = elim[0][1] | elim[1][1] | elim[2][1] | elim[3][1] | elim[4][1] | elim[5][1] | elim[7][1] | elim[8][1] | elim[6][0] | elim[6][2] | elim[6][3] | elim[6][4] | elim[6][5] | elim[6][6] | elim[6][7] | elim[6][8] | elim[7][0] | elim[7][2] | elim[8][0] | elim[8][2];
assign cellElim[6][2] = elim[0][2] | elim[1][2] | elim[2][2] | elim[3][2] | elim[4][2] | elim[5][2] | elim[7][2] | elim[8][2] | elim[6][0] | elim[6][1] | elim[6][3] | elim[6][4] | elim[6][5] | elim[6][6] | elim[6][7] | elim[6][8] | elim[7][0] | elim[7][1] | elim[8][0] | elim[8][1];
assign cellElim[6][3] = elim[0][3] | elim[1][3] | elim[2][3] | elim[3][3] | elim[4][3] | elim[5][3] | elim[7][3] | elim[8][3] | elim[6][0] | elim[6][1] | elim[6][2] | elim[6][4] | elim[6][5] | elim[6][6] | elim[6][7] | elim[6][8] | elim[7][4] | elim[7][5] | elim[8][4] | elim[8][5];
assign cellElim[6][4] = elim[0][4] | elim[1][4] | elim[2][4] | elim[3][4] | elim[4][4] | elim[5][4] | elim[7][4] | elim[8][4] | elim[6][0] | elim[6][1] | elim[6][2] | elim[6][3] | elim[6][5] | elim[6][6] | elim[6][7] | elim[6][8] | elim[7][3] | elim[7][5] | elim[8][3] | elim[8][5];
assign cellElim[6][5] = elim[0][5] | elim[1][5] | elim[2][5] | elim[3][5] | elim[4][5] | elim[5][5] | elim[7][5] | elim[8][5] | elim[6][0] | elim[6][1] | elim[6][2] | elim[6][3] | elim[6][4] | elim[6][6] | elim[6][7] | elim[6][8] | elim[7][3] | elim[7][4] | elim[8][3] | elim[8][4];
assign cellElim[6][6] = elim[0][6] | elim[1][6] | elim[2][6] | elim[3][6] | elim[4][6] | elim[5][6] | elim[7][6] | elim[8][6] | elim[6][0] | elim[6][1] | elim[6][2] | elim[6][3] | elim[6][4] | elim[6][5] | elim[6][7] | elim[6][8] | elim[7][7] | elim[7][8] | elim[8][7] | elim[8][8];
assign cellElim[6][7] = elim[0][7] | elim[1][7] | elim[2][7] | elim[3][7] | elim[4][7] | elim[5][7] | elim[7][7] | elim[8][7] | elim[6][0] | elim[6][1] | elim[6][2] | elim[6][3] | elim[6][4] | elim[6][5] | elim[6][6] | elim[6][8] | elim[7][6] | elim[7][8] | elim[8][6] | elim[8][8];
assign cellElim[6][8] = elim[0][8] | elim[1][8] | elim[2][8] | elim[3][8] | elim[4][8] | elim[5][8] | elim[7][8] | elim[8][8] | elim[6][0] | elim[6][1] | elim[6][2] | elim[6][3] | elim[6][4] | elim[6][5] | elim[6][6] | elim[6][7] | elim[7][6] | elim[7][7] | elim[8][6] | elim[8][7];
assign cellElim[7][0] = elim[0][0] | elim[1][0] | elim[2][0] | elim[3][0] | elim[4][0] | elim[5][0] | elim[6][0] | elim[8][0] | elim[7][1] | elim[7][2] | elim[7][3] | elim[7][4] | elim[7][5] | elim[7][6] | elim[7][7] | elim[7][8] | elim[6][1] | elim[6][2] | elim[8][1] | elim[8][2];
assign cellElim[7][1] = elim[0][1] | elim[1][1] | elim[2][1] | elim[3][1] | elim[4][1] | elim[5][1] | elim[6][1] | elim[8][1] | elim[7][0] | elim[7][2] | elim[7][3] | elim[7][4] | elim[7][5] | elim[7][6] | elim[7][7] | elim[7][8] | elim[6][0] | elim[6][2] | elim[8][0] | elim[8][2];
assign cellElim[7][2] = elim[0][2] | elim[1][2] | elim[2][2] | elim[3][2] | elim[4][2] | elim[5][2] | elim[6][2] | elim[8][2] | elim[7][0] | elim[7][1] | elim[7][3] | elim[7][4] | elim[7][5] | elim[7][6] | elim[7][7] | elim[7][8] | elim[6][0] | elim[6][1] | elim[8][0] | elim[8][1];
assign cellElim[7][3] = elim[0][3] | elim[1][3] | elim[2][3] | elim[3][3] | elim[4][3] | elim[5][3] | elim[6][3] | elim[8][3] | elim[7][0] | elim[7][1] | elim[7][2] | elim[7][4] | elim[7][5] | elim[7][6] | elim[7][7] | elim[7][8] | elim[6][4] | elim[6][5] | elim[8][4] | elim[8][5];
assign cellElim[7][4] = elim[0][4] | elim[1][4] | elim[2][4] | elim[3][4] | elim[4][4] | elim[5][4] | elim[6][4] | elim[8][4] | elim[7][0] | elim[7][1] | elim[7][2] | elim[7][3] | elim[7][5] | elim[7][6] | elim[7][7] | elim[7][8] | elim[6][3] | elim[6][5] | elim[8][3] | elim[8][5];
assign cellElim[7][5] = elim[0][5] | elim[1][5] | elim[2][5] | elim[3][5] | elim[4][5] | elim[5][5] | elim[6][5] | elim[8][5] | elim[7][0] | elim[7][1] | elim[7][2] | elim[7][3] | elim[7][4] | elim[7][6] | elim[7][7] | elim[7][8] | elim[6][3] | elim[6][4] | elim[8][3] | elim[8][4];
assign cellElim[7][6] = elim[0][6] | elim[1][6] | elim[2][6] | elim[3][6] | elim[4][6] | elim[5][6] | elim[6][6] | elim[8][6] | elim[7][0] | elim[7][1] | elim[7][2] | elim[7][3] | elim[7][4] | elim[7][5] | elim[7][7] | elim[7][8] | elim[6][7] | elim[6][8] | elim[8][7] | elim[8][8];
assign cellElim[7][7] = elim[0][7] | elim[1][7] | elim[2][7] | elim[3][7] | elim[4][7] | elim[5][7] | elim[6][7] | elim[8][7] | elim[7][0] | elim[7][1] | elim[7][2] | elim[7][3] | elim[7][4] | elim[7][5] | elim[7][6] | elim[7][8] | elim[6][6] | elim[6][8] | elim[8][6] | elim[8][8];
assign cellElim[7][8] = elim[0][8] | elim[1][8] | elim[2][8] | elim[3][8] | elim[4][8] | elim[5][8] | elim[6][8] | elim[8][8] | elim[7][0] | elim[7][1] | elim[7][2] | elim[7][3] | elim[7][4] | elim[7][5] | elim[7][6] | elim[7][7] | elim[6][6] | elim[6][7] | elim[8][6] | elim[8][7];
assign cellElim[8][0] = elim[0][0] | elim[1][0] | elim[2][0] | elim[3][0] | elim[4][0] | elim[5][0] | elim[6][0] | elim[7][0] | elim[8][1] | elim[8][2] | elim[8][3] | elim[8][4] | elim[8][5] | elim[8][6] | elim[8][7] | elim[8][8] | elim[6][1] | elim[6][2] | elim[7][1] | elim[7][2];
assign cellElim[8][1] = elim[0][1] | elim[1][1] | elim[2][1] | elim[3][1] | elim[4][1] | elim[5][1] | elim[6][1] | elim[7][1] | elim[8][0] | elim[8][2] | elim[8][3] | elim[8][4] | elim[8][5] | elim[8][6] | elim[8][7] | elim[8][8] | elim[6][0] | elim[6][2] | elim[7][0] | elim[7][2];
assign cellElim[8][2] = elim[0][2] | elim[1][2] | elim[2][2] | elim[3][2] | elim[4][2] | elim[5][2] | elim[6][2] | elim[7][2] | elim[8][0] | elim[8][1] | elim[8][3] | elim[8][4] | elim[8][5] | elim[8][6] | elim[8][7] | elim[8][8] | elim[6][0] | elim[6][1] | elim[7][0] | elim[7][1];
assign cellElim[8][3] = elim[0][3] | elim[1][3] | elim[2][3] | elim[3][3] | elim[4][3] | elim[5][3] | elim[6][3] | elim[7][3] | elim[8][0] | elim[8][1] | elim[8][2] | elim[8][4] | elim[8][5] | elim[8][6] | elim[8][7] | elim[8][8] | elim[6][4] | elim[6][5] | elim[7][4] | elim[7][5];
assign cellElim[8][4] = elim[0][4] | elim[1][4] | elim[2][4] | elim[3][4] | elim[4][4] | elim[5][4] | elim[6][4] | elim[7][4] | elim[8][0] | elim[8][1] | elim[8][2] | elim[8][3] | elim[8][5] | elim[8][6] | elim[8][7] | elim[8][8] | elim[6][3] | elim[6][5] | elim[7][3] | elim[7][5];
assign cellElim[8][5] = elim[0][5] | elim[1][5] | elim[2][5] | elim[3][5] | elim[4][5] | elim[5][5] | elim[6][5] | elim[7][5] | elim[8][0] | elim[8][1] | elim[8][2] | elim[8][3] | elim[8][4] | elim[8][6] | elim[8][7] | elim[8][8] | elim[6][3] | elim[6][4] | elim[7][3] | elim[7][4];
assign cellElim[8][6] = elim[0][6] | elim[1][6] | elim[2][6] | elim[3][6] | elim[4][6] | elim[5][6] | elim[6][6] | elim[7][6] | elim[8][0] | elim[8][1] | elim[8][2] | elim[8][3] | elim[8][4] | elim[8][5] | elim[8][7] | elim[8][8] | elim[6][7] | elim[6][8] | elim[7][7] | elim[7][8];
assign cellElim[8][7] = elim[0][7] | elim[1][7] | elim[2][7] | elim[3][7] | elim[4][7] | elim[5][7] | elim[6][7] | elim[7][7] | elim[8][0] | elim[8][1] | elim[8][2] | elim[8][3] | elim[8][4] | elim[8][5] | elim[8][6] | elim[8][8] | elim[6][6] | elim[6][8] | elim[7][6] | elim[7][8];
assign cellElim[8][8] = elim[0][8] | elim[1][8] | elim[2][8] | elim[3][8] | elim[4][8] | elim[5][8] | elim[6][8] | elim[7][8] | elim[8][0] | elim[8][1] | elim[8][2] | elim[8][3] | elim[8][4] | elim[8][5] | elim[8][6] | elim[8][7] | elim[6][6] | elim[6][7] | elim[7][6] | elim[7][7];
 
 
assign finished = solved[0][0]&solved[0][1]&solved[0][2]&solved[0][3]&solved[0][4]&solved[0][5]&solved[0][6]&solved[0][7]&solved[0][8]&
solved[1][0]&solved[1][1]&solved[1][2]&solved[1][3]&solved[1][4]&solved[1][5]&solved[1][6]&solved[1][7]&solved[1][8]&
solved[2][0]&solved[2][1]&solved[2][2]&solved[2][3]&solved[2][4]&solved[2][5]&solved[2][6]&solved[2][7]&solved[2][8]&
solved[3][0]&solved[3][1]&solved[3][2]&solved[3][3]&solved[3][4]&solved[3][5]&solved[3][6]&solved[3][7]&solved[3][8]&
solved[4][0]&solved[4][1]&solved[4][2]&solved[4][3]&solved[4][4]&solved[4][5]&solved[4][6]&solved[4][7]&solved[4][8]&
solved[5][0]&solved[5][1]&solved[5][2]&solved[5][3]&solved[5][4]&solved[5][5]&solved[5][6]&solved[5][7]&solved[5][8]&
solved[6][0]&solved[6][1]&solved[6][2]&solved[6][3]&solved[6][4]&solved[6][5]&solved[6][6]&solved[6][7]&solved[6][8]&
solved[7][0]&solved[7][1]&solved[7][2]&solved[7][3]&solved[7][4]&solved[7][5]&solved[7][6]&solved[7][7]&solved[7][8]&
solved[8][0]&solved[8][1]&solved[8][2]&solved[8][3]&solved[8][4]&solved[8][5]&solved[8][6]&solved[8][7]&solved[8][8];
 
parameter read=0, solving=1, write1=2, write2=3, solving2=4;
integer state;
 
genvar z, y, x;
generate
wire[8:-1] overflow[0:8][0:8];
wire[8:-1] atLeast1[0:8][0:8];
for (x=0; x<9; x=x+1) begin :b1
for (y=0; y<9; y=y+1) begin :b2
assign atLeast1[x][y][-1] = 0;
assign overflow[x][y][-1] = 0;
for (z=0; z<9; z=z+1) begin :b3
assign atLeast1[x][y][z] = atLeast1[x][y][z-1] | possible[x][y][z];
assign overflow[x][y][z] = overflow[x][y][z-1] | atLeast1[x][y][z-1] & possible[x][y][z];
end
assign solved[x][y] = atLeast1[x][y][8] & !overflow[x][y][8];
for (z=0; z<9; z=z+1) begin :b4
assign elim[x][y][z] = solved[x][y] & possible[x][y][z];
end
end
for (y=0; y<9; y=y+1) begin :b6
for (z=0; z<9; z=z+1) begin :b7
always @(*) begin :b8
possible[x][y][z] = state==read ? 1 : initialx[x][y][z] & possible[x][y][z] & !(cellElim[x][y][z]);
end
end
end
end
endgenerate
 
initial begin
integer x, y, z;
txStart <= 0;
state <= read;
end
 
always @(posedge clk) begin
case (state)
read: begin
if (rxReady) begin
initialx[count81 % 9][count81 / 9] = rxData ? 1<<(rxData-1) : -1;
if (count81 < 80) count81 <= count81 + 1;
else begin
count81 <= 0;
state <= solving;
end
end
end
solving: begin
state <= write1;
end
write1:
if (!txBusy && !txStart) begin
integer hiBits, highestBit, z;
hiBits = 0;
highestBit = 0;
for (z=0; z<9; z=z+1) begin
if (possible[count81 % 9][count81 / 9][z]) begin
hiBits = hiBits + 1;
highestBit = z + 1;
end
end
txData <= (hiBits << 4) | highestBit;
txStart <= 1;
state <= write2;
end
write2: begin
txStart <= 0;
if (count81 != 80) begin
count81 <= count81 + 1;
state <= write1;
end else begin
count81 <= 0;
state <= read;
end end
endcase
end
endmodule

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.