Module ariths_gen.multi_bit_circuits.adders.carry_skip_adder
Classes
class SignedCarrySkipAdder (a: Bus,
b: Bus,
bypass_block_size: int = 4,
prefix: str = '',
name: str = 's_cska',
**kwargs)-
Class representing signed carry skip (bypass) adder composed of smaller carry bypass blocks of chosen size to reduce propagation delay.
Signed carry skip (bypass) adder represents faster adder circuit which is composed of more complex circuitry but provides much less propagation delay as opposed to rca.
Each carry bypass block is composed of these logic parts: Propagate XOR gates compute propagate signals of corresponding bit pairs, these signals are then combined in multiple input AND gate (cascaded two input gates). Half/full adder cascade represents basic ripple carry adder design for input carry to ripple through them, additionally these adders compute individual output sum bits. Finally multiplexer lies at the end of each carry bypass block and is used to propagate block's input carry if multiple input AND gate output, which serves as select signal, is 1 or to wait for rippling of cout from the block's adders if it is 0.
At last XOR gates are used to ensure proper sign extension.
┼ ┼ ┼ ┼ ┌───▼───▼───┐ ┌───▼───▼───┐ ┌────┤ Propagate │ ┌────┤ Propagate │ │SEL │ signals │ │SEL │ signals │ ┌────▼─┐ └───────────┘ ┌────▼─┐ └───────────┘ │ │ │ │ ┌─┤2:1MUX│◄────────────────┬─┤2:1MUX│◄────────────────┬─Cin │ │ │ │ │ │ │ │ └────▲─┘ ┼ ┼ │ └────▲─┘ ┼ ┼ │ ┌──▼───┐ │ ┌───▼───▼───┐ │ │ ┌───▼───▼───┐ │ │ SIGN │ │ │ Adders │◄─┘ │ │ Adders │◄─┘ │Extend│ └────┤ │ └────┤ │ └──┬───┘ └─────┬─────┘ └─────┬─────┘ │ ┼ ┼ ▼ ▼ ▼ Cout Sums Sums
Description of the init method.
Args
a
:Bus
- First input bus.
b
:Bus
- Second input bus.
bypass_block_size
:int
, optional- Size of each composite bypass adder block size. Defaults to 4.
prefix
:str
, optional- Prefix name of signed cska. Defaults to "".
name
:str
, optional- Name of signed cska. Defaults to "s_cska".
Expand source code
class SignedCarrySkipAdder(UnsignedCarrySkipAdder, GeneralCircuit): """Class representing signed carry skip (bypass) adder composed of smaller carry bypass blocks of chosen size to reduce propagation delay. Signed carry skip (bypass) adder represents faster adder circuit which is composed of more complex circuitry but provides much less propagation delay as opposed to rca. Each carry bypass block is composed of these logic parts: Propagate XOR gates compute propagate signals of corresponding bit pairs, these signals are then combined in multiple input AND gate (cascaded two input gates). Half/full adder cascade represents basic ripple carry adder design for input carry to ripple through them, additionally these adders compute individual output sum bits. Finally multiplexer lies at the end of each carry bypass block and is used to propagate block's input carry if multiple input AND gate output, which serves as select signal, is 1 or to wait for rippling of cout from the block's adders if it is 0. At last XOR gates are used to ensure proper sign extension. ``` ┼ ┼ ┼ ┼ ┌───▼───▼───┐ ┌───▼───▼───┐ ┌────┤ Propagate │ ┌────┤ Propagate │ │SEL │ signals │ │SEL │ signals │ ┌────▼─┐ └───────────┘ ┌────▼─┐ └───────────┘ │ │ │ │ ┌─┤2:1MUX│◄────────────────┬─┤2:1MUX│◄────────────────┬─Cin │ │ │ │ │ │ │ │ └────▲─┘ ┼ ┼ │ └────▲─┘ ┼ ┼ │ ┌──▼───┐ │ ┌───▼───▼───┐ │ │ ┌───▼───▼───┐ │ │ SIGN │ │ │ Adders │◄─┘ │ │ Adders │◄─┘ │Extend│ └────┤ │ └────┤ │ └──┬───┘ └─────┬─────┘ └─────┬─────┘ │ ┼ ┼ ▼ ▼ ▼ Cout Sums Sums ``` Description of the __init__ method. Args: a (Bus): First input bus. b (Bus): Second input bus. bypass_block_size (int, optional): Size of each composite bypass adder block size. Defaults to 4. prefix (str, optional): Prefix name of signed cska. Defaults to "". name (str, optional): Name of signed cska. Defaults to "s_cska". """ def __init__(self, a: Bus, b: Bus, bypass_block_size: int = 4, prefix: str = "", name: str = "s_cska", **kwargs): super().__init__(a=a, b=b, bypass_block_size=bypass_block_size, prefix=prefix, name=name, signed=True, **kwargs) # Additional XOR gates to ensure correct sign extension in case of sign addition sign_xor_1 = XorGate(self.a.get_wire(self.N-1), self.b.get_wire(self.N-1), prefix=self.prefix+"_xor"+str(self.get_instance_num(cls=XorGate, count_disabled_gates=False)), parent_component=self) self.add_component(sign_xor_1) sign_xor_2 = XorGate(sign_xor_1.out, self.get_previous_component(2).out.get_wire(), prefix=self.prefix+"_xor"+str(self.get_instance_num(cls=XorGate, count_disabled_gates=False)), parent_component=self) self.add_component(sign_xor_2) self.out.connect(self.N, sign_xor_2.out)
Ancestors
Inherited members
UnsignedCarrySkipAdder
:add_component
get_blif_code_flat
get_blif_code_hier
get_c_code_flat
get_c_code_hier
get_cgp_code_flat
get_circuit_blif
get_circuit_c
get_circuit_def
get_circuit_gates
get_circuit_v
get_circuit_wire_index
get_circuit_wires
get_component_types
get_declaration_blif
get_declaration_c_flat
get_declaration_c_hier
get_declaration_v_flat
get_declaration_v_hier
get_declarations_c_hier
get_declarations_v_hier
get_function_blif_flat
get_function_block_blif
get_function_block_c
get_function_block_v
get_function_blocks_blif
get_function_blocks_c
get_function_blocks_v
get_function_out_blif
get_function_out_c_flat
get_function_out_c_hier
get_function_out_python_flat
get_function_out_v_flat
get_function_out_v_hier
get_hier_subcomponent_def
get_includes_c
get_init_c_flat
get_init_c_hier
get_init_python_flat
get_init_v_flat
get_init_v_hier
get_instance_num
get_invocation_blif_hier
get_invocations_blif_hier
get_multi_bit_components
get_one_bit_components
get_out_invocation_c
get_out_invocation_v
get_outputs_cgp
get_parameters_cgp
get_previous_component
get_prototype_blif
get_prototype_c
get_prototype_python
get_prototype_v
get_python_code_flat
get_triplets_cgp
get_unique_types
get_v_code_flat
get_v_code_hier
save_wire_id
class UnsignedCarrySkipAdder (a: Bus,
b: Bus,
bypass_block_size: int = 4,
prefix: str = '',
name: str = 'u_cska',
**kwargs)-
Class representing unsigned carry skip (bypass) adder composed of smaller carry bypass blocks of chosen size to reduce propagation delay.
Unsigned carry skip (bypass) adder represents faster adder circuit which is composed of more complex circuitry but provides much less propagation delay as opposed to rca.
Each carry bypass block is composed of these logic parts: Propagate XOR gates compute propagate signals of corresponding bit pairs, these signals are then combined in multiple input AND gate (cascaded two input gates). Half/full adder cascade represents basic ripple carry adder design for input carry to ripple through them, additionally these adders compute individual output sum bits. Finally multiplexer lies at the end of each carry bypass block and is used to propagate block's input carry if multiple input AND gate output, which serves as select signal, is 1 or to wait for rippling of cout from the block's adders if it is 0.
┼ ┼ ┼ ┼ ┌───▼───▼───┐ ┌───▼───▼───┐ ┌────┤ Propagate │ ┌────┤ Propagate │ │SEL │ signals │ │SEL │ signals │ ┌────▼─┐ └───────────┘ ┌────▼─┐ └───────────┘ │ │ │ │ ┌──┤2:1MUX│◄────────────────┬─┤2:1MUX│◄────────────────┬─Cin │ │ │ │ │ │ │ │ └────▲─┘ ┼ ┼ │ └────▲─┘ ┼ ┼ │ │ │ ┌───▼───▼───┐ │ │ ┌───▼───▼───┐ │ │ │ │ Adders │◄─┘ │ │ Adders │◄─┘ │ └────┤ │ └────┤ │ │ └─────┬─────┘ └─────┬─────┘ │ ┼ ┼ ▼ ▼ ▼ Cout Sums Sums
Description of the init method.
Args
a
:Bus
- First input bus.
b
:Bus
- Second input bus.
bypass_block_size
:int
, optional- Size of each composite bypass adder block size. Defaults to 4.
prefix
:str
, optional- Prefix name of unsigned cska. Defaults to "".
name
:str
, optional- Name of unsigned cska. Defaults to "u_cska".
Expand source code
class UnsignedCarrySkipAdder(GeneralCircuit): """Class representing unsigned carry skip (bypass) adder composed of smaller carry bypass blocks of chosen size to reduce propagation delay. Unsigned carry skip (bypass) adder represents faster adder circuit which is composed of more complex circuitry but provides much less propagation delay as opposed to rca. Each carry bypass block is composed of these logic parts: Propagate XOR gates compute propagate signals of corresponding bit pairs, these signals are then combined in multiple input AND gate (cascaded two input gates). Half/full adder cascade represents basic ripple carry adder design for input carry to ripple through them, additionally these adders compute individual output sum bits. Finally multiplexer lies at the end of each carry bypass block and is used to propagate block's input carry if multiple input AND gate output, which serves as select signal, is 1 or to wait for rippling of cout from the block's adders if it is 0. ``` ┼ ┼ ┼ ┼ ┌───▼───▼───┐ ┌───▼───▼───┐ ┌────┤ Propagate │ ┌────┤ Propagate │ │SEL │ signals │ │SEL │ signals │ ┌────▼─┐ └───────────┘ ┌────▼─┐ └───────────┘ │ │ │ │ ┌──┤2:1MUX│◄────────────────┬─┤2:1MUX│◄────────────────┬─Cin │ │ │ │ │ │ │ │ └────▲─┘ ┼ ┼ │ └────▲─┘ ┼ ┼ │ │ │ ┌───▼───▼───┐ │ │ ┌───▼───▼───┐ │ │ │ │ Adders │◄─┘ │ │ Adders │◄─┘ │ └────┤ │ └────┤ │ │ └─────┬─────┘ └─────┬─────┘ │ ┼ ┼ ▼ ▼ ▼ Cout Sums Sums ``` Description of the __init__ method. Args: a (Bus): First input bus. b (Bus): Second input bus. bypass_block_size (int, optional): Size of each composite bypass adder block size. Defaults to 4. prefix (str, optional): Prefix name of unsigned cska. Defaults to "". name (str, optional): Name of unsigned cska. Defaults to "u_cska". """ def __init__(self, a: Bus, b: Bus, bypass_block_size: int = 4, prefix: str = "", name: str = "u_cska", **kwargs): self.N = max(a.N, b.N) super().__init__(inputs=[a, b], prefix=prefix, name=name, out_N=self.N+1, **kwargs) # Bus sign extension in case buses have different lengths self.a.bus_extend(N=self.N, prefix=a.prefix) self.b.bus_extend(N=self.N, prefix=b.prefix) assert bypass_block_size > 0, "Block size of the individual bypass groups must be greater than 0." # To signify current number of blocks and number of bits that remain to be added into function blocks block_n = 0 N_wires = self.N cin = ConstantWireValue0() while N_wires != 0: propagate_wires = [] block_size = bypass_block_size if N_wires >= bypass_block_size else N_wires for i in range(block_size): # Generate propagate wires for corresponding bit pairs propagate_xor = XorGate(a=self.a.get_wire((block_n*bypass_block_size)+i), b=self.b.get_wire((block_n*bypass_block_size)+i), prefix=self.prefix+"_xor"+str(self.get_instance_num(cls=XorGate)), parent_component=self) self.add_component(propagate_xor) propagate_wires.append(propagate_xor.out) if block_n == 0 and i == 0: obj_adder = HalfAdder(a=self.a.get_wire((block_n*bypass_block_size)+i), b=self.b.get_wire((block_n*bypass_block_size)+i), prefix=self.prefix+"_ha"+str(self.get_instance_num(cls=HalfAdder))) else: obj_adder = FullAdder(a=self.a.get_wire((block_n*bypass_block_size)+i), b=self.b.get_wire((block_n*bypass_block_size)+i), c=cout, prefix=self.prefix+"_fa"+str(self.get_instance_num(cls=FullAdder))) cout = obj_adder.get_carry_wire() self.add_component(obj_adder) # Connecting adder's output sum bit to its proper position within the described circuit's output bus self.out.connect(i+(block_n*bypass_block_size), obj_adder.get_sum_wire()) # ANDing of propagate wires, gate's output serves as select signal into 2:1 multiplexer and signifies whether block's input carry should be propagated (thus reducing delay) or not propagation_and = MultipleInputLogicGate(a=Bus(prefix=self.prefix+f"_propagate_signals{block_n}", N=len(propagate_wires), wires_list=propagate_wires), two_input_gate_cls=AndGate, parent_component=self, prefix=self.prefix+f"_and_propagate{block_n}") mux = TwoOneMultiplexer(a=cout, b=cin, c=propagation_and.out, prefix=self.prefix+"_mux2to1"+str(self.get_instance_num(cls=TwoOneMultiplexer))) self.add_component(mux) # Updating cin for the the next bypass block # Also updating cout value which is used as cin for the first adder of the next block cin = mux.out.get_wire() cout = mux.out.get_wire() N_wires -= block_size block_n += 1 # Connection of final Cout self.out.connect(self.N, cin)
Ancestors
Subclasses
Inherited members
GeneralCircuit
:add_component
get_blif_code_flat
get_blif_code_hier
get_c_code_flat
get_c_code_hier
get_cgp_code_flat
get_circuit_blif
get_circuit_c
get_circuit_def
get_circuit_gates
get_circuit_v
get_circuit_wire_index
get_circuit_wires
get_component_types
get_declaration_blif
get_declaration_c_flat
get_declaration_c_hier
get_declaration_v_flat
get_declaration_v_hier
get_declarations_c_hier
get_declarations_v_hier
get_function_blif_flat
get_function_block_blif
get_function_block_c
get_function_block_v
get_function_blocks_blif
get_function_blocks_c
get_function_blocks_v
get_function_out_blif
get_function_out_c_flat
get_function_out_c_hier
get_function_out_python_flat
get_function_out_v_flat
get_function_out_v_hier
get_hier_subcomponent_def
get_includes_c
get_init_c_flat
get_init_c_hier
get_init_python_flat
get_init_v_flat
get_init_v_hier
get_instance_num
get_invocation_blif_hier
get_invocations_blif_hier
get_multi_bit_components
get_one_bit_components
get_out_invocation_c
get_out_invocation_v
get_outputs_cgp
get_parameters_cgp
get_previous_component
get_prototype_blif
get_prototype_c
get_prototype_python
get_prototype_v
get_python_code_flat
get_triplets_cgp
get_unique_types
get_v_code_flat
get_v_code_hier
save_wire_id