From: Luke Kenneth Casson Leighton Date: Sun, 6 Mar 2022 13:24:15 +0000 (+0000) Subject: experiment with gf_invert, not quite right X-Git-Tag: opf_rfc_ls005_v1~3140 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5184fc42c8574b8f7c7eabbcfd54631d8e534b25;p=libreriscv.git experiment with gf_invert, not quite right --- diff --git a/openpower/sv/gf2.py b/openpower/sv/gf2.py index 8a52a2b99..145825281 100644 --- a/openpower/sv/gf2.py +++ b/openpower/sv/gf2.py @@ -65,6 +65,31 @@ def xgcd(a, b): x0, x1 = x1, x0 - q * x1 return b, x0, y0 +def gf_invert(a, mod=0x11B) : + + mod_degree = gf_degree(mod) - 1 + v = mod + g1 = 1 + g2 = 0 + j = gf_degree(a) - mod_degree + + while (a != 1) : + # print (bin(a), j, bin(g1), bin(g2)) + if (j < 0) : + a, v = v, a + g1, g2 = g2, g1 + j = -j + + a ^= v << j + g1 ^= g2 << j + + + j = gf_degree(a) - gf_degree(v) + + a %= (1<