├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── test.cc ├── timer.h ├── varintdecode.c ├── varintdecode.h ├── vbyte.cc └── vbyte.h /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | 3 | # Object files 4 | *.o 5 | *.ko 6 | *.obj 7 | *.elf 8 | 9 | # Precompiled Headers 10 | *.gch 11 | *.pch 12 | 13 | # Libraries 14 | *.lib 15 | *.a 16 | *.la 17 | *.lo 18 | 19 | # Shared objects (inc. Windows DLLs) 20 | *.dll 21 | *.so 22 | *.so.* 23 | *.dylib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | *.i*86 30 | *.x86_64 31 | *.hex 32 | test 33 | 34 | # Debug files 35 | *.dSYM/ 36 | 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #DEBUG=1 2 | VBYTE_CFLAGS=-mavx # undefine this to compile on non-intel platforms. 3 | 4 | # ------------------------------------------------------- 5 | 6 | .SUFFIXES: .cpp .o .c .h 7 | OBJECTS = vbyte.o varintdecode.o 8 | 9 | ifeq ($(DEBUG),1) 10 | CFLAGS = -g -pedantic -DDEBUG=1 -D_GLIBCXX_DEBUG -Wall -Wextra 11 | else 12 | CFLAGS = -g -pedantic -Wall -Wextra -O3 13 | endif #debug 14 | 15 | 16 | HEADERS= $(shell ls *h) 17 | 18 | all: test libvbyte.a 19 | echo "please run unit tests by running ./test" 20 | 21 | vbyte.o: vbyte.h vbyte.cc 22 | $(CXX) $(CFLAGS) $(VBYTE_CFLAGS) -c vbyte.cc 23 | 24 | varintdecode.o: vbyte.h varintdecode.c 25 | $(CXX) $(CFLAGS) -mavx -c varintdecode.c 26 | 27 | vbyte: $(HEADERS) $(OBJECTS) 28 | ar rvs libvbyte.a $(OBJECTS) 29 | 30 | test: vbyte $(HEADERS) test.cc 31 | $(CXX) $(CFLAGS) -std=c++11 -o test test.cc libvbyte.a \ 32 | -lboost_chrono -lboost_system 33 | 34 | clean: 35 | rm -f *.o test 36 | 37 | .PHONY: all clean test 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libvbyte - Fast C Library for 32bit and 64bit Integer Compression 2 | ====================== 3 | 4 | A C library with a fast implementation for VByte integer compression. 5 | Uses MaskedVbyte (SSE/AVX) for 32bit integers on supported platforms. It works 6 | on Linux, Microsoft Windows and most likely all other sane systems. 7 | 8 | libvbyte can compress sorted and unsorted integer sequences. It uses delta 9 | compression for the sorted sequences. 10 | 11 | In addition, the library can perform operations directly on compressed data: 12 | 13 | * select: returns a value at a specified index 14 | * linear search: for unsorted sequences, or short sorted sequences 15 | * lower bound search: based on binary search, for sorted sequences 16 | * append: appends an integer to a compressed sequence 17 | 18 | Simple demo 19 | ------------------------ 20 | 21 | #define LEN 100 22 | uint32_t in[LEN] = {0}; 23 | uint8_t out[512]; 24 | 25 | // Fill |in| with numbers of your choice 26 | for (int i = 0; i < LEN; i++) 27 | in[i] = i; 28 | 29 | // Now compress; can also use vbyte_compress_sorted() if the numbers 30 | // are sorted. This improves compression. 31 | uint32_t size = vbyte_compress_unsorted32(&in[0], &out[0], LEN); 32 | printf("compressing %u integers (%u bytes) into %u bytes\n", 33 | LEN, LEN * 4, size); 34 | 35 | // Decompress again 36 | uint32_t decompressed[LEN]; 37 | vbyte_uncompress_unsorted32(&out[0], &decompressed[0], LEN); 38 | 39 | See test.cc for more usage examples. 40 | 41 | Usage 42 | ------------------------ 43 | 44 | It can't be more simple: 45 | 46 | make 47 | 48 | To run the tests: 49 | 50 | ./test 51 | 52 | Compile time configuration 53 | ---------------------- 54 | 55 | The Makefile automatically enables use of MaskedVbyte (SSE/AVX). If your 56 | code should run on older platforms then undefine VBYTE_CFLAGS in the 57 | Makefile (at the very top of the file). 58 | 59 | MaskedVbyte can be compiled with AVX and AVX2. The code currently uses AVX. 60 | If you want to use AVX2 instead then change the compiler setting in 61 | the Makefile. 62 | 63 | Where is this used? 64 | ---------------------- 65 | 66 | I use this library to compress 32bit and 64bit integers in upscaledb, a very 67 | fast embedded key/value store (see https://upscaledb.com). 68 | 69 | If you would like me to add your application to this list then please send 70 | me a mail at chris@crupp.de. 71 | 72 | Licensing 73 | ------------------------ 74 | 75 | Apache License, Version 2.0 76 | 77 | Requirements 78 | ------------------------ 79 | 80 | This library only works with little-endian CPUs. 81 | 82 | Tested on Linux and Windows (Visual Studio 2013). Porting it should not 83 | be difficult. 84 | 85 | Acknowledgement 86 | ------------------------ 87 | 88 | This work is based on Daniel Lemire (http://lemire.me)'s ideas and 89 | implementation at https://github.com/lemire/MaskedVbyte. 90 | 91 | For further information, see 92 | * Daniel Lemire, Christoph Rupp, Upscaledb: Efficient Integer-Key Compression in a Key-Value Store using SIMD Instructions, Information Systems 66, 2017. https://arxiv.org/abs/1611.05428 93 | * Goldstein J, Ramakrishnan R, Shaft U. Compressing relations and indexes. Proceedings of the Fourteenth International Conference on Data Engineering, ICDE ’98, IEEE Computer Society: Washington, DC, USA, 1998; 370–379. 94 | * Daniel Lemire and Leonid Boytsov, Decoding billions of integers per second through vectorization, Software Practice & Experience 45 (1), 2015. http://arxiv.org/abs/1209.2137 http://onlinelibrary.wiley.com/doi/10.1002/spe.2203/abstract 95 | * Daniel Lemire, Leonid Boytsov, Nathan Kurz, SIMD Compression and the Intersection of Sorted Integers, Software Practice & Experience (to appear) http://arxiv.org/abs/1401.6399 96 | * Jeff Plaisance, Nathan Kurz, Daniel Lemire, Vectorized VByte Decoding, International Symposium on Web Algorithms 2015, 2015. http://arxiv.org/abs/1503.07387 97 | * Wayne Xin Zhao, Xudong Zhang, Daniel Lemire, Dongdong Shan, Jian-Yun Nie, Hongfei Yan, Ji-Rong Wen, A General SIMD-based Approach to Accelerating Compression Algorithms, ACM Transactions on Information Systems 33 (3), 2015. http://arxiv.org/abs/1502.01916 98 | 99 | 100 | -------------------------------------------------------------------------------- /test.cc: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include "timer.h" 12 | #include "vbyte.h" 13 | #include "varintdecode.h" 14 | 15 | static const int loops = 5; 16 | 17 | template 18 | static void 19 | run_compression_test(std::vector &plain, 20 | std::vector &z) 21 | { 22 | size_t len = Traits::compress(&plain[0], &z[0], plain.size()); 23 | z.resize(len); 24 | assert(len == Traits::compressed_size(&plain[0], plain.size())); 25 | } 26 | 27 | template 28 | static void 29 | run_uncompression_test(const std::vector &plain, 30 | std::vector &z, 31 | std::vector &out) 32 | { 33 | Timer t; 34 | for (int l = 0; l < loops; l++) { 35 | Traits::uncompress(&z[0], &out[0], plain.size()); 36 | for (uint32_t j = 0; j < plain.size(); j++) 37 | assert(plain[j] == out[j]); 38 | } 39 | printf(" %s decode -> %f\n", Traits::name, t.seconds() / loops); 40 | } 41 | 42 | template 43 | static void 44 | run_select_test(const std::vector &plain, 45 | std::vector &z) 46 | { 47 | Timer t; 48 | for (int l = 0; l < loops; l++) { 49 | for (uint32_t i = 0; i < plain.size(); i += 1 + plain.size() / 100) { 50 | typename Traits::type v = Traits::select(&z[0], z.size(), i); 51 | assert(plain[i] == v); 52 | } 53 | } 54 | printf(" %s select -> %f\n", Traits::name, t.seconds() / loops); 55 | } 56 | 57 | template 58 | static void 59 | run_search_test(const std::vector &plain, 60 | std::vector &z) 61 | { 62 | Timer t; 63 | for (int l = 0; l < loops; l++) { 64 | for (size_t i = 0; i < plain.size(); i += 1 + plain.size() / 5000) { 65 | typename Traits::type found; 66 | size_t pos = Traits::search(&z[0], z.size(), plain[i], &found); 67 | assert(found == plain[i]); 68 | assert(i == pos); 69 | } 70 | } 71 | printf(" %s search -> %f\n", Traits::name, t.seconds() / loops); 72 | } 73 | 74 | template 75 | static void 76 | run_append_test(std::vector &plain, 77 | std::vector &z) 78 | { 79 | size_t zsize = z.size(); 80 | 81 | z.reserve(z.size() + 1024); 82 | 83 | Timer t; 84 | for (uint32_t i = 0; i < 100; i++) { 85 | typename Traits::type highest = plain[plain.size() - 1]; 86 | typename Traits::type value = highest + 5; 87 | size_t size = Traits::append(z.data() + zsize, highest, value); 88 | zsize += size; 89 | plain.push_back(value); 90 | } 91 | printf(" %s append -> %f\n", Traits::name, t.seconds() / loops); 92 | 93 | // verify 94 | for (uint32_t i = 1; i <= 100; i++) { 95 | typename Traits::type sel = Traits::select(&z[0], zsize, plain.size() - i); 96 | assert(sel == plain[plain.size() - i]); 97 | } 98 | } 99 | 100 | template 101 | static void 102 | run_tests(size_t length) 103 | { 104 | std::vector plain; 105 | std::vector z(length * 10); 106 | std::vector out(length); 107 | 108 | for (size_t i = 0; i < length; i++) 109 | plain.push_back(Traits::make_plain_value(i)); 110 | 111 | // compress the data 112 | run_compression_test(plain, z); 113 | 114 | // uncompress the data 115 | run_uncompression_test(plain, z, out); 116 | 117 | // select values 118 | run_select_test(plain, z); 119 | 120 | // search for keys 121 | run_search_test(plain, z); 122 | 123 | // append keys. Will modify |plain| and |z|! 124 | run_append_test(plain, z); 125 | } 126 | 127 | struct Sorted32Traits { 128 | typedef uint32_t type; 129 | static constexpr const char *name = "Sorted32"; 130 | 131 | static type make_plain_value(size_t i) { 132 | return i * 7; 133 | } 134 | 135 | static size_t compress(const type *in, uint8_t *out, size_t length) { 136 | return vbyte_compress_sorted32(in, out, 0, length); 137 | } 138 | 139 | static size_t compressed_size(const type *in, size_t length) { 140 | return vbyte_compressed_size_sorted32(in, length, 0); 141 | } 142 | 143 | static size_t uncompress(const uint8_t *in, type *out, size_t length) { 144 | return vbyte_uncompress_sorted32(in, out, 0, length); 145 | } 146 | 147 | static type select(const uint8_t *in, size_t length, size_t index) { 148 | return vbyte_select_sorted32(in, length, 0, index); 149 | } 150 | 151 | static size_t search(const uint8_t *in, size_t length, type value, 152 | type *result) { 153 | return vbyte_search_lower_bound_sorted32(in, length, value, 0, result); 154 | } 155 | 156 | static size_t append(uint8_t *end, type highest, type value) { 157 | return vbyte_append_sorted64(end, highest, value); 158 | } 159 | }; 160 | 161 | struct Sorted64Traits { 162 | typedef uint64_t type; 163 | static constexpr const char *name = "Sorted64"; 164 | 165 | static type make_plain_value(size_t i) { 166 | return i * i; 167 | } 168 | 169 | static size_t compress(const type *in, uint8_t *out, size_t length) { 170 | return vbyte_compress_sorted64(in, out, 0, length); 171 | } 172 | 173 | static size_t compressed_size(const type *in, size_t length) { 174 | return vbyte_compressed_size_sorted64(in, length, 0); 175 | } 176 | 177 | static size_t uncompress(const uint8_t *in, type *out, size_t length) { 178 | return vbyte_uncompress_sorted64(in, out, 0, length); 179 | } 180 | 181 | static type select(const uint8_t *in, size_t length, size_t index) { 182 | return vbyte_select_sorted64(in, length, 0, index); 183 | } 184 | 185 | static size_t search(const uint8_t *in, size_t length, type value, 186 | type *result) { 187 | return vbyte_search_lower_bound_sorted64(in, length, value, 0, result); 188 | } 189 | 190 | static size_t append(uint8_t *end, type highest, type value) { 191 | return vbyte_append_sorted64(end, highest, value); 192 | } 193 | }; 194 | 195 | struct Unsorted32Traits { 196 | typedef uint32_t type; 197 | static constexpr const char *name = "Unsorted32"; 198 | 199 | static type make_plain_value(size_t i) { 200 | return i * 7; 201 | } 202 | 203 | static size_t compress(const type *in, uint8_t *out, size_t length) { 204 | return vbyte_compress_unsorted32(in, out, length); 205 | } 206 | 207 | static size_t compressed_size(const type *in, size_t length) { 208 | return vbyte_compressed_size_unsorted32(in, length); 209 | } 210 | 211 | static size_t uncompress(const uint8_t *in, type *out, size_t length) { 212 | return vbyte_uncompress_unsorted32(in, out, length); 213 | } 214 | 215 | static type select(const uint8_t *in, size_t length, size_t index) { 216 | return vbyte_select_unsorted32(in, length, index); 217 | } 218 | 219 | static size_t search(const uint8_t *in, size_t length, type value, 220 | type *result) { 221 | *result = value; 222 | return vbyte_search_unsorted32(in, length, value); 223 | } 224 | 225 | static size_t append(uint8_t *end, type, type value) { 226 | return vbyte_append_unsorted32(end, value); 227 | } 228 | }; 229 | 230 | struct Unsorted64Traits { 231 | typedef uint64_t type; 232 | static constexpr const char *name = "Unsorted64"; 233 | 234 | static type make_plain_value(size_t i) { 235 | return i * i; 236 | } 237 | 238 | static size_t compress(const type *in, uint8_t *out, size_t length) { 239 | return vbyte_compress_unsorted64(in, out, length); 240 | } 241 | 242 | static size_t compressed_size(const type *in, size_t length) { 243 | return vbyte_compressed_size_unsorted64(in, length); 244 | } 245 | 246 | static size_t uncompress(const uint8_t *in, type *out, size_t length) { 247 | return vbyte_uncompress_unsorted64(in, out, length); 248 | } 249 | 250 | static type select(const uint8_t *in, size_t length, size_t index) { 251 | return vbyte_select_unsorted64(in, length, index); 252 | } 253 | 254 | static size_t search(const uint8_t *in, size_t length, type value, 255 | type *result) { 256 | *result = value; 257 | return vbyte_search_unsorted64(in, length, value); 258 | } 259 | 260 | static size_t append(uint8_t *end, type, type value) { 261 | return vbyte_append_unsorted64(end, value); 262 | } 263 | }; 264 | 265 | inline static void 266 | test(size_t length) 267 | { 268 | printf("%u, sorted, 32bit\n", (uint32_t)length); 269 | run_tests(length); 270 | 271 | printf("%u, sorted, 64bit\n", (uint32_t)length); 272 | run_tests(length); 273 | 274 | printf("%u, unsorted, 32bit\n", (uint32_t)length); 275 | run_tests(length); 276 | 277 | printf("%u, unsorted, 64bit\n", (uint32_t)length); 278 | run_tests(length); 279 | } 280 | 281 | int 282 | main() 283 | { 284 | uint32_t seed = std::time(0); 285 | printf("seed: %u\n", seed); 286 | 287 | test(1); 288 | test(2); 289 | test(10); 290 | test(16); 291 | test(33); 292 | test(42); 293 | test(100); 294 | test(128); 295 | test(256); 296 | test(333); 297 | test(1000); 298 | test(10000); 299 | test(20000); 300 | test(100000); 301 | test(1000000); 302 | test(10000000); 303 | return 0; 304 | } 305 | -------------------------------------------------------------------------------- /timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2016 Christoph Rupp (chris@crupp.de). 3 | * All Rights Reserved. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * See the file COPYING for License information. 16 | */ 17 | 18 | #ifndef UPS_BENCH_TIMER_H 19 | #define UPS_BENCH_TIMER_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace boost::chrono; 26 | 27 | // based on 28 | // http://www.boost.org/doc/libs/1_54_0/libs/chrono/example/await_keystroke.cpp 29 | template 30 | struct Timer { 31 | typename Clock::time_point _start; 32 | 33 | Timer() { 34 | start(); 35 | } 36 | 37 | void start() { 38 | _start = Clock::now(); 39 | } 40 | 41 | typename Clock::duration elapsed() const { 42 | return Clock::now() - _start; 43 | } 44 | 45 | double seconds() const { 46 | return elapsed().count() * 47 | ((double)Clock::period::num / Clock::period::den); 48 | } 49 | }; 50 | 51 | #endif // UPS_BENCH_TIMER_H 52 | -------------------------------------------------------------------------------- /varintdecode.c: -------------------------------------------------------------------------------- 1 | #include "varintdecode.h" 2 | 3 | #include 4 | 5 | #if defined(_MSC_VER) 6 | #define ALIGNED(x) __declspec(align(x)) 7 | #else 8 | #if defined(__GNUC__) 9 | #define ALIGNED(x) __attribute__ ((aligned(x))) 10 | #endif 11 | #endif 12 | 13 | 14 | #if defined(_MSC_VER) 15 | # include 16 | /* 64-bit needs extending */ 17 | # define SIMDCOMP_CTZ(result, mask) do { \ 18 | unsigned long index; \ 19 | if (!_BitScanForward(&(index), (mask))) { \ 20 | (result) = 32U; \ 21 | } else { \ 22 | (result) = (uint32_t)(index); \ 23 | } \ 24 | } while (0) 25 | #else 26 | # define SIMDCOMP_CTZ(result, mask) \ 27 | result = __builtin_ctz(mask) 28 | #endif 29 | 30 | typedef struct index_bytes_consumed { 31 | uint8_t index; 32 | uint8_t bytes_consumed; 33 | } index_bytes_consumed; 34 | 35 | static index_bytes_consumed combined_lookup[] ALIGNED(0x1000) = { 36 | {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, 37 | {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, 38 | {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, 39 | {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, 40 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, 41 | {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, 42 | {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, 43 | {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, 44 | {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, 45 | {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, 46 | {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, 47 | {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, 48 | {14, 9}, {60, 10}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, 49 | {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, 50 | {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, 51 | {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, 52 | {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, 53 | {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, 54 | {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, 55 | {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, 56 | {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, 57 | {121, 7}, {13, 9}, {58, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, 58 | {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, 59 | {35, 9}, {19, 9}, {119, 7}, {11, 9}, {54, 10}, {83, 7}, {160, 5}, 60 | {7, 9}, {46, 10}, {30, 10}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, 61 | {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, 62 | {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, 63 | {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, 64 | {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, 65 | {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, 66 | {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, 67 | {99, 9}, {81, 9}, {142, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, 68 | {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, 69 | {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, 70 | {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, 71 | {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, 72 | {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, 73 | {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, 74 | {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, 75 | {36, 8}, {20, 8}, {121, 7}, {12, 8}, {57, 10}, {85, 7}, {161, 6}, 76 | {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, 77 | {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {53, 10}, 78 | {83, 7}, {160, 5}, {6, 8}, {45, 10}, {29, 10}, {130, 8}, {71, 7}, 79 | {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, 80 | {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, 81 | {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, 82 | {17, 8}, {118, 6}, {9, 8}, {51, 10}, {82, 6}, {160, 5}, {5, 8}, 83 | {43, 10}, {27, 10}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, 84 | {3, 8}, {39, 10}, {23, 10}, {122, 8}, {15, 10}, {62, 11}, {86, 8}, 85 | {161, 6}, {66, 6}, {98, 8}, {80, 8}, {140, 10}, {145, 2}, {153, 6}, 86 | {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, 87 | {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {134, 10}, 88 | {72, 8}, {116, 10}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, 89 | {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, 90 | {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, 91 | {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, 92 | {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, 93 | {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, 94 | {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {138, 10}, {145, 2}, 95 | {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, 96 | {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, 97 | {132, 10}, {71, 7}, {114, 10}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, 98 | {75, 7}, {126, 10}, {69, 7}, {108, 10}, {90, 10}, {162, 7}, {145, 2}, 99 | {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, 100 | {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, 101 | {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, 102 | {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, 103 | {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, 104 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, 105 | {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, 106 | {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {169, 10}, {0, 4}, 107 | {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, 108 | {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, 109 | {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, 110 | {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, 111 | {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, 112 | {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, 113 | {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, 114 | {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, 115 | {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, 116 | {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, 117 | {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, 118 | {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, 119 | {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, 120 | {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, 121 | {122, 8}, {14, 9}, {61, 11}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, 122 | {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, 123 | {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, 124 | {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, 125 | {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, 126 | {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, 127 | {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, 128 | {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, 129 | {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, 130 | {21, 9}, {121, 7}, {13, 9}, {59, 11}, {85, 7}, {161, 6}, {66, 6}, 131 | {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, 132 | {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {55, 11}, {83, 7}, 133 | {160, 5}, {7, 9}, {47, 11}, {31, 11}, {131, 9}, {71, 7}, {113, 9}, 134 | {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, 135 | {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, 136 | {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, 137 | {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, 138 | {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, 139 | {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, 140 | {66, 6}, {99, 9}, {81, 9}, {143, 11}, {145, 2}, {153, 6}, {149, 6}, 141 | {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, 142 | {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, 143 | {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, 144 | {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, 145 | {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, 146 | {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, 147 | {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, 148 | {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {103, 7}, {85, 7}, 149 | {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, 150 | {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, 151 | {101, 7}, {83, 7}, {160, 5}, {6, 8}, {95, 7}, {77, 7}, {130, 8}, 152 | {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, 153 | {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, 154 | {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, 155 | {33, 8}, {17, 8}, {118, 6}, {9, 8}, {100, 6}, {82, 6}, {160, 5}, 156 | {5, 8}, {94, 6}, {76, 6}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, 157 | {165, 6}, {3, 8}, {92, 6}, {74, 6}, {122, 8}, {68, 6}, {104, 8}, 158 | {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {141, 11}, {145, 2}, 159 | {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, 160 | {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, 161 | {135, 11}, {72, 8}, {117, 11}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, 162 | {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, 163 | {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, 164 | {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, 165 | {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, 166 | {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, 167 | {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {157, 6}, 168 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, 169 | {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, 170 | {77, 7}, {156, 5}, {71, 7}, {152, 5}, {148, 5}, {166, 7}, {64, 4}, 171 | {93, 7}, {75, 7}, {155, 4}, {69, 7}, {151, 4}, {147, 4}, {162, 7}, 172 | {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, 173 | {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, 174 | {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, 175 | {152, 5}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, 176 | {68, 6}, {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, 177 | {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {0, 4}, {0, 5}, 178 | {0, 5}, {0, 4}, {0, 5}, {0, 4}, {0, 4}, {0, 5}, {0, 5}, 179 | {0, 3}, {0, 3}, {0, 5}, {0, 2}, {0, 5}, {0, 5}, {0, 0}, 180 | {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, 181 | {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, 182 | {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, 183 | {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, 184 | {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, 185 | {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, 186 | {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, 187 | {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, 188 | {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, 189 | {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, 190 | {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, 191 | {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, 192 | {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, 193 | {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, 194 | {22, 9}, {122, 8}, {14, 9}, {60, 10}, {86, 8}, {161, 6}, {66, 6}, 195 | {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, 196 | {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, 197 | {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, 198 | {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, 199 | {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, 200 | {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, 201 | {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, 202 | {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, 203 | {37, 9}, {21, 9}, {121, 7}, {13, 9}, {58, 10}, {85, 7}, {161, 6}, 204 | {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, 205 | {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, {54, 10}, 206 | {83, 7}, {160, 5}, {7, 9}, {46, 10}, {30, 10}, {131, 9}, {71, 7}, 207 | {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, 208 | {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, 209 | {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, 210 | {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, 211 | {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, 212 | {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, 213 | {161, 6}, {66, 6}, {99, 9}, {81, 9}, {142, 10}, {145, 2}, {153, 6}, 214 | {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, 215 | {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, 216 | {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, 217 | {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, 218 | {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, 219 | {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, 220 | {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, 221 | {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {57, 10}, 222 | {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, 223 | {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, 224 | {10, 8}, {53, 10}, {83, 7}, {160, 5}, {6, 8}, {45, 10}, {29, 10}, 225 | {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, 226 | {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, 227 | {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, 228 | {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {51, 10}, {82, 6}, 229 | {160, 5}, {5, 8}, {43, 10}, {27, 10}, {128, 8}, {70, 6}, {110, 8}, 230 | {148, 5}, {165, 6}, {3, 8}, {39, 10}, {23, 10}, {122, 8}, {15, 10}, 231 | {63, 12}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {140, 10}, 232 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, 233 | {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, 234 | {78, 8}, {134, 10}, {72, 8}, {116, 10}, {148, 5}, {167, 8}, {64, 4}, 235 | {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, 236 | {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, 237 | {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {100, 6}, 238 | {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, {70, 6}, 239 | {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, {121, 7}, 240 | {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, 241 | {138, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {91, 5}, 242 | {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, {65, 5}, 243 | {95, 7}, {77, 7}, {132, 10}, {71, 7}, {114, 10}, {148, 5}, {166, 7}, 244 | {64, 4}, {93, 7}, {75, 7}, {126, 10}, {69, 7}, {108, 10}, {90, 10}, 245 | {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, 246 | {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, 247 | {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {156, 5}, 248 | {70, 6}, {152, 5}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, 249 | {155, 4}, {68, 6}, {151, 4}, {147, 4}, {161, 6}, {66, 6}, {150, 3}, 250 | {146, 3}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, 251 | {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, 252 | {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, 253 | {169, 10}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, 254 | {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, 255 | {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, 256 | {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, 257 | {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, 258 | {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, {66, 6}, 259 | {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, 260 | {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, {83, 7}, 261 | {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, {112, 8}, 262 | {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, 263 | {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, 264 | {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, 265 | {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, {42, 9}, 266 | {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, 267 | {38, 9}, {22, 9}, {122, 8}, {14, 9}, {104, 8}, {86, 8}, {161, 6}, 268 | {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, {149, 6}, 269 | {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, 270 | {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, {72, 8}, 271 | {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, 272 | {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, 273 | {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, 274 | {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, {4, 7}, 275 | {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, 276 | {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {103, 7}, {85, 7}, 277 | {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, {153, 6}, 278 | {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, {11, 9}, 279 | {101, 7}, {83, 7}, {160, 5}, {7, 9}, {95, 7}, {77, 7}, {131, 9}, 280 | {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, 281 | {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, {150, 3}, 282 | {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, 283 | {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, 284 | {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, {148, 5}, 285 | {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, {105, 9}, 286 | {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {144, 12}, {145, 2}, 287 | {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, 288 | {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, 289 | {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, {150, 3}, 290 | {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, {0, 2}, 291 | {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, 292 | {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, 293 | {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, 294 | {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, 295 | {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, 296 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, 297 | {119, 7}, {10, 8}, {101, 7}, {83, 7}, {160, 5}, {6, 8}, {95, 7}, 298 | {77, 7}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, 299 | {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, 300 | {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, 301 | {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {100, 6}, 302 | {82, 6}, {160, 5}, {5, 8}, {94, 6}, {76, 6}, {128, 8}, {70, 6}, 303 | {110, 8}, {148, 5}, {165, 6}, {3, 8}, {92, 6}, {74, 6}, {122, 8}, 304 | {68, 6}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, 305 | {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, 306 | {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, 307 | {96, 8}, {78, 8}, {156, 5}, {72, 8}, {152, 5}, {148, 5}, {167, 8}, 308 | {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, 309 | {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, 310 | {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, 311 | {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, {127, 7}, 312 | {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, {74, 6}, 313 | {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, 314 | {79, 7}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, 315 | {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, {160, 5}, 316 | {65, 5}, {95, 7}, {77, 7}, {156, 5}, {71, 7}, {152, 5}, {148, 5}, 317 | {166, 7}, {64, 4}, {93, 7}, {75, 7}, {155, 4}, {69, 7}, {151, 4}, 318 | {147, 4}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, 319 | {154, 7}, {0, 0}, {0, 0}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, 320 | {0, 5}, {0, 6}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 6}, 321 | {0, 5}, {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 4}, {0, 6}, 322 | {0, 6}, {0, 4}, {0, 6}, {0, 4}, {0, 4}, {0, 6}, {0, 6}, 323 | {0, 3}, {0, 3}, {0, 6}, {0, 2}, {0, 6}, {0, 6}, {0, 0}, 324 | {0, 4}, {0, 5}, {0, 5}, {0, 4}, {0, 5}, {0, 4}, {0, 4}, 325 | {0, 5}, {0, 5}, {0, 3}, {0, 3}, {0, 5}, {0, 2}, {0, 5}, 326 | {0, 5}, {0, 0}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, {0, 2}, 327 | {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, 328 | {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, 329 | {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, 330 | {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, 331 | {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, {161, 6}, 332 | {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, 333 | {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {52, 9}, 334 | {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, {71, 7}, 335 | {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, 336 | {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, 337 | {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, 338 | {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, {5, 8}, 339 | {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, 340 | {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {60, 10}, {86, 8}, 341 | {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, {153, 6}, 342 | {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, 343 | {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {133, 9}, 344 | {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, 345 | {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, 346 | {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, 347 | {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, {160, 5}, 348 | {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, 349 | {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, {58, 10}, 350 | {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, {145, 2}, 351 | {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, {119, 7}, 352 | {11, 9}, {54, 10}, {83, 7}, {160, 5}, {7, 9}, {46, 10}, {30, 10}, 353 | {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, 354 | {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, {145, 2}, 355 | {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, 356 | {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, 357 | {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, {111, 9}, 358 | {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, {68, 6}, 359 | {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, {142, 10}, 360 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, 361 | {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, 362 | {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, {64, 4}, 363 | {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {164, 9}, 364 | {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, 365 | {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, 366 | {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, 367 | {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, 368 | {12, 8}, {57, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, 369 | {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, 370 | {18, 8}, {119, 7}, {10, 8}, {53, 10}, {83, 7}, {160, 5}, {6, 8}, 371 | {45, 10}, {29, 10}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, 372 | {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, 373 | {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, 374 | {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, 375 | {51, 10}, {82, 6}, {160, 5}, {5, 8}, {43, 10}, {27, 10}, {128, 8}, 376 | {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {39, 10}, {23, 10}, 377 | {122, 8}, {15, 10}, {62, 11}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, 378 | {80, 8}, {140, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, 379 | {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, 380 | {65, 5}, {96, 8}, {78, 8}, {134, 10}, {72, 8}, {116, 10}, {148, 5}, 381 | {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, 382 | {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, 383 | {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, 384 | {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, {76, 6}, 385 | {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {92, 6}, 386 | {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, 387 | {97, 7}, {79, 7}, {138, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, 388 | {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, {83, 7}, 389 | {160, 5}, {65, 5}, {95, 7}, {77, 7}, {132, 10}, {71, 7}, {114, 10}, 390 | {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {126, 10}, {69, 7}, 391 | {108, 10}, {90, 10}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, 392 | {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, 393 | {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, 394 | {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, {165, 6}, {64, 4}, 395 | {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, {147, 4}, {161, 6}, 396 | {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, 397 | {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, 398 | {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, 399 | {152, 5}, {148, 5}, {169, 10}, {0, 4}, {0, 3}, {0, 3}, {0, 4}, 400 | {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, {0, 3}, 401 | {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, 402 | {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, 403 | {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, 404 | {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, {85, 7}, 405 | {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, 406 | {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, 407 | {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, {130, 8}, 408 | {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, 409 | {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, 410 | {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, 411 | {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, {160, 5}, 412 | {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, 413 | {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, {61, 11}, 414 | {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, {145, 2}, 415 | {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, 416 | {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, 417 | {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, 418 | {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, 419 | {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, 420 | {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, {82, 6}, 421 | {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, {109, 7}, 422 | {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, {13, 9}, 423 | {59, 11}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {137, 9}, 424 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, {19, 9}, 425 | {119, 7}, {11, 9}, {55, 11}, {83, 7}, {160, 5}, {7, 9}, {47, 11}, 426 | {31, 11}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, {64, 4}, 427 | {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, {162, 7}, 428 | {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, 429 | {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, 430 | {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, {70, 6}, 431 | {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, {123, 9}, 432 | {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, {81, 9}, 433 | {143, 11}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, 434 | {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, 435 | {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, {168, 9}, 436 | {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, 437 | {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, 438 | {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, 439 | {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, 440 | {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, 441 | {121, 7}, {12, 8}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, 442 | {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, 443 | {34, 8}, {18, 8}, {119, 7}, {10, 8}, {101, 7}, {83, 7}, {160, 5}, 444 | {6, 8}, {95, 7}, {77, 7}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, 445 | {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, 446 | {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, 447 | {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, 448 | {9, 8}, {100, 6}, {82, 6}, {160, 5}, {5, 8}, {94, 6}, {76, 6}, 449 | {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, {92, 6}, 450 | {74, 6}, {122, 8}, {68, 6}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, 451 | {98, 8}, {80, 8}, {141, 11}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, 452 | {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, 453 | {160, 5}, {65, 5}, {96, 8}, {78, 8}, {135, 11}, {72, 8}, {117, 11}, 454 | {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, 455 | {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, 456 | {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, 457 | {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, {94, 6}, 458 | {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, 459 | {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, {161, 6}, 460 | {66, 6}, {97, 7}, {79, 7}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, 461 | {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, {101, 7}, 462 | {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {156, 5}, {71, 7}, 463 | {152, 5}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {155, 4}, 464 | {69, 7}, {151, 4}, {147, 4}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, 465 | {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, 466 | {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, 467 | {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, {165, 6}, 468 | {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, {147, 4}, 469 | {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, {153, 6}, 470 | {149, 6}, {0, 0}, {0, 4}, {0, 5}, {0, 5}, {0, 4}, {0, 5}, 471 | {0, 4}, {0, 4}, {0, 5}, {0, 5}, {0, 3}, {0, 3}, {0, 5}, 472 | {0, 2}, {0, 5}, {0, 5}, {0, 0}, {0, 4}, {0, 3}, {0, 3}, 473 | {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, {0, 3}, 474 | {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, 475 | {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, 476 | {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, 477 | {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, {56, 9}, 478 | {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, 479 | {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, 480 | {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, {28, 9}, 481 | {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, 482 | {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, 483 | {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, 484 | {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, {82, 6}, 485 | {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, {110, 8}, 486 | {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, {14, 9}, 487 | {60, 10}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, {139, 9}, 488 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, 489 | {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, 490 | {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, {64, 4}, 491 | {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, 492 | {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, 493 | {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {49, 9}, 494 | {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, {70, 6}, 495 | {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, {121, 7}, 496 | {13, 9}, {58, 10}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, 497 | {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {35, 9}, 498 | {19, 9}, {119, 7}, {11, 9}, {54, 10}, {83, 7}, {160, 5}, {7, 9}, 499 | {46, 10}, {30, 10}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, {166, 7}, 500 | {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, {89, 9}, 501 | {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, 502 | {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, {67, 5}, 503 | {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, {129, 9}, 504 | {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, {74, 6}, 505 | {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, {99, 9}, 506 | {81, 9}, {142, 10}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, 507 | {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, {160, 5}, 508 | {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, {148, 5}, 509 | {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, 510 | {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, 511 | {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, 512 | {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, {24, 8}, 513 | {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {36, 8}, 514 | {20, 8}, {121, 7}, {12, 8}, {57, 10}, {85, 7}, {161, 6}, {66, 6}, 515 | {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, 516 | {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {53, 10}, {83, 7}, 517 | {160, 5}, {6, 8}, {45, 10}, {29, 10}, {130, 8}, {71, 7}, {112, 8}, 518 | {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, {69, 7}, 519 | {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, 520 | {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, {17, 8}, 521 | {118, 6}, {9, 8}, {51, 10}, {82, 6}, {160, 5}, {5, 8}, {43, 10}, 522 | {27, 10}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, {3, 8}, 523 | {39, 10}, {23, 10}, {122, 8}, {15, 10}, {104, 8}, {86, 8}, {161, 6}, 524 | {66, 6}, {98, 8}, {80, 8}, {140, 10}, {145, 2}, {153, 6}, {149, 6}, 525 | {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, {102, 8}, 526 | {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {134, 10}, {72, 8}, 527 | {116, 10}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, 528 | {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, {146, 3}, 529 | {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, 530 | {16, 7}, {118, 6}, {8, 7}, {100, 6}, {82, 6}, {160, 5}, {4, 7}, 531 | {94, 6}, {76, 6}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, 532 | {2, 7}, {92, 6}, {74, 6}, {121, 7}, {68, 6}, {103, 7}, {85, 7}, 533 | {161, 6}, {66, 6}, {97, 7}, {79, 7}, {138, 10}, {145, 2}, {153, 6}, 534 | {149, 6}, {0, 0}, {1, 7}, {91, 5}, {73, 5}, {119, 7}, {67, 5}, 535 | {101, 7}, {83, 7}, {160, 5}, {65, 5}, {95, 7}, {77, 7}, {132, 10}, 536 | {71, 7}, {114, 10}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, 537 | {126, 10}, {69, 7}, {108, 10}, {90, 10}, {162, 7}, {145, 2}, {150, 3}, 538 | {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, 539 | {91, 5}, {73, 5}, {118, 6}, {67, 5}, {100, 6}, {82, 6}, {160, 5}, 540 | {65, 5}, {94, 6}, {76, 6}, {156, 5}, {70, 6}, {152, 5}, {148, 5}, 541 | {165, 6}, {64, 4}, {92, 6}, {74, 6}, {155, 4}, {68, 6}, {151, 4}, 542 | {147, 4}, {161, 6}, {66, 6}, {150, 3}, {146, 3}, {157, 6}, {145, 2}, 543 | {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {155, 4}, 544 | {67, 5}, {151, 4}, {147, 4}, {160, 5}, {65, 5}, {150, 3}, {146, 3}, 545 | {156, 5}, {145, 2}, {152, 5}, {148, 5}, {169, 10}, {0, 4}, {0, 3}, 546 | {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, {0, 2}, 547 | {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, 548 | {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, {48, 8}, {82, 6}, 549 | {160, 5}, {4, 7}, {40, 8}, {24, 8}, {127, 7}, {70, 6}, {109, 7}, 550 | {148, 5}, {165, 6}, {2, 7}, {36, 8}, {20, 8}, {121, 7}, {12, 8}, 551 | {56, 9}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, {79, 7}, {136, 8}, 552 | {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, {34, 8}, {18, 8}, 553 | {119, 7}, {10, 8}, {52, 9}, {83, 7}, {160, 5}, {6, 8}, {44, 9}, 554 | {28, 9}, {130, 8}, {71, 7}, {112, 8}, {148, 5}, {166, 7}, {64, 4}, 555 | {93, 7}, {75, 7}, {124, 8}, {69, 7}, {106, 8}, {88, 8}, {162, 7}, 556 | {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, {154, 7}, {0, 0}, 557 | {0, 0}, {0, 6}, {33, 8}, {17, 8}, {118, 6}, {9, 8}, {50, 9}, 558 | {82, 6}, {160, 5}, {5, 8}, {42, 9}, {26, 9}, {128, 8}, {70, 6}, 559 | {110, 8}, {148, 5}, {165, 6}, {3, 8}, {38, 9}, {22, 9}, {122, 8}, 560 | {14, 9}, {104, 8}, {86, 8}, {161, 6}, {66, 6}, {98, 8}, {80, 8}, 561 | {139, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {64, 4}, {91, 5}, 562 | {73, 5}, {120, 8}, {67, 5}, {102, 8}, {84, 8}, {160, 5}, {65, 5}, 563 | {96, 8}, {78, 8}, {133, 9}, {72, 8}, {115, 9}, {148, 5}, {167, 8}, 564 | {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, {151, 4}, {147, 4}, 565 | {163, 8}, {145, 2}, {150, 3}, {146, 3}, {159, 8}, {0, 2}, {0, 0}, 566 | {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, {118, 6}, {8, 7}, 567 | {49, 9}, {82, 6}, {160, 5}, {4, 7}, {41, 9}, {25, 9}, {127, 7}, 568 | {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, {37, 9}, {21, 9}, 569 | {121, 7}, {13, 9}, {103, 7}, {85, 7}, {161, 6}, {66, 6}, {97, 7}, 570 | {79, 7}, {137, 9}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, {1, 7}, 571 | {35, 9}, {19, 9}, {119, 7}, {11, 9}, {101, 7}, {83, 7}, {160, 5}, 572 | {7, 9}, {95, 7}, {77, 7}, {131, 9}, {71, 7}, {113, 9}, {148, 5}, 573 | {166, 7}, {64, 4}, {93, 7}, {75, 7}, {125, 9}, {69, 7}, {107, 9}, 574 | {89, 9}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, {158, 7}, {145, 2}, 575 | {154, 7}, {0, 0}, {0, 0}, {0, 6}, {91, 5}, {73, 5}, {118, 6}, 576 | {67, 5}, {100, 6}, {82, 6}, {160, 5}, {65, 5}, {94, 6}, {76, 6}, 577 | {129, 9}, {70, 6}, {111, 9}, {148, 5}, {165, 6}, {64, 4}, {92, 6}, 578 | {74, 6}, {123, 9}, {68, 6}, {105, 9}, {87, 9}, {161, 6}, {66, 6}, 579 | {99, 9}, {81, 9}, {157, 6}, {145, 2}, {153, 6}, {149, 6}, {0, 0}, 580 | {64, 4}, {91, 5}, {73, 5}, {155, 4}, {67, 5}, {151, 4}, {147, 4}, 581 | {160, 5}, {65, 5}, {150, 3}, {146, 3}, {156, 5}, {145, 2}, {152, 5}, 582 | {148, 5}, {168, 9}, {64, 4}, {150, 3}, {146, 3}, {155, 4}, {145, 2}, 583 | {151, 4}, {147, 4}, {164, 9}, {0, 2}, {0, 3}, {0, 3}, {0, 0}, 584 | {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, {32, 7}, {16, 7}, 585 | {118, 6}, {8, 7}, {48, 8}, {82, 6}, {160, 5}, {4, 7}, {40, 8}, 586 | {24, 8}, {127, 7}, {70, 6}, {109, 7}, {148, 5}, {165, 6}, {2, 7}, 587 | {36, 8}, {20, 8}, {121, 7}, {12, 8}, {103, 7}, {85, 7}, {161, 6}, 588 | {66, 6}, {97, 7}, {79, 7}, {136, 8}, {145, 2}, {153, 6}, {149, 6}, 589 | {0, 0}, {1, 7}, {34, 8}, {18, 8}, {119, 7}, {10, 8}, {101, 7}, 590 | {83, 7}, {160, 5}, {6, 8}, {95, 7}, {77, 7}, {130, 8}, {71, 7}, 591 | {112, 8}, {148, 5}, {166, 7}, {64, 4}, {93, 7}, {75, 7}, {124, 8}, 592 | {69, 7}, {106, 8}, {88, 8}, {162, 7}, {145, 2}, {150, 3}, {146, 3}, 593 | {158, 7}, {145, 2}, {154, 7}, {0, 0}, {0, 0}, {0, 6}, {33, 8}, 594 | {17, 8}, {118, 6}, {9, 8}, {100, 6}, {82, 6}, {160, 5}, {5, 8}, 595 | {94, 6}, {76, 6}, {128, 8}, {70, 6}, {110, 8}, {148, 5}, {165, 6}, 596 | {3, 8}, {92, 6}, {74, 6}, {122, 8}, {68, 6}, {104, 8}, {86, 8}, 597 | {161, 6}, {66, 6}, {98, 8}, {80, 8}, {157, 6}, {145, 2}, {153, 6}, 598 | {149, 6}, {0, 0}, {64, 4}, {91, 5}, {73, 5}, {120, 8}, {67, 5}, 599 | {102, 8}, {84, 8}, {160, 5}, {65, 5}, {96, 8}, {78, 8}, {156, 5}, 600 | {72, 8}, {152, 5}, {148, 5}, {167, 8}, {64, 4}, {150, 3}, {146, 3}, 601 | {155, 4}, {145, 2}, {151, 4}, {147, 4}, {163, 8}, {145, 2}, {150, 3}, 602 | {146, 3}, {159, 8}, {0, 2}, {0, 0}, {0, 0}, {0, 0}, {0, 6}, 603 | {0, 7}, {0, 7}, {0, 6}, {0, 7}, {0, 6}, {0, 6}, {0, 5}, 604 | {0, 7}, {0, 6}, {0, 6}, {0, 7}, {0, 6}, {0, 7}, {0, 5}, 605 | {0, 6}, {0, 7}, {0, 6}, {0, 6}, {0, 7}, {0, 6}, {0, 7}, 606 | {0, 7}, {0, 6}, {0, 6}, {0, 7}, {0, 7}, {0, 6}, {0, 2}, 607 | {0, 6}, {0, 6}, {0, 0}, {0, 7}, {0, 5}, {0, 5}, {0, 7}, 608 | {0, 5}, {0, 7}, {0, 7}, {0, 5}, {0, 5}, {0, 7}, {0, 7}, 609 | {0, 5}, {0, 7}, {0, 5}, {0, 5}, {0, 7}, {0, 4}, {0, 7}, 610 | {0, 7}, {0, 4}, {0, 7}, {0, 4}, {0, 4}, {0, 7}, {0, 2}, 611 | {0, 3}, {0, 3}, {0, 7}, {0, 2}, {0, 7}, {0, 0}, {0, 0}, 612 | {0, 6}, {0, 5}, {0, 5}, {0, 6}, {0, 5}, {0, 6}, {0, 6}, 613 | {0, 5}, {0, 5}, {0, 6}, {0, 6}, {0, 5}, {0, 6}, {0, 5}, 614 | {0, 5}, {0, 6}, {0, 4}, {0, 6}, {0, 6}, {0, 4}, {0, 6}, 615 | {0, 4}, {0, 4}, {0, 6}, {0, 6}, {0, 3}, {0, 3}, {0, 6}, 616 | {0, 2}, {0, 6}, {0, 6}, {0, 0}, {0, 4}, {0, 5}, {0, 5}, 617 | {0, 4}, {0, 5}, {0, 4}, {0, 4}, {0, 5}, {0, 5}, {0, 3}, 618 | {0, 3}, {0, 5}, {0, 2}, {0, 5}, {0, 5}, {0, 0}, {0, 4}, 619 | {0, 3}, {0, 3}, {0, 4}, {0, 2}, {0, 4}, {0, 4}, {0, 0}, 620 | {0, 2}, {0, 3}, {0, 3}, {0, 0}, {0, 2}, {0, 0}, {0, 0}, 621 | {0, 0} 622 | }; 623 | 624 | 625 | static const int8_t vectorsrawbytes[] ALIGNED(0x1000) = { 626 | 0, -1, 4, -1, 1, -1, 5, -1, 2, -1, -1, -1, 3, -1, -1, -1, // 0 627 | 0, -1, 4, -1, 1, -1, 5, 6, 2, -1, -1, -1, 3, -1, -1, -1, // 1 628 | 0, -1, 4, 5, 1, -1, 6, -1, 2, -1, -1, -1, 3, -1, -1, -1, // 2 629 | 0, -1, 4, 5, 1, -1, 6, 7, 2, -1, -1, -1, 3, -1, -1, -1, // 3 630 | 0, -1, 5, -1, 1, -1, 6, -1, 2, -1, -1, -1, 3, 4, -1, -1, // 4 631 | 0, -1, 5, -1, 1, -1, 6, 7, 2, -1, -1, -1, 3, 4, -1, -1, // 5 632 | 0, -1, 5, 6, 1, -1, 7, -1, 2, -1, -1, -1, 3, 4, -1, -1, // 6 633 | 0, -1, 5, 6, 1, -1, 7, 8, 2, -1, -1, -1, 3, 4, -1, -1, // 7 634 | 0, -1, 5, -1, 1, -1, 6, -1, 2, 3, -1, -1, 4, -1, -1, -1, // 8 635 | 0, -1, 5, -1, 1, -1, 6, 7, 2, 3, -1, -1, 4, -1, -1, -1, // 9 636 | 0, -1, 5, 6, 1, -1, 7, -1, 2, 3, -1, -1, 4, -1, -1, -1, // 10 637 | 0, -1, 5, 6, 1, -1, 7, 8, 2, 3, -1, -1, 4, -1, -1, -1, // 11 638 | 0, -1, 6, -1, 1, -1, 7, -1, 2, 3, -1, -1, 4, 5, -1, -1, // 12 639 | 0, -1, 6, -1, 1, -1, 7, 8, 2, 3, -1, -1, 4, 5, -1, -1, // 13 640 | 0, -1, 6, 7, 1, -1, 8, -1, 2, 3, -1, -1, 4, 5, -1, -1, // 14 641 | 0, -1, 6, 7, 1, -1, 8, 9, 2, 3, -1, -1, 4, 5, -1, -1, // 15 642 | 0, -1, 5, -1, 1, 2, 6, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 16 643 | 0, -1, 5, -1, 1, 2, 6, 7, 3, -1, -1, -1, 4, -1, -1, -1, // 17 644 | 0, -1, 5, 6, 1, 2, 7, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 18 645 | 0, -1, 5, 6, 1, 2, 7, 8, 3, -1, -1, -1, 4, -1, -1, -1, // 19 646 | 0, -1, 6, -1, 1, 2, 7, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 20 647 | 0, -1, 6, -1, 1, 2, 7, 8, 3, -1, -1, -1, 4, 5, -1, -1, // 21 648 | 0, -1, 6, 7, 1, 2, 8, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 22 649 | 0, -1, 6, 7, 1, 2, 8, 9, 3, -1, -1, -1, 4, 5, -1, -1, // 23 650 | 0, -1, 6, -1, 1, 2, 7, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 24 651 | 0, -1, 6, -1, 1, 2, 7, 8, 3, 4, -1, -1, 5, -1, -1, -1, // 25 652 | 0, -1, 6, 7, 1, 2, 8, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 26 653 | 0, -1, 6, 7, 1, 2, 8, 9, 3, 4, -1, -1, 5, -1, -1, -1, // 27 654 | 0, -1, 7, -1, 1, 2, 8, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 28 655 | 0, -1, 7, -1, 1, 2, 8, 9, 3, 4, -1, -1, 5, 6, -1, -1, // 29 656 | 0, -1, 7, 8, 1, 2, 9, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 30 657 | 0, -1, 7, 8, 1, 2, 9, 10, 3, 4, -1, -1, 5, 6, -1, -1, // 31 658 | 0, 1, 5, -1, 2, -1, 6, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 32 659 | 0, 1, 5, -1, 2, -1, 6, 7, 3, -1, -1, -1, 4, -1, -1, -1, // 33 660 | 0, 1, 5, 6, 2, -1, 7, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 34 661 | 0, 1, 5, 6, 2, -1, 7, 8, 3, -1, -1, -1, 4, -1, -1, -1, // 35 662 | 0, 1, 6, -1, 2, -1, 7, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 36 663 | 0, 1, 6, -1, 2, -1, 7, 8, 3, -1, -1, -1, 4, 5, -1, -1, // 37 664 | 0, 1, 6, 7, 2, -1, 8, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 38 665 | 0, 1, 6, 7, 2, -1, 8, 9, 3, -1, -1, -1, 4, 5, -1, -1, // 39 666 | 0, 1, 6, -1, 2, -1, 7, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 40 667 | 0, 1, 6, -1, 2, -1, 7, 8, 3, 4, -1, -1, 5, -1, -1, -1, // 41 668 | 0, 1, 6, 7, 2, -1, 8, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 42 669 | 0, 1, 6, 7, 2, -1, 8, 9, 3, 4, -1, -1, 5, -1, -1, -1, // 43 670 | 0, 1, 7, -1, 2, -1, 8, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 44 671 | 0, 1, 7, -1, 2, -1, 8, 9, 3, 4, -1, -1, 5, 6, -1, -1, // 45 672 | 0, 1, 7, 8, 2, -1, 9, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 46 673 | 0, 1, 7, 8, 2, -1, 9, 10, 3, 4, -1, -1, 5, 6, -1, -1, // 47 674 | 0, 1, 6, -1, 2, 3, 7, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 48 675 | 0, 1, 6, -1, 2, 3, 7, 8, 4, -1, -1, -1, 5, -1, -1, -1, // 49 676 | 0, 1, 6, 7, 2, 3, 8, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 50 677 | 0, 1, 6, 7, 2, 3, 8, 9, 4, -1, -1, -1, 5, -1, -1, -1, // 51 678 | 0, 1, 7, -1, 2, 3, 8, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 52 679 | 0, 1, 7, -1, 2, 3, 8, 9, 4, -1, -1, -1, 5, 6, -1, -1, // 53 680 | 0, 1, 7, 8, 2, 3, 9, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 54 681 | 0, 1, 7, 8, 2, 3, 9, 10, 4, -1, -1, -1, 5, 6, -1, -1, // 55 682 | 0, 1, 7, -1, 2, 3, 8, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 56 683 | 0, 1, 7, -1, 2, 3, 8, 9, 4, 5, -1, -1, 6, -1, -1, -1, // 57 684 | 0, 1, 7, 8, 2, 3, 9, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 58 685 | 0, 1, 7, 8, 2, 3, 9, 10, 4, 5, -1, -1, 6, -1, -1, -1, // 59 686 | 0, 1, 8, -1, 2, 3, 9, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 60 687 | 0, 1, 8, -1, 2, 3, 9, 10, 4, 5, -1, -1, 6, 7, -1, -1, // 61 688 | 0, 1, 8, 9, 2, 3, 10, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 62 689 | 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, -1, -1, 6, 7, -1, -1, // 63 690 | 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, // 64 691 | 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, // 65 692 | 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, // 66 693 | 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, // 67 694 | 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, // 68 695 | 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, // 69 696 | 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, // 70 697 | 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, // 71 698 | 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, // 72 699 | 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 73 700 | 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 74 701 | 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, 6, -1, // 75 702 | 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 76 703 | 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 77 704 | 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, 7, -1, // 78 705 | 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, -1, -1, -1, // 79 706 | 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, -1, -1, // 80 707 | 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, 8, -1, // 81 708 | 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 82 709 | 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 83 710 | 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, 7, -1, // 84 711 | 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 85 712 | 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 86 713 | 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, 8, -1, // 87 714 | 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, -1, -1, -1, // 88 715 | 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, -1, -1, // 89 716 | 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, 9, -1, // 90 717 | 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1, // 91 718 | 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1, // 92 719 | 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, 6, -1, // 93 720 | 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, // 94 721 | 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1, // 95 722 | 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, 7, -1, // 96 723 | 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, -1, -1, -1, // 97 724 | 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, -1, -1, // 98 725 | 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, 8, -1, // 99 726 | 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 100 727 | 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 101 728 | 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, 7, -1, // 102 729 | 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 103 730 | 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 104 731 | 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, 8, -1, // 105 732 | 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, -1, -1, -1, // 106 733 | 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1, // 107 734 | 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, 9, -1, // 108 735 | 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, -1, -1, -1, // 109 736 | 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, -1, -1, // 110 737 | 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, 8, -1, // 111 738 | 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, -1, -1, -1, // 112 739 | 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, -1, -1, // 113 740 | 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, 9, -1, // 114 741 | 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, -1, -1, -1, // 115 742 | 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, -1, -1, // 116 743 | 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, 10, -1, // 117 744 | 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1, // 118 745 | 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1, // 119 746 | 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, 7, -1, // 120 747 | 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1, // 121 748 | 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1, // 122 749 | 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, 8, -1, // 123 750 | 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, -1, -1, -1, // 124 751 | 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1, // 125 752 | 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, 9, -1, // 126 753 | 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, -1, -1, -1, // 127 754 | 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, -1, -1, // 128 755 | 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, 8, -1, // 129 756 | 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, -1, -1, -1, // 130 757 | 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, -1, -1, // 131 758 | 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, 9, -1, // 132 759 | 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, -1, -1, -1, // 133 760 | 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, -1, -1, // 134 761 | 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, 10, -1, // 135 762 | 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, -1, -1, -1, // 136 763 | 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, -1, -1, // 137 764 | 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, 9, -1, // 138 765 | 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, -1, -1, -1, // 139 766 | 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, -1, -1, // 140 767 | 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, 10, -1, // 141 768 | 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, -1, -1, -1, // 142 769 | 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, -1, -1, // 143 770 | 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, -1, // 144 771 | -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 1, // 145 772 | -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, -1, -1, -1, -1, -1, 1, // 146 773 | -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, 3, -1, -1, -1, -1, 1, // 147 774 | -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, 3, -1, 4, -1, -1, 1, // 148 775 | -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, 3, -1, 4, -1, 5, 1, // 149 776 | 1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 2, // 150 777 | 1, -1, -1, -1, -1, -1, -1, 0, 3, -1, -1, -1, -1, -1, -1, 2, // 151 778 | 1, -1, -1, -1, -1, -1, -1, 0, 3, -1, 4, -1, -1, -1, -1, 2, // 152 779 | 1, -1, -1, -1, -1, -1, -1, 0, 3, -1, 4, -1, 5, -1, -1, 2, // 153 780 | 1, -1, -1, -1, -1, -1, -1, 0, 3, -1, 4, -1, 5, -1, 6, 2, // 154 781 | 1, -1, 2, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 3, // 155 782 | 1, -1, 2, -1, -1, -1, -1, 0, 4, -1, -1, -1, -1, -1, -1, 3, // 156 783 | 1, -1, 2, -1, -1, -1, -1, 0, 4, -1, 5, -1, -1, -1, -1, 3, // 157 784 | 1, -1, 2, -1, -1, -1, -1, 0, 4, -1, 5, -1, 6, -1, -1, 3, // 158 785 | 1, -1, 2, -1, -1, -1, -1, 0, 4, -1, 5, -1, 6, -1, 7, 3, // 159 786 | 1, -1, 2, -1, 3, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 4, // 160 787 | 1, -1, 2, -1, 3, -1, -1, 0, 5, -1, -1, -1, -1, -1, -1, 4, // 161 788 | 1, -1, 2, -1, 3, -1, -1, 0, 5, -1, 6, -1, -1, -1, -1, 4, // 162 789 | 1, -1, 2, -1, 3, -1, -1, 0, 5, -1, 6, -1, 7, -1, -1, 4, // 163 790 | 1, -1, 2, -1, 3, -1, -1, 0, 5, -1, 6, -1, 7, -1, 8, 4, // 164 791 | 1, -1, 2, -1, 3, -1, 4, 0, -1, -1, -1, -1, -1, -1, -1, 5, // 165 792 | 1, -1, 2, -1, 3, -1, 4, 0, 6, -1, -1, -1, -1, -1, -1, 5, // 166 793 | 1, -1, 2, -1, 3, -1, 4, 0, 6, -1, 7, -1, -1, -1, -1, 5, // 167 794 | 1, -1, 2, -1, 3, -1, 4, 0, 6, -1, 7, -1, 8, -1, -1, 5, // 168 795 | 1, -1, 2, -1, 3, -1, 4, 0, 6, -1, 7, -1, 8, -1, 9, 5, // 169 796 | }; 797 | 798 | static const __m128i* vectors = (const __m128i*)vectorsrawbytes; 799 | 800 | static int read_int(const uint8_t* in, uint32_t* out) { 801 | *out = in[0] & 0x7F; 802 | if (in[0] < 128) { 803 | return 1; 804 | } 805 | *out = ((in[1] & 0x7FU) << 7) | *out; 806 | if (in[1] < 128) { 807 | return 2; 808 | } 809 | *out = ((in[2] & 0x7FU) << 14) | *out; 810 | if (in[2] < 128) { 811 | return 3; 812 | } 813 | *out = ((in[3] & 0x7FU) << 21) | *out; 814 | if (in[3] < 128) { 815 | return 4; 816 | } 817 | *out = ((in[4] & 0x7FU) << 28) | *out; 818 | return 5; 819 | } 820 | 821 | static inline int read_int_delta(const uint8_t* in, uint32_t* out, uint32_t* prev) { 822 | *out = in[0] & 0x7F; 823 | if (in[0] < 128) { 824 | *prev += *out; 825 | *out = *prev; 826 | return 1; 827 | } 828 | *out = ((in[1] & 0x7FU) << 7) | *out; 829 | if (in[1] < 128) { 830 | *prev += *out; 831 | *out = *prev; 832 | return 2; 833 | } 834 | *out = ((in[2] & 0x7FU) << 14) | *out; 835 | if (in[2] < 128) { 836 | *prev += *out; 837 | *out = *prev; 838 | return 3; 839 | } 840 | *out = ((in[3] & 0x7FU) << 21) | *out; 841 | if (in[3] < 128) { 842 | *prev += *out; 843 | *out = *prev; 844 | return 4; 845 | } 846 | *out = ((in[4] & 0x7FU) << 28) | *out; 847 | *prev += *out; 848 | *out = *prev; 849 | return 5; 850 | } 851 | 852 | 853 | static uint64_t masked_vbyte_read_group(const uint8_t* in, uint32_t* out, 854 | uint64_t mask, uint64_t* ints_read) { 855 | __m128i initial = _mm_lddqu_si128((const __m128i *) (in)); 856 | __m128i * mout = (__m128i *) out; 857 | 858 | if (!(mask & 0xFFFF)) { 859 | __m128i result = _mm_cvtepi8_epi32(initial); 860 | _mm_storeu_si128(mout, result); 861 | initial = _mm_srli_si128(initial, 4); 862 | result = _mm_cvtepi8_epi32(initial); 863 | _mm_storeu_si128(mout + 1, result); 864 | initial = _mm_srli_si128(initial, 4); 865 | result = _mm_cvtepi8_epi32(initial); 866 | _mm_storeu_si128(mout + 2, result); 867 | initial = _mm_srli_si128(initial, 4); 868 | result = _mm_cvtepi8_epi32(initial); 869 | _mm_storeu_si128(mout + 3, result); 870 | *ints_read = 16; 871 | return 16; 872 | } 873 | 874 | uint32_t low_12_bits = mask & 0xFFF; 875 | // combine index and bytes consumed into a single lookup 876 | index_bytes_consumed combined = combined_lookup[low_12_bits]; 877 | uint64_t consumed = combined.bytes_consumed; 878 | uint8_t index = combined.index; 879 | 880 | __m128i shuffle_vector = vectors[index]; 881 | 882 | if (index < 64) { 883 | *ints_read = 6; 884 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 885 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 886 | _mm_set1_epi16(0x007F)); 887 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 888 | _mm_set1_epi16(0x7F00)); 889 | __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); 890 | __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); 891 | __m128i unpacked_result_a = _mm_and_si128(packed_result, 892 | _mm_set1_epi32(0x0000FFFF)); 893 | _mm_storeu_si128(mout, unpacked_result_a); 894 | __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); 895 | _mm_storel_epi64(mout+1, unpacked_result_b); 896 | //_mm_storeu_si128(mout + 1, unpacked_result_b); // maybe faster to write 16 bytes? 897 | return consumed; 898 | } 899 | if (index < 145) { 900 | 901 | *ints_read = 4; 902 | 903 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 904 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 905 | _mm_set1_epi32(0x0000007F)); 906 | __m128i middle_bytes = _mm_and_si128(bytes_to_decode, 907 | _mm_set1_epi32(0x00007F00)); 908 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 909 | _mm_set1_epi32(0x007F0000)); 910 | __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); 911 | __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); 912 | __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); 913 | __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); 914 | _mm_storeu_si128(mout, result); 915 | return consumed; 916 | } 917 | 918 | *ints_read = 2; 919 | 920 | __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); 921 | __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); 922 | __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, 923 | _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); 924 | __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); 925 | __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); 926 | __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); 927 | __m128i result_evens = _mm_or_si128(recombined, low_byte); 928 | __m128i result = _mm_shuffle_epi8(result_evens, 929 | _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, 930 | -1)); 931 | _mm_storel_epi64(mout, result); 932 | //_mm_storeu_si128(mout, result); // maybe faster to write 16 bytes? 933 | 934 | return consumed; 935 | } 936 | 937 | static inline __m128i PrefixSum(__m128i curr, __m128i prev) { 938 | __m128i Add = _mm_slli_si128(curr, 4); // Cycle 1: [- A B C] (already done) 939 | prev = _mm_shuffle_epi32(prev, 0xff); // Cycle 2: [P P P P] 940 | curr = _mm_add_epi32(curr, Add); // Cycle 2: [A AB BC CD] 941 | Add = _mm_slli_si128(curr, 8); // Cycle 3: [- - A AB] 942 | curr = _mm_add_epi32(curr, prev); // Cycle 3: [PA PAB PBC PCD] 943 | curr = _mm_add_epi32(curr, Add); // Cycle 4: [PA PAB PABC PABCD] 944 | return curr; 945 | } 946 | 947 | // only the first two ints of curr are meaningful, rest is garbage to beignored 948 | static inline __m128i PrefixSum2ints(__m128i curr, __m128i prev) { 949 | __m128i Add = _mm_slli_si128(curr, 4); // Cycle 1: [- A B G] (already done) 950 | prev = _mm_shuffle_epi32(prev, 0xff); // Cycle 2: [P P P P] 951 | curr = _mm_add_epi32(curr, Add); // Cycle 2: [A AB BG GG] 952 | curr = _mm_shuffle_epi32(curr, 0x54); //Cycle 3:[A AB AB AB] 953 | curr = _mm_add_epi32(curr, prev); // Cycle 4: [PA PAB PAB PAB] 954 | return curr; 955 | } 956 | 957 | static uint64_t masked_vbyte_read_group_delta(const uint8_t* in, uint32_t* out, 958 | uint64_t mask, uint64_t* ints_read, __m128i * prev) { 959 | __m128i initial = _mm_lddqu_si128((const __m128i *) (in)); 960 | __m128i * mout = (__m128i *) out; 961 | 962 | if (!(mask & 0xFFFF)) { 963 | __m128i result = _mm_cvtepi8_epi32(initial); 964 | *prev = PrefixSum(result, *prev); 965 | _mm_storeu_si128(mout, *prev); 966 | initial = _mm_srli_si128(initial, 4); 967 | result = _mm_cvtepi8_epi32(initial); 968 | *prev = PrefixSum(result, *prev); 969 | _mm_storeu_si128(mout + 1, *prev); 970 | initial = _mm_srli_si128(initial, 4); 971 | result = _mm_cvtepi8_epi32(initial); 972 | *prev = PrefixSum(result, *prev); 973 | _mm_storeu_si128(mout + 2, *prev); 974 | initial = _mm_srli_si128(initial, 4); 975 | result = _mm_cvtepi8_epi32(initial); 976 | *prev = PrefixSum(result, *prev); 977 | _mm_storeu_si128(mout + 3, *prev); 978 | *ints_read = 16; 979 | return 16; 980 | } 981 | 982 | uint32_t low_12_bits = mask & 0xFFF; 983 | // combine index and bytes consumed into a single lookup 984 | index_bytes_consumed combined = combined_lookup[low_12_bits]; 985 | uint64_t consumed = combined.bytes_consumed; 986 | uint8_t index = combined.index; 987 | 988 | __m128i shuffle_vector = vectors[index]; 989 | 990 | if (index < 64) { 991 | *ints_read = 6; 992 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 993 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 994 | _mm_set1_epi16(0x007F)); 995 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 996 | _mm_set1_epi16(0x7F00)); 997 | __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); 998 | __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); 999 | __m128i unpacked_result_a = _mm_and_si128(packed_result, 1000 | _mm_set1_epi32(0x0000FFFF)); 1001 | *prev = PrefixSum(unpacked_result_a, *prev); 1002 | _mm_storeu_si128(mout, *prev); 1003 | __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); 1004 | *prev = PrefixSum2ints(unpacked_result_b, *prev); 1005 | _mm_storel_epi64(mout + 1, *prev); 1006 | return consumed; 1007 | } 1008 | if (index < 145) { 1009 | 1010 | *ints_read = 4; 1011 | 1012 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 1013 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 1014 | _mm_set1_epi32(0x0000007F)); 1015 | __m128i middle_bytes = _mm_and_si128(bytes_to_decode, 1016 | _mm_set1_epi32(0x00007F00)); 1017 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 1018 | _mm_set1_epi32(0x007F0000)); 1019 | __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); 1020 | __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); 1021 | __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); 1022 | __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); 1023 | *prev = PrefixSum(result, *prev); 1024 | _mm_storeu_si128(mout, *prev); 1025 | return consumed; 1026 | } 1027 | 1028 | *ints_read = 2; 1029 | 1030 | __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); 1031 | __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); 1032 | __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, 1033 | _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); 1034 | __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); 1035 | __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); 1036 | __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); 1037 | __m128i result_evens = _mm_or_si128(recombined, low_byte); 1038 | __m128i result = _mm_shuffle_epi8(result_evens, 1039 | _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, 1040 | -1)); 1041 | *prev = PrefixSum2ints(result, *prev); 1042 | _mm_storel_epi64(mout, *prev); 1043 | return consumed; 1044 | } 1045 | 1046 | 1047 | static int read_int_group(const uint8_t* in, uint32_t* out, int* ints_read) { 1048 | 1049 | __m128i initial = _mm_lddqu_si128((const __m128i *) in); 1050 | __m128i * const mout = (__m128i *) out; 1051 | 1052 | int mask = _mm_movemask_epi8(initial); 1053 | if (mask == 0) { 1054 | __m128i result; 1055 | result = _mm_cvtepi8_epi32(initial); 1056 | initial = _mm_srli_si128(initial, 4); 1057 | _mm_storeu_si128(mout, result); 1058 | result = _mm_cvtepi8_epi32(initial); 1059 | initial = _mm_srli_si128(initial, 4); 1060 | _mm_storeu_si128(mout + 1, result); 1061 | result = _mm_cvtepi8_epi32(initial); 1062 | initial = _mm_srli_si128(initial, 4); 1063 | _mm_storeu_si128(mout + 2, result); 1064 | result = _mm_cvtepi8_epi32(initial); 1065 | _mm_storeu_si128(mout + 3, result); 1066 | *ints_read = 16; 1067 | return 16; 1068 | } 1069 | int mask2 = mask & 0xFFF; 1070 | index_bytes_consumed combined = combined_lookup[mask2]; 1071 | 1072 | int index = combined.index; 1073 | 1074 | __m128i shuffle_vector = vectors[index]; 1075 | int consumed = combined.bytes_consumed; 1076 | 1077 | if (index < 64) { 1078 | *ints_read = 6; 1079 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 1080 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 1081 | _mm_set1_epi16(0x007F)); 1082 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 1083 | _mm_set1_epi16(0x7F00)); 1084 | __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); 1085 | __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); 1086 | __m128i unpacked_result_a = _mm_and_si128(packed_result, 1087 | _mm_set1_epi32(0x0000FFFF)); 1088 | _mm_storeu_si128(mout, unpacked_result_a); 1089 | __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); 1090 | _mm_storel_epi64(mout + 1, unpacked_result_b); 1091 | return consumed; 1092 | } 1093 | if (index < 145) { 1094 | 1095 | *ints_read = 4; 1096 | 1097 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 1098 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 1099 | _mm_set1_epi32(0x0000007F)); 1100 | __m128i middle_bytes = _mm_and_si128(bytes_to_decode, 1101 | _mm_set1_epi32(0x00007F00)); 1102 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 1103 | _mm_set1_epi32(0x007F0000)); 1104 | __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); 1105 | __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); 1106 | __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); 1107 | __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); 1108 | _mm_storeu_si128(mout, result); 1109 | return consumed; 1110 | } 1111 | 1112 | *ints_read = 2; 1113 | 1114 | __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); 1115 | __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); 1116 | __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, 1117 | _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); 1118 | __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); 1119 | __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); 1120 | __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); 1121 | __m128i result_evens = _mm_or_si128(recombined, low_byte); 1122 | __m128i result = _mm_shuffle_epi8(result_evens, 1123 | _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, 1124 | -1)); 1125 | 1126 | _mm_storel_epi64(mout, result); 1127 | return consumed; 1128 | } 1129 | 1130 | 1131 | // len_signed : number of ints we want to decode 1132 | size_t masked_vbyte_decode(const uint8_t* in, uint32_t* out, 1133 | uint64_t length) { 1134 | size_t consumed = 0; // number of bytes read 1135 | uint64_t count = 0; // how many integers we have read so far 1136 | 1137 | uint64_t sig = 0; 1138 | int availablebytes = 0; 1139 | if (96 < length) { 1140 | size_t scanned = 0; 1141 | 1142 | 1143 | #ifdef __AVX2__ 1144 | __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1145 | uint32_t lowSig = _mm256_movemask_epi8(low); 1146 | #else 1147 | __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1148 | uint32_t lowSig1 = _mm_movemask_epi8(low1); 1149 | __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1150 | uint32_t lowSig2 = _mm_movemask_epi8(low2); 1151 | uint32_t lowSig = lowSig2 << 16; 1152 | lowSig |= lowSig1; 1153 | #endif 1154 | 1155 | // excess verbosity to avoid problems with sign extension on conversions 1156 | // better to think about what's happening and make it clearer 1157 | __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1158 | uint32_t highSig = _mm_movemask_epi8(high); 1159 | uint64_t nextSig = highSig; 1160 | nextSig <<= 32; 1161 | nextSig |= lowSig; 1162 | scanned += 48; 1163 | 1164 | do { 1165 | uint64_t thisSig = nextSig; 1166 | 1167 | #ifdef __AVX2__ 1168 | low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1169 | lowSig = _mm256_movemask_epi8(low); 1170 | #else 1171 | low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1172 | lowSig1 = _mm_movemask_epi8(low1); 1173 | low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1174 | lowSig2 = _mm_movemask_epi8(low2); 1175 | lowSig = lowSig2 << 16; 1176 | lowSig |= lowSig1; 1177 | #endif 1178 | 1179 | high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1180 | highSig = _mm_movemask_epi8(high); 1181 | nextSig = highSig; 1182 | nextSig <<= 32; 1183 | nextSig |= lowSig; 1184 | 1185 | uint64_t remaining = scanned - (consumed + 48); 1186 | sig = (thisSig << remaining) | sig; 1187 | 1188 | uint64_t reload = scanned - 16; 1189 | scanned += 48; 1190 | 1191 | // need to reload when less than 16 scanned bytes remain in sig 1192 | while (consumed < reload) { 1193 | uint64_t ints_read; 1194 | uint64_t bytes = masked_vbyte_read_group(in + consumed, 1195 | out + count, sig, &ints_read); 1196 | sig >>= bytes; 1197 | 1198 | // seems like this might force the compiler to prioritize shifting sig >>= bytes 1199 | if (sig == 0xFFFFFFFFFFFFFFFF) 1200 | return 0; // fake check to force earliest evaluation 1201 | 1202 | consumed += bytes; 1203 | count += ints_read; 1204 | } 1205 | } while (count + 112 < length); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig 1206 | sig = (nextSig << (scanned - consumed - 48)) | sig; 1207 | availablebytes = scanned - consumed; 1208 | } 1209 | while (availablebytes + count < length) { 1210 | if (availablebytes < 16) { 1211 | if (availablebytes + count + 31 < length) { 1212 | #ifdef __AVX2__ 1213 | uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); 1214 | sig |= (newsigavx << availablebytes); 1215 | #else 1216 | uint64_t newsig = _mm_movemask_epi8( 1217 | _mm_lddqu_si128( 1218 | (const __m128i *) (in + availablebytes 1219 | + consumed))); 1220 | uint64_t newsig2 = _mm_movemask_epi8( 1221 | _mm_lddqu_si128( 1222 | (const __m128i *) (in + availablebytes + 16 1223 | + consumed))); 1224 | sig |= (newsig << availablebytes) 1225 | | (newsig2 << (availablebytes + 16)); 1226 | #endif 1227 | availablebytes += 32; 1228 | } else if (availablebytes + count + 15 < length) { 1229 | int newsig = _mm_movemask_epi8( 1230 | _mm_lddqu_si128( 1231 | (const __m128i *) (in + availablebytes 1232 | + consumed))); 1233 | sig |= newsig << availablebytes; 1234 | availablebytes += 16; 1235 | } else { 1236 | break; 1237 | } 1238 | } 1239 | uint64_t ints_read; 1240 | 1241 | uint64_t eaten = masked_vbyte_read_group(in + consumed, out + count, 1242 | sig, &ints_read); 1243 | consumed += eaten; 1244 | availablebytes -= eaten; 1245 | sig >>= eaten; 1246 | count += ints_read; 1247 | } 1248 | for (; count < length; count++) { 1249 | consumed += read_int(in + consumed, out + count); 1250 | } 1251 | return consumed; 1252 | } 1253 | 1254 | 1255 | // inputsize : number of input bytes we want to decode 1256 | // returns the number of written ints 1257 | size_t masked_vbyte_decode_fromcompressedsize(const uint8_t* in, uint32_t* out, 1258 | size_t inputsize) { 1259 | size_t consumed = 0; // number of bytes read 1260 | uint32_t * initout = out; 1261 | 1262 | uint64_t sig = 0; 1263 | int availablebytes = 0; 1264 | if (96 < inputsize) { 1265 | size_t scanned = 0; 1266 | 1267 | 1268 | #ifdef __AVX2__ 1269 | __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1270 | uint32_t lowSig = _mm256_movemask_epi8(low); 1271 | #else 1272 | __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1273 | uint32_t lowSig1 = _mm_movemask_epi8(low1); 1274 | __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1275 | uint32_t lowSig2 = _mm_movemask_epi8(low2); 1276 | uint32_t lowSig = lowSig2 << 16; 1277 | lowSig |= lowSig1; 1278 | #endif 1279 | 1280 | // excess verbosity to avoid problems with sign extension on conversions 1281 | // better to think about what's happening and make it clearer 1282 | __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1283 | uint32_t highSig = _mm_movemask_epi8(high); 1284 | uint64_t nextSig = highSig; 1285 | nextSig <<= 32; 1286 | nextSig |= lowSig; 1287 | scanned += 48; 1288 | 1289 | do { 1290 | uint64_t thisSig = nextSig; 1291 | 1292 | #ifdef __AVX2__ 1293 | low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1294 | lowSig = _mm256_movemask_epi8(low); 1295 | #else 1296 | low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1297 | lowSig1 = _mm_movemask_epi8(low1); 1298 | low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1299 | lowSig2 = _mm_movemask_epi8(low2); 1300 | lowSig = lowSig2 << 16; 1301 | lowSig |= lowSig1; 1302 | #endif 1303 | 1304 | high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1305 | highSig = _mm_movemask_epi8(high); 1306 | nextSig = highSig; 1307 | nextSig <<= 32; 1308 | nextSig |= lowSig; 1309 | 1310 | uint64_t remaining = scanned - (consumed + 48); 1311 | sig = (thisSig << remaining) | sig; 1312 | 1313 | uint64_t reload = scanned - 16; 1314 | scanned += 48; 1315 | 1316 | // need to reload when less than 16 scanned bytes remain in sig 1317 | while (consumed < reload) { 1318 | uint64_t ints_read; 1319 | uint64_t bytes = masked_vbyte_read_group(in + consumed, 1320 | out, sig, &ints_read); 1321 | sig >>= bytes; 1322 | 1323 | // seems like this might force the compiler to prioritize shifting sig >>= bytes 1324 | if (sig == 0xFFFFFFFFFFFFFFFF) 1325 | return 0; // fake check to force earliest evaluation 1326 | 1327 | consumed += bytes; 1328 | out += ints_read; 1329 | } 1330 | } while (scanned + 112 < inputsize); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig 1331 | sig = (nextSig << (scanned - consumed - 48)) | sig; 1332 | availablebytes = scanned - consumed; 1333 | } 1334 | while (1) { 1335 | if (availablebytes < 16) { 1336 | if (availablebytes + consumed + 31 < inputsize) { 1337 | #ifdef __AVX2__ 1338 | uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); 1339 | sig |= (newsigavx << availablebytes); 1340 | #else 1341 | uint64_t newsig = _mm_movemask_epi8( 1342 | _mm_lddqu_si128( 1343 | (const __m128i *) (in + availablebytes 1344 | + consumed))); 1345 | uint64_t newsig2 = _mm_movemask_epi8( 1346 | _mm_lddqu_si128( 1347 | (const __m128i *) (in + availablebytes + 16 1348 | + consumed))); 1349 | sig |= (newsig << availablebytes) 1350 | | (newsig2 << (availablebytes + 16)); 1351 | #endif 1352 | availablebytes += 32; 1353 | } else if(availablebytes + consumed + 15 < inputsize ) { 1354 | int newsig = _mm_movemask_epi8( 1355 | _mm_lddqu_si128( 1356 | (const __m128i *) (in + availablebytes 1357 | + consumed))); 1358 | sig |= newsig << availablebytes; 1359 | availablebytes += 16; 1360 | } else { 1361 | break; 1362 | } 1363 | } 1364 | uint64_t ints_read; 1365 | uint64_t bytes = masked_vbyte_read_group(in + consumed, out, 1366 | sig, &ints_read); 1367 | consumed += bytes; 1368 | availablebytes -= bytes; 1369 | sig >>= bytes; 1370 | out += ints_read; 1371 | } 1372 | while (consumed < inputsize) { 1373 | unsigned int shift = 0; 1374 | for (uint32_t v = 0; consumed < inputsize; shift += 7) { 1375 | uint8_t c = in[consumed++]; 1376 | if ((c & 128) == 0) { 1377 | out[0] = v + (c << shift); 1378 | ++out; 1379 | break; 1380 | } else { 1381 | v += (c & 127) << shift; 1382 | } 1383 | } 1384 | } 1385 | return out - initout; 1386 | } 1387 | 1388 | 1389 | size_t read_ints(const uint8_t* in, uint32_t* out, int length) { 1390 | size_t consumed = 0; 1391 | int count; 1392 | for (count = 0; count + 15 < length;) { 1393 | int ints_read; 1394 | consumed += read_int_group(in + consumed, out + count, &ints_read); 1395 | count += ints_read; 1396 | } 1397 | for (; count < length; count++) { 1398 | consumed += read_int(in + consumed, out + count); 1399 | } 1400 | return consumed; 1401 | } 1402 | 1403 | static int read_int_group_delta(const uint8_t* in, uint32_t* out, 1404 | int* ints_read, __m128i * prev) { 1405 | 1406 | __m128i initial = _mm_lddqu_si128((const __m128i *) in); 1407 | __m128i * const mout = (__m128i *) out; 1408 | 1409 | int mask = _mm_movemask_epi8(initial); 1410 | if (mask == 0) { 1411 | __m128i result; 1412 | result = _mm_cvtepi8_epi32(initial); 1413 | initial = _mm_srli_si128(initial, 4); 1414 | *prev = PrefixSum(result, *prev); 1415 | _mm_storeu_si128(mout, *prev); 1416 | result = _mm_cvtepi8_epi32(initial); 1417 | initial = _mm_srli_si128(initial, 4); 1418 | *prev = PrefixSum(result, *prev); 1419 | _mm_storeu_si128(mout + 1, *prev); 1420 | result = _mm_cvtepi8_epi32(initial); 1421 | initial = _mm_srli_si128(initial, 4); 1422 | *prev = PrefixSum(result, *prev); 1423 | _mm_storeu_si128(mout + 2, *prev); 1424 | result = _mm_cvtepi8_epi32(initial); 1425 | *prev = PrefixSum(result, *prev); 1426 | _mm_storeu_si128(mout + 3, *prev); 1427 | *ints_read = 16; 1428 | return 16; 1429 | } 1430 | int mask2 = mask & 0xFFF; 1431 | index_bytes_consumed combined = combined_lookup[mask2]; 1432 | 1433 | int index = combined.index; 1434 | 1435 | __m128i shuffle_vector = vectors[index]; 1436 | int consumed = combined.bytes_consumed; 1437 | 1438 | if (index < 64) { 1439 | *ints_read = 6; 1440 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 1441 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 1442 | _mm_set1_epi16(0x007F)); 1443 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 1444 | _mm_set1_epi16(0x7F00)); 1445 | __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); 1446 | __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); 1447 | __m128i unpacked_result_a = _mm_and_si128(packed_result, 1448 | _mm_set1_epi32(0x0000FFFF)); 1449 | *prev = PrefixSum(unpacked_result_a, *prev); 1450 | _mm_storeu_si128(mout, *prev); 1451 | __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); 1452 | *prev = PrefixSum2ints(unpacked_result_b, *prev); 1453 | _mm_storeu_si128(mout + 1, *prev); 1454 | return consumed; 1455 | } 1456 | if (index < 145) { 1457 | 1458 | *ints_read = 4; 1459 | 1460 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 1461 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 1462 | _mm_set1_epi32(0x0000007F)); 1463 | __m128i middle_bytes = _mm_and_si128(bytes_to_decode, 1464 | _mm_set1_epi32(0x00007F00)); 1465 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 1466 | _mm_set1_epi32(0x007F0000)); 1467 | __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); 1468 | __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); 1469 | __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); 1470 | __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); 1471 | *prev = PrefixSum(result, *prev); 1472 | _mm_storeu_si128(mout, *prev); 1473 | 1474 | return consumed; 1475 | } 1476 | 1477 | *ints_read = 2; 1478 | 1479 | __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); 1480 | __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); 1481 | __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, 1482 | _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); 1483 | __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); 1484 | __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); 1485 | __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); 1486 | __m128i result_evens = _mm_or_si128(recombined, low_byte); 1487 | __m128i result = _mm_shuffle_epi8(result_evens, 1488 | _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, 1489 | -1)); 1490 | *prev = PrefixSum2ints(result, *prev); 1491 | _mm_storeu_si128(mout, *prev); 1492 | return consumed; 1493 | } 1494 | 1495 | 1496 | // len_signed : number of ints we want to decode 1497 | size_t masked_vbyte_decode_delta(const uint8_t* in, uint32_t* out, 1498 | uint64_t length, uint32_t prev) { 1499 | //uint64_t length = (uint64_t) len_signed; // number of ints we want to decode 1500 | size_t consumed = 0; // number of bytes read 1501 | __m128i mprev = _mm_set1_epi32(prev); 1502 | uint64_t count = 0; // how many integers we have read so far 1503 | 1504 | uint64_t sig = 0; 1505 | int availablebytes = 0; 1506 | if (96 < length) { 1507 | size_t scanned = 0; 1508 | 1509 | 1510 | #ifdef __AVX2__ 1511 | __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1512 | uint32_t lowSig = _mm256_movemask_epi8(low); 1513 | #else 1514 | __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1515 | uint32_t lowSig1 = _mm_movemask_epi8(low1); 1516 | __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1517 | uint32_t lowSig2 = _mm_movemask_epi8(low2); 1518 | uint32_t lowSig = lowSig2 << 16; 1519 | lowSig |= lowSig1; 1520 | #endif 1521 | 1522 | // excess verbosity to avoid problems with sign extension on conversions 1523 | // better to think about what's happening and make it clearer 1524 | __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1525 | uint32_t highSig = _mm_movemask_epi8(high); 1526 | uint64_t nextSig = highSig; 1527 | nextSig <<= 32; 1528 | nextSig |= lowSig; 1529 | scanned += 48; 1530 | 1531 | do { 1532 | uint64_t thisSig = nextSig; 1533 | 1534 | #ifdef __AVX2__ 1535 | low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1536 | lowSig = _mm256_movemask_epi8(low); 1537 | #else 1538 | low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1539 | lowSig1 = _mm_movemask_epi8(low1); 1540 | low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1541 | lowSig2 = _mm_movemask_epi8(low2); 1542 | lowSig = lowSig2 << 16; 1543 | lowSig |= lowSig1; 1544 | #endif 1545 | 1546 | high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1547 | highSig = _mm_movemask_epi8(high); 1548 | nextSig = highSig; 1549 | nextSig <<= 32; 1550 | nextSig |= lowSig; 1551 | 1552 | uint64_t remaining = scanned - (consumed + 48); 1553 | sig = (thisSig << remaining) | sig; 1554 | 1555 | uint64_t reload = scanned - 16; 1556 | scanned += 48; 1557 | 1558 | // need to reload when less than 16 scanned bytes remain in sig 1559 | while (consumed < reload) { 1560 | uint64_t ints_read; 1561 | uint64_t bytes = masked_vbyte_read_group_delta(in + consumed, 1562 | out + count, sig, &ints_read, &mprev); 1563 | sig >>= bytes; 1564 | 1565 | // seems like this might force the compiler to prioritize shifting sig >>= bytes 1566 | if (sig == 0xFFFFFFFFFFFFFFFF) 1567 | return 0; // fake check to force earliest evaluation 1568 | 1569 | consumed += bytes; 1570 | count += ints_read; 1571 | } 1572 | } while (count + 112 < length); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig 1573 | sig = (nextSig << (scanned - consumed - 48)) | sig; 1574 | availablebytes = scanned - consumed; 1575 | } 1576 | while (availablebytes + count < length) { 1577 | if (availablebytes < 16) break; 1578 | 1579 | if (availablebytes < 16) { 1580 | if (availablebytes + count + 31 < length) { 1581 | #ifdef __AVX2__ 1582 | uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); 1583 | sig |= (newsigavx << availablebytes); 1584 | #else 1585 | uint64_t newsig = _mm_movemask_epi8( 1586 | _mm_lddqu_si128( 1587 | (const __m128i *) (in + availablebytes 1588 | + consumed))); 1589 | uint64_t newsig2 = _mm_movemask_epi8( 1590 | _mm_lddqu_si128( 1591 | (const __m128i *) (in + availablebytes + 16 1592 | + consumed))); 1593 | sig |= (newsig << availablebytes) 1594 | | (newsig2 << (availablebytes + 16)); 1595 | #endif 1596 | availablebytes += 32; 1597 | } else if (availablebytes + count + 15 < length) { 1598 | int newsig = _mm_movemask_epi8( 1599 | _mm_lddqu_si128( 1600 | (const __m128i *) (in + availablebytes 1601 | + consumed))); 1602 | sig |= newsig << availablebytes; 1603 | availablebytes += 16; 1604 | } else { 1605 | break; 1606 | } 1607 | } 1608 | uint64_t ints_read; 1609 | uint64_t eaten = masked_vbyte_read_group_delta(in + consumed, out + count, 1610 | sig, &ints_read, &mprev); 1611 | consumed += eaten; 1612 | availablebytes -= eaten; 1613 | sig >>= eaten; 1614 | count += ints_read; 1615 | } 1616 | prev = _mm_extract_epi32(mprev, 3); 1617 | for (; count < length; count++) { 1618 | consumed += read_int_delta(in + consumed, out + count, &prev); 1619 | } 1620 | return consumed; 1621 | } 1622 | 1623 | size_t read_ints_delta(const uint8_t* in, uint32_t* out, int length, 1624 | uint32_t prev) { 1625 | __m128i mprev = _mm_set1_epi32(prev); 1626 | size_t consumed = 0; 1627 | int count; 1628 | for (count = 0; count + 15 < length;) { 1629 | int ints_read; 1630 | consumed += read_int_group_delta(in + consumed, out + count, &ints_read, 1631 | &mprev); 1632 | count += ints_read; 1633 | } 1634 | prev = _mm_extract_epi32(mprev, 3); 1635 | for (; count < length; count++) { 1636 | consumed += read_int_delta(in + consumed, out + count, &prev); 1637 | } 1638 | return consumed; 1639 | } 1640 | 1641 | 1642 | 1643 | // inputsize : number of input bytes we want to decode 1644 | // returns the number of written ints 1645 | size_t masked_vbyte_decode_fromcompressedsize_delta(const uint8_t* in, uint32_t* out, 1646 | size_t inputsize, uint32_t prev) { 1647 | size_t consumed = 0; // number of bytes read 1648 | uint32_t * initout = out; 1649 | __m128i mprev = _mm_set1_epi32(prev); 1650 | uint64_t sig = 0; 1651 | int availablebytes = 0; 1652 | if (96 < inputsize) { 1653 | size_t scanned = 0; 1654 | 1655 | 1656 | #ifdef __AVX2__ 1657 | __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1658 | uint32_t lowSig = _mm256_movemask_epi8(low); 1659 | #else 1660 | __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1661 | uint32_t lowSig1 = _mm_movemask_epi8(low1); 1662 | __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1663 | uint32_t lowSig2 = _mm_movemask_epi8(low2); 1664 | uint32_t lowSig = lowSig2 << 16; 1665 | lowSig |= lowSig1; 1666 | #endif 1667 | 1668 | // excess verbosity to avoid problems with sign extension on conversions 1669 | // better to think about what's happening and make it clearer 1670 | __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1671 | uint32_t highSig = _mm_movemask_epi8(high); 1672 | uint64_t nextSig = highSig; 1673 | nextSig <<= 32; 1674 | nextSig |= lowSig; 1675 | scanned += 48; 1676 | 1677 | do { 1678 | uint64_t thisSig = nextSig; 1679 | 1680 | #ifdef __AVX2__ 1681 | low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1682 | lowSig = _mm256_movemask_epi8(low); 1683 | #else 1684 | low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1685 | lowSig1 = _mm_movemask_epi8(low1); 1686 | low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1687 | lowSig2 = _mm_movemask_epi8(low2); 1688 | lowSig = lowSig2 << 16; 1689 | lowSig |= lowSig1; 1690 | #endif 1691 | 1692 | high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1693 | highSig = _mm_movemask_epi8(high); 1694 | nextSig = highSig; 1695 | nextSig <<= 32; 1696 | nextSig |= lowSig; 1697 | 1698 | uint64_t remaining = scanned - (consumed + 48); 1699 | sig = (thisSig << remaining) | sig; 1700 | 1701 | uint64_t reload = scanned - 16; 1702 | scanned += 48; 1703 | 1704 | // need to reload when less than 16 scanned bytes remain in sig 1705 | while (consumed < reload) { 1706 | uint64_t ints_read; 1707 | uint64_t bytes = masked_vbyte_read_group_delta(in + consumed, 1708 | out, sig, &ints_read, &mprev); 1709 | sig >>= bytes; 1710 | 1711 | // seems like this might force the compiler to prioritize shifting sig >>= bytes 1712 | if (sig == 0xFFFFFFFFFFFFFFFF) 1713 | return 0; // fake check to force earliest evaluation 1714 | 1715 | consumed += bytes; 1716 | out += ints_read; 1717 | } 1718 | } while (scanned + 112 < inputsize); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig 1719 | sig = (nextSig << (scanned - consumed - 48)) | sig; 1720 | availablebytes = scanned - consumed; 1721 | } 1722 | while (1) { 1723 | if (availablebytes < 16) { 1724 | if (availablebytes + consumed + 31 < inputsize) { 1725 | #ifdef __AVX2__ 1726 | uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); 1727 | sig |= (newsigavx << availablebytes); 1728 | #else 1729 | uint64_t newsig = _mm_movemask_epi8( 1730 | _mm_lddqu_si128( 1731 | (const __m128i *) (in + availablebytes 1732 | + consumed))); 1733 | uint64_t newsig2 = _mm_movemask_epi8( 1734 | _mm_lddqu_si128( 1735 | (const __m128i *) (in + availablebytes + 16 1736 | + consumed))); 1737 | sig |= (newsig << availablebytes) 1738 | | (newsig2 << (availablebytes + 16)); 1739 | #endif 1740 | availablebytes += 32; 1741 | } else if(availablebytes + consumed + 15 < inputsize ) { 1742 | int newsig = _mm_movemask_epi8( 1743 | _mm_lddqu_si128( 1744 | (const __m128i *) (in + availablebytes 1745 | + consumed))); 1746 | sig |= newsig << availablebytes; 1747 | availablebytes += 16; 1748 | } else { 1749 | break; 1750 | } 1751 | } 1752 | uint64_t ints_read; 1753 | uint64_t bytes = masked_vbyte_read_group_delta(in + consumed, out, 1754 | sig, &ints_read, &mprev); 1755 | consumed += bytes; 1756 | availablebytes -= bytes; 1757 | sig >>= bytes; 1758 | out += ints_read; 1759 | } 1760 | prev = _mm_extract_epi32(mprev, 3); 1761 | while (consumed < inputsize) { 1762 | unsigned int shift = 0; 1763 | for (uint32_t v = 0; consumed < inputsize; shift += 7) { 1764 | uint8_t c = in[consumed++]; 1765 | if ((c & 128) == 0) { 1766 | uint32_t delta = v + (c << shift); 1767 | prev += delta; 1768 | *out++ = prev; 1769 | break; 1770 | } else { 1771 | v += (c & 127) << shift; 1772 | } 1773 | } 1774 | } 1775 | return out - initout; 1776 | } 1777 | 1778 | 1779 | 1780 | static int8_t shuffle_mask_bytes1[16 * 16 ] ALIGNED(16) = { 1781 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1782 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1783 | 4, 5, 6, 7, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1784 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1785 | 8, 9, 10, 11, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1786 | 0, 1, 2, 3, 8, 9, 10, 11, 8, 9, 10, 11, 12, 13, 14, 15, 1787 | 4, 5, 6, 7, 8, 9, 10, 11, 8, 9, 10, 11, 12, 13, 14, 15, 1788 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1789 | 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1790 | 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 1791 | 4, 5, 6, 7, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 1792 | 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 12, 13, 14, 15, 1793 | 8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15, 1794 | 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, 12, 13, 14, 15, 1795 | 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 12, 13, 14, 15, 1796 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1797 | }; 1798 | 1799 | static const __m128i *shuffle_mask = (__m128i *) shuffle_mask_bytes1; 1800 | 1801 | /* perform a lower-bound search for |key| in |out|; the resulting uint32 1802 | * is stored in |*presult|.*/ 1803 | #define CHECK_AND_INCREMENT(i, out, key, presult) \ 1804 | do { \ 1805 | __m128i tmpout = _mm_sub_epi32(out, conversion); \ 1806 | uint32_t mmask = _mm_movemask_ps(_mm_castsi128_ps(_mm_cmplt_epi32(tmpout, key4))); \ 1807 | if (mmask != 15) { \ 1808 | __m128i pp = _mm_shuffle_epi8(out, shuffle_mask[mmask ^ 15]); \ 1809 | int offset; \ 1810 | SIMDCOMP_CTZ(offset, mmask ^ 15); \ 1811 | *presult = _mm_cvtsi128_si32(pp); \ 1812 | return (i + offset); \ 1813 | } \ 1814 | i += 4; \ 1815 | } while (0) 1816 | 1817 | 1818 | /* perform a lower-bound search for |key| in |out|; the resulting uint32 1819 | * is stored in |*presult|.*/ 1820 | #define CHECK_AND_INCREMENT_2(i, out, key, presult) \ 1821 | do { \ 1822 | __m128i tmpout = _mm_sub_epi32(out, conversion); \ 1823 | uint32_t mmask = 3 & _mm_movemask_ps(_mm_castsi128_ps(_mm_cmplt_epi32(tmpout, key4))); \ 1824 | if (mmask != 3) { \ 1825 | __m128i pp = _mm_shuffle_epi8(out, shuffle_mask[mmask ^ 3]); \ 1826 | int offset; \ 1827 | SIMDCOMP_CTZ(offset, mmask ^ 3); \ 1828 | *presult = _mm_cvtsi128_si32(pp); \ 1829 | return (i + offset); \ 1830 | } \ 1831 | i += 2; \ 1832 | } while (0) 1833 | 1834 | static int masked_vbyte_search_group_delta(const uint8_t *in, uint64_t *p, 1835 | uint64_t mask, uint64_t *ints_read, __m128i *prev, 1836 | int i, uint32_t key, uint32_t *presult) { 1837 | __m128i initial = _mm_lddqu_si128((const __m128i *) (in)); 1838 | __m128i conversion = _mm_set1_epi32(2147483648U); 1839 | __m128i key4 = _mm_set1_epi32(key - 2147483648U); 1840 | 1841 | if (!(mask & 0xFFFF)) { 1842 | __m128i result = _mm_cvtepi8_epi32(initial); 1843 | *prev = PrefixSum(result, *prev); 1844 | CHECK_AND_INCREMENT(i, *prev, key, presult); 1845 | initial = _mm_srli_si128(initial, 4); 1846 | result = _mm_cvtepi8_epi32(initial); 1847 | *prev = PrefixSum(result, *prev); 1848 | CHECK_AND_INCREMENT(i, *prev, key, presult); 1849 | initial = _mm_srli_si128(initial, 4); 1850 | result = _mm_cvtepi8_epi32(initial); 1851 | *prev = PrefixSum(result, *prev); 1852 | CHECK_AND_INCREMENT(i, *prev, key, presult); 1853 | initial = _mm_srli_si128(initial, 4); 1854 | result = _mm_cvtepi8_epi32(initial); 1855 | *prev = PrefixSum(result, *prev); 1856 | CHECK_AND_INCREMENT(i, *prev, key, presult); 1857 | *ints_read = 16; 1858 | *p = 16; 1859 | return (-1); 1860 | } 1861 | 1862 | uint32_t low_12_bits = mask & 0xFFF; 1863 | // combine index and bytes consumed into a single lookup 1864 | index_bytes_consumed combined = combined_lookup[low_12_bits]; 1865 | uint64_t consumed = combined.bytes_consumed; 1866 | uint8_t index = combined.index; 1867 | 1868 | __m128i shuffle_vector = vectors[index]; 1869 | // __m128i shuffle_vector = {0, 0}; // speed check: 20% faster at large, less at small 1870 | 1871 | if (index < 64) { 1872 | *ints_read = 6; 1873 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 1874 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 1875 | _mm_set1_epi16(0x007F)); 1876 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 1877 | _mm_set1_epi16(0x7F00)); 1878 | __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); 1879 | __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); 1880 | __m128i unpacked_result_a = _mm_and_si128(packed_result, 1881 | _mm_set1_epi32(0x0000FFFF)); 1882 | *prev = PrefixSum(unpacked_result_a, *prev); 1883 | CHECK_AND_INCREMENT(i, *prev, key, presult); 1884 | __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); 1885 | *prev = PrefixSum2ints(unpacked_result_b, *prev); 1886 | //_mm_storel_epi64(&out, *prev); 1887 | CHECK_AND_INCREMENT_2(i, *prev, key, presult); 1888 | *p = consumed; 1889 | return (-1); 1890 | } 1891 | if (index < 145) { 1892 | 1893 | *ints_read = 4; 1894 | 1895 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 1896 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 1897 | _mm_set1_epi32(0x0000007F)); 1898 | __m128i middle_bytes = _mm_and_si128(bytes_to_decode, 1899 | _mm_set1_epi32(0x00007F00)); 1900 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 1901 | _mm_set1_epi32(0x007F0000)); 1902 | __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); 1903 | __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); 1904 | __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); 1905 | __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); 1906 | *prev = PrefixSum(result, *prev); 1907 | CHECK_AND_INCREMENT(i, *prev, key, presult); 1908 | *p = consumed; 1909 | return (-1); 1910 | } 1911 | 1912 | *ints_read = 2; 1913 | 1914 | __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); 1915 | __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); 1916 | __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, 1917 | _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); 1918 | __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); 1919 | __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); 1920 | __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); 1921 | __m128i result_evens = _mm_or_si128(recombined, low_byte); 1922 | __m128i result = _mm_shuffle_epi8(result_evens, 1923 | _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, 1924 | -1)); 1925 | *prev = PrefixSum2ints(result, *prev); 1926 | //_mm_storel_epi64(&out, *prev); 1927 | CHECK_AND_INCREMENT_2(i, *prev, key, presult); 1928 | *p = consumed; 1929 | return (-1); 1930 | } 1931 | 1932 | 1933 | 1934 | // returns the index of the matching key 1935 | int masked_vbyte_search_delta(const uint8_t *in, uint64_t length, uint32_t prev, 1936 | uint32_t key, uint32_t *presult) { 1937 | size_t consumed = 0; // number of bytes read 1938 | __m128i mprev = _mm_set1_epi32(prev); 1939 | uint64_t count = 0; // how many integers we have read so far 1940 | uint64_t sig = 0; 1941 | int availablebytes = 0; 1942 | if (96 < length) { 1943 | size_t scanned = 0; 1944 | 1945 | #ifdef __AVX2__ 1946 | __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1947 | uint32_t lowSig = _mm256_movemask_epi8(low); 1948 | #else 1949 | __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1950 | uint32_t lowSig1 = _mm_movemask_epi8(low1); 1951 | __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1952 | uint32_t lowSig2 = _mm_movemask_epi8(low2); 1953 | uint32_t lowSig = lowSig2 << 16; 1954 | lowSig |= lowSig1; 1955 | #endif 1956 | 1957 | // excess verbosity to avoid problems with sign extension on conversions 1958 | // better to think about what's happening and make it clearer 1959 | __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1960 | uint32_t highSig = _mm_movemask_epi8(high); 1961 | uint64_t nextSig = highSig; 1962 | nextSig <<= 32; 1963 | nextSig |= lowSig; 1964 | scanned += 48; 1965 | 1966 | do { 1967 | uint64_t thisSig = nextSig; 1968 | 1969 | #ifdef __AVX2__ 1970 | low = _mm256_loadu_si256((__m256i *)(in + scanned)); 1971 | lowSig = _mm256_movemask_epi8(low); 1972 | #else 1973 | low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 1974 | lowSig1 = _mm_movemask_epi8(low1); 1975 | low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 1976 | lowSig2 = _mm_movemask_epi8(low2); 1977 | lowSig = lowSig2 << 16; 1978 | lowSig |= lowSig1; 1979 | #endif 1980 | 1981 | high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 1982 | highSig = _mm_movemask_epi8(high); 1983 | nextSig = highSig; 1984 | nextSig <<= 32; 1985 | nextSig |= lowSig; 1986 | 1987 | uint64_t remaining = scanned - (consumed + 48); 1988 | sig = (thisSig << remaining) | sig; 1989 | 1990 | uint64_t reload = scanned - 16; 1991 | scanned += 48; 1992 | 1993 | // need to reload when less than 16 scanned bytes remain in sig 1994 | while (consumed < reload) { 1995 | uint64_t ints_read = 0, bytes = 0; 1996 | int ret = masked_vbyte_search_group_delta(in + consumed, &bytes, 1997 | sig, &ints_read, &mprev, 1998 | count, key, presult); 1999 | if (ret >= 0) 2000 | return (ret); 2001 | sig >>= bytes; 2002 | 2003 | // seems like this might force the compiler to prioritize shifting sig >>= bytes 2004 | if (sig == 0xFFFFFFFFFFFFFFFF) 2005 | return 0; // fake check to force earliest evaluation 2006 | 2007 | consumed += bytes; 2008 | count += ints_read; 2009 | } 2010 | } while (count + 112 < length); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig 2011 | sig = (nextSig << (scanned - consumed - 48)) | sig; 2012 | availablebytes = scanned - consumed; 2013 | } 2014 | 2015 | while (availablebytes + count < length) { 2016 | if (availablebytes < 16) break; 2017 | 2018 | uint64_t ints_read = 0, bytes = 0; 2019 | int ret = masked_vbyte_search_group_delta(in + consumed, &bytes, 2020 | sig, &ints_read, &mprev, count, key, presult); 2021 | if (ret >= 0) 2022 | return (ret); 2023 | consumed += bytes; 2024 | availablebytes -= bytes; 2025 | sig >>= bytes; 2026 | count += ints_read; 2027 | } 2028 | prev = _mm_extract_epi32(mprev, 3); 2029 | for (; count < length; count++) { 2030 | uint32_t out; 2031 | consumed += read_int_delta(in + consumed, &out, &prev); 2032 | if (key <= prev) { 2033 | *presult = prev; 2034 | return (count); 2035 | } 2036 | } 2037 | 2038 | *presult = key + 1; 2039 | return length; 2040 | } 2041 | 2042 | static int8_t shuffle_mask_bytes2[16 * 16 ] ALIGNED(16) = { 2043 | 0,1,2,3,0,0,0,0,0,0,0,0,0,0,0,0, 2044 | 4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0, 2045 | 8,9,10,11,0,0,0,0,0,0,0,0,0,0,0,0, 2046 | 12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0, 2047 | }; 2048 | 2049 | static const __m128i *shuffle_mask_extract = (__m128i *) shuffle_mask_bytes2; 2050 | 2051 | static uint32_t branchlessextract (__m128i out, int i) { 2052 | return _mm_cvtsi128_si32(_mm_shuffle_epi8(out,shuffle_mask_extract[i])); 2053 | } 2054 | 2055 | #define CHECK_SELECT(i, out, slot, presult) \ 2056 | i += 4; \ 2057 | if (i > slot) { \ 2058 | *presult = branchlessextract (out, slot - (i - 4)); \ 2059 | return (1); \ 2060 | } 2061 | 2062 | 2063 | #define CHECK_SELECT_2(i, out, slot, presult) \ 2064 | i += 2; \ 2065 | if (i > slot) { \ 2066 | *presult = branchlessextract (out, slot - (i - 2)); \ 2067 | return (1); \ 2068 | } 2069 | 2070 | static int masked_vbyte_select_group_delta(const uint8_t *in, uint64_t *p, 2071 | uint64_t mask, uint64_t *ints_read, __m128i *prev, 2072 | int slot, uint32_t *presult) { 2073 | __m128i initial = _mm_lddqu_si128((const __m128i *) (in)); 2074 | int i = 0; 2075 | 2076 | if (!(mask & 0xFFFF)) { 2077 | __m128i result = _mm_cvtepi8_epi32(initial); 2078 | *prev = PrefixSum(result, *prev); 2079 | CHECK_SELECT(i, *prev, slot, presult); 2080 | initial = _mm_srli_si128(initial, 4); 2081 | result = _mm_cvtepi8_epi32(initial); 2082 | *prev = PrefixSum(result, *prev); 2083 | CHECK_SELECT(i, *prev, slot, presult); 2084 | initial = _mm_srli_si128(initial, 4); 2085 | result = _mm_cvtepi8_epi32(initial); 2086 | *prev = PrefixSum(result, *prev); 2087 | CHECK_SELECT(i, *prev, slot, presult); 2088 | initial = _mm_srli_si128(initial, 4); 2089 | result = _mm_cvtepi8_epi32(initial); 2090 | *prev = PrefixSum(result, *prev); 2091 | CHECK_SELECT(i, *prev, slot, presult); 2092 | *ints_read = 16; 2093 | *p = 16; 2094 | return (0); 2095 | } 2096 | 2097 | uint32_t low_12_bits = mask & 0xFFF; 2098 | // combine index and bytes consumed into a single lookup 2099 | index_bytes_consumed combined = combined_lookup[low_12_bits]; 2100 | uint64_t consumed = combined.bytes_consumed; 2101 | uint8_t index = combined.index; 2102 | 2103 | __m128i shuffle_vector = vectors[index]; 2104 | // __m128i shuffle_vector = {0, 0}; // speed check: 20% faster at large, less at small 2105 | 2106 | if (index < 64) { 2107 | *ints_read = 6; 2108 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 2109 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 2110 | _mm_set1_epi16(0x007F)); 2111 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 2112 | _mm_set1_epi16(0x7F00)); 2113 | __m128i high_bytes_shifted = _mm_srli_epi16(high_bytes, 1); 2114 | __m128i packed_result = _mm_or_si128(low_bytes, high_bytes_shifted); 2115 | __m128i unpacked_result_a = _mm_and_si128(packed_result, 2116 | _mm_set1_epi32(0x0000FFFF)); 2117 | *prev = PrefixSum(unpacked_result_a, *prev); 2118 | CHECK_SELECT(i, *prev, slot, presult); 2119 | __m128i unpacked_result_b = _mm_srli_epi32(packed_result, 16); 2120 | *prev = PrefixSum2ints(unpacked_result_b, *prev); 2121 | //_mm_storel_epi64(&out, *prev); 2122 | CHECK_SELECT_2(i, *prev, slot, presult); 2123 | *p = consumed; 2124 | return (0); 2125 | } 2126 | if (index < 145) { 2127 | 2128 | *ints_read = 4; 2129 | 2130 | __m128i bytes_to_decode = _mm_shuffle_epi8(initial, shuffle_vector); 2131 | __m128i low_bytes = _mm_and_si128(bytes_to_decode, 2132 | _mm_set1_epi32(0x0000007F)); 2133 | __m128i middle_bytes = _mm_and_si128(bytes_to_decode, 2134 | _mm_set1_epi32(0x00007F00)); 2135 | __m128i high_bytes = _mm_and_si128(bytes_to_decode, 2136 | _mm_set1_epi32(0x007F0000)); 2137 | __m128i middle_bytes_shifted = _mm_srli_epi32(middle_bytes, 1); 2138 | __m128i high_bytes_shifted = _mm_srli_epi32(high_bytes, 2); 2139 | __m128i low_middle = _mm_or_si128(low_bytes, middle_bytes_shifted); 2140 | __m128i result = _mm_or_si128(low_middle, high_bytes_shifted); 2141 | *prev = PrefixSum(result, *prev); 2142 | CHECK_SELECT(i, *prev, slot, presult); 2143 | *p = consumed; 2144 | return (0); 2145 | } 2146 | 2147 | *ints_read = 2; 2148 | 2149 | __m128i data_bits = _mm_and_si128(initial, _mm_set1_epi8(0x7F)); 2150 | __m128i bytes_to_decode = _mm_shuffle_epi8(data_bits, shuffle_vector); 2151 | __m128i split_bytes = _mm_mullo_epi16(bytes_to_decode, 2152 | _mm_setr_epi16(128, 64, 32, 16, 128, 64, 32, 16)); 2153 | __m128i shifted_split_bytes = _mm_slli_epi64(split_bytes, 8); 2154 | __m128i recombined = _mm_or_si128(split_bytes, shifted_split_bytes); 2155 | __m128i low_byte = _mm_srli_epi64(bytes_to_decode, 56); 2156 | __m128i result_evens = _mm_or_si128(recombined, low_byte); 2157 | __m128i result = _mm_shuffle_epi8(result_evens, 2158 | _mm_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, -1, -1, -1, -1, -1, -1, -1, 2159 | -1)); 2160 | *prev = PrefixSum2ints(result, *prev); 2161 | //_mm_storel_epi64(&out, *prev); 2162 | CHECK_SELECT_2(i, *prev, slot, presult); 2163 | *p = consumed; 2164 | return (0); 2165 | } 2166 | 2167 | 2168 | 2169 | uint32_t masked_vbyte_select_delta(const uint8_t *in, uint64_t length, 2170 | uint32_t prev, size_t slot) { 2171 | size_t consumed = 0; // number of bytes read 2172 | __m128i mprev = _mm_set1_epi32(prev); 2173 | uint64_t count = 0; // how many integers we have read so far 2174 | uint64_t sig = 0; 2175 | int availablebytes = 0; 2176 | if (96 < length) { 2177 | size_t scanned = 0; 2178 | 2179 | #ifdef __AVX2__ 2180 | __m256i low = _mm256_loadu_si256((__m256i *)(in + scanned)); 2181 | uint32_t lowSig = _mm256_movemask_epi8(low); 2182 | #else 2183 | __m128i low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 2184 | uint32_t lowSig1 = _mm_movemask_epi8(low1); 2185 | __m128i low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 2186 | uint32_t lowSig2 = _mm_movemask_epi8(low2); 2187 | uint32_t lowSig = lowSig2 << 16; 2188 | lowSig |= lowSig1; 2189 | #endif 2190 | 2191 | // excess verbosity to avoid problems with sign extension on conversions 2192 | // better to think about what's happening and make it clearer 2193 | __m128i high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 2194 | uint32_t highSig = _mm_movemask_epi8(high); 2195 | uint64_t nextSig = highSig; 2196 | nextSig <<= 32; 2197 | nextSig |= lowSig; 2198 | scanned += 48; 2199 | 2200 | do { 2201 | uint64_t thisSig = nextSig; 2202 | 2203 | #ifdef __AVX2__ 2204 | low = _mm256_loadu_si256((__m256i *)(in + scanned)); 2205 | lowSig = _mm256_movemask_epi8(low); 2206 | #else 2207 | low1 = _mm_loadu_si128((__m128i *) (in + scanned)); 2208 | lowSig1 = _mm_movemask_epi8(low1); 2209 | low2 = _mm_loadu_si128((__m128i *) (in + scanned + 16)); 2210 | lowSig2 = _mm_movemask_epi8(low2); 2211 | lowSig = lowSig2 << 16; 2212 | lowSig |= lowSig1; 2213 | #endif 2214 | 2215 | high = _mm_loadu_si128((__m128i *) (in + scanned + 32)); 2216 | highSig = _mm_movemask_epi8(high); 2217 | nextSig = highSig; 2218 | nextSig <<= 32; 2219 | nextSig |= lowSig; 2220 | 2221 | uint64_t remaining = scanned - (consumed + 48); 2222 | sig = (thisSig << remaining) | sig; 2223 | 2224 | uint64_t reload = scanned - 16; 2225 | scanned += 48; 2226 | 2227 | // need to reload when less than 16 scanned bytes remain in sig 2228 | while (consumed < reload) { 2229 | uint32_t result; 2230 | uint64_t ints_read, bytes; 2231 | if (masked_vbyte_select_group_delta(in + consumed, &bytes, 2232 | sig, &ints_read, &mprev, 2233 | slot - count, &result)) { 2234 | return (result); 2235 | } 2236 | sig >>= bytes; 2237 | 2238 | // seems like this might force the compiler to prioritize shifting sig >>= bytes 2239 | if (sig == 0xFFFFFFFFFFFFFFFF) 2240 | return 0; // fake check to force earliest evaluation 2241 | 2242 | consumed += bytes; 2243 | count += ints_read; 2244 | } 2245 | } while (count + 112 < length); // 112 == 48 + 48 ahead for scanning + up to 16 remaining in sig 2246 | sig = (nextSig << (scanned - consumed - 48)) | sig; 2247 | availablebytes = scanned - consumed; 2248 | } 2249 | while (availablebytes + count < length) { 2250 | if (availablebytes < 16) break; 2251 | 2252 | if (availablebytes < 16) { 2253 | if (availablebytes + count + 31 < length) { 2254 | #ifdef __AVX2__ 2255 | uint64_t newsigavx = (uint32_t) _mm256_movemask_epi8(_mm256_loadu_si256((__m256i *)(in + availablebytes + consumed))); 2256 | sig |= (newsigavx << availablebytes); 2257 | #else 2258 | uint64_t newsig = _mm_movemask_epi8( 2259 | _mm_lddqu_si128( 2260 | (const __m128i *) (in + availablebytes 2261 | + consumed))); 2262 | uint64_t newsig2 = _mm_movemask_epi8( 2263 | _mm_lddqu_si128( 2264 | (const __m128i *) (in + availablebytes + 16 2265 | + consumed))); 2266 | sig |= (newsig << availablebytes) 2267 | | (newsig2 << (availablebytes + 16)); 2268 | #endif 2269 | availablebytes += 32; 2270 | } else if (availablebytes + count + 15 < length) { 2271 | int newsig = _mm_movemask_epi8( 2272 | _mm_lddqu_si128( 2273 | (const __m128i *) (in + availablebytes 2274 | + consumed))); 2275 | sig |= newsig << availablebytes; 2276 | availablebytes += 16; 2277 | } else { 2278 | break; 2279 | } 2280 | } 2281 | 2282 | uint32_t result; 2283 | uint64_t ints_read, bytes; 2284 | if (masked_vbyte_select_group_delta(in + consumed, &bytes, 2285 | sig, &ints_read, &mprev, 2286 | slot - count, &result)) { 2287 | return (result); 2288 | } 2289 | consumed += bytes; 2290 | availablebytes -= bytes; 2291 | sig >>= bytes; 2292 | count += ints_read; 2293 | } 2294 | 2295 | prev = _mm_extract_epi32(mprev, 3); 2296 | for (; count < slot + 1; count++) { 2297 | uint32_t out; 2298 | consumed += read_int_delta(in + consumed, &out, &prev); 2299 | } 2300 | 2301 | return prev; 2302 | } 2303 | -------------------------------------------------------------------------------- /varintdecode.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef VARINTDECODE_H_ 3 | #define VARINTDECODE_H_ 4 | #define __STDC_FORMAT_MACROS 5 | #include 6 | #include // please use a C99-compatible compiler 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | // Read "length" 32-bit integers in varint format from in, storing the result in out. Returns the number of bytes read. 14 | size_t masked_vbyte_decode(const uint8_t* in, uint32_t* out, uint64_t length); 15 | 16 | // Read "length" 32-bit integers in varint format from in, storing the result in out with differential coding starting at prev. Setting prev to zero is a good default. Returns the number of bytes read. 17 | size_t masked_vbyte_decode_delta(const uint8_t* in, uint32_t* out, uint64_t length, uint32_t prev); 18 | 19 | // Read 32-bit integers in varint format from in, reading inputsize bytes, storing the result in out. Returns the number of integers read. 20 | size_t masked_vbyte_decode_fromcompressedsize(const uint8_t* in, uint32_t* out, 21 | size_t inputsize); 22 | 23 | // Read 32-bit integers in varint format from in, reading inputsize bytes, storing the result in out with differential coding starting at prev. Setting prev to zero is a good default. Returns the number of integers read. 24 | size_t masked_vbyte_decode_fromcompressedsize_delta(const uint8_t* in, uint32_t* out, 25 | size_t inputsize, uint32_t prev); 26 | 27 | // assuming that the data was differentially-coded, retrieve one particular value (at location slot) 28 | uint32_t masked_vbyte_select_delta(const uint8_t *in, uint64_t length, 29 | uint32_t prev, size_t slot); 30 | 31 | // return the position of the first value >= key, assumes differential-coded values 32 | int masked_vbyte_search_delta(const uint8_t *in, uint64_t length, uint32_t prev, 33 | uint32_t key, uint32_t *presult); 34 | 35 | #ifdef __cplusplus 36 | } // extern "C" 37 | #endif 38 | 39 | #endif /* VARINTDECODE_H_ */ 40 | -------------------------------------------------------------------------------- /vbyte.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2016 Christoph Rupp (chris@crupp.de). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | 19 | #if defined(_MSC_VER) && _MSC_VER < 1600 20 | typedef unsigned int uint32_t; 21 | typedef unsigned char uint8_t; 22 | typedef signed char int8_t; 23 | #else 24 | # include 25 | #endif 26 | 27 | #if defined(__AVX__) || defined(__AVX2__) || defined(__SSE4__) 28 | # define USE_MASKEDVBYTE 1 29 | #endif 30 | 31 | #include "vbyte.h" 32 | #include "varintdecode.h" 33 | 34 | namespace vbyte { 35 | 36 | #ifdef __SSE2__ 37 | 38 | // AVX might be enabled at compile time, but it's still possible that 39 | // it's not available at run-time because the CPU is an older model. 40 | 41 | // from http://stackoverflow.com/questions/6121792/how-to-check-if-a-cpu-supports-the-sse3-instruction-set 42 | 43 | #ifdef _WIN32 44 | // Windows 45 | # include 46 | # define cpuid __cpuid 47 | #else 48 | // GCC Inline Assembly 49 | static void 50 | cpuid(int cpuinfo[4], int infotype) { 51 | __asm__ __volatile__ ( 52 | "cpuid": 53 | "=a" (cpuinfo[0]), 54 | "=b" (cpuinfo[1]), 55 | "=c" (cpuinfo[2]), 56 | "=d" (cpuinfo[3]) : 57 | "a" (infotype) 58 | ); 59 | } 60 | #endif 61 | 62 | static inline bool 63 | is_avx_available() 64 | { 65 | static bool available = false; 66 | static bool initialized = false; 67 | if (!initialized) { 68 | initialized = true; 69 | 70 | int info[4]; 71 | cpuid(info, 0); 72 | int num_ids = info[0]; 73 | cpuid(info, 0x80000000); 74 | 75 | // Detect Instruction Set 76 | if (num_ids >= 1) { 77 | cpuid(info, 0x00000001); 78 | available = (info[2] & ((int)1 << 28)) != 0; 79 | } 80 | } 81 | 82 | return available; 83 | } 84 | #else 85 | static inline bool 86 | is_avx_available() 87 | { 88 | return false; 89 | } 90 | #endif 91 | 92 | static inline int 93 | read_int(const uint8_t *in, uint32_t *out) 94 | { 95 | *out = in[0] & 0x7Fu; 96 | if (in[0] < 128) 97 | return 1; 98 | *out = ((in[1] & 0x7Fu) << 7) | *out; 99 | if (in[1] < 128) 100 | return 2; 101 | *out = ((in[2] & 0x7Fu) << 14) | *out; 102 | if (in[2] < 128) 103 | return 3; 104 | *out = ((in[3] & 0x7Fu) << 21) | *out; 105 | if (in[3] < 128) 106 | return 4; 107 | *out = ((in[4] & 0x7Fu) << 28) | *out; 108 | return 5; 109 | } 110 | 111 | static inline int 112 | read_int(const uint8_t *in, uint64_t *out) 113 | { 114 | *out = in[0] & 0x7Fu; 115 | if (in[0] < 128) 116 | return 1; 117 | *out = ((in[1] & 0x7Fu) << 7) | *out; 118 | if (in[1] < 128) 119 | return 2; 120 | *out = ((in[2] & 0x7Fu) << 14) | *out; 121 | if (in[2] < 128) 122 | return 3; 123 | *out = ((in[3] & 0x7Fu) << 21) | *out; 124 | if (in[3] < 128) 125 | return 4; 126 | *out = ((uint64_t)(in[4] & 0x7Fu) << 28) | *out; 127 | if (in[4] < 128) 128 | return 5; 129 | *out = ((uint64_t)(in[5] & 0x7Fu) << 35) | *out; 130 | if (in[5] < 128) 131 | return 6; 132 | *out = ((uint64_t)(in[6] & 0x7Fu) << 42) | *out; 133 | if (in[6] < 128) 134 | return 7; 135 | *out = ((uint64_t)(in[7] & 0x7Fu) << 49) | *out; 136 | if (in[7] < 128) 137 | return 8; 138 | *out = ((uint64_t)(in[8] & 0x7Fu) << 56) | *out; 139 | if (in[8] < 128) 140 | return 9; 141 | *out = ((uint64_t)(in[9] & 0x7Fu) << 63) | *out; 142 | return 10; 143 | } 144 | 145 | static inline int 146 | write_int(uint8_t *p, uint32_t value) 147 | { 148 | if (value < (1u << 7)) { 149 | *p = value & 0x7Fu; 150 | return 1; 151 | } 152 | if (value < (1u << 14)) { 153 | *p = (value & 0x7Fu) | (1u << 7); 154 | ++p; 155 | *p = value >> 7; 156 | return 2; 157 | } 158 | if (value < (1u << 21)) { 159 | *p = (value & 0x7Fu) | (1u << 7); 160 | ++p; 161 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 162 | ++p; 163 | *p = value >> 14; 164 | return 3; 165 | } 166 | if (value < (1u << 28)) { 167 | *p = (value & 0x7Fu) | (1u << 7); 168 | ++p; 169 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 170 | ++p; 171 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 172 | ++p; 173 | *p = value >> 21; 174 | return 4; 175 | } 176 | else { 177 | *p = (value & 0x7Fu) | (1u << 7); 178 | ++p; 179 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 180 | ++p; 181 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 182 | ++p; 183 | *p = ((value >> 21) & 0x7Fu) | (1u << 7); 184 | ++p; 185 | *p = value >> 28; 186 | return 5; 187 | } 188 | } 189 | 190 | static inline int 191 | write_int(uint8_t *p, uint64_t value) 192 | { 193 | if (value < (1lu << 7)) { 194 | *p = value & 0x7Fu; 195 | return 1; 196 | } 197 | if (value < (1lu << 14)) { 198 | *p = (value & 0x7Fu) | (1u << 7); 199 | ++p; 200 | *p = value >> 7; 201 | return 2; 202 | } 203 | if (value < (1lu << 21)) { 204 | *p = (value & 0x7Fu) | (1u << 7); 205 | ++p; 206 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 207 | ++p; 208 | *p = value >> 14; 209 | return 3; 210 | } 211 | if (value < (1lu << 28)) { 212 | *p = (value & 0x7Fu) | (1u << 7); 213 | ++p; 214 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 215 | ++p; 216 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 217 | ++p; 218 | *p = value >> 21; 219 | return 4; 220 | } 221 | if (value < (1lu << 35)) { 222 | *p = (value & 0x7Fu) | (1u << 7); 223 | ++p; 224 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 225 | ++p; 226 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 227 | ++p; 228 | *p = ((value >> 21) & 0x7Fu) | (1u << 7); 229 | ++p; 230 | *p = value >> 28; 231 | return 5; 232 | } 233 | if (value < (1lu << 42)) { 234 | *p = (value & 0x7Fu) | (1u << 7); 235 | ++p; 236 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 237 | ++p; 238 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 239 | ++p; 240 | *p = ((value >> 21) & 0x7Fu) | (1u << 7); 241 | ++p; 242 | *p = ((value >> 28) & 0x7Fu) | (1u << 7); 243 | ++p; 244 | *p = value >> 35; 245 | return 6; 246 | } 247 | if (value < (1lu << 49)) { 248 | *p = (value & 0x7Fu) | (1u << 7); 249 | ++p; 250 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 251 | ++p; 252 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 253 | ++p; 254 | *p = ((value >> 21) & 0x7Fu) | (1u << 7); 255 | ++p; 256 | *p = ((value >> 28) & 0x7Fu) | (1u << 7); 257 | ++p; 258 | *p = ((value >> 35) & 0x7Fu) | (1u << 7); 259 | ++p; 260 | *p = value >> 42; 261 | return 7; 262 | } 263 | if (value < (1lu << 56)) { 264 | *p = (value & 0x7Fu) | (1u << 7); 265 | ++p; 266 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 267 | ++p; 268 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 269 | ++p; 270 | *p = ((value >> 21) & 0x7Fu) | (1u << 7); 271 | ++p; 272 | *p = ((value >> 28) & 0x7Fu) | (1u << 7); 273 | ++p; 274 | *p = ((value >> 35) & 0x7Fu) | (1u << 7); 275 | ++p; 276 | *p = ((value >> 42) & 0x7Fu) | (1u << 7); 277 | ++p; 278 | *p = value >> 49; 279 | return 8; 280 | } 281 | if (value < (1lu << 63)) { 282 | *p = (value & 0x7Fu) | (1u << 7); 283 | ++p; 284 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 285 | ++p; 286 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 287 | ++p; 288 | *p = ((value >> 21) & 0x7Fu) | (1u << 7); 289 | ++p; 290 | *p = ((value >> 28) & 0x7Fu) | (1u << 7); 291 | ++p; 292 | *p = ((value >> 35) & 0x7Fu) | (1u << 7); 293 | ++p; 294 | *p = ((value >> 42) & 0x7Fu) | (1u << 7); 295 | ++p; 296 | *p = ((value >> 49) & 0x7Fu) | (1u << 7); 297 | ++p; 298 | *p = value >> 56; 299 | return 9; 300 | } 301 | else { 302 | *p = (value & 0x7Fu) | (1u << 7); 303 | ++p; 304 | *p = ((value >> 7) & 0x7Fu) | (1u << 7); 305 | ++p; 306 | *p = ((value >> 14) & 0x7Fu) | (1u << 7); 307 | ++p; 308 | *p = ((value >> 21) & 0x7Fu) | (1u << 7); 309 | ++p; 310 | *p = ((value >> 28) & 0x7Fu) | (1u << 7); 311 | ++p; 312 | *p = ((value >> 35) & 0x7Fu) | (1u << 7); 313 | ++p; 314 | *p = ((value >> 42) & 0x7Fu) | (1u << 7); 315 | ++p; 316 | *p = ((value >> 49) & 0x7Fu) | (1u << 7); 317 | ++p; 318 | *p = ((value >> 56) & 0x7Fu) | (1u << 7); 319 | ++p; 320 | *p = value >> 63; 321 | return 10; 322 | } 323 | } 324 | 325 | static inline int 326 | compressed_size(uint32_t value) 327 | { 328 | if (value < (1u << 7)) 329 | return 1; 330 | if (value < (1u << 14)) 331 | return 2; 332 | if (value < (1u << 21)) 333 | return 3; 334 | if (value < (1u << 28)) 335 | return 4; 336 | return 5; 337 | } 338 | 339 | static inline int 340 | compressed_size(uint64_t value) 341 | { 342 | if (value < (1lu << 7)) 343 | return 1; 344 | if (value < (1lu << 14)) 345 | return 2; 346 | if (value < (1lu << 21)) 347 | return 3; 348 | if (value < (1lu << 28)) 349 | return 4; 350 | if (value < (1lu << 35)) 351 | return 5; 352 | if (value < (1lu << 42)) 353 | return 6; 354 | if (value < (1lu << 49)) 355 | return 7; 356 | if (value < (1lu << 56)) 357 | return 8; 358 | if (value < (1lu << 63)) 359 | return 9; 360 | return 10; 361 | } 362 | 363 | template 364 | static inline size_t 365 | compressed_size_sorted(const T *in, size_t length, T previous) 366 | { 367 | size_t size = 0; 368 | const T *end = in + length; 369 | 370 | for (; in < end; in++) { 371 | size += compressed_size(*in - previous); 372 | previous = *in; 373 | } 374 | 375 | return size; 376 | } 377 | 378 | template 379 | static inline size_t 380 | compressed_size_unsorted(const T *in, size_t length) 381 | { 382 | size_t size = 0; 383 | const T *end = in + length; 384 | 385 | for (; in < end; in++) 386 | size += compressed_size(*in); 387 | return size; 388 | } 389 | 390 | template 391 | static inline size_t 392 | compress_unsorted(const T *in, uint8_t *out, size_t length) 393 | { 394 | const uint8_t *initial_out = out; 395 | const T *end = in + length; 396 | 397 | while (in < end) { 398 | out += write_int(out, *in); 399 | ++in; 400 | } 401 | return out - initial_out; 402 | } 403 | 404 | template 405 | static inline size_t 406 | uncompress_unsorted(const uint8_t *in, T *out, size_t length) 407 | { 408 | const uint8_t *initial_in = in; 409 | 410 | for (size_t i = 0; i < length; i++) { 411 | in += read_int(in, out); 412 | ++out; 413 | } 414 | return in - initial_in; 415 | } 416 | 417 | template 418 | static inline size_t 419 | compress_sorted(const T *in, uint8_t *out, T previous, size_t length) 420 | { 421 | const uint8_t *initial_out = out; 422 | const T *end = in + length; 423 | 424 | while (in < end) { 425 | out += write_int(out, *in - previous); 426 | previous = *in; 427 | ++in; 428 | } 429 | return out - initial_out; 430 | } 431 | 432 | template 433 | static inline size_t 434 | uncompress_sorted(const uint8_t *in, T *out, T previous, size_t length) 435 | { 436 | const uint8_t *initial_in = in; 437 | 438 | for (size_t i = 0; i < length; i++) { 439 | T current; 440 | in += read_int(in, ¤t); 441 | previous += current; 442 | *out = previous; 443 | ++out; 444 | } 445 | return in - initial_in; 446 | } 447 | 448 | template 449 | static inline T 450 | select_sorted(const uint8_t *in, T previous, size_t index) 451 | { 452 | for (size_t i = 0; i <= index; i++) { 453 | T current; 454 | in += read_int(in, ¤t); 455 | previous += current; 456 | } 457 | return previous; 458 | } 459 | 460 | template 461 | static inline T 462 | select_unsorted(const uint8_t *in, size_t index) 463 | { 464 | T value = 0; 465 | 466 | for (size_t i = 0; i <= index; i++) 467 | in += read_int(in, &value); 468 | return value; 469 | } 470 | 471 | template 472 | static inline size_t 473 | search_unsorted(const uint8_t *in, size_t length, T value) 474 | { 475 | T v; 476 | 477 | for (size_t i = 0; i < length; i++) { 478 | in += read_int(in, &v); 479 | if (v == value) 480 | return i; 481 | } 482 | return length; 483 | } 484 | 485 | template 486 | static inline size_t 487 | sorted_search(const uint8_t *in, size_t length, T value, T previous, T *actual) 488 | { 489 | T v; 490 | 491 | for (size_t i = 0; i < length; i++) { 492 | in += read_int(in, &v); 493 | previous += v; 494 | if (previous >= value) { 495 | *actual = previous; 496 | return i; 497 | } 498 | } 499 | return length; 500 | } 501 | 502 | } // namespace vbyte 503 | 504 | size_t 505 | vbyte_compressed_size_sorted32(const uint32_t *in, size_t length, 506 | uint32_t previous) 507 | { 508 | return vbyte::compressed_size_sorted(in, length, previous); 509 | } 510 | 511 | size_t 512 | vbyte_compressed_size_sorted64(const uint64_t *in, size_t length, 513 | uint64_t previous) 514 | { 515 | return vbyte::compressed_size_sorted(in, length, previous); 516 | } 517 | 518 | size_t 519 | vbyte_compressed_size_unsorted32(const uint32_t *in, size_t length) 520 | { 521 | return vbyte::compressed_size_unsorted(in, length); 522 | } 523 | 524 | size_t 525 | vbyte_compressed_size_unsorted64(const uint64_t *in, size_t length) 526 | { 527 | return vbyte::compressed_size_unsorted(in, length); 528 | } 529 | 530 | size_t 531 | vbyte_compress_unsorted32(const uint32_t *in, uint8_t *out, size_t length) 532 | { 533 | return vbyte::compress_unsorted(in, out, length); 534 | } 535 | 536 | size_t 537 | vbyte_compress_unsorted64(const uint64_t *in, uint8_t *out, size_t length) 538 | { 539 | return vbyte::compress_unsorted(in, out, length); 540 | } 541 | 542 | size_t 543 | vbyte_uncompress_unsorted32(const uint8_t *in, uint32_t *out, size_t length) 544 | { 545 | #if defined(USE_MASKEDVBYTE) 546 | if (vbyte::is_avx_available()) 547 | return masked_vbyte_decode(in, out, (uint64_t)length); 548 | #endif 549 | return vbyte::uncompress_unsorted(in, out, length); 550 | } 551 | 552 | size_t 553 | vbyte_uncompress_unsorted64(const uint8_t *in, uint64_t *out, size_t length) 554 | { 555 | return vbyte::uncompress_unsorted(in, out, length); 556 | } 557 | 558 | size_t 559 | vbyte_compress_sorted32(const uint32_t *in, uint8_t *out, uint32_t previous, 560 | size_t length) 561 | { 562 | return vbyte::compress_sorted(in, out, previous, length); 563 | } 564 | 565 | size_t 566 | vbyte_compress_sorted64(const uint64_t *in, uint8_t *out, uint64_t previous, 567 | size_t length) 568 | { 569 | return vbyte::compress_sorted(in, out, previous, length); 570 | } 571 | 572 | size_t 573 | vbyte_uncompress_sorted32(const uint8_t *in, uint32_t *out, uint32_t previous, 574 | size_t length) 575 | { 576 | #if defined(USE_MASKEDVBYTE) 577 | if (vbyte::is_avx_available()) 578 | return masked_vbyte_decode_delta(in, out, (uint64_t)length, previous); 579 | #endif 580 | return vbyte::uncompress_sorted(in, out, previous, length); 581 | } 582 | 583 | size_t 584 | vbyte_uncompress_sorted64(const uint8_t *in, uint64_t *out, uint64_t previous, 585 | size_t length) 586 | { 587 | return vbyte::uncompress_sorted(in, out, previous, length); 588 | } 589 | 590 | uint32_t 591 | vbyte_select_sorted32(const uint8_t *in, size_t size, uint32_t previous, 592 | size_t index) 593 | { 594 | (void)size; 595 | #if defined(USE_MASKEDVBYTE) 596 | if (vbyte::is_avx_available()) 597 | return masked_vbyte_select_delta(in, (uint64_t)size, previous, index); 598 | #endif 599 | return vbyte::select_sorted(in, previous, index); 600 | } 601 | 602 | uint64_t 603 | vbyte_select_sorted64(const uint8_t *in, size_t size, uint64_t previous, 604 | size_t index) 605 | { 606 | (void)size; 607 | return vbyte::select_sorted(in, previous, index); 608 | } 609 | 610 | uint32_t 611 | vbyte_select_unsorted32(const uint8_t *in, size_t size, size_t index) 612 | { 613 | (void)size; 614 | return vbyte::select_unsorted(in, index); 615 | } 616 | 617 | uint64_t 618 | vbyte_select_unsorted64(const uint8_t *in, size_t size, size_t index) 619 | { 620 | (void)size; 621 | return vbyte::select_unsorted(in, index); 622 | } 623 | 624 | size_t 625 | vbyte_search_unsorted32(const uint8_t *in, size_t length, uint32_t value) 626 | { 627 | return vbyte::search_unsorted(in, length, value); 628 | } 629 | 630 | size_t 631 | vbyte_search_unsorted64(const uint8_t *in, size_t length, uint64_t value) 632 | { 633 | return vbyte::search_unsorted(in, length, value); 634 | } 635 | 636 | size_t 637 | vbyte_search_lower_bound_sorted32(const uint8_t *in, size_t length, 638 | uint32_t value, uint32_t previous, uint32_t *actual) 639 | { 640 | #if defined(USE_MASKEDVBYTE) 641 | if (vbyte::is_avx_available()) 642 | return (size_t)masked_vbyte_search_delta(in, (uint64_t)length, previous, 643 | value, actual); 644 | #endif 645 | return vbyte::sorted_search(in, length, value, previous, actual); 646 | } 647 | 648 | size_t 649 | vbyte_search_lower_bound_sorted64(const uint8_t *in, size_t length, 650 | uint64_t value, uint64_t previous, uint64_t *actual) 651 | { 652 | return vbyte::sorted_search(in, length, value, previous, actual); 653 | } 654 | 655 | size_t 656 | vbyte_append_sorted32(uint8_t *end, uint32_t previous, uint32_t value) 657 | { 658 | assert(value > previous); 659 | return vbyte::write_int(end, value - previous); 660 | } 661 | 662 | size_t 663 | vbyte_append_sorted64(uint8_t *end, uint64_t previous, uint64_t value) 664 | { 665 | assert(value > previous); 666 | return vbyte::write_int(end, value - previous); 667 | } 668 | 669 | size_t 670 | vbyte_append_unsorted32(uint8_t *end, uint32_t value) 671 | { 672 | return vbyte::write_int(end, value); 673 | } 674 | 675 | size_t 676 | vbyte_append_unsorted64(uint8_t *end, uint64_t value) 677 | { 678 | return vbyte::write_int(end, value); 679 | } 680 | -------------------------------------------------------------------------------- /vbyte.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-2016 Christoph Rupp (chris@crupp.de). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * A fast implementation for the Variable Byte encoding. 19 | * 20 | * See the README.md file for more information, example code and references. 21 | * 22 | * Feel free to send comments/questions to chris@crupp.de. I am available 23 | * for consulting. 24 | */ 25 | 26 | #ifndef VBYTE_H_ee452711_c856_416d_82f4_e12eef8a49be 27 | #define VBYTE_H_ee452711_c856_416d_82f4_e12eef8a49be 28 | 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /** 36 | * Calculates the size (in bytes) of a compressed stream of sorted 32bit 37 | * integers. 38 | * 39 | * This calculation is relatively expensive. As a cheap estimate, simply 40 | * multiply the number of integers by 5. 41 | * 42 | * This function uses delta encoding. Set |previous| to the initial value, 43 | * or 0. 44 | */ 45 | extern size_t 46 | vbyte_compressed_size_sorted32(const uint32_t *in, size_t length, 47 | uint32_t previous); 48 | 49 | /** 50 | * Calculates the size (in bytes) of a compressed stream of sorted 64bit 51 | * integers. 52 | * 53 | * This calculation is relatively expensive. As a cheap estimate, simply 54 | * multiply the number of integers by 5. 55 | * 56 | * This function uses delta encoding. Set |previous| to the initial value, 57 | * or 0. 58 | */ 59 | extern size_t 60 | vbyte_compressed_size_sorted64(const uint64_t *in, size_t length, 61 | uint64_t previous); 62 | 63 | /** 64 | * Calculates the size (in bytes) of a compressed stream of unsorted 32bit 65 | * integers. 66 | * 67 | * This calculation is relatively expensive. As a cheap estimate, simply 68 | * multiply the number of integers by 5. 69 | * 70 | * This function does NOT use delta encoding. 71 | */ 72 | extern size_t 73 | vbyte_compressed_size_unsorted32(const uint32_t *in, size_t length); 74 | 75 | /** 76 | * Calculates the size (in bytes) of a compressed stream of unsorted 64bit 77 | * integers. 78 | * 79 | * This calculation is relatively expensive. As a cheap estimate, simply 80 | * multiply the number of integers by 10. 81 | * 82 | * This function does NOT use delta encoding. 83 | */ 84 | extern size_t 85 | vbyte_compressed_size_unsorted64(const uint64_t *in, size_t length); 86 | 87 | /** 88 | * Compresses an unsorted sequence of |length| 32bit unsigned integers 89 | * at |in| and stores the result in |out|. 90 | * 91 | * This function does NOT use delta encoding. 92 | */ 93 | extern size_t 94 | vbyte_compress_unsorted32(const uint32_t *in, uint8_t *out, size_t length); 95 | 96 | /** 97 | * Compresses an unsorted sequence of |length| 64bit unsigned integers 98 | * at |in| and stores the result in |out|. 99 | * 100 | * This function does NOT use delta encoding. 101 | */ 102 | extern size_t 103 | vbyte_compress_unsorted64(const uint64_t *in, uint8_t *out, size_t length); 104 | 105 | /** 106 | * Compresses a sorted sequence of |length| 32bit unsigned integers 107 | * at |in| and stores the result in |out|. 108 | * 109 | * This function uses delta encoding. Set |previous| to the initial value, 110 | * or 0. 111 | */ 112 | extern size_t 113 | vbyte_compress_sorted32(const uint32_t *in, uint8_t *out, uint32_t previous, 114 | size_t length); 115 | 116 | /** 117 | * Compresses a sorted sequence of |length| 64bit unsigned integers 118 | * at |in| and stores the result in |out|. 119 | * 120 | * This function uses delta encoding. Set |previous| to the initial value, 121 | * or 0. 122 | */ 123 | extern size_t 124 | vbyte_compress_sorted64(const uint64_t *in, uint8_t *out, uint64_t previous, 125 | size_t length); 126 | 127 | /** 128 | * Uncompresses a sequence of |length| 32bit unsigned integers at |in| 129 | * and stores the result in |out|. 130 | * 131 | * This is the equivalent of |vbyte_compress_unsorted32|. It does NOT use 132 | * delta encoding. 133 | * 134 | * Returns the number of compressed bytes processed. 135 | */ 136 | extern size_t 137 | vbyte_uncompress_unsorted32(const uint8_t *in, uint32_t *out, size_t length); 138 | 139 | /** 140 | * Uncompresses a sequence of |length| 64bit unsigned integers at |in| 141 | * and stores the result in |out|. 142 | * 143 | * This is the equivalent of |vbyte_compress_unsorted64|. It does NOT use 144 | * delta encoding. 145 | * 146 | * Returns the number of compressed bytes processed. 147 | */ 148 | extern size_t 149 | vbyte_uncompress_unsorted64(const uint8_t *in, uint64_t *out, size_t length); 150 | 151 | /** 152 | * Uncompresses a sequence of |length| 32bit unsigned integers at |in| 153 | * and stores the result in |out|. 154 | * 155 | * This is the equivalent of |vbyte_compress_sorted32|. 156 | * This function uses delta encoding. Set |previous| to the initial value, 157 | * or 0. 158 | * 159 | * Returns the number of compressed bytes processed. 160 | */ 161 | extern size_t 162 | vbyte_uncompress_sorted32(const uint8_t *in, uint32_t *out, uint32_t previous, 163 | size_t length); 164 | 165 | /** 166 | * Uncompresses a sequence of |length| 64bit unsigned integers at |in| 167 | * and stores the result in |out|. 168 | * 169 | * This is the equivalent of |vbyte_compress_sorted64|. 170 | * This function uses delta encoding. Set |previous| to the initial value, 171 | * or 0. 172 | * 173 | * Returns the number of compressed bytes processed. 174 | */ 175 | extern size_t 176 | vbyte_uncompress_sorted64(const uint8_t *in, uint64_t *out, uint64_t previous, 177 | size_t length); 178 | 179 | /** 180 | * Returns the value at the given |index| from a sequence of compressed 181 | * 32bit integers. 182 | * 183 | * This function uses delta encoding. Set |previous| to the initial value, 184 | * or 0. 185 | * 186 | * |size| is the size of the byte array pointed to by |in|. 187 | * Make sure that |index| does not exceed the length of the sequence. 188 | */ 189 | extern uint32_t 190 | vbyte_select_sorted32(const uint8_t *in, size_t size, uint32_t previous, 191 | size_t index); 192 | 193 | /** 194 | * Returns the value at the given |index| from a sequence of compressed 195 | * 64bit integers. 196 | * 197 | * This function uses delta encoding. Set |previous| to the initial value, 198 | * or 0. 199 | * 200 | * |size| is the size of the byte array pointed to by |in|. 201 | * Make sure that |index| does not exceed the length of the sequence. 202 | */ 203 | extern uint64_t 204 | vbyte_select_sorted64(const uint8_t *in, size_t size, uint64_t previous, 205 | size_t index); 206 | 207 | /** 208 | * Returns the value at the given |index| from a sequence of compressed 209 | * 32bit integers. 210 | * 211 | * This routine does NOT use delta compression. 212 | * 213 | * |size| is the size of the byte array pointed to by |in|. 214 | * Make sure that |index| does not exceed the length of the sequence. 215 | */ 216 | extern uint32_t 217 | vbyte_select_unsorted32(const uint8_t *in, size_t size, size_t index); 218 | 219 | /** 220 | * Returns the value at the given |index| from a sequence of compressed 221 | * 64bit integers. 222 | * 223 | * This routine does NOT use delta compression. 224 | * 225 | * |size| is the size of the byte array pointed to by |in|. 226 | * Make sure that |index| does not exceed the length of the sequence. 227 | */ 228 | extern uint64_t 229 | vbyte_select_unsorted64(const uint8_t *in, size_t size, size_t index); 230 | 231 | 232 | /** 233 | * Performs a linear search for |value| in a sequence of compressed 32bit 234 | * unsigned integers. 235 | * 236 | * This function does NOT use delta encoding. 237 | * 238 | * Returns the index of the found element, or |length| if the key was not 239 | * found. 240 | */ 241 | extern size_t 242 | vbyte_search_unsorted32(const uint8_t *in, size_t length, uint32_t value); 243 | 244 | /** 245 | * Performs a linear search for |value| in a sequence of compressed 64bit 246 | * unsigned integers. 247 | * 248 | * This function does NOT use delta encoding. 249 | * 250 | * Returns the index of the found element, or |length| if the key was not 251 | * found. 252 | */ 253 | extern size_t 254 | vbyte_search_unsorted64(const uint8_t *in, size_t length, uint64_t value); 255 | 256 | 257 | /** 258 | * Performs a lower-bound search for |value| in a sequence of compressed 32bit 259 | * unsigned integers. 260 | * 261 | * A lower bound search returns the first element in the sequence which does 262 | * not compare less than |value|. 263 | * The actual result is stored in |*actual|. 264 | * 265 | * This function uses delta encoding. Set |previous| to the initial value, 266 | * or 0. 267 | * 268 | * Returns the index of the found element, or |length| if the key was not 269 | * found. 270 | */ 271 | extern size_t 272 | vbyte_search_lower_bound_sorted32(const uint8_t *in, size_t length, 273 | uint32_t value, uint32_t previous, uint32_t *actual); 274 | 275 | /** 276 | * Performs a lower-bound search for |value| in a sequence of compressed 64bit 277 | * unsigned integers. 278 | * 279 | * A lower bound search returns the first element in the sequence which does 280 | * not compare less than |value|. 281 | * The actual result is stored in |*actual|. 282 | * 283 | * This function uses delta encoding. Set |previous| to the initial value, 284 | * or 0. 285 | * 286 | * Returns the index of the found element, or |length| if the key was not 287 | * found. 288 | */ 289 | extern size_t 290 | vbyte_search_lower_bound_sorted64(const uint8_t *in, size_t length, 291 | uint64_t value, uint64_t previous, uint64_t *actual); 292 | 293 | 294 | /** 295 | * Appends |value| to a sequence of compressed 32bit unsigned integers. 296 | * 297 | * |end| is a pointer to the end of the compressed sequence (the first byte 298 | * AFTER the compressed data). 299 | * |previous| is the greatest encoded value in the sequence. 300 | * 301 | * This function uses delta encoding. 302 | * 303 | * Returns the number of bytes required to compress |value|. 304 | */ 305 | extern size_t 306 | vbyte_append_sorted32(uint8_t *end, uint32_t previous, uint32_t value); 307 | 308 | /** 309 | * Appends |value| to a sequence of compressed 64bit unsigned integers. 310 | * 311 | * |end| is a pointer to the end of the compressed sequence (the first byte 312 | * AFTER the compressed data). 313 | * |previous| is the greatest encoded value in the sequence. 314 | * 315 | * This function uses delta encoding. 316 | * 317 | * Returns the number of bytes required to compress |value|. 318 | */ 319 | extern size_t 320 | vbyte_append_sorted64(uint8_t *end, uint64_t previous, uint64_t value); 321 | 322 | /** 323 | * Appends |value| to a sequence of compressed 32bit unsigned integers. 324 | * 325 | * |end| is a pointer to the end of the compressed sequence (the first byte 326 | * AFTER the compressed data). 327 | * 328 | * This function does NOT use encoding. 329 | * 330 | * Returns the number of bytes required to compress |value|. 331 | */ 332 | extern size_t 333 | vbyte_append_unsorted32(uint8_t *end, uint32_t value); 334 | 335 | /** 336 | * Appends |value| to a sequence of compressed 64bit unsigned integers. 337 | * 338 | * |end| is a pointer to the end of the compressed sequence (the first byte 339 | * AFTER the compressed data). 340 | * 341 | * This function does NOT use encoding. 342 | * 343 | * Returns the number of bytes required to compress |value|. 344 | */ 345 | extern size_t 346 | vbyte_append_unsorted64(uint8_t *end, uint64_t value); 347 | 348 | 349 | #ifdef __cplusplus 350 | } /* extern "C" */ 351 | #endif 352 | 353 | #endif /* VBYTE_H_ee452711_c856_416d_82f4_e12eef8a49be */ 354 | --------------------------------------------------------------------------------