:: commit 6ce36b8aebfe93b3e6a91e75b17dcab255c1211e

Kamila Szewczyk <kspalaiologos@gmail.com> — 2022-08-04 08:11

parents: 1f0d3c0e77

`restrict` patch

diff --git a/include/common.h b/include/common.h
index ae94041..04b5649 100644
--- a/include/common.h
+++ b/include/common.h
@@ -52,4 +52,13 @@ static void write_neutral_s32(u8 * data, s32 value) {
     #define PUBLIC_API
 #endif
 
+#if defined(__GNUC__) || defined(__clang__)
+    #define RESTRICT __restrict__
+#elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
+    #define RESTRICT __restrict
+#else
+    #define RESTRICT restrict
+    #warning Your compiler, configuration or platform might not be supported.
+#endif
+
 #endif
diff --git a/src/cm.c b/src/cm.c
index 3a14fab..d669922 100644
--- a/src/cm.c
+++ b/src/cm.c
@@ -1,5 +1,6 @@
 
 #include "cm.h"
+#include "common.h"
 
 #if defined(__has_builtin)
     #if __has_builtin(__builtin_prefetch)
diff --git a/src/crc32.c b/src/crc32.c
index 856fcd4..d455a44 100644
--- a/src/crc32.c
+++ b/src/crc32.c
@@ -18,6 +18,7 @@
  */
 
 #include "crc32.h"
+#include "common.h"
 
 static const u32 crc32Table[256] = {
     0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, 0x8AD958CFL,
@@ -51,7 +52,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/libsais.c b/src/libsais.c
index 5460502..04d45e8 100644
--- a/src/libsais.c
+++ b/src/libsais.c
@@ -22,6 +22,7 @@ Please see the file LICENSE for full copyright information.
 --*/
 
 #include "libsais.h"
+#include "common.h"
 
 #include <limits.h>
 #include <stddef.h>
@@ -84,14 +85,6 @@ typedef struct LIBSAIS_UNBWT_CONTEXT {
     fast_sint_t threads;
 } LIBSAIS_UNBWT_CONTEXT;
 
-#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
-
 #if defined(__has_builtin)
     #if __has_builtin(__builtin_prefetch)
         #define HAS_BUILTIN_PREFECTCH
diff --git a/src/lzp.c b/src/lzp.c
index c19580d..ccb0a8b 100644
--- a/src/lzp.c
+++ b/src/lzp.c
@@ -11,8 +11,8 @@
 
 #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) {
+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 +28,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 +85,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 +129,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 +137,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..ea1cfd1 100644
--- a/src/rle.c
+++ b/src/rle.c
@@ -18,6 +18,7 @@
  */
 
 #include "rle.h"
+#include "common.h"
 
 s32 mrlec(u8 * in, s32 inlen, u8 * out) {
     u8 *ip = in, *in_end = in + inlen;
@@ -57,7 +58,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;
tab: 248 wrap: offon