v / thirdparty / zstd / zstd_v.patch
117 lines · 110 sloc · 4.76 KB · 4333e2ddcb5c5e0927c630bc5c17bdf915a71696
Raw
1--- zstd.c 2026-01-10 14:25:18.651952689 +0100
2+++ zstd.c 2026-01-09 17:55:20.698628329 +0100
3@@ -50,6 +50,27 @@
4 /* TODO: Can't amalgamate ASM function */
5 #define ZSTD_DISABLE_ASM 1
6
7+/* >> v_patch start */
8+#if defined(__TINYC__)
9+
10+#if defined(_WIN32)
11+#undef ZSTD_MULTITHREAD
12+#define ZSTD_NO_INTRINSICS
13+#endif
14+
15+/* tcc doesn't support ARM asm */
16+#if defined(__arm__) || defined(__aarch64__)
17+#define NO_PREFETCH
18+#endif
19+
20+#if defined(__FreeBSD__) || defined(__OpenBSD__)
21+/* tcc on FreeBSD/OpenBSD define __GNUC__, but it can't work here */
22+#undef __GNUC__
23+#endif
24+
25+#endif /* __TINYC__ */
26+/* << v_patch end */
27+
28 /* Include zstd_deps.h first with all the options we need enabled. */
29 #define ZSTD_DEPS_NEED_MALLOC
30 #define ZSTD_DEPS_NEED_MATH64
31@@ -698,7 +719,7 @@
32 /* vectorization
33 * older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax,
34 * and some compilers, like Intel ICC and MCST LCC, do not support it at all. */
35-#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && !defined(__LCC__)
36+#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && !defined(__LCC__) && !defined(__TINYC__)
37 # if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
38 # define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
39 # else
40@@ -22353,7 +22374,7 @@
41 ZSTD_GEN_RECORD_FINGERPRINT(43, 8)
42
43
44-static U64 abs64(S64 s64) { return (U64)((s64 < 0) ? -s64 : s64); }
45+static U64 zstd_abs64(S64 s64) { return (U64)((s64 < 0) ? -s64 : s64); }
46
47 static U64 fpDistance(const Fingerprint* fp1, const Fingerprint* fp2, unsigned hashLog)
48 {
49@@ -22362,7 +22383,7 @@
50 assert(hashLog <= HASHLOG_MAX);
51 for (n = 0; n < ((size_t)1 << hashLog); n++) {
52 distance +=
53- abs64((S64)fp1->events[n] * (S64)fp2->nbEvents - (S64)fp2->events[n] * (S64)fp1->nbEvents);
54+ zstd_abs64((S64)fp1->events[n] * (S64)fp2->nbEvents - (S64)fp2->events[n] * (S64)fp1->nbEvents);
55 }
56 return distance;
57 }
58@@ -22482,7 +22503,7 @@
59 { U64 const distFromBegin = fpDistance(&fpstats->pastEvents, middleEvents, 8);
60 U64 const distFromEnd = fpDistance(&fpstats->newEvents, middleEvents, 8);
61 U64 const minDistance = SEGMENT_SIZE * SEGMENT_SIZE / 3;
62- if (abs64((S64)distFromBegin - (S64)distFromEnd) < minDistance)
63+ if (zstd_abs64((S64)distFromBegin - (S64)distFromEnd) < minDistance)
64 return 64 KB;
65 return (distFromBegin > distFromEnd) ? 32 KB : 96 KB;
66 }
67@@ -47318,8 +47339,9 @@
68 unsigned d;
69 } COVER_ctx_t;
70
71-#if !defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER)
72-/* C90 only offers qsort() that needs a global context. */
73+#if defined(ZSTD_USE_C90_QSORT) \
74+ || (!defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER))
75+/* Use global context for non-reentrant sort functions */
76 static COVER_ctx_t *g_coverCtx = NULL;
77 #endif
78
79@@ -47390,7 +47412,7 @@ static int COVER_cmp8(COVER_ctx_t *ctx, const void *lp, const void *rp) {
80 * Same as COVER_cmp() except ties are broken by pointer value
81 */
82 #if (defined(_WIN32) && defined(_MSC_VER)) || defined(__APPLE__)
83 static int WIN_CDECL COVER_strict_cmp(void* g_coverCtx, const void* lp, const void* rp) {
84-#elif defined(_GNU_SOURCE)
85+#elif defined(_GNU_SOURCE) && !defined(ZSTD_USE_C90_QSORT)
86 static int COVER_strict_cmp(const void *lp, const void *rp, void *g_coverCtx) {
87 #else /* C90 fallback.*/
88 static int COVER_strict_cmp(const void *lp, const void *rp) {
89@@ -47406,7 +47428,7 @@ static int COVER_strict_cmp(const void *lp, const void *rp) {
90 * Faster version for d <= 8.
91 */
92 #if (defined(_WIN32) && defined(_MSC_VER)) || defined(__APPLE__)
93 static int WIN_CDECL COVER_strict_cmp8(void* g_coverCtx, const void* lp, const void* rp) {
94-#elif defined(_GNU_SOURCE)
95+#elif defined(_GNU_SOURCE) && !defined(ZSTD_USE_C90_QSORT)
96 static int COVER_strict_cmp8(const void *lp, const void *rp, void *g_coverCtx) {
97 #else /* C90 fallback.*/
98 static int COVER_strict_cmp8(const void *lp, const void *rp) {
99
100@@ -47405,7 +47427,7 @@
101 qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
102 ctx,
103 (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
104-#elif defined(_GNU_SOURCE)
105+#elif defined(_GNU_SOURCE) && !defined(ZSTD_USE_C90_QSORT)
106 qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
107 (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
108 ctx);
109@@ -47419,7 +47441,7 @@
110 (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
111 #else /* C90 fallback.*/
112 g_coverCtx = ctx;
113- /* TODO(cavalcanti): implement a reentrant qsort() when is not available. */
114+ /* TODO(cavalcanti): implement a reentrant qsort() when _r is not available. */
115 qsort(ctx->suffix, ctx->suffixSize, sizeof(U32),
116 (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
117 #endif
118