Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added truth table helpers for 3-input functions #430

Merged
merged 6 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2614,13 +2614,27 @@ static const char *__doc_fiction_cp_and_tp_throughput =
R"doc(Throughput of the layout in clock cycles as :math:`\frac{1}{x}` where
only :math:`x` is stored.)doc";

static const char *__doc_fiction_create_and3_tt =
R"doc(Creates and returns a truth table that implements the conjunction in
three variables.

Returns:
Conjunction in three variables.)doc";

static const char *__doc_fiction_create_and_tt =
R"doc(Creates and returns a truth table that implements the conjunction in
two variables.

Returns:
Conjunction in two variables.)doc";

static const char *__doc_fiction_create_and_xor_tt =
R"doc(Creates and returns a truth table that implements the AND-XOR function
(a xor b and c) in three variables.

Returns:
AND-XOR in three variables.)doc";

static const char *__doc_fiction_create_array =
R"doc(Creates an array of size `N` and initializes its fields with value of
type `T` at compile time.
Expand Down Expand Up @@ -2650,6 +2664,13 @@ variables. The function returns a vector containing two truth tables.
Vector of truth tables, each representing an output of the
crossing wire function.)doc";

static const char *__doc_fiction_create_dot_tt =
R"doc(Creates and returns a truth table that implements the Dot function (a
xor (c or a and b)) in three variables.

Returns:
Dot function in three variables.)doc";

static const char *__doc_fiction_create_double_wire_tt =
R"doc(Creates and returns a vector of truth tables for a double wire multi-
output function.
Expand All @@ -2673,6 +2694,13 @@ one of the outputs of a multi-output function in two variables.
Vector of truth tables, each representing an output of the
identity function.)doc";

static const char *__doc_fiction_create_gamble_tt =
R"doc(Creates and returns a truth table that implements the Gamble function
(all or none of a,b,c) in three variables.

Returns:
Gamble in three variables.)doc";

static const char *__doc_fiction_create_ge_tt =
R"doc(Creates and returns a truth table that implements the greater-than-or-
equal function in two variables.
Expand Down Expand Up @@ -2706,6 +2734,13 @@ function in one variable.
Returns:
Identity function in one variable.)doc";

static const char *__doc_fiction_create_ite_tt =
R"doc(Creates and returns a truth table that implements the ITE (MUX)
function (if a then b else c) in three variables.

Returns:
ITE (MUX) in three variables.)doc";

static const char *__doc_fiction_create_le_tt =
R"doc(Creates and returns a truth table that implements the less-than-or-
equal function in two variables.
Expand Down Expand Up @@ -2748,6 +2783,20 @@ variable.
Returns:
Negation in one variable.)doc";

static const char *__doc_fiction_create_onehot_tt =
R"doc(Creates and returns a truth table that implements the Onehot function
(exactly one of a,b,c) in three variables.

Returns:
Onehot in three variables.)doc";

static const char *__doc_fiction_create_or_and_tt =
R"doc(Creates and returns a truth table that implements the OR-AND function
(a and (b or c)) in three variables.

Returns:
OR-AND in three variables.)doc";

static const char *__doc_fiction_create_or_tt =
R"doc(Creates and returns a truth table that implements the disjunction in
two variables.
Expand All @@ -2762,6 +2811,20 @@ exclusive disjunction in two variables.
Returns:
Negated exclusive disjunction in two variables.)doc";

static const char *__doc_fiction_create_xor3_tt =
R"doc(Creates and returns a truth table that implements the exclusive
disjunction in three variables.

Returns:
Exclusive disjunction in three variables.)doc";

static const char *__doc_fiction_create_xor_and_tt =
R"doc(Creates and returns a truth table that implements the XOR-AND function
(a and (b xor c)) in three variables.

Returns:
XOR-AND in three variables.)doc";

static const char *__doc_fiction_create_xor_tt =
R"doc(Creates and returns a truth table that implements the exclusive
disjunction in two variables.
Expand Down
13 changes: 13 additions & 0 deletions bindings/pyfiction/include/pyfiction/utils/truth_table_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ inline void truth_table_utils(pybind11::module& m)
m.def("create_nor_tt", &fiction::create_nor_tt, DOC(fiction_create_nor_tt));
m.def("create_xor_tt", &fiction::create_xor_tt, DOC(fiction_create_xor_tt));
m.def("create_xnor_tt", &fiction::create_xnor_tt, DOC(fiction_create_xnor_tt));
m.def("create_lt_tt", &fiction::create_lt_tt, DOC(fiction_create_lt_tt));
m.def("create_gt_tt", &fiction::create_gt_tt, DOC(fiction_create_gt_tt));
m.def("create_le_tt", &fiction::create_le_tt, DOC(fiction_create_le_tt));
m.def("create_ge_tt", &fiction::create_ge_tt, DOC(fiction_create_ge_tt));
m.def("create_and3_tt", &fiction::create_and3_tt, DOC(fiction_create_and3_tt));
m.def("create_xor_and_tt", &fiction::create_xor_and_tt, DOC(fiction_create_xor_and_tt));
m.def("create_or_and_tt", &fiction::create_or_and_tt, DOC(fiction_create_or_and_tt));
m.def("create_onehot_tt", &fiction::create_onehot_tt, DOC(fiction_create_onehot_tt));
m.def("create_maj_tt", &fiction::create_maj_tt, DOC(fiction_create_maj_tt));
m.def("create_gamble_tt", &fiction::create_gamble_tt, DOC(fiction_create_gamble_tt));
m.def("create_dot_tt", &fiction::create_dot_tt, DOC(fiction_create_dot_tt));
m.def("create_ite_tt", &fiction::create_ite_tt, DOC(fiction_create_ite_tt));
m.def("create_and_xor_tt", &fiction::create_and_xor_tt, DOC(fiction_create_and_xor_tt));
m.def("create_xor3_tt", &fiction::create_xor3_tt, DOC(fiction_create_xor3_tt));
m.def("create_double_wire_tt", &fiction::create_double_wire_tt, DOC(fiction_create_double_wire_tt));
m.def("create_crossing_wire_tt", &fiction::create_crossing_wire_tt, DOC(fiction_create_crossing_wire_tt));
m.def("create_fan_out_tt", &fiction::create_fan_out_tt, DOC(fiction_create_fan_out_tt));
Expand Down
13 changes: 13 additions & 0 deletions docs/utils/utils.rst
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,20 @@ Truth Table Utils
.. doxygenfunction:: fiction::create_nor_tt
.. doxygenfunction:: fiction::create_xor_tt
.. doxygenfunction:: fiction::create_xnor_tt
.. doxygenfunction:: fiction::create_lt_tt
.. doxygenfunction:: fiction::create_gt_tt
.. doxygenfunction:: fiction::create_le_tt
.. doxygenfunction:: fiction::create_ge_tt
.. doxygenfunction:: fiction::create_and3_tt
.. doxygenfunction:: fiction::create_xor_and_tt
.. doxygenfunction:: fiction::create_or_and_tt
.. doxygenfunction:: fiction::create_onehot_tt
.. doxygenfunction:: fiction::create_maj_tt
.. doxygenfunction:: fiction::create_gamble_tt
.. doxygenfunction:: fiction::create_dot_tt
.. doxygenfunction:: fiction::create_ite_tt
.. doxygenfunction:: fiction::create_and_xor_tt
.. doxygenfunction:: fiction::create_and_xor3_tt
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
.. doxygenfunction:: fiction::create_double_wire_tt
.. doxygenfunction:: fiction::create_crossing_wire_tt
.. doxygenfunction:: fiction::create_fan_out_tt
Expand Down
127 changes: 127 additions & 0 deletions include/fiction/utils/truth_table_utils.hpp
marcelwa marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <kitty/dynamic_truth_table.hpp>

#include <cstdint>
#include <vector>

namespace fiction
{
Expand Down Expand Up @@ -183,6 +184,62 @@ namespace fiction

return table;
}
/**
* Creates and returns a truth table that implements the conjunction in three variables.
*
* @return Conjunction in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_and3_tt() noexcept
{
constexpr const uint64_t lit = 0x80;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a truth table that implements the XOR-AND function (a and (b xor c)) in three variables.
*
* @return XOR-AND in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_xor_and_tt() noexcept
{
constexpr const uint64_t lit = 0x28;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a truth table that implements the OR-AND function (a and (b or c)) in three variables.
*
* @return OR-AND in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_or_and_tt() noexcept
{
constexpr const uint64_t lit = 0xa8;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a truth table that implements the Onehot function (exactly one of a,b,c) in three variables.
*
* @return Onehot in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_onehot_tt() noexcept
{
constexpr const uint64_t lit = 0x16;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a truth table that implements the majority function in three variables.
*
Expand All @@ -197,6 +254,76 @@ namespace fiction

return table;
}
/**
* Creates and returns a truth table that implements the Gamble function (all or none of a,b,c) in three variables.
*
* @return Gamble in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_gamble_tt() noexcept
{
constexpr const uint64_t lit = 0x81;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a truth table that implements the Dot function (a xor (c or a and b)) in three variables.
*
* @return Dot function in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_dot_tt() noexcept
{
constexpr const uint64_t lit = 0x52;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a truth table that implements the ITE (MUX) function (if a then b else c) in three variables.
*
* @return ITE (MUX) in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_ite_tt() noexcept
{
constexpr const uint64_t lit = 0xd8;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a truth table that implements the AND-XOR function (a xor b and c) in three variables.
*
* @return AND-XOR in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_and_xor_tt() noexcept
{
constexpr const uint64_t lit = 0x6a;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a truth table that implements the exclusive disjunction in three variables.
*
* @return Exclusive disjunction in three variables.
*/
[[nodiscard]] inline kitty::dynamic_truth_table create_xor3_tt() noexcept
{
constexpr const uint64_t lit = 0x96;

kitty::dynamic_truth_table table{3};
kitty::create_from_words(table, &lit, &lit + 1);

return table;
}
/**
* Creates and returns a vector of truth tables for a double wire multi-output function.
*
Expand Down
Loading