Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | List of all members
circt::llhd::deseq::TruthTable Struct Reference

A boolean function expressed as a truth table. More...

#include <DeseqUtils.h>

Collaboration diagram for circt::llhd::deseq::TruthTable:
Collaboration graph
[legend]

Public Member Functions

unsigned getNumTerms () const
 Get the number of terms in the truth table.
 
bool isPoison () const
 
bool isTrue () const
 
bool isFalse () const
 
TruthTable operator~ () const
 
TruthTable operator& (const TruthTable &other) const
 
TruthTable operator| (const TruthTable &other) const
 
TruthTable operator^ (const TruthTable &other) const
 
TruthTableinvert ()
 
TruthTableoperator&= (const TruthTable &other)
 
TruthTableoperator|= (const TruthTable &other)
 
TruthTableoperator^= (const TruthTable &other)
 
bool operator== (const TruthTable &other) const
 
bool operator!= (const TruthTable &other) const
 
DNF canonicalize () const
 Convert the truth table into its canonical disjunctive normal form.
 

Static Public Member Functions

static TruthTable getPoison ()
 
static TruthTable getConst (unsigned numTerms, bool value)
 Create a boolean expression with a constant true or false value.
 
static TruthTable getTerm (unsigned numTerms, unsigned term)
 Create a boolean expression consisting of a single term.
 

Public Attributes

APInt bits
 The value of the boolean function for each possible combination of input term assignments.
 

Private Member Functions

APInt getTermMask (unsigned term) const
 
void fixupUnknown ()
 

Static Private Member Functions

static APInt getTermMask (unsigned bitWidth, unsigned term)
 Return a mask that has a 1 in all truth table rows where term is 1, and a 0 otherwise.
 

Detailed Description

A boolean function expressed as a truth table.

The first term is treated as a special "unknown" value marker with special semantics. Truth tables have exponential memory requirements. They are only useful to track a small number of terms, say up to 16, which already requires 64 kB of memory.

Definition at line 62 of file DeseqUtils.h.

Member Function Documentation

◆ canonicalize()

DNF TruthTable::canonicalize ( ) const

Convert the truth table into its canonical disjunctive normal form.

Definition at line 141 of file DeseqUtils.cpp.

References circt::llhd::deseq::DNFTerm::andTerms, bits, getNumTerms(), getTermMask(), invert(), isFalse(), isPoison(), isTrue(), and circt::llhd::deseq::DNF::orTerms.

Referenced by circt::llhd::deseq::operator<<().

◆ fixupUnknown()

void TruthTable::fixupUnknown ( )
private

Definition at line 207 of file DeseqUtils.cpp.

References bits, and getTermMask().

Referenced by invert().

◆ getConst()

static TruthTable circt::llhd::deseq::TruthTable::getConst ( unsigned  numTerms,
bool  value 
)
inlinestatic

Create a boolean expression with a constant true or false value.

Definition at line 84 of file DeseqUtils.h.

References assert().

◆ getNumTerms()

unsigned circt::llhd::deseq::TruthTable::getNumTerms ( ) const
inline

Get the number of terms in the truth table.

Since the width of bits corresponds to 2**numInputs, we count the number of trailing zeros in the width of bits to determine numInputs.

Definition at line 72 of file DeseqUtils.h.

References bits, and isPoison().

Referenced by canonicalize().

◆ getPoison()

static TruthTable circt::llhd::deseq::TruthTable::getPoison ( )
inlinestatic

Definition at line 78 of file DeseqUtils.h.

Referenced by operator&=(), operator^=(), and operator|=().

◆ getTerm()

static TruthTable circt::llhd::deseq::TruthTable::getTerm ( unsigned  numTerms,
unsigned  term 
)
inlinestatic

Create a boolean expression consisting of a single term.

Definition at line 91 of file DeseqUtils.h.

References assert(), and getTermMask().

◆ getTermMask() [1/2]

static APInt circt::llhd::deseq::TruthTable::getTermMask ( unsigned  bitWidth,
unsigned  term 
)
inlinestaticprivate

Return a mask that has a 1 in all truth table rows where term is 1, and a 0 otherwise.

This is equivalent to the truth table of a boolean expression consisting of a single term.

Definition at line 118 of file DeseqUtils.h.

Referenced by canonicalize(), fixupUnknown(), getTerm(), and getTermMask().

◆ getTermMask() [2/2]

APInt circt::llhd::deseq::TruthTable::getTermMask ( unsigned  term) const
inlineprivate

Definition at line 122 of file DeseqUtils.h.

References bits, and getTermMask().

◆ invert()

TruthTable & TruthTable::invert ( )

Definition at line 90 of file DeseqUtils.cpp.

References bits, fixupUnknown(), and isPoison().

Referenced by canonicalize(), operator^=(), and operator~().

◆ isFalse()

bool circt::llhd::deseq::TruthTable::isFalse ( ) const
inline

Definition at line 81 of file DeseqUtils.h.

References bits.

Referenced by canonicalize(), and operator^=().

◆ isPoison()

bool circt::llhd::deseq::TruthTable::isPoison ( ) const
inline

Definition at line 79 of file DeseqUtils.h.

References bits.

Referenced by canonicalize(), getNumTerms(), invert(), operator&=(), operator^=(), and operator|=().

◆ isTrue()

bool circt::llhd::deseq::TruthTable::isTrue ( ) const
inline

Definition at line 80 of file DeseqUtils.h.

References bits.

Referenced by canonicalize(), and operator^=().

◆ operator!=()

bool circt::llhd::deseq::TruthTable::operator!= ( const TruthTable other) const
inline

Definition at line 109 of file DeseqUtils.h.

◆ operator&()

TruthTable TruthTable::operator& ( const TruthTable other) const

Definition at line 72 of file DeseqUtils.cpp.

◆ operator&=()

TruthTable & TruthTable::operator&= ( const TruthTable other)

Definition at line 98 of file DeseqUtils.cpp.

References bits, getPoison(), and isPoison().

◆ operator==()

bool circt::llhd::deseq::TruthTable::operator== ( const TruthTable other) const
inline

Definition at line 108 of file DeseqUtils.h.

References bits.

◆ operator^()

TruthTable TruthTable::operator^ ( const TruthTable other) const

Definition at line 84 of file DeseqUtils.cpp.

◆ operator^=()

TruthTable & TruthTable::operator^= ( const TruthTable other)

Definition at line 118 of file DeseqUtils.cpp.

References getPoison(), invert(), isFalse(), isPoison(), and isTrue().

◆ operator|()

TruthTable TruthTable::operator| ( const TruthTable other) const

Definition at line 78 of file DeseqUtils.cpp.

◆ operator|=()

TruthTable & TruthTable::operator|= ( const TruthTable other)

Definition at line 108 of file DeseqUtils.cpp.

References bits, getPoison(), and isPoison().

◆ operator~()

TruthTable TruthTable::operator~ ( ) const

Definition at line 66 of file DeseqUtils.cpp.

References invert().

Member Data Documentation

◆ bits

APInt circt::llhd::deseq::TruthTable::bits

The value of the boolean function for each possible combination of input term assignments.

If the boolean function has N input terms, this APInt lists all 2**N possible combinations. The special "poison" value is represented as a zero-width bits.

Definition at line 67 of file DeseqUtils.h.

Referenced by canonicalize(), fixupUnknown(), getNumTerms(), getTermMask(), invert(), isFalse(), isPoison(), isTrue(), operator&=(), operator==(), and operator|=().


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