Chisel uses the boolean algebra operators and arithmetic operators same as in c, java, scala, etc programming languages.
val sel = a & b
The keyword val is part of scala which is used to name the variables that have values that won’t change. And here it is used to name the chisel wire, sel, holding the output of the bitwise and operation. A signal can also first be defined as a Wire of some type. Afterward, we can assign a value to the wire with the ‘:=’ update operator.
val sel = Wire(UInt()))
sel := a & b
Boolean operators
& —– represents bitwise AND operator
val and = a & b
| —– represents bitwise OR operator
val or = a | b
^ —– represents bitwise XOR operator
val xor = a ^ b
~ —– represents bitwise negation
val not = ~a
Arithmetic operations
+ —– Addition operation
val add = a + b
– —– Subtraction operation
val sub = a – b
* —– multiplication operation
val mul = a * b
/ —– division operation
val div = a / b
% —– modulo operation
val mod = a % b
Operator | Description | Data Types |
* / % | Multiplication, division, modulus | UInt, SInt |
+ – | Addition, subtraction | UInt, SInt |
=== =/= | Equal, not equal | UInt, SInt, returns Bool |
> >= <= | Comparison operations | UInt, SInt, returns Bool |
<< >> | Shift left, shift right | UInt, SInt |
~ | NOT | UInt, SInt, Bool |
& | ^ | AND, OR, XOR | UInt, SInt, Bool |
! | Logical NOT | Bool |
&& || | Logical AND, OR | Bool |