]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/BrotliCompress/enc/hash_composite_inc.h
BaseTools: Update Brotli Compress to the latest one 1.0.6
[mirror_edk2.git] / BaseTools / Source / C / BrotliCompress / enc / hash_composite_inc.h
diff --git a/BaseTools/Source/C/BrotliCompress/enc/hash_composite_inc.h b/BaseTools/Source/C/BrotliCompress/enc/hash_composite_inc.h
new file mode 100644 (file)
index 0000000..ec3e39c
--- /dev/null
@@ -0,0 +1,133 @@
+/* NOLINT(build/header_guard) */\r
+/* Copyright 2018 Google Inc. All Rights Reserved.\r
+\r
+   Distributed under MIT license.\r
+   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r
+*/\r
+\r
+/* template parameters: FN, HASHER_A, HASHER_B */\r
+\r
+/* Composite hasher: This hasher allows to combine two other hashers, HASHER_A\r
+   and HASHER_B. */\r
+\r
+#define HashComposite HASHER()\r
+\r
+#define FN_A(X) EXPAND_CAT(X, HASHER_A)\r
+#define FN_B(X) EXPAND_CAT(X, HASHER_B)\r
+\r
+static BROTLI_INLINE size_t FN(HashTypeLength)(void) {\r
+  size_t a =  FN_A(HashTypeLength)();\r
+  size_t b =  FN_B(HashTypeLength)();\r
+  return a > b ? a : b;\r
+}\r
+\r
+static BROTLI_INLINE size_t FN(StoreLookahead)(void) {\r
+  size_t a =  FN_A(StoreLookahead)();\r
+  size_t b =  FN_B(StoreLookahead)();\r
+  return a > b ? a : b;\r
+}\r
+\r
+typedef struct HashComposite {\r
+  HasherHandle ha;\r
+  HasherHandle hb;\r
+  const BrotliEncoderParams* params;\r
+} HashComposite;\r
+\r
+static BROTLI_INLINE HashComposite* FN(Self)(HasherHandle handle) {\r
+  return (HashComposite*)&(GetHasherCommon(handle)[1]);\r
+}\r
+\r
+static void FN(Initialize)(\r
+    HasherHandle handle, const BrotliEncoderParams* params) {\r
+  HashComposite* self = FN(Self)(handle);\r
+  self->ha = 0;\r
+  self->hb = 0;\r
+  self->params = params;\r
+  /* TODO: Initialize of the hashers is defered to Prepare (and params\r
+     remembered here) because we don't get the one_shot and input_size params\r
+     here that are needed to know the memory size of them. Instead provide\r
+     those params to all hashers FN(Initialize) */\r
+}\r
+\r
+static void FN(Prepare)(HasherHandle handle, BROTLI_BOOL one_shot,\r
+    size_t input_size, const uint8_t* data) {\r
+  HashComposite* self = FN(Self)(handle);\r
+  if (!self->ha) {\r
+    HasherCommon* common_a;\r
+    HasherCommon* common_b;\r
+\r
+    self->ha = handle + sizeof(HasherCommon) + sizeof(HashComposite);\r
+    common_a = (HasherCommon*)self->ha;\r
+    common_a->params = self->params->hasher;\r
+    common_a->is_prepared_ = BROTLI_FALSE;\r
+    common_a->dict_num_lookups = 0;\r
+    common_a->dict_num_matches = 0;\r
+    FN_A(Initialize)(self->ha, self->params);\r
+\r
+    self->hb = self->ha + sizeof(HasherCommon) + FN_A(HashMemAllocInBytes)(\r
+        self->params, one_shot, input_size);\r
+    common_b = (HasherCommon*)self->hb;\r
+    common_b->params = self->params->hasher;\r
+    common_b->is_prepared_ = BROTLI_FALSE;\r
+    common_b->dict_num_lookups = 0;\r
+    common_b->dict_num_matches = 0;\r
+    FN_B(Initialize)(self->hb, self->params);\r
+  }\r
+  FN_A(Prepare)(self->ha, one_shot, input_size, data);\r
+  FN_B(Prepare)(self->hb, one_shot, input_size, data);\r
+}\r
+\r
+static BROTLI_INLINE size_t FN(HashMemAllocInBytes)(\r
+    const BrotliEncoderParams* params, BROTLI_BOOL one_shot,\r
+    size_t input_size) {\r
+  return sizeof(HashComposite) + 2 * sizeof(HasherCommon) +\r
+      FN_A(HashMemAllocInBytes)(params, one_shot, input_size) +\r
+      FN_B(HashMemAllocInBytes)(params, one_shot, input_size);\r
+}\r
+\r
+static BROTLI_INLINE void FN(Store)(HasherHandle BROTLI_RESTRICT handle,\r
+    const uint8_t* BROTLI_RESTRICT data, const size_t mask, const size_t ix) {\r
+  HashComposite* self = FN(Self)(handle);\r
+  FN_A(Store)(self->ha, data, mask, ix);\r
+  FN_B(Store)(self->hb, data, mask, ix);\r
+}\r
+\r
+static BROTLI_INLINE void FN(StoreRange)(HasherHandle handle,\r
+    const uint8_t* data, const size_t mask, const size_t ix_start,\r
+    const size_t ix_end) {\r
+  HashComposite* self = FN(Self)(handle);\r
+  FN_A(StoreRange)(self->ha, data, mask, ix_start, ix_end);\r
+  FN_B(StoreRange)(self->hb, data, mask, ix_start, ix_end);\r
+}\r
+\r
+static BROTLI_INLINE void FN(StitchToPreviousBlock)(HasherHandle handle,\r
+    size_t num_bytes, size_t position, const uint8_t* ringbuffer,\r
+    size_t ring_buffer_mask) {\r
+  HashComposite* self = FN(Self)(handle);\r
+  FN_A(StitchToPreviousBlock)(self->ha, num_bytes, position, ringbuffer,\r
+      ring_buffer_mask);\r
+  FN_B(StitchToPreviousBlock)(self->hb, num_bytes, position, ringbuffer,\r
+      ring_buffer_mask);\r
+}\r
+\r
+static BROTLI_INLINE void FN(PrepareDistanceCache)(\r
+    HasherHandle handle, int* BROTLI_RESTRICT distance_cache) {\r
+  HashComposite* self = FN(Self)(handle);\r
+  FN_A(PrepareDistanceCache)(self->ha, distance_cache);\r
+  FN_B(PrepareDistanceCache)(self->hb, distance_cache);\r
+}\r
+\r
+static BROTLI_INLINE void FN(FindLongestMatch)(HasherHandle handle,\r
+    const BrotliEncoderDictionary* dictionary,\r
+    const uint8_t* BROTLI_RESTRICT data, const size_t ring_buffer_mask,\r
+    const int* BROTLI_RESTRICT distance_cache, const size_t cur_ix,\r
+    const size_t max_length, const size_t max_backward, const size_t gap,\r
+    const size_t max_distance, HasherSearchResult* BROTLI_RESTRICT out) {\r
+  HashComposite* self = FN(Self)(handle);\r
+  FN_A(FindLongestMatch)(self->ha, dictionary, data, ring_buffer_mask,\r
+      distance_cache, cur_ix, max_length, max_backward, gap, max_distance, out);\r
+  FN_B(FindLongestMatch)(self->hb, dictionary, data, ring_buffer_mask,\r
+      distance_cache, cur_ix, max_length, max_backward, gap, max_distance, out);\r
+}\r
+\r
+#undef HashComposite\r