module bnn_dense8(
    input  [15:0] x_in,
    output reg [7:0] y_out
);
    localparam [15:0] W0 = 16'hB3A6;
    localparam [15:0] W1 = 16'h5CD9;
    localparam [15:0] W2 = 16'hE3C5;
    localparam [15:0] W3 = 16'h35B6;
    localparam [15:0] W4 = 16'hCA79;
    localparam [15:0] W5 = 16'h6E1E;
    localparam [15:0] W6 = 16'h95E3;
    localparam [15:0] W7 = 16'hF42D;

    function integer score_for;
        input [15:0] x_vec;
        input [15:0] w_vec;
        integer bit_idx;
        integer sum;
        begin
            sum = 0;
            for (bit_idx = 0; bit_idx < 16; bit_idx = bit_idx + 1) begin
                if (x_vec[bit_idx] == w_vec[bit_idx])
                    sum = sum + 1;
                else
                    sum = sum - 1;
            end
            score_for = sum;
        end
    endfunction

    always @* begin
        y_out[0] = (score_for(x_in, W0) >= 2);
        y_out[1] = (score_for(x_in, W1) >= 0);
        y_out[2] = (score_for(x_in, W2) >= -4);
        y_out[3] = (score_for(x_in, W3) >= 6);
        y_out[4] = (score_for(x_in, W4) >= -2);
        y_out[5] = (score_for(x_in, W5) >= 4);
        y_out[6] = (score_for(x_in, W6) >= 8);
        y_out[7] = (score_for(x_in, W7) >= 0);
    end
endmodule
