Modified definition of MAC class to allow proper generation of output representations.
This commit is contained in:
parent
8c0f24cd2d
commit
a1827c957c
26
test_gen.py
26
test_gen.py
@ -1,6 +1,6 @@
|
||||
|
||||
from ariths_gen.core.arithmetic_circuits import GeneralCircuit
|
||||
from ariths_gen.wire_components import Bus
|
||||
from ariths_gen.wire_components import Bus, Wire
|
||||
from ariths_gen.multi_bit_circuits.adders import UnsignedRippleCarryAdder
|
||||
from ariths_gen.multi_bit_circuits.multipliers import UnsignedArrayMultiplier
|
||||
|
||||
@ -10,12 +10,28 @@ class MAC(GeneralCircuit):
|
||||
super().__init__([A, B, R])
|
||||
assert A.N == B.N
|
||||
assert R.N == 2 * A.N
|
||||
self.mul = self.add_component(UnsignedArrayMultiplier(A, B))
|
||||
self.add = self.add_component(UnsignedRippleCarryAdder(R, self.mul.out))
|
||||
|
||||
self.out = self.add.out
|
||||
# Je zapotřebí zajistit ještě unikátnost jmen podkomponent a jejich vodičů pro správné generování
|
||||
mul_prefix = self.prefix + "_" + UnsignedArrayMultiplier(a=A, b=B).prefix + str(A.N)
|
||||
mul_a = Bus(prefix=f"{mul_prefix}_a", wires_list=A.bus)
|
||||
mul_b = Bus(prefix=f"{mul_prefix}_b", wires_list=B.bus)
|
||||
self.mul = self.add_component(UnsignedArrayMultiplier(a=mul_a, b=mul_b, prefix=mul_prefix))
|
||||
|
||||
add_prefix = self.prefix + "_" + UnsignedRippleCarryAdder(a=R, b=self.mul.out).prefix + str(R.N)
|
||||
add_a = Bus(prefix=f"{add_prefix}_a", N=self.mul.out.N)
|
||||
add_b = Bus(prefix=f"{add_prefix}_b", wires_list=R.bus)
|
||||
# Kvůli správnému generování je potřeba správně napojit vodiče mezi mul a add
|
||||
[add_a.connect(o, self.mul.out.get_wire(o), inserted_wire_desired_index=o) for o in range(0, self.mul.out.N)]
|
||||
|
||||
self.add = self.add_component(UnsignedRippleCarryAdder(a=add_a, b=add_b, prefix=add_prefix))
|
||||
|
||||
# Bylo potřeba upravit definici pro výstupní sběrnici (vázanou na název top level obvodu ("ma") a mající délku jako výstup z adderu)
|
||||
self.out = Bus(self.prefix+"_out", self.add.out.N)
|
||||
|
||||
# Nakonec je potřeba napojit výstup adderu na výstup mac
|
||||
[self.out.connect(o, self.add.out.get_wire(o), inserted_wire_desired_index=o) for o in range(0, self.out.N)]
|
||||
|
||||
# usage
|
||||
mymac = MAC(Bus("a",8), Bus("b", 8), Bus("acc", 16))
|
||||
mymac.get_v_code_hier(open("out.v", "w"))
|
||||
mymac.get_c_code_hier(open("out.c", "w"))
|
||||
mymac.get_c_code_hier(open("out.c", "w"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user