This repository was archived by the owner on Aug 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminor-optimization.patch
More file actions
46 lines (43 loc) · 1.65 KB
/
minor-optimization.patch
File metadata and controls
46 lines (43 loc) · 1.65 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
diff --git a/src/liblzma/rangecoder/range_encoder.h b/src/liblzma/rangecoder/range_encoder.h
index d794eab..aa52424 100644
--- a/src/liblzma/rangecoder/range_encoder.h
+++ b/src/liblzma/rangecoder/range_encoder.h
@@ -128,6 +128,7 @@ rc_direct(lzma_range_encoder *rc,
static inline void
rc_flush(lzma_range_encoder *rc)
{
+ _Pragma("GCC unroll 5")
for (size_t i = 0; i < 5; ++i)
rc->symbols[rc->count++] = RC_FLUSH;
}
@@ -140,7 +141,7 @@ rc_shift_low(lzma_range_encoder *rc,
if ((uint32_t)(rc->low) < (uint32_t)(0xFF000000)
|| (uint32_t)(rc->low >> 32) != 0) {
do {
- if (*out_pos == out_size)
+ if (__builtin_expect((*out_pos == out_size), 0))
return true;
out[*out_pos] = rc->cache + (uint8_t)(rc->low >> 32);
@@ -187,7 +188,6 @@ rc_shift_low_dummy(uint64_t *low, uint64_t *cache_size, uint8_t *cache,
return false;
}
-
static inline bool
rc_encode(lzma_range_encoder *rc,
uint8_t *out, size_t *out_pos, size_t out_size)
@@ -279,7 +279,7 @@ rc_encode_dummy(const lzma_range_encoder *rc, uint64_t out_limit)
while (true) {
// Normalize
- if (range < RC_TOP_VALUE) {
+ if (__builtin_expect((range < RC_TOP_VALUE), 0)) {
if (rc_shift_low_dummy(&low, &cache_size, &cache,
&out_pos, out_limit))
return true;
@@ -331,6 +331,7 @@ rc_encode_dummy(const lzma_range_encoder *rc, uint64_t out_limit)
// Flush the last bytes. This isn't in rc->symbols[] so we do
// it after the above loop to take into account the size of
// the flushing that will be done at the end of the stream.
+ _Pragma("GCC unroll 5")
for (pos = 0; pos < 5; ++pos) {
if (rc_shift_low_dummy(&low, &cache_size,
&cache, &out_pos, out_limit))