def match_bitwidth(*args): # TODO: allow for custom bit extension functions """ Matches the bitwidth of all of the input arguments. :type args: WireVector :return tuple of args in order with extended bits """ return pyrtl.match_bitwidth(*args)
def match_bitwidth(*args): # TODO: allow for custom bit extension functions """ Matches the bitwidth of all of the input arguments. :param WireVector args: input arguments :return: tuple of `args` in order with extended bits """ return pyrtl.match_bitwidth(*args)
def ripple_add(a, b, carry_in=0): a, b = pyrtl.match_bitwidth(a, b) # function that allows us to match the bitwidth of multiple different wires # By default, it zero extends the shorter bits if len(a) == 1: sumbits, carry_out = one_bit_add(a, b, carry_in) else: lsbit, ripplecarry = one_bit_add(a[0], b[0], carry_in) msbits, carry_out = ripple_add(a[1:], b[1:], ripplecarry) sumbits = pyrtl.concat(msbits, lsbit) return sumbits, carry_out
def ripple_add(a, b, cin=0): a, b = pyrtl.match_bitwidth(a, b) # this function is a function that allows us to match the bitwidth of multiple # different wires. By default, it zero extends the shorter bits if len(a) == 1: sumbits, cout = one_bit_add(a, b, cin) else: lsbit, ripplecarry = one_bit_add(a[0], b[0], cin) msbits, cout = ripple_add(a[1:], b[1:], ripplecarry) sumbits = pyrtl.concat(msbits, lsbit) return sumbits, cout
def cla_adder(a, b, cin=0, la_unit_len=4): """ Carry Lookahead Adder :param int la_unit_len: the length of input that every unit processes A Carry LookAhead Adder is an adder that is faster than a ripple carry adder, as it calculates the carry bits faster. It is not as fast as a Kogge-Stone adder, but uses less area. """ a, b = pyrtl.match_bitwidth(a, b) if len(a) <= la_unit_len: sum, cout = _cla_adder_unit(a, b, cin) return pyrtl.concat(cout, sum) else: sum, cout = _cla_adder_unit(a[0:la_unit_len], b[0:la_unit_len], cin) msbits = cla_adder(a[la_unit_len:], b[la_unit_len:], cout, la_unit_len) return pyrtl.concat(msbits, sum)