module filt_longv(clk, d, q);
parameter N = 10;
input clk, d;
output q;
function integer log2;
input integer ni;
begin
log2 = 0;
while (ni > 0)
begin
log2 = log2 + 1;
ni = (ni >> 1);
end
end
endfunction
localparam cnt_size = log2(N-2);
reg [1:0] samples;
reg [cnt_size-1:0] counter;
reg q;
always @(posedge clk)
begin
samples <= {samples[0], d};
if (^ samples) counter <= N-2;
else
if (counter > 0) counter <= counter - 1'b1;
else
q <= samples[1];
end
endmodule