From: lkcl Date: Wed, 4 May 2022 00:13:39 +0000 (+0100) Subject: (no commit message) X-Git-Tag: opf_rfc_ls005_v1~2492 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f5e05d83d1e87c032bdc53e45cc12e24ce430438;p=libreriscv.git --- diff --git a/openpower/sv/bitmanip.mdwn b/openpower/sv/bitmanip.mdwn index 62b17ac2a..d6f58e595 100644 --- a/openpower/sv/bitmanip.mdwn +++ b/openpower/sv/bitmanip.mdwn @@ -732,6 +732,54 @@ q, r = cldivrem(n, d, width=XLEN) (RT) = r ``` +# bitmatrix + +``` +uint64_t bmatflip(uint64_t RA) +{ + uint64_t x = RA; + x = shfl64(x, 31); + x = shfl64(x, 31); + x = shfl64(x, 31); + return x; +} +uint64_t bmatxor(uint64_t RA, uint64_t RB) +{ + // transpose of RB + uint64_t RBt = bmatflip(RB); + uint8_t u[8]; // rows of RA + uint8_t v[8]; // cols of RB + for (int i = 0; i < 8; i++) { + u[i] = RA >> (i*8); + v[i] = RBt >> (i*8); + } + uint64_t x = 0; + for (int i = 0; i < 64; i++) { + if (pcnt(u[i / 8] & v[i % 8]) & 1) + x |= 1LL << i; + } + return x; +} +uint64_t bmator(uint64_t RA, uint64_t RB) +{ + // transpose of RB + uint64_t RBt = bmatflip(RB); + uint8_t u[8]; // rows of RA + uint8_t v[8]; // cols of RB + for (int i = 0; i < 8; i++) { + u[i] = RA >> (i*8); + v[i] = RBt >> (i*8); + } + uint64_t x = 0; + for (int i = 0; i < 64; i++) { + if ((u[i / 8] & v[i % 8]) != 0) + x |= 1LL << i; + } + return x; +} + +``` + # Instructions for Binary Galois Fields `GF(2^m)` see: @@ -935,54 +983,6 @@ term = (RC) (RS) = gfpmsubr(factor1, factor2, term) ``` -# bitmatrix - -``` -uint64_t bmatflip(uint64_t RA) -{ - uint64_t x = RA; - x = shfl64(x, 31); - x = shfl64(x, 31); - x = shfl64(x, 31); - return x; -} -uint64_t bmatxor(uint64_t RA, uint64_t RB) -{ - // transpose of RB - uint64_t RBt = bmatflip(RB); - uint8_t u[8]; // rows of RA - uint8_t v[8]; // cols of RB - for (int i = 0; i < 8; i++) { - u[i] = RA >> (i*8); - v[i] = RBt >> (i*8); - } - uint64_t x = 0; - for (int i = 0; i < 64; i++) { - if (pcnt(u[i / 8] & v[i % 8]) & 1) - x |= 1LL << i; - } - return x; -} -uint64_t bmator(uint64_t RA, uint64_t RB) -{ - // transpose of RB - uint64_t RBt = bmatflip(RB); - uint8_t u[8]; // rows of RA - uint8_t v[8]; // cols of RB - for (int i = 0; i < 8; i++) { - u[i] = RA >> (i*8); - v[i] = RBt >> (i*8); - } - uint64_t x = 0; - for (int i = 0; i < 64; i++) { - if ((u[i / 8] & v[i % 8]) != 0) - x |= 1LL << i; - } - return x; -} - -``` - # Already in POWER ISA ## count leading/trailing zeros with mask