isomorfeus-ferret 0.12.4 → 0.12.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +612 -612
  3. data/README.md +77 -48
  4. data/ext/isomorfeus_ferret_ext/bm_hash.c +9 -6
  5. data/ext/isomorfeus_ferret_ext/bm_micro_string.c +4 -2
  6. data/ext/isomorfeus_ferret_ext/brotli_common_constants.c +15 -0
  7. data/ext/isomorfeus_ferret_ext/brotli_common_constants.h +200 -0
  8. data/ext/isomorfeus_ferret_ext/brotli_common_context.c +156 -0
  9. data/ext/isomorfeus_ferret_ext/brotli_common_context.h +113 -0
  10. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +5914 -0
  11. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.h +64 -0
  12. data/ext/isomorfeus_ferret_ext/brotli_common_platform.c +22 -0
  13. data/ext/isomorfeus_ferret_ext/brotli_common_platform.h +594 -0
  14. data/ext/isomorfeus_ferret_ext/brotli_common_transform.c +291 -0
  15. data/ext/isomorfeus_ferret_ext/brotli_common_transform.h +85 -0
  16. data/ext/isomorfeus_ferret_ext/brotli_common_version.h +26 -0
  17. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.c +76 -0
  18. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.h +351 -0
  19. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +2608 -0
  20. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.c +339 -0
  21. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.h +121 -0
  22. data/ext/isomorfeus_ferret_ext/brotli_dec_prefix.h +732 -0
  23. data/ext/isomorfeus_ferret_ext/brotli_dec_state.c +159 -0
  24. data/ext/isomorfeus_ferret_ext/brotli_dec_state.h +365 -0
  25. data/ext/isomorfeus_ferret_ext/brotli_decode.h +344 -0
  26. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.c +145 -0
  27. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.h +39 -0
  28. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.c +843 -0
  29. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.h +95 -0
  30. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_inc.h +163 -0
  31. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.c +35 -0
  32. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.h +63 -0
  33. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost_inc.h +127 -0
  34. data/ext/isomorfeus_ferret_ext/brotli_enc_block_encoder_inc.h +34 -0
  35. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.c +194 -0
  36. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.h +51 -0
  37. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter_inc.h +440 -0
  38. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.c +1314 -0
  39. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.h +84 -0
  40. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.c +56 -0
  41. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.h +48 -0
  42. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster_inc.h +320 -0
  43. data/ext/isomorfeus_ferret_ext/brotli_enc_command.c +28 -0
  44. data/ext/isomorfeus_ferret_ext/brotli_enc_command.h +190 -0
  45. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.c +790 -0
  46. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.h +61 -0
  47. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.c +645 -0
  48. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.h +54 -0
  49. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.c +1846 -0
  50. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.h +25 -0
  51. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +1927 -0
  52. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.c +33 -0
  53. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.h +43 -0
  54. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.c +503 -0
  55. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.h +122 -0
  56. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode_static.h +539 -0
  57. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.c +105 -0
  58. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.h +66 -0
  59. data/ext/isomorfeus_ferret_ext/brotli_enc_find_match_length.h +79 -0
  60. data/ext/isomorfeus_ferret_ext/brotli_enc_hash.h +488 -0
  61. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_composite_inc.h +125 -0
  62. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_forgetful_chain_inc.h +293 -0
  63. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match64_inc.h +267 -0
  64. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_inc.h +262 -0
  65. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_quickly_inc.h +266 -0
  66. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_rolling_inc.h +212 -0
  67. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_to_binary_tree_inc.h +329 -0
  68. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.c +100 -0
  69. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.h +63 -0
  70. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram_inc.h +51 -0
  71. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.c +175 -0
  72. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.h +30 -0
  73. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.c +170 -0
  74. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.h +114 -0
  75. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.c +663 -0
  76. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.h +105 -0
  77. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock_inc.h +183 -0
  78. data/ext/isomorfeus_ferret_ext/brotli_enc_params.h +46 -0
  79. data/ext/isomorfeus_ferret_ext/brotli_enc_prefix.h +53 -0
  80. data/ext/isomorfeus_ferret_ext/brotli_enc_quality.h +165 -0
  81. data/ext/isomorfeus_ferret_ext/brotli_enc_ringbuffer.h +167 -0
  82. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.c +486 -0
  83. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.h +40 -0
  84. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict_lut.h +5864 -0
  85. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.c +85 -0
  86. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.h +32 -0
  87. data/ext/isomorfeus_ferret_ext/brotli_enc_write_bits.h +87 -0
  88. data/ext/isomorfeus_ferret_ext/brotli_encode.h +448 -0
  89. data/ext/isomorfeus_ferret_ext/brotli_port.h +288 -0
  90. data/ext/isomorfeus_ferret_ext/brotli_types.h +83 -0
  91. data/ext/isomorfeus_ferret_ext/frb_index.c +35 -4
  92. data/ext/isomorfeus_ferret_ext/frb_store.c +34 -5
  93. data/ext/isomorfeus_ferret_ext/frt_document.h +1 -0
  94. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +1 -0
  95. data/ext/isomorfeus_ferret_ext/frt_index.c +174 -25
  96. data/ext/isomorfeus_ferret_ext/frt_index.h +6 -3
  97. data/ext/isomorfeus_ferret_ext/frt_posh.h +11 -19
  98. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +1844 -1911
  99. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +12 -15
  100. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +1 -0
  101. data/ext/isomorfeus_ferret_ext/frt_scanner.c +1 -0
  102. data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +1 -0
  103. data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +1 -0
  104. data/ext/isomorfeus_ferret_ext/frt_search.h +1 -1
  105. data/ext/isomorfeus_ferret_ext/libstemmer.c +14 -11
  106. data/ext/isomorfeus_ferret_ext/libstemmer.h +4 -9
  107. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.c +1167 -0
  108. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.h +6 -0
  109. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.c +1433 -0
  110. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.h +6 -0
  111. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +120 -143
  112. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +1 -2
  113. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +217 -237
  114. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +1 -1
  115. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +377 -432
  116. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +1 -1
  117. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +298 -342
  118. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +1 -2
  119. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +530 -524
  120. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +1 -1
  121. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +201 -214
  122. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +1 -1
  123. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1 -1
  124. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.c +394 -0
  125. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.h +6 -0
  126. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.c +457 -0
  127. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.h +6 -0
  128. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +396 -439
  129. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +1 -1
  130. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +104 -128
  131. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +1 -1
  132. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +242 -273
  133. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +1 -1
  134. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +406 -461
  135. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +1 -2
  136. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +405 -456
  137. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +1 -1
  138. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +108 -126
  139. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +1 -1
  140. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.c +849 -0
  141. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.h +6 -0
  142. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +373 -405
  143. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +1 -1
  144. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +288 -305
  145. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +1 -1
  146. data/ext/isomorfeus_ferret_ext/stem_UTF_8_arabic.c +1651 -0
  147. data/ext/isomorfeus_ferret_ext/stem_UTF_8_arabic.h +6 -0
  148. data/ext/isomorfeus_ferret_ext/stem_UTF_8_armenian.c +546 -0
  149. data/ext/isomorfeus_ferret_ext/stem_UTF_8_armenian.h +6 -0
  150. data/ext/isomorfeus_ferret_ext/stem_UTF_8_basque.c +1171 -0
  151. data/ext/isomorfeus_ferret_ext/stem_UTF_8_basque.h +6 -0
  152. data/ext/isomorfeus_ferret_ext/stem_UTF_8_catalan.c +1436 -0
  153. data/ext/isomorfeus_ferret_ext/stem_UTF_8_catalan.h +6 -0
  154. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +121 -141
  155. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +1 -1
  156. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +221 -241
  157. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +1 -1
  158. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +381 -431
  159. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +1 -1
  160. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +300 -345
  161. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +1 -1
  162. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +518 -511
  163. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +1 -1
  164. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +201 -209
  165. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +1 -1
  166. data/ext/isomorfeus_ferret_ext/stem_UTF_8_greek.c +3660 -0
  167. data/ext/isomorfeus_ferret_ext/stem_UTF_8_greek.h +6 -0
  168. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hindi.c +309 -0
  169. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hindi.h +6 -0
  170. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +306 -671
  171. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +1 -1
  172. data/ext/isomorfeus_ferret_ext/stem_UTF_8_indonesian.c +394 -0
  173. data/ext/isomorfeus_ferret_ext/stem_UTF_8_indonesian.h +6 -0
  174. data/ext/isomorfeus_ferret_ext/stem_UTF_8_irish.c +457 -0
  175. data/ext/isomorfeus_ferret_ext/stem_UTF_8_irish.h +6 -0
  176. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +400 -442
  177. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +1 -1
  178. data/ext/isomorfeus_ferret_ext/stem_UTF_8_lithuanian.c +824 -0
  179. data/ext/isomorfeus_ferret_ext/stem_UTF_8_lithuanian.h +6 -0
  180. data/ext/isomorfeus_ferret_ext/stem_UTF_8_nepali.c +408 -0
  181. data/ext/isomorfeus_ferret_ext/stem_UTF_8_nepali.h +6 -0
  182. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +105 -127
  183. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +1 -1
  184. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +245 -276
  185. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +1 -1
  186. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +409 -464
  187. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +1 -1
  188. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +376 -408
  189. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +1 -1
  190. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +272 -287
  191. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +1 -1
  192. data/ext/isomorfeus_ferret_ext/stem_UTF_8_serbian.c +6530 -0
  193. data/ext/isomorfeus_ferret_ext/stem_UTF_8_serbian.h +6 -0
  194. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +407 -458
  195. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +1 -1
  196. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +110 -125
  197. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +1 -1
  198. data/ext/isomorfeus_ferret_ext/stem_UTF_8_tamil.c +1865 -0
  199. data/ext/isomorfeus_ferret_ext/stem_UTF_8_tamil.h +6 -0
  200. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +698 -806
  201. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +1 -1
  202. data/ext/isomorfeus_ferret_ext/stem_UTF_8_yiddish.c +1220 -0
  203. data/ext/isomorfeus_ferret_ext/stem_UTF_8_yiddish.h +6 -0
  204. data/ext/isomorfeus_ferret_ext/stem_api.c +1 -9
  205. data/ext/isomorfeus_ferret_ext/stem_api.h +1 -3
  206. data/ext/isomorfeus_ferret_ext/stem_header.h +30 -26
  207. data/ext/isomorfeus_ferret_ext/stem_modules.h +113 -26
  208. data/ext/isomorfeus_ferret_ext/stem_modules.txt +18 -5
  209. data/ext/isomorfeus_ferret_ext/stem_utilities.c +167 -132
  210. data/ext/isomorfeus_ferret_ext/test.c +7 -1
  211. data/ext/isomorfeus_ferret_ext/test_fields.c +57 -45
  212. data/ext/isomorfeus_ferret_ext/test_index.c +4 -1
  213. data/ext/isomorfeus_ferret_ext/test_search.c +0 -1
  214. data/lib/isomorfeus/ferret/version.rb +1 -1
  215. metadata +125 -5
  216. data/ext/isomorfeus_ferret_ext/q_parser.y +0 -1366
@@ -0,0 +1,64 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Collection of static dictionary words. */
8
+
9
+ #ifndef BROTLI_COMMON_DICTIONARY_H_
10
+ #define BROTLI_COMMON_DICTIONARY_H_
11
+
12
+ #include "brotli_port.h"
13
+ #include "brotli_types.h"
14
+
15
+ #if defined(__cplusplus) || defined(c_plusplus)
16
+ extern "C" {
17
+ #endif
18
+
19
+ typedef struct BrotliDictionary {
20
+ /**
21
+ * Number of bits to encode index of dictionary word in a bucket.
22
+ *
23
+ * Specification: Appendix A. Static Dictionary Data
24
+ *
25
+ * Words in a dictionary are bucketed by length.
26
+ * @c 0 means that there are no words of a given length.
27
+ * Dictionary consists of words with length of [4..24] bytes.
28
+ * Values at [0..3] and [25..31] indices should not be addressed.
29
+ */
30
+ uint8_t size_bits_by_length[32];
31
+
32
+ /* assert(offset[i + 1] == offset[i] + (bits[i] ? (i << bits[i]) : 0)) */
33
+ uint32_t offsets_by_length[32];
34
+
35
+ /* assert(data_size == offsets_by_length[31]) */
36
+ size_t data_size;
37
+
38
+ /* Data array is not bound, and should obey to size_bits_by_length values.
39
+ Specified size matches default (RFC 7932) dictionary. Its size is
40
+ defined by data_size */
41
+ const uint8_t* data;
42
+ } BrotliDictionary;
43
+
44
+ BROTLI_COMMON_API const BrotliDictionary* BrotliGetDictionary(void);
45
+
46
+ /**
47
+ * Sets dictionary data.
48
+ *
49
+ * When dictionary data is already set / present, this method is no-op.
50
+ *
51
+ * Dictionary data MUST be provided before BrotliGetDictionary is invoked.
52
+ * This method is used ONLY in multi-client environment (e.g. C + Java),
53
+ * to reduce storage by sharing single dictionary between implementations.
54
+ */
55
+ BROTLI_COMMON_API void BrotliSetDictionaryData(const uint8_t* data);
56
+
57
+ #define BROTLI_MIN_DICTIONARY_WORD_LENGTH 4
58
+ #define BROTLI_MAX_DICTIONARY_WORD_LENGTH 24
59
+
60
+ #if defined(__cplusplus) || defined(c_plusplus)
61
+ } /* extern "C" */
62
+ #endif
63
+
64
+ #endif /* BROTLI_COMMON_DICTIONARY_H_ */
@@ -0,0 +1,22 @@
1
+ /* Copyright 2016 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ #include <stdlib.h>
8
+
9
+ #include "brotli_common_platform.h"
10
+ #include "brotli_types.h"
11
+
12
+ /* Default brotli_alloc_func */
13
+ void* BrotliDefaultAllocFunc(void* opaque, size_t size) {
14
+ BROTLI_UNUSED(opaque);
15
+ return malloc(size);
16
+ }
17
+
18
+ /* Default brotli_free_func */
19
+ void BrotliDefaultFreeFunc(void* opaque, void* address) {
20
+ BROTLI_UNUSED(opaque);
21
+ free(address);
22
+ }
@@ -0,0 +1,594 @@
1
+ /* Copyright 2016 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Macros for compiler / platform specific features and build options.
8
+
9
+ Build options are:
10
+ * BROTLI_BUILD_32_BIT disables 64-bit optimizations
11
+ * BROTLI_BUILD_64_BIT forces to use 64-bit optimizations
12
+ * BROTLI_BUILD_BIG_ENDIAN forces to use big-endian optimizations
13
+ * BROTLI_BUILD_ENDIAN_NEUTRAL disables endian-aware optimizations
14
+ * BROTLI_BUILD_LITTLE_ENDIAN forces to use little-endian optimizations
15
+ * BROTLI_BUILD_PORTABLE disables dangerous optimizations, like unaligned
16
+ read and overlapping memcpy; this reduces decompression speed by 5%
17
+ * BROTLI_BUILD_NO_RBIT disables "rbit" optimization for ARM CPUs
18
+ * BROTLI_DEBUG dumps file name and line number when decoder detects stream
19
+ or memory error
20
+ * BROTLI_ENABLE_LOG enables asserts and dumps various state information
21
+ */
22
+
23
+ #ifndef BROTLI_COMMON_PLATFORM_H_
24
+ #define BROTLI_COMMON_PLATFORM_H_
25
+
26
+ #include <string.h> /* memcpy */
27
+
28
+ #include "brotli_port.h"
29
+ #include "brotli_types.h"
30
+
31
+ #if defined(OS_LINUX) || defined(OS_CYGWIN) || defined(__EMSCRIPTEN__)
32
+ #include <endian.h>
33
+ #elif defined(OS_FREEBSD)
34
+ #include <machine/endian.h>
35
+ #elif defined(OS_MACOSX)
36
+ #include <machine/endian.h>
37
+ /* Let's try and follow the Linux convention */
38
+ #define BROTLI_X_BYTE_ORDER BYTE_ORDER
39
+ #define BROTLI_X_LITTLE_ENDIAN LITTLE_ENDIAN
40
+ #define BROTLI_X_BIG_ENDIAN BIG_ENDIAN
41
+ #endif
42
+
43
+ #if BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
44
+ #include <intrin.h>
45
+ #endif
46
+
47
+ #if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
48
+ #include <assert.h>
49
+ #include <stdio.h>
50
+ #endif
51
+
52
+ /* The following macros were borrowed from https://github.com/nemequ/hedley
53
+ * with permission of original author - Evan Nemerson <evan@nemerson.com> */
54
+
55
+ /* >>> >>> >>> hedley macros */
56
+
57
+ /* Define "BROTLI_PREDICT_TRUE" and "BROTLI_PREDICT_FALSE" macros for capable
58
+ compilers.
59
+
60
+ To apply compiler hint, enclose the branching condition into macros, like this:
61
+
62
+ if (BROTLI_PREDICT_TRUE(zero == 0)) {
63
+ // main execution path
64
+ } else {
65
+ // compiler should place this code outside of main execution path
66
+ }
67
+
68
+ OR:
69
+
70
+ if (BROTLI_PREDICT_FALSE(something_rare_or_unexpected_happens)) {
71
+ // compiler should place this code outside of main execution path
72
+ }
73
+
74
+ */
75
+ #if BROTLI_GNUC_HAS_BUILTIN(__builtin_expect, 3, 0, 0) || \
76
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
77
+ BROTLI_SUNPRO_VERSION_CHECK(5, 15, 0) || \
78
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
79
+ BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
80
+ BROTLI_TI_VERSION_CHECK(7, 3, 0) || \
81
+ BROTLI_TINYC_VERSION_CHECK(0, 9, 27)
82
+ #define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
83
+ #define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
84
+ #else
85
+ #define BROTLI_PREDICT_FALSE(x) (x)
86
+ #define BROTLI_PREDICT_TRUE(x) (x)
87
+ #endif
88
+
89
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
90
+ !defined(__cplusplus)
91
+ #define BROTLI_RESTRICT restrict
92
+ #elif BROTLI_GNUC_VERSION_CHECK(3, 1, 0) || \
93
+ BROTLI_MSVC_VERSION_CHECK(14, 0, 0) || \
94
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
95
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
96
+ BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
97
+ BROTLI_PGI_VERSION_CHECK(17, 10, 0) || \
98
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
99
+ BROTLI_IAR_VERSION_CHECK(8, 0, 0) || \
100
+ (BROTLI_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus))
101
+ #define BROTLI_RESTRICT __restrict
102
+ #elif BROTLI_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus)
103
+ #define BROTLI_RESTRICT _Restrict
104
+ #else
105
+ #define BROTLI_RESTRICT
106
+ #endif
107
+
108
+ #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
109
+ (defined(__cplusplus) && (__cplusplus >= 199711L))
110
+ #define BROTLI_MAYBE_INLINE inline
111
+ #elif defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__) || \
112
+ BROTLI_ARM_VERSION_CHECK(6, 2, 0)
113
+ #define BROTLI_MAYBE_INLINE __inline__
114
+ #elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0) || \
115
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || BROTLI_TI_VERSION_CHECK(8, 0, 0)
116
+ #define BROTLI_MAYBE_INLINE __inline
117
+ #else
118
+ #define BROTLI_MAYBE_INLINE
119
+ #endif
120
+
121
+ #if BROTLI_GNUC_HAS_ATTRIBUTE(always_inline, 4, 0, 0) || \
122
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
123
+ BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
124
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
125
+ BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
126
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
127
+ (BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
128
+ #define BROTLI_INLINE BROTLI_MAYBE_INLINE __attribute__((__always_inline__))
129
+ #elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
130
+ #define BROTLI_INLINE BROTLI_MAYBE_INLINE __forceinline
131
+ #elif BROTLI_TI_VERSION_CHECK(7, 0, 0) && defined(__cplusplus)
132
+ #define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
133
+ #elif BROTLI_IAR_VERSION_CHECK(8, 0, 0)
134
+ #define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("inline=forced")
135
+ #else
136
+ #define BROTLI_INLINE BROTLI_MAYBE_INLINE
137
+ #endif
138
+
139
+ #if BROTLI_GNUC_HAS_ATTRIBUTE(noinline, 4, 0, 0) || \
140
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
141
+ BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
142
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
143
+ BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
144
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
145
+ (BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
146
+ #define BROTLI_NOINLINE __attribute__((__noinline__))
147
+ #elif BROTLI_MSVC_VERSION_CHECK(13, 10, 0)
148
+ #define BROTLI_NOINLINE __declspec(noinline)
149
+ #elif BROTLI_PGI_VERSION_CHECK(10, 2, 0)
150
+ #define BROTLI_NOINLINE _Pragma("noinline")
151
+ #elif BROTLI_TI_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
152
+ #define BROTLI_NOINLINE _Pragma("FUNC_CANNOT_INLINE;")
153
+ #elif BROTLI_IAR_VERSION_CHECK(8, 0, 0)
154
+ #define BROTLI_NOINLINE _Pragma("inline=never")
155
+ #else
156
+ #define BROTLI_NOINLINE
157
+ #endif
158
+
159
+ /* BROTLI_INTERNAL could be defined to override visibility, e.g. for tests. */
160
+ #if !defined(BROTLI_INTERNAL)
161
+ #if defined(_WIN32) || defined(__CYGWIN__)
162
+ #define BROTLI_INTERNAL
163
+ #elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \
164
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
165
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
166
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
167
+ BROTLI_IBM_VERSION_CHECK(13, 1, 0) || \
168
+ BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
169
+ (BROTLI_TI_VERSION_CHECK(7, 3, 0) && \
170
+ defined(__TI_GNU_ATTRIBUTE_SUPPORT__) && defined(__TI_EABI__))
171
+ #define BROTLI_INTERNAL __attribute__ ((visibility ("hidden")))
172
+ #else
173
+ #define BROTLI_INTERNAL
174
+ #endif
175
+ #endif
176
+
177
+ /* <<< <<< <<< end of hedley macros. */
178
+
179
+ #if BROTLI_GNUC_HAS_ATTRIBUTE(unused, 2, 7, 0) || \
180
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
181
+ #define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE __attribute__ ((unused))
182
+ #else
183
+ #define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE
184
+ #endif
185
+
186
+ #if BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0)
187
+ #define BROTLI_ALIGNED(N) __attribute__((aligned(N)))
188
+ #else
189
+ #define BROTLI_ALIGNED(N)
190
+ #endif
191
+
192
+ #if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
193
+ (defined(M_ARM) && (M_ARM == 7))
194
+ #define BROTLI_TARGET_ARMV7
195
+ #endif /* ARMv7 */
196
+
197
+ #if (defined(__ARM_ARCH) && (__ARM_ARCH == 8)) || \
198
+ defined(__aarch64__) || defined(__ARM64_ARCH_8__)
199
+ #define BROTLI_TARGET_ARMV8_ANY
200
+
201
+ #if defined(__ARM_32BIT_STATE)
202
+ #define BROTLI_TARGET_ARMV8_32
203
+ #elif defined(__ARM_64BIT_STATE)
204
+ #define BROTLI_TARGET_ARMV8_64
205
+ #endif
206
+
207
+ #endif /* ARMv8 */
208
+
209
+ #if defined(__ARM_NEON__) || defined(__ARM_NEON)
210
+ #define BROTLI_TARGET_NEON
211
+ #endif
212
+
213
+ #if defined(__i386) || defined(_M_IX86)
214
+ #define BROTLI_TARGET_X86
215
+ #endif
216
+
217
+ #if defined(__x86_64__) || defined(_M_X64)
218
+ #define BROTLI_TARGET_X64
219
+ #endif
220
+
221
+ #if defined(__PPC64__)
222
+ #define BROTLI_TARGET_POWERPC64
223
+ #endif
224
+
225
+ #if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
226
+ #define BROTLI_TARGET_RISCV64
227
+ #endif
228
+
229
+ #if defined(BROTLI_BUILD_64_BIT)
230
+ #define BROTLI_64_BITS 1
231
+ #elif defined(BROTLI_BUILD_32_BIT)
232
+ #define BROTLI_64_BITS 0
233
+ #elif defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8_64) || \
234
+ defined(BROTLI_TARGET_POWERPC64) || defined(BROTLI_TARGET_RISCV64)
235
+ #define BROTLI_64_BITS 1
236
+ #else
237
+ #define BROTLI_64_BITS 0
238
+ #endif
239
+
240
+ #if (BROTLI_64_BITS)
241
+ #define brotli_reg_t uint64_t
242
+ #else
243
+ #define brotli_reg_t uint32_t
244
+ #endif
245
+
246
+ #if defined(BROTLI_BUILD_BIG_ENDIAN)
247
+ #define BROTLI_BIG_ENDIAN 1
248
+ #elif defined(BROTLI_BUILD_LITTLE_ENDIAN)
249
+ #define BROTLI_LITTLE_ENDIAN 1
250
+ #elif defined(BROTLI_BUILD_ENDIAN_NEUTRAL)
251
+ /* Just break elif chain. */
252
+ #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
253
+ #define BROTLI_LITTLE_ENDIAN 1
254
+ #elif defined(_WIN32) || defined(BROTLI_TARGET_X64)
255
+ /* Win32 & x64 can currently always be assumed to be little endian */
256
+ #define BROTLI_LITTLE_ENDIAN 1
257
+ #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
258
+ #define BROTLI_BIG_ENDIAN 1
259
+ #elif defined(BROTLI_X_BYTE_ORDER)
260
+ #if BROTLI_X_BYTE_ORDER == BROTLI_X_LITTLE_ENDIAN
261
+ #define BROTLI_LITTLE_ENDIAN 1
262
+ #elif BROTLI_X_BYTE_ORDER == BROTLI_X_BIG_ENDIAN
263
+ #define BROTLI_BIG_ENDIAN 1
264
+ #endif
265
+ #endif /* BROTLI_X_BYTE_ORDER */
266
+
267
+ #if !defined(BROTLI_LITTLE_ENDIAN)
268
+ #define BROTLI_LITTLE_ENDIAN 0
269
+ #endif
270
+
271
+ #if !defined(BROTLI_BIG_ENDIAN)
272
+ #define BROTLI_BIG_ENDIAN 0
273
+ #endif
274
+
275
+ #if defined(BROTLI_X_BYTE_ORDER)
276
+ #undef BROTLI_X_BYTE_ORDER
277
+ #undef BROTLI_X_LITTLE_ENDIAN
278
+ #undef BROTLI_X_BIG_ENDIAN
279
+ #endif
280
+
281
+ #if defined(BROTLI_BUILD_PORTABLE)
282
+ #define BROTLI_ALIGNED_READ (!!1)
283
+ #elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
284
+ defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY) || \
285
+ defined(BROTLI_TARGET_RISCV64)
286
+ /* Allow unaligned read only for white-listed CPUs. */
287
+ #define BROTLI_ALIGNED_READ (!!0)
288
+ #else
289
+ #define BROTLI_ALIGNED_READ (!!1)
290
+ #endif
291
+
292
+ #if BROTLI_ALIGNED_READ
293
+ /* Portable unaligned memory access: read / write values via memcpy. */
294
+ static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) {
295
+ uint16_t t;
296
+ memcpy(&t, p, sizeof t);
297
+ return t;
298
+ }
299
+ static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) {
300
+ uint32_t t;
301
+ memcpy(&t, p, sizeof t);
302
+ return t;
303
+ }
304
+ static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
305
+ uint64_t t;
306
+ memcpy(&t, p, sizeof t);
307
+ return t;
308
+ }
309
+ static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
310
+ memcpy(p, &v, sizeof v);
311
+ }
312
+ #else /* BROTLI_ALIGNED_READ */
313
+ /* Unaligned memory access is allowed: just cast pointer to requested type. */
314
+ #if BROTLI_SANITIZED
315
+ /* Consider we have an unaligned load/store of 4 bytes from address 0x...05.
316
+ AddressSanitizer will treat it as a 3-byte access to the range 05:07 and
317
+ will miss a bug if 08 is the first unaddressable byte.
318
+ ThreadSanitizer will also treat this as a 3-byte access to 05:07 and will
319
+ miss a race between this access and some other accesses to 08.
320
+ MemorySanitizer will correctly propagate the shadow on unaligned stores
321
+ and correctly report bugs on unaligned loads, but it may not properly
322
+ update and report the origin of the uninitialized memory.
323
+ For all three tools, replacing an unaligned access with a tool-specific
324
+ callback solves the problem. */
325
+ #if defined(__cplusplus)
326
+ extern "C" {
327
+ #endif /* __cplusplus */
328
+ uint16_t __sanitizer_unaligned_load16(const void* p);
329
+ uint32_t __sanitizer_unaligned_load32(const void* p);
330
+ uint64_t __sanitizer_unaligned_load64(const void* p);
331
+ void __sanitizer_unaligned_store64(void* p, uint64_t v);
332
+ #if defined(__cplusplus)
333
+ } /* extern "C" */
334
+ #endif /* __cplusplus */
335
+ #define BrotliUnalignedRead16 __sanitizer_unaligned_load16
336
+ #define BrotliUnalignedRead32 __sanitizer_unaligned_load32
337
+ #define BrotliUnalignedRead64 __sanitizer_unaligned_load64
338
+ #define BrotliUnalignedWrite64 __sanitizer_unaligned_store64
339
+ #else /* BROTLI_SANITIZED */
340
+ static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) {
341
+ return *(const uint16_t*)p;
342
+ }
343
+ static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) {
344
+ return *(const uint32_t*)p;
345
+ }
346
+ #if (BROTLI_64_BITS)
347
+ static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
348
+ return *(const uint64_t*)p;
349
+ }
350
+ static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
351
+ *(uint64_t*)p = v;
352
+ }
353
+ #else /* BROTLI_64_BITS */
354
+ /* Avoid emitting LDRD / STRD, which require properly aligned address. */
355
+ /* If __attribute__(aligned) is available, use that. Otherwise, memcpy. */
356
+
357
+ #if BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0)
358
+ typedef BROTLI_ALIGNED(1) uint64_t brotli_unaligned_uint64_t;
359
+
360
+ static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
361
+ return (uint64_t) ((const brotli_unaligned_uint64_t*) p)[0];
362
+ }
363
+ static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
364
+ brotli_unaligned_uint64_t* dwords = (brotli_unaligned_uint64_t*) p;
365
+ dwords[0] = (brotli_unaligned_uint64_t) v;
366
+ }
367
+ #else /* BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0) */
368
+ static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
369
+ uint64_t v;
370
+ memcpy(&v, p, sizeof(uint64_t));
371
+ return v;
372
+ }
373
+
374
+ static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
375
+ memcpy(p, &v, sizeof(uint64_t));
376
+ }
377
+ #endif /* BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0) */
378
+ #endif /* BROTLI_64_BITS */
379
+ #endif /* BROTLI_SANITIZED */
380
+ #endif /* BROTLI_ALIGNED_READ */
381
+
382
+ #if BROTLI_LITTLE_ENDIAN
383
+ /* Straight endianness. Just read / write values. */
384
+ #define BROTLI_UNALIGNED_LOAD16LE BrotliUnalignedRead16
385
+ #define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32
386
+ #define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
387
+ #define BROTLI_UNALIGNED_STORE64LE BrotliUnalignedWrite64
388
+ #elif BROTLI_BIG_ENDIAN /* BROTLI_LITTLE_ENDIAN */
389
+ /* Explain compiler to byte-swap values. */
390
+ #define BROTLI_BSWAP16_(V) ((uint16_t)( \
391
+ (((V) & 0xFFU) << 8) | \
392
+ (((V) >> 8) & 0xFFU)))
393
+ static BROTLI_INLINE uint16_t BROTLI_UNALIGNED_LOAD16LE(const void* p) {
394
+ uint16_t value = BrotliUnalignedRead16(p);
395
+ return BROTLI_BSWAP16_(value);
396
+ }
397
+ #define BROTLI_BSWAP32_(V) ( \
398
+ (((V) & 0xFFU) << 24) | (((V) & 0xFF00U) << 8) | \
399
+ (((V) >> 8) & 0xFF00U) | (((V) >> 24) & 0xFFU))
400
+ static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32LE(const void* p) {
401
+ uint32_t value = BrotliUnalignedRead32(p);
402
+ return BROTLI_BSWAP32_(value);
403
+ }
404
+ #define BROTLI_BSWAP64_(V) ( \
405
+ (((V) & 0xFFU) << 56) | (((V) & 0xFF00U) << 40) | \
406
+ (((V) & 0xFF0000U) << 24) | (((V) & 0xFF000000U) << 8) | \
407
+ (((V) >> 8) & 0xFF000000U) | (((V) >> 24) & 0xFF0000U) | \
408
+ (((V) >> 40) & 0xFF00U) | (((V) >> 56) & 0xFFU))
409
+ static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void* p) {
410
+ uint64_t value = BrotliUnalignedRead64(p);
411
+ return BROTLI_BSWAP64_(value);
412
+ }
413
+ static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
414
+ uint64_t value = BROTLI_BSWAP64_(v);
415
+ BrotliUnalignedWrite64(p, value);
416
+ }
417
+ #else /* BROTLI_LITTLE_ENDIAN */
418
+ /* Read / store values byte-wise; hopefully compiler will understand. */
419
+ static BROTLI_INLINE uint16_t BROTLI_UNALIGNED_LOAD16LE(const void* p) {
420
+ const uint8_t* in = (const uint8_t*)p;
421
+ return (uint16_t)(in[0] | (in[1] << 8));
422
+ }
423
+ static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32LE(const void* p) {
424
+ const uint8_t* in = (const uint8_t*)p;
425
+ uint32_t value = (uint32_t)(in[0]);
426
+ value |= (uint32_t)(in[1]) << 8;
427
+ value |= (uint32_t)(in[2]) << 16;
428
+ value |= (uint32_t)(in[3]) << 24;
429
+ return value;
430
+ }
431
+ static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void* p) {
432
+ const uint8_t* in = (const uint8_t*)p;
433
+ uint64_t value = (uint64_t)(in[0]);
434
+ value |= (uint64_t)(in[1]) << 8;
435
+ value |= (uint64_t)(in[2]) << 16;
436
+ value |= (uint64_t)(in[3]) << 24;
437
+ value |= (uint64_t)(in[4]) << 32;
438
+ value |= (uint64_t)(in[5]) << 40;
439
+ value |= (uint64_t)(in[6]) << 48;
440
+ value |= (uint64_t)(in[7]) << 56;
441
+ return value;
442
+ }
443
+ static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
444
+ uint8_t* out = (uint8_t*)p;
445
+ out[0] = (uint8_t)v;
446
+ out[1] = (uint8_t)(v >> 8);
447
+ out[2] = (uint8_t)(v >> 16);
448
+ out[3] = (uint8_t)(v >> 24);
449
+ out[4] = (uint8_t)(v >> 32);
450
+ out[5] = (uint8_t)(v >> 40);
451
+ out[6] = (uint8_t)(v >> 48);
452
+ out[7] = (uint8_t)(v >> 56);
453
+ }
454
+ #endif /* BROTLI_LITTLE_ENDIAN */
455
+
456
+ /* BROTLI_IS_CONSTANT macros returns true for compile-time constants. */
457
+ #if BROTLI_GNUC_HAS_BUILTIN(__builtin_constant_p, 3, 0, 1) || \
458
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
459
+ #define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
460
+ #else
461
+ #define BROTLI_IS_CONSTANT(x) (!!0)
462
+ #endif
463
+
464
+ #if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY)
465
+ #define BROTLI_HAS_UBFX (!!1)
466
+ #else
467
+ #define BROTLI_HAS_UBFX (!!0)
468
+ #endif
469
+
470
+ #if defined(BROTLI_ENABLE_LOG)
471
+ #define BROTLI_LOG(x) printf x
472
+ #else
473
+ #define BROTLI_LOG(x)
474
+ #endif
475
+
476
+ #if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
477
+ #define BROTLI_DCHECK(x) assert(x)
478
+ static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
479
+ fprintf(stderr, "%s:%d (%s)\n", f, l, fn);
480
+ fflush(stderr);
481
+ }
482
+ #define BROTLI_DUMP() BrotliDump(__FILE__, __LINE__, __FUNCTION__)
483
+ #else
484
+ #define BROTLI_DCHECK(x)
485
+ #define BROTLI_DUMP() (void)(0)
486
+ #endif
487
+
488
+ /* TODO: add appropriate icc/sunpro/arm/ibm/ti checks. */
489
+ #if (BROTLI_GNUC_VERSION_CHECK(3, 0, 0) || defined(__llvm__)) && \
490
+ !defined(BROTLI_BUILD_NO_RBIT)
491
+ #if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY)
492
+ /* TODO: detect ARMv6T2 and enable this code for it. */
493
+ static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) {
494
+ brotli_reg_t output;
495
+ __asm__("rbit %0, %1\n" : "=r"(output) : "r"(input));
496
+ return output;
497
+ }
498
+ #define BROTLI_RBIT(x) BrotliRBit(x)
499
+ #endif /* armv7 / armv8 */
500
+ #endif /* gcc || clang */
501
+ #if !defined(BROTLI_RBIT)
502
+ static BROTLI_INLINE void BrotliRBit(void) { /* Should break build if used. */ }
503
+ #endif /* BROTLI_RBIT */
504
+
505
+ #define BROTLI_REPEAT(N, X) { \
506
+ if ((N & 1) != 0) {X;} \
507
+ if ((N & 2) != 0) {X; X;} \
508
+ if ((N & 4) != 0) {X; X; X; X;} \
509
+ }
510
+
511
+ #define BROTLI_UNUSED(X) (void)(X)
512
+
513
+ #define BROTLI_MIN_MAX(T) \
514
+ static BROTLI_INLINE T brotli_min_ ## T (T a, T b) { return a < b ? a : b; } \
515
+ static BROTLI_INLINE T brotli_max_ ## T (T a, T b) { return a > b ? a : b; }
516
+ BROTLI_MIN_MAX(double) BROTLI_MIN_MAX(float) BROTLI_MIN_MAX(int)
517
+ BROTLI_MIN_MAX(size_t) BROTLI_MIN_MAX(uint32_t) BROTLI_MIN_MAX(uint8_t)
518
+ #undef BROTLI_MIN_MAX
519
+ #define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B)))
520
+ #define BROTLI_MAX(T, A, B) (brotli_max_ ## T((A), (B)))
521
+
522
+ #define BROTLI_SWAP(T, A, I, J) { \
523
+ T __brotli_swap_tmp = (A)[(I)]; \
524
+ (A)[(I)] = (A)[(J)]; \
525
+ (A)[(J)] = __brotli_swap_tmp; \
526
+ }
527
+
528
+ #if BROTLI_64_BITS
529
+ #if BROTLI_GNUC_HAS_BUILTIN(__builtin_ctzll, 3, 4, 0) || \
530
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
531
+ #define BROTLI_TZCNT64 __builtin_ctzll
532
+ #elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
533
+ #if defined(BROTLI_TARGET_X64)
534
+ #define BROTLI_TZCNT64 _tzcnt_u64
535
+ #else /* BROTLI_TARGET_X64 */
536
+ static BROTLI_INLINE uint32_t BrotliBsf64Msvc(uint64_t x) {
537
+ uint32_t lsb;
538
+ _BitScanForward64(&lsb, x);
539
+ return lsb;
540
+ }
541
+ #define BROTLI_TZCNT64 BrotliBsf64Msvc
542
+ #endif /* BROTLI_TARGET_X64 */
543
+ #endif /* __builtin_ctzll */
544
+ #endif /* BROTLI_64_BITS */
545
+
546
+ #if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \
547
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
548
+ #define BROTLI_BSR32(x) (31u ^ (uint32_t)__builtin_clz(x))
549
+ #elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
550
+ static BROTLI_INLINE uint32_t BrotliBsr32Msvc(uint32_t x) {
551
+ unsigned long msb;
552
+ _BitScanReverse(&msb, x);
553
+ return (uint32_t)msb;
554
+ }
555
+ #define BROTLI_BSR32 BrotliBsr32Msvc
556
+ #endif /* __builtin_clz */
557
+
558
+ /* Default brotli_alloc_func */
559
+ BROTLI_COMMON_API void* BrotliDefaultAllocFunc(void* opaque, size_t size);
560
+
561
+ /* Default brotli_free_func */
562
+ BROTLI_COMMON_API void BrotliDefaultFreeFunc(void* opaque, void* address);
563
+
564
+ BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
565
+ BROTLI_UNUSED(&BrotliSuppressUnusedFunctions);
566
+ BROTLI_UNUSED(&BrotliUnalignedRead16);
567
+ BROTLI_UNUSED(&BrotliUnalignedRead32);
568
+ BROTLI_UNUSED(&BrotliUnalignedRead64);
569
+ BROTLI_UNUSED(&BrotliUnalignedWrite64);
570
+ BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD16LE);
571
+ BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD32LE);
572
+ BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD64LE);
573
+ BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE64LE);
574
+ BROTLI_UNUSED(&BrotliRBit);
575
+ BROTLI_UNUSED(&brotli_min_double);
576
+ BROTLI_UNUSED(&brotli_max_double);
577
+ BROTLI_UNUSED(&brotli_min_float);
578
+ BROTLI_UNUSED(&brotli_max_float);
579
+ BROTLI_UNUSED(&brotli_min_int);
580
+ BROTLI_UNUSED(&brotli_max_int);
581
+ BROTLI_UNUSED(&brotli_min_size_t);
582
+ BROTLI_UNUSED(&brotli_max_size_t);
583
+ BROTLI_UNUSED(&brotli_min_uint32_t);
584
+ BROTLI_UNUSED(&brotli_max_uint32_t);
585
+ BROTLI_UNUSED(&brotli_min_uint8_t);
586
+ BROTLI_UNUSED(&brotli_max_uint8_t);
587
+ BROTLI_UNUSED(&BrotliDefaultAllocFunc);
588
+ BROTLI_UNUSED(&BrotliDefaultFreeFunc);
589
+ #if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
590
+ BROTLI_UNUSED(&BrotliDump);
591
+ #endif
592
+ }
593
+
594
+ #endif /* BROTLI_COMMON_PLATFORM_H_ */