annotate src/utils.c @ 9:07f0e2f43204

*: add the restrict keyword when necessary also fixed some typos in the README
author Paper
date Fri, 16 Dec 2022 21:55:37 -0500
parents be4835547dd0
children 42ac054c0231
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
1 /**
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
2 * utils.c:
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
3 *
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
4 * Useful utilities for general use.
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
5 **/
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
6 #ifndef WIN32_LEAN_AND_MEAN
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
7 # define WIN32_LEAN_AND_MEAN
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
8 #endif
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
9 #include <windows.h>
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
10 #include <stdint.h>
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
11
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
12 uint64_t get_system_time_in_milliseconds(void) {
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
13 FILETIME ft;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
14 GetSystemTimeAsFileTime(&ft);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
15 uint64_t ul = (uint64_t) ft.dwHighDateTime << 32 | ft.dwLowDateTime;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
16 return ((ul - 116444736000000000ULL)/10000000);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
17 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
18
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
19 uint32_t crc32b(unsigned char* restrict message) {
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
20 int32_t i, j;
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
21 uint32_t byte, crc, mask;
7
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
22
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
23 crc = 0xFFFFFFFF;
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
24 for (i = 0; message[i] != 0; i++) {
7
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
25 byte = message[i]; // Get next byte.
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
26 crc = crc ^ byte;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
27 for (j = 7; j >= 0; j--) { // Do eight times.
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
28 mask = -(crc & 1);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
29 crc = (crc >> 1) ^ (0xEDB88320 & mask);
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
30 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
31 }
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
32 return ~crc;
be4835547dd0 clean up code, convert git files to hg, etc.
Paper
parents:
diff changeset
33 }