SystemVerilog Operators

SystemVerilog, like other programming languages, offers a rich set of operators to perform various operations on data. These operators are categorized into different types:

Arithmetic Operators:

  • Addition (+): Adds two operands.
  • Subtraction (-): Subtracts the second operand from the first.
  • Multiplication (*): Multiplies two operands.
  • Division (/): Divides the first operand by the second.
  • Modulus (%): Returns the remainder of a division operation.  

Logical Operators:

  • Logical AND (&&): Returns true if both operands are true.
  • Logical OR (||): Returns true if at least one operand is true.
  • Logical NOT (!): Inverts the truth value of an operand.  

Bitwise Operators:

  • Bitwise AND (&): Performs a bitwise AND operation on each bit of the operands.
  • Bitwise OR (|): Performs a bitwise OR operation on each bit of the operands.
  • Bitwise XOR (^): Performs a bitwise XOR operation on each bit of the operands.
  • Bitwise NOT (~): Inverts each bit of an operand.
  • Bitwise NAND (~&): Performs a bitwise AND operation and then inverts the result.
  • Bitwise NOR (~|): Performs a bitwise OR operation and then inverts the result.
  • Bitwise XNOR (~^): Performs a bitwise XOR operation and then inverts the result.

Relational Operators:

  • Equal to (==): Compares two operands for equality.
  • Not equal to (!=): Compares two operands for inequality.
  • Greater than (>): Compares two operands to determine if the first is greater than the second.
  • Less than (<): Compares two operands to determine if the first is less than the second.
  • Greater than or equal to (>=): Compares two operands to determine if the first is greater than or equal to the second.
  • Less than or equal to (<=): Compares two operands to determine if the first is less than or equal to the second.

Shift Operators:

  • Left Shift (<<): Shifts bits to the left.
  • Right Shift (>>): Shifts bits to the right.
  • Arithmetic Right Shift (>>>): Shifts bits to the right, filling the leftmost bits with the sign bit.
  • Logical Right Shift (<<<): Shifts bits to the left, filling the rightmost bits with zeros.

Reduction Operators:

  • Logical AND Reduction (&): Performs a logical AND operation on all bits of an operand.
  • Logical OR Reduction (|): Performs a logical OR operation on all bits of an operand.
  • Logical XOR Reduction (^): Performs a logical XOR operation on all bits of an operand.

Assignment Operators:

  • Simple Assignment (=): Assigns a value to a variable.
  • Compound Assignment Operators:
    • +=, -=, *=, /=: Perform arithmetic operations and assign the result.
    • &=, |=, ^=, <<=, >>=, >>>=, <<<=: Perform bitwise operations and assign the result.

Conditional Operator (Ternary Operator):

condition ? expression1 : expression2

Evaluates the condition. If true, returns expression1; otherwise, returns expression2.