OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
simple_checksum.cpp
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23// ----------------------------------------------------------------------------------------------------------------------
24
25#include <cstdint>
26#include <cstring> // For memcpy
27#include <cmath> // For std::isnan
28#include <limits> // For std::numeric_limits
29
30extern "C" {
31
32#define POLYNOMIAL 0xEDB88320 // standard polynomial for CRC32
33
34void init_crc32_table(uint32_t *crc32_table) {
35 for (uint32_t i = 0; i < 256; i++) {
36 uint32_t crc = i;
37 for (uint32_t j = 0; j < 8; j++) {
38 crc = (crc >> 1) ^ (POLYNOMIAL * (crc & 1));
39 }
40 crc32_table[i] = crc;
41 }
42}
43void simple_checksum(const double* vector, const int* length, double* hash) {
44 uint32_t crc32_table[256];
45 uint32_t crc = 0xFFFFFFFF; // initial value
46
47 init_crc32_table(crc32_table);
48
49 for (size_t i = 0; i < *length; i++) {
50 uint64_t value = *(uint64_t*)&vector[i]; // Conversion of double to uint64_t
51
52 for (size_t j = 0; j < sizeof(value); j++) {
53 uint8_t byte = value & 0xFF; // byte extraction
54 crc = (crc >> 8) ^ crc32_table[(crc ^ byte) & 0xFF];
55 value >>= 8; // shift for the next byte
56 }
57 }
58 *hash = (double) (crc ^ 0xFFFFFFFF);
59 }
60}
void simple_checksum(const double *vector, const int *length, double *hash)
void init_crc32_table(uint32_t *crc32_table)
#define POLYNOMIAL