2
\$\begingroup\$

How to assign a wire with a AND operation of a wire array?

    parameter row = 4;
    parameter col = 8;
    wire ready [row-1:0][col-1:0];
    output wire allready;

logically i want to do

allready=AND ready[i][j] for all i,j

\$\endgroup\$
2
\$\begingroup\$

For a mutlibit wire the reduction operator & can be used:

wire [row-1:0] ready;
wire allready = &ready;

However this will not work with unpacked arrays (multi-dimensions).

One solution is to create a loop to index the dimensions ANDing the values with the result so far. This could be achieved with some thing along the lines of:

output reg allready; 

always @* begin
  allready=1'b1;
  for (int i =0; i<col; i++) begin
    allready = allready & (&ready[i]) ;
  end 
end
\$\endgroup\$
  • \$\begingroup\$ is the for loop time consuming? or is it the same as ANDing all the wires and assignning the result in a new wire? \$\endgroup\$ – Ofek Ron Aug 5 '14 at 6:48
  • \$\begingroup\$ Each loop will take some time for the simulator, but it is unrolled in hardware, ie it is all in parallel. Loops can not consume time other wise they are not synthesizable. \$\endgroup\$ – pre_randomize Aug 5 '14 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.