]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/BrotliCompress/enc/find_match_length.h
1 /* Copyright 2010 Google Inc. All Rights Reserved.
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
7 /* Function to find maximal matching prefixes of strings. */
9 #ifndef BROTLI_ENC_FIND_MATCH_LENGTH_H_
10 #define BROTLI_ENC_FIND_MATCH_LENGTH_H_
12 #include "../common/types.h"
15 #if defined(__cplusplus) || defined(c_plusplus)
19 /* Separate implementation for little-endian 64-bit targets, for speed. */
20 #if defined(__GNUC__) && defined(_LP64) && defined(IS_LITTLE_ENDIAN)
22 static BROTLI_INLINE
size_t FindMatchLengthWithLimit(const uint8_t* s1
,
26 size_t limit2
= (limit
>> 3) + 1; /* + 1 is for pre-decrement in while */
27 while (PREDICT_TRUE(--limit2
)) {
28 if (PREDICT_FALSE(BROTLI_UNALIGNED_LOAD64(s2
) ==
29 BROTLI_UNALIGNED_LOAD64(s1
+ matched
))) {
34 BROTLI_UNALIGNED_LOAD64(s2
) ^ BROTLI_UNALIGNED_LOAD64(s1
+ matched
);
35 size_t matching_bits
= (size_t)__builtin_ctzll(x
);
36 matched
+= matching_bits
>> 3;
40 limit
= (limit
& 7) + 1; /* + 1 is for pre-decrement in while */
42 if (PREDICT_TRUE(s1
[matched
] == *s2
)) {
52 static BROTLI_INLINE
size_t FindMatchLengthWithLimit(const uint8_t* s1
,
56 const uint8_t* s2_limit
= s2
+ limit
;
57 const uint8_t* s2_ptr
= s2
;
58 /* Find out how long the match is. We loop over the data 32 bits at a
59 time until we find a 32-bit block that doesn't match; then we find
60 the first non-matching bit and use that to calculate the total
61 length of the match. */
62 while (s2_ptr
<= s2_limit
- 4 &&
63 BROTLI_UNALIGNED_LOAD32(s2_ptr
) ==
64 BROTLI_UNALIGNED_LOAD32(s1
+ matched
)) {
68 while ((s2_ptr
< s2_limit
) && (s1
[matched
] == *s2_ptr
)) {
76 #if defined(__cplusplus) || defined(c_plusplus)
80 #endif /* BROTLI_ENC_FIND_MATCH_LENGTH_H_ */