diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py index 296803e3e55b7b92d85f52b91b30533ecdfbc0b6..c43a12c738abe05daee5fc8de7bfbd19fbb1b118 100644 --- a/b_asic/core_operations.py +++ b/b_asic/core_operations.py @@ -229,3 +229,18 @@ class Butterfly(AbstractOperation): def evaluate(self, a, b): return a + b, a - b + +class MAD(AbstractOperation): + """Multiply-and-add operation. + TODO: More info. + """ + + def __init__(self, src0: Optional[SignalSourceProvider] = None, src1: Optional[SignalSourceProvider] = None, name: Name = ""): + super().__init__(input_count = 3, output_count = 1, name = name, input_sources = [src0, src1]) + + @property + def type_name(self) -> TypeName: + return "mad" + + def evaluate(self, a, b, c): + return a * b + c diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index d311bfacb69878c76d03b4194c5cf24a54e4f79c..7643af2d500ac06b683c6d09fb704d48e137c0a1 100644 --- a/b_asic/signal_flow_graph.py +++ b/b_asic/signal_flow_graph.py @@ -405,6 +405,16 @@ class SFG(AbstractOperation): # The old SFG will be deleted by Python GC return self() + def replace_operations(self, inputs: Sequence[Input], outputs: Sequence[Output], operation: Operation): + """Replace one or more operations in the sfg with a operation that have same number of inputs and outputs. + Then return a new deepcopy of the sfg. + + Arguments: + inputs: The inputs for the operations we are replacing. + outputs: The outputs for the operations we are replacing. + operation: The replacing operation. + """ + def _evaluate_source(self, src: OutputPort, results: MutableResultMap, registers: MutableRegisterMap, prefix: str) -> Number: src_prefix = prefix if src_prefix: