From 8b2e4c9fba7fdc1d7ff14ce5998f0018e71b4e7b Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Tue, 26 Apr 2022 21:41:05 -0700 Subject: [PATCH] add default_cost_fn --- .../fu/div/experiment/goldschmidt_div_sqrt.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py b/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py index 03378048..e319b9f6 100644 --- a/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py +++ b/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py @@ -699,6 +699,26 @@ class GoldschmidtDivParams: yield GoldschmidtDivOp.CalcResult + def default_cost_fn(self): + """ calculate the estimated cost on an arbitrary scale of implementing + goldschmidt division with the specified parameters. larger cost + values mean worse parameters. + + This is the default cost function for `GoldschmidtDivParams.get`. + + returns: float + """ + rom_cells = self.table_data_bits << self.table_addr_bits + cost = float(rom_cells) + for op in self.ops: + if op == GoldschmidtDivOp.MulNByF \ + or op == GoldschmidtDivOp.MulDByF: + mul_cost = self.expanded_width ** 2 + mul_cost *= self.expanded_width.bit_length() + cost += mul_cost + cost += 1e6 * self.iter_count + return cost + @staticmethod def get(io_width): """ find efficient parameters for a goldschmidt division algorithm -- 2.30.2