CIRCT 24.0.0git
Loading...
Searching...
No Matches
circt::BinaryTruthTable Struct Reference

Represents a boolean function as a truth table. More...

#include <TruthTable.h>

Collaboration diagram for circt::BinaryTruthTable:

Public Member Functions

 BinaryTruthTable ()
 Default constructor creates an empty truth table.
 BinaryTruthTable (unsigned numInputs, unsigned numOutputs, const llvm::APInt &table)
 Constructor for a truth table with given dimensions and evaluation data.
 BinaryTruthTable (unsigned numInputs, unsigned numOutputs)
 Constructor for a truth table with given dimensions, initialized to zero.
llvm::APInt getOutput (const llvm::APInt &input) const
 Get the output value for a given input combination.
void setOutput (const llvm::APInt &input, const llvm::APInt &output)
 Set the output value for a given input combination.
BinaryTruthTable applyPermutation (ArrayRef< unsigned > permutation) const
 Apply input permutation to create a new truth table.
BinaryTruthTable applyInputNegation (unsigned mask) const
 Apply input negation to create a new truth table.
BinaryTruthTable applyOutputNegation (unsigned negation) const
 Apply output negation to create a new truth table.
bool isLexicographicallySmaller (const BinaryTruthTable &other) const
 Check if this truth table is lexicographically smaller than another.
bool operator== (const BinaryTruthTable &other) const
 Equality comparison for truth tables.
void dump (llvm::raw_ostream &os=llvm::errs()) const
 Debug dump method for truth tables.

Public Attributes

unsigned numInputs
 Number of inputs for this boolean function.
unsigned numOutputs
 Number of outputs for this boolean function.
llvm::APInt table
 Truth table data as a packed bit vector.

Detailed Description

Represents a boolean function as a truth table.

A truth table stores the output values for all possible input combinations of a boolean function. For a function with n inputs and m outputs, the truth table contains 2^n entries, each with m output bits.

Example: For a 2-input AND gate:

  • Input 00 -> Output 0
  • Input 01 -> Output 0
  • Input 10 -> Output 0
  • Input 11 -> Output 1 This would be stored as the bit pattern 0001 in the truth table.

TODO: Rename this to MultiOutputTruthTable since for single-output functions we can just use llvm::APInt directly.

Definition at line 41 of file TruthTable.h.

Constructor & Destructor Documentation

◆ BinaryTruthTable() [1/3]

circt::BinaryTruthTable::BinaryTruthTable ( )
inline

Default constructor creates an empty truth table.

Definition at line 47 of file TruthTable.h.

References numInputs, numOutputs, and table.

Referenced by applyInputNegation(), applyOutputNegation(), applyPermutation(), isLexicographicallySmaller(), and operator==().

◆ BinaryTruthTable() [2/3]

circt::BinaryTruthTable::BinaryTruthTable ( unsigned numInputs,
unsigned numOutputs,
const llvm::APInt & table )
inline

Constructor for a truth table with given dimensions and evaluation data.

Definition at line 50 of file TruthTable.h.

References assert(), numInputs, numOutputs, and table.

◆ BinaryTruthTable() [3/3]

circt::BinaryTruthTable::BinaryTruthTable ( unsigned numInputs,
unsigned numOutputs )
inline

Constructor for a truth table with given dimensions, initialized to zero.

Definition at line 58 of file TruthTable.h.

References numInputs, numOutputs, and table.

Member Function Documentation

◆ applyInputNegation()

BinaryTruthTable BinaryTruthTable::applyInputNegation ( unsigned mask) const

Apply input negation to create a new truth table.

This negates selected input variables based on the mask.

Definition at line 177 of file TruthTable.cpp.

References BinaryTruthTable(), getOutput(), numInputs, numOutputs, and setOutput().

Referenced by circt::NPNClass::computeNPNCanonicalForm().

◆ applyOutputNegation()

BinaryTruthTable BinaryTruthTable::applyOutputNegation ( unsigned negation) const

Apply output negation to create a new truth table.

This negates selected output variables based on the mask.

Definition at line 193 of file TruthTable.cpp.

References BinaryTruthTable(), getOutput(), numInputs, numOutputs, and setOutput().

Referenced by circt::NPNClass::computeNPNCanonicalForm().

◆ applyPermutation()

BinaryTruthTable BinaryTruthTable::applyPermutation ( ArrayRef< unsigned > permutation) const

Apply input permutation to create a new truth table.

This reorders the input variables according to the given permutation.

Definition at line 157 of file TruthTable.cpp.

References assert(), BinaryTruthTable(), getOutput(), numInputs, numOutputs, and setOutput().

Referenced by circt::NPNClass::computeNPNCanonicalForm().

◆ dump()

void BinaryTruthTable::dump ( llvm::raw_ostream & os = llvm::errs()) const

Debug dump method for truth tables.

Definition at line 220 of file TruthTable.cpp.

References getOutput(), numInputs, numOutputs, and table.

◆ getOutput()

llvm::APInt BinaryTruthTable::getOutput ( const llvm::APInt & input) const

Get the output value for a given input combination.

Definition at line 141 of file TruthTable.cpp.

References assert(), numInputs, numOutputs, and table.

Referenced by applyInputNegation(), applyOutputNegation(), applyPermutation(), and dump().

◆ isLexicographicallySmaller()

bool BinaryTruthTable::isLexicographicallySmaller ( const BinaryTruthTable & other) const

Check if this truth table is lexicographically smaller than another.

Used for canonical ordering of truth tables.

Definition at line 209 of file TruthTable.cpp.

References assert(), BinaryTruthTable(), numInputs, numOutputs, and table.

◆ operator==()

bool BinaryTruthTable::operator== ( const BinaryTruthTable & other) const

Equality comparison for truth tables.

Definition at line 215 of file TruthTable.cpp.

References BinaryTruthTable(), numInputs, numOutputs, and table.

◆ setOutput()

void BinaryTruthTable::setOutput ( const llvm::APInt & input,
const llvm::APInt & output )

Set the output value for a given input combination.

Definition at line 146 of file TruthTable.cpp.

References assert(), numInputs, numOutputs, and table.

Referenced by applyInputNegation(), applyOutputNegation(), and applyPermutation().

Member Data Documentation

◆ numInputs

◆ numOutputs

◆ table

llvm::APInt circt::BinaryTruthTable::table

The documentation for this struct was generated from the following files: