blob: 86cb48f127b31f196462a624de39467dfaa29310 [file] [log] [blame]
Karl Zhang3de5ab12021-05-31 11:45:48 +08001/*
Nik Dewallybacae6c2024-07-30 16:58:14 +01002 * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
Karl Zhang3de5ab12021-05-31 11:45:48 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef COMPUTE_HPP
9#define COMPUTE_HPP
10
Nik Dewallybacae6c2024-07-30 16:58:14 +010011#include <stdint.h>
Karl Zhang3de5ab12021-05-31 11:45:48 +080012#include <cstdlib>
13
14using 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
21class crc32
22{
23public:
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);
33private:
34 const uint32_t polynomial = 0xb4bcd35c;
35 uint32_t shift_reg;
36};
37
38#endif /* COMPUTE_HPP */