From: Luke Kenneth Casson Leighton Date: Tue, 5 Apr 2022 15:04:57 +0000 (+0100) Subject: intriguing small tidyup on gfpinv making it more symmetrical X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6082a5b3eab004baf821d17c5b245b9992fd9540;p=nmigen-gf.git intriguing small tidyup on gfpinv making it more symmetrical --- diff --git a/gf_reference/gfpinv.py b/gf_reference/gfpinv.py index 45b6dbb..ba1494e 100644 --- a/gf_reference/gfpinv.py +++ b/gf_reference/gfpinv.py @@ -19,19 +19,17 @@ def gfpinv(a): # implementations could use count-zeros on # both u and r to save cycles if u & 1 == 0: + if r & 1 != 0: + r += p u >>= 1 - if r & 1 == 0: - r >>= 1 - else: - r = (r + p) >> 1 + r >>= 1 # implementations could use count-zeros on # both v and s to save cycles elif v & 1 == 0: + if s & 1 != 0: + s += p v >>= 1 - if s & 1 == 0: - s >>= 1 - else: - s = (s + p) >> 1 + s >>= 1 else: x = u - v if x > 0: