15

Say I'm given a vector wire large_bus[63:0] of width 64. How can I XOR the individual signals together without writing them all out:

assign XOR_value = large_bus[0] ^ large_bus[1] ^ ... ^ large_bus[63] ?

I'm especially interested in doing this for vectors where the width is specified by a localparam.

Randomblue
  • 10,953
  • 29
  • 105
  • 178

1 Answers1

21

Binary operators like &, |, ^ and some others can also be unary in verilog, which is quite convenient. They perform bitwise operations on the operand and return a single bit value. See e.g. reduction operators on asic-world.com.

reg [63:0] large_bus;

wire xor_value;
assign xor_value = ^large_bus;
Thorn
  • 2,130
  • 14
  • 15