// leading one detector
module c_lod
(data_in, data_out);
`include "D:/trunk/src/c_func
tions.v"
// number of input ports
parameter width = 32;
// number of stages
localparam depth = clogb(width);
// vector of requests
input [0:width-1] data_in;
// vector of grants
output [0:width-1] data_out;
wire [0:width-1] data_out;
genvar level;
wire [0:(depth+1)*width-1] a_int;
wire [0:(depth+1)*width-1] b_int;
assign a_int[0:width-1] = data_in;
assign b_int[0:width-1] = data_in;
generate
for(level = 0; level < depth; level = level + 1)
begin:levels
wire [0:width-1] a_in;
assign a_in = a_int[level*width:(level+1)*width-1];
wire [0:width-1] b_in;
assign b_in = b_int[level*width:(level+1)*width-1];
wire [0:width-1] a_shifted;
assign a_shifted = {{(1<<level){1'b0}}, a_in[0:width-(1<<level)-1]};
wire [0:width-1] a_out;
assign a_out = a_in | a_shifted;
wire [0:width-1] b_out;
assign b_out = b_in & ~a_shifted;
assign a_int[(level+1)*width:(level+2)*width-1] = a_out;
assign b_int[(level+1)*width:(level+2)*width-1] = b_out;
end
endgenerate
assign data_out = b_int[depth*width:(depth+1)*width-1];
endmodule
一周热门 更多>