Skip to content

Commit

Permalink
Use a hash table header and SIMD to speed up hash table operations (s…
Browse files Browse the repository at this point in the history
…imilar to [Swiss Tables](https://abseil.io/about/design/swisstables)).

PiperOrigin-RevId: 632238409
  • Loading branch information
Brotli authored and Copybara-Service committed May 9, 2024
1 parent bb809ac commit 0438830
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 729 deletions.
29 changes: 0 additions & 29 deletions c/common/platform.h
Expand Up @@ -282,11 +282,6 @@ static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
memcpy(&t, p, sizeof t);
return t;
}
static BROTLI_INLINE size_t BrotliUnalignedReadSizeT(const void* p) {
size_t t;
memcpy(&t, p, sizeof t);
return t;
}
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
memcpy(p, &v, sizeof v);
}
Expand Down Expand Up @@ -494,23 +489,6 @@ BROTLI_COMMON_API void* BrotliDefaultAllocFunc(void* opaque, size_t size);
/* Default brotli_free_func */
BROTLI_COMMON_API void BrotliDefaultFreeFunc(void* opaque, void* address);

/* Circular logical rotates. */
static BROTLI_INLINE uint16_t BrotliRotateRight16(uint16_t const value,
size_t count) {
count &= 0x0F; /* for fickle pattern recognition */
return (value >> count) | (uint16_t)(value << ((0U - count) & 0x0F));
}
static BROTLI_INLINE uint32_t BrotliRotateRight32(uint32_t const value,
size_t count) {
count &= 0x1F; /* for fickle pattern recognition */
return (value >> count) | (uint32_t)(value << ((0U - count) & 0x1F));
}
static BROTLI_INLINE uint64_t BrotliRotateRight64(uint64_t const value,
size_t count) {
count &= 0x3F; /* for fickle pattern recognition */
return (value >> count) | (uint64_t)(value << ((0U - count) & 0x3F));
}

BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
BROTLI_UNUSED(&BrotliSuppressUnusedFunctions);
BROTLI_UNUSED(&BrotliUnalignedRead16);
Expand Down Expand Up @@ -556,13 +534,6 @@ BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
# define PREFETCH_L1(ptr) do { (void)(ptr); } while (0) /* disabled */
# define PREFETCH_L2(ptr) do { (void)(ptr); } while (0) /* disabled */
#endif

/* The SIMD matchers are only faster at certain quality levels. */
#if defined(_M_X64) && defined(BROTLI_TZCNT64)
#define BROTLI_MAX_SIMD_QUALITY 7
#elif defined(BROTLI_TZCNT64)
#define BROTLI_MAX_SIMD_QUALITY 6
#endif
}

#endif /* BROTLI_COMMON_PLATFORM_H_ */
26 changes: 0 additions & 26 deletions c/enc/backward_references.c
Expand Up @@ -116,18 +116,6 @@ static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance,
#include "backward_references_inc.h"
#undef HASHER

#if defined(BROTLI_MAX_SIMD_QUALITY)
#define HASHER() H58
/* NOLINTNEXTLINE(build/include) */
#include "backward_references_inc.h"
#undef HASHER

#define HASHER() H68
/* NOLINTNEXTLINE(build/include) */
#include "backward_references_inc.h"
#undef HASHER
#endif

#undef ENABLE_COMPOUND_DICTIONARY
#undef PREFIX
#define PREFIX() D
Expand Down Expand Up @@ -161,16 +149,6 @@ static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance,
/* NOLINTNEXTLINE(build/include) */
#include "backward_references_inc.h"
#undef HASHER
#if defined(BROTLI_MAX_SIMD_QUALITY)
#define HASHER() H58
/* NOLINTNEXTLINE(build/include) */
#include "backward_references_inc.h"
#undef HASHER
#define HASHER() H68
/* NOLINTNEXTLINE(build/include) */
#include "backward_references_inc.h"
#undef HASHER
#endif

#undef ENABLE_COMPOUND_DICTIONARY
#undef PREFIX
Expand All @@ -196,10 +174,6 @@ void BrotliCreateBackwardReferences(size_t num_bytes,
return;
CASE_(5)
CASE_(6)
#if defined(BROTLI_MAX_SIMD_QUALITY)
CASE_(58)
CASE_(68)
#endif
CASE_(40)
CASE_(41)
CASE_(42)
Expand Down
19 changes: 1 addition & 18 deletions c/enc/hash.h
Expand Up @@ -22,7 +22,6 @@
#include "encoder_dict.h"
#include "fast_log.h"
#include "find_match_length.h"
#include "matching_tag_mask.h"
#include "memory.h"
#include "quality.h"
#include "static_dict.h"
Expand Down Expand Up @@ -298,16 +297,6 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) {
#include "hash_longest_match64_inc.h" /* NOLINT(build/include) */
#undef HASHER

#if defined(BROTLI_MAX_SIMD_QUALITY)
#define HASHER() H58
#include "hash_longest_match_simd_inc.h" /* NOLINT(build/include) */
#undef HASHER

#define HASHER() H68
#include "hash_longest_match64_simd_inc.h" /* NOLINT(build/include) */
#undef HASHER
#endif

#define BUCKET_BITS 15

#define NUM_LAST_DISTANCES_TO_CHECK 4
Expand Down Expand Up @@ -399,13 +388,7 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) {
#undef CAT
#undef EXPAND_CAT

#if defined(BROTLI_MAX_SIMD_QUALITY)
#define FOR_SIMPLE_HASHERS(H) \
H(2) H(3) H(4) H(5) H(6) H(40) H(41) H(42) H(54) H(58) H(68)
#else
#define FOR_SIMPLE_HASHERS(H) \
H(2) H(3) H(4) H(5) H(6) H(40) H(41) H(42) H(54)
#endif
#define FOR_SIMPLE_HASHERS(H) H(2) H(3) H(4) H(5) H(6) H(40) H(41) H(42) H(54)
#define FOR_COMPOSITE_HASHERS(H) H(35) H(55) H(65)
#define FOR_GENERIC_HASHERS(H) FOR_SIMPLE_HASHERS(H) FOR_COMPOSITE_HASHERS(H)
#define FOR_ALL_HASHERS(H) FOR_GENERIC_HASHERS(H) H(10)
Expand Down

0 comments on commit 0438830

Please sign in to comment.