Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1 | /* |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2019-2024, Arm Limited. All rights reserved. |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef COMPUTE_HPP |
| 9 | #define COMPUTE_HPP |
| 10 | |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame^] | 11 | #include <stdint.h> |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 12 | #include <cstdlib> |
| 13 | |
| 14 | using namespace std; |
| 15 | |
| 16 | /* Arguably at least, this LFSR-based hashing code is run more commonly on the |
| 17 | target itself -- included in the generated code -- than it is run here. |
| 18 | However, it's available here too, such as to parallel-calculate expected hash |
| 19 | values. */ |
| 20 | |
| 21 | class crc32 |
| 22 | { |
| 23 | public: |
| 24 | void seed_lfsr (uint32_t init_value); |
| 25 | /* lfsr_1b() performs one shift of the LFSR, factoring in a single bit of info, |
| 26 | that single bit must be in the low-order bit of the parameter. */ |
| 27 | uint32_t lfsr_1b (uint32_t a_bit); |
| 28 | // crc() has two overloadings, calculating the CRC for byte or word quantities: |
| 29 | uint32_t crc (uint8_t a_byte); |
| 30 | uint32_t crc (uint16_t a_halfword); |
| 31 | uint32_t crc (uint32_t a_word); |
| 32 | crc32 (void); |
| 33 | private: |
| 34 | const uint32_t polynomial = 0xb4bcd35c; |
| 35 | uint32_t shift_reg; |
| 36 | }; |
| 37 | |
| 38 | #endif /* COMPUTE_HPP */ |