pax_global_header00006660000000000000000000000064134646005360014521gustar00rootroot0000000000000052 comment=92ab8a74c96b9e0f684c45aec9cf7f57405ff8da streamvbyte-0.4.1/000077500000000000000000000000001346460053600140705ustar00rootroot00000000000000streamvbyte-0.4.1/.gitignore000066400000000000000000000003661346460053600160650ustar00rootroot00000000000000# Object files *.o *.ko *.obj *.elf # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ streamvbyte-0.4.1/.travis.yml000066400000000000000000000002641346460053600162030ustar00rootroot00000000000000language: c sudo: false compiler: - clang script: make && ./unit && make example && ./example && make perf && ./perf && mkdir build && cd build && cmake .. && make && make test streamvbyte-0.4.1/AUTHORS000066400000000000000000000002071346460053600151370ustar00rootroot00000000000000# this is the official list of authors for copyright purposes Daniel Lemire Kendall Willets Alexander Gallego @aqrit Vladimir Kazanov streamvbyte-0.4.1/CMakeLists.txt000066400000000000000000000065571346460053600166450ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.3) set(CMAKE_MACOSX_RPATH OFF) if (NOT CMAKE_BUILD_TYPE) message(STATUS "No build type selected, default to Release") set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) endif() project(STREAMVBYTE VERSION "0.0.1") cmake_policy(SET CMP0065 OLD) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -v" ) set(BASE_FLAGS "-std=c99" "-fPIC" "-Wextra" "-pedantic" "-Wshadow" ) if(CMAKE_BUILD_TYPE MATCHES Debug) set(BASE_FLAGS ${BASE_FLAGS} "-O0" "-ggdb" ) else() set(BASE_FLAGS ${BASE_FLAGS} "-O3" "-g" ) endif() # test for arm if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") set(BASE_FLAGS ${BASE_FLAGS} "-D__ARM_NEON__" ) endif() set(STREAMVBYTE_SRCS ${PROJECT_SOURCE_DIR}/src/streamvbyte_encode.c ${PROJECT_SOURCE_DIR}/src/streamvbyte_decode.c ${PROJECT_SOURCE_DIR}/src/streamvbyte_zigzag.c ${PROJECT_SOURCE_DIR}/src/streamvbytedelta_encode.c ${PROJECT_SOURCE_DIR}/src/streamvbytedelta_decode.c ${PROJECT_SOURCE_DIR}/src/streamvbyte_0124_encode.c ${PROJECT_SOURCE_DIR}/src/streamvbyte_0124_decode.c ) add_library(streamvbyte_static STATIC "${STREAMVBYTE_SRCS}") target_link_libraries(streamvbyte_static ${BASE_FLAGS}) add_library(streamvbyte SHARED "${STREAMVBYTE_SRCS}") target_link_libraries(streamvbyte ${BASE_FLAGS}) target_include_directories( streamvbyte PUBLIC ${PROJECT_SOURCE_DIR}/include ) target_include_directories( streamvbyte_static PUBLIC ${PROJECT_SOURCE_DIR}/include ) install(FILES ${PROJECT_SOURCE_DIR}/include/streamvbyte.h ${PROJECT_SOURCE_DIR}/include/streamvbytedelta.h ${PROJECT_SOURCE_DIR}/include/streamvbyte_zigzag.h DESTINATION include ) install( TARGETS streamvbyte streamvbyte_static DESTINATION lib) ## -march=native is not supported on some platforms if(NOT MSVC) if(NOT STREAMVBYTE_DISABLE_NATIVE) set(OPT_FLAGS "-march=native") endif() endif() set(CMAKE_C_FLAGS "${STD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SANITIZE_FLAGS} ") MESSAGE( STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR}) MESSAGE( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} ) # this tends to be "sticky" so you can remain unknowingly in debug mode MESSAGE( STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER} ) # important to know which compiler is used MESSAGE( STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS} ) # important to know the flags MESSAGE( STATUS "CMAKE_C_FLAGS_DEBUG: " ${CMAKE_C_FLAGS_DEBUG} ) MESSAGE( STATUS "CMAKE_C_FLAGS_RELEASE: " ${CMAKE_C_FLAGS_RELEASE} ) # build programs # example add_executable (example ${PROJECT_SOURCE_DIR}/example.c) target_link_libraries (example streamvbyte_static) # perf add_executable (perf ${PROJECT_SOURCE_DIR}/tests/perf.c) target_link_libraries (perf streamvbyte_static) target_link_libraries(perf m) # writeseq add_executable (writeseq ${PROJECT_SOURCE_DIR}/tests/writeseq.c) target_link_libraries (writeseq streamvbyte_static) # unit add_executable (unit ${PROJECT_SOURCE_DIR}/tests/unit.c) target_link_libraries (unit streamvbyte_static) option(STREAMVBYTE_ENABLE_TESTS "enable unit tests for streamvbyte" ON) if(STREAMVBYTE_ENABLE_TESTS) enable_testing() # add unit tests add_test(NAME unit COMMAND unit) add_custom_target(check COMMAND ctest --output-on-failure DEPENDS unit) endif() streamvbyte-0.4.1/LICENSE000066400000000000000000000260751346460053600151070ustar00rootroot00000000000000Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. streamvbyte-0.4.1/Makefile000066400000000000000000000061551346460053600155370ustar00rootroot00000000000000# minimalist makefile .SUFFIXES: # .SUFFIXES: .cpp .o .c .h PROCESSOR:=$(shell uname -m) ifeq ($(PROCESSOR), aarch64) # for 64-bit ARM processors CFLAGS = -fPIC -std=c99 -O3 -Wall -Wextra -pedantic -Wshadow -D__ARM_NEON__ else ifeq ($(PROCESSOR), armv7l) # for 32-bit ARM processors CFLAGS = -fPIC -std=c99 -O3 -Wall -Wextra -pedantic -Wshadow else # Here we expect x64 # Formally speaking, we only need SSE4, at best, but code checks for AVX # since MSVC only allows to check for AVX and nothing finer like just SSE4 CFLAGS = -fPIC -march=native -std=c99 -O3 -Wall -Wextra -pedantic -Wshadow endif LDFLAGS = -shared LIBNAME=libstreamvbyte.so.0.0.1 LNLIBNAME=libstreamvbyte.so all: unit $(LIBNAME) test: ./unit dyntest: dynunit $(LNLIBNAME) LD_LIBRARY_PATH=. ./dynunit install: $(OBJECTS) $(LIBNAME) cp $(LIBNAME) /usr/local/lib ln -f -s /usr/local/lib/$(LIBNAME) /usr/local/lib/libstreamvbyte.so ldconfig cp $(HEADERS) /usr/local/include HEADERS=./include/streamvbyte.h ./include/streamvbytedelta.h ./include/streamvbyte_zigzag.h uninstall: for h in $(HEADERS) ; do rm /usr/local/$$h; done rm /usr/local/lib/$(LIBNAME) rm /usr/local/lib/libstreamvbyte.so ldconfig OBJECTS= streamvbyte_decode.o streamvbyte_encode.o streamvbytedelta_decode.o streamvbytedelta_encode.o streamvbyte_0124_encode.o streamvbyte_0124_decode.o streamvbyte_zigzag.o streamvbyte_zigzag.o: ./src/streamvbyte_zigzag.c $(HEADERS) $(CC) $(CFLAGS) -c ./src/streamvbyte_zigzag.c -Iinclude streamvbytedelta_encode.o: ./src/streamvbytedelta_encode.c $(HEADERS) $(CC) $(CFLAGS) -c ./src/streamvbytedelta_encode.c -Iinclude streamvbytedelta_decode.o: ./src/streamvbytedelta_decode.c $(HEADERS) $(CC) $(CFLAGS) -c ./src/streamvbytedelta_decode.c -Iinclude streamvbyte_0124_encode.o: ./src/streamvbyte_0124_encode.c $(HEADERS) $(CC) $(CFLAGS) -c ./src/streamvbyte_0124_encode.c -Iinclude streamvbyte_0124_decode.o: ./src/streamvbyte_0124_decode.c $(HEADERS) $(CC) $(CFLAGS) -c ./src/streamvbyte_0124_decode.c -Iinclude streamvbyte_decode.o: ./src/streamvbyte_decode.c $(HEADERS) $(CC) $(CFLAGS) -c ./src/streamvbyte_decode.c -Iinclude streamvbyte_encode.o: ./src/streamvbyte_encode.c $(HEADERS) $(CC) $(CFLAGS) -c ./src/streamvbyte_encode.c -Iinclude $(LIBNAME): $(OBJECTS) $(CC) $(CFLAGS) -o $(LIBNAME) $(OBJECTS) $(LDFLAGS) $(LNLIBNAME): $(LIBNAME) ln -f -s $(LIBNAME) $(LNLIBNAME) shuffle_tables: ./utils/shuffle_tables.c $(CC) $(CFLAGS) -o shuffle_tables ./utils/shuffle_tables.c example: ./example.c $(HEADERS) $(OBJECTS) $(CC) $(CFLAGS) -o example ./example.c -Iinclude $(OBJECTS) perf: ./tests/perf.c $(HEADERS) $(OBJECTS) $(CC) $(CFLAGS) -o perf ./tests/perf.c -Iinclude $(OBJECTS) -lm writeseq: ./tests/writeseq.c $(HEADERS) $(OBJECTS) $(CC) $(CFLAGS) -o writeseq ./tests/writeseq.c -Iinclude $(OBJECTS) unit: ./tests/unit.c $(HEADERS) $(OBJECTS) $(CC) $(CFLAGS) -o unit ./tests/unit.c -Iinclude $(OBJECTS) dynunit: ./tests/unit.c $(HEADERS) $(LIBNAME) $(LNLIBNAME) $(CC) $(CFLAGS) -o dynunit ./tests/unit.c -Iinclude -L. -lstreamvbyte clean: rm -f unit *.o $(LIBNAME) $(LNLIBNAME) example shuffle_tables perf writeseq dynunit streamvbyte-0.4.1/README.md000066400000000000000000000174141346460053600153560ustar00rootroot00000000000000streamvbyte =========== [![Build Status](https://travis-ci.org/lemire/streamvbyte.png)](https://travis-ci.org/lemire/streamvbyte) StreamVByte is a new integer compression technique that applies SIMD instructions (vectorization) to Google's Group Varint approach. The net result is faster than other byte-oriented compression techniques. The approach is patent-free, the code is available under the Apache License. It includes fast differential coding. It assumes a recent Intel processor (e.g., haswell or better) or an ARM processor with NEON instructions (which is almost all of them). The code should build using most standard-compliant C99 compilers. The provided makefile expects a Linux-like system. This library is used by [UpscaleDB](https://github.com/cruppstahl/upscaledb), Redis' [RediSearch](https://github.com/RedisLabsModules/RediSearch) and by the [Trinity Information Retrieval framework](https://github.com/phaistos-networks/Trinity). Usage with Makefile: make ./unit Usage with CMake: The cmake build system also offers a `libstreamvbyte_static.a` in addition to `libstreamvbyte.so`. `-DCMAKE_INSTALL_PREFIX:PATH=/path/to/install` is optional. Defaults to /usr/local{include,lib} By default, the project builds with ``-march=native`` (except on MSVC), use ``-DSTREAMVBYTE_DISABLE_NATIVE=ON`` to disable. ``` mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install \ make install # run the tests like: ctest -V ``` See example.c for an example. Short code sample: ```C // suppose that datain is an array of uint32_t integers size_t compsize = streamvbyte_encode(datain, N, compressedbuffer); // encoding // here the result is stored in compressedbuffer using compsize bytes streamvbyte_decode(compressedbuffer, recovdata, N); // decoding (fast) ``` If the values are sorted, then it might be preferable to use differential coding: ```C // suppose that datain is an array of uint32_t integers size_t compsize = streamvbyte_delta_encode(datain, N, compressedbuffer,0); // encoding // here the result is stored in compressedbuffer using compsize bytes streamvbyte_delta_decode(compressedbuffer, recovdata, N,0); // decoding (fast) ``` You have to know how many integers were coded when you decompress. You can store this information along with the compressed stream. Signed integers ----------------- We do not directly support signed integers, but you can use fast functions to convert signed integers to unsigned integers. ```C #include "streamvbyte_zigzag.h" zigzag_encode(mysignedints, myunsignedints, number); // mysignedints => myunsignedints zigzag_decode(myunsignedints, mysignedints, number); // myunsignedints => mysignedints ``` Installation ---------------- You can install the library (as a dynamic library) on your machine if you have root access: sudo make install To uninstall, simply type: sudo make uninstall It is recommended that you try ``make dyntest`` before proceeding. Benchmarking ----------------- You can try to benchmark the speed in this manner: make perf ./perf Make sure to run ``make test`` before, as a sanity test. Technical posts --------------- * [Trinity Updates and integer codes benchmarks](https://medium.com/@markpapadakis/trinity-updates-and-integer-codes-benchmarks-6a4fa2eb3fd1) by Mark Papadakis * [Stream VByte: breaking new speed records for integer compression](https://lemire.me/blog/2017/09/27/stream-vbyte-breaking-new-speed-records-for-integer-compression/) by Daniel Lemire Alternative encoding ------------------------------- By default, Stream VByte uses 1, 2, 3 or 4 bytes per integer. In the case where you expect many of your integers to be zero, you might try the ``streamvbyte_encode_0124`` and ``streamvbyte_decode_0124`` which use 0, 1, 2, or 4 bytes per integer. Stream VByte in other languages -------------------------------- * There is a [Rust version](https://bitbucket.org/marshallpierce/stream-vbyte-rust) by Marshall Pierce. * There is a [Go version](https://github.com/nelz9999/stream-vbyte-go) by Nelz. Format Specification --------------------- We specify the format as follows. We do not store how many integers (``count``) are compressed in the compressed data per se. If you want to store the data stream (e.g., to disk), you need to add this information. It is intentionally left out because, in applications, it is often the case that there are better ways to store this count. There are two streams: - The data starts with an array of "control bytes". There are (count + 3) / 4 of them. - Following the array of control bytes, there are data bytes. We can interpret the control bytes as a sequence of 2-bit words. The first 2-bit word is made of the least significant 2 bits in the first byte, and so forth. There are four 2-bit words written in each byte. Starting from the first 2-bit word, we have corresponding sequence in the data bytes, written in sequence from the beginning: - When the 2-bit word is 00, there is a single data byte. - When the 2-bit words is 01, there are two data bytes. - When the 2-bit words is 10, there are three data bytes. - When the 2-bit words is 11, there are four data bytes. The data bytes are stored using a little-endian encoding. Consider the following example: ``` control bytes: [0x40 0x55 ... ] data bytes: [0x00 0x64 0xc8 0x2c 0x01 0x90 0x01 0xf4 0x01 0x58 0x02 0xbc 0x02 ...] ``` The first control byte is 0x40 or the four 2-bit words : ``00 00 00 01``. The second control byte is 0x55 or the four 2-bit words : ``01 01 01 01``. Thus the first three values are given by the first three bytes: ``0x00, 0x64, 0xc8`` (or 0, 100, 200 in base 10). The five next values are stored using two bytes each: ``0x2c 0x01, 0x90 0x01, 0xf4 0x01, 0x58 0x02, 0xbc 0x02``. As little endian integers, these are to be interpreted as 300, 400, 500, 600, 700. Thus, to recap, the sequence of integers (0,100,200,300,400,500,600,700) gets encoded as the 15 bytes ``0x40 0x55 0x00 0x64 0xc8 0x2c 0x01 0x90 0x01 0xf4 0x01 0x58 0x02 0xbc 0x02``. If the ``count``is not divisible by four, then we include a final partial group where we use zero 2-bit corresponding to no data byte. Reference --------- * Daniel Lemire, Nathan Kurz, Christoph Rupp, [Stream VByte: Faster Byte-Oriented Integer Compression](https://arxiv.org/abs/1709.08990), Information Processing Letters 130, 2018. See also -------- * SIMDCompressionAndIntersection: A C++ library to compress and intersect sorted lists of integers using SIMD instructions https://github.com/lemire/SIMDCompressionAndIntersection * The FastPFOR C++ library : Fast integer compression https://github.com/lemire/FastPFor * High-performance dictionary coding https://github.com/lemire/dictionary * LittleIntPacker: C library to pack and unpack short arrays of integers as fast as possible https://github.com/lemire/LittleIntPacker * The SIMDComp library: A simple C library for compressing lists of integers using binary packing https://github.com/lemire/simdcomp * MaskedVByte: Fast decoder for VByte-compressed integers https://github.com/lemire/MaskedVByte * CSharpFastPFOR: A C# integer compression library https://github.com/Genbox/CSharpFastPFOR * JavaFastPFOR: A java integer compression library https://github.com/lemire/JavaFastPFOR * Encoding: Integer Compression Libraries for Go https://github.com/zhenjl/encoding * FrameOfReference is a C++ library dedicated to frame-of-reference (FOR) compression: https://github.com/lemire/FrameOfReference * libvbyte: A fast implementation for varbyte 32bit/64bit integer compression https://github.com/cruppstahl/libvbyte * TurboPFor is a C library that offers lots of interesting optimizations. Well worth checking! (GPL license) https://github.com/powturbo/TurboPFor * Oroch is a C++ library that offers a usable API (MIT license) https://github.com/ademakov/Oroch streamvbyte-0.4.1/example.c000066400000000000000000000013731346460053600156730ustar00rootroot00000000000000#include #include #include #include "streamvbyte.h" int main() { int N = 5000; uint32_t * datain = malloc(N * sizeof(uint32_t)); uint8_t * compressedbuffer = malloc(streamvbyte_max_compressedbytes(N)); uint32_t * recovdata = malloc(N * sizeof(uint32_t)); for (int k = 0; k < N; ++k) datain[k] = 120; size_t compsize = streamvbyte_encode(datain, N, compressedbuffer); // encoding // here the result is stored in compressedbuffer using compsize bytes size_t compsize2 = streamvbyte_decode(compressedbuffer, recovdata, N); // decoding (fast) assert(compsize == compsize2); free(datain); free(compressedbuffer); free(recovdata); printf("Compressed %d integers down to %d bytes.\n",N,(int) compsize); return 0; } streamvbyte-0.4.1/include/000077500000000000000000000000001346460053600155135ustar00rootroot00000000000000streamvbyte-0.4.1/include/streamvbyte.h000066400000000000000000000042371346460053600202370ustar00rootroot00000000000000 #ifndef INCLUDE_STREAMVBYTE_H_ #define INCLUDE_STREAMVBYTE_H_ #define __STDC_FORMAT_MACROS #include #include // please use a C99-compatible compiler #include #if defined(__cplusplus) extern "C" { #endif // Encode an array of a given length read from in to bout in varint format. // Returns the number of bytes written. // The number of values being stored (length) is not encoded in the compressed stream, // the caller is responsible for keeping a record of this length. // The pointer "in" should point to "length" values of size uint32_t // there is no alignment requirement on the out pointer // For safety, the out pointer should point to at least streamvbyte_max_compressedbyte(length) // bytes. // Uses 1,2,3 or 4 bytes per value + the decoding keys. size_t streamvbyte_encode(const uint32_t *in, uint32_t length, uint8_t *out); // same as streamvbyte_encode but 0,1,2 or 4 bytes per value (plus decoding keys) instead of using 1,2,3 or 4 // bytes. This might be useful when there's a lot of zeroes in the input array. size_t streamvbyte_encode_0124(const uint32_t *in, uint32_t length, uint8_t *out); // return the maximum number of compressed bytes given length input integers static inline size_t streamvbyte_max_compressedbytes(const uint32_t length) { // number of control bytes: size_t cb = (length + 3) / 4; // maximum number of control bytes: size_t db = (size_t) length * sizeof(uint32_t); return cb + db; } // Read "length" 32-bit integers in varint format from in, storing the result in out. // Returns the number of bytes read. // The caller is responsible for knowing how many integers ("length") are to be read: // this information ought to be stored somehow. // There is no alignment requirement on the "in" pointer. // The out pointer should point to length * sizeof(uint32_t) bytes. size_t streamvbyte_decode(const uint8_t *in, uint32_t *out, uint32_t length); // Same as streamvbyte_decode but is meant to be used for streams encoded with // streamvbyte_encode_0124. size_t streamvbyte_decode_0124(const uint8_t *in, uint32_t *out, uint32_t length); #if defined(__cplusplus) }; #endif #endif /* INCLUDE_STREAMVBYTE_H_ */ streamvbyte-0.4.1/include/streamvbyte_zigzag.h000066400000000000000000000017531346460053600216120ustar00rootroot00000000000000 #ifndef INCLUDE_STREAMVBYTE_ZIGZAG_H_ #define INCLUDE_STREAMVBYTE_ZIGZAG_H_ #define __STDC_FORMAT_MACROS #include #include // please use a C99-compatible compiler #include #if defined(__cplusplus) extern "C" { #endif /** * Convert N signed integers to N unsigned integers, using zigzag * encoding. */ void zigzag_encode(const int32_t * in, uint32_t * out, size_t N); /** * Convert N signed integers to N unsigned integers, using zigzag * delta encoding. */ void zigzag_delta_encode(const int32_t * in, uint32_t * out, size_t N, int32_t prev); /** * Convert N unsigned integers to N signed integers, using zigzag * encoding. */ void zigzag_decode(const uint32_t * in, int32_t * out, size_t N); /** * Convert N unsigned integers to N signed integers, using zigzag * delta encoding. */ void zigzag_delta_decode(const uint32_t * in, int32_t * out, size_t N, int32_t prev); #if defined(__cplusplus) }; #endif #endif /* INCLUDE_STREAMVBYTE_ZIGZAG_H_ */ streamvbyte-0.4.1/include/streamvbytedelta.h000066400000000000000000000032031346460053600212410ustar00rootroot00000000000000#ifndef INCLUDE_STREAMVBYTEDELTA_H_ #define INCLUDE_STREAMVBYTEDELTA_H_ #if defined(__cplusplus) extern "C" { #endif #include #include // please use a C99-compatible compiler #include // Encode an array of a given length read from in to bout in StreamVByte format. // Returns the number of bytes written. // The number of values being stored (length) is not encoded in the compressed stream, // the caller is responsible for keeping a record of this length. // The pointer "in" should point to "length" values of size uint32_t // there is no alignment requirement on the out pointer // this version uses differential coding (coding differences between values) starting at prev (you can often set prev to zero) // For safety, the out pointer should point to at least streamvbyte_max_compressedbyte(length) // bytes ( see streamvbyte.h ) size_t streamvbyte_delta_encode(const uint32_t *in, uint32_t length, uint8_t *out, uint32_t prev); // Read "length" 32-bit integers in StreamVByte format from in, storing the result in out. // Returns the number of bytes read. // The caller is responsible for knowing how many integers ("length") are to be read: // this information ought to be stored somehow. // There is no alignment requirement on the "in" pointer. // The out pointer should point to length * sizeof(uint32_t) bytes. // this version uses differential coding (coding differences between values) starting at prev (you can often set prev to zero) size_t streamvbyte_delta_decode(const uint8_t *in, uint32_t *out, uint32_t length, uint32_t prev); #if defined(__cplusplus) }; #endif #endif /* INCLUDE_STREAMVBYTEDELTA_H_ */ streamvbyte-0.4.1/src/000077500000000000000000000000001346460053600146575ustar00rootroot00000000000000streamvbyte-0.4.1/src/streamvbyte_0124_decode.c000066400000000000000000000122041346460053600213400ustar00rootroot00000000000000#include "streamvbyte.h" #if defined(_MSC_VER) /* Microsoft C/C++-compatible compiler */ #include #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) /* GCC-compatible compiler, targeting x86/x86-64 */ #include #endif #ifdef __AVX__ #include "streamvbyte_shuffle_tables_0124_decode.h" #endif #include // for memcpy #ifdef __AVX__ // though we do not require AVX per se, it is a macro that MSVC // will issue static inline __m128i _decode_avx(uint32_t key, const uint8_t *__restrict__ *dataPtrPtr) { uint8_t len; __m128i Data = _mm_loadu_si128((__m128i *)*dataPtrPtr); uint8_t *pshuf = (uint8_t *) &shuffleTable[key]; __m128i Shuf = *(__m128i *)pshuf; len = lengthTable[key]; Data = _mm_shuffle_epi8(Data, Shuf); *dataPtrPtr += len; return Data; } static inline void _write_avx(uint32_t *out, __m128i Vec) { _mm_storeu_si128((__m128i *)out, Vec); } #endif // __AVX__ static inline uint32_t _decode_data(const uint8_t **dataPtrPtr, uint8_t code) { const uint8_t *dataPtr = *dataPtrPtr; uint32_t val; if (code == 0) { // 0 byte val = 0; } else if (code == 1) { // 1 bytes val = (uint32_t)*dataPtr; dataPtr += 1; } else if (code == 2) { // 2 bytes val = 0; memcpy(&val, dataPtr, 2); // assumes little endian dataPtr += 2; } else { // code == 3, 4 bytes memcpy(&val, dataPtr, 4); dataPtr += 4; } *dataPtrPtr = dataPtr; return val; } static const uint8_t *svb_decode_scalar(uint32_t *outPtr, const uint8_t *keyPtr, const uint8_t *dataPtr, uint32_t count) { if (count == 0) return dataPtr; // no reads or writes if no data uint8_t shift = 0; uint32_t key = *keyPtr++; for (uint32_t c = 0; c < count; c++) { if (shift == 8) { shift = 0; key = *keyPtr++; } uint32_t val = _decode_data(&dataPtr, (key >> shift) & 0x3); *outPtr++ = val; shift += 2; } return dataPtr; // pointer to first unused byte after end } #ifdef __AVX__ // though we do not require AVX per se, it is a macro that MSVC // will issue static const uint8_t *svb_decode_avx_simple(uint32_t *out, const uint8_t *__restrict__ keyPtr, const uint8_t *__restrict__ dataPtr, uint64_t count) { uint64_t keybytes = count / 4; // number of key bytes __m128i Data; if (keybytes >= 8) { int64_t Offset = -(int64_t)keybytes / 8 + 1; const uint64_t *keyPtr64 = (const uint64_t *)keyPtr - Offset; uint64_t nextkeys; memcpy(&nextkeys, keyPtr64 + Offset, sizeof(nextkeys)); for (; Offset != 0; ++Offset) { uint64_t keys = nextkeys; memcpy(&nextkeys, keyPtr64 + Offset + 1, sizeof(nextkeys)); Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 4, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 8, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 12, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 16, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 20, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 24, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 28, Data); out += 32; } { uint64_t keys = nextkeys; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 4, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 8, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 12, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 16, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 20, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 24, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 28, Data); out += 32; } } return dataPtr; } #endif // Read count 32-bit integers in maskedvbyte format from in, storing the result // in out. Returns the number of bytes read. size_t streamvbyte_decode_0124(const uint8_t *in, uint32_t *out, uint32_t count) { if (count == 0) return 0; const uint8_t *keyPtr = in; // full list of keys is next uint32_t keyLen = ((count + 3) / 4); // 2-bits per key (rounded up) const uint8_t *dataPtr = keyPtr + keyLen; // data starts at end of keys #ifdef __AVX__ dataPtr = svb_decode_avx_simple(out, keyPtr, dataPtr, count); out += count & ~ 31; keyPtr += (count/4) & ~ 7; count &= 31; #endif return svb_decode_scalar(out, keyPtr, dataPtr, count) - in; } streamvbyte-0.4.1/src/streamvbyte_0124_encode.c000066400000000000000000000070361346460053600213610ustar00rootroot00000000000000#include "streamvbyte.h" #if defined(_MSC_VER) /* Microsoft C/C++-compatible compiler */ #include #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) /* GCC-compatible compiler, targeting x86/x86-64 */ #include #endif #ifdef __AVX__ #include "streamvbyte_shuffle_tables_0124_encode.h" #endif #include // for memcpy static uint8_t _encode_data(uint32_t val, uint8_t *__restrict__ *dataPtrPtr) { uint8_t *dataPtr = *dataPtrPtr; uint8_t code; if (val == 0) { // 0 bytes code = 0; } else if (val < (1 << 8)) { // 1 bytes *dataPtr = (uint8_t)(val); *dataPtrPtr += 1; code = 1; } else if (val < (1 << 16)) { // 2 bytes memcpy(dataPtr, &val, 2); // assumes little endian *dataPtrPtr += 2; code = 2; } else { // 4 bytes memcpy(dataPtr, &val, sizeof(uint32_t)); *dataPtrPtr += sizeof(uint32_t); code = 3; } return code; } static uint8_t *svb_encode_scalar(const uint32_t *in, uint8_t *__restrict__ keyPtr, uint8_t *__restrict__ dataPtr, uint32_t count) { if (count == 0) return dataPtr; // exit immediately if no data uint8_t shift = 0; // cycles 0, 2, 4, 6, 0, 2, 4, 6, ... uint8_t key = 0; for (uint32_t c = 0; c < count; c++) { if (shift == 8) { shift = 0; *keyPtr++ = key; key = 0; } uint32_t val = in[c]; uint8_t code = _encode_data(val, &dataPtr); key |= code << shift; shift += 2; } *keyPtr = key; // write last key (no increment needed) return dataPtr; // pointer to first unused data byte } #ifdef __AVX__ static size_t streamvbyte_encode4(__m128i in, uint8_t *outData, uint8_t *outCode) { const __m128i Ones = _mm_set1_epi32(0x01010101); const __m128i GatherBits = _mm_set1_epi32(0x08040102); const __m128i CodeTable = _mm_set_epi32(0x03030303, 0x03030303, 0x03030303, 0x02020100); const __m128i GatherBytes = _mm_set_epi32(0, 0, 0x0D090501, 0x0D090501); const __m128i Aggregators = _mm_set_epi32(0, 0, 0x01010101, 0x10400104); __m128i m0, m1; m0 = _mm_min_epu8(in, Ones); // set byte to 1 if it is not zero m0 = _mm_madd_epi16(m0, GatherBits); // gather bits 8,16,24 to bits 8,9,10 m1 = _mm_shuffle_epi8(CodeTable, m0); // translate to a 2-bit encoded symbol m1 = _mm_shuffle_epi8(m1, GatherBytes); // gather bytes holding symbols; 2 copies m1 = _mm_madd_epi16(m1, Aggregators); // sum dword_1, pack dword_0 size_t code = (size_t)_mm_extract_epi8(m1, 1); size_t length = lengthTable[code]; __m128i* shuf = (__m128i*)(((uint8_t*)encodingShuffleTable) + code * 16); __m128i out = _mm_shuffle_epi8(in, _mm_loadu_si128(shuf)); // todo: aligned access _mm_storeu_si128((__m128i *)outData, out); *outCode = (uint8_t)code; return length; } static size_t streamvbyte_encode_quad(const uint32_t *in, uint8_t *outData, uint8_t *outKey) { __m128i vin = _mm_loadu_si128((__m128i *) in ); return streamvbyte_encode4(vin, outData, outKey); } #endif size_t streamvbyte_encode_0124(const uint32_t *in, uint32_t count, uint8_t *out) { uint8_t *keyPtr = out; uint32_t keyLen = (count + 3) / 4; // 2-bits rounded to full byte uint8_t *dataPtr = keyPtr + keyLen; // variable byte data after all keys #ifdef __AVX__ uint32_t count_quads = count / 4; count -= 4 * count_quads; for (uint32_t c = 0; c < count_quads; c++) { dataPtr += streamvbyte_encode_quad(in, dataPtr, keyPtr); keyPtr++; in += 4; } #endif return svb_encode_scalar(in, keyPtr, dataPtr, count) - out; } streamvbyte-0.4.1/src/streamvbyte_arm_decode.c000066400000000000000000000027161346460053600215400ustar00rootroot00000000000000 #ifdef __aarch64__ typedef uint8x16_t decode_t; #else typedef uint8x8x2_t decode_t; #endif static inline decode_t _decode_neon(const uint8_t key, const uint8_t * restrict *dataPtrPtr) { uint8_t len; uint8_t *pshuf = (uint8_t *)&shuffleTable[key]; uint8x16_t decodingShuffle = vld1q_u8(pshuf); uint8x16_t compressed = vld1q_u8(*dataPtrPtr); #ifdef AVOIDLENGTHLOOKUP // this avoids the dependency on lengthTable, // see https://github.com/lemire/streamvbyte/issues/12 len = pshuf[12 + (key >> 6)] + 1; #else len = lengthTable[key]; #endif #ifdef __aarch64__ uint8x16_t data = vqtbl1q_u8(compressed, decodingShuffle); #else uint8x8x2_t codehalves = {{vget_low_u8(compressed), vget_high_u8(compressed)}}; uint8x8x2_t data = {{vtbl2_u8(codehalves, vget_low_u8(decodingShuffle)), vtbl2_u8(codehalves, vget_high_u8(decodingShuffle))}}; #endif *dataPtrPtr += len; return data; } static void streamvbyte_decode_quad( const uint8_t * restrict *dataPtrPtr, uint8_t key, uint32_t * restrict out ) { decode_t data =_decode_neon( key, dataPtrPtr ); #ifdef __aarch64__ vst1q_u8((uint8_t *) out, data); #else vst1_u8((uint8_t *) out, data.val[0]); vst1_u8((uint8_t *) (out + 2), data.val[1]); #endif } static const uint8_t *svb_decode_vector(uint32_t *out, const uint8_t *keyPtr, const uint8_t *dataPtr, uint32_t count) { for(uint32_t i = 0; i < count/4; i++) streamvbyte_decode_quad( &dataPtr, keyPtr[i], out + 4*i ); return dataPtr; } streamvbyte-0.4.1/src/streamvbyte_arm_encode.c000066400000000000000000000040101346460053600215370ustar00rootroot00000000000000 static const uint8_t pgatherlo[] = {12, 8, 4, 0, 12, 8, 4, 0}; // apparently only used in streamvbyte_encode4 #define concat (1 | 1 << 10 | 1 << 20 | 1 << 30) #define sum (1 | 1 << 8 | 1 << 16 | 1 << 24) static const uint32_t pAggregators[2] = {concat, sum}; // apparently only used in streamvbyte_encode4 static inline size_t streamvbyte_encode4(uint32x4_t data, uint8_t *__restrict__ outData, uint8_t *__restrict__ outCode) { const uint8x8_t gatherlo = vld1_u8(pgatherlo); const uint32x2_t Aggregators = vld1_u32(pAggregators); // lane code is 3 - (saturating sub) (clz(data)/8) uint32x4_t clzbytes = vshrq_n_u32(vclzq_u32(data), 3); uint32x4_t lanecodes = vqsubq_u32(vdupq_n_u32(3), clzbytes); // nops uint8x16_t lanebytes = vreinterpretq_u8_u32(lanecodes); #ifdef __aarch64__ uint8x8_t lobytes = vqtbl1_u8( lanebytes, gatherlo ); #else uint8x8x2_t twohalves = {{vget_low_u8(lanebytes), vget_high_u8(lanebytes)}}; // shuffle lsbytes into two copies of an int uint8x8_t lobytes = vtbl2_u8(twohalves, gatherlo); #endif uint32x2_t mulshift = vreinterpret_u32_u8(lobytes); uint32_t codeAndLength[2]; vst1_u32(codeAndLength, vmul_u32(mulshift, Aggregators)); uint32_t code = codeAndLength[0] >> 24; size_t length = 4 + (codeAndLength[1] >> 24); // shuffle in 8-byte chunks uint8x16_t databytes = vreinterpretq_u8_u32(data); uint8x16_t encodingShuffle = vld1q_u8((uint8_t *) &encodingShuffleTable[code]); #ifdef __aarch64__ vst1q_u8(outData, vqtbl1q_u8(databytes, encodingShuffle)); #else uint8x8x2_t datahalves = {{vget_low_u8(databytes), vget_high_u8(databytes)}}; vst1_u8(outData, vtbl2_u8(datahalves, vget_low_u8(encodingShuffle))); vst1_u8(outData + 8, vtbl2_u8(datahalves, vget_high_u8(encodingShuffle))); #endif *outCode = (uint8_t) code; return length; } static inline size_t streamvbyte_encode_quad(const uint32_t *__restrict__ in, uint8_t *__restrict__ outData, uint8_t *__restrict__ outCode) { uint32x4_t inq = vld1q_u32(in); return streamvbyte_encode4(inq, outData, outCode); } streamvbyte-0.4.1/src/streamvbyte_decode.c000066400000000000000000000061451346460053600207010ustar00rootroot00000000000000#include "streamvbyte.h" #if defined(_MSC_VER) /* Microsoft C/C++-compatible compiler */ #include #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) /* GCC-compatible compiler, targeting x86/x86-64 */ #include #elif defined(__GNUC__) && defined(__ARM_NEON__) /* GCC-compatible compiler, targeting ARM with NEON */ #include #elif defined(__GNUC__) && defined(__IWMMXT__) /* GCC-compatible compiler, targeting ARM with WMMX */ #include #elif (defined(__GNUC__) || defined(__xlC__)) && \ (defined(__VEC__) || defined(__ALTIVEC__)) /* XLC or GCC-compatible compiler, targeting PowerPC with VMX/VSX */ #include #elif defined(__GNUC__) && defined(__SPE__) /* GCC-compatible compiler, targeting PowerPC with SPE */ #include #endif #include // for memcpy #include "streamvbyte_shuffle_tables_decode.h" #ifdef __ARM_NEON__ #include "streamvbyte_arm_decode.c" #endif #ifdef __AVX__ // though we do not require AVX per se, it is a macro that MSVC // will issue #include "streamvbyte_x64_decode.c" #endif // __AVX__ static inline uint32_t _decode_data(const uint8_t **dataPtrPtr, uint8_t code) { const uint8_t *dataPtr = *dataPtrPtr; uint32_t val; if (code == 0) { // 1 byte val = (uint32_t)*dataPtr; dataPtr += 1; } else if (code == 1) { // 2 bytes val = 0; memcpy(&val, dataPtr, 2); // assumes little endian dataPtr += 2; } else if (code == 2) { // 3 bytes val = 0; memcpy(&val, dataPtr, 3); // assumes little endian dataPtr += 3; } else { // code == 3 memcpy(&val, dataPtr, 4); dataPtr += 4; } *dataPtrPtr = dataPtr; return val; } static const uint8_t *svb_decode_scalar(uint32_t *outPtr, const uint8_t *keyPtr, const uint8_t *dataPtr, uint32_t count) { if (count == 0) return dataPtr; // no reads or writes if no data uint8_t shift = 0; uint32_t key = *keyPtr++; for (uint32_t c = 0; c < count; c++) { if (shift == 8) { shift = 0; key = *keyPtr++; } uint32_t val = _decode_data(&dataPtr, (key >> shift) & 0x3); *outPtr++ = val; shift += 2; } return dataPtr; // pointer to first unused byte after end } // Read count 32-bit integers in maskedvbyte format from in, storing the result // in out. Returns the number of bytes read. size_t streamvbyte_decode(const uint8_t *in, uint32_t *out, uint32_t count) { if (count == 0) return 0; const uint8_t *keyPtr = in; // full list of keys is next uint32_t keyLen = ((count + 3) / 4); // 2-bits per key (rounded up) const uint8_t *dataPtr = keyPtr + keyLen; // data starts at end of keys #ifdef __AVX__ dataPtr = svb_decode_avx_simple(out, keyPtr, dataPtr, count); out += count & ~ 31; keyPtr += (count/4) & ~ 7; count &= 31; #elif defined(__ARM_NEON__) dataPtr = svb_decode_vector(out, keyPtr, dataPtr, count); out += count - (count & 3); keyPtr += count/4; count &= 3; #endif return svb_decode_scalar(out, keyPtr, dataPtr, count) - in; } streamvbyte-0.4.1/src/streamvbyte_encode.c000066400000000000000000000062111346460053600207050ustar00rootroot00000000000000#include "streamvbyte.h" #if defined(_MSC_VER) /* Microsoft C/C++-compatible compiler */ #include #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) /* GCC-compatible compiler, targeting x86/x86-64 */ #include #elif defined(__GNUC__) && defined(__ARM_NEON__) /* GCC-compatible compiler, targeting ARM with NEON */ #include #elif defined(__GNUC__) && defined(__IWMMXT__) /* GCC-compatible compiler, targeting ARM with WMMX */ #include #elif (defined(__GNUC__) || defined(__xlC__)) && \ (defined(__VEC__) || defined(__ALTIVEC__)) /* XLC or GCC-compatible compiler, targeting PowerPC with VMX/VSX */ #include #elif defined(__GNUC__) && defined(__SPE__) /* GCC-compatible compiler, targeting PowerPC with SPE */ #include #endif #include // for memcpy #include "streamvbyte_shuffle_tables_encode.h" #ifdef __AVX__ #include "streamvbyte_x64_encode.c" #else static uint8_t _encode_data(uint32_t val, uint8_t *__restrict__ *dataPtrPtr) { uint8_t *dataPtr = *dataPtrPtr; uint8_t code; if (val < (1 << 8)) { // 1 byte *dataPtr = (uint8_t)(val); *dataPtrPtr += 1; code = 0; } else if (val < (1 << 16)) { // 2 bytes memcpy(dataPtr, &val, 2); // assumes little endian *dataPtrPtr += 2; code = 1; } else if (val < (1 << 24)) { // 3 bytes memcpy(dataPtr, &val, 3); // assumes little endian *dataPtrPtr += 3; code = 2; } else { // 4 bytes memcpy(dataPtr, &val, sizeof(uint32_t)); *dataPtrPtr += sizeof(uint32_t); code = 3; } return code; } static uint8_t *svb_encode_scalar(const uint32_t *in, uint8_t *__restrict__ keyPtr, uint8_t *__restrict__ dataPtr, uint32_t count) { if (count == 0) return dataPtr; // exit immediately if no data uint8_t shift = 0; // cycles 0, 2, 4, 6, 0, 2, 4, 6, ... uint8_t key = 0; for (uint32_t c = 0; c < count; c++) { if (shift == 8) { shift = 0; *keyPtr++ = key; key = 0; } uint32_t val = in[c]; uint8_t code = _encode_data(val, &dataPtr); key |= code << shift; shift += 2; } *keyPtr = key; // write last key (no increment needed) return dataPtr; // pointer to first unused data byte } #endif #ifdef __ARM_NEON__ #include "streamvbyte_arm_encode.c" #endif // Encode an array of a given length read from in to bout in streamvbyte format. // Returns the number of bytes written. size_t streamvbyte_encode(const uint32_t *in, uint32_t count, uint8_t *out) { #ifdef __AVX__ return streamvbyte_encode_SSSE3(in,count,out); #else uint8_t *keyPtr = out; uint32_t keyLen = (count + 3) / 4; // 2-bits rounded to full byte uint8_t *dataPtr = keyPtr + keyLen; // variable byte data after all keys #if defined(__ARM_NEON__) uint32_t count_quads = count / 4; count -= 4 * count_quads; for (uint32_t c = 0; c < count_quads; c++) { dataPtr += streamvbyte_encode_quad(in, dataPtr, keyPtr); keyPtr++; in += 4; } #endif return svb_encode_scalar(in, keyPtr, dataPtr, count) - out; #endif// no AVX } streamvbyte-0.4.1/src/streamvbyte_shuffle_tables_0124_decode.h000066400000000000000000000522221346460053600244170ustar00rootroot00000000000000// using 0,1,2,4 bytes per value static uint8_t lengthTable[256] ={ 0, 1, 2, 4, 1, 2, 3, 5, 2, 3, 4, 6, 4, 5, 6, 8, 1, 2, 3, 5, 2, 3, 4, 6, 3, 4, 5, 7, 5, 6, 7, 9, 2, 3, 4, 6, 3, 4, 5, 7, 4, 5, 6, 8, 6, 7, 8, 10, 4, 5, 6, 8, 5, 6, 7, 9, 6, 7, 8, 10, 8, 9, 10, 12, 1, 2, 3, 5, 2, 3, 4, 6, 3, 4, 5, 7, 5, 6, 7, 9, 2, 3, 4, 6, 3, 4, 5, 7, 4, 5, 6, 8, 6, 7, 8, 10, 3, 4, 5, 7, 4, 5, 6, 8, 5, 6, 7, 9, 7, 8, 9, 11, 5, 6, 7, 9, 6, 7, 8, 10, 7, 8, 9, 11, 9, 10, 11, 13, 2, 3, 4, 6, 3, 4, 5, 7, 4, 5, 6, 8, 6, 7, 8, 10, 3, 4, 5, 7, 4, 5, 6, 8, 5, 6, 7, 9, 7, 8, 9, 11, 4, 5, 6, 8, 5, 6, 7, 9, 6, 7, 8, 10, 8, 9, 10, 12, 6, 7, 8, 10, 7, 8, 9, 11, 8, 9, 10, 12, 10, 11, 12, 14, 4, 5, 6, 8, 5, 6, 7, 9, 6, 7, 8, 10, 8, 9, 10, 12, 5, 6, 7, 9, 6, 7, 8, 10, 7, 8, 9, 11, 9, 10, 11, 13, 6, 7, 8, 10, 7, 8, 9, 11, 8, 9, 10, 12, 10, 11, 12, 14, 8, 9, 10, 12, 9, 10, 11, 13, 10, 11, 12, 14, 12, 13, 14, 16, }; // decoding: static uint8_t shuffleTable[256][16] = { { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0000 { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1000 { 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2000 { 0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3000 { -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0100 { 0, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1100 { 0, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2100 { 0, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3100 { -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0200 { 0, -1, -1, -1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1200 { 0, 1, -1, -1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2200 { 0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3200 { -1, -1, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0300 { 0, -1, -1, -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1300 { 0, 1, -1, -1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2300 { 0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3300 { -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1 }, // 0010 { 0, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1 }, // 1010 { 0, 1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1 }, // 2010 { 0, 1, 2, 3, -1, -1, -1, -1, 4, -1, -1, -1, -1, -1, -1, -1 }, // 3010 { -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1 }, // 0110 { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1 }, // 1110 { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1 }, // 2110 { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, -1, -1, -1, -1 }, // 3110 { -1, -1, -1, -1, 0, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1 }, // 0210 { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1 }, // 1210 { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, -1, -1, -1, -1 }, // 2210 { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, -1, -1, -1, -1 }, // 3210 { -1, -1, -1, -1, 0, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1 }, // 0310 { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, -1 }, // 1310 { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, -1, -1, -1, -1 }, // 2310 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, -1 }, // 3310 { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1 }, // 0020 { 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, -1, -1, -1, -1, -1 }, // 1020 { 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, -1, -1, -1, -1, -1, -1 }, // 2020 { 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, -1, -1, -1, -1, -1, -1 }, // 3020 { -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, -1, -1, -1, -1, -1, -1 }, // 0120 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, -1, -1, -1, -1 }, // 1120 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, -1, -1, -1, -1 }, // 2120 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, -1, -1, -1, -1 }, // 3120 { -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, -1, -1, -1, -1, -1, -1 }, // 0220 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, -1, -1, -1, -1 }, // 1220 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, -1, -1, -1, -1 }, // 2220 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1 }, // 3220 { -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1 }, // 0320 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, -1, -1, -1, -1 }, // 1320 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, -1, -1 }, // 2320 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1 }, // 3320 { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1 }, // 0030 { 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4, -1, -1, -1, -1 }, // 1030 { 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, -1, -1, -1, -1 }, // 2030 { 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, 6, 7, -1, -1, -1, -1 }, // 3030 { -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, 3, 4, -1, -1, -1, -1 }, // 0130 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, -1, -1, -1, -1 }, // 1130 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, -1, -1, -1, -1 }, // 2130 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, -1, -1, -1, -1 }, // 3130 { -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, 4, 5, -1, -1, -1, -1 }, // 0230 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, -1, -1, -1, -1 }, // 1230 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, -1, -1, -1, -1 }, // 2230 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, -1, -1, -1, -1 }, // 3230 { -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1 }, // 0330 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1 }, // 1330 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1 }, // 2330 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1, -1 }, // 3330 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1 }, // 0001 { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1 }, // 1001 { 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1 }, // 2001 { 0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, 4, -1, -1, -1 }, // 3001 { -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1 }, // 0101 { 0, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1 }, // 1101 { 0, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, 3, -1, -1, -1 }, // 2101 { 0, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 5, -1, -1, -1 }, // 3101 { -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1 }, // 0201 { 0, -1, -1, -1, 1, 2, -1, -1, -1, -1, -1, -1, 3, -1, -1, -1 }, // 1201 { 0, 1, -1, -1, 2, 3, -1, -1, -1, -1, -1, -1, 4, -1, -1, -1 }, // 2201 { 0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, 6, -1, -1, -1 }, // 3201 { -1, -1, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1, 4, -1, -1, -1 }, // 0301 { 0, -1, -1, -1, 1, 2, 3, 4, -1, -1, -1, -1, 5, -1, -1, -1 }, // 1301 { 0, 1, -1, -1, 2, 3, 4, 5, -1, -1, -1, -1, 6, -1, -1, -1 }, // 2301 { 0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, 8, -1, -1, -1 }, // 3301 { -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, -1 }, // 0011 { 0, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1 }, // 1011 { 0, 1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1 }, // 2011 { 0, 1, 2, 3, -1, -1, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1 }, // 3011 { -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1 }, // 0111 { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1 }, // 1111 { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1 }, // 2111 { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, -1, -1, -1 }, // 3111 { -1, -1, -1, -1, 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1 }, // 0211 { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1 }, // 1211 { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1 }, // 2211 { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, -1, -1, -1 }, // 3211 { -1, -1, -1, -1, 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1 }, // 0311 { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, -1, -1, -1 }, // 1311 { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, -1, -1, -1 }, // 2311 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, -1, -1, -1 }, // 3311 { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, 2, -1, -1, -1 }, // 0021 { 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1 }, // 1021 { 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1 }, // 2021 { 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1 }, // 3021 { -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1 }, // 0121 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1 }, // 1121 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1 }, // 2121 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, -1, -1, -1 }, // 3121 { -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1 }, // 0221 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1 }, // 1221 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1 }, // 2221 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, -1, -1, -1 }, // 3221 { -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1 }, // 0321 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, -1, -1, -1 }, // 1321 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, -1, -1, -1 }, // 2321 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, -1, -1, -1 }, // 3321 { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, -1, -1, -1 }, // 0031 { 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1 }, // 1031 { 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1 }, // 2031 { 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, 6, 7, 8, -1, -1, -1 }, // 3031 { -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1 }, // 0131 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1 }, // 1131 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, -1, -1, -1 }, // 2131 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, -1, -1, -1 }, // 3131 { -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1 }, // 0231 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, -1, -1, -1 }, // 1231 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, -1, -1, -1 }, // 2231 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, -1, -1, -1 }, // 3231 { -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1 }, // 0331 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1 }, // 1331 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1 }, // 2331 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1 }, // 3331 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1 }, // 0002 { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, -1 }, // 1002 { 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 3, -1, -1 }, // 2002 { 0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, 4, 5, -1, -1 }, // 3002 { -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, -1 }, // 0102 { 0, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 2, 3, -1, -1 }, // 1102 { 0, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, 3, 4, -1, -1 }, // 2102 { 0, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 5, 6, -1, -1 }, // 3102 { -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, -1, -1 }, // 0202 { 0, -1, -1, -1, 1, 2, -1, -1, -1, -1, -1, -1, 3, 4, -1, -1 }, // 1202 { 0, 1, -1, -1, 2, 3, -1, -1, -1, -1, -1, -1, 4, 5, -1, -1 }, // 2202 { 0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, 6, 7, -1, -1 }, // 3202 { -1, -1, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, -1, -1 }, // 0302 { 0, -1, -1, -1, 1, 2, 3, 4, -1, -1, -1, -1, 5, 6, -1, -1 }, // 1302 { 0, 1, -1, -1, 2, 3, 4, 5, -1, -1, -1, -1, 6, 7, -1, -1 }, // 2302 { 0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, 8, 9, -1, -1 }, // 3302 { -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, -1, -1 }, // 0012 { 0, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1 }, // 1012 { 0, 1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1 }, // 2012 { 0, 1, 2, 3, -1, -1, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1 }, // 3012 { -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1 }, // 0112 { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1 }, // 1112 { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1 }, // 2112 { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, 7, -1, -1 }, // 3112 { -1, -1, -1, -1, 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1 }, // 0212 { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1 }, // 1212 { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1 }, // 2212 { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, 8, -1, -1 }, // 3212 { -1, -1, -1, -1, 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1 }, // 0312 { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, 7, -1, -1 }, // 1312 { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, 8, -1, -1 }, // 2312 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, 10, -1, -1 }, // 3312 { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, -1, -1 }, // 0022 { 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1 }, // 1022 { 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1 }, // 2022 { 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1 }, // 3022 { -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1 }, // 0122 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1 }, // 1122 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1 }, // 2122 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, 8, -1, -1 }, // 3122 { -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1 }, // 0222 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1 }, // 1222 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1 }, // 2222 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, -1, -1 }, // 3222 { -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1 }, // 0322 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, 8, -1, -1 }, // 1322 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, -1, -1 }, // 2322 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, -1, -1 }, // 3322 { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, -1 }, // 0032 { 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1 }, // 1032 { 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1 }, // 2032 { 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, -1, -1 }, // 3032 { -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1 }, // 0132 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1 }, // 1132 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, 8, -1, -1 }, // 2132 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, 10, -1, -1 }, // 3132 { -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1 }, // 0232 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, 8, -1, -1 }, // 1232 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, 9, -1, -1 }, // 2232 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, -1, -1 }, // 3232 { -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1 }, // 0332 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1 }, // 1332 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1 }, // 2332 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1 }, // 3332 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3 }, // 0003 { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4 }, // 1003 { 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5 }, // 2003 { 0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, 4, 5, 6, 7 }, // 3003 { -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4 }, // 0103 { 0, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5 }, // 1103 { 0, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, 3, 4, 5, 6 }, // 2103 { 0, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 5, 6, 7, 8 }, // 3103 { -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5 }, // 0203 { 0, -1, -1, -1, 1, 2, -1, -1, -1, -1, -1, -1, 3, 4, 5, 6 }, // 1203 { 0, 1, -1, -1, 2, 3, -1, -1, -1, -1, -1, -1, 4, 5, 6, 7 }, // 2203 { 0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, 6, 7, 8, 9 }, // 3203 { -1, -1, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, 6, 7 }, // 0303 { 0, -1, -1, -1, 1, 2, 3, 4, -1, -1, -1, -1, 5, 6, 7, 8 }, // 1303 { 0, 1, -1, -1, 2, 3, 4, 5, -1, -1, -1, -1, 6, 7, 8, 9 }, // 2303 { 0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, 8, 9, 10, 11 }, // 3303 { -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, 3, 4 }, // 0013 { 0, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5 }, // 1013 { 0, 1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6 }, // 2013 { 0, 1, 2, 3, -1, -1, -1, -1, 4, -1, -1, -1, 5, 6, 7, 8 }, // 3013 { -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5 }, // 0113 { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6 }, // 1113 { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, 6, 7 }, // 2113 { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, 7, 8, 9 }, // 3113 { -1, -1, -1, -1, 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6 }, // 0213 { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, 6, 7 }, // 1213 { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, 7, 8 }, // 2213 { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, 8, 9, 10 }, // 3213 { -1, -1, -1, -1, 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8 }, // 0313 { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, 7, 8, 9 }, // 1313 { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, 8, 9, 10 }, // 2313 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, 10, 11, 12 }, // 3313 { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, 4, 5 }, // 0023 { 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6 }, // 1023 { 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7 }, // 2023 { 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, -1, -1, 6, 7, 8, 9 }, // 3023 { -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6 }, // 0123 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7 }, // 1123 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, 7, 8 }, // 2123 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, 8, 9, 10 }, // 3123 { -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7 }, // 0223 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, 7, 8 }, // 1223 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, 8, 9 }, // 2223 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, 10, 11 }, // 3223 { -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9 }, // 0323 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, 8, 9, 10 }, // 1323 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, 10, 11 }, // 2323 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13 }, // 3323 { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7 }, // 0033 { 0, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8 }, // 1033 { 0, 1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 2033 { 0, 1, 2, 3, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11 }, // 3033 { -1, -1, -1, -1, 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8 }, // 0133 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 1133 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, 8, 9, 10 }, // 2133 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, 10, 11, 12 }, // 3133 { -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 0233 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, 8, 9, 10 }, // 1233 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11 }, // 2233 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, 12, 13 }, // 3233 { -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, // 0333 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, // 1333 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, // 2333 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // 3333 }; streamvbyte-0.4.1/src/streamvbyte_shuffle_tables_0124_encode.h000066400000000000000000000522321346460053600244320ustar00rootroot00000000000000// using 0,1,2,4 bytes per value static uint8_t lengthTable[256] ={ 0, 1, 2, 4, 1, 2, 3, 5, 2, 3, 4, 6, 4, 5, 6, 8, 1, 2, 3, 5, 2, 3, 4, 6, 3, 4, 5, 7, 5, 6, 7, 9, 2, 3, 4, 6, 3, 4, 5, 7, 4, 5, 6, 8, 6, 7, 8, 10, 4, 5, 6, 8, 5, 6, 7, 9, 6, 7, 8, 10, 8, 9, 10, 12, 1, 2, 3, 5, 2, 3, 4, 6, 3, 4, 5, 7, 5, 6, 7, 9, 2, 3, 4, 6, 3, 4, 5, 7, 4, 5, 6, 8, 6, 7, 8, 10, 3, 4, 5, 7, 4, 5, 6, 8, 5, 6, 7, 9, 7, 8, 9, 11, 5, 6, 7, 9, 6, 7, 8, 10, 7, 8, 9, 11, 9, 10, 11, 13, 2, 3, 4, 6, 3, 4, 5, 7, 4, 5, 6, 8, 6, 7, 8, 10, 3, 4, 5, 7, 4, 5, 6, 8, 5, 6, 7, 9, 7, 8, 9, 11, 4, 5, 6, 8, 5, 6, 7, 9, 6, 7, 8, 10, 8, 9, 10, 12, 6, 7, 8, 10, 7, 8, 9, 11, 8, 9, 10, 12, 10, 11, 12, 14, 4, 5, 6, 8, 5, 6, 7, 9, 6, 7, 8, 10, 8, 9, 10, 12, 5, 6, 7, 9, 6, 7, 8, 10, 7, 8, 9, 11, 9, 10, 11, 13, 6, 7, 8, 10, 7, 8, 9, 11, 8, 9, 10, 12, 10, 11, 12, 14, 8, 9, 10, 12, 9, 10, 11, 13, 10, 11, 12, 14, 12, 13, 14, 16, }; // encoding: static uint8_t encodingShuffleTable[256][16] = { { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0000 { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1000 { 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2000 { 0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3000 { 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0100 { 0, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1100 { 0, 1, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2100 { 0, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3100 { 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0200 { 0, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1200 { 0, 1, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2200 { 0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3200 { 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0300 { 0, 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1300 { 0, 1, 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2300 { 0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3300 { 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0010 { 0, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1010 { 0, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2010 { 0, 1, 2, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3010 { 4, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0110 { 0, 4, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1110 { 0, 1, 4, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2110 { 0, 1, 2, 3, 4, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3110 { 4, 5, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0210 { 0, 4, 5, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1210 { 0, 1, 4, 5, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2210 { 0, 1, 2, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3210 { 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0310 { 0, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1310 { 0, 1, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2310 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, -1 }, // 3310 { 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0020 { 0, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1020 { 0, 1, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2020 { 0, 1, 2, 3, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3020 { 4, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0120 { 0, 4, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1120 { 0, 1, 4, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2120 { 0, 1, 2, 3, 4, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3120 { 4, 5, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0220 { 0, 4, 5, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1220 { 0, 1, 4, 5, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2220 { 0, 1, 2, 3, 4, 5, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3220 { 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0320 { 0, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1320 { 0, 1, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2320 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1 }, // 3320 { 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0030 { 0, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1030 { 0, 1, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2030 { 0, 1, 2, 3, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3030 { 4, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0130 { 0, 4, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1130 { 0, 1, 4, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2130 { 0, 1, 2, 3, 4, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1 }, // 3130 { 4, 5, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0230 { 0, 4, 5, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1230 { 0, 1, 4, 5, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2230 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1 }, // 3230 { 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0330 { 0, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1 }, // 1330 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1, -1, -1, -1 }, // 2330 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1, -1 }, // 3330 { 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0001 { 0, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1001 { 0, 1, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2001 { 0, 1, 2, 3, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3001 { 4, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0101 { 0, 4, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1101 { 0, 1, 4, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2101 { 0, 1, 2, 3, 4, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3101 { 4, 5, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0201 { 0, 4, 5, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1201 { 0, 1, 4, 5, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2201 { 0, 1, 2, 3, 4, 5, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3201 { 4, 5, 6, 7, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0301 { 0, 4, 5, 6, 7, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1301 { 0, 1, 4, 5, 6, 7, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2301 { 0, 1, 2, 3, 4, 5, 6, 7, 12, -1, -1, -1, -1, -1, -1, -1 }, // 3301 { 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0011 { 0, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1011 { 0, 1, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2011 { 0, 1, 2, 3, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3011 { 4, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0111 { 0, 4, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1111 { 0, 1, 4, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2111 { 0, 1, 2, 3, 4, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3111 { 4, 5, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0211 { 0, 4, 5, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1211 { 0, 1, 4, 5, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2211 { 0, 1, 2, 3, 4, 5, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3211 { 4, 5, 6, 7, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0311 { 0, 4, 5, 6, 7, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1311 { 0, 1, 4, 5, 6, 7, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2311 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, -1, -1, -1, -1, -1, -1 }, // 3311 { 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0021 { 0, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1021 { 0, 1, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2021 { 0, 1, 2, 3, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3021 { 4, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0121 { 0, 4, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1121 { 0, 1, 4, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2121 { 0, 1, 2, 3, 4, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3121 { 4, 5, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0221 { 0, 4, 5, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1221 { 0, 1, 4, 5, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2221 { 0, 1, 2, 3, 4, 5, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1 }, // 3221 { 4, 5, 6, 7, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0321 { 0, 4, 5, 6, 7, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1321 { 0, 1, 4, 5, 6, 7, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1 }, // 2321 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, -1, -1, -1, -1, -1 }, // 3321 { 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0031 { 0, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1031 { 0, 1, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2031 { 0, 1, 2, 3, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1 }, // 3031 { 4, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0131 { 0, 4, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1131 { 0, 1, 4, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2131 { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1 }, // 3131 { 4, 5, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0231 { 0, 4, 5, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1231 { 0, 1, 4, 5, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1 }, // 2231 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1 }, // 3231 { 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1 }, // 0331 { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1 }, // 1331 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1 }, // 2331 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1 }, // 3331 { 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0002 { 0, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1002 { 0, 1, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2002 { 0, 1, 2, 3, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3002 { 4, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0102 { 0, 4, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1102 { 0, 1, 4, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2102 { 0, 1, 2, 3, 4, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3102 { 4, 5, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0202 { 0, 4, 5, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1202 { 0, 1, 4, 5, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2202 { 0, 1, 2, 3, 4, 5, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3202 { 4, 5, 6, 7, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0302 { 0, 4, 5, 6, 7, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1302 { 0, 1, 4, 5, 6, 7, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2302 { 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, -1, -1, -1, -1, -1, -1 }, // 3302 { 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0012 { 0, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1012 { 0, 1, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2012 { 0, 1, 2, 3, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3012 { 4, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0112 { 0, 4, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1112 { 0, 1, 4, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2112 { 0, 1, 2, 3, 4, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3112 { 4, 5, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0212 { 0, 4, 5, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1212 { 0, 1, 4, 5, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2212 { 0, 1, 2, 3, 4, 5, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 3212 { 4, 5, 6, 7, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0312 { 0, 4, 5, 6, 7, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1312 { 0, 1, 4, 5, 6, 7, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 2312 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, -1, -1, -1, -1, -1 }, // 3312 { 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0022 { 0, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1022 { 0, 1, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2022 { 0, 1, 2, 3, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3022 { 4, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0122 { 0, 4, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1122 { 0, 1, 4, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2122 { 0, 1, 2, 3, 4, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 3122 { 4, 5, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0222 { 0, 4, 5, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1222 { 0, 1, 4, 5, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2222 { 0, 1, 2, 3, 4, 5, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1 }, // 3222 { 4, 5, 6, 7, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0322 { 0, 4, 5, 6, 7, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 1322 { 0, 1, 4, 5, 6, 7, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1 }, // 2322 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, -1, -1, -1, -1 }, // 3322 { 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0032 { 0, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1032 { 0, 1, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2032 { 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1 }, // 3032 { 4, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0132 { 0, 4, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1132 { 0, 1, 4, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 2132 { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1 }, // 3132 { 4, 5, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0232 { 0, 4, 5, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 1232 { 0, 1, 4, 5, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1 }, // 2232 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1 }, // 3232 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1 }, // 0332 { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1 }, // 1332 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1 }, // 2332 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1 }, // 3332 { 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0003 { 0, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1003 { 0, 1, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2003 { 0, 1, 2, 3, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3003 { 4, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0103 { 0, 4, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1103 { 0, 1, 4, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2103 { 0, 1, 2, 3, 4, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 3103 { 4, 5, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0203 { 0, 4, 5, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1203 { 0, 1, 4, 5, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2203 { 0, 1, 2, 3, 4, 5, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 3203 { 4, 5, 6, 7, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0303 { 0, 4, 5, 6, 7, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 1303 { 0, 1, 4, 5, 6, 7, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 2303 { 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, -1, -1, -1, -1 }, // 3303 { 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0013 { 0, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1013 { 0, 1, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2013 { 0, 1, 2, 3, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 3013 { 4, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0113 { 0, 4, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1113 { 0, 1, 4, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2113 { 0, 1, 2, 3, 4, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 3113 { 4, 5, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0213 { 0, 4, 5, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1213 { 0, 1, 4, 5, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 2213 { 0, 1, 2, 3, 4, 5, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 3213 { 4, 5, 6, 7, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 0313 { 0, 4, 5, 6, 7, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 1313 { 0, 1, 4, 5, 6, 7, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 2313 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, -1, -1, -1 }, // 3313 { 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0023 { 0, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1023 { 0, 1, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2023 { 0, 1, 2, 3, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 3023 { 4, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0123 { 0, 4, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1123 { 0, 1, 4, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 2123 { 0, 1, 2, 3, 4, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 3123 { 4, 5, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0223 { 0, 4, 5, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 1223 { 0, 1, 4, 5, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 2223 { 0, 1, 2, 3, 4, 5, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1 }, // 3223 { 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 0323 { 0, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 1323 { 0, 1, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1 }, // 2323 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, -1, -1 }, // 3323 { 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 0033 { 0, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 1033 { 0, 1, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 2033 { 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1 }, // 3033 { 4, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 0133 { 0, 4, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 1133 { 0, 1, 4, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 2133 { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1 }, // 3133 { 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 0233 { 0, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 1233 { 0, 1, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1 }, // 2233 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1 }, // 3233 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1 }, // 0333 { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1 }, // 1333 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1 }, // 2333 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // 3333 }; streamvbyte-0.4.1/src/streamvbyte_shuffle_tables_decode.h000066400000000000000000000522221346460053600237510ustar00rootroot00000000000000// using 1,2,3,4 bytes per value static uint8_t lengthTable[256] ={ 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15, 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15, 13, 14, 15, 16, }; // decoding: static uint8_t shuffleTable[256][16] = { { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1 }, // 0000 { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1 }, // 1000 { 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1 }, // 2000 { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, -1, -1, -1 }, // 3000 { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1 }, // 0100 { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1 }, // 1100 { 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, -1, -1, -1 }, // 2100 { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, -1, -1, -1 }, // 3100 { 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, -1, -1, -1 }, // 0200 { 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, -1, -1, -1 }, // 1200 { 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, -1, -1, -1 }, // 2200 { 0, 1, 2, 3, 4, 5, 6, -1, 7, -1, -1, -1, 8, -1, -1, -1 }, // 3200 { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, -1, -1, -1 }, // 0300 { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, -1, -1, -1 }, // 1300 { 0, 1, 2, -1, 3, 4, 5, 6, 7, -1, -1, -1, 8, -1, -1, -1 }, // 2300 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, -1, -1, -1 }, // 3300 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1 }, // 0010 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1 }, // 1010 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1 }, // 2010 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, -1, -1, -1 }, // 3010 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1 }, // 0110 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, -1, -1, -1 }, // 1110 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, -1, -1, -1 }, // 2110 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, -1, -1, -1 }, // 3110 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, -1, -1, -1 }, // 0210 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, -1, -1, -1 }, // 1210 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, -1, -1, -1 }, // 2210 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, -1, -1, 9, -1, -1, -1 }, // 3210 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, -1, -1, -1 }, // 0310 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, -1, -1, -1 }, // 1310 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, -1, -1, 9, -1, -1, -1 }, // 2310 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, -1, -1, -1 }, // 3310 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1 }, // 0020 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, -1, -1, -1 }, // 1020 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, -1, -1, -1 }, // 2020 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, -1, 8, -1, -1, -1 }, // 3020 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, -1, -1, -1 }, // 0120 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, -1, -1, -1 }, // 1120 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, -1, -1, -1 }, // 2120 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, -1, 9, -1, -1, -1 }, // 3120 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, -1, -1, -1 }, // 0220 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, -1, -1, -1 }, // 1220 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, -1, -1, -1 }, // 2220 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, -1, 10, -1, -1, -1 }, // 3220 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, -1, 8, -1, -1, -1 }, // 0320 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1, 9, -1, -1, -1 }, // 1320 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, -1, -1, -1 }, // 2320 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, -1, -1, -1 }, // 3320 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1 }, // 0030 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, -1, -1, -1 }, // 1030 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, 7, 8, -1, -1, -1 }, // 2030 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, -1, -1, -1 }, // 3030 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, -1, -1, -1 }, // 0130 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, -1, -1, -1 }, // 1130 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, 8, 9, -1, -1, -1 }, // 2130 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, -1, -1, -1 }, // 3130 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, -1, -1, -1 }, // 0230 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8, 9, -1, -1, -1 }, // 1230 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, 10, -1, -1, -1 }, // 2230 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, 10, 11, -1, -1, -1 }, // 3230 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1 }, // 0330 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1 }, // 1330 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1, -1 }, // 2330 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1 }, // 3330 { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1 }, // 0001 { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1 }, // 1001 { 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1 }, // 2001 { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, 7, -1, -1 }, // 3001 { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, -1, -1 }, // 0101 { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, -1, -1 }, // 1101 { 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, -1, -1 }, // 2101 { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, 8, -1, -1 }, // 3101 { 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, -1, -1 }, // 0201 { 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, -1, -1 }, // 1201 { 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, -1, -1 }, // 2201 { 0, 1, 2, 3, 4, 5, 6, -1, 7, -1, -1, -1, 8, 9, -1, -1 }, // 3201 { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, 7, -1, -1 }, // 0301 { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, 8, -1, -1 }, // 1301 { 0, 1, 2, -1, 3, 4, 5, 6, 7, -1, -1, -1, 8, 9, -1, -1 }, // 2301 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, 10, -1, -1 }, // 3301 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1 }, // 0011 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1 }, // 1011 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1 }, // 2011 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, 8, -1, -1 }, // 3011 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, -1, -1 }, // 0111 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1 }, // 1111 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, -1, -1 }, // 2111 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, -1, -1 }, // 3111 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, -1, -1 }, // 0211 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, -1, -1 }, // 1211 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, -1, -1 }, // 2211 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, -1, -1, 9, 10, -1, -1 }, // 3211 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, 8, -1, -1 }, // 0311 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, -1, -1 }, // 1311 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, -1, -1, 9, 10, -1, -1 }, // 2311 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, -1, -1 }, // 3311 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1 }, // 0021 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, -1, -1 }, // 1021 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1 }, // 2021 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, -1, 8, 9, -1, -1 }, // 3021 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, -1, -1 }, // 0121 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, -1, -1 }, // 1121 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, -1, -1 }, // 2121 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, -1, 9, 10, -1, -1 }, // 3121 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, -1, -1 }, // 0221 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, -1, -1 }, // 1221 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, -1, -1 }, // 2221 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, -1, 10, 11, -1, -1 }, // 3221 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, -1, 8, 9, -1, -1 }, // 0321 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1, 9, 10, -1, -1 }, // 1321 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, -1, -1 }, // 2321 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, -1, -1 }, // 3321 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1 }, // 0031 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, 8, -1, -1 }, // 1031 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, 7, 8, 9, -1, -1 }, // 2031 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, 10, -1, -1 }, // 3031 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, 8, -1, -1 }, // 0131 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, 9, -1, -1 }, // 1131 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, 8, 9, 10, -1, -1 }, // 2131 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, -1, -1 }, // 3131 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, 9, -1, -1 }, // 0231 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8, 9, 10, -1, -1 }, // 1231 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, -1, -1 }, // 2231 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, 10, 11, 12, -1, -1 }, // 3231 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1 }, // 0331 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -1 }, // 1331 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1 }, // 2331 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1 }, // 3331 { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1 }, // 0002 { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, 6, -1 }, // 1002 { 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, 7, -1 }, // 2002 { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, 7, 8, -1 }, // 3002 { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, 6, -1 }, // 0102 { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, 7, -1 }, // 1102 { 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, 8, -1 }, // 2102 { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, 8, 9, -1 }, // 3102 { 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, 7, -1 }, // 0202 { 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, 8, -1 }, // 1202 { 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, 9, -1 }, // 2202 { 0, 1, 2, 3, 4, 5, 6, -1, 7, -1, -1, -1, 8, 9, 10, -1 }, // 3202 { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, 7, 8, -1 }, // 0302 { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, 8, 9, -1 }, // 1302 { 0, 1, 2, -1, 3, 4, 5, 6, 7, -1, -1, -1, 8, 9, 10, -1 }, // 2302 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, 10, 11, -1 }, // 3302 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1 }, // 0012 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, 7, -1 }, // 1012 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, 8, -1 }, // 2012 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, 8, 9, -1 }, // 3012 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, 7, -1 }, // 0112 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, 8, -1 }, // 1112 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, 9, -1 }, // 2112 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, 10, -1 }, // 3112 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, 8, -1 }, // 0212 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, 9, -1 }, // 1212 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, 10, -1 }, // 2212 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, -1, -1, 9, 10, 11, -1 }, // 3212 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, 8, 9, -1 }, // 0312 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, 10, -1 }, // 1312 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, -1, -1, 9, 10, 11, -1 }, // 2312 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, -1 }, // 3312 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1 }, // 0022 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, 8, -1 }, // 1022 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, 9, -1 }, // 2022 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, -1, 8, 9, 10, -1 }, // 3022 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, 8, -1 }, // 0122 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, 9, -1 }, // 1122 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, 10, -1 }, // 2122 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, -1, 9, 10, 11, -1 }, // 3122 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, 9, -1 }, // 0222 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, 10, -1 }, // 1222 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, -1 }, // 2222 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, -1, 10, 11, 12, -1 }, // 3222 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, -1, 8, 9, 10, -1 }, // 0322 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1, 9, 10, 11, -1 }, // 1322 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, -1 }, // 2322 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, 13, -1 }, // 3322 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1 }, // 0032 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, 8, 9, -1 }, // 1032 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, -1 }, // 2032 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, 10, 11, -1 }, // 3032 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, 8, 9, -1 }, // 0132 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, 9, 10, -1 }, // 1132 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, 8, 9, 10, 11, -1 }, // 2132 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, 12, -1 }, // 3132 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, 9, 10, -1 }, // 0232 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8, 9, 10, 11, -1 }, // 1232 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, -1 }, // 2232 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, 10, 11, 12, 13, -1 }, // 3232 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1 }, // 0332 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1 }, // 1332 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1 }, // 2332 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -1 }, // 3332 { 0, -1, -1, -1, 1, -1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6 }, // 0003 { 0, 1, -1, -1, 2, -1, -1, -1, 3, -1, -1, -1, 4, 5, 6, 7 }, // 1003 { 0, 1, 2, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, 6, 7, 8 }, // 2003 { 0, 1, 2, 3, 4, -1, -1, -1, 5, -1, -1, -1, 6, 7, 8, 9 }, // 3003 { 0, -1, -1, -1, 1, 2, -1, -1, 3, -1, -1, -1, 4, 5, 6, 7 }, // 0103 { 0, 1, -1, -1, 2, 3, -1, -1, 4, -1, -1, -1, 5, 6, 7, 8 }, // 1103 { 0, 1, 2, -1, 3, 4, -1, -1, 5, -1, -1, -1, 6, 7, 8, 9 }, // 2103 { 0, 1, 2, 3, 4, 5, -1, -1, 6, -1, -1, -1, 7, 8, 9, 10 }, // 3103 { 0, -1, -1, -1, 1, 2, 3, -1, 4, -1, -1, -1, 5, 6, 7, 8 }, // 0203 { 0, 1, -1, -1, 2, 3, 4, -1, 5, -1, -1, -1, 6, 7, 8, 9 }, // 1203 { 0, 1, 2, -1, 3, 4, 5, -1, 6, -1, -1, -1, 7, 8, 9, 10 }, // 2203 { 0, 1, 2, 3, 4, 5, 6, -1, 7, -1, -1, -1, 8, 9, 10, 11 }, // 3203 { 0, -1, -1, -1, 1, 2, 3, 4, 5, -1, -1, -1, 6, 7, 8, 9 }, // 0303 { 0, 1, -1, -1, 2, 3, 4, 5, 6, -1, -1, -1, 7, 8, 9, 10 }, // 1303 { 0, 1, 2, -1, 3, 4, 5, 6, 7, -1, -1, -1, 8, 9, 10, 11 }, // 2303 { 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, 9, 10, 11, 12 }, // 3303 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7 }, // 0013 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, -1, -1, 5, 6, 7, 8 }, // 1013 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, -1, -1, 6, 7, 8, 9 }, // 2013 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, -1, -1, 7, 8, 9, 10 }, // 3013 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, -1, -1, 5, 6, 7, 8 }, // 0113 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, 8, 9 }, // 1113 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, -1, -1, 7, 8, 9, 10 }, // 2113 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, 10, 11 }, // 3113 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, -1, -1, 6, 7, 8, 9 }, // 0213 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, -1, -1, 7, 8, 9, 10 }, // 1213 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, -1, -1, 8, 9, 10, 11 }, // 2213 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, -1, -1, 9, 10, 11, 12 }, // 3213 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, -1, -1, 7, 8, 9, 10 }, // 0313 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, -1, -1, 8, 9, 10, 11 }, // 1313 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, -1, -1, 9, 10, 11, 12 }, // 2313 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13 }, // 3313 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8 }, // 0023 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, -1, 6, 7, 8, 9 }, // 1023 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, -1, 7, 8, 9, 10 }, // 2023 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, -1, 8, 9, 10, 11 }, // 3023 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, -1, 6, 7, 8, 9 }, // 0123 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, -1, 7, 8, 9, 10 }, // 1123 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, -1, 8, 9, 10, 11 }, // 2123 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, -1, 9, 10, 11, 12 }, // 3123 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, -1, 7, 8, 9, 10 }, // 0223 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 8, 9, 10, 11 }, // 1223 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, 12 }, // 2223 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, -1, 10, 11, 12, 13 }, // 3223 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11 }, // 0323 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, -1, 9, 10, 11, 12 }, // 1323 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13 }, // 2323 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, 13, 14 }, // 3323 { 0, -1, -1, -1, 1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9 }, // 0033 { 0, 1, -1, -1, 2, -1, -1, -1, 3, 4, 5, 6, 7, 8, 9, 10 }, // 1033 { 0, 1, 2, -1, 3, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11 }, // 2033 { 0, 1, 2, 3, 4, -1, -1, -1, 5, 6, 7, 8, 9, 10, 11, 12 }, // 3033 { 0, -1, -1, -1, 1, 2, -1, -1, 3, 4, 5, 6, 7, 8, 9, 10 }, // 0133 { 0, 1, -1, -1, 2, 3, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11 }, // 1133 { 0, 1, 2, -1, 3, 4, -1, -1, 5, 6, 7, 8, 9, 10, 11, 12 }, // 2133 { 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, 12, 13 }, // 3133 { 0, -1, -1, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11 }, // 0233 { 0, 1, -1, -1, 2, 3, 4, -1, 5, 6, 7, 8, 9, 10, 11, 12 }, // 1233 { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, 13 }, // 2233 { 0, 1, 2, 3, 4, 5, 6, -1, 7, 8, 9, 10, 11, 12, 13, 14 }, // 3233 { 0, -1, -1, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, // 0333 { 0, 1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, // 1333 { 0, 1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, // 2333 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // 3333 }; streamvbyte-0.4.1/src/streamvbyte_shuffle_tables_encode.h000066400000000000000000000664071346460053600237750ustar00rootroot00000000000000 // encoding: #ifdef __AVX__ static const uint8_t shuf_lut[64*16] = { 0x00, 0x04, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x06, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x06, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0x00, 0x04, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0x00, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0x00, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0x00, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; static const uint8_t len_lut[256] = { 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 8, 9, 10, 11, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 9, 10, 11, 12, 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15, 10, 11, 12, 13, 11, 12, 13, 14, 12, 13, 14, 15, 13, 14, 15, 16, }; #else static uint8_t encodingShuffleTable[256][16] = { { 0, 4, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1111 { 0, 1, 4, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2111 { 0, 1, 2, 4, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3111 { 0, 1, 2, 3, 4, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 4111 { 0, 4, 5, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1211 { 0, 1, 4, 5, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2211 { 0, 1, 2, 4, 5, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3211 { 0, 1, 2, 3, 4, 5, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 4211 { 0, 4, 5, 6, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1311 { 0, 1, 4, 5, 6, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2311 { 0, 1, 2, 4, 5, 6, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3311 { 0, 1, 2, 3, 4, 5, 6, 8, 12, -1, -1, -1, -1, -1, -1, -1 }, // 4311 { 0, 4, 5, 6, 7, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1411 { 0, 1, 4, 5, 6, 7, 8, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2411 { 0, 1, 2, 4, 5, 6, 7, 8, 12, -1, -1, -1, -1, -1, -1, -1 }, // 3411 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, -1, -1, -1, -1, -1, -1 }, // 4411 { 0, 4, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1121 { 0, 1, 4, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2121 { 0, 1, 2, 4, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3121 { 0, 1, 2, 3, 4, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 4121 { 0, 4, 5, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1221 { 0, 1, 4, 5, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2221 { 0, 1, 2, 4, 5, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3221 { 0, 1, 2, 3, 4, 5, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1 }, // 4221 { 0, 4, 5, 6, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1321 { 0, 1, 4, 5, 6, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2321 { 0, 1, 2, 4, 5, 6, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1 }, // 3321 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 12, -1, -1, -1, -1, -1, -1 }, // 4321 { 0, 4, 5, 6, 7, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1421 { 0, 1, 4, 5, 6, 7, 8, 9, 12, -1, -1, -1, -1, -1, -1, -1 }, // 2421 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 12, -1, -1, -1, -1, -1, -1 }, // 3421 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, -1, -1, -1, -1, -1 }, // 4421 { 0, 4, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1131 { 0, 1, 4, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2131 { 0, 1, 2, 4, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3131 { 0, 1, 2, 3, 4, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1 }, // 4131 { 0, 4, 5, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1231 { 0, 1, 4, 5, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2231 { 0, 1, 2, 4, 5, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1 }, // 3231 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1 }, // 4231 { 0, 4, 5, 6, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1331 { 0, 1, 4, 5, 6, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1 }, // 2331 { 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1 }, // 3331 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, -1, -1, -1, -1, -1 }, // 4331 { 0, 4, 5, 6, 7, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1, -1 }, // 1431 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 12, -1, -1, -1, -1, -1, -1 }, // 2431 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, -1, -1, -1, -1, -1 }, // 3431 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, -1, -1, -1, -1 }, // 4431 { 0, 4, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1141 { 0, 1, 4, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2141 { 0, 1, 2, 4, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1 }, // 3141 { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1 }, // 4141 { 0, 4, 5, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1241 { 0, 1, 4, 5, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1 }, // 2241 { 0, 1, 2, 4, 5, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1 }, // 3241 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1 }, // 4241 { 0, 4, 5, 6, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1 }, // 1341 { 0, 1, 4, 5, 6, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1 }, // 2341 { 0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1 }, // 3341 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, -1, -1, -1, -1 }, // 4341 { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1 }, // 1441 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1, -1, -1 }, // 2441 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1, -1 }, // 3441 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1, -1, -1 }, // 4441 { 0, 4, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1112 { 0, 1, 4, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2112 { 0, 1, 2, 4, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3112 { 0, 1, 2, 3, 4, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 4112 { 0, 4, 5, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1212 { 0, 1, 4, 5, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2212 { 0, 1, 2, 4, 5, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3212 { 0, 1, 2, 3, 4, 5, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 4212 { 0, 4, 5, 6, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1312 { 0, 1, 4, 5, 6, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2312 { 0, 1, 2, 4, 5, 6, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 3312 { 0, 1, 2, 3, 4, 5, 6, 8, 12, 13, -1, -1, -1, -1, -1, -1 }, // 4312 { 0, 4, 5, 6, 7, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1412 { 0, 1, 4, 5, 6, 7, 8, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 2412 { 0, 1, 2, 4, 5, 6, 7, 8, 12, 13, -1, -1, -1, -1, -1, -1 }, // 3412 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, -1, -1, -1, -1, -1 }, // 4412 { 0, 4, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1122 { 0, 1, 4, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2122 { 0, 1, 2, 4, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3122 { 0, 1, 2, 3, 4, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 4122 { 0, 4, 5, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1222 { 0, 1, 4, 5, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2222 { 0, 1, 2, 4, 5, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 3222 { 0, 1, 2, 3, 4, 5, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1 }, // 4222 { 0, 4, 5, 6, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1322 { 0, 1, 4, 5, 6, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 2322 { 0, 1, 2, 4, 5, 6, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1 }, // 3322 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 12, 13, -1, -1, -1, -1, -1 }, // 4322 { 0, 4, 5, 6, 7, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 1422 { 0, 1, 4, 5, 6, 7, 8, 9, 12, 13, -1, -1, -1, -1, -1, -1 }, // 2422 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 12, 13, -1, -1, -1, -1, -1 }, // 3422 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, -1, -1, -1, -1 }, // 4422 { 0, 4, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1132 { 0, 1, 4, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2132 { 0, 1, 2, 4, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 3132 { 0, 1, 2, 3, 4, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1 }, // 4132 { 0, 4, 5, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1232 { 0, 1, 4, 5, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 2232 { 0, 1, 2, 4, 5, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1 }, // 3232 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1 }, // 4232 { 0, 4, 5, 6, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 1332 { 0, 1, 4, 5, 6, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1 }, // 2332 { 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1 }, // 3332 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 13, -1, -1, -1, -1 }, // 4332 { 0, 4, 5, 6, 7, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1, -1 }, // 1432 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 12, 13, -1, -1, -1, -1, -1 }, // 2432 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, -1, -1, -1, -1 }, // 3432 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, -1, -1, -1 }, // 4432 { 0, 4, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1142 { 0, 1, 4, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 2142 { 0, 1, 2, 4, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1 }, // 3142 { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1 }, // 4142 { 0, 4, 5, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1 }, // 1242 { 0, 1, 4, 5, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1 }, // 2242 { 0, 1, 2, 4, 5, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1 }, // 3242 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1 }, // 4242 { 0, 4, 5, 6, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1 }, // 1342 { 0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1 }, // 2342 { 0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1 }, // 3342 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, -1, -1, -1 }, // 4342 { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1 }, // 1442 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1 }, // 2442 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1 }, // 3442 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1 }, // 4442 { 0, 4, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1113 { 0, 1, 4, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2113 { 0, 1, 2, 4, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 }, // 3113 { 0, 1, 2, 3, 4, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 4113 { 0, 4, 5, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1213 { 0, 1, 4, 5, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2213 { 0, 1, 2, 4, 5, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 3213 { 0, 1, 2, 3, 4, 5, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 4213 { 0, 4, 5, 6, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1313 { 0, 1, 4, 5, 6, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 2313 { 0, 1, 2, 4, 5, 6, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 3313 { 0, 1, 2, 3, 4, 5, 6, 8, 12, 13, 14, -1, -1, -1, -1, -1 }, // 4313 { 0, 4, 5, 6, 7, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 1413 { 0, 1, 4, 5, 6, 7, 8, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 2413 { 0, 1, 2, 4, 5, 6, 7, 8, 12, 13, 14, -1, -1, -1, -1, -1 }, // 3413 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, -1, -1, -1, -1 }, // 4413 { 0, 4, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1123 { 0, 1, 4, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2123 { 0, 1, 2, 4, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 3123 { 0, 1, 2, 3, 4, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 4123 { 0, 4, 5, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1223 { 0, 1, 4, 5, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 2223 { 0, 1, 2, 4, 5, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 3223 { 0, 1, 2, 3, 4, 5, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1 }, // 4223 { 0, 4, 5, 6, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 1323 { 0, 1, 4, 5, 6, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 2323 { 0, 1, 2, 4, 5, 6, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1 }, // 3323 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 12, 13, 14, -1, -1, -1, -1 }, // 4323 { 0, 4, 5, 6, 7, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 1423 { 0, 1, 4, 5, 6, 7, 8, 9, 12, 13, 14, -1, -1, -1, -1, -1 }, // 2423 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 12, 13, 14, -1, -1, -1, -1 }, // 3423 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, -1, -1, -1 }, // 4423 { 0, 4, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1133 { 0, 1, 4, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 2133 { 0, 1, 2, 4, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 3133 { 0, 1, 2, 3, 4, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1 }, // 4133 { 0, 4, 5, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 1233 { 0, 1, 4, 5, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 2233 { 0, 1, 2, 4, 5, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1 }, // 3233 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1 }, // 4233 { 0, 4, 5, 6, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 1333 { 0, 1, 4, 5, 6, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1 }, // 2333 { 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1 }, // 3333 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 13, 14, -1, -1, -1 }, // 4333 { 0, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, -1 }, // 1433 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1 }, // 2433 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, -1, -1, -1 }, // 3433 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, -1, -1 }, // 4433 { 0, 4, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1 }, // 1143 { 0, 1, 4, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 2143 { 0, 1, 2, 4, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1 }, // 3143 { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1 }, // 4143 { 0, 4, 5, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1 }, // 1243 { 0, 1, 4, 5, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1 }, // 2243 { 0, 1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1 }, // 3243 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1 }, // 4243 { 0, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1 }, // 1343 { 0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1 }, // 2343 { 0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1 }, // 3343 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, -1, -1 }, // 4343 { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1 }, // 1443 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1 }, // 2443 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -1, -1 }, // 3443 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, -1 }, // 4443 { 0, 4, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1114 { 0, 1, 4, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 2114 { 0, 1, 2, 4, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 3114 { 0, 1, 2, 3, 4, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 4114 { 0, 4, 5, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1214 { 0, 1, 4, 5, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 2214 { 0, 1, 2, 4, 5, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 3214 { 0, 1, 2, 3, 4, 5, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 4214 { 0, 4, 5, 6, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 1314 { 0, 1, 4, 5, 6, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 2314 { 0, 1, 2, 4, 5, 6, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 3314 { 0, 1, 2, 3, 4, 5, 6, 8, 12, 13, 14, 15, -1, -1, -1, -1 }, // 4314 { 0, 4, 5, 6, 7, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 1414 { 0, 1, 4, 5, 6, 7, 8, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 2414 { 0, 1, 2, 4, 5, 6, 7, 8, 12, 13, 14, 15, -1, -1, -1, -1 }, // 3414 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, -1, -1, -1 }, // 4414 { 0, 4, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1 }, // 1124 { 0, 1, 4, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 2124 { 0, 1, 2, 4, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 3124 { 0, 1, 2, 3, 4, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 4124 { 0, 4, 5, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 1224 { 0, 1, 4, 5, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 2224 { 0, 1, 2, 4, 5, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 3224 { 0, 1, 2, 3, 4, 5, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1 }, // 4224 { 0, 4, 5, 6, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 1324 { 0, 1, 4, 5, 6, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 2324 { 0, 1, 2, 4, 5, 6, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1 }, // 3324 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 12, 13, 14, 15, -1, -1, -1 }, // 4324 { 0, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 1424 { 0, 1, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, -1, -1, -1, -1 }, // 2424 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, -1, -1, -1 }, // 3424 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, -1, -1 }, // 4424 { 0, 4, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1 }, // 1134 { 0, 1, 4, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 2134 { 0, 1, 2, 4, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 3134 { 0, 1, 2, 3, 4, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1 }, // 4134 { 0, 4, 5, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 1234 { 0, 1, 4, 5, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 2234 { 0, 1, 2, 4, 5, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1 }, // 3234 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1 }, // 4234 { 0, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 1334 { 0, 1, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1 }, // 2334 { 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1 }, // 3334 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, -1, -1 }, // 4334 { 0, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1, -1 }, // 1434 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, -1, -1, -1 }, // 2434 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, -1, -1 }, // 3434 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, -1 }, // 4434 { 0, 4, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1 }, // 1144 { 0, 1, 4, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 2144 { 0, 1, 2, 4, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1 }, // 3144 { 0, 1, 2, 3, 4, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1 }, // 4144 { 0, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1 }, // 1244 { 0, 1, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1 }, // 2244 { 0, 1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1 }, // 3244 { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1 }, // 4244 { 0, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1 }, // 1344 { 0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1 }, // 2344 { 0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1 }, // 3344 { 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, -1 }, // 4344 { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1 }, // 1444 { 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1 }, // 2444 { 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1 }, // 3444 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, // 4444 }; #endif streamvbyte-0.4.1/src/streamvbyte_x64_decode.c000066400000000000000000000056641346460053600214070ustar00rootroot00000000000000 static inline __m128i _decode_avx(uint32_t key, const uint8_t *__restrict__ *dataPtrPtr) { uint8_t len; __m128i Data = _mm_loadu_si128((__m128i *)*dataPtrPtr); uint8_t *pshuf = (uint8_t *) &shuffleTable[key]; __m128i Shuf = *(__m128i *)pshuf; #ifdef AVOIDLENGTHLOOKUP // this avoids the dependency on lengthTable, // see https://github.com/lemire/streamvbyte/issues/12 len = pshuf[12 + (key >> 6)] + 1; #else len = lengthTable[key]; #endif Data = _mm_shuffle_epi8(Data, Shuf); *dataPtrPtr += len; return Data; } static inline void _write_avx(uint32_t *out, __m128i Vec) { _mm_storeu_si128((__m128i *)out, Vec); } const uint8_t *svb_decode_avx_simple(uint32_t *out, const uint8_t *__restrict__ keyPtr, const uint8_t *__restrict__ dataPtr, uint64_t count) { uint64_t keybytes = count / 4; // number of key bytes __m128i Data; if (keybytes >= 8) { int64_t Offset = -(int64_t)keybytes / 8 + 1; const uint64_t *keyPtr64 = (const uint64_t *)keyPtr - Offset; uint64_t nextkeys; memcpy(&nextkeys, keyPtr64 + Offset, sizeof(nextkeys)); for (; Offset != 0; ++Offset) { uint64_t keys = nextkeys; memcpy(&nextkeys, keyPtr64 + Offset + 1, sizeof(nextkeys)); Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 4, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 8, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 12, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 16, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 20, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 24, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 28, Data); out += 32; } { uint64_t keys = nextkeys; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 4, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 8, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 12, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 16, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 20, Data); keys >>= 16; Data = _decode_avx((keys & 0xFF), &dataPtr); _write_avx(out + 24, Data); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); _write_avx(out + 28, Data); out += 32; } } return dataPtr; } streamvbyte-0.4.1/src/streamvbyte_x64_encode.c000066400000000000000000000032171346460053600214110ustar00rootroot00000000000000 // contributed by aqrit size_t streamvbyte_encode_SSSE3 (const uint32_t* in, uint32_t count, uint8_t* out) { uint32_t keyLen = (count >> 2) + (((count & 3) + 3) >> 2); // 2-bits per each rounded up to byte boundry uint8_t *restrict keyPtr = &out[0]; uint8_t *restrict dataPtr = &out[keyLen]; // variable length data after keys const __m128i mask_01 = _mm_set1_epi8(0x01); const __m128i mask_7F00 = _mm_set1_epi16(0x7F00); for (const uint32_t* end = &in[(count & ~7)]; in != end; in += 8) { __m128i r0, r1, r2, r3; size_t keys; r0 = _mm_loadu_si128((__m128i*)&in[0]); r1 = _mm_loadu_si128((__m128i*)&in[4]); r2 = _mm_min_epu8(mask_01, r0); r3 = _mm_min_epu8(mask_01, r1); r2 = _mm_packus_epi16(r2, r3); r2 = _mm_min_epi16(r2, mask_01); // convert 0x01FF to 0x0101 r2 = _mm_adds_epu16(r2, mask_7F00); // convert: 0x0101 to 0x8001, 0xFF01 to 0xFFFF keys = (size_t)_mm_movemask_epi8(r2); r2 = _mm_loadu_si128((__m128i*)&shuf_lut[(keys << 4) & 0x03F0]); r3 = _mm_loadu_si128((__m128i*)&shuf_lut[(keys >> 4) & 0x03F0]); r0 = _mm_shuffle_epi8(r0, r2); r1 = _mm_shuffle_epi8(r1, r3); _mm_storeu_si128((__m128i *)dataPtr, r0); dataPtr += len_lut[keys & 0xFF]; _mm_storeu_si128((__m128i *)dataPtr, r1); dataPtr += len_lut[keys >> 8]; *((uint16_t*)keyPtr) = (uint16_t)keys; keyPtr += 2; } // do remaining uint32_t key = 0; for(size_t i = 0; i < (count & 7); i++) { uint32_t dw = in[i]; uint32_t symbol = (dw > 0x000000FF) + (dw > 0x0000FFFF) + (dw > 0x00FFFFFF); key |= symbol << (i + i); *((uint32_t*)dataPtr) = dw; dataPtr += 1 + symbol; } memcpy(keyPtr, &key, ((count & 7) + 3) >> 2); return dataPtr - out; } streamvbyte-0.4.1/src/streamvbyte_zigzag.c000066400000000000000000000016501346460053600207450ustar00rootroot00000000000000#include "streamvbyte_zigzag.h" static inline uint32_t _zigzag_encode_32 (int32_t val) { return (val + val) ^ (val >> 31); } void zigzag_encode(const int32_t * in, uint32_t * out, size_t N) { for(size_t i = 0; i < N; i++) out[i] = _zigzag_encode_32(in[i]); } void zigzag_delta_encode(const int32_t * in, uint32_t * out, size_t N, int32_t prev) { for (size_t i = 0; i < N; i++) { out[i] = _zigzag_encode_32(in[i] - prev); prev = in[i]; } } static inline int32_t _zigzag_decode_32 (uint32_t val) { return (val >> 1) ^ -(val & 1); } void zigzag_decode(const uint32_t * in, int32_t * out, size_t N) { for(size_t i = 0; i < N; i++) out[i] = _zigzag_decode_32(in[i]); } void zigzag_delta_decode(const uint32_t * in, int32_t * out, size_t N, int32_t prev) { for(size_t i = 0; i < N; i++) { int32_t val =_zigzag_decode_32(in[i]); out[i] = val + prev; prev += val; } } streamvbyte-0.4.1/src/streamvbytedelta.c000066400000000000000000000304101346460053600204000ustar00rootroot00000000000000#include "streamvbytedelta.h" #if defined(_MSC_VER) /* Microsoft C/C++-compatible compiler */ #include #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) /* GCC-compatible compiler, targeting x86/x86-64 */ #include #elif defined(__GNUC__) && defined(__ARM_NEON__) /* GCC-compatible compiler, targeting ARM with NEON */ #include #elif defined(__GNUC__) && defined(__IWMMXT__) /* GCC-compatible compiler, targeting ARM with WMMX */ #include #elif (defined(__GNUC__) || defined(__xlC__)) && \ (defined(__VEC__) || defined(__ALTIVEC__)) /* XLC or GCC-compatible compiler, targeting PowerPC with VMX/VSX */ #include #elif defined(__GNUC__) && defined(__SPE__) /* GCC-compatible compiler, targeting PowerPC with SPE */ #include #endif #ifdef __AVX__ #include "streamvbyte_shuffle_tables.h" size_t streamvbyte_encode4(__m128i in, uint8_t *outData, uint8_t *outCode); #endif #include // for memcpy static uint8_t _encode_data(uint32_t val, uint8_t *__restrict__ *dataPtrPtr) { uint8_t *dataPtr = *dataPtrPtr; uint8_t code; if (val < (1 << 8)) { // 1 byte *dataPtr = (uint8_t)(val); *dataPtrPtr += 1; code = 0; } else if (val < (1 << 16)) { // 2 bytes memcpy(dataPtr, &val, 2); // assumes little endian *dataPtrPtr += 2; code = 1; } else if (val < (1 << 24)) { // 3 bytes memcpy(dataPtr, &val, 3); // assumes little endian *dataPtrPtr += 3; code = 2; } else { // 4 bytes memcpy(dataPtr, &val, sizeof(uint32_t)); *dataPtrPtr += sizeof(uint32_t); code = 3; } return code; } static uint8_t *svb_encode_scalar_d1_init(const uint32_t *in, uint8_t *__restrict__ keyPtr, uint8_t *__restrict__ dataPtr, uint32_t count, uint32_t prev) { if (count == 0) return dataPtr; // exit immediately if no data uint8_t shift = 0; // cycles 0, 2, 4, 6, 0, 2, 4, 6, ... uint8_t key = 0; for (uint32_t c = 0; c < count; c++) { if (shift == 8) { shift = 0; *keyPtr++ = key; key = 0; } uint32_t val = in[c] - prev; prev = in[c]; uint8_t code = _encode_data(val, &dataPtr); key |= code << shift; shift += 2; } *keyPtr = key; // write last key (no increment needed) return dataPtr; // pointer to first unused data byte } #ifdef __AVX__ // from streamvbyte.c size_t streamvbyte_encode_quad(__m128i in, uint8_t *outData, uint8_t *outCode); static __m128i Delta(__m128i curr, __m128i prev) { return _mm_sub_epi32(curr, _mm_alignr_epi8(curr, prev, 12)); } static uint8_t *svb_encode_vector_d1_init(const uint32_t *in, uint8_t *__restrict__ keyPtr, uint8_t *__restrict__ dataPtr, uint32_t count, uint32_t prev) { uint8_t *outData = dataPtr; uint8_t *outKey = keyPtr; uint32_t count4 = count / 4; __m128i Prev = _mm_set1_epi32(prev); for (uint32_t c = 0; c < count4; c++) { __m128i vin = _mm_loadu_si128((__m128i *)(in + 4 * c)); __m128i deltain = Delta(vin, Prev); Prev = vin; outData += streamvbyte_encode4(deltain, outData, outKey); outKey++; } prev = _mm_extract_epi32(Prev, 3); // we grab the last*/ outData = svb_encode_scalar_d1_init(in + 4 * count4, outKey, outData, count - 4 * count4, prev); // outData = svb_encode_scalar_d1_init(in, outKey, outData, count, prev); return outData; } #endif size_t streamvbyte_delta_encode(const uint32_t *in, uint32_t count, uint8_t *out, uint32_t prev) { uint8_t *keyPtr = out; // keys come immediately after 32-bit count uint32_t keyLen = (count + 3) / 4; // 2-bits rounded to full byte uint8_t *dataPtr = keyPtr + keyLen; // variable byte data after all keys #ifdef __AVX__ return svb_encode_vector_d1_init(in, keyPtr, dataPtr, count, prev) - out; #else return svb_encode_scalar_d1_init(in, keyPtr, dataPtr, count, prev) - out; #endif } #ifdef __AVX__ static inline __m128i _decode_avx(uint32_t key, const uint8_t *__restrict__ *dataPtrPtr) { uint8_t len = lengthTable[key]; __m128i Data = _mm_loadu_si128((__m128i *)*dataPtrPtr); __m128i Shuf = *(__m128i *)&shuffleTable[key]; Data = _mm_shuffle_epi8(Data, Shuf); *dataPtrPtr += len; return Data; } #define BroadcastLastXMM 0xFF // bits 0-7 all set to choose highest element static inline void _write_avx(uint32_t *out, __m128i Vec) { _mm_storeu_si128((__m128i *)out, Vec); } static __m128i _write_avx_d1(uint32_t *out, __m128i Vec, __m128i Prev) { __m128i Add = _mm_slli_si128(Vec, 4); // Cycle 1: [- A B C] (already done) Prev = _mm_shuffle_epi32(Prev, BroadcastLastXMM); // Cycle 2: [P P P P] Vec = _mm_add_epi32(Vec, Add); // Cycle 2: [A AB BC CD] Add = _mm_slli_si128(Vec, 8); // Cycle 3: [- - A AB] Vec = _mm_add_epi32(Vec, Prev); // Cycle 3: [PA PAB PBC PCD] Vec = _mm_add_epi32(Vec, Add); // Cycle 4: [PA PAB PABC PABCD] _write_avx(out, Vec); return Vec; } #ifndef _MSC_VER static __m128i High16To32 = {0xFFFF0B0AFFFF0908, 0xFFFF0F0EFFFF0D0C}; #else static __m128i High16To32 = {8, 9, -1, -1, 10, 11, -1, -1, 12, 13, -1, -1, 14, 15, -1, -1}; #endif static inline __m128i _write_16bit_avx_d1(uint32_t *out, __m128i Vec, __m128i Prev) { // vec == [A B C D E F G H] (16 bit values) __m128i Add = _mm_slli_si128(Vec, 2); // [- A B C D E F G] Prev = _mm_shuffle_epi32(Prev, BroadcastLastXMM); // [P P P P] (32-bit) Vec = _mm_add_epi32(Vec, Add); // [A AB BC CD DE FG GH] Add = _mm_slli_si128(Vec, 4); // [- - A AB BC CD DE EF] Vec = _mm_add_epi32(Vec, Add); // [A AB ABC ABCD BCDE CDEF DEFG EFGH] __m128i V1 = _mm_cvtepu16_epi32(Vec); // [A AB ABC ABCD] (32-bit) V1 = _mm_add_epi32(V1, Prev); // [PA PAB PABC PABCD] (32-bit) __m128i V2 = _mm_shuffle_epi8(Vec, High16To32); // [BCDE CDEF DEFG EFGH] (32-bit) V2 = _mm_add_epi32(V1, V2); // [PABCDE PABCDEF PABCDEFG PABCDEFGH] (32-bit) _write_avx(out, V1); _write_avx(out + 4, V2); return V2; } #endif static inline uint32_t _decode_data(const uint8_t **dataPtrPtr, uint8_t code) { const uint8_t *dataPtr = *dataPtrPtr; uint32_t val; if (code == 0) { // 1 byte val = (uint32_t)*dataPtr; dataPtr += 1; } else if (code == 1) { // 2 bytes val = 0; memcpy(&val, dataPtr, 2); // assumes little endian dataPtr += 2; } else if (code == 2) { // 3 bytes val = 0; memcpy(&val, dataPtr, 3); // assumes little endian dataPtr += 3; } else { // code == 3 memcpy(&val, dataPtr, 4); dataPtr += 4; } *dataPtrPtr = dataPtr; return val; } static const uint8_t *svb_decode_scalar_d1_init(uint32_t *outPtr, const uint8_t *keyPtr, const uint8_t *dataPtr, uint32_t count, uint32_t prev) { if (count == 0) return dataPtr; // no reads or writes if no data uint8_t shift = 0; uint32_t key = *keyPtr++; for (uint32_t c = 0; c < count; c++) { if (shift == 8) { shift = 0; key = *keyPtr++; } uint32_t val = _decode_data(&dataPtr, (key >> shift) & 0x3); val += prev; *outPtr++ = val; prev = val; shift += 2; } return dataPtr; // pointer to first unused byte after end } #ifdef __AVX__ const uint8_t *svb_decode_avx_d1_init(uint32_t *out, const uint8_t *__restrict__ keyPtr, const uint8_t *__restrict__ dataPtr, uint64_t count, uint32_t prev) { uint64_t keybytes = count / 4; // number of key bytes if (keybytes >= 8) { __m128i Prev = _mm_set1_epi32(prev); __m128i Data; int64_t Offset = -(int64_t)keybytes / 8 + 1; const uint64_t *keyPtr64 = (const uint64_t *)keyPtr - Offset; uint64_t nextkeys; memcpy(&nextkeys, keyPtr64 + Offset, sizeof(nextkeys)); for (; Offset != 0; ++Offset) { uint64_t keys = nextkeys; memcpy(&nextkeys, keyPtr64 + Offset + 1, sizeof(nextkeys)); // faster 16-bit delta since we only have 8-bit values if (!keys) { // 32 1-byte ints in a row Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr))); Prev = _write_16bit_avx_d1(out, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 8))); Prev = _write_16bit_avx_d1(out + 8, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 16))); Prev = _write_16bit_avx_d1(out + 16, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 24))); Prev = _write_16bit_avx_d1(out + 24, Data, Prev); out += 32; dataPtr += 32; continue; } Data = _decode_avx(keys & 0x00FF, &dataPtr); Prev = _write_avx_d1(out, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 4, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 8, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 12, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 16, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 20, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 24, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 28, Data, Prev); out += 32; } { uint64_t keys = nextkeys; // faster 16-bit delta since we only have 8-bit values if (!keys) { // 32 1-byte ints in a row Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr))); Prev = _write_16bit_avx_d1(out, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 8))); Prev = _write_16bit_avx_d1(out + 8, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 16))); Prev = _write_16bit_avx_d1(out + 16, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_loadl_epi64((__m128i *)(dataPtr + 24))); Prev = _write_16bit_avx_d1(out + 24, Data, Prev); out += 32; dataPtr += 32; } else { Data = _decode_avx(keys & 0x00FF, &dataPtr); Prev = _write_avx_d1(out, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 4, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 8, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 12, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 16, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 20, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 24, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 28, Data, Prev); out += 32; } } prev = out[-1]; } uint64_t consumedkeys = keybytes - (keybytes & 7); return svb_decode_scalar_d1_init(out, keyPtr + consumedkeys, dataPtr, count & 31, prev); } #endif size_t streamvbyte_delta_decode(const uint8_t *in, uint32_t *out, uint32_t count, uint32_t prev) { uint32_t keyLen = ((count + 3) / 4); // 2-bits per key (rounded up) const uint8_t *keyPtr = in; const uint8_t *dataPtr = keyPtr + keyLen; // data starts at end of keys #ifdef __AVX__ return svb_decode_avx_d1_init(out, keyPtr, dataPtr, count, prev) - in; #else return svb_decode_scalar_d1_init(out, keyPtr, dataPtr, count, prev) - in; #endif } streamvbyte-0.4.1/src/streamvbytedelta_decode.c000066400000000000000000000052461346460053600217140ustar00rootroot00000000000000#include "streamvbytedelta.h" #if defined(_MSC_VER) /* Microsoft C/C++-compatible compiler */ #include #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) /* GCC-compatible compiler, targeting x86/x86-64 */ #include #elif defined(__GNUC__) && defined(__ARM_NEON__) /* GCC-compatible compiler, targeting ARM with NEON */ #include #elif defined(__GNUC__) && defined(__IWMMXT__) /* GCC-compatible compiler, targeting ARM with WMMX */ #include #elif (defined(__GNUC__) || defined(__xlC__)) && \ (defined(__VEC__) || defined(__ALTIVEC__)) /* XLC or GCC-compatible compiler, targeting PowerPC with VMX/VSX */ #include #elif defined(__GNUC__) && defined(__SPE__) /* GCC-compatible compiler, targeting PowerPC with SPE */ #include #endif #include // for memcpy static inline uint32_t _decode_data(const uint8_t **dataPtrPtr, uint8_t code) { const uint8_t *dataPtr = *dataPtrPtr; uint32_t val; if (code == 0) { // 1 byte val = (uint32_t)*dataPtr; dataPtr += 1; } else if (code == 1) { // 2 bytes val = 0; memcpy(&val, dataPtr, 2); // assumes little endian dataPtr += 2; } else if (code == 2) { // 3 bytes val = 0; memcpy(&val, dataPtr, 3); // assumes little endian dataPtr += 3; } else { // code == 3 memcpy(&val, dataPtr, 4); dataPtr += 4; } *dataPtrPtr = dataPtr; return val; } static const uint8_t *svb_decode_scalar_d1_init(uint32_t *outPtr, const uint8_t *keyPtr, const uint8_t *dataPtr, uint32_t count, uint32_t prev) { if (count == 0) return dataPtr; // no reads or writes if no data uint8_t shift = 0; uint32_t key = *keyPtr++; for (uint32_t c = 0; c < count; c++) { if (shift == 8) { shift = 0; key = *keyPtr++; } uint32_t val = _decode_data(&dataPtr, (key >> shift) & 0x3); val += prev; *outPtr++ = val; prev = val; shift += 2; } return dataPtr; // pointer to first unused byte after end } #ifdef __AVX__ #include "streamvbytedelta_x64_decode.c" #endif size_t streamvbyte_delta_decode(const uint8_t *in, uint32_t *out, uint32_t count, uint32_t prev) { uint32_t keyLen = ((count + 3) / 4); // 2-bits per key (rounded up) const uint8_t *keyPtr = in; const uint8_t *dataPtr = keyPtr + keyLen; // data starts at end of keys #ifdef __AVX__ return svb_decode_avx_d1_init(out, keyPtr, dataPtr, count, prev) - in; #else return svb_decode_scalar_d1_init(out, keyPtr, dataPtr, count, prev) - in; #endif } streamvbyte-0.4.1/src/streamvbytedelta_encode.c000066400000000000000000000056071346460053600217270ustar00rootroot00000000000000#include "streamvbytedelta.h" #if defined(_MSC_VER) /* Microsoft C/C++-compatible compiler */ #include #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) /* GCC-compatible compiler, targeting x86/x86-64 */ #include #elif defined(__GNUC__) && defined(__ARM_NEON__) /* GCC-compatible compiler, targeting ARM with NEON */ #include #elif defined(__GNUC__) && defined(__IWMMXT__) /* GCC-compatible compiler, targeting ARM with WMMX */ #include #elif (defined(__GNUC__) || defined(__xlC__)) && \ (defined(__VEC__) || defined(__ALTIVEC__)) /* XLC or GCC-compatible compiler, targeting PowerPC with VMX/VSX */ #include #elif defined(__GNUC__) && defined(__SPE__) /* GCC-compatible compiler, targeting PowerPC with SPE */ #include #endif #include // for memcpy #ifdef __AVX__ #include "streamvbytedelta_x64_encode.c" #else static uint8_t _encode_data(uint32_t val, uint8_t *__restrict__ *dataPtrPtr) { uint8_t *dataPtr = *dataPtrPtr; uint8_t code; if (val < (1 << 8)) { // 1 byte *dataPtr = (uint8_t)(val); *dataPtrPtr += 1; code = 0; } else if (val < (1 << 16)) { // 2 bytes memcpy(dataPtr, &val, 2); // assumes little endian *dataPtrPtr += 2; code = 1; } else if (val < (1 << 24)) { // 3 bytes memcpy(dataPtr, &val, 3); // assumes little endian *dataPtrPtr += 3; code = 2; } else { // 4 bytes memcpy(dataPtr, &val, sizeof(uint32_t)); *dataPtrPtr += sizeof(uint32_t); code = 3; } return code; } static uint8_t *svb_encode_scalar_d1_init(const uint32_t *in, uint8_t *__restrict__ keyPtr, uint8_t *__restrict__ dataPtr, uint32_t count, uint32_t prev) { if (count == 0) return dataPtr; // exit immediately if no data uint8_t shift = 0; // cycles 0, 2, 4, 6, 0, 2, 4, 6, ... uint8_t key = 0; for (uint32_t c = 0; c < count; c++) { if (shift == 8) { shift = 0; *keyPtr++ = key; key = 0; } uint32_t val = in[c] - prev; prev = in[c]; uint8_t code = _encode_data(val, &dataPtr); key |= code << shift; shift += 2; } *keyPtr = key; // write last key (no increment needed) return dataPtr; // pointer to first unused data byte } #endif size_t streamvbyte_delta_encode(const uint32_t *in, uint32_t count, uint8_t *out, uint32_t prev) { #ifdef __AVX__ return streamvbyte_encode_SSSE3_d1_init(in,count,out,prev); #else uint8_t *keyPtr = out; // keys come immediately after 32-bit count uint32_t keyLen = (count + 3) / 4; // 2-bits rounded to full byte uint8_t *dataPtr = keyPtr + keyLen; // variable byte data after all keys return svb_encode_scalar_d1_init(in, keyPtr, dataPtr, count, prev) - out; #endif } streamvbyte-0.4.1/src/streamvbytedelta_x64_decode.c000066400000000000000000000147201346460053600224120ustar00rootroot00000000000000#include // for memcpy #include "streamvbyte_shuffle_tables_decode.h" static inline __m128i _decode_avx(uint32_t key, const uint8_t *__restrict__ *dataPtrPtr) { uint8_t len = lengthTable[key]; __m128i Data = _mm_loadu_si128((__m128i *)*dataPtrPtr); __m128i Shuf = *(__m128i *)&shuffleTable[key]; Data = _mm_shuffle_epi8(Data, Shuf); *dataPtrPtr += len; return Data; } #define BroadcastLastXMM 0xFF // bits 0-7 all set to choose highest element static inline void _write_avx(uint32_t *out, __m128i Vec) { _mm_storeu_si128((__m128i *)out, Vec); } static __m128i _write_avx_d1(uint32_t *out, __m128i Vec, __m128i Prev) { __m128i Add = _mm_slli_si128(Vec, 4); // Cycle 1: [- A B C] (already done) Prev = _mm_shuffle_epi32(Prev, BroadcastLastXMM); // Cycle 2: [P P P P] Vec = _mm_add_epi32(Vec, Add); // Cycle 2: [A AB BC CD] Add = _mm_slli_si128(Vec, 8); // Cycle 3: [- - A AB] Vec = _mm_add_epi32(Vec, Prev); // Cycle 3: [PA PAB PBC PCD] Vec = _mm_add_epi32(Vec, Add); // Cycle 4: [PA PAB PABC PABCD] _write_avx(out, Vec); return Vec; } #ifndef _MSC_VER static __m128i High16To32 = {0xFFFF0B0AFFFF0908, 0xFFFF0F0EFFFF0D0C}; #else static __m128i High16To32 = {8, 9, -1, -1, 10, 11, -1, -1, 12, 13, -1, -1, 14, 15, -1, -1}; #endif static inline __m128i _write_16bit_avx_d1(uint32_t *out, __m128i Vec, __m128i Prev) { // vec == [A B C D E F G H] (16 bit values) __m128i Add = _mm_slli_si128(Vec, 2); // [- A B C D E F G] Prev = _mm_shuffle_epi32(Prev, BroadcastLastXMM); // [P P P P] (32-bit) Vec = _mm_add_epi32(Vec, Add); // [A AB BC CD DE FG GH] Add = _mm_slli_si128(Vec, 4); // [- - A AB BC CD DE EF] Vec = _mm_add_epi32(Vec, Add); // [A AB ABC ABCD BCDE CDEF DEFG EFGH] __m128i V1 = _mm_cvtepu16_epi32(Vec); // [A AB ABC ABCD] (32-bit) V1 = _mm_add_epi32(V1, Prev); // [PA PAB PABC PABCD] (32-bit) __m128i V2 = _mm_shuffle_epi8(Vec, High16To32); // [BCDE CDEF DEFG EFGH] (32-bit) V2 = _mm_add_epi32(V1, V2); // [PABCDE PABCDEF PABCDEFG PABCDEFGH] (32-bit) _write_avx(out, V1); _write_avx(out + 4, V2); return V2; } const uint8_t *svb_decode_avx_d1_init(uint32_t *out, const uint8_t *__restrict__ keyPtr, const uint8_t *__restrict__ dataPtr, uint64_t count, uint32_t prev) { uint64_t keybytes = count / 4; // number of key bytes if (keybytes >= 8) { __m128i Prev = _mm_set1_epi32(prev); __m128i Data; int64_t Offset = -(int64_t)keybytes / 8 + 1; const uint64_t *keyPtr64 = (const uint64_t *)keyPtr - Offset; uint64_t nextkeys; memcpy(&nextkeys, keyPtr64 + Offset, sizeof(nextkeys)); for (; Offset != 0; ++Offset) { uint64_t keys = nextkeys; memcpy(&nextkeys, keyPtr64 + Offset + 1, sizeof(nextkeys)); // faster 16-bit delta since we only have 8-bit values if (!keys) { // 32 1-byte ints in a row Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr))); Prev = _write_16bit_avx_d1(out, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 8))); Prev = _write_16bit_avx_d1(out + 8, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 16))); Prev = _write_16bit_avx_d1(out + 16, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 24))); Prev = _write_16bit_avx_d1(out + 24, Data, Prev); out += 32; dataPtr += 32; continue; } Data = _decode_avx(keys & 0x00FF, &dataPtr); Prev = _write_avx_d1(out, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 4, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 8, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 12, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 16, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 20, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 24, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 28, Data, Prev); out += 32; } { uint64_t keys = nextkeys; // faster 16-bit delta since we only have 8-bit values if (!keys) { // 32 1-byte ints in a row Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr))); Prev = _write_16bit_avx_d1(out, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 8))); Prev = _write_16bit_avx_d1(out + 8, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_lddqu_si128((__m128i *)(dataPtr + 16))); Prev = _write_16bit_avx_d1(out + 16, Data, Prev); Data = _mm_cvtepu8_epi16(_mm_loadl_epi64((__m128i *)(dataPtr + 24))); Prev = _write_16bit_avx_d1(out + 24, Data, Prev); out += 32; dataPtr += 32; } else { Data = _decode_avx(keys & 0x00FF, &dataPtr); Prev = _write_avx_d1(out, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 4, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 8, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 12, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 16, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 20, Data, Prev); keys >>= 16; Data = _decode_avx((keys & 0x00FF), &dataPtr); Prev = _write_avx_d1(out + 24, Data, Prev); Data = _decode_avx((keys & 0xFF00) >> 8, &dataPtr); Prev = _write_avx_d1(out + 28, Data, Prev); out += 32; } } prev = out[-1]; } uint64_t consumedkeys = keybytes - (keybytes & 7); return svb_decode_scalar_d1_init(out, keyPtr + consumedkeys, dataPtr, count & 31, prev); } streamvbyte-0.4.1/src/streamvbytedelta_x64_encode.c000066400000000000000000000040731346460053600224240ustar00rootroot00000000000000 #include "streamvbyte_shuffle_tables_encode.h" static __m128i Delta(__m128i curr, __m128i prev) { return _mm_sub_epi32(curr, _mm_alignr_epi8(curr, prev, 12)); } // based on code by aqrit (streamvbyte_encode_SSSE3) size_t streamvbyte_encode_SSSE3_d1_init (const uint32_t* in, uint32_t count, uint8_t* out, uint32_t prev) { __m128i Prev = _mm_set1_epi32(prev); uint32_t keyLen = (count >> 2) + (((count & 3) + 3) >> 2); // 2-bits per each rounded up to byte boundry uint8_t *restrict keyPtr = &out[0]; uint8_t *restrict dataPtr = &out[keyLen]; // variable length data after keys const __m128i mask_01 = _mm_set1_epi8(0x01); const __m128i mask_7F00 = _mm_set1_epi16(0x7F00); for (const uint32_t* end = &in[(count & ~7)]; in != end; in += 8) { __m128i rawr0, r0, rawr1, r1, r2, r3; size_t keys; rawr0 = _mm_loadu_si128((__m128i*)&in[0]); r0 = Delta(rawr0, Prev); Prev = rawr0; rawr1 = _mm_loadu_si128((__m128i*)&in[4]); r1 = Delta(rawr1, Prev); Prev = rawr1; r2 = _mm_min_epu8(mask_01, r0); r3 = _mm_min_epu8(mask_01, r1); r2 = _mm_packus_epi16(r2, r3); r2 = _mm_min_epi16(r2, mask_01); // convert 0x01FF to 0x0101 r2 = _mm_adds_epu16(r2, mask_7F00); // convert: 0x0101 to 0x8001, 0xFF01 to 0xFFFF keys = (size_t)_mm_movemask_epi8(r2); r2 = _mm_loadu_si128((__m128i*)&shuf_lut[(keys << 4) & 0x03F0]); r3 = _mm_loadu_si128((__m128i*)&shuf_lut[(keys >> 4) & 0x03F0]); r0 = _mm_shuffle_epi8(r0, r2); r1 = _mm_shuffle_epi8(r1, r3); _mm_storeu_si128((__m128i *)dataPtr, r0); dataPtr += len_lut[keys & 0xFF]; _mm_storeu_si128((__m128i *)dataPtr, r1); dataPtr += len_lut[keys >> 8]; *((uint16_t*)keyPtr) = (uint16_t)keys; keyPtr += 2; } prev = _mm_extract_epi32(Prev,3); // do remaining uint32_t key = 0; for(size_t i = 0; i < (count & 7); i++) { uint32_t dw = in[i] - prev; prev = in[i]; uint32_t symbol = (dw > 0x000000FF) + (dw > 0x0000FFFF) + (dw > 0x00FFFFFF); key |= symbol << (i + i); *((uint32_t*)dataPtr) = dw; dataPtr += 1 + symbol; } memcpy(keyPtr, &key, ((count & 7) + 3) >> 2); return dataPtr - out; } streamvbyte-0.4.1/tests/000077500000000000000000000000001346460053600152325ustar00rootroot00000000000000streamvbyte-0.4.1/tests/perf.c000066400000000000000000000037161346460053600163410ustar00rootroot00000000000000#include "streamvbyte.h" #include #include #include #include #include #include #include void punt(long long n, char *s) { int i = 127; int sign = 0; if (n < 0) { sign = 1; n = -n; } s[i--] = '\0'; // null terminated int digits = 0; do { s[i--] = n % 10 + '0'; digits++; n /= 10; if (((digits % 3) == 0) && (n != 0)) s[i--] = ','; } while (n); if (sign) s[i--] = '-'; memmove(s, s + i + 1, 127 - i); } int main() { int N = 500000; int NTrials = 100; struct rusage before; struct rusage after; float t; char s[128]; char s1[128]; char s2[128]; uint32_t datain[N]; uint8_t compressedbuffer[N * 5]; uint32_t recovdata[N]; for (int k = 0; k < N; ++k) datain[k] = rand() >> (31 & rand()); size_t compsize = 0; getrusage(RUSAGE_SELF, &before); for (int i = 0; i < NTrials; i++) compsize = streamvbyte_encode(datain, N, compressedbuffer); getrusage(RUSAGE_SELF, &after); t = (after.ru_utime.tv_usec - before.ru_utime.tv_usec) / 1000000.0; punt((long long)round(N * NTrials / t), s); printf("encoding time = %f s, %s uints/sec\n", t, s); size_t compsize2; getrusage(RUSAGE_SELF, &before); for (int i = 0; i < NTrials; i++) compsize2 = streamvbyte_decode(compressedbuffer, recovdata, N); getrusage(RUSAGE_SELF, &after); t = (after.ru_utime.tv_usec - before.ru_utime.tv_usec) / 1000000.0; punt((long long)round(N * NTrials / t), s); printf("decoding time = %f s, %s uints/sec\n", t, s); if (compsize != compsize2) printf("compsize=%zu compsize2 = %zu\n", compsize, compsize2); int k; for (k = 0; k < N && datain[k] == recovdata[k]; k++) ; if (k < N) printf("mismatch at %d before=%d after=%d\n", k, datain[k], recovdata[k]); assert(k >= N); punt(N * sizeof(uint32_t), s1); punt(compsize, s2); printf("Compressed %s bytes down to %s bytes.\n", s1, s2); return 0; } streamvbyte-0.4.1/tests/unit.c000066400000000000000000000147121346460053600163620ustar00rootroot00000000000000#include "streamvbyte.h" #include "streamvbyte_zigzag.h" #include "streamvbytedelta.h" #include #include #include #include static bool isLittleEndian() { int x = 1; char *c = (char *)&x; return (*c == 1); } // return -1 in case of failure int zigzagtests() { size_t N = 4096; int32_t *datain = malloc(N * sizeof(int32_t)); for(size_t i = 0; i < N; i++) datain[i] = rand() - rand(); uint32_t *dataout = malloc(N * sizeof(uint32_t)); int32_t *databack = malloc(N * sizeof(int32_t)); uint32_t *deltadataout = malloc(N * sizeof(uint32_t)); int32_t *deltadataback = malloc(N * sizeof(int32_t)); zigzag_encode(datain, dataout, N); zigzag_decode(dataout, databack, N); zigzag_delta_encode(datain, deltadataout, N, 0); zigzag_delta_decode(deltadataout, deltadataback, N, 0); int isok = 1; for(size_t i = 0; i < N; i++) { if(datain[i] != databack[i]) { printf("bug\n"); isok = -1; } if(datain[i] != deltadataback[i]) { printf("bug\n"); isok = -1; } } free(databack); free(dataout); free(datain); return isok; } // return -1 in case of failure int basictests() { int N = 4096; uint32_t *datain = malloc(N * sizeof(uint32_t)); // on purpose we mess with the alignment of compressedbufferorig uint8_t *compressedbufferorig = malloc(streamvbyte_max_compressedbytes(N) + sizeof(uint32_t)); uint8_t *compressedbuffer = compressedbufferorig + (sizeof(uint32_t) - 1); uint32_t *recovdata = malloc(N * sizeof(uint32_t)); for (int length = 0; length <= N;) { for (uint32_t gap = 1; gap <= 387420489; gap *= 3) { for (int k = 0; k < length; ++k) datain[k] = gap - 1 + (rand() % 8); // sometimes start with zero // Default encoding: 1,2,3,4 bytes per value size_t compsize = streamvbyte_encode(datain, length, compressedbuffer); size_t usedbytes = streamvbyte_decode(compressedbuffer, recovdata, length); if (compsize != usedbytes) { printf("[streamvbyte_decode] code is buggy length=%d gap=%d: compsize=%d != " "usedbytes=%d \n", (int)length, (int)gap, (int)compsize, (int)usedbytes); return -1; } for (int k = 0; k < length; ++k) { if (recovdata[k] != datain[k]) { printf("[streamvbyte_decode] code is buggy gap=%d\n", (int)gap); return -1; } } // Alternative encoding: 0,1,2,4 bytes per value compsize = streamvbyte_encode_0124(datain, length, compressedbuffer); usedbytes = streamvbyte_decode_0124(compressedbuffer, recovdata, length); if (compsize != usedbytes) { printf("[streamvbyte_decode_0124] code is buggy length=%d gap=%d: compsize=%d != " "usedbytes=%d \n", (int)length, (int)gap, (int)compsize, (int)usedbytes); return -1; } for (int k = 0; k < length; ++k) { if (recovdata[k] != datain[k]) { printf("[streamvbyte_decode_0124] code is buggy gap=%d\n", (int)gap); return -1; } } } // Delta-encoded functions for (size_t gap = 1; gap <= 531441; gap *= 3) { for (int k = 0; k < length; ++k) datain[k] = gap * k; size_t compsize = streamvbyte_delta_encode(datain, length, compressedbuffer, 0); size_t usedbytes = streamvbyte_delta_decode(compressedbuffer, recovdata, length, 0); if (compsize != usedbytes) { printf("[streamvbyte_delta_decode] code is buggy gap=%d, size " "mismatch %d %d \n", (int)gap, (int)compsize, (int)usedbytes); return -1; } for (int k = 0; k < length; ++k) { if (recovdata[k] != datain[k]) { printf("[streamvbyte_delta_decode] code is buggy gap=%d\n", (int)gap); return -1; } } } if (length < 128) ++length; else { length *= 2; } } free(datain); free(compressedbufferorig); free(recovdata); return 0; } // return -1 in case of failure int aqrittests() { uint8_t in[16]; uint8_t compressedbuffer[32]; uint8_t recovdata[16]; memset(compressedbuffer, 0, 32); memset(recovdata, 0, 16); for (int i = 0; i < 0x10000; i++) { in[0] = (uint8_t)((i >> 0) & 1); in[1] = (uint8_t)((i >> 1) & 1); in[2] = (uint8_t)((i >> 2) & 1); in[3] = (uint8_t)((i >> 3) & 1); in[4] = (uint8_t)((i >> 4) & 1); in[5] = (uint8_t)((i >> 5) & 1); in[6] = (uint8_t)((i >> 6) & 1); in[7] = (uint8_t)((i >> 7) & 1); in[8] = (uint8_t)((i >> 8) & 1); in[9] = (uint8_t)((i >> 9) & 1); in[10] = (uint8_t)((i >> 10) & 1); in[11] = (uint8_t)((i >> 11) & 1); in[12] = (uint8_t)((i >> 12) & 1); in[13] = (uint8_t)((i >> 13) & 1); in[14] = (uint8_t)((i >> 14) & 1); in[15] = (uint8_t)((i >> 15) & 1); const int length = 4; size_t compsize = streamvbyte_encode((uint32_t *)in, length, compressedbuffer); size_t usedbytes = streamvbyte_decode(compressedbuffer, (uint32_t *)recovdata, length); if (compsize != usedbytes) { printf("[streamvbyte_decode] code is buggy"); return -1; } for (size_t k = 0; k < length * sizeof(uint32_t); ++k) { if (recovdata[k] != in[k]) { printf("[streamvbyte_decode] code is buggy"); return -1; } } compsize = streamvbyte_encode_0124((uint32_t *)in, length, compressedbuffer); usedbytes = streamvbyte_decode_0124(compressedbuffer, (uint32_t *)recovdata, length); if (compsize != usedbytes) { printf("[streamvbyte_decode_0124] code is buggy"); return -1; } for (size_t k = 0; k < length * sizeof(uint32_t); ++k) { if (recovdata[k] != in[k]) { printf("[streamvbyte_decode_0124] code is buggy"); return -1; } } } return 0; } int main() { if(zigzagtests() == -1) return -1; if (basictests() == -1) return -1; if (aqrittests() == -1) return -1; printf("Code looks good.\n"); if (isLittleEndian()) { printf("And you have a little endian architecture.\n"); } else { printf("And you have a big endian architecture.\n"); printf("Warning: produced compressed bytes may not be interoperable with " "little endian systems.\n"); } #ifdef __AVX__ printf("Code was vectorized (x64).\n"); #elif defined(__ARM_NEON__) printf("Code was vectorized (ARM NEON).\n"); #else printf("Warning: you tested non-vectorized code.\n"); #endif return 0; } streamvbyte-0.4.1/tests/writeseq.c000066400000000000000000000025101346460053600172370ustar00rootroot00000000000000#include #include #include #include "streamvbyte.h" int main() { int N = 5000; uint32_t *datain = malloc(N * sizeof(uint32_t)); uint8_t *compressedbuffer = malloc(N * sizeof(uint32_t)); uint32_t *recovdata = malloc(N * sizeof(uint32_t)); for (int k = 0; k < N; ++k) datain[k] = k * 100; size_t compsize = streamvbyte_encode(datain, N, compressedbuffer); // encoding const char *filename = "data.bin"; printf("I will write the data to %s \n", filename); FILE *f = fopen(filename, "w"); size_t bw = fwrite(compressedbuffer, 1, compsize, f); fclose(f); if (bw != compsize) { printf("Tried to write %zu bytes, wrote %zu \n", compsize, bw); } f = fopen(filename, "r"); for (size_t k = 0; k < N * sizeof(uint32_t); ++k) compressedbuffer[k] = 0; size_t br = fread(compressedbuffer, 1, compsize, f); if (br != compsize) { printf("Tried to read %zu bytes, wrote %zu \n", compsize, br); } // here the result is stored in compressedbuffer using compsize bytes size_t compsize2 = streamvbyte_decode(compressedbuffer, recovdata, N); // decoding (fast) assert(compsize == compsize2); free(datain); free(compressedbuffer); free(recovdata); printf("Compressed %d integers down to %d bytes.\n", N, (int)compsize); return 0; } streamvbyte-0.4.1/utils/000077500000000000000000000000001346460053600152305ustar00rootroot00000000000000streamvbyte-0.4.1/utils/shuffle_tables.c000066400000000000000000000121441346460053600203640ustar00rootroot00000000000000#include #include #include #include #define extract(c,i) (3 & (c >> 2*i)) typedef uint8_t (*code_len_function)(int c); static uint8_t code_to_length(int c) { /* 0,1,2,3 codes-> 1,2,3,4 bytes */ return c + 1; } static uint8_t code_to_length_0124(int c) { switch (c) { case 0: // 0 bytes return 0; case 1: // 1 byte return 1; case 2: // 2 bytes return 2; default: // 4 bytes return 4; } } // Initializes the lengths tables. Meant to be called before // decoder_permutation/encoder_permutation functions. static void lengths_init(uint8_t *lengths, code_len_function code_len) { for(int code = 0; code < 256; code++) { lengths[code] = 0; for(int i = 0; i < 4; i++ ) { int c = extract(code, i); lengths[code] += code_len(c); } } } // produces the decoder permutation tables // as well as the "length" tables. The length table // is the same for encoding and decoding. // table should point at 256*16 bytes // length should point at 256 bytes static void decoder_permutation(uint8_t *table) { uint8_t *p = table; for(int code = 0; code < 256; code++) { int byte = 0; for(int i = 0; i < 4; i++ ) { int c = extract(code, i); int j; for( j = 0; j <= c; j++ ) *p++ = byte++; for( ; j < 4; j++ ) *p++ = -1; } } } // produces the encoder permutation tables // table should point at 256*16 bytes // length should point at 256 bytes initialized with init_lengths static void encoder_permutation(uint8_t *table, uint8_t *lengths) { uint8_t *p = table; for(int code = 0; code < 256; code++) { for(int i = 0; i < 4; i++ ) { int c = extract(code, i); int j; for( j = 0; j <= c; j++ ) *p++ = 4*i + j; } for( int i = lengths[code]; i < 16; i++ ) *p++ = -1; } } // produces the decoder permutation tables // table should point at 256*16 bytes static void decoder_permutation_0124(uint8_t *table) { uint8_t *p = table; for(int code = 0; code < 256; code++) { int byte = 0; for(int i = 0; i < 4; i++ ) { int c = extract(code, i); if (c < 3) { // Here c stands for a number of bytes to copy, i.e. 0,1,2 int j; for( j = 0; j < c; j++ ) *p++ = byte++; for( ; j < 4; j++ ) *p++ = -1; } else { // Otherwise always copy all 4 bytes for(int j = 0; j < 4; j++ ) *p++ = byte++; } } } } // produces the encoder permutation tables // table should point at 256*16 bytes // length should point at 256 bytes initialized // with lengths_init static void encoder_permutation_0124(uint8_t *table, uint8_t *lengths) { uint8_t *p = table; for(int code = 0; code < 256; code++) { for(int i = 0; i < 4; i++ ) { int c = extract(code, i); if (c < 3) { for( int j = 1; j <= c; j++ ) *p++ = 4*i + j - 1; } else { for( int j = 0; j <= c; j++ ) *p++ = 4*i + j; } } for( int i = lengths[code]; i < 16; i++ ) *p++ = -1; } } // to be used after calling either decoder_permutation or encoder_permutation // table should point at 256*16 bytes static void print_permutation(uint8_t *table) { for(int code = 0; code < 256; code++) { int x; printf(" {"); for(int i = 0; i < 15; i++) printf(" %2d,", x = (int8_t) table[code*16 + i]); printf( " %2d", x = (int8_t) table[code*16 + 15]); printf(" }, // %d%d%d%d\n", extract(code,0), extract(code,1), extract(code,2), extract(code,3)); } } // to be used after calling either decoder_permutation or encoder_permutation // length should point at 256 bytes static void print_lengths(uint8_t *length) { printf("{"); printf("\n"); for(int code = 0; code < 256; ) { for(int k = 0; k < 16 ; k++) { printf(" %2d,", length[code]); code++; } printf("\n"); } printf(" }"); } int main(int argc, char **argv) { uint8_t *encoder_table = (uint8_t *) malloc( sizeof(uint8_t[256][16])); uint8_t *decoder_table = (uint8_t *) malloc( sizeof(uint8_t[256][16])); uint8_t lengths[256]; if (argc == 2 && 0 == strcmp(argv[1], "0124")) { printf("// using 0,1,2,4 bytes per value\n"); lengths_init(lengths, code_to_length_0124); encoder_permutation_0124(encoder_table, lengths); decoder_permutation_0124(decoder_table); } else if (argc == 2 && 0 == strcmp(argv[1], "1234")) { printf("// using 1,2,3,4 bytes per value\n"); lengths_init(lengths, code_to_length); encoder_permutation(encoder_table, lengths); decoder_permutation(decoder_table); } else { fprintf(stderr, "Usage: shuffle_tables <0124|1234> > src/streamvbyte_shuffle_tables.h\n"); exit(EXIT_FAILURE); } printf("static uint8_t lengthTable[256] ="); print_lengths(lengths); printf(";\n\n"); printf("// decoding:\n"); printf("static uint8_t shuffleTable[256][16] = {\n"); print_permutation(decoder_table); printf("};\n\n"); printf("// encoding:\n"); printf("static uint8_t encodingShuffleTable[256][16] = {\n"); print_permutation(encoder_table); printf("};\n"); return 0; }