jak-project/common/util/crc32.h
water111 cc8801a27b
[goalc] speed up jak3 compilation (#3454)
I noticed that jak 3's compilation was spending a lot of time accessing
the `unordered_map`s we use to store constants and symbol types.

 
I repurposed the `EnvironmentMap` originally made for GOOS for this. It
turns out that we were copying the entire constant map whenever we
encountered a `deftype`, and fixed that too.

This speeds up jak3 compiles from ~16 to 11 seconds for me.
2024-04-06 16:01:17 -04:00

47 lines
822 B
C

#pragma once
#include <cstdlib>
#include "common/common_types.h"
u32 crc32(const u8* data, size_t size);
#include <cstring>
#ifdef __aarch64__
#include <arm_acle.h>
inline u32 crc32(const u8* data, size_t size) {
u32 result = 0xffffffff;
while (size >= 4) {
u32 x;
memcpy(&x, data, 4);
data += 4;
size -= 4;
result = __crc32w(result, x);
}
while (size) {
result = __crc32b(result, *data);
data++;
size--;
}
return ~result;
}
#else
#include <immintrin.h>
inline u32 crc32(const u8* data, size_t size) {
u32 result = 0xffffffff;
while (size >= 4) {
u32 x;
memcpy(&x, data, 4);
data += 4;
size -= 4;
result = _mm_crc32_u32(result, x);
}
while (size) {
result = _mm_crc32_u8(result, *data);
data++;
size--;
}
return ~result;
}
#endif