--- /dev/null
+/* Copyright 2013 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
+/* Functions for encoding of integers into prefix codes the amount of extra\r
+ bits, and the actual values of the extra bits. */\r
+\r
+#ifndef BROTLI_ENC_PREFIX_H_\r
+#define BROTLI_ENC_PREFIX_H_\r
+\r
+#include "../common/constants.h"\r
+#include "../common/port.h"\r
+#include "../common/types.h"\r
+#include "./fast_log.h"\r
+\r
+#if defined(__cplusplus) || defined(c_plusplus)\r
+extern "C" {\r
+#endif\r
+\r
+static BROTLI_INLINE void PrefixEncodeCopyDistance(size_t distance_code,\r
+ size_t num_direct_codes,\r
+ size_t postfix_bits,\r
+ uint16_t* code,\r
+ uint32_t* extra_bits) {\r
+ if (distance_code < BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes) {\r
+ *code = (uint16_t)distance_code;\r
+ *extra_bits = 0;\r
+ return;\r
+ } else {\r
+ size_t dist = ((size_t)1 << (postfix_bits + 2u)) +\r
+ (distance_code - BROTLI_NUM_DISTANCE_SHORT_CODES - num_direct_codes);\r
+ size_t bucket = Log2FloorNonZero(dist) - 1;\r
+ size_t postfix_mask = (1u << postfix_bits) - 1;\r
+ size_t postfix = dist & postfix_mask;\r
+ size_t prefix = (dist >> bucket) & 1;\r
+ size_t offset = (2 + prefix) << bucket;\r
+ size_t nbits = bucket - postfix_bits;\r
+ *code = (uint16_t)(\r
+ (BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes +\r
+ ((2 * (nbits - 1) + prefix) << postfix_bits) + postfix));\r
+ *extra_bits = (uint32_t)(\r
+ (nbits << 24) | ((dist - offset) >> postfix_bits));\r
+ }\r
+}\r
+\r
+#if defined(__cplusplus) || defined(c_plusplus)\r
+} /* extern "C" */\r
+#endif\r
+\r
+#endif /* BROTLI_ENC_PREFIX_H_ */\r