From: lkcl Date: Mon, 28 Dec 2020 16:31:00 +0000 (+0000) Subject: (no commit message) X-Git-Tag: convert-csv-opcode-to-binary~758 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=44e0e3f333353436e3b3f856dc4b87aa187bcd10;p=libreriscv.git --- diff --git a/openpower/sv/bitmanip.mdwn b/openpower/sv/bitmanip.mdwn index 73ba2ba15..21eebc708 100644 --- a/openpower/sv/bitmanip.mdwn +++ b/openpower/sv/bitmanip.mdwn @@ -230,3 +230,22 @@ for (int i = 0; i < XLEN; i++) if ((rs2 >> i) & 1) x ^= rs1 >> (XLEN-i-1); return x; ``` + +# crc + +``` +uint_xlen_t crc32(uint_xlen_t x, int nbits) { for (int i = 0; i < nbits; i++) +} +x = (x >> 1) ^ (0xEDB88320 & ~((x&1)-1)); return x; +uint_xlen_t crc32c(uint_xlen_t x, int nbits) { for (int i = 0; i < nbits; i++) +} +x = (x >> 1) ^ (0x82F63B78 & ~((x&1)-1)); return x; +uint_xlen_t crc32_b(uint_xlen_t rs1) { return crc32(rs1, 8); } uint_xlen_t crc32_h(uint_xlen_t rs1) { return crc32(rs1, 16); } uint_xlen_t crc32_w(uint_xlen_t rs1) { return crc32(rs1, 32); } +uint_xlen_t crc32c_b(uint_xlen_t rs1) { return crc32c(rs1, 8); } uint_xlen_t crc32c_h(uint_xlen_t rs1) { return crc32c(rs1, 16); } uint_xlen_t crc32c_w(uint_xlen_t rs1) { return crc32c(rs1, 32); } +#if XLEN > 32 +uint_xlen_t crc32_d (uint_xlen_t rs1) { return crc32 (rs1, 64); } uint_xlen_t crc32c_d(uint_xlen_t rs1) { return crc32c(rs1, 64); } #endif +Payload data must be XOR’ed into the LSB end of the state before executing the CRC instruction. The following code demonstrates the use of crc32.b: +uint32_t crc32_demo(const uint8_t *p, int len) { uint32_t x = 0xffffffff; +for (int i = 0; i < len; i++) { x = x ^ p[i]; +x = crc32_b(x); } }return ~x; +```