From: Jacob Lifshay Date: Thu, 28 Apr 2022 05:52:41 +0000 (-0700) Subject: move GoldschmidtDivState X-Git-Url: https://git.libre-soc.org/?p=soc.git;a=commitdiff_plain;h=ed18e275f2b8f3fe2b4151c46e92e1ec3e76372f move GoldschmidtDivState --- diff --git a/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py b/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py index e17f64c7..c3837e9a 100644 --- a/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py +++ b/src/soc/fu/div/experiment/goldschmidt_div_sqrt.py @@ -315,35 +315,6 @@ class FixedPoint: return retval -@dataclass -class GoldschmidtDivState: - orig_n: int - """original numerator""" - - orig_d: int - """original denominator""" - - n: FixedPoint - """numerator -- N_prime[i] in the paper's algorithm 2""" - - d: FixedPoint - """denominator -- D_prime[i] in the paper's algorithm 2""" - - f: "FixedPoint | None" = None - """current factor -- F_prime[i] in the paper's algorithm 2""" - - quotient: "int | None" = None - """final quotient""" - - remainder: "int | None" = None - """final remainder""" - - n_shift: "int | None" = None - """amount the numerator needs to be left-shifted at the end of the - algorithm. - """ - - class ParamsNotAccurateEnough(Exception): """raised when the parameters aren't accurate enough to have goldschmidt division work.""" @@ -1005,6 +976,35 @@ class GoldschmidtDivOp(enum.Enum): assert False, f"unimplemented GoldschmidtDivOp: {self}" +@dataclass +class GoldschmidtDivState: + orig_n: int + """original numerator""" + + orig_d: int + """original denominator""" + + n: FixedPoint + """numerator -- N_prime[i] in the paper's algorithm 2""" + + d: FixedPoint + """denominator -- D_prime[i] in the paper's algorithm 2""" + + f: "FixedPoint | None" = None + """current factor -- F_prime[i] in the paper's algorithm 2""" + + quotient: "int | None" = None + """final quotient""" + + remainder: "int | None" = None + """final remainder""" + + n_shift: "int | None" = None + """amount the numerator needs to be left-shifted at the end of the + algorithm. + """ + + def goldschmidt_div(n, d, params): """ Goldschmidt division algorithm.