// case 1
// w_buf_x : registered value
localparam
threshold = 3'd2;
reg [7:0] w_buf_0 [2:0];
reg [7:0] w_buf_1 [2:0];
reg [7:0] w_buf_2 [2:0];
wire signed [8:0] s_0, s_1, s_2, s_3;
assign s_0 = (w_buf_1[0] - w_buf_1[2] - threshold);
assign s_1 = (w_buf_2[0] - w_buf_0[2] - threshold);
assign s_2 = (w_buf_2[1] - w_buf_0[1] - threshold);
assign s_3 = (w_buf_2[2] - w_buf_0[0] - threshold);
assign r_0 = (s_0 > 0) ? 1'b1 : 0;
assign r_1 = (s_1 > 0) ? 2'd2 : 0;
assign r_2 = (s_2 > 0) ? 3'd4 : 0;
assign r_3 = (s_3 > 0) ? 4'd8 : 0;
//case 2
assign s_0 = (w_buf_1[0] - w_buf_1[2]);
assign s_1 = (w_buf_2[0] - w_buf_0[2]);
assign s_2 = (w_buf_2[1] - w_buf_0[1]);
assign s_3 = (w_buf_2[2] - w_buf_0[0]);
assign r_0 = (s_0 > threshold) ? 1'b1 : 0;
assign r_1 = (s_1 > threshold) ? 2'd2 : 0;
assign r_2 = (s_2 > threshold) ? 3'd4 : 0;
assign r_3 = (s_3 > threshold) ? 4'd8 : 0;
assign result = r_0 + r_1 + r_2 + r_3;