13#ifndef CIRCT_SUPPORT_TRUTHTABLE_H
14#define CIRCT_SUPPORT_TRUTHTABLE_H
17#include "llvm/ADT/APInt.h"
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/SmallVector.h"
20#include "llvm/Support/raw_ostream.h"
49 const llvm::APInt &
table)
52 "Truth table size mismatch");
61 llvm::APInt
getOutput(
const llvm::APInt &input)
const;
64 void setOutput(
const llvm::APInt &input,
const llvm::APInt &output);
86 void dump(llvm::raw_ostream &os = llvm::errs())
const;
117 unsigned inputNeg,
unsigned outputNeg)
144 llvm::SmallVectorImpl<unsigned> &permutation)
const;
162 void dump(llvm::raw_ostream &os = llvm::errs())
const;
188llvm::APInt
createVarMask(
unsigned numVars,
unsigned varIndex,
bool positive);
206std::pair<llvm::APInt, llvm::APInt>
225 unsigned size()
const {
return llvm::popcount(
mask); }
229 return mask & (1ULL << varIndex);
233 uint64_t varMask = 1ULL << varIndex;
239 uint64_t varMask = 1ULL << varIndex;
245 return inverted & (1ULL << varIndex);
261 void dump(llvm::raw_ostream &os = llvm::errs())
const;
assert(baseType &&"element must be base type")
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
SOPForm extractISOP(const llvm::APInt &truthTable, unsigned numVars)
Extract ISOP (Irredundant Sum-of-Products) from a truth table.
std::pair< llvm::APInt, llvm::APInt > computeCofactors(const llvm::APInt &f, unsigned numVars, unsigned varIndex)
Compute cofactor of a Boolean function for a given variable.
llvm::APInt createVarMask(unsigned numVars, unsigned varIndex, bool positive)
Create a mask for a variable in the truth table.
Represents a boolean function as a truth table.
BinaryTruthTable()
Default constructor creates an empty truth table.
BinaryTruthTable(unsigned numInputs, unsigned numOutputs)
Constructor for a truth table with given dimensions, initialized to zero.
BinaryTruthTable applyOutputNegation(unsigned negation) const
Apply output negation to create a new truth table.
llvm::APInt table
Truth table data as a packed bit vector.
BinaryTruthTable applyInputNegation(unsigned mask) const
Apply input negation to create a new truth table.
unsigned numInputs
Number of inputs for this boolean function.
BinaryTruthTable(unsigned numInputs, unsigned numOutputs, const llvm::APInt &table)
Constructor for a truth table with given dimensions and evaluation data.
void dump(llvm::raw_ostream &os=llvm::errs()) const
Debug dump method for truth tables.
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.
llvm::APInt getOutput(const llvm::APInt &input) const
Get the output value for a given input combination.
BinaryTruthTable applyPermutation(ArrayRef< unsigned > permutation) const
Apply input permutation to create a new truth table.
void setOutput(const llvm::APInt &input, const llvm::APInt &output)
Set the output value for a given input combination.
unsigned numOutputs
Number of outputs for this boolean function.
Represents a product term (cube) in a sum-of-products expression.
bool hasLiteral(unsigned varIndex) const
Has literal for variable at index varIndex.
unsigned size() const
Get number of literals in this cube.
void removeLiteral(unsigned varIndex)
uint64_t inverted
Bitmask indicating which variables are negated.
bool isLiteralInverted(unsigned varIndex) const
void setLiteral(unsigned varIndex, bool isInverted)
uint64_t mask
Bitmask indicating which variables appear in this cube.
Represents the canonical form of a boolean function under NPN equivalence.
NPNClass(const BinaryTruthTable &tt)
Constructor from a truth table.
unsigned outputNegation
Output negation mask.
static NPNClass computeNPNCanonicalForm(const BinaryTruthTable &tt)
Compute the canonical NPN form for a given truth table.
void getInputPermutation(const NPNClass &targetNPN, llvm::SmallVectorImpl< unsigned > &permutation) const
Get input permutation from this NPN class to another equivalent NPN class.
BinaryTruthTable truthTable
Canonical truth table.
void dump(llvm::raw_ostream &os=llvm::errs()) const
Debug dump method for NPN classes.
NPNClass()=default
Default constructor creates an empty NPN class.
bool equivalentOtherThanPermutation(const NPNClass &other) const
Equality comparison for NPN classes.
llvm::SmallVector< unsigned > inputPermutation
Input permutation applied.
unsigned inputNegation
Input negation mask.
bool isLexicographicallySmaller(const NPNClass &other) const
NPNClass(const BinaryTruthTable &tt, llvm::SmallVector< unsigned > inputPerm, unsigned inputNeg, unsigned outputNeg)