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