From: lkcl Date: Tue, 26 Jan 2021 04:16:35 +0000 (+0000) Subject: (no commit message) X-Git-Tag: convert-csv-opcode-to-binary~313 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0f8ce4a927547b468d25b1088e918f37caa26977;p=libreriscv.git --- diff --git a/openpower/sv/bitmanip.mdwn b/openpower/sv/bitmanip.mdwn index 6ba7fa24c..0138f9e56 100644 --- a/openpower/sv/bitmanip.mdwn +++ b/openpower/sv/bitmanip.mdwn @@ -492,6 +492,40 @@ if __name__ == "__main__": print("{:02x}".format(multGF2(0b10000000, 0b10000011))) ``` +gf invert + +``` +def gf_degree(a) : + res = 0 + a >>= 1 + while (a != 0) : + a >>= 1; + res += 1; + return res + +def gf_invert(a, mod=0x1B) : + v = mod + g1 = 1 + g2 = 0 + j = gf_degree(a) - 8 + + while (a != 1) : + if (j < 0) : + a, v = v, a + g1, g2 = g2, g1 + j = -j + + a ^= v << j + g1 ^= g2 << j + + a %= 256 # Emulating 8-bit overflow + g1 %= 256 # Emulating 8-bit overflow + + j = gf_degree(a) - gf_degree(v) + + return g1 +``` + # crc *