Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verilog bitwise or ("|") monadic

Tags:

verilog

I've seen Verilog code where the bitwise or operator ("|") is used monadic. What's the purpose?

For example

| address[15:14]==0

or

|address[15:14]? io_din : ramrd

Cann't we omit the "|" in these cases?

like image 434
Zhe Hu Avatar asked Sep 15 '25 07:09

Zhe Hu


2 Answers

In this case it acts as a reduction operator, for example:

|4'b1000 => 1'b1 (OR)
&4'b1000 => 1'b0 (AND)
^4'b1000 => 1'b1 (XOR)

|4'b0000 => 1'b0
&4'b1111 => 1'b1
^4'b1111 => 1'b0

ORing the entire bus to a 1 bit value, or applying an AND/XOR to the entire bus.

This is referred to as a 'unary' operator as it only take a right hand argument. They are covered in Section 11.4.9 of SystemVerilog IEEE1800-2012.

like image 181
Morgan Avatar answered Sep 18 '25 10:09

Morgan


|address[15:14]? io_din : ramrd

is the shortcut for writing

(address[15] | address[14]) ? io_din : ramrd

i.e bitwise ORing of all bits of the bus together to generate a 1bit value. In this case it will evaluate as HIGH if either(or both) bit 15 OR bit 14 is HIGH.

similarly you can write other bitwise operators

&address[15:14]? io_din : ramrd   // ANDing

^address[15:14]? io_din : ramrd   // XORing
like image 40
Jean Avatar answered Sep 18 '25 09:09

Jean