From 5e5056c616797bbd3a6b001483ff7377984f165d Mon Sep 17 00:00:00 2001 From: Kevin <Kevin> Date: Fri, 24 Apr 2020 14:09:01 +0200 Subject: [PATCH] Added MAD operation to core_operations.py and function definition for replacing operations --- b_asic/core_operations.py | 15 +++++++++++++++ b_asic/signal_flow_graph.py | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/b_asic/core_operations.py b/b_asic/core_operations.py index 296803e3..c43a12c7 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 d311bfac..7643af2d 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: -- GitLab