From: lkcl Date: Sat, 11 Dec 2021 21:21:41 +0000 (+0000) Subject: (no commit message) X-Git-Tag: opf_rfc_ls005_v1~3285 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=42499e421ea4ebbaed8af2077ca4939fe1064f54;p=libreriscv.git --- diff --git a/openpower/sv/bitmanip.mdwn b/openpower/sv/bitmanip.mdwn index 63db85117..d9c836bd9 100644 --- a/openpower/sv/bitmanip.mdwn +++ b/openpower/sv/bitmanip.mdwn @@ -462,37 +462,6 @@ uint64_t gorc64(uint64_t RA, uint64_t RB) ``` -# carryless mul - -based on RV bitmanip -see https://en.wikipedia.org/wiki/CLMUL_instruction_set - -``` -uint_xlen_t clmul(uint_xlen_t RA, uint_xlen_t RB) -{ - uint_xlen_t x = 0; - for (int i = 0; i < XLEN; i++) - if ((RB >> i) & 1) - x ^= RA << i; - return x; -} -uint_xlen_t clmulh(uint_xlen_t RA, uint_xlen_t RB) -{ - uint_xlen_t x = 0; - for (int i = 1; i < XLEN; i++) - if ((RB >> i) & 1) - x ^= RA >> (XLEN-i); - return x; -} -uint_xlen_t clmulr(uint_xlen_t RA, uint_xlen_t RB) -{ - uint_xlen_t x = 0; - for (int i = 0; i < XLEN; i++) - if ((RB >> i) & 1) - x ^= RA >> (XLEN-i-1); - return x; -} -``` # Galois Field see @@ -611,6 +580,42 @@ def gf_invert(a, mod=0x1B) : return g1 ``` +## carryless mul + +based on RV bitmanip +see https://en.wikipedia.org/wiki/CLMUL_instruction_set + +these are GF2 operations with the modulo set to 2^degree. +they are worth adding as their own non-overwrite operations +(in the same pipeline). + +``` +uint_xlen_t clmul(uint_xlen_t RA, uint_xlen_t RB) +{ + uint_xlen_t x = 0; + for (int i = 0; i < XLEN; i++) + if ((RB >> i) & 1) + x ^= RA << i; + return x; +} +uint_xlen_t clmulh(uint_xlen_t RA, uint_xlen_t RB) +{ + uint_xlen_t x = 0; + for (int i = 1; i < XLEN; i++) + if ((RB >> i) & 1) + x ^= RA >> (XLEN-i); + return x; +} +uint_xlen_t clmulr(uint_xlen_t RA, uint_xlen_t RB) +{ + uint_xlen_t x = 0; + for (int i = 0; i < XLEN; i++) + if ((RB >> i) & 1) + x ^= RA >> (XLEN-i-1); + return x; +} +``` + # bitmatrix ```