From: Jacob Lifshay Date: Wed, 27 Apr 2022 04:41:05 +0000 (-0700) Subject: add default_cost_fn X-Git-Url: https://git.libre-soc.org/?p=soc.git;a=commitdiff_plain;h=8b2e4c9fba7fdc1d7ff14ce5998f0018e71b4e7b add default_cost_fn --- 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