diff --git a/src/crc32.c b/src/crc32.c index 856fcd4..d9fb87a 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -19,6 +19,14 @@ #include "crc32.h" +#if defined(__GNUC__) || defined(__clang__) + #define RESTRICT __restrict__ +#elif defined(_MSC_VER) || defined(__INTEL_COMPILER) + #define RESTRICT __restrict +#else + #error Your compiler, configuration or platform is not supported. +#endif + static const u32 crc32Table[256] = { 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, 0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L, 0x105EC76FL, 0xE235446CL, @@ -51,7 +59,7 @@ static const u32 crc32Table[256] = { 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L }; -u32 crc32sum(u32 crc, u8 * restrict buf, size_t size) { +u32 crc32sum(u32 crc, u8 * RESTRICT buf, size_t size) { while (size--) crc = crc32Table[(crc ^ *(buf++)) & 0xff] ^ (crc >> 8); return crc; } diff --git a/src/lzp.c b/src/lzp.c index c19580d..2206673 100644 --- a/src/lzp.c +++ b/src/lzp.c @@ -11,8 +11,16 @@ #define MATCH 0xf2 -static s32 lzp_encode_block(const u8 * restrict in, const u8 * in_end, u8 * restrict out, u8 * out_end, - s32 * restrict lut, s32 mask, s32 m_len) { +#if defined(__GNUC__) || defined(__clang__) + #define RESTRICT __restrict__ +#elif defined(_MSC_VER) || defined(__INTEL_COMPILER) + #define RESTRICT __restrict +#else + #error Your compiler, configuration or platform is not supported. +#endif + +static s32 lzp_encode_block(const u8 * RESTRICT in, const u8 * in_end, u8 * RESTRICT out, u8 * out_end, + s32 * RESTRICT lut, s32 mask, s32 m_len) { const u8 *ins = in, *outs = out; const u8 * out_eob = out_end - 8; const u8 * heur = in; @@ -28,7 +36,7 @@ static s32 lzp_encode_block(const u8 * restrict in, const u8 * in_end, u8 * rest s32 val = lut[idx]; lut[idx] = in - ins; if (val > 0) { - const u8 * restrict ref = ins + val; + const u8 * RESTRICT ref = ins + val; if (memcmp(in + m_len - 4, ref + m_len - 4, sizeof(u32)) == 0 && memcmp(in, ref, sizeof(u32)) == 0) { if (heur > in && *(u32 *)heur != *(u32 *)(ref + (heur - in))) goto not_found; @@ -85,7 +93,7 @@ static s32 lzp_encode_block(const u8 * restrict in, const u8 * in_end, u8 * rest return out >= out_eob ? -1 : (s32)(out - outs); } -static s32 lzp_decode_block(const u8 * restrict in, const u8 * in_end, s32 * restrict lut, u8 * restrict out, s32 hash, +static s32 lzp_decode_block(const u8 * RESTRICT in, const u8 * in_end, s32 * RESTRICT lut, u8 * RESTRICT out, s32 hash, s32 m_len) { if (in_end - in < 4) return -1; @@ -129,7 +137,7 @@ static s32 lzp_decode_block(const u8 * restrict in, const u8 * in_end, s32 * res return out - outs; } -s32 lzp_compress(const u8 * restrict in, u8 * restrict out, s32 n, s32 hash, s32 m_len, s32 * restrict lut) { +s32 lzp_compress(const u8 * RESTRICT in, u8 * RESTRICT out, s32 n, s32 hash, s32 m_len, s32 * RESTRICT lut) { if (n - m_len < 32) return -1; memset(lut, 0, sizeof(s32) * (1 << hash)); @@ -137,6 +145,6 @@ s32 lzp_compress(const u8 * restrict in, u8 * restrict out, s32 n, s32 hash, s32 return lzp_encode_block(in, in + n, out, out + n, lut, (s32)(1 << hash) - 1, m_len); } -s32 lzp_decompress(const u8 * restrict in, u8 * restrict out, s32 n, s32 hash, s32 m_len, s32 * restrict lut) { +s32 lzp_decompress(const u8 * RESTRICT in, u8 * RESTRICT out, s32 n, s32 hash, s32 m_len, s32 * RESTRICT lut) { return lzp_decode_block(in, in + n, lut, out, hash, m_len); } diff --git a/src/rle.c b/src/rle.c index b1f0340..2cb2e53 100644 --- a/src/rle.c +++ b/src/rle.c @@ -19,6 +19,14 @@ #include "rle.h" +#if defined(__GNUC__) || defined(__clang__) + #define RESTRICT __restrict__ +#elif defined(_MSC_VER) || defined(__INTEL_COMPILER) + #define RESTRICT __restrict +#else + #error Your compiler, configuration or platform is not supported. +#endif + s32 mrlec(u8 * in, s32 inlen, u8 * out) { u8 *ip = in, *in_end = in + inlen; s32 op = 0; @@ -57,7 +65,7 @@ s32 mrlec(u8 * in, s32 inlen, u8 * out) { return op; } -void mrled(u8 * restrict in, u8 * restrict out, s32 outlen) { +void mrled(u8 * RESTRICT in, u8 * RESTRICT out, s32 outlen) { s32 op = 0, ip = 0; s32 c, pc = -1;