From 6082a5b3eab004baf821d17c5b245b9992fd9540 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 5 Apr 2022 16:04:57 +0100 Subject: [PATCH] intriguing small tidyup on gfpinv making it more symmetrical --- gf_reference/gfpinv.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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: -- 2.30.2