From: lkcl Date: Sun, 6 Mar 2022 07:52:27 +0000 (+0000) Subject: (no commit message) X-Git-Tag: opf_rfc_ls005_v1~3149 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bbbd1296e042ffbfd4cb94e4749f106d25d2ac4a;p=libreriscv.git --- diff --git a/openpower/sv/bitmanip.mdwn b/openpower/sv/bitmanip.mdwn index 80bfeeccb..b7a54c7ff 100644 --- a/openpower/sv/bitmanip.mdwn +++ b/openpower/sv/bitmanip.mdwn @@ -562,14 +562,24 @@ where the SimpleV variant may override RS-as-src differently from RS-as-dest ``` from functools import reduce +def gf_degree(a) : + res = 0 + a >>= 1 + while (a != 0) : + a >>= 1; + res += 1; + return res + # constants used in the multGF2 function mask1 = mask2 = polyred = None -def setGF2(degree, irPoly): +def setGF2(irPoly): """Define parameters of binary finite field GF(2^m)/g(x) - - degree: extension degree of binary field - irPoly: coefficients of irreducible polynomial g(x) """ + # degree: extension degree of binary field + degree = gf_degree(irPoly) + def i2P(sInt): """Convert an integer into a polynomial""" return [(sInt >> i) & 1 @@ -595,14 +605,14 @@ def multGF2(p1, p2): if __name__ == "__main__": # Define binary field GF(2^3)/x^3 + x + 1 - setGF2(3, 0b1011) + setGF2(0b1011) # degree 3 # Evaluate the product (x^2 + x + 1)(x^2 + 1) print("{:02x}".format(multGF2(0b111, 0b101))) # Define binary field GF(2^8)/x^8 + x^4 + x^3 + x + 1 # (used in the Advanced Encryption Standard-AES) - setGF2(8, 0b100011011) + setGF2(0b100011011) # degree 8 # Evaluate the product (x^7)(x^7 + x + 1) print("{:02x}".format(multGF2(0b10000000, 0b10000011)))