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