From 2dc2d429432b95bd2cd967248e7db97b02f3ed7d Mon Sep 17 00:00:00 2001 From: lkcl Date: Wed, 4 May 2022 01:15:05 +0100 Subject: [PATCH] --- openpower/sv/bitmanip.mdwn | 97 +++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/openpower/sv/bitmanip.mdwn b/openpower/sv/bitmanip.mdwn index d6f58e595..a1d3de1b2 100644 --- a/openpower/sv/bitmanip.mdwn +++ b/openpower/sv/bitmanip.mdwn @@ -560,6 +560,55 @@ uint64_t gorc64(uint64_t RA, uint64_t RB) } ``` + +# 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; +} + +``` + # Introduction to Carry-less and GF arithmetic * obligatory xkcd @@ -732,54 +781,6 @@ 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: -- 2.30.2