求助,下面的verilog代码起了什么作用。看的时候没有明白

2019-07-15 21:50发布

// leading one detector
module c_lod
  (data_in, data_out);

`include "D:/trunk/src/c_functions.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

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。