Arithmetic networks
The file mockturtle/generators/arithmetic.hpp
implements several functions
to generate arithmetic networks.
Addition and Subtraction
-
template<typename Ntk>
inline std::pair<signal<Ntk>, signal<Ntk>> mockturtle::full_adder(Ntk &ntk, const signal<Ntk> &a, const signal<Ntk> &b, const signal<Ntk> &c) Inserts a full adder into a network.
Inserts a full adder for three inputs (two 1-bit operands and one carry) into the network and returns a pair of sum and carry bit.
By default creates a seven 2-input gate network composed of AND, NOR, and OR gates. If network has
create_node
function, creates two 3-input gate network. If the network has ternarycreate_maj
andcreate_xor3
functions, it will use them (except for AIGs).- Parameters:
ntk – Network
a – First input operand
b – Second input operand
c – Carry
- Returns:
Pair of sum (
first
) and carry (second
)
-
template<typename Ntk>
inline void mockturtle::carry_ripple_adder_inplace(Ntk &ntk, std::vector<signal<Ntk>> &a, std::vector<signal<Ntk>> const &b, signal<Ntk> &carry) Creates carry ripple adder structure.
Creates a carry ripple structure composed of full adders. The vectors
a
andb
must have the same size. The resulting sum bits are eventually stored ina
and the carry bit will be overridden to store the output carry bit.- Parameters:
a – First input operand, will also have the output after the call
b – Second input operand
carry – Carry bit, will also have the output carry after the call
-
template<typename Ntk>
inline void mockturtle::carry_ripple_subtractor_inplace(Ntk &ntk, std::vector<signal<Ntk>> &a, const std::vector<signal<Ntk>> &b, signal<Ntk> &carry) Creates carry ripple subtractor structure.
Creates a carry ripple structure composed of full adders. The vectors
a
andb
must have the same size. The resulting sum bits are eventually stored ina
and the carry bit will be overridden to store the output carry bit. The inputs inb
are inverted to realize subtraction with full adders. The carry bit must be passed in inverted state to the subtractor.- Parameters:
a – First input operand, will also have the output after the call
b – Second input operand
carry – Carry bit, will also have the output carry after the call
-
template<typename Ntk>
inline std::vector<signal<Ntk>> mockturtle::carry_ripple_multiplier(Ntk &ntk, std::vector<signal<Ntk>> const &a, std::vector<signal<Ntk>> const &b) Creates a classical multiplier using full adders.
The vectors
a
andb
must not have the same size. The function creates the multiplier inntk
and returns output signals, whose size is the summed sizes ofa
andb
.- Parameters:
ntk – Network
a – First input operand
b – Second input operand
-
template<typename Ntk>
inline void mockturtle::carry_lookahead_adder_inplace(Ntk &ntk, std::vector<signal<Ntk>> &a, std::vector<signal<Ntk>> const &b, signal<Ntk> &carry) Creates carry lookahead adder structure.
Creates a carry lookahead structure composed of full adders. The vectors
a
andb
must have the same size. The resulting sum bits are eventually stored ina
and the carry bit will be overridden to store the output carry bit.- Parameters:
a – First input operand, will also have the output after the call
b – Second input operand
carry – Carry bit, will also have the output carry after the call
-
template<typename Ntk>
inline std::vector<signal<Ntk>> mockturtle::sideways_sum_adder(Ntk &ntk, std::vector<signal<Ntk>> const &a) Creates a sideways sum adder using half and full adders.
The function creates the adder in
ntk
and returns output signals, whose size is floor(log2(a.size()))+1.- Parameters:
ntk – Network
a – Input operand